sub hitman { @labels = ('','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 qq| $headTitle $links $bodyTag $bodyTitle |; !$cookie{$website.'APW'} && passtest($HITPWD); #prevent hackers from getting info print qq|
[ Pageviews] [ Visits]     |; print qq|         $printpage
|; ######################################################################## #resetting of all figures if($Form{'newfigs'} eq 'RESET') { open(DAT,">$HITCNT") || endMan("Read: $HITCNT"); open(DAT,">$PGECNT") || endMan("Read: $PGECNT"); open(DAT,">$HITLOG1") || endMan("Read: $HITLOG1"); open(DAT,">$HITLOG2") || endMan("Read: $HITLOG2"); foreach $month (1..12) { open(DAT,">$HVMON$month.db") || endMan("Read: $HVMON$month.db"); open(DAT,">$HPMON$month.db") || endMan("Read: $HPMON$month.db"); } } ######################################################################## # Case: View Hit stats by day if ($Form{'detail'} >0) { $month = $Form{'detail'}; if ($Form{'type'} eq 'Visits'){ $HITDAT = "$HVMON$month.db"; } else { $Form{'type'} = 'Pageviews'; $HITDAT = "$HPMON$month.db"; } if ($mo >= $month) { $year = $yyyy +0; } else { $year = $yyyy -1; } if ($year %4 == 0 && $year %100 !=0) { $dyinMon[2] = 29; } # Read all data into hashes $total = 0; open(DAT,"<$HITDAT") || open(DAT,">$HITDAT") || &endMan("Read: $HITDAT"); $file_lock && flock (DAT,1); seek (DAT,0,0); while ($line = ) { @hits = split (/\|/,$line); $page = ''; $group = ''; $pagecode = $hits[0]; if ($pagecode =~ /^([^+]+)\+$/){ $group = $1; } else { $page = $pagecode; } foreach $day (1..$dyinMon[$month]) { if ($page) { $Tbl{$page}{$day} += $hits[$day]; $PageTtl{$page} += $hits[$day]; $DayTtl{$day} += $hits[$day]; } if ($group) { $Tbl{$group}{$day} += $hits[$day]; $GroupTtl{$group} += $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
Days:$dayTotals
GROUPS:
$group$Tbl{$group}{$day}$GroupTtl{$group}
PAGES:
$page$Tbl{$page}{$day}$PageTtl{$page}

|; footnote(); } else ######################################################################## # Case: View Hitstats by month { # Read all data into hashes $total = 0; foreach $month (1..12) { $MonthTtl{$month} =0; if ($Form{'type'} eq 'Visits'){ $HITDAT = "$HVMON$month.db"; } else{ $Form{'type'} = 'Pageviews'; $HITDAT = "$HPMON$month.db"; } open(DAT,"<$HITDAT") || open(DAT,">$HITDAT") || &endMan ("Read: $HITDAT"); $file_lock && flock (DAT,1); seek (DAT,0,0); while ($line = ) { @hits = split (/\|/,$line); $page = ''; $group = ''; $pagecode = $hits[0]; if ($pagecode =~ /^([^+]+)\+$/){ $group = $1; } else{ $page = $pagecode; } $Tbl{$month}{$page} =0; if ($page) { foreach $day (1..31){ $Tbl{$month}{$page} += $hits[$day]; } $PageTtl{$page} += $Tbl{$month}{$page}; $MonthTtl{$month} += $Tbl{$month}{$page}; } if ($group) { foreach $day (1..31){ $Tbl{$month}{$group} += $hits[$day]; } $GroupTtl{$group} += $Tbl{$month}{$group}; } } 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 qq|\n|; print qq|\n|; # Print col headers and order the months $month = $mo; do { if ($month == 12) {$month =1;} else {$month++;} print qq|\n"; push @monthCol, $month; } until ($month == $mo); print qq||; # print group hit rows print qq|\n\n|; foreach (@groups) { print qq|\n\n|; foreach $month (@monthCol) { print qq||; } print qq||; } # print page hit rows print qq|\n\n|; foreach (@pages) { print qq|\n\n|; foreach $month (@monthCol) { print qq||; } print qq||; } print qq|\n
Months:$labels[$month]
|; if ($month > $mo) {$year = $yyyy -1;} else {$year = $yyyy +0;} print "$year
Totals
GROUPS:
$_$Tbl{$month}{$_}$GroupTtl{$_}
PAGES:
$_$Tbl{$month}{$_}$PageTtl{$_}

|; footnote(); } # end manFooter(); } # end hitman ######################################################################## sub newDay { $HPDAT = "$HPMON$logMonth.db"; $HVDAT = "$HVMON$logMonth.db"; @dyinMon = (0,31,28,31,30,31,30,31,31,30,31,30,31); if ($year %4 == 0 && $year %100 !=0) { $dyinMon[2] = 29; } $dyinMon = $dyinMon[$logMonth]; open(HPDAT,"+<$HPDAT") || open(HPDAT,">$HPDAT") || endIt("Cant open $HPDAT"); $file_lock && flock (HPDAT,2); seek (HPDAT,0,0); @hpDat = ; # add this month's views to Tbl hash foreach $hitLine (@hpDat) { @hits = split (/\|/,$hitLine); $page = $hits[0]; $PTbl{$page}[0] = $page; for $day (1..$dyinMon){ $PTbl{$page}[$day] += $hits[$day]; } $PIndex{$page} = 'Y'; } open(HVDAT,"+<$HVDAT") || open(HVDAT,">$HVDAT") || endIt("Cant open $HVDAT"); $file_lock && flock (HVDAT,2); seek (HVDAT,0,0); @hvDat = ; # add this month's visits to VTbl hash foreach $hitLine (@hvDat) { @hits = split (/\|/,$hitLine); $page = $hits[0]; $VTbl{$page}[0] = $page; for $day (1..$dyinMon){ $VTbl{$page}[$day] += $hits[$day]; } $VIndex{$page} = 'Y'; } # Read log file open(LOG1,"+<$HITLOG1") || open(LOG1,">$HITLOG1") ||endIt("Cant open $HITLOG1"); $file_lock && flock (LOG1,2); seek (LOG1,0,0); @logFile = ; # add yesterday's hits to Tbl hash foreach $logLine (@logFile) { @log = split (/\|/,$logLine); $page = "$log[1]"; ($group,$foo) = split (/\+/,$page); # create new line if no previous hits for $x ('SITE+',$group.'+',$page) { if (!$PTbl{$x}[0] && $x) { $PTbl{$x}[0] = $x; for $day (1..$dyinMon){ $PTbl{$x}[$day] +=0; } $PIndex{$x} = 'Y'; } $PTbl{$x}[$logDay]++; } for $x ('SITE+',$group.'+',$page) { if (!$Ip{$log[2]}{$x}) { $Ip{$log[2]}{$x} =1; $IpCnt{$x} ++; if (!$VTbl{$x}[0] && $x) { $VTbl{$x}[0] = $x; for $day (1..$dyinMon) { $VTbl{$x}[$day] +=0; } $VIndex{$x} = 'Y'; } } } } foreach $visit (keys %IpCnt){ $VTbl{$visit}[$logDay] += $IpCnt{$visit}; } # write updated PTbl back to file seek (HPDAT,0,0); foreach $page (sort {uc($a) cmp uc($b)} keys %PIndex) { $line = ''; for $day (0..$dyinMon){ $line .= "$PTbl{$page}[$day]\|"; } print HPDAT "$line\n"; } truncate (HPDAT,tell(HPDAT)); close (HPDAT); # write updated VTbl back to file seek (HVDAT,0,0); foreach $page (sort {uc($a) cmp uc($b)} keys %VIndex) { $line = ''; for $day (0..$dyinMon){ $line .= "$VTbl{$page}[$day]\|"; } print HVDAT "$line\n"; } truncate (HVDAT,tell (HVDAT)); close (HVDAT); open(LOG2,">$HITLOG2") || endIt("Cant open $HITLOG2"); $file_lock && flock (LOG2,2); seek (LOG2,0,0); print (LOG2 @logFile); truncate (LOG2,tell (LOG2)); close (LOG2); truncate (LOG1,0); close (LOG1); $logDay = $dd; changeCfg(); } # end newDay sub newMonth { # Empty last year's month file and update cfg if new month $logMonth = $mo; $HPDAT = "$HPMON$logMonth.db"; open(HPDAT,">$HPDAT") || endIt("Cant open $HPDAT"); $file_lock && flock (HPDAT,2); truncate (HPDAT,0); close (HPDAT); $HVDAT = "$HVMON$logMonth.db"; open(HVDAT,">$HVDAT") || endIt("Cant open $HVDAT"); $file_lock && flock (HVDAT,2); truncate (HVDAT,0); close (HVDAT); changeCfg(); } # end newMonth sub changeCfg # update hit cfg file { $cfgFile = join ("\|",$logDay,$logMonth,$eol); seek (CFG,0,0); print (CFG $cfgFile); truncate (CFG,tell(CFG)); } # end changeCfg sub manFooter # print hitman footer { print qq|\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!!"); } } } else { &passbox ("Wrong!!"); } } else { &passbox ("What's the Password?"); } } 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 qq|ERROR:
$_[0]
\n

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

\n|; exit; } # end endMan sub footnote { print qq| Completed on $timeStamp (Current days totals not included till following day.)

$i_note A hit counter must be placed on each page before stats can be recorded.
More Stats to be included in future upgrade.

|; } 1; # return true