ColdFusion RegEx White List Example

Posted by Quinn Madson | Posted in | Posted on 9:49 AM

0

I needed to build a function that would strip out characters in event information because, otherwise it would break a JSON feed. Here is what I used:


<cffunction name="jsonSafe" access="private">
<cfargument name="str" type="string" required="true">
<cfset newStr = reReplace(arguments.str, '[^[:alnum:][:space:]$=;.?!\\/&"''`():,\[\]{}_\-]', '_','all')>
<cfreturn newStr>
</cffunction>

Preserve epoch dates in Zimbra JSON via ColdFusion DeserializeJSON function

Posted by Quinn Madson | Posted in | Posted on 2:14 PM

0

The DeserializeJSON() function in ColdFusion converts an epoch date/time in JSON from something like: 1281364965000 to: 1.281364965E+012.


To prevent this from happening, you can use something like this:

<cfset jsonData = reReplace(jsonData, '([0-9]{13})', '"\1"', 'ALL')>


Alternatively, to convert any number, 10 digits or more into a string to preserve the proper formatting, use something like this:

<cfset jsonData = reReplace(jsonData, '([0-9]{10,})', '"\1"', 'ALL')>

Fixing bootloaders when dual booting OS X and Ubuntu

Posted by Quinn Madson | Posted in | Posted on 9:03 PM

0

I ran into a problem the last time Ubuntu upgraded either the kernel or grub (not sure which); Either way, it blew away my Chameleon bootloader and replaced it with Grub. Here's how to fix it:


  • Reboot from the iATKOS v7 CD
  • Deselect all checkboxes except the one for Install Chameleon
  • Install
Now you should be able to boot into OS X but, Ubuntu will be unavailable.

  • Boot from the Ubuntu Live CD
  • Open the Terminal from Applications >> Accessories
sudo -s
mkdir /mnt/r
mount /dev/sda4 /mnt/r
mount --bind /dev /mnt/r/dev
mount --bind /proc /mnt/r/proc
chroot /mnt/r
update-grub
grub-install --force /dev/sda4

Adding CFWheels Applications as "Custom Script" elements in the CommonSpot CMS

Posted by Quinn Madson | Posted in | Posted on 1:43 PM

0

It appears that CommonSpot (version 5, at least) ignores Application.cfc files when using a custom script in the same directory. In CF Wheels, Application.cfc is used to setup the entire framework.

Here is what I did to get it working:

  • Put your CF Wheels application in the customcf/ subdirectory
  • Rename Application.cfc to application.cfc (This is done to prevent the application from being initialized twice if accessed outside the CMS.)
  • Edit the index.cfm at the root of the application directory:
<!--- Manually instantiate the application.cfc --->
<cfset server.railo = structNew()>
<cfset server.railo.version = "fake version">

<!--- If this is the first time the application has run, call the onApplicationStart method --->
<cfset app = CreateObject("component","application")>

<!--- Call the onRequestStart method and pass the current page as a parameter --->
<cfif not structKeyExists(application, "wheels")>
<cfset app.onApplicationStart()>
</cfif>

<!--- Call the onRequestStart method and pass the current page as a parameter --->
<cfset app.onRequestStart(cgi.script_name)>


<!--- This is the only original line in the file --->
<cfinclude template="wheels/index.cfm">

Gnome Screensaver Missing Lock Screen Prompt in Ubuntu Lucid 10.04

Posted by Quinn Madson | Posted in | Posted on 12:43 PM

4

For some reason, the unlock dialog box for Gnome Screensaver suddenly stopped appearing. Screensaver works fine but, move the mouse and no unlock prompt, just back to the screen saver. The only work-around was to press Ctrl-Alt-F1, login, and type the command:

