Enabling SSL on the ColdFusion 8 built-in web server

This tutorial assumes default install location for ColdFusion 8 on Windows XP.

The first thing you need to do is to create a keystore. This can be done with the keytool utility. I used the one that is part of ColdFusion 8.

Open a command prompt.

Execute the following command:
cd C:\ColdFusion8\runtime\jre\bin

Create the keystore with this command:
keytool -genkey -dname "cn=127.0.0.1, ou=CF, o=cfchimp, L=Decatur, ST=GA, C=US" -keyalg rsa -keystore mykey

If you have previously configured a keystore you might run into this error:
keytool error: java.lang.Exception: Key pair not generated, alias already exists

If you got the “already exists” error run this command to list the keystores:
keytool -list -v | more

If you got the “already exists” error run this command to delete the keystore:
keytool -delete -alias mykey

If you got the “already exists” error re-run the command to create the keystore.

Enter in a password when prompted (2 times)

Move the keystore file (mykey) to C:\ColdFusion8\runtime\lib\

Edit the config file C:\ColdFusion8\runtime\servers\coldfusion\SERVER-INF\jrun.xml with an xml editor of choice. This file is VERY sensitive so be sure to not screw up the syntax of it. You should probably make a copy of it before you edit it.


<!-- Uncomment this service to use SSL with the JRun Web Server
Note that you MUST create your own keystore before using this service -->
<service class="jrun.servlet.http.SSLService" name="SSLService">
<attribute name="enabled">true </attribute>
<attribute name="interface">* </attribute>
<attribute name="port">9100 </attribute>
<attribute name="keyStore">{jrun.rootdir}/lib/mykey </attribute>
<attribute name="keyStorePassword">mypassword </attribute>
<attribute name="trustStore">{jrun.rootdir}/lib/trustStore </attribute>
<attribute name="socketFactoryName">jrun.servlet.http.JRunSSLServerSocketFactory </attribute>
</service>

Restart the ColdFusion8 application service.

Create a test page in the ColdFusion 8 wwwroot and opening it in a web browser using: https://127.0.0.1:9100/testpage.cfm

You should be good to go.

REFERENCES:
For some keytool commands: http://www.instantssl.com/ssl-certificate-support/server_faq/ssl-server-certificate-java.html
Adobe instructions: http://www.adobe.com/support/coldfusion/using/ssl_with_cf_web_server/ssl_with_cf_web_server03.html

Save, Format, View Dreamweaver Search Results

For as long as I can remember I have wanted a formatted, printable report of Dreamweaver search results. Since Dreamweaver’s “Save Report” of the results pane is an xml file I have always been too lazy to pursue it. I have finally put forth a little effort to generate one using XSLT. XSLT stands for XSL Transformations. XSLT “transforms” XML documents into other formats, like XHTML.

Download the search_results.xsl file here. Unzip it. It is the file that will perform the styling of your XML results file. Hang on to it for now.

Open Dreamweaver’s “Find and Replace” window (Command + F). Enter your search criteria and click “Find All”.

.DW Finder Window

In the “Results” pane click the save icon.
DW Results Pane

You can accept Dreamweaver’s default file name or give the file a name related to your search. I’ll call mine Post.xml. Save it in the same directory where you put search_results.xsl. Open Post.xml (or whatever you called it) with Dreamweaver and add the one line of code annotated below with the red arrow.

XSL code

Now open your Post.xml file with a web browser such as Safari. You should see your search report formatted as follows:

Post.xml

You now have a nice printable report complete with results total.

*** UPDATED 2/27/2015 ***

As a security measure Chrome blocks access to local files. You must open Chrome from the command line with a flag to allow access to local files.

Follow these steps to allow local file access in Chrome on the Mac:

  • If you have Chrome open, close it
  • Open a terminal window
  • Execute the command:
    open /Applications/Google\ Chrome.app --args --allow-file-access-from-files
  • Once Chrome opens select ‘File > Open File’ and browse to your local xml file
  • Voilà

