#! /usr/local/bin/perl # # HITMAN - The HITMATIC Manager # Displays and reports various hit count statistics. # # Filename: hitman.pl # Last revised: March 15, 1998 # Copyright: 1997,1998 by Joe DePasquale # E-Mail: crypt@getcruising.com # Website: http://www.GetCruising.com # ######################################################################## # # # This script and accompanying files may be distributed freely # # and modified, provided this header with my name, E-Mail address and # # this notice remain intact. Ownership rights remain with me. You may # # not sell this script without my approval. # # # # This script comes with no guarantee or warranty except for my good # # intentions. By using this code you agree to indemnify me from any # # liability that might arise from it's use. # # # # There is no technical support for this script, neither am I a # # professional programmer. Refer to 'HELPME.TXT' for further guidance. # # # ######################################################################## sub hitman { @labels = ('Foo','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); @dyinMon = (0,31,28,31,30,31,30,31,31,30,31,30,31); # Parse form input read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @cgiPairs = split(/&/,$buffer); foreach $cgiPair (@cgiPairs) { ($name, $value) = split(/=/,$cgiPair); $name =~ s/\+/ /g; $value =~ s/\+/ /g; $name =~ s/%(..)/pack("c",hex($1))/ge; $value =~ s/%(..)/pack("c",hex($1))/ge; $Form{$name} .= "\0" if (defined($Form{$name})); $Form{$name} .= "$value"; } undef $name; undef $value; print "Content-type: text/html\n\n"; print "\n$headTitle\n"; print "$bodyTag\n$bodyTitle

\n"; &passtest ($HITPWD); print qq|

\n|; print qq|\n|; ######################################################################## # Case: View Hit stats by year if ($Form{'hittable'}) { if ($Form{'detail'} && $Form{'detail'} =~ /^(M|G|P)\|(.+)/) { if ($1 eq "M") # month { $month = $2; print "Hits By MONTH for: $labels[$month] "; if ($monthStamp >= $month) {$year = $yearStamp +0;} else {$year = $yearStamp -1;} print "$year
\n"; if ($year %4 == 0) { $dyinMon[2] = 29; } # Read all data into hashes $total = 0; $HITDAT = "$HITMON$month.dat"; open (DAT,"<$HITDAT") || &endMan ("Read: $HITDAT"); flock (DAT,1); seek (DAT,0,0); while ($line = ) { @hits = split (/\|/,$line); $page = $hits[0]; if ($page =~ /(.+)\+(.+)/) { $group =$1; } foreach $day (1..$dyinMon[$month]) { $Tbl{$page}{$day} += $hits[$day]; $PageTtl{$page} += $hits[$day]; if ($group) { $Tbl{$group}{$day} += $hits[$day]; $GroupTtl{$group} += $hits[$day]; } $DayTtl{$day} += $hits[$day]; } $total += $PageTtl{$page}; } close (DAT); @pages = sort {$PageTtl{$b} <=> $PageTtl{$a}} keys %PageTtl; @groups = sort {$GroupTtl{$b} <=> $GroupTtl{$a}} keys %GroupTtl; print qq|\n|; print qq|\n|; foreach $day (1..$dyinMon[$month]) { print qq||; } print qq||; # print group hit rows print qq|\n\n|; foreach $group (@groups) { print qq|\n\n|; foreach $day (1..$dyinMon[$month]) { print qq||; } print qq||; } # print page hit rows print qq|\n\n|; foreach $page (@pages) { print qq|\n\n|; foreach $day (1..$dyinMon[$month]) { print qq||; } print qq||; } print qq|\n\n|; foreach $day (1..$dyinMon[$month]) { print qq||; } print qq||; print qq|\n

Days:
$dayGroup
/Page
Totals
GROUPS:
$group$Tbl{$group}{$day}$GroupTtl{$group}
PAGES:
$page$Tbl{$page}{$day}$PageTtl{$page}
Day Totals$DayTtl{$day}$total

Completed on $timeStamp\n

\n|; } else # group or page { print "Hits By "; if ($1 eq "G") { $group = $2; print "GROUP for "$group""; } else { $page = $2; print "PAGE for "$page""; } print "
\n"; # Read all data into hashes $total = 0; foreach $month (1..12) { $MonthTtl{$month} =0; $HITDAT = "$HITMON$month.dat"; open (DAT,"<$HITDAT") || &endMan ("Read: $HITDAT"); flock (DAT,1); seek (DAT,0,0); while ($line = ) { @hits = split (/\|/,$line); if ($hits[0] eq $page || $hits[0] =~ /^$group\+/) { foreach $day (1..31) { $Tbl{$month}{$day} += $hits[$day]; $DayTtl{$day} += $hits[$day]; $MonthTtl{$month} += $Tbl{$month}{$day}; } } } close (DAT); $total += $MonthTtl{$month}; } print "\n"; print "\n"; # Print col headers and order the months $month = $monthStamp; do { if ($month == 12) {$month =1;} else {$month++;} print "\n"; push @monthCol, $month; } until ($month == $monthStamp); print ""; foreach $day (1..31) { print "\n\n"; foreach $month (@monthCol) { print ""; } print ""; } print "\n\n"; foreach $month (@monthCol) { print ""; } print ""; print "\n

Months:

$labels[$month]
"; if ($month > $monthStamp) {$year = $yearStamp -1;} else {$year = $yearStamp +0;} print "$year
Day
Totals
$day$Tbl{$month}{$day}$DayTtl{$day}
Month Totals$MonthTtl{$month}$total

Completed on $timeStamp\n

\n"; } } else # default by year { print "Hits By YEAR as of $timeStamp
\n"; # Read all data into hashes $total = 0; foreach $month (1..12) { $MonthTtl{$month} =0; $HITDAT = "$HITMON$month.dat"; open (DAT,"<$HITDAT") || &endMan ("Read: $HITDAT"); flock (DAT,1); seek (DAT,0,0); while ($line = ) { @hits = split (/\|/,$line); $page = $hits[0]; if ($page =~ /(.+)\+(.+)/) { $group =$1; } $Tbl{$month}{$page} =0; foreach $day (1..31) { $Tbl{$month}{$page} += $hits[$day]; } $PageTtl{$page} += $Tbl{$month}{$page}; $MonthTtl{$month} += $Tbl{$month}{$page}; if ($group) { $Tbl{$month}{$group} += $Tbl{$month}{$page}; $GroupTtl{$group} += $Tbl{$month}{$page}; } } close (DAT); $total += $MonthTtl{$month}; } # Sort by descending page total @pages = sort {$PageTtl{$b} <=> $PageTtl{$a}} keys %PageTtl; @groups = sort {$GroupTtl{$b} <=> $GroupTtl{$a}} keys %GroupTtl; print "\n"; print "\n"; # Print col headers and order the months $month = $monthStamp; do { if ($month == 12) {$month =1;} else {$month++;} print "\n"; push @monthCol, $month; } until ($month == $monthStamp); print ""; # print group hit rows print "\n\n"; foreach $group (@groups) { print "\n\n"; foreach $month (@monthCol) { print ""; } print ""; } # print page hit rows print "\n\n"; foreach $page (@pages) { print "\n\n"; foreach $month (@monthCol) { print ""; } print ""; } # print month subtotal row print "\n\n"; foreach $month (@monthCol) { print ""; } print ""; print "\n

Months:

$labels[$month]
"; if ($month > $monthStamp) {$year = $yearStamp -1;} else {$year = $yearStamp +0;} print "$year
Group
/Page
Totals
GROUPS:
$group$Tbl{$month}{$group}$GroupTtl{$group}
PAGES:
$page$Tbl{$month}{$page}$PageTtl{$page}
Month Totals$MonthTtl{$month}$total

\n"; } # end default by year print <<__HITFORM;
Hit Tables
For more detail select any MONTH, GROUP or PAGE button above, then..
PRESS:
Hit Counter
For the count DISPLAYED to users or to RESET counter date..
PRESS:
__HITFORM &manFooter; } # end case hittable ######################################################################## # Case: Flag to reset hitcount at next daily maintenance elsif ($Form{'resetcount'}) { open (LOCK,">$HITFLK") || &endMan ("Write: $HITFLK"); if (!flock (LOCK,2)) { &endMan ("Lock: $HITFLK"); } # Write new cnt date to CFG open (CFG,"+<$HITCFG") || &endMan ("Read\/Write: $HITCFG"); flock (CFG,2); seek (CFG,0,0); $cfgFile = ; ($logDay,$datMonth,$cntMonth,$cntFlag,$eol) = split (/\|/,$cfgFile); $cntMonth = $Form{'setmonth'} +0; $cntFlag = 'Y'; $cfgFile = join ("\|",$logDay,$datMonth,$cntMonth,$cntFlag,$eol); seek (CFG,0,0); print (CFG $cfgFile); truncate (CFG,tell(CFG)); close (CFG); close (LOCK); print "Hit Counter will be reset at next daily maintenance
\n to $labels[$cntMonth] 1, $year\n

