#!/usr/bin/perl
# run getstats to create reports from httpd log files

die "usage: run-gs <date>\n\nfor example: run-gs 19980221\n"
				unless $#ARGV == 0;

$date=$ARGV[0];
if      (-x '/opt/ACISweb/bin/getstats/getstats') {
    $GETSTATS='/opt/ACISweb/bin/getstats/getstats';
} elsif (-x '/usr/local/bin/getstats') {
    $GETSTATS='/usr/local/bin/getstats';
} else {
    die("can't find getstats\n")
}

if      (-x '/opt/local/bin/gzip') {
    $GZIP='/opt/local/bin/gzip';
} elsif (-x '/usr/local/bin/gzip') {
    $GZIP='/usr/local/bin/gzip';
} else {
    $GZIP='';
}
$rpt='/www/data/httpd/reports';
$sta='/www/data/httpd/staff';
$log='/www/data/httpd/log';
$msg="/tmp/getstats-$date-www";

print STDERR "getstats will create reports for $date\n";

open (CMD, "|$GETSTATS") || die "can't execute $GETSTATS\n";

print CMD "
set date $date
set msgfile $msg
set defaulthost www.columbia.edu

set domroot www.columbia.edu        $rpt/columbia/dom
set domroot www.kermit-project.org  $rpt/kermit/dom
set domroot www.ciaonet.org         $rpt/ciao/dom
set domroot www.najp.org            $rpt/najp/dom
set domroot www.thornton-wilder.com $rpt/wilder/dom
set domroot www.thewildones.org     $rpt/wildones/dom
set domroot www.worldmonuments.org  $rpt/worldmon/dom

set xtroot  www.columbia.edu        $log/xt/www
set xtroot  www.kermit-project.org  $log/xt/kermit
set xtroot  www.ciaonet.org         $log/xt/ciao
set xtroot  www.najp.org            $log/xt/najp
set xtroot  www.thornton-wilder.com $log/xt/wilder
set xtroot  www.thewildones.org     $log/xt/wildones
set xtroot  www.worldmonuments.org  $log/xt/worldmon

# how many levels to keep in memory
set dtrlevels 6
set domlevels 2
set countbytes yes
read std $log/fu/jonapot/httpd.access.$date.gz
read std $log/fu/kwaziwai/httpd.access.$date.gz

#####
# print reports for the main server
set servername \"http://www.columbia.edu/\"
set icon \"http://www.columbia.edu/httpd/getstats/getstats.gif\"

set ignorepublic yes
set sortkey nreq
set ignoreimages no
write dirtree 6 $rpt/columbia/$date.dtrreq6.html
write dirtree 5 $rpt/columbia/$date.dtrreq5.html
write dirtree 4 $rpt/columbia/$date.dtrreq4.html
write dirtree 3 $rpt/columbia/$date.dtrreq3.html
write dirtree 2 $rpt/columbia/$date.dtrreq2.html
write dirtree 1 $rpt/columbia/$date.dtrreq1.html

set sortkey alpha
set ignoreimages no
write dirtree 6 $rpt/columbia/$date.dtralp6.html
write dirtree 5 $rpt/columbia/$date.dtralp5.html
write dirtree 4 $rpt/columbia/$date.dtralp4.html
write dirtree 3 $rpt/columbia/$date.dtralp3.html
write dirtree 2 $rpt/columbia/$date.dtralp2.html
write dirtree 1 $rpt/columbia/$date.dtralp1.html

set sortkey nreq
set ignoreimages yes
write dirtree 6 $rpt/columbia/$date.htrreq6.html
write dirtree 5 $rpt/columbia/$date.htrreq5.html
write dirtree 4 $rpt/columbia/$date.htrreq4.html
write dirtree 3 $rpt/columbia/$date.htrreq3.html
write dirtree 2 $rpt/columbia/$date.htrreq2.html
write dirtree 1 $rpt/columbia/$date.htrreq1.html

set sortkey alpha
set ignoreimages yes
write dirtree 6 $rpt/columbia/$date.htralp6.html
write dirtree 5 $rpt/columbia/$date.htralp5.html
write dirtree 4 $rpt/columbia/$date.htralp4.html
write dirtree 3 $rpt/columbia/$date.htralp3.html
write dirtree 2 $rpt/columbia/$date.htralp2.html
write dirtree 1 $rpt/columbia/$date.htralp1.html

# report on public_html directories
set ignorepublic no
set sortkey nreq
set ignoreimages no
write dirtree 3 $sta/$date.dtrreq3.html
write dirtree 2 $sta/$date.dtrreq2.html
write dirtree 1 $sta/$date.dtrreq1.html

# other reports: domain, redirects, errors
write domain 1 $rpt/columbia/dom/$date.domreq1.html
write redir  6 $rpt/columbia/$date.redir.html
write error  6 $rpt/columbia/$date.error.list


#####
# print reports for Kermit
set servername \"http://www.kermit-project.org/\"
set icon \"http://www.columbia.edu/kermit/k95green.gif\"

set ignorepublic yes
set sortkey nreq
set ignoreimages yes
write dirtree 4 $rpt/kermit/$date.htrreq4.html
write dirtree 3 $rpt/kermit/$date.htrreq3.html
write dirtree 2 $rpt/kermit/$date.htrreq2.html
write dirtree 1 $rpt/kermit/$date.htrreq1.html
write domain  1 $rpt/kermit/dom/$date.domreq1.html
write redir   6 $rpt/kermit/$date.redir.html
write error   6 $rpt/kermit/$date.error.list


#####
# print reports for CIAO
set servername \"http://www.ciaonet.org/\"
set icon \"https://www1.columbia.edu/sec/dlc/ciao/ciaobt.gif\"

set ignorepublic yes
set sortkey nreq
set ignoreimages yes
write dirtree 4 $rpt/ciao/$date.htrreq4.html
write dirtree 3 $rpt/ciao/$date.htrreq3.html
write dirtree 2 $rpt/ciao/$date.htrreq2.html
write dirtree 1 $rpt/ciao/$date.htrreq1.html
write domain  1 $rpt/ciao/dom/$date.domreq1.html
write redir   6 $rpt/ciao/$date.redir.html
write error   6 $rpt/ciao/$date.error.list


#####
# print reports for NAJP
set servername \"http://www.najp.org/\"
set icon \"http://www.columbia.edu/httpd/getstats/getstats.gif\"

set ignorepublic yes
set sortkey nreq
set ignoreimages yes
write dirtree 4 $rpt/najp/$date.htrreq4.html
write dirtree 3 $rpt/najp/$date.htrreq3.html
write dirtree 2 $rpt/najp/$date.htrreq2.html
write dirtree 1 $rpt/najp/$date.htrreq1.html
write domain  1 $rpt/najp/dom/$date.domreq1.html
write redir   6 $rpt/najp/$date.redir.html
write error   6 $rpt/najp/$date.error.list

#####
# print reports for Thornton Wilder
set servername \"http://www.thornton-wilder.com/\"
set icon \"http://www.columbia.edu/httpd/getstats/getstats.gif\"

set ignorepublic yes
set sortkey nreq
set ignoreimages yes
write dirtree 4 $rpt/wilder/$date.htrreq4.html
write dirtree 3 $rpt/wilder/$date.htrreq3.html
write dirtree 2 $rpt/wilder/$date.htrreq2.html
write dirtree 1 $rpt/wilder/$date.htrreq1.html
write domain  1 $rpt/wilder/dom/$date.domreq1.html
write redir   6 $rpt/wilder/$date.redir.html
write error   6 $rpt/wilder/$date.error.list

#####
# print reports for The Wild Ones
set servername \"http://www.thewildones.org/\"
set icon \"http://www.columbia.edu/httpd/getstats/getstats.gif\"

set ignorepublic yes
set sortkey nreq
set ignoreimages yes
write dirtree 4 $rpt/wildones/$date.htrreq4.html
write dirtree 3 $rpt/wildones/$date.htrreq3.html
write dirtree 2 $rpt/wildones/$date.htrreq2.html
write dirtree 1 $rpt/wildones/$date.htrreq1.html
write domain  1 $rpt/wildones/dom/$date.domreq1.html
write redir   6 $rpt/wildones/$date.redir.html
write error   6 $rpt/wildones/$date.error.list

#####
# print reports for the World Monuments Fund
set servername \"http://www.worldmonuments.org/\"
set icon \"http://www.columbia.edu/httpd/getstats/getstats.gif\"

set ignorepublic yes
set sortkey nreq
set ignoreimages yes
write dirtree 4 $rpt/worldmon/$date.htrreq4.html
write dirtree 3 $rpt/worldmon/$date.htrreq3.html
write dirtree 2 $rpt/worldmon/$date.htrreq2.html
write dirtree 1 $rpt/worldmon/$date.htrreq1.html
write domain  1 $rpt/worldmon/dom/$date.domreq1.html
write redir   6 $rpt/worldmon/$date.redir.html
write error   6 $rpt/worldmon/$date.error.list
";
close (CMD);

system("chgrp www $rpt/*/$date*");
system("chmod a+r $rpt/*/$date*");
system("chgrp www $sta/$date*");
system("chmod o-r $sta/$date*");
unlink("$msg.gz") if -r "$msg.gz";	# remove old compressed file
if ($GZIP) {system("$GZIP $msg");}
else       {print "can't find gzip, $msg not compressed\n";}

exit;