DOS .bat files (What I learned from writing a subversion backup script)

Comments
REM Comment Style 1
:: Comment Style 2

Set a variable
SET myCat=Dante
Output a variable
ECHO %myCat%
If then Else statement
if %yCat%== "Dante" (ECHO MY CAT) ELSE (ECHO NOT MY CAT)
Output a command’s result to a file
dir >> log.txt
Split a command across 2 lines (use ^ at the end of the line)
ECHO This is line one and ^
this is line 2.

Two commands on 1 line (separate with &)
echo command 1 & echo command2
List only directory names and no info
dir /b /ad
For-in-do (For every item do something)
FOR /F %%G IN ('dir /b /ad %repodir%') DO ECHO %%G

Virtual hosts with MAMP on Leopard

Assumptions (Kind of major assumptions):

  • You are running Leopard (and therefore cannot use “Netinfo Manager” to edit your hosts).
  • You already have MAMP up and running and MAMP is using the Apache config file located here: /Applications/MAMP/conf/appache/httpd.conf
  1. Set up a directory for your dev website. I created: /Applications/MAMP/htdocs/csimmons
  2. Create a “host” for your site. In Leopard this will require you to edit the hosts file manually. Be sure to use sudo or you will not be able to save the file. Type the following and enter the root password when prompted:
    $ sudo pico /etc/hosts
    Add the following at the bottom

    # VIRTUAL HOST START
    127.0.0.1 csimmons.dev
    # VIRTUAL HOST STOP

    CTRL+O to write the file (then hit ENTER)
    CTRL+X to exit pico
  3. Flush the DNS cache
    $ dscacheutil -flushcache
  4. Edit the Apache config file:
    $ pico /Applications/MAMP/conf/apache/httpd.confChange the following:
    OLD:
    ServerName localhost:8888
    NEW:
    ServerName 127.0.0.1:8888

    Continue to the very bottom of the file (use CTRL+V to page down faster) and you will find “Section 3: Virtual Hosts”. Add the following at the very end:

    NameVirtualHost 127.0.0.1
    <virtualhost 127.0.0.1>
    DocumentRoot /Applications/MAMP/htdocs
    ServerName localhost
    </virtualhost>
    # DEVELOPMENT HOSTS START
    <virtualhost 127.0.0.1>
    DocumentRoot /Users/username/Sites/csimmons
    ServerName csimmons.dev
    </virtualhost>
    # DEVELOPMENT HOSTS STOP

    CTRL+O to write the file (then hit ENTER)
    CTRL+X to exit pico

  5. Restart the MAMP servers. I just click “Stop Servers” and then “Start Servers” on the MAMP widget.
  6. Try it out. Point your browser to the following (no www in the address and don’t forget the port[8888]): http://csimmons.dev:8888
  7. Rinse. Repeat for each of your dev sites. Multiple sites would look like this:

    hosts file:

    # VIRTUAL HOST START
    127.0.0.1 csimmons.dev
    127.0.0.1 site2.dev
    # VIRTUAL HOST STOP

    Apache config file:

    # DEVELOPMENT HOSTS START
    <virtualhost 127.0.0.1>
    DocumentRoot /Users/username/Sites/site2
    ServerName csimmons.dev
    </virtualhost>
    <virtualhost 127.0.0.1>
    DocumentRoot /Users/username/Sites/site2
    ServerName site2.dev
    </virtualhost>
    # DEVELOPMENT HOSTS STOP

Subversion backup of multiple repositories via DOS .bat file

I recently had to implement Subversion at work to manage our source code. Part of that implementation was coming up with a way to automate the backup process. Since developers could be accessing code repositories at any time there is a special command (called hotcopy) in Subversion for copying a repository to another location, which you can then backup to disk, tape, etc.

I started out just doing a simple DOS .bat file to run the hotcopy. My plan was to schedule this to run in the Windows scheduler prior to the nightly backup. As I started working on the script though I found myself trying to improve it to be as generic and hands off as possible. I also wanted to backup multiple repositories.