\n"; &hitCount; &manFooter; } # end resetcount ######################################################################## # Default Case: Display hitcount else { &hitCount; &manFooter; } # end default } # end hitman ######################################################################## sub hitCount # Display hitcount { open (CNT,"<$HITCNT") || &endMan ("Read: $HITCNT"); flock (CNT,1); seek (CNT,0,0); @hitFile = ; close (CNT); print "\n\n"; $hitTtl =0; for ($x=0; $x<=$#hitFile; $x++) { print "\n\n"; ($count,$code,$eol) = split (/\|/,$hitFile[$x]); if ($code =~/\+/) { ($group,$page) = split (/\+/,$code); $GroupTtl{$group} += $count; } print ""; $hitTtl = $hitTtl + $count; } print "\n
HITSby PAGECODE
$count$code

\n"; if ($group) { print "\n\n"; @groups = sort {$GroupTtl{$b} <=> $GroupTtl{$a}} keys %GroupTtl; foreach $group (@groups) { print "\n\n"; print ""; } print "\n
HITSby GROUP
$GroupTtl{$group}$group

\n"; } open (CFG,"<$HITCFG") || &endMan ("Read: $HITCNT"); flock (CFG,1); seek (CFG,0,0); $cfgFile = ; close (CFG); ($logDay,$datMonth,$cntMonth,$cntFlag,$eol) = split (/\|/,$cfgFile); print "Total: $hitTtl hits for $x pages since $labels[$cntMonth] 1, "; if ($monthStamp >= $cntMonth) {$year = $yearStamp +0;} else {$year = $yearStamp -1;} print "$year\n
Completed at $timeStamp\n

\n"; print qq|\n\n|; print qq|\n|; print qq|\n|; print qq|\n|; print qq|\n
Hit Counter\n|; print qq|
To reset the counter and starting date, select a starting MONTH and press CHANGE. A new image of the SINCE date will also be created.
SINCE: \n \n|; print qq|
Hit Tables
For ALL hits by MONTH, GROUP or PAGE
PRESS:
\n|; } # end hitCount sub manFooter # print hitman footer { print qq|

\nExit $headTitle\n|; print qq|

HITMATIC is one of Joe's CGI Scripts From The Crypt!\n|; print qq|

\n\n|; } # end manFooter sub passtest # password routines { $PASSFILE = $_[0]; if (-s $PASSFILE) { if ($Form{'password'}) { open (PASS,"<$PASSFILE"); $passcode = ; close (PASS); chop ($passcode) if $passcode =~ /\n$/; $lp = length $Form{'password'}; $salt = substr($Form{'password'},$lp-2,1).substr($Form{'password'},1,1); if ($passcode eq crypt ($Form{'password'},$salt)) { if ($Form{'newpassword'}) { $lp = length $Form{'newpassword'}; if ($Form{'newpassword'} =~ /^\w{$lp}\b/) { $Form{'password'} = $Form{'newpassword'}; $salt = substr($Form{'password'},$lp-2,1).substr($Form{'password'},1,1); $passcode = crypt ($Form{'password'},$salt); open (PASS,">$PASSFILE"); print PASS "$passcode"; close (PASS); } else { &passbox ("Bad choice, Creep!!"); } } } else { &passbox ("Wrong, Creep!!"); } } else { &passbox ("What's the Password, Creep?"); } } else { &endMan ("Password File $PASSFILE Not Found"); } } sub passbox { print <<__PASSBOX;

$_[0]
Enter Password:
Change Password:

Password must be 4 to 12 alpha-numeric characters.

__PASSBOX exit; } # end passbox sub endMan # Error handling for manager scripts { print "ERROR:
$_[0]
\n

"; if ($!) { print "Server made a Boo-Boo! $!\n"; } else { print "Use your browser's [BACK] button and try again.\n"; } print "

\n"; exit; } # end endMan 1; # return true