killall gnome-screensaver
Although, after a while this gets annoying so, I looked for a better long term solution. Here it is:
sudo chmod a+r /etc/pam.d/*
That's it. I assume that the permissions may have been messed up during an update. Posted here for posterity.

CFEclipse Dictionary for CF on Wheels

Posted by Quinn Madson | Posted in | Posted on 9:56 PM

1

As far as I could tell, there was no CFEclipse dictionary available for CF on Wheels so I created one.


To get it, download the XML at: http://su.pr/6s1VUi

To use it:
  • Open your Eclipse plugins/ directory
  • Open the directory: org.cfeclipse.cfml_X/ (where X is your CFEclipse version number)
  • Open the directory: dictionary
  • Copy cfwheels.xml to this location
  • Close Eclipse if it is running
  • Open up: dictionaryconfig.xml
Change:
<version key="cf8" label="Coldfusion 8">
<grammar location="cf8.xml" />
<grammar location="user.xml" />
</version>
To:
<version key="cf8" label="Coldfusion 8">
<grammar location="cf8.xml" />
<grammar location="user.xml" />
<grammar location="cfwheels.xml" />
</version>
I am not sure if it is an Ubuntu bug but, any thing that is not in the first grammar file is not loaded in Eclipse. If you run into problems, just copy and paste the functions listed in cfwheels.xml to cf8.xml or whatever dialect you use. The other option is to create a separate CFWheels dictionary entry but, it doesn't work very well switching back and forth between dictionary sets.

In the likely event that I am struck by a bus, a very confused sperm whale, or bowl of petunias, I created a script that scrapes the CF on Wheels documentation and creates the dictionary XML. If more functions are added and the structure of the docs pages don't change immensely, rerun the script to refresh the dictionary XML.

Here's the code:

<cfparam name="url.page" default="0">
<cfparam name="url.start" default="0">
<cfparam name="url.end" default="0">

<!---
Strips all table and table content tags and extra whitespace from a string.

@param string String to format. (Required)
@return Returns a string.
@author Jared Rypka-Hauer (jared@web-relevant.com)
@version 1, August 25, 2005
--->
<cffunction name="detableize">
<cfargument name="string" type="string" required="true" />
<cfset var outputString = arguments["string"]>
<cfset outputString = reReplaceNoCase(outputString , "</*table>", "", "all")>
<cfset outputString = reReplaceNoCase(outputString , "</*td>", "ø", "all")>
<cfset outputString = reReplaceNoCase(outputString , "</*t[rhd](\s*\w*=*""*\w*""*)*>", "", "all")>
<cfset outputString = reReplaceNoCase(outputString , "(?m)^\s*", "", "all")>
<cfset outputString = reReplaceNoCase(outputString , "\n{2,}", "#chr(10)#", "all")>
<cfreturn outputString />
</cffunction>

<!--- based on function above; removes garbage from api page --->
<cffunction name="detagify">
<cfargument name="string" type="string" required="true" />
<cfset var outputString = arguments["string"]>
<cfset outputString = reReplaceNoCase(outputString , "</*li>", "", "all")>
<cfset outputString = reReplaceNoCase(outputString , "<code>[a-z\(\)]*</code>", "", "all")>
<cfset outputString = reReplaceNoCase(outputString , "<a href=""", "", "all")>
<cfset outputString = reReplaceNoCase(outputString , """></a>", ",", "all")>
<cfset outputString = reReplaceNoCase(outputString , "(?m)^\s*", "", "all")>
<cfset outputString = reReplaceNoCase(outputString , "\n{2,}", "#chr(10)#", "all")>
<cfreturn outputString />
</cffunction>

<cfscript>
/**
* Returns the content enclosed in a tag pair.
*
* @param tag The tag to look for. Should be passed without < or > and without attributes. (Required)
* @param string The string to search. (Required)
* @return Returns a string.
* @author Johan Steenkamp (johan@orbital.co.nz)
* @version 1, September 16, 2002
*/
function getTagContent(tag,str) {
var matchStruct = structNew();
var startTag = "<#tag#[^>]*>";
var endTag = "</#tag#>";
var endTagStart = 0;
matchStruct = REFindNoCase(startTag,str,1,"true");
if(matchStruct.len[1] eq 0 ) return "";
endTagStart = REFindNoCase(endTag,str,matchStruct.pos[1],"false");
return Mid(str,matchStruct.pos[1]+matchStruct.len[1],endTagStart-matchStruct.pos[1]-matchStruct.len[1]);
}
</cfscript>

