#!/usr/bin/perl
# You may need to change this path to /usr/local/bin/perl
#**************************************************************
#
# Script to edit users on "UserDir enabled" line: PWSpostwwwacct1 V1.3
#
# Written by:
# Premier Website Solutions - http://www.premierwebsitesolutions.com
# Created - January 2, 2004 (V1.0)
# Modified - January 3, 2004 (V1.1)
# - added line to restart apache for changes to take effect
# Modified - February 29, 2004 (V1.2)
# - added detailed instructions
# Modified - March 2, 2004 (V1.21)
# - added warning at start of actual code
# Last Modified - March 11, 2004 (V1.3)
# - made it easy to use when another postwwwacct script is also being used
# - made adjustment so only the first UserDir line is modified
# - removed taint checking (not necessary and sometimes causes problems)
#
# To use this script, you need to add 1 line to your httpd.conf file,
# and you MUST HAVE the "mod_userdir.c" function in that file. That part
# of the httpd.conf file should look something like what's inside this block:
# _________________________________________
# | |
# | |
# | UserDir disabled |
# | UserDir enabled username1 username2 |
# | UserDir public_html |
# | |
# |_________________________________________|
#
# If your httpd.conf file does not have that, add it to the file just before where
# the VirtualHost (website account) entries start. Once this is at the start of your
# conf file, any UserDir enabled lines in VirtualHost entries are ignored.
#
#
# If you currently don't have any users on the UserDir enabled line, add the
# following line, everything inside the quotes, to your httpd.conf file just
# before the line.
#
# "# UserDirData|14|"
#
# The 14 is the number of days accounts are left there, and can be changed to
# whatever you prefer.
#
#
# This part is only needed if you ARE currently using the UserDir enabled line.
# _________________________________________________________________________________
# | If you do currently have users on the UserDir enabled line, add the following |
# | line, everything inside the quotes, to your httpd.conf file just before the |
# | line, replacing the usernames with the actual |
# | usernames and the 10 digit numbers with the approximate "time" of the account |
# | creation, before each username. |
# | |
# | "# UserDirData|14|1001901618|username1|1073001618|username2|" |
# | |
# | The 14 is the number of days accounts are left there, and can be changed to |
# | whatever you prefer. Any number of accounts can be included, seperating the |
# | times and usernames with |. (usually shift and the \ key) |
# | |
# | To help you calculate the number to put for the time value, we have a very |
# | simple script that will help you calculate that value. |
# | http://www.premierwebsitesolutions.com/scripts/time.cgi |
# | |
# | If you have any usernames that you want left in the UserDir enabled line |
# | permanently, just add the names to a second UserDirData enabled line, like |
# | what's inside these quotes: |
# | "UserDir enabled username1 username2" |
# | This script will only change the first UserDir enabled line, making usernames |
# | on the second line permanent. |
# |_________________________________________________________________________________|
#
# The UserDirData line must have the # at the beginning because it is not a command
# of any kind, but a line of data that is read by this script.
#
# Save a backup copy of the httpd.conf file before altering it just in case of errors.
#
# If your httpd.conf file has UserDir lines in the VirtualHost entries, this script
# will not touch them. It only adds or removes users from the first UserDir line
# it finds which should be before all VirtualHost entries. Any accounts with UserDir
# enabled in it's VirtualHost entry are therefore permanently enabled.
#
# If you are already using another postwwwacct script, just rename it to postwwwacct2.
# When this one is finished, it will call that one to do it's job.
#
# If you have any questions about this part of the script, or would like me to
# modify your httpd.conf file for you, email me @
# webmaster@premierwebsitesolutions.com
#
#
# Registered users of this script will be notified of any future updates.
# If you registered this copy with us, put your email here for future reference.
# This copy is registered to:
#
#**************************************************************
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# UNLESS YOU KNOW CGI, DO NOT EDIT ANYTHING BELOW HERE
# Feel free to study the code, but alterations are at your own risk
#-------------------------------------------------------------------
#-------------------------------------------------------------------
print "\nRunning postwwwacct...\n";
&edit_httpd;
print "\nUserDir line has been modified\n";
print "\npostwwwacct finished\n";
if (-e "/scripts/postwwwacct2") {
print "\nSending variables to postwwwacct2.\n";
system("/scripts/postwwwacct2",@ARGV);
}
exit;
sub edit_httpd {
system("cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.prescript");
open(DATFILE,"/usr/local/apache/conf/httpd.conf");
@lines = ;
close(DATFILE);
$users = "";
$newcommentline = "";
$newdataline = "";
foreach $l (@lines) {
chomp($l);
if ($l =~ "UserDirData") {
@check = split(/\|/,$l);
shift(@check);
$daystosave = shift(@check);
$timetosave = $daystosave * 86400;
$qtyvars = $#check + 1;
for ($i=0;$i<$qtyvars;$i++) {
if ($i/2 eq int($i/2)) {
if ($check[$i] + $timetosave > time) {
$j = $i + 1;
$newcommentline = $newcommentline . $check[$i] . "|" . $check[$j] . "|";
$users = $users . " " . $check[$j];
}
}
}
}
}
$newcommentline = "# UserDirData|" . $daystosave . "|" . $newcommentline . time . "|" . $ARGV[1] . "|";
$newdataline = " UserDir enabled" . $users . " " . $ARGV[1];
open(DATFILE,">/usr/local/apache/conf/httpd.conf");
flock (DATFILE,2);
seek (DATFILE,0,0);
foreach $l (@lines) {
if ($l =~ "UserDirData") {
$l = $newcommentline;
}
if ($l =~ "UserDir enabled" && $edited ne "Y") {
$l = $newdataline;
$edited = "Y";
}
print DATFILE "$l\n";
}
close(DATFILE);
chmod(0644,"/usr/local/apache/conf/httpd.conf");
print "Restarting apache\n";
system("killall -USR1 httpd");
}