#!/usr/local/bin/perl $| = 1; require 'snitch_subs.cgi'; require 'snitch.cfg'; $date = $FORM{date}; ($tmonth, $tday, $tyear) = split(/\|/, $date); print "Content-type:text/html\n\n"; $query = $ENV{QUERY_STRING}; &img_path; &log_size; &parse_form; if ($FORM{spmonth} eq "01"){$monthname = "January";} if ($FORM{spmonth} eq "02"){$monthname = "February";} if ($FORM{spmonth} eq "03"){$monthname = "March";} if ($FORM{spmonth} eq "04"){$monthname = "April";} if ($FORM{spmonth} eq "05"){$monthname = "May";} if ($FORM{spmonth} eq "06"){$monthname = "June";} if ($FORM{spmonth} eq "07"){$monthname = "July";} if ($FORM{spmonth} eq "08"){$monthname = "August";} if ($FORM{spmonth} eq "09"){$monthname = "September";} if ($FORM{spmonth} eq "10"){$monthname = "October";} if ($FORM{spmonth} eq "11"){$monthname = "November";} if ($FORM{spmonth} eq "12"){$monthname = "December";} if ($FORM{bmonth} eq "01"){$bmonthname = "January";} if ($FORM{bmonth} eq "02"){$bmonthname = "February";} if ($FORM{bmonth} eq "03"){$bmonthname = "March";} if ($FORM{bmonth} eq "04"){$bmonthname = "April";} if ($FORM{bmonth} eq "05"){$bmonthname = "May";} if ($FORM{bmonth} eq "06"){$bmonthname = "June";} if ($FORM{bmonth} eq "07"){$bmonthname = "July";} if ($FORM{bmonth} eq "08"){$bmonthname = "August";} if ($FORM{bmonth} eq "09"){$bmonthname = "September";} if ($FORM{bmonth} eq "10"){$bmonthname = "October";} if ($FORM{bmonth} eq "11"){$bmonthname = "November";} if ($FORM{bmonth} eq "12"){$bmonthname = "December";} if ($FORM{emonth} eq "01"){$emonthname = "January";} if ($FORM{emonth} eq "02"){$emonthname = "February";} if ($FORM{emonth} eq "03"){$emonthname = "March";} if ($FORM{emonth} eq "04"){$emonthname = "April";} if ($FORM{emonth} eq "05"){$emonthname = "May";} if ($FORM{emonth} eq "06"){$emonthname = "June";} if ($FORM{emonth} eq "07"){$emonthname = "July";} if ($FORM{emonth} eq "08"){$emonthname = "August";} if ($FORM{emonth} eq "09"){$emonthname = "September";} if ($FORM{emonth} eq "10"){$emonthname = "October";} if ($FORM{emonth} eq "11"){$emonthname = "November";} if ($FORM{emonth} eq "12"){$emonthname = "December";} open(FILE, "$logfile"); @infile = ; close(FILE); $count = 0; foreach $temp (@infile) { $count++; } if ($count ne 0) { $count--; } foreach $key (keys(%FORM)) { chop($key); $c = chop($key); if ($c eq '.') { $q = $key; } } if ($q eq "view_by_date" || $q eq "view_date_range" || $q eq "view_hits" || $q eq "") { $option = "chart"; } else { $option = "bars"; } print "$cginame $version statistics\n"; &template1; print "
\n"; print " 
\n"; if ($option eq "chart") { $credit = 0; $bad = "yes"; if ($q eq "view_by_date") { $bad = "no"; print "Hits for $monthname $FORM{spday}, $FORM{spyear}\n"; $stday=$endday=$FORM{spday}; $stmonth=$endmonth=$FORM{spmonth}; $styear=$endyear=$FORM{spyear}; $sthour=0; $stminute=0; $endhour=24; $endminute=00; } elsif ($q eq "view_date_range") { $bad="no"; while (length($FORM{spday}) > 2) { chop($FORM{spday}); } while (length($FORM{spyear}) > 2) { chop($FORM{spyear}); } $stday = $FORM{bday}; $stmonth = $FORM{bmonth}; $styear = $FORM{byear}; $endday = $FORM{eday}; $endmonth = $FORM{emonth}; $endyear = $FORM{eyear}; $sthour = 0; $stminute = 0; $endhour = 24; $endminute = 0; print "Hits from $bmonthname $FORM{bday}, $FORM{byear} to $emonthname $FORM{eday}, $FORM{eyear}\n"; } elsif ($q eq "view_hits") { $bad = "no"; $credit = $FORM{lhits}; print "Last $FORM{lhits} hits\n"; } elsif ($q eq "") { $bad = "no"; $credit = $starthits; print "Last $starthits hits\n"; } print "

