...run all 3 by themselves..."
I wish it were that simple. I'm reverse-engineering old code, and there's lots of tie-ins and connections I don't understand yet.
Here's the PERL script, below that is the shell script.
#!/usr/bin/perl -w
###############################################################################
use strict; # Activate compile-time syntax checking
use CGI; # Needed for CGI environment
use CGI::Carp qw(fatalsToBrowser); # Throw errors as HTML pages
use File::Copy; # Much easier for duplicating the sample conf
###############################################################################
# Initialize CGI and set expected parameters
###############################################################################
my $thecgi = new CGI;
# the arg container for the shell script
my ($instructions,$redirect,$code,$clientDB,$clientName,$eventID,$eventName,$mode);
# these are expected in either case
$mode = $thecgi->param("mode");
$clientDB = $thecgi->param("clientDB");
# container for args, make the default mode 'client'
if ($mode eq "client")
{
# take care of webalizer config file
$clientName = $thecgi->param("clientName");
newClient();
$instructions = "$mode $clientDB";
$redirect = "
}
# if it is for a new event, add the eventID
if ($mode eq "event")
{
# update webalizer conf file
$eventName = $thecgi->param("eventName");
$eventID = $thecgi->param("eventID");
newEvent();
$code = $thecgi->param("c");
#debug
$instructions = "$mode $clientDB $eventID";
#$instructions = "./test.sh";
#$instructions = "./createdir.sh $mode $clientDB $eventID";
$redirect = "
}
###############################################################################
# Call the shell script with instructions
###############################################################################
#debug
my $cmd = "./createdir.sh $instructions";
#my $cmd = ($instructions);
my $result = system($cmd);
$result >>= 8; # shift 8 bits
#debug
print $result;
if ($result > 0)
{
printError("The createdir shell script failed: '$result'");
}
else
{
select (STDOUT);
print $thecgi->redirect( $redirect );
exit 0;
}
################################################################################
# Webalizer config file subroutines
################################################################################
# Set up a new client.
################################################################################
sub newClient
{
# first we need to create the target directory for stats
my $statdir = "<path>/$clientDB";
system ("mkdir -m 775 $statdir");
# prepare the client-specific conf file entries
my $outputDir = "OutputDir $statdir\n";
my $reportTitle = "ReportTitle Usage Statistics for $clientName\n";
# duplicate the default conf file
my $basefile = "<path>/client.sample.conf";
my $newfile = "<path>/$clientDB.conf";
copy ($basefile,$newfile);
# open and append to the new conf file
open (NEWCONF, ">> $newfile")
or die printError("Could not open $newfile for writing: $!");
flock (NEWCONF, 2);
select (NEWCONF);
print "$outputDir";
print "$reportTitle";
close (NEWCONF);
}
################################################################################
# Set up a new event.
################################################################################
sub newEvent
{
# prepare the grouping directives for the event
my $includeURL = "IncludeURL /$clientDB/$eventID/player.php*\n";
my $groupURL = "GroupURL /$clientDB/$eventID/player.php* $eventName\n";
my $hideURL = "HideURL /$clientDB/$eventID/player.php*\n";
# confirm the conf file exists
my $newfile = "<path>/$clientDB.conf";
open (YO, "< $newfile")
or die printError("Could not open $newfile for reading: $!");
close (YO);
# open and append the new event to the conf file
open (CONF, ">> $newfile")
or die printError("Could not open $newfile for writing: $!");
flock (CONF, 2);
select (CONF);
print "$includeURL";
print "$groupURL";
print "$hideURL";
close (CONF);
}
################################################################################
###############################################################################
# printError() - print error message
###############################################################################
sub printError
{
my $em = shift;
print $thecgi->header();
print<<EOF;
<center>
<table border=0 bgcolor="#c0c0c0" cellpadding=0 cellspacing=0>
<tr>
<td>
<table border=0 width="100%" cellpadding=5 cellspacing=1>
<tr">
<td bgcolor="#311C52" width="100%">
<font color="#ff0000"><b>Error -</b></font>
<font color="#ffffff">$em</font>
</td>
</tr>
<tr>
<td>Please contact OBC sysadmin and report the error shown above."</td>
</tr>
</table>
</td>
</tr>
</table>
</center>
print $cmd;
EOF
;
}
exit 0;
Shell:
#!/usr/local/bin/bash
BASE_PATH="<path>/htdocs/"
REMOTE_PATH="<path>/htdocs/"
# the first arg is essential since it defines what is to be done
if [ -z $1 ]
then
echo "Usage: `basename $0` [client|event] [client] [directory]"
exit 0
else
mode=$1
fi
# the mode is used to setup the directory needed
if [ "$mode" == client ]
then
THISDIR=$2
fi
if [ "$mode" == event ]
then
BASE_PATH=$BASE_PATH/$2
THISDIR=$3
REMOTE_PATH=$REMOTE_PATH/$2
fi
# the commands are executed using the variable as set above
# make the directory here on staging
mkdir -m 775 $BASE_PATH/$THISDIR
#mkdir -m 775 ./$THISDIR
# now sync <serverpath> so the directory is replicated there too
#rsync -aze ssh $BASE_PATH/ --include $THISDIR --exclude "*" <path>:$REMOTE_PATH/
rsync -aze ssh $BASE_PATH/ --include $THISDIR --exclude "*" <path>:$REMOTE_PATH/
#exit 0