Skip to content

Instantly share code, notes, and snippets.

@brucekirkpatrick
Last active December 27, 2015 07:09
Show Gist options
  • Save brucekirkpatrick/7286593 to your computer and use it in GitHub Desktop.
Save brucekirkpatrick/7286593 to your computer and use it in GitHub Desktop.
CFML UDF to output the railo 4+ implicit variables debug log as a table at the end of your request.
<cffunction name="getImplicitVariableAccessAsHTMLTable">
<cfargument name="railoWebAdminPassword" type="string" required="yes">
<cfscript>
var uniqueStruct={};
var ts=0;
var q=0;
var output=0;
var count=0;
var jsoutput=0;
admin action="getDebug" type="web" password="#arguments.railoWebAdminPassword#" returnVariable="ts";
if(not ts.implicitAccess){
return "";
}
admin action="getDebugData" returnVariable="q";
savecontent variable="output"{
writeoutput('
<style type="text/css">
/* <![CDATA[ */
.implicit-variable-table-list {
border: 1px solid ##999999 !important;
padding: 0px;
background-color: ##FFFFFF !important;
}
.implicit-variable-table-list td {
padding: 5px;
}
.implicit-variable-table-list th, .implicit-variable-table-list-header, th {
padding: 5px;
text-align:left;
font-weight: bold !important;
background-color: ##113355 !important;
color: ##FFFFFF !important;
white-space: nowrap;
vertical-align: top;
}
/* ]]> */
</style>
<table style="border-spacing:0px;" class="implicit-variable-table-list">
<tr><td colspan="5" style="font-weight:bold; color:##FFF; background-color:##113355;">Implicit Variable Access Detected.</td></tr>
<tr><th>Template</th><th>Line</th><th>Scope</th><th>Count</th><th>Name</th></tr>');
for(var row in q.implicitAccess){
if(row.scope NEQ "thread" or row.name NEQ "cfthread"){
count++;
uniqueStruct[row.template][row.scope][row.name]=true;
writeoutput('<tr><td>'&row.template&'</td><td>'&row.line&'</td><td>'&row.scope&'</td><td>'&row.count&'</td><td>'&row.name&'</td></tr>');
}
}
writeoutput('</table><br />');
savecontent variable="jsoutput"{
for(var i in uniqueStruct){
writeoutput(i&chr(10));
for(var i2 in uniqueStruct[i]){
writeoutput(i2&chr(10));
for(var i3 in uniqueStruct[i][i2]){
writeoutput('var '&i3&'=0;'&chr(10));
}
writeoutput(chr(10));
}
}
}
writeoutput('<textarea id="zScopeDebugTextArea99" cols="100" rows="10"></textarea><script type="text/javascript">/* <![CDATA[ */document.getElementById("zScopeDebugTextArea99").value="'&jsStringFormat(jsoutput)&'";/* ]]> */</script>');
}
if(not count){
return "";
}
return output;
</cfscript>
</cffunction>
<cfscript>
// make sure Railo web admin debugging is enabled with the "implicit variable access" checkbox checked before running this code.
variables.test=true;
structdelete(local, 'test');
writeoutput(test); // cause an implicit variable access intentionally.
// make sure to update the railoWebAdminPassword below with your actual password.
// It would be best to put this function at the bottom of the application.cfc onAbort and onError functions. Also add before any cflocation tag.
var output=getImplicitVariableAccessAsHTMLTable("railoWebAdminPassword");
writeoutput(output);
request.zos.isImplicitScopeCheckEnabled=false;
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment