ITCOM |
|
|
This document is obsolete and is retained for reference purposes only. It will not be maintained. The information contained should also be considered obsolete. |
Converting a CSV File to .htpasswd/.htgroup |
Overview:
A CSV file is a "Comma Seperated Values" file. These are easily created with standard database and spreadsheet applications. The NEWxxx.DAT file, part of the current shipped rosters from national, is actually a CSV file, but may need to be renamed (from a .DAT to .CSV) before being opened by your spreadsheet or database application. The Perl script csv2htpasswd.pl is used to convert a CSV file containing 3 fields:
A seperate template .htaccess file will need to be editted to enable the web server's authorization directives. The "user name" will be the certificate number, and the "password" will be the email address. The last name is used to salt the crypt() function. |
Notes:
|
Procedure:
Get to your web document directory - not your home directory: cd /doc/samplesiteps If it has not yet been created, create the formembersonly directory: mkdir formembersonly All the files to be protected - as well as the perl script, your CSV file, and the .ht-files - will reside in this directory: cd formembersonly Copy the csv2htpasswd.pl perl script from the ITCom directory to your working directory and make it executable. cp /nat/itcom/shared/help/samples/csv2htpasswd.txt ./csv2htpasswd.pl chmod +x csv2htpasswd.pl Now that the perl script is there, you will need to transfer in your CSV file. Use your ftp program from your desktop and put the CSV file into this subdirectory. Run the perl script and convert your new CSV to the corresponding .htpasswd and .htgroup files, passing as the single command line argument the name of the file you just ftp-ed in: ./csv2htpasswd.pl yourfilename.csv Now that you have a list of valid users (.htgroup) and an encrypted password file (.htpasswd), you should remove the readable, unencrypted, source CSV file: rm yourfilename.csv Hint - don't bother deleting the script. Whenever you make a change to your list of members with email addresses, you can ftp the updated CSV file and execute the script to recreate the group and password files. Copy the template .htaccess file from the ITCom directory. cp /nat/itcom/shared/help/samples/htaccess.txt ./htaccess.txt Note - do not copy this to .htaccess yet. The file is a template and the web server will begin to enforce the rules with incorrect data. This text file will be renamed a little later. Edit the text file using your favorite text editor. If you have a problem with the editors on the UNIX server (ed, ex, sed, vi) you will have to ftp the text file back to your desktop, edit it there, and ftp it back to the ITCom server. You will need to change the first 2 lines. These are the ones that refer to the formembersonly directory name. Actually, you need to change the 3rd line too. Make sure the real squadron name is there and in quotes. Once you are finished with the template file edits (or ftp'ing the text file around), move the template to .htaccess. Once the file is in place, the web server will begin enforcing the rules. mv htaccess.txt .htaccess Hint: This file only needs to be editted once. Even when users are added or deleted, this file does not change - only the group and password files do. Done. Now, when visitors try to access any page in the formembersonly directory (or any subdirectory), they will be presented a standard user name (certificate number) and password (email address) dialog box by the web server before being granted authorization to recieve the files. Optional: If you are concerned that your members may not be able to fill in the dialog properly, and would like to provide them a friendly error page instead of the generic "Unauthorized" (error 401) error provided by the web server, you must add a directive to the .htaccess file. ErrorDocument 401 /localusps/samplesiteps/accessdenied.html It is important to note that you must provide this referenced HTML file and it is a URL, unlike the other lines in the .htaccess file. |