Managing ColdFusion Mappings through the BACK DOOR
Often when hosting a site somewhere, it can be a slow process to get a mapping created or modified. Then there are also those times when all you really need to be able to do is SEE them so you can verify paths and what not.
Using snippets harvested from google, I wrote myself a simple little MappingUtil.cfm page that I use to perform the tasks previously mentioned, and now i share it here with those who may be interested.
WARNING:
A few things you should think about before using this tool:
Okay, cautions out of the way, below is the code. It should be saved in a template name that matches the form action. Currently that is "mappingutil.cfm". If you wish to save it as a different name, be sure to edit the form action as well.
******************************** The Code ***********************************************************
Using snippets harvested from google, I wrote myself a simple little MappingUtil.cfm page that I use to perform the tasks previously mentioned, and now i share it here with those who may be interested.
WARNING:
A few things you should think about before using this tool:
- This code uses undocumented methods and is not supported by Adobe. It is not guaranteed to work against every version of ColdFusion server.
- Most of the time, yours isn't the only site living on a particular host server. This tool will allow you to see and manage ALL mappings, whether yours or not, therefore you must be very careful not to delete someone else's mapping.
- Performing your own back door mapping management without the admin's knowledge could get you kicked off of your current host.
- Never drink and manage mappings at the same time.
Okay, cautions out of the way, below is the code. It should be saved in a template name that matches the form action. Currently that is "mappingutil.cfm". If you wish to save it as a different name, be sure to edit the form action as well.
******************************** The Code ***********************************************************
<cfparam name="url.action" default="false">
<cfparam name="form.mapping" default="">
<cfset factory=createObject("java","coldfusion.server.ServiceFactory")>
<cfset mappings = factory.runtimeService.getMappings()>
<cfset actionmessage = "">
<cfif url.action>
<cfif form.mapping IS NOT "">
<cfloop index="m" list="#form.mapping#">
<cfset tmp= structdelete(mappings,m)>
</cfloop>
<cfset actionmessage = "<h3>Items Deleted.</h3>">
</cfif>
<cfif form.mapname IS NOT "" and form.mappath IS NOT "">
<cfset mappings[form.mapname] = form.mappath>
<cfset actionmessage = actionmessage & "<h3>Mapping added.</h3>">
</cfif>
</cfif>
<cfoutput>
#actionmessage#
<h2>Mapping Admin</h2>
<form action="mappingutil.cfm?action=true" method="post">
<table cellpadding="5" cellspacing="5" bgcolor="##FFFFFF">
<tr><th>Delete</th><th colspan="2" align="center">Mapping</th></tr>
<cfloop collection="#mappings#" item="thismapping">
<tr>
<td>
<input type="checkbox" name="mapping" value="#thismapping#">
</td>
<td>
<strong>#thismapping#</strong>
</td>
<td>
(#mappings[thismapping]#)
</td>
</tr>
</cfloop>
<tr><td colspan="3">Enter new mapping: name<input type="text" value="" name="mapname" size="15"> path<input type="text" name="mappath" value="#expandpath(".")#" size="45"></td></tr>
<tr><td colspan="3" align="center"><input type="submit" value="Save Changes"></td></tr>
</table>
</form>
</cfoutput>
<cfparam name="form.mapping" default="">
<cfset factory=createObject("java","coldfusion.server.ServiceFactory")>
<cfset mappings = factory.runtimeService.getMappings()>
<cfset actionmessage = "">
<cfif url.action>
<cfif form.mapping IS NOT "">
<cfloop index="m" list="#form.mapping#">
<cfset tmp= structdelete(mappings,m)>
</cfloop>
<cfset actionmessage = "<h3>Items Deleted.</h3>">
</cfif>
<cfif form.mapname IS NOT "" and form.mappath IS NOT "">
<cfset mappings[form.mapname] = form.mappath>
<cfset actionmessage = actionmessage & "<h3>Mapping added.</h3>">
</cfif>
</cfif>
<cfoutput>
#actionmessage#
<h2>Mapping Admin</h2>
<form action="mappingutil.cfm?action=true" method="post">
<table cellpadding="5" cellspacing="5" bgcolor="##FFFFFF">
<tr><th>Delete</th><th colspan="2" align="center">Mapping</th></tr>
<cfloop collection="#mappings#" item="thismapping">
<tr>
<td>
<input type="checkbox" name="mapping" value="#thismapping#">
</td>
<td>
<strong>#thismapping#</strong>
</td>
<td>
(#mappings[thismapping]#)
</td>
</tr>
</cfloop>
<tr><td colspan="3">Enter new mapping: name<input type="text" value="" name="mapname" size="15"> path<input type="text" name="mappath" value="#expandpath(".")#" size="45"></td></tr>
<tr><td colspan="3" align="center"><input type="submit" value="Save Changes"></td></tr>
</table>
</form>
</cfoutput>
Subscription Options
You are not logged in, so your subscription status for this entry is unknown. You can login or register here.
Re: Managing ColdFusion Mappings through the BACK DOOR
Nice work Doug. Just one small pointer, the action "mappingutil.cfm?action=true" should probably say "#cgi.script_name#?action=true" instead so I can name the file whatever I want.
Posted by Boyan on September 21, 2007 at 4:20 PM
Re: Managing ColdFusion Mappings through the BACK DOOR
man this worked. had no problems running this on a CF8 local developer and standard server versions. wow!
Posted by scott welker on February 27, 2009 at 2:40 PM