Here are some “features” of the script:

  • It will hotcopy multiple repositories in a specified directory.
  • It can be run attended or unattended
  • It has some basic log functionality

Here is a look at the actual hotcopy command in the .bat file:
ECHO Starting SVN backup for %%G... >> %repolog% & ^
svnadmin hotcopy %repodir%%%G %repodirhot%%%G --clean-logs >> %repolog% & ^

Download it here and rename it from svn_backup.txt to svn_backup.bat.

A few SQL queries

I had to do some basic analysis of email addresses at my company the other day.  Here are a few useful SQL queries.

Show 10 records with the most data in field ’email’ (10 longest email addresses)

SELECT TOP 10 email, LEN(email) AS fieldLength
FROM person
ORDER BY fieldLength DESC

Count all records with field ’email’ over 20 chars

SELECT COUNT(*) AS emailOver20
FROM person
WHERE LEN(email) > 20

Display the average length of data (in characters) of field ’email’

SELECT AVG(LEN(email)) AS emailAvgLength
FROM person

Prepend existing data in SQL

Disclaimer: This tip will probably be really basic for most SQL folks.

The task: The company I work for has a web application that does some basic tracking of grants. The system feeding information to this application just had an across the board change to the numbering scheme of the grants. All grants must have a prefix of “999-“. Therefore, any grant not beginning with “999-” must be updated. Example: a grant with the current number 8789966 needs to be 999-8789966.

The solution: The SQL below does two things. It updates all the grants to prepend the 999- prefix while also skipping any grants that are already correctly prefixed.


UPDATE tbl_grants
SET grant_no = '999-' + grant_no
WHERE grant_no NOT LIKE '999-%'

Subversion on Ubuntu (Feisty) with a Mac Client

Subversion gets my ducks in a row

As part of a continuous effort to improve my organization (a.k.a. not lose stuff) I have finally set up Subversion at home. If you are not familiar with Subversion it is an open source version control system used (mostly) by developers to keep up with changes to their codebase.

I’ve spent most of my career as kind of a “one man team” where I have been responsible for all phases of development and maintenance of code. However, I was exposed to Subversion when I contracted briefly last year in a multi-developer environment. I made a mental note at that time to revisit Subversion at a later date.

At last that date has come…

Subversion is now running at home on an old Gateway pc that I recently “upgraded” from XP to Ubuntu. I’m a total newbie with Linux, but I’ll be posting some on it in the future. Thanks to this tutorial the process was ridiculously easy (less than 5 minutes).

The next step was to get an SVN client. My previous exposure to Subversion was in the Windows world so we used TortoiseSVN. I have a PowerBook and an iMac at home though so I hunted down scplugin which integrates with Mac Finder the way TortoiseSVN integrates with Windows Explorer.

Now I just have to get all my code checked in.

Comment yer code with myRev Dreamweaver Extension

myRev logo

It’s March and amazingly I have stuck to one of my New Year’s Resolutions for work. What is that resolution you may or may not be asking? …Comment my frigging code.

Several years ago I fooled around with making a few little Dreamweaver Extensions. I pulled out an old one, dusted if off, pimped it up, and am providing it here for your benefit. It’s called myRev and it will insert a comment header for you (ideally you would insert it at the top of the page you are developing). Here is a sample of the output:


<!---
============================================================
File: SomeFile.cfm
Author: Christopher C. Simmons (CCS)
Date: 3.4.2008
Purpose: To perform some calculations
History: 0.1 Initial Release
============================================================
--->

You can use it with Coldfusion, PHP, CSS, JavaScript, or HTML. The header knows what comment style to use based on your choice in the Extension’s UI.

Here’s the fine print…

csimmons.net, LLC supplies this software AS IS and makes no guarantees for your use of it. csimmons.net, LLC is not responsible for any damage or pain the use of this product may cause you.

GET IT HERE (or by clicking the myRev icon above). To install it just unzip it and double click the myRev.mxp file. The Dreamweaver Extension manager will then install it.