#!/usr/bin/perl $USER = an4m; $WEBLOG = "/users/$USER/public_html/cgi-bin/.weblog"; #$WEBLOG = "/users/webman/server/httpd_current/logs/access_log"; ########## DO NOT CROSS - MAYHEM BELOW #################################### $PROG = $0; $PROG =~ s#.*/##; $DATE = $EXCEPT = $ONLY = ""; $PAGES = $SITES = 1; $OUTPUT = "html"; for ($i = 0; $i <= $#ARGV; $i++) { if (@ARGV[$i] =~ /-*help/) { die "Repeatable optionally-hyphenated command switches for $PROG\n" . "\t-date : statistics for day \n" . "\t-hour : shortcut for -date " . `date "+%d/%b/%Y:%H"` . "\t-today : shortcut for -date " . `date "+%d/%b/%Y"` . "\t-month : shortcut for -date " . `date "+../%b/%Y"` . "\t-year : shortcut for -date " . `date "+../.../%Y"` . "\t-only : only pages matching included\n" . "\t-except : pages/sites matching excluded\n" . "\t-pages : only page statistics\n" . "\t-sites : only site statistics\n" . "\t-output : = text/html/raw\n" . "\t-help : this help page\n" . "Example: $PROG " . "-date 30/Aug/1971 only html -only gif -except oops.html " . "except cs.virginia.edu sites\n"; } elsif (@ARGV[$i] =~ /-*hour/) { $DATE = `date "+%d/%b/%Y:%H:"`; chop($DATE); } elsif (@ARGV[$i] =~ /-*today/) { $DATE = `date "+%d/%b/%Y:"`; chop($DATE); } elsif (@ARGV[$i] =~ /-*month/) { $DATE = `date "+../%b/%Y:"`; chop($DATE); } elsif (@ARGV[$i] =~ /-*year/) { $DATE = `date "+../.../%Y:"`; chop($DATE); } elsif (@ARGV[$i] =~ /-*date/) { $DATE = @ARGV[++$i]; } elsif (@ARGV[$i] =~ /-*only/) { $ONLY .= "|@ARGV[++$i]"; } elsif (@ARGV[$i] =~ /-*except/) { $EXCEPT .= "|@ARGV[++$i]"; } elsif (@ARGV[$i] =~ /-*page/) { $PAGES = 1; $SITES = 0; } elsif (@ARGV[$i] =~ /-*site/) { $PAGES = 0; $SITES = 1; } elsif (@ARGV[$i] =~ /-*output/) { $OUTPUT = @ARGV[++$i]; } else { print "Unknown option: @ARGV[$i]\n"; @ARGV[$i+1] = "help"; } } $EXCEPT =~ s/^\|//; $ONLY =~ s/^\|//; @weblog = ($EXCEPT eq "") ? `egrep \"$DATE.*$USER.*$ONLY\" $WEBLOG` : `egrep \"$DATE.*$USER.*$ONLY\" $WEBLOG | egrep -v \"$EXCEPT\"`; $totalhits = 0; %pages = %visitors = (); foreach (@weblog) { ($site, $tmp, $tmp, $tmp, $tmp, $tmp, $page, $tmp, $result, $tmp) = split; next if ($result ne "200"); $page =~ s/\?.*//; $page =~ s/%7[eE]/~/; $page =~ s/index.html//; $page =~ s/\/~$USER\///; if ($page eq "") { $page = "index.html"; } $totalhits++; $visitors{$site}++; $pages{$page}++; } if ($OUTPUT eq "text") { print "TOTAL HITS: $totalhits\n"; if ($PAGES == 1 && print "\nPOPULAR PAGES\n") { foreach (sort { $pages{$a} < $pages{$b} } keys(%pages)) { printf("%-50s %d\n", $_, $pages{$_}); } } if ($SITES == 1 && print "\nFREQUENT VISITORS\n") { foreach (sort { $visitors{$a} < $visitors{$b} } keys(%visitors)) { printf("%-50s %d\n", $_, $visitors{$_}); } } } elsif ($OUTPUT eq "html") { print "Web Visitors Page" . "" . "

Web Visitors Page, $DATE" . "


TOTAL HITS: $totalhits
"; if ($PAGES == 1 && print ""; } if ($SITES == 1 && print ""; } print "
" . "" . "") { foreach (sort { $pages{$a} < $pages{$b} } keys(%pages)) { print "" . ""; } print "
POPULAR " . "PAGES" . "
$_
" . "" . "") { foreach (sort { $visitors{$a} < $visitors{$b} } keys(%visitors)) { print ""; } print "
FREQUENT " . "VISITORS" . "
$_

\n"; } elsif ($OUTPUT eq "raw") { foreach (@weblog) { print; } } else { die "Unimplemented\n"; }