Posts

Showing posts with the label coldfusion

Lucee vs Adobe ColdFusion columnList vs getColumnList vs getmetadata

I have a general section which dynamically displays reports, which are preconfigured in a certain way.  There are some totals and data rows which are not part of the metrics so net result is I had some CF code looking at the column lists and displaying appropriately.  Turns out there are very different results between Lucee and Adobe Coldfusion, for this example, it's important to create a sample table like so:  CREATE TABLE testtable( [Col1] [varchar](50) NULL, [ACol2] [varchar](50) NULL ) so that ACol2 is actually alphabetically before Col1.  Then run this <cfquery datasource="aTestDSN" name="qry"> select * from testtable </cfquery> <cfset columns = ""> <cfloop array="#getmetadata(qry)#" item="aryItem"> <cfset columns = listappend(columns, aryItem.Name)> </cfloop> <table> <tr><td>getmetadata</td><td><cfoutput>#columns#</cfoutput></td></tr...

Oh dear, a dodgy old piece of code in ColdFusion 8 style with local scopes!

A seldom used piece of code fell victim to the "new" ColdFusion "Local scope" from CF 9 (Centaur) With an Application.cfc; naturally everything inside it is local'ish when the onRequest exists: <cfcomponent displayname="Application" output="true" hint="Handle the application.">     <cffunction name="OnRequestStart" access="public" returntype="boolean" output="false">         <cfargument name="TargetPage" type="string" required="true"    />         <cfreturn true />     </cffunction>     <cffunction name="OnRequest" access="public" returntype="void" output="true">         <cfargument    name="TargetPage" type="string" required="true" />         <cfinclude template="#arguments.TargetPage#" />         <cfret...

Design best practice for an image library

If the library holds data in a raw format (ie a big sized image), then can then make all sorts of algorithms out of that to produce images. Generate different sizes, eg 100x100, 200x400 or what ever is required from the original Generate different types of images, either by conversion (png etc) or type, maybe base 64 for CSS and separate style sheet images for non base64 supporting CSS (like IE8 etc) Overlay another graphic on top (like a sash or otherwise) to generate only 1 image that needs to be retrieved All of this requires the smarts that you allow the original image to have coordinates stored against it as to where the center is or maybe use something like  https://github.com/tapmodo/Jcrop to create and store these coordinates of the box sizes. I've found it quite useful when uploading images through custom application to write the files as (for example) full_raw.png (usually stored in a database somewhere) full100x100.png (resized, re scaled depending how ...

JVM 1.7 and Coldfusion and Connection Failure

A lot of connection failures were showing up due to servers upgrading their certificates to the latest and greatest versions (256 bit) which (by the looks of things) weren't really working on Java 1.6 (128bit). Anyway, to upgrade CF 9 to 1.7 (1.8 not supported and the server monitor stopped working if this was done); installed Java 1.7, opened up the jvm.config for ColdFusion and changed the path for java.home. Copy of msvcr100.dll from JDK\bin in JRun4\bin Restarted the service and all went well. Then it fell over! Then I restarted the service. Then it fell over... Turns out, need to remove -XX:MaxPermSize=192m  from the jvm params, else preapre for some see sawing! Also, good idea to use the  -Duser.country= &  -Duser.language= parameters if required, as I ended up constantly getting US set up (despite the OS saying otherwise) Any other Connection Failure issues with these new certificates were resolved by importing missing chains using keytool . ...

cf_sql_timestamp vs cf_sql_date vs getdate()

