Conflicting mapping for two ColdFusion Applications - coldfusion

I've spent over a day now trying to resolve an issue where two applications use the same relative paths but are under a different "root", and this causes the wrong code base to be accessed for one of the applications.
These are my roots to the two Applications:
\www\Clients\
\www\Other\Clients\
Structure
..www
....Clients
......Application.cfc
....Other
......Clients
........Application.cfc
In both Applications there is code that references the relative path (e.g., /clients/content/login.cfm)
I noticed that the ColdFusion Administrator has a Mappings section where the first mapping has a logical path / mapped to the directory path D:/www/.
This works well for the first application since the clients folder is found directly under the www folder, however the second application doesn't work correctly as it too adheres to the same mapping. Therefore instead of searching for /clients/content/login.cfm under the Others folder, it searches yet again under the www folder.
Note: Both applications have a different Application.Name so they are indeed segregated.
The biggest red flag is that we don't experience this issue on our older ColdFusion 9 server, however we are experiencing this on the newer ColdFusion 2016 server.
Sifting through ColdFusion Administrator, I can't seem to find any other settings which could affect the underlying root per Application which could take precedence over the Mappings.
Is there a setting I missed? Was there a drastic change regarding relative paths or mappings between ColdFusion 9 and ColdFusion 2016?

Sifting through ColdFusion Administrator, I can't seem to find any
other settings which could affect the underlying root per Application
which could take precedence over the Mappings.
Solution: Use application specific mappings.
<cfset this.mappings["/Clients"] = GetDirectoryFromPath(GetCurrentTemplatePath())>
Source

Related

ColdFusion 2016: cfinclude dynamic template name; occasional error

Good day -
My work group upgraded from CF10 to CF2016. We have finished 2 of the 3 servers that run the application behind a load balancer.
Since the two servers have been upgraded, we get an occasional (<<1%) error on <cfinclude> statements:
The process cannot access the file because it is being used by another process
The included files are different each time, but they have the same characteristic: the names are dynamically generated in the cfinclude tag. For example:
<cfinclude template="#fileManager.getFile('appl1')#">
where #fileManager.getFile('appl1')# simply returns a string path to a CFM file. The file definitely exists, and it is not e.g. being modified by a programmer or any other (known) process. The files themselves are generally just simple index.cfm files in directories that haven't been touched in a year.
This only happens on dynamically named templates in <cfinclude>, never static template names.
Here are the cache settings on the server. Please note that the settings are the same on the server that doesn't experience this problem (the CF10 server)
Any ideas what can cause this random, fleeting error? I can not establish any pattern other than CF2016.

Locating Specific Files on a ColdFusion Server

So I've began working with .cfm files recently at work, currently my assignment is to modify and update webpages to be more suited to mobile devices and tablets. Now, being relatively new to ColdFusion, I've been having a bit of trouble with how multiple .cfm files are used within a server to create a single webpage. Because of this, I've had issues with finding where specific sections of HTML are located, be it something as where a simple tag is, or where a call to another .cfm, javascript, or .css file may be. Is there anyway to find the origin of certain code without having to skim through hundreds of different files?
If you are working on your code on a local webserver on your computer (i.e. not a production site) then you can enable ColdFusion's debugging output.
Documentation for the ColdFusion Administrator debugging options are here: ColdFusion Administrator Debugging
You will want to enable Enable Request Debugging Output and turn on Report Execution Times. When you browse to the page, ColdFusion will give you a list of all files that ColdFusion used to render that page (with how long each file took) appended to the bottom of the page.
Otherwise, any good IDE/Editor (CFBuilder, SublimeText, NotePad++ etc) will be able to search across files.
I would suggest downloading the code from your server to a local drive. From there you can search using an IDE (ColdFusion Builder, Dreamweaver, etc) or a good text editor that can search multiple files at once. I personally use ColdFusion Builder 3 and Notepad++.
Multiple cfm files are put together into a single page usually by using the cfinclude tag, so that would be a good starting point for your search. There are other methods to include different pages into a single page but cfinclude is probably the most common one. BUT, if the programmer used cfscript instead of cfml, look for the include function instead.
Adobe documentation on the cfinclude tag can be found at https://wikidocs.adobe.com/wiki/display/coldfusionen/cfinclude.

How To Change The Default Circuit

I am new to a company that is using fusebox. We need to run two versions of the application on the same box, so we duplicated all of the ColdFusion mappings from, say, "mapping" to "mappingD" in order to indicate these are the ones on the D drive.
All well and good.
In the D drive version of the app, though, while most of the settings have been changed to point to "mappedD", Fusebox keeps rewriting the parsed files to use "mapped" and I cannot for the life of me figure out where the heck to change the setting in Fusebox so it uses "mappedD" from now on!
We are using Fusebox with ColdSpring (which also has a new mapping of coldspringD) if that helps.

How to get paths to user desktops from a service?

I need to enumerate paths to desktop folders for all users on a local Windows system from a service application. The catch is that some users may not be logged in at the time. So is there any API, or some other method to do that?
EDIT1: For those who didn't read the first paragraph let me repeat -- I do not have a token to a user account, a user may not be logged in at the time.
EDIT2: I need this to remove a shortcut from user desktops before a feature supported by my application is turned off, or the app is uninstalled.
Here's the best method I was able to come up so far. So I'd appreciate if someone with a non-English installation of Windows could check this for me?
(I'm posting just a pseudo-code for brevity.)
1 - All of the steps below are done from a local service application.
2 - To get paths to all user profiles enumerate subfolders in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList key and read ProfileImagePath value from them. It will give profile paths for each user account.
3 - To get the folder name for the desktop, read the Desktop value from the HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders key from the service app (yes, I know HKCU sounds strange, but it worked for me.) After that get the path for the %USERPROFILE% environment variable, using environment variable APIs. So you'll get two paths, something like this:
C:\Windows\system32\config\systemprofile\Desktop
and
C:\Windows\system32\config\systemprofile
Then simply isolate the 2nd string from the 1st, using case-insensitive comparison, and you'll get the folder name for the desktop, (i.e. "\Desktop" in this case.)
4 - Add the desktop folder to the path obtained in step 2 to produce the full path to that user's desktop folder.
From userenv.h : GetProfilesDirectory (win2k+, iirc)
msdn.microsoft.com/en-us/library/windows/desktop/bb762278(v=vs.85).aspx
Use this to find the directory containing all the local user account profile directories.
To find the desktop folder:
Shlobj.h : SHGetKnownFolderPath (vista+)
msdn.microsoft.com/en-us/library/windows/desktop/bb762188(v=vs.85).aspx
You'll need FOLDERID_Desktop as the known-folder id. This symbol is declared in Knownfolders.h
msdn.microsoft.com/en-us/library/windows/desktop/dd378457(v=vs.85).aspx
Using these, you might get closer to what you want without directly reading the registry. Of course this belies any elegant way of enumerating the users aside from inferring from the folder list within the
GetProfilesDirectory. Perhaps there is a more api appropriate way to enumerate the local users.
Secondly, and this depends on the purpose of your service, but perhaps by working with the 'allusers' profile, instead of each individually you won't need to know the current list of local users.

Best practices for storing settings

I have a fairly large C++ application (on Windows, no other platforms planned), which currently stores all settings (even some kind of addresses) in the Windows registry.
Sometimes this is inconvenient, because the users have difficulties changing entries in the registry. I would like to have settings versioned, so settings always match the current code. At the moment we version reg-files, but you are never sure, if all reg-files have been added on the target machines. With C# you can define default values in app.config, but don't overwrite existing settings. I don't know, if such a mechanism or library exists for C++.
I would like to have the following "features":
Settings can be versioned
Simple update on target machines (can be done by user)
Ensure that on update only new settings are added and no existing settings are overwritten with default values
Simple change of settings for user
Same workflow under Win XP and Win 7
As far as I see it, there are 3 possibilities to store settings on Windows:
Registry
Ini file
XML file
Only one application of our suite uses Qt at the moment, but Boost would be available.
For addresses, we will put them in some kind of XML address book, but for the other settings we are not sure, what's the best practise.
As comments mention, tree-based key/value structures are a common solution and libraries are easy to find.
Boost's property_tree is an excellent choice, as it is well-tested and can easily be exported as XML or JSON
Regarding your requirements:
Settings can be versioned
Yes! Make "version" a top-level key. Make it easily comparable with other versions.
You can also categorize your settings into various tree nodes and give each node a version.
Simple update on target machines (can be done by user)
Have your application do that when it runs. See below.
Ensure that on update only new settings are added and no existing settings are overwritten with default values
Simple change of settings for user
Same workflow under Win XP and Win 7
As settings change from one version to another, usually these changes fall into three categories. New properties are needed, old settings are abandoned, and some settings change their expected format. E.g. "32 Fahrenheit" becomes "0 Celsius"
When your application initializes:
Load the existing configuration file, regardless of its version.
If the version does not match what's current for the application:
Create a new blank property tree for the new configuration
For each node in the tree, have a set of expected property names, and a function pointer or similar to get this setting if it's absent in the old file's tree. If a setting changes its format, give it a new name.
Search for each setting in the old tree, copying it if it's found, and using the result of the supplied function if it's not.
Save your new settings file.
Your "missing setting" functions can:
Return a constant default value.
Query the tree for a different setting and convert it (with a default value if the old setting isn't found either)
Ask the user