Steven Erat's Blog Steven Erat Photography
 
 
Viewing By Entry
 
 

TalkingTree  Selective, Bulk CFEncode Wrapper

 


Just a quick post to share a utility I wrote to facilitate using cfencode on a batch of ColdFusion templates. The purpose was to enable a way to encode a subset of templates in a selective way rather than just encoding everything recursively.

Example, say you have C:\foo\bar\, C:\foo\baz\, and C:\foo\qux\, and you want to encode only the baz directory and a single cfm in the qux directory, but without touching the bar directory. You would enter C:\foo\ as the base path, and then for the file list you would enter baz\ and qux\test.cfm similar to the screenshot here.

Code is without warranty, use at your own risk. Big caveat: Remember the cfencode tool doesn't truly encrypt CF templates, but merely obfuscates them. This can be easily decoded by those who know how. Also you may want to check out Ben Nadel's CFEncode extension for CFBuilder, and read Joshua Cyr's perspective on why you would or would not want to encode your files.

Plain Text

<!---
author: Steven Erat
purpose: Wrapper for selective, bulk encoding of ColdFusion templates
--->


<style>
h1 {
font-size:14pt;
}
h2 {
font-size:11pt;
}
td {
padding:10px;
align:right;
font-size:10pt;
}
.body {
font-family:Verdana,Helvetica;
font-size:10pt;
width:800;
}
.batch {
font-family:Verdana,Helvetica;
font-size:8pt;
width:800;
color:#252525;
}
</style>

<cfset currentDir = getdirectoryfrompath(expandpath('*.*'))>

<!--- Parse form to encode files --->
<cfif isdefined("form.basePath") and isdefined("form.fileList")>

<cfsilent>