If there's one thing I don't like it is people confusing a date with a timestamp, and how a lazy bit of development can ruin a load of data. Here is a simple query inserting data to a timestamp I found in a system where all the created dates were truncated because of the incorrect syntax. Bad one which was in use: insert into testdate values (<cfqueryparam cfsqltype="cf_sql_date" value="#createodbcdatetime(now())#">); Result :  2015-09-29 00:00:00.000 Best One (easiest to read) insert into testdate values(getdate() ); Result : 2015-09-29 10:10:09.880 Not great (no binding) insert into testdate values(#createodbcdatetime(now())#); Result :  2015-09-29 10:14:44.000 What the bad one should have been insert into testdate values(<cfqueryparam cfsqltype=" cf_sql_timestamp " value="#createodbcdatetime(now())#">)

Chrome 44 cgi.https value changed from "on" for SSL traffic to "1" for all traffic

Weird issue, used to use a few cgi.https comparison with "on" as per  https://msdn.microsoft.com/en-us/library/ms524602(v=vs.90).aspx which indicates it would be populated with on or off in IIS. In Chrome 43 this used to return the value on for https and off for http, in chrome 44 the value has change to 1 for all traffic (https and http), nothing in the release notes from what I can see at  https://chromium.googlesource.com/chromium/src/+log/43.0.2357.134..44.0.2403.89?pretty=fuller&n=10000 Update: Google acknowledge the issue and fixed it see http://src.chromium.org/viewvc/blink?view=revision&revision=199090 The "number" of websites the release broke is funny, as I would think it is "a lot", WooCommerce apparently was broken, as was any PHP or ColdFusion code using the cgi.https comparison. Just as an FYI, I'm not sure what php.net did to their website in response, but their main google SERP says https://www.php.net which is unre...

Checking Email and DNS MX records in ColdFusion with Java DnsContextFactory and Google Public DNS

Nice short function using Google's DNS and Java DnsContextFactory. Based on a script I saw here Note; a trailing space fails here; so make sure that doesn't waste some time of your day when validating. <cffunction name="validateEmailAndMXRecord" returntype="Struct">      <cfargument name="emailAddress" required="true">     <cfargument name="checkMXRecord" required="false" default="true">     <cfscript>     var env = CreateObject("java", "java.util.Hashtable");     var dirContext = CreateObject("java", "javax.naming.directory.InitialDirContext");     var type = ArrayNew(1);     var attributes = "";     var atribEnum = "";     var stReturn = StructNew();     </cfscript>     <cfif isvalid("email", arguments.emailAddress)><!--- basic validation (possibly not good...

Find and kill a SQL query

The ColdFusion calls to external systems will just hang around FOREVER waiting for a reply, until the server just gives up! This is because like any good application software, it can't really be sure that it "should" be able to terminate any connection it is waiting for in case it is waiting for something really important (maybe a booking receipt, or credit card payment receipt!!). Clearly some will be outside your control, but when a dodgy SQL query has gone ape, you can always kill that on the database and release the ColdFusion thread and everything will return to normal. Find the session in SQL like so:  select sq.text,r.session_id,r.status,r.command,r.cpu_time,r.total_elapsed_time from sys.dm_exec_requests r cross apply sys.dm_exec_sql_text(sql_handle) AS sq Then issue the KILL command. KILL 59 -- where 59 is the value from session_id.

Railo vs ColdFusion cfqueryparam and SQL HashBtytes

While testing an application against Adobe ColdFusion vs Railo 4.2.1 ; everything went quite well except for a simple piece of inline SQL for an a legacy appication with a bit HashBytes encryption. Nothing too fancy there, just comparing Hashed String with an inputted string, like so:  .... where hashedkey =HashBytes('SHA1', <cfqueryparam cfsqltype="cf_sql_varchar" value="#variables.unhashedkey#">) Except... The input of HashBytes is a binary. Adobe CF, created the hashedkey (elsewhere) with a cfqueryparam type of  cf_sql_varchar but not cast/ converted as a binary. There was no cf_sql_nvarchar which was added in CF10,   Railo came back with a different results here running this code on each environment: <cfquery name="qryInteresting" datasource="datasource"> select hashbytes('SHA1', 'poodle') nocfqueryparam , hashbytes('SHA1', cast('poodle' as varchar(50) ) ) nocfqueryparamC...

Organizing SQL Procedures and Functions like Oracle Packages (ish)

Oracle's package syntax is a nice way of packaging sets of functions/ procedures etc, however when a package is updated, that brings everything down. If you have a cached JDBC connection, that causes even more problems as you have to recycle the connections. On SQL, there is no package, and thus you could end up with hundreds if not thousands of little procedures and functions. A good trick is to use schemas to organize them: this example will return 2 queries; could also use input output parameters create schema [myutils]; create procedure [ myutils ].[aFewQueries] @someid int output ,@someid2 int output as begin --  set nocount on; added to prevent extra result sets from interfering with SELECT statements. set nocount on; -- Insert statements for procedure here select * from table1 where id = @someid; select * from  table2_other where  id = @someid ;  select  @someid2  = 5; end go In ColdFusion you could neatly call this ...

MX Checking and Email Validation

Whilst encountering people inputting technically correct email address, but generally not correct (there is no gmail.com.au etc), was looking around for an MX validation, particularly important for eCommerce guest checkouts when receipt emails are just not arriving. Dominic Sayers example in PHP (ported in Java also) seems to be one of the top ones, but kept replying with invalid MX records (probably my fault) and it is written PHP, which didn't suit my needs, see https://code.google.com/p/isemail/ Also attempted this guys implementation in ColdFusion of the above one, but didn't quite work for me either:  https://gist.github.com/JamoCA/72cdcb77246ea0ee5820 When checking how the PHP was actually written; noticed a function called dns_get_record in PHP, haven't seen that one in ColdFusion, had a root round, found Pete Freitag example at http://www.petefreitag.com/item/487.cfm Modifed that slighlty for my own needs, using Google's Public DNS ; ended up with below (...

Session Variable Loss and Session Fixation in ColdFusion

ColdFusion Variable is undefined in Session For the proper explanation of Session Fixation and how a session is undefined see http://www.petefreitag.com/item/815.cfm Watch out for the version of Coldfusion you are running and the hot fixes as there are differences http://www.bennadel.com/blog/2050-changes-in-cflocation-onrequestend-behavior-in-coldfusion-9-s-application-cfc.htm Session Fixation Bug (it's back to the old sessions lost after cflocation which was either introduced as a bug or fixed in CFMX6 ) "A JVM property was added in case you want to completely switch off the fix for the Session Fixation issue ( Bug 86378) which prior to this security release changed Session behavior in some environments. Add the following JVM property -Dcoldfusion.session.protectfixation=false in the JVM Arguments for the Coldfusion Server." http://helpx.adobe.com/coldfusion/kb/security-hotfix-coldfusion-8-8.html Programmatically can be fixed using the below: <cf...