<!--- get urls --->
<cfhttp url="http://cfwheels.org/docs/function/"></cfhttp>
<cfscript>
urlsFilecontent = cfhttp.filecontent;
urlsStartPoint = find("<h1>Wheels <abbr title=""Application Programming Interface"">API</abbr></h1>", urlsFilecontent);
urlsEndPoint = len(urlsFilecontent) - urlsStartPoint;
urlsChopped = mid(urlsFilecontent, urlsStartPoint, urlsEndPoint);
urlsChopped = getTagContent("ul", urlsChopped);
urlsChopped = detagify(urlsChopped);
urlsChopped = listToArray(urlsChopped);
dictionary = "";
itemsPerPage = 25;
urlsPages = ceiling(arrayLen(urlsChopped) / itemsPerPage);
</cfscript>

<cfoutput>
<h1>CFWheels API to CFEclipse Dictionary Conversion</h1>
<p>#arrayLen(urlsChopped)# functions listed in documentation. Function conversions are broken up into batches to prevent timeouts.
Click below to convert a batch.</p>
<ul>
<cfloop from="1" to="#urlsPages#" index="i">
<cfscript>
if (i neq 1) {
start = (i - 1) * itemsPerPage;
end = start + itemsPerPage - 1;
} else {
start = 1;
end = itemsPerPage - 1;
}

if (end gt arrayLen(urlsChopped)) {
end = arrayLen(urlsChopped);
}
</cfscript>
<li><a href="?page=#i#&start=#start#&end=#end#">#i#: #start# - #end#</a></li>
</cfloop>
</ul>
</cfoutput>

<cfif url.page>
<cfloop from="#url.start#" to="#url.end#" index="i">

<!--- convert html to cfeclipse dictionary xml --->
<cfhttp url="http://cfwheels.org#urlsChopped[i]#"></cfhttp>
<cfset functionFilecontent = cfhttp.filecontent>

<cfscript>
functionStartPoint = findnocase("contentWrapper", functionFilecontent);
functionEndPoint = len(functionFilecontent) - functionStartPoint;
functionChopped = mid(functionFilecontent, functionStartPoint, functionEndPoint);
functionName = getTagContent("code", functionChopped);
functionChopped = replacenocase(functionChopped, "<code>", "", "all");
functionChopped = replacenocase(functionChopped, "</code>", "", "all");
functionDescription = getTagContent("p", functionChopped);
functionParameters = getTagContent("tbody", functionChopped);
functionParameters = detableize(functionParameters);
functionParameters = listToArray(functionParameters, "ø", true);
</cfscript>

<cfoutput>
<cfsavecontent variable="functionOutput">
<function xmlns="http://www.cfeclipse.org/version1/dictionary" name="#xmlFormat(functionName)#" returns="">

<help><![CDATA[
#xmlFormat(trim(functionDescription))#
]]></help>
<cfloop from="1" to="#arrayLen(functionParameters)-1#" index="i" step="5"><cfif functionParameters[i+2] eq "No"><cfset required="false"><cfelse><cfset required="true"></cfif>
<parameter name="#xmlFormat(trim(functionParameters[i]))#" type="#xmlFormat(trim(functionParameters[i+1]))#" required="#xmlFormat(trim(required))#">
<help><![CDATA[
#xmlFormat(trim(functionParameters[i+4]))#
]]></help>
</parameter>
</cfloop>
</function>
</cfsavecontent>
</cfoutput>

<cfset dictionary = dictionary & functionOutput>

</cfloop>
<cfoutput>
<textarea cols="150" rows="50">
#dictionary#
</textarea>
</cfoutput>
</cfif>
Hopes this helps some other CFEclipse & CF on Wheels developers out there.

Zimbra ZmAppt Object Properties

Posted by Quinn Madson | Posted in | Posted on 1:45 PM

0

As of this writing in July of 2009, the only documentation of the Zimbra ZmAppt object is a preliminary draft of a white paper released by Zimbra in 2006. The documentation is out of date so, I am putting up an example of a current ZmAppt object (as of release 5.0.18) here, in case anyone is googling for updated documentation like I was.

ALARM undefined
ALLDAYEVENT false
ATTENDEES [empty string]
ENDDATE Tue Jul 28 2009 16:00:00 GMT-0500 (CST)
EXCEPTION undefined
ID f6ec6325-5dd9-452c-aec5-c60561900b79:560
ISRECURRING false
LOCATION Test Location 254
NOTES Test Notes 254
OTHERATTENDEES undefined
RESOURCES [empty string]
SRCOBJ ZmAppt
STARTDATE Tue Jul 28 2009 11:00:00 GMT-0500 (CST)
SUBJECT Test Event 254
TIMEZONE (GMT-06.00) Central Time (US & Canada)
TYPE ZmAppt
UID 02b205bf-72cc-48c7-a0ec-0862ae321124

