Click here to Skip to main content
15,884,007 members
Articles / Web Development / HTML
Tip/Trick

Configuration File Formatting Oddities: A Short Case Study

Rate me:
Please Sign up or sign in to vote.
3.67/5 (2 votes)
5 Jan 2018CPOL3 min read 6.5K   1   1
URL Encoded Text is URL Encoded Text, wherever you find it, even if it happens to be in and old school Windows INI file.

Introduction

When I discovered that WinSCP wasn’t showing me what I expected to see, I decided to see whether exporting the known good configuration from the old machine would be worth the effort. Anticipating that the configuration included the bookmarks that I saved, half of which (the bookmarks to local directories, all of which moved to a dedicated data volume on the new machine) would need attention before I import them into the copy of WinSCP that’s installed there, I opened the export in my all purpose text editor. I was astonished to see something that I’ve never seen in a Windows configuration file; the Windows paths were URL encoded. The Unix paths weren’t subjected to that indignity.

Background

Fortunately, in this age of online apps for dealing with such matters, I knew exactly where to turn, https://www.urldecoder.org/, which has served me well for quite some time, such as decoding the query strings returned by the Salesforce OAuth API. Since encoded text is encoded text, regardless of the context in which it exists, I used the decoder tab on the application to decode the strings (all in one go), performed a quick find and replace to point them to the corresponding locations on the new machine, then used the encoder tab to encode them before I pasted the updated strings into the configuration file.

Using the Code

Converting the encoded bookmarks was a relatively straightforward process, as shown in the four listings that follow.

0=C:%5CUsers%5CDAVE%5CDocuments%5CPraesidium%5CBuilding%5CPCH%5CAWS_LOGS%5C%2A.%2A
1=C:%5CUsers%5CDAVE%5CDocuments%5CPraesidium%5CBuilding%5CPCH%5CAWS_Tests%5CLoginError%5C%2A.%2A
2=C:%5CUsers%5CDAVE%5CDocuments%5CPraesidium%5CBuilding%5CPCH%5CAWS_Tests%5C%2A.%2A
3=C:%5CUsers%5CDAVE%5CDocuments%5CPraesidium%5CBuilding%5CPCH%5CAWS_Web%5Cetc%5Chttpd%5Cconf.d%5C%2A.%2A
4=C:%5CUsers%5CDAVE%5CDocuments%5CPraesidium%5CBuilding%5CPCH%5CAWS_Web%5Cetc%5C%2A.%2A
5=C:%5CUsers%5CDAVE%5CDocuments%5CPraesidium%5CBuilding%5CPCH%5COAuth%5CAWS_Tests%5C%2A.%2A

Listing 1 shows the WinSCP Configuration exported from ENIGMA, the old machine, which I pasted into the Decode tab of the online encoder/decoder app. Listing 2 shows the decoded text.

0=C:\Users\DAVE\Documents\Praesidium\Building\PCH\AWS_LOGS\*.*
1=C:\Users\DAVE\Documents\Praesidium\Building\PCH\AWS_Tests\LoginError\*.*
2=C:\Users\DAVE\Documents\Praesidium\Building\PCH\AWS_Tests\*.*
3=C:\Users\DAVE\Documents\Praesidium\Building\PCH\AWS_Web\etc\httpd\conf.d\*.*
4=C:\Users\DAVE\Documents\Praesidium\Building\PCH\AWS_Web\etc\*.*
5=C:\Users\DAVE\Documents\Praesidium\Building\PCH\OAuth\AWS_Tests\*.*

Listing 2 shows the decoded WinSCP Configuration from ENIGMA, the old machine:, which I copied  from the decoder output window into my text editor. This text was generated from the text shown in Listing 1 by applying the Decode button in the online app, causing the text to appear in the lower text area of the decoder form.

0=F:\Praesidium\Building\PCH\AWS_LOGS\*.*
1=F:\Praesidium\Building\PCH\AWS_Tests\LoginError\*.*
2=F:\Praesidium\Building\PCH\AWS_Tests\*.*
3=F:\Praesidium\Building\PCH\AWS_Web\etc\httpd\conf.d\*.*
4=F:\Praesidium\Building\PCH\AWS_Web\etc\*.*
5=F:\Praesidium\Building\PCH\OAuth\AWS_Tests\*.*

