This HOWTO was inspired by a need to figure out a way to automatically create .htaccess and associated .htpasswd files for specified directories without having a separate userid and password to have to maintain.
I have come up with a solution to this problem and have created a perl script that handles exactly this. This script is unique in the regard that it uses either site admins information or both site admins and users (name and password) to generate a .htaccess and .htpasswd file. Syncronization of this information occurs when running this script as a cron job.
It is particularly important to having protection for directores such as /awstats, where sensitive site stats information is left open by default. With recent exploits found (although fixed with the latest awstats), this is a must have for protecting these locations from unwanted visitors.
Please read the information in the comment section of the script prior to running. Although I have a high confidence level with this script, I must state to use at your own risk and understand what this script is doing. Running this script in debug mode and using it with one domain (specified as a command line option) is strongly suggested before implementing for all domains.
V1.1 - REVISION 02/23/05:
====================
I have revised the original script to now handle either site admin or both site admin and users associated with a virtual domain. You may choose either method for any directory listed in @protected_dirs.
V1.2 - REVISION 03/24/05:
====================
There was an issue in the previous version (1.1) when using "all" as the parameter in @protected_dirs which essentially allowed all users from each domain being processed to be added to the next domain -- not a good thing.
The new version fixes this issue, plus provides the option to force delete all domains htpasswd file before re-creating it. If you have been using v1.1 or previous you will want to enable this option for the first run through the application by setting the variable $force_delete_htpasswd to 1. Then set this back to the default value of 0 when done.
The sitelookup application is now a variable. The default is Ensim's sitelookup, however, you may use Doobla's dsitelookup as a replacement.
COMMENT 02/23/05:
===============
Doobla has created an application called dsitelookup which provides the same functionality as Ensim's sitelookup, except with much better performance. Due to the frequency that the autoprotect script should be executed in cron, I highly suggest replacing sitelookup with dsitelookup.
Download sitelookup here:
http://www.doobla.com/ensim/dsitelookup
-------------------------------------------------------------------------------------
The autoprotect script can be downloaded here:
http://www.cacheweb.com/ensim/autoprotect_...t_ensim_dirs.pl
I had to remove the code in this thread due to exceeding the length of the post.