Here is an example of the srcObj above:
ADDCHANGELISTENER undefined
ADJUSTMS undefined
ALARM undefined
ALARMDATA undefined
ALLDAYEVENT false
ATTACHMENTS undefined
CACHE undefined
CANCEL undefined
CLEAR undefined
COMPNUM undefined
CONSTRUCTOR function Object() { [native code] }
CREATE undefined
DELETELOCAL undefined
ENDDATE Tue Jul 28 2009 16:00:00 GMT-0500 (CST)
ENDSINUTC undefined
FBA undefined
FLAGLOCAL undefined
FOLDERID undefined
FRAGMENT undefined
FREEBUSY undefined
GETATTACHLISTHTML undefined
GETATTACHMENTS undefined
GETATTENDEES undefined
GETATTENDEESTEXT undefined
GETATTENDEETOOLTIPDATA undefined
GETATTENDEETOOLTIPSTRING undefined
GETBYID undefined
GETCOMPNUM undefined
GETDATERANGE undefined
GETDEFAULTDNDACTION undefined
GETDETAILS undefined
GETDURATION undefined
GETDURATIONTEXT undefined
GETENDTIME undefined
GETFOLDER undefined
GETFOLDERID undefined
GETHTMLSUMMARY undefined
GETLOCALFOLDERID undefined
GETLOCATION undefined
GETMAILNOTIFICATIONOPTION undefined
GETNAME undefined
GETNOTESPART undefined
GETORGANIZER undefined
GETORIGSTARTDATE undefined
GETORIGSTARTTIME undefined
GETORIGTIMEZONE undefined
GETPARTICIPANTSTATUSSTR undefined
GETPRINTHTML undefined
GETRECURBLURB undefined
GETRECURTYPE undefined
GETREMINDERLOCATION undefined
GETREMINDERNAME undefined
GETREMOTEFOLDEROWNER undefined
GETRESTURL undefined
GETSENTBY undefined
GETSHORTSTARTHOUR undefined
GETSTARTTIME undefined
GETSUMMARY undefined
GETTAGIMAGEINFO undefined
GETTEXTSUMMARY undefined
GETTIMEZONE undefined
GETTOOLTIP undefined
GETUNIQUEENDDATE undefined
GETUNIQUEID undefined
GETUNIQUESTARTDATE undefined
GETURL undefined
HASALARMDATA undefined
HASATTACHMENTS undefined
HASATTENDEEFORTYPE undefined
HASATTENDEES undefined
HASPERSONATTENDEES undefined
HASTAG undefined
ID f6ec6325-5dd9-452c-aec5-c60561900b79:560
INVID undefined
ISALARMINRANGE undefined
ISALARMINSTANCE undefined
ISALLDAYEVENT undefined
ISCUSTOMRECURRENCE undefined
ISENDINRANGE undefined
ISEXCEPTION undefined
ISINRANGE undefined
ISMULTIDAY undefined
ISORG undefined
ISORGANIZER undefined
ISOVERLAPPING undefined
ISPRIVATE undefined
ISREADONLY undefined
ISRECURRING false
ISSHARED undefined
ISSTARTINRANGE undefined
LIST undefined
LOCATION location 254
MESSAGE undefined
MODIFY undefined
MOVE undefined
MOVELOCAL undefined
NAME undefined
NOTESTOPPART undefined
NOTIFYDELETE undefined
NOTIFYMODIFY undefined
ORGANIZER undefined
ORIGATTENDEES undefined
ORIGEQUIPMENT undefined
ORIGLOCATIONS undefined
OTHERATTENDEES undefined
PARSEALARM undefined
PARSEALARMDATA undefined
PRIORITY undefined
PRIVACY undefined
PTST undefined
RECURRING undefined
REMOVEALLCHANGELISTENERS undefined
REMOVEALLTAGSLOCAL undefined
REMOVEATTACHMENT undefined
REMOVECHANGELISTENER undefined
RESETREPEATCUSTOMDAYOFWEEK undefined
RESETREPEATMONTHLYDAYLIST undefined
RESETREPEATWEEKLYDAYS undefined
RESETREPEATYEARLYMONTHSLIST undefined
RIDZ undefined
RSVP undefined
SAVE undefined
SENTBY undefined
SERIESINVID undefined
SETALLDAYEVENT undefined
SETATTACHMENTS undefined
SETATTENDEES undefined
SETATTENDEETOOLTIPDATA undefined
SETDATERANGE undefined
SETENDDATE undefined
SETFOLDERID undefined
SETFROMMAILMESSAGE undefined
SETFROMMESSAGE undefined
SETINCLUDEEDITREPLY undefined
SETMAILNOTIFICATIONOPTION undefined
SETNAME undefined
SETNOBUSYOVERLAY undefined
SETORGANIZER undefined
SETRECURTYPE undefined
SETREMINDERMINUTES undefined
SETRSVP undefined
SETSTARTDATE undefined
SETTEXTNOTES undefined
SETTIMEZONE undefined
SETTYPE undefined
SETVIEWMODE undefined
SHOULDRSVP undefined
SHOWBLOBMISSINGDLG undefined
STARTDATE Tue Jul 28 2009 11:00:00 GMT-0500 (CST)
STARTSINUTC undefined
STATUS undefined
TAGHASH undefined
TAGLOCAL undefined
TAGS undefined
TIMEZONE undefined
TOOLTIP undefined
TOSTRING function toString() { [native code] }
TRANSPARENCY undefined
TYPE undefined
TZO undefined
UID 02b205bf-72cc-48c7-a0ec-0862ae321124
UNIQSTARTTIME undefined
VIEWMODE undefined
_ADDATTENDEESTOSOAP undefined
_ADDATTENDEETOSOAP undefined
_ADDDATETIMETOSOAP undefined
_ADDEXTRASTOSOAP undefined
_ADDINVITEANDCOMPNUM undefined
_ADDLOCATIONTOSOAP undefined
_ADDNOTESTOSOAP undefined
_ADDXPARAMTOSOAP undefined
_ADDXPROPSTOALARM undefined
_ADDXPROPSTOSOAP undefined
_ATTENDEES undefined
_CURRENTLYLOADED undefined
_DOCANCEL undefined
_EVT undefined
_EVTMGR undefined
_FANOUTFIRST undefined
_FANOUTLAST undefined
_FANOUTNUM undefined
_GETATTR undefined
_GETCLEANHTML2TEXT undefined
_GETDEFAULTBLURB undefined
_GETDEFAULTFOLDERID undefined
_GETFLAGS undefined
_GETINVITEFROMERROR undefined
_GETSOAPFORMODE undefined
_GETTEXTSUMMARYTIME undefined
_GETTTDAY undefined
_HANDLECANCELERROR undefined
_HANDLEERRORGETDETAILS undefined
_HANDLEERRORGETDETAILS2 undefined
_HANDLERESPONSEGETDETAILS undefined
_HANDLERESPONSESEND undefined
_LAYOUT undefined
_LOADFROMDOM undefined
_NOBUSYOVERLAY undefined
_NOTIFY undefined
_ORIG undefined
_ORIGSTARTDATE undefined
_ORIGTIMEZONE undefined
_PARSEFLAGS undefined
_PARSETAGS undefined
_PTSTLOCATIONMAP undefined
_RECURRENCE undefined
_REMINDERMINUTES undefined
_REPLIES undefined
_RESETCACHED undefined
_SENDNOTIFICATIONMAIL undefined
_SENDREQUEST undefined
_SETALARMDATA undefined
_SETALARMFROMMESSAGE undefined
_SETALARMXPROPS undefined
_SETEXTRASFROMMESSAGE undefined
_SETNOTES undefined
_SETRECURRENCE undefined
_SETSIMPLESOAPATTRIBUTES undefined
_SETTIMEFROMMESSAGE undefined
_STARTTIMEUNIQID undefined
_TOOLTIP undefined
_TRIMNOTESSUMMARY undefined
_UNIQID undefined
_UPDATEPARTICIPANTSTATUS undefined
_VALIDATTACHMENTS undefined