<cfset issues = arrayNew(1)>
<cfif server.os.name contains "Win">
<!--- clear previous file contents or write file from start --->
<cffile action="write" file="#currentDir#/cfencode_batch.bat" output=" ">
<!--- iterate over file paths that were input and make full path --->
<cfloop list="#trim(form.fileList)#" index="i" delimiters="#chr(10)#">
<cfset target = trim(form.basepath) & "\" & trim(i)>
<cfset target = replace(target,"\\","\","all")>

<!--- file or dir? if dir then recurse? --->
<cfset recurse = "">
<cfif target contains ".cf">
<cfset type = "file">
<cfelse>
<cfset type = "dir">
<!--- cfencode bug discovered. recurse is always on for directories --->
<cfif right(target,1) eq "*">
<cfset recurse = "/r">
<!--- the * wildcard is used in the input, but not accepted by cfencode --->
<cfset target = left(target,len(target)-1)>
</cfif>
<cfif right(target,1) eq "\">
<!--- cfencode bombs if a slash appears at end of dir name --->
<cfset target = left(target,len(target)-1)>
</cfif>
</cfif>

<cfif (type is "file" and fileExists(target)) or (type is "dir" and directoryExists(target))>
<cftry>
<!--- add a line to bat file --->
<cffile action="append" file="#currentDir#/cfencode_batch.bat"
output='#server.ColdFusion.rootDir#\bin\cfencode.exe #target# #recurse# /q /v "2"'>

<cfcatch>
<cfset arrayAppend(issues,"ERROR: [#target#] #chr(10)##chr(13)#[#cfcatch.message#] #chr(10)##chr(13)#[#cfcatch.detail#]")>
</cfcatch>
</cftry>
<cfelse>
<cfset arrayAppend(issues,"INFO: [#type# #target# does not exist]")>
</cfif>
</cfloop>

<!--- wait for file write to complete --->
<cfscript>sleep(2000);</cfscript>

<!--- if bat file exists, run it --->
<cfif fileexists("#currentDir#/cfencode_batch.bat")>
<cfexecute name="#currentDir#/cfencode_batch.bat"></cfexecute>
<cfelse>
<cfset arrayAppend(issues,"INFO: [batch file does not exist at #currentDir#/cfencode_batch.bat]")>
</cfif>

<cfelse>
<cfset arrayAppend(issues,"INFO: [MUST RUN THIS ON WINDOWS]")>
</cfif>

</cfsilent>

</cfif>

<!--- Form to enter file list. Always display --->
<div class="body">
<h1>Encrypt ColdFusion Files</h1>
<p>
Enter a base path and then a list of relative paths off the base to specific ColdFusion files. Directories are acceptable too. Indicate recursion by ending a directory path ending in "*".
</p>
<p>
Files will be encrypted with cfencode in place, so make sure you have a backup of unencrypted source.
</p>
<cfoutput>
<form name="encodeForm" method="post" action="">
<table>
<tr><td>Base Path:</td><td><input name="basePath" value="<cfif isdefined("form.basePath")>#form.basePath#</cfif><cfoutput></cfoutput>" size="57" title="A base path to be prefixed to the relative path for each item in File List"/></td></tr>
<tr><td valign="top">File List:</td><td><textarea name="fileList" rows="15" cols="50" title="A list of files or directories to encode, one per line. Use relative paths from base path."><cfif isdefined("form.fileList")>#form.fileList#</cfif><cfoutput></cfoutput></textarea></td></tr>
<tr><td colspan="2"><input name="submit" type="submit" value="Encode Files"></td></tr>
</table>
</form>
</cfoutput>
</div>



<cfif isdefined("issues")>
<div class="batch">
<hr>
<h2>CFENCODE Completed</h2>
<cfif arraylen(issues)>
<cfdump var="#issues#" label="There were problems with your request">
</cfif>
<cfif fileexists("#currentDir#/cfencode_batch.bat")>
<br/><br/>Here's the contents of the batch file that was created:
<cffile action="read" file="#currentDir#/cfencode_batch.bat" variable="batchContents">
<cfoutput><pre>#batchContents#</pre></cfoutput>
</cfif>
</div>
</cfif>

 


Comments

There are no comments for this entry.

 

 

Calendar

 
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Search This Site

 
This is an exact search only

topics

 
adobe blogging coldfusion computer technology events flex java learning linux mac os x macromedia meetup new england odds & ends outdoors personal photos photoshop science travel video

About This Site

 
Adobe Alumni & Community Professional. Expert in ColdFusion, Flex, LCDS, Photoshop, Lightroom. Linux RHCE. Follow Me!. For my photography check out Boston Portrait Photographer.

Speaker at CF.Objective(): Automated UI Testing with CFSelenium, MXUnit, ANT, and JenkinsCI

Adobe Community Professional (ACP)
Red Hat Linux Certified Engineer

Recent Entries

 
Automated System Testing for ..
Could not find ColdFusion com..
No April Fools: Selenium Ship..

Recent Comments

 
Posted By Steven Erat:
Jim, and anyone else that may attend, if you would like the full slide deck and my demo project files BEFORE the conference, please reply as a comment ...

Posted By Jim Priest:
Can't wait for this one!!

Posted By iPhone Repair:
It appears there are so many people have issue with their iPhone & iPod Touch screens dropped and cracked. It happened to me also when u haven't got a ...

recently played

 
Mr. Brightside
by The Killers
on Hot Fuss
Get Hot Fuss by The Killers on Amazon

now playing, a plug-in for itunes

Categories

 
RSS Adobe (34)
RSS Bicycling (9)
RSS Blogging (39)
RSS Books (13)
RSS Breeze (13)
RSS CFMX Podcasts (10)
RSS ColdFusion (437)
RSS Computer Technology (51)
RSS Events (26)
RSS Flex (20)
RSS Gadgets (11)
RSS HiTech Industry (16)
RSS Java (26)
RSS Learning (57)
RSS Linux (70)
RSS Mac OS X (23)
RSS Macromedia (27)
RSS Meetup (35)
RSS New England (62)
RSS Odds & Ends (25)
RSS Outdoors (32)
RSS Personal (29)
RSS Photos (111)
RSS Photoshop (29)
RSS Podcasts (18)
RSS Rants (19)
RSS Restaurants (8)
RSS Science (34)
RSS Spain (16)
RSS Travel (42)
RSS Twitter (10)
RSS Video (20)
RSS Webcam (3)
RSS Writing (10)

RSS

 


Add to Google
Add to My Yahoo!

Credits and Stuff

 
BlogCFC - Free ColdFusion Powered Blog Software


 
 
blog | photos | flickr | referers | webcam | stats | about | contact
 
Copyright © 2012 Steven Erat. All rights reserved.
This is a personal weblog. The opinions expressed here represent my own and not those of my employer