Coldfusion viewSource component

One thing always leads to another...
Because I wrote the code-coloring component, I needed a file which could display source code, and color-codes it.
That routine is actually fairly simple: just do a file-read, then convert all ampersands ('&') to &amp;', and all <'s to &lt;'s, and then display it into the browser.

Using this as a basis, I created the viewsource.cfm component, which does the above things, and adds the following:

  • Security measures, to allow only certain extensions / cerain directories / certain flenames;
  • Color-coding off course
  • And a copyright notice with a link to the clor-coding component :-)

Downloads

Usage

Just unzip the zip file somewhere in your web-root, let's say in '/viewsource/*'.
With this done, you are already able to view all html, js, css, txt, cfm, cfc, and cfml files within the directory '/viewsource/'.
You can check it out by viewing the viewsource file itself: http:/yoursite.com/viewsource/viewsource.cfm?file=viewsource.cfm

Now, if you want to do some more advanced configuration, check out the documentation inside the viewsource.cfm file, or read the following:

<!---
 Advice for users of this code:
 ** By default, THIS FILE can be viewed! So be carefull about modifying this; the security
    will otherwise become only as good as your coding skills are ;-)
 ** By default, all files in the same directory as this file can be viewed!
    If you want to be certain that only certain files can be viewed, then fill the list 'viewablefiles' underneath.
 ** If you want more directories to be viewable, then add them to the 'variables.viewablePaths' list.
    By default, this variable must hold './', which means the current directory.
--->

<!--- usage: leave empty if all files of the directory/ies may be viewed. Otherwise, use a comma-delimited list. --->
<cfset variables.viewablefiles = "" />
<!--- usage: leave empty if all file-extensions may be viewed. Otherwise, use a comma-delimited list. --->
<cfset variables.viewableExtensions = "cfm,cfc,cfml,txt,js,htm,html" />
<!--- usage: absolute path from site-root, or relative from THIS directory. It will be expanded by expandPath() function.
Example: <cfset variables.viewablePaths = "./,/javascript/,/css/,../scripts/" /> --->
<cfset variables.viewablePaths = "./" />

If you're using the viewsource component, then please leave me a comment; I really appreciate it!

del.icio.us Digg StumbleUpon Facebook Technorati Fav reddit Google Bookmarks
| Viewed 2442 times
  1. Chacidy

    #1 by Chacidy - May 24, 2011 at 4:58 PM

    That’s raelly shrewd! Good to see the logic set out so well.
(will not be published)
Leave this field empty