Evaluating Coldfusion directory path for file existence

I've been working on a script for a couple of weeks tweaking it as need be to track CGI.script_PATH and CGI.REFERER on an older coldfusion install which has over 500 .cfc and .cfm pages. I just hit a snag in my code. It doesn't capture a page name in the CGI.Referer variable when the referer is a folder. I'm sure it has something to do with Coldfusion automatically looking for an index.cfm even when the path doesn't include an actual file name.

How can I write an addition to my script where if there is no .cfm in the CGI.Referer, it can search the directory and capture the default file set to load or at least search for an occurrence of index.cfm or default.cfm?

Here is a block of code handling the referer element:

   <!---Variable declared and set to empty--->
    <cfset referer_path_and_file = "">
    <cfset referer_path = "">
    <cfset referer_file_name = "">
    <cfset script_path_and_file = "">
    <cfset script_path = "">
    <cfset script_file_name = "">

    <cfif cgi.HTTP_REFERER neq ''>
      <!--- all of this will fail if there is no referer, for instance, if they bookmark the page --->
      <!--- cgi.HTTP_REFERER may contain URL parameters, so let's strip those --->
      <cfset referer_path_and_file = ListFirst(CGI.HTTP_REFERER, "?")>
      <!--- now let's get just the path, stripping out the web server info --->
      <cfset referer_path = ListDeleteAt(CGI.HTTP_REFERER, ListLen(CGI.HTTP_REFERER, "/"), "/")>
      <cfset referer_path = ReplaceNoCase(referer_path, "https", "", "All")>
      <cfset referer_path = ReplaceNoCase(referer_path, "http", "", "All")>
      <cfset referer_path = ReplaceNoCase(referer_path, "://machine1.fss.com", "", "All")>
      <cfset referer_path = ReplaceNoCase(referer_path, "://www_dev.fss.com", "", "All")>
      <cfset referer_path = ReplaceNoCase(referer_path, "://www.fss.com", "", "All")>
      <cfset referer_path = ReplaceNoCase(referer_path, "://10.11.2.60/", "", "All")>
      <cfset referer_path = referer_path & "/">
      <cfset referer_path = ReplaceNoCase(referer_path, "/", "", "All")>
      <!--- now let's remove everything but the file name --->
      <cfset referer_file_name = ListLast(referer_path_and_file, "/")>
      <!--- and that leaves us with these variables set --->
     <!--- referer_path_and_file = "#referer_path_and_file#"<br />
      referer_path = "#referer_path#"<br />
      referer_file_name = "#referer_file_name#"<br />
      <br />--->
    </cfif>
<!---Directory Stripping And Modifier Block Goes Here--->
<!---Set CGI System Variables--->
<cfset currentHeader = CGI.HTTP_REFERER >
<cfset currentScriptPage = CGI.SCRIPT_NAME > 
<!---Set currentScriptPage as command line directory string and delcare new variable "reverseScriptPage"--->
<cfset reverseScriptPage = ReReplace(#currentScriptPage#, "/", "","ALL")>
<!---Set reverseScriptPage value as newly format command line directory structure--->
<cfset newScriptPage = ListSetAt(#reverseScriptPage#, 1, "#reverseScriptPage#") >

The code just strips the CGI script and referer variables of their http web references and then strips the directory structure portion and inserts the .cfm file name and original directory structure into the DB table, but not before reversing the / characters to because they want to be able to setup a script which will loop through the table and see something like "admincontrols" and auto create those directories, then copy the example.cfm page into that directory. The aim is to 1.) determine which of the 500 cfc/cfm files are still used in the application, then copy them and their directory structure to a new location, and redesign those files in a new technology that isn't Coldfusion.

Update: I'm running into an issue with my code. When I test it, it works well, truncating the http domain portion. However once its operating live under the web server, it doesn't truncate the url despite there being a ReplaceNoCase method to do so:

Under the web root in the wwwroot root, it works well giving this output: refererPage: testFiles.cfm refererPath = testCodesMVC

Under the live site I get this: refererPage: client_display refererPath: **:dev.fss.comadmin_area** despite having this line in my code:

Any idea why?


If your cgi.http_referrer variable does not not contain .cfm, you can use the DirectoryExists function on your referer_path variable. If it returns true, you can use the DirectoryList function or cfdirectory tag to search for an occurrence of index.cfm or default.cfm.


they may have this going through a framework (like a model view controller). Without knowing more about the URL structures and the naming conventions.

And without knowing more I would say you are dealing with dynamic content (especially if it is going through index.cfm). Even in an engine with 500 pages, there is a unique identifier and that should be your target not a file. So we may assume there are no files at all and we are just calling parts and pieces from here and there to make a page based on your URL querystring, local variables and/or form variables.

So tables are your friends. Examine your URL structure, try to break down the parameters, search the code base for those parameters and once you have located the area that builds the pages then somewhere there set your tracking tools (a bit higher up stream in the page request stream).

Maybe with some code snippets we could give you a more precise answer but for now this should at least get you looking at your code base for clues.

链接地址: http://www.djcxy.com/p/31218.html

上一篇: 使用Coldfusion发布xml API调用(用于Intuit)

下一篇: 评估文件存在的Coldfusion目录路径