Listing 3 shows the amended WinSCP Configuration for ABACUS, the new machine, which I created by applying a simple find and replace to the five lines shown in Listing 2. This text I pasted into the upper (input) box of the Encoder tab on the online app. Please see the comment in the Points of Interest section that follows.

0=F:%5CPraesidium%5CBuilding%5CPCH%5CAWS_LOGS%5C%2A.%2A
1=F:A%5CPraesidium%5CBuilding%5CPCH%5CAWS_Tests%5CLoginError%5C%2A.%2A
2=F:A%5CPraesidium%5CBuilding%5CPCH%5CAWS_Tests%5C%2A.%2A
3=F:A%5CPraesidium%5CBuilding%5CPCH%5CAWS_Web%5Cetc%5Chttpd%5Cconf.d%5C%2A.%2A
4=F:A%5CPraesidium%5CBuilding%5CPCH%5CAWS_Web%5Cetc%5C%2A.%2A
5=F:A%5CPraesidium%5CBuilding%5CPCH%5COAuth%5CAWS_Tests%5C%2A.%2A

Listing 4 shows the encoded WinSCP Configuration for ABACUS, the new machine, which I copied from the output (lower) text area in the decoder form of the online app, where it appeared after I pasted the text shown in Listing 3 into the input (upper) text area, then pressed the Encode button. This I copied into the configuration file, replacing the text shown in Listing 1. Please see the comment in the Points of Interest section that follows.

Points of Interest

Encoding took two passes, since the first pass, in which I pasted the entire block of text into the input text area of the encoder, produced a single continuous line of output; the line breaks had been stripped. Consequently, it required another pass, in which all but the first four characters of each line, which were not encoded in the configuration that I exported from the old machine, got encoded and pasted back into the text editor.

Neither encoding, nor decoding is technically difficult; they are straightforward one for one text replacements, easily driven by a bidirectional lookup table. Nevertheless, the work is tedious to get right, and simple to program, even in old school JavaScript, of the sort that first appeared in the Netscape Navigator Web browser. It wouldn't surprise me to learn that lots of up and coming programmers are assigned to write such an encoder/decoder application as a school homework assignment.

Nevertheless, it demonstrates the value that lies just a quick Google search away on the World Wide Web of online tools and other resources.

History

Friday, 05 January 2018 was the initial release date.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
I deliver robust, clean, adaptable, future-ready applications that are properly documented for users and maintainers. I have deep knowledge in multiple technologies and broad familiarity with computer and software technologies of yesterday, today, and tomorrow.

While it isn't perceived as sexy, my focus has always been the back end of the application stack, where data arrives from a multitude of sources, and is converted into reports that express my interpretation of The Fundamental Principle of Tabular Reporting, and are the most visible aspect of the system to senior executives who approve the projects and sign the checks.

While I can design a front end, I prefer to work at the back end, getting data into the system from outside sources, such as other computers, electronic sensors, and so forth, and getting it out of the system, as reports to IDENTIFY and SOLVE problems.

When presented with a problem, I focus on identifying and solving the root problem for the long term.

Specialties: Design: Relational data base design, focusing on reporting; organization and presentation of large document collections such as MSDS libraries

Development: Powerful, imaginative utility programs and scripts for automated systems management and maintenance

Industries: Property management, Employee Health and Safety, Services

Languages: C#, C++, C, Python, VBA, Visual Basic, Perl, WinBatch, SQL, XML, HTML, Javascript

Outside Interests: Great music (mostly, but by no means limited to, classical), viewing and photographing sunsets and clouds, traveling by car on small country roads, attending museum exhibits (fine art, history, science, technology), long walks, especially where there is little or no motor traffic, reading, especially nonfiction and thoughtfully written, thought provoking science fiction

Comments and Discussions

 
QuestionMessage Closed Pin
27-Dec-20 20:44
Member 1502849627-Dec-20 20:44 
QuestionI solved it a different way Pin
Member 133016798-Jan-18 10:04
Member 133016798-Jan-18 10:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.