\n"; if ($bad eq "no") { $count = 0; $combstartdate = ($styear * 100000000) + ($stmonth * 1000000) + ($stday * 10000) + ($sthour * 100) + $endminute; $combenddate = ($endyear * 100000000) + ($endmonth * 1000000) + ($endday * 10000) + ($endhour * 100) + $endminute; print "\n"; $cnt=0; foreach $lineofdata (@infile) { $cnt++; } for ($x = $cnt; $x>=1; $x--) { $lineofdata = $infile[$x]; &extract_logs; $httprefererlink = $httpreferer; chop($remotehost); $onoff = "off"; while (length($httprefererlink) >= 60) { chop($httprefererlink); $onoff = "on";} if ($onoff eq "on") { $httprefererlink = "$httprefererlink..."; } $recorddate = ($year * 100000000) + ($mon * 1000000) + ($mday * 10000) + ($hour * 100) + $min; if ($x eq $cnt && $credit > 0) { $i = "bad"; } if (($recorddate <= $combenddate && $recorddate >= $combstartdate) && $q ne "view_hits" && $q ne "") { $count++; $color="000088"; if (($count/2) eq int($count/2)) { $color="006666"; } print "
$count \n"; print "
  • WHEN:
  • $dayname, $fullmon $mday, $year at $hour:$min:$sec $ampm
  • BROWSER TYPE:  
  • $browsertype
  • SERVER (IP):
  • $remotehost ($remoteaddr)"; if ($remoteaddr eq "$ENV{'REMOTE_ADDR'}"){ print "   YOU"; } print "\n"; if ($httpreferer ne "") { print "
  • CAME FROM:
  • $httprefererlink\n"; } else { print "
  • CAME FROM:
  • an unknown address\n"; } print "
  • WENT TO:
     
  • $documenturi
     
    \n"; } elsif (($q eq "view_hits" || $q eq "") && $credit >= 1) { if ($x ne $cnt) { $credit--; $count++; $color="000088"; if (($count/2) eq int($count/2)) { $color="006666"; } print "
    $count \n"; print "
  • WHEN:
  • $dayname, $fullmon $mday, $year at $hour:$min:$sec $ampm
  • BROWSER TYPE:  
  • $browsertype
  • SERVER (IP):
  • $remotehost ($remoteaddr)"; if ($remoteaddr eq "$ENV{'REMOTE_ADDR'}"){ print "   YOU"; } print "\n"; if ($httpreferer ne "") { print "
  • CAME FROM:
  • $httprefererlink\n"; } else { print "
  • CAME FROM:
  • an unknown address\n"; } print "
  • WENT TO:
     
  • $documenturi
     
    \n"; } } } if ($count eq 0) { print "There were no hits within the selected time period.\n"; } print "
    \n"; } else { print "Sorry, you did not enter valid information. Please click the back button, recheck your information, and retry.\n"; } } elsif ($option eq "bars") { if ($q eq "view_page_hits"){print"Documents Viewed\n";foreach $lineofdata(@infile){&extract_logs;$labels{$documenturi}++;}} elsif ($q eq "browser_types"){print"Browser Types\n";foreach $lineofdata(@infile){&extract_logs;$labels{$browsertype}++;}} elsif ($q eq "view_hits_by_hour"){print"Overall Hits by Hours\n";foreach $lineofdata(@infile){&extract_logs;$labels{"$hour" . "  " . "$ampm"}++;}} elsif ($q eq "view_hits_by_day"){print"Overall Hits by Days\n";foreach $lineofdata(@infile){&extract_logs;$labels{$dayname}++;}} elsif ($q eq "view_hits_by_month"){print"Overall Hits by Months\n";foreach $lineofdata(@infile){&extract_logs;$labels{$fullmon}++;}} elsif ($q eq "referring_domains") { print "Domains of Referring URLs\n"; $thisaddr = $ENV{HTTP_HOST}; $len = length($thisaddr); for ($x = 1; $x <= $len; $x++) { $c = chop($thisaddr); $backwords = "$backwords" . "$c"; } ($one,$two,$a) = split(/\./, $backwords); $backwords = "$one" . "." . "$two"; $len = length($backwords); $forwards = ""; for ($x = 1; $x <= $len; $x++) { $c = chop($backwords); $forwards = "$forwards" . "$c"; } $thisaddr=$forwards; foreach $lineofdata (@infile) { &extract_logs; $backwords = ""; ($a, $a, $httpreferer, $a) = split(/\//, $httpreferer); $len = length($httpreferer); for ($x = 1; $x <= $len; $x++) { $c = chop($httpreferer); $backwords = "$backwords" . "$c"; } ($one,$two,$a) = split(/\./, $backwords); $backwords = "$one" . "." . "$two"; $len = length($backwords); $forwards = ""; for ($x = 1; $x <= $len; $x++) { $c = chop($backwords); $forwards = "$forwards" . "$c"; } if ($forwards ne "." && $forwards ne "$thisaddr") { $labels{$forwards}++; } } } elsif ($q eq "visitor_domains") { print "Visitor Domains\n"; foreach $lineofdata (@infile) { &extract_logs; chop($remotehost); $chp = chop($remotehost); $remotehost = "$remotehost" . "$chp"; if ($chp eq "" || $chp eq "0" || $chp eq "1" || $chp eq "2" || $chp eq "3" || $chp eq "4" || $chp eq "5" || $chp eq "6" || $chp eq "7" || $chp eq "8" || $chp eq "9") { $labels{'IP Address Only'}++; } else { $backwords = ""; $len = length($remotehost); for ($x = 1; $x <= $len; $x++) { $c = chop($remotehost); $backwords = "$backwords" . "$c"; } ($one,$two,$a) = split(/\./, $backwords); $backwords = "$one" . "." . "$two"; $len = length($backwords); $forwards = ""; for ($x = 1; $x <= $len; $x++) { $c = chop($backwords); $forwards = "$forwards" . "$c"; } $labels{$forwards}++; } } } print "


    \n"; $count=0; $totalvalue=0; foreach $key (keys(%labels)) { $count++; $label[$count]=$key; $value[$count]=$labels{$key}; $totalvalue=$totalvalue+$labels{$key}; } for ($i = 1; $i <= ($count-1); $i++) { for ($j = 1; $j <= ($count - %i); $j++) { if ($value[$j] < $value[$j+1]) { $temp = $value[$j+1]; $value[$j+1] = $value[$j]; $value[$j] = $temp; $temp = $label[$j+1]; $label[$j+1] = $label[$j]; $label[$j] = $temp; } } } print "\n"; print "\n"; print "\n"; for ($x = 1; $x <= $count; $x++) { if ($q eq "view_page_hits") { print "\n"; }elsif (($q eq "view_hits_by_hour") || ($q eq "view_hits_by_day") || ($q eq "view_hits_by_month") || ($q eq "browser_types")){ print "\n"; }else{ print "\n"; } } print "
     HITS  PERCENT  GRAPH

    $label[$x] $value[$x]",int($value[$x]/$totalvalue*1000)/10,"%  
    $label[$x] $value[$x]",int($value[$x]/$totalvalue*1000)/10,"%  
    \"whois $label[$x] $value[$x]",int($value[$x]/$totalvalue*1000)/10,"%  
    \n"; } print "

    \n";