#!/usr/bin/perl print "Content-type: text/html", "\n\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "

Raw

\n"; open(COUNTER,'counter/counter.txt'); print ""; while () { chomp(); if ($_ =~ /^[0-9][0-9]*$/) { $k=$_; $n=" "; } else { $k=$_; $k=~s/^.*=//; $n=$_; $n=~s/=.*$//; } print "\n"; #print "\n"; print "\n"; print "\n"; print "\n"; } close(COUNTER); print "
$_$k$n
\n"; print "
\n"; print "

Name

\n"; open(COUNTER,'counter/counter.txt'); @table=; close(COUNTER); print ""; #for($i=0;$i<$#table;$i++) { foreach(sort @table) { #$_=$table[$i]; chomp(); if ($_ =~ /^[0-9][0-9]*$/) { $k=$_; $n=" "; } else { $k=$_; $k=~s/^.*=//; $n=$_; $n=~s/=.*$//; } print "\n"; #print "\n"; print "\n"; print "\n"; print "\n"; if ($_ =~ /^[0-9][0-9]*$/) { while(length($_) < 20 ) { $_="0".$_; } } else { while(length($k) < 20 ) { $k="0".$k; } $_="$k"."="."$n"; } push(@table2, $_); } print "
$_$k$n
\n"; print "
\n"; print "

Kount

\n"; #@table2=@table; print ""; foreach(sort @table2) { #$_=$table[$i]; chomp(); if ($_ =~ /=/) { $_=~s/([0-9][0-9]*)=(.*)/$2=$1/; } if ($_ =~ /^[0-9][0-9]*$/) { $k=$_; $k=$k+0; $n=" "; } else { $k=$_; $k=~s/^.*=//; $n=$_; $n=~s/=.*$//; $k=$k+0; } print "\n"; #print "\n"; print "\n"; print "\n"; print "\n"; } print "
$_$k$n
\n"; print "
\n"; #print "

Dump Log File

\n"; #print ""; open(LOGIPADDRESS,'counter/ip_log.txt'); while () { #print "$_
"; #print "
\n"; # # allow comments in the log file # just skip over them # if ($_ =~ /^ *#/ ) { #continue; #print "skipping $_
"; goto sinfull; } # # split the record into # date, time, ip-address, and URL # ($d, $t, $ip, $url)=split(' ',$_); $ip3=$ip; $ip3=~s/\.[0-9]*$//; $hour=$t; $hour=~s/:.*$//; if ( $url =~ /^ *$/ ) { $url=" "; } else { $url=~s/.*/$&<\/a>/; } #print "\n"; #print "\n"; #print "\n"; #print "\n"; #print "\n"; # # count each unique date # if ($date{$d} eq "" ) { $date{$d}=1; } else { $date{$d}++; } # # count each unique URL # if ($urls{$url} eq "" ) { $urls{$url}=1; } else { $urls{$url}++; } # # count each unique IP address # if ($ips{$ip} eq "" ) { $ips{$ip}=1; } else { $ips{$ip}++; } # # count each unique 3 digit IP address # if ($ip3s{$ip3} eq "" ) { $ip3s{$ip3}=1; } else { $ip3s{$ip3}++; } # # count the hits in each hour # if ($hours{$hour} eq "" ) { $hours{$hour}=1; } else { $hours{$hour}++; } sinfull:; } close(LOGIPADDRESS); #print "
$d$t$ip$url
\n"; print "

Count by Date

\n"; print ""; foreach (keys %date) { print "\n"; print "\n"; print ""; print "\n"; } print "
$date{$_}$_
"; ##################################################### ##################################################### print "

Hits by Date

\n"; print "

This is from the file ip_log.txt and it is the number of hits your web site(s) received each day

\n"; print "

Sort Date is sorted by date, Count is sorted by the number of hits, Raw Date is how PERL stores the data internally in a hash and is for debugging

\n"; print ""; print ""; print ""; @datetable2=sort(@datetable); $i=0; print ""; @datetable3=sort(@kountdatetable); $i=0; print ""; print ""; print "
"; print "

Raw Date

\n"; print ""; @datetable=(); @kountdatetable=(); foreach (keys %date) { $datekount=$date{$_}; #while (length($datekount) < 10 ) { # $datekount="0".$datekount; #} $datekount=&add_leading_zeros($datekount,10); push(@datetable, $_.":".$date{$_}); push(@kountdatetable, $datekount.":".$_); print "\n"; print "\n"; print ""; print "\n"; } print "
$date{$_}$_
"; print "
"; print "

Sort Date

\n"; print ""; foreach (keys %date) { #foreach(sort @table2) { print "\n"; #print "\n"; #print ""; #print ""; ($k,$j)=split(':', $datetable2[$i]); #print ""; print ""; print ""; $i++; print "\n"; } print "
$date{$_}$_$datetable2[$i]$j $k$j$k
"; print "
"; print "

Count Date

\n"; print ""; foreach (keys %date) { #foreach(sort @table2) { print "\n"; #print "\n"; #print ""; #print ""; ($j,$k)=split(':', $datetable3[$i]); #print ""; #while ($j =~ /^0/) { # $j=s/^0//; #} $j=$j*1; print ""; print ""; $i++; print "\n"; } print "
$date{$_}$_$datetable3[$i]$j $k$j$k
"; print "
"; ##################################################### ##################################################### # # only print the count by URL after sorting # it by the number of hits on the URL # print "

Count by URL

\n"; print ""; foreach (keys %urls) { print "\n"; print "\n"; print ""; print "\n"; } print "
$urls{$_}$_
"; # # sort by the number of hits on the url's # grab the data # $kount=0; foreach (keys %urls) { $names[$kount]=$_; $values[$kount]=$urls{$_}; $kount++; } # # sort the puppies # $kount2=$kount; $changed="y"; while ($kount2 > 1 && $changed eq "y") { $changed="n"; for ($i=0;$i<$kount2;$i++) { #print "compare $i $kount2
"; # # if the 2nd count is greater # then the first counter then swap them # if ($values[$i] > $values[$i+1] ) { $temp=$values[$i]; $values[$i]=$values[$i+1]; $values[$i+1]=$temp; $temp=$names[$i]; $names[$i]=$names[$i+1]; $names[$i+1]=$temp; $changed="y"; } # # if the counters are equal # AND the second URL less then the first URL # then switch the URL's # if ($values[$i] == $values[$i+1] ) { if ($names[$i] gt $names[$i+1] ) { $temp=$names[$i]; $names[$i]=$names[$i+1]; $names[$i+1]=$temp; $changed="y"; } } } $kount2--; } print "

Count by URL hits

\n"; print ""; for ($i=0;$i<=$kount;$i++) { print "\n"; print "\n"; print ""; print "\n"; } print "
$urls{$names[$i]}$names[$i]
"; for ($i=0;$i<=24;$i++) { $zhour[$i]=0; } # # only print hours after sorting them # #print "

Count by Hour

\n"; #print ""; foreach (keys %hours) { #print "\n"; #print "\n"; $zhour[$_]=$hours{$_}; #print ""; #print "\n"; } #print "
$hours{$_}$_
"; print "

Count by Hour

\n"; print ""; $k=-12; $part="a.m."; $part2=""; for ($i=0;$i<=24;$i++) { if ($i == 12 ) { $part="p.m."; } if ($i > 12 ) { $part2=" $k p.m."; } if ($zhour[$i] != 0 ) { print "\n"; print "\n"; $x=""; if ($i < 10 ) { $x="0"; } print ""; print "\n"; } $k++; } print "
$zhour[$i]$x$i $part$part2
"; # # zero the table of IP to be sorted by number IP hits # and by IP address @iptable=(); @kountiptable=(); print "

Count by IP address

\n"; print ""; print ""; print ""; print ""; print ""; print ""; print "
"; print "Raw"; print ""; foreach (keys %ips) { # # get the count # $ipkount=$ips{$_}; # # convert the count into a 10 digit number so we can sort it # #while (length($ipkount) < 10 ) { # $ipkount="0".$ipkount; #} $ipkount=&add_leading_zeros($ipkount,10); #print "debug1x". $_.":".$ips{$_}; #print "debug2x". $ipkount.":".$_; # # convert the IP into 3 digits for each node so it sorts # $ips3=&lenthen_ip_address($_); # # save two versions - one with IP first - to be sorted by IP # one with hits first - to be sorted by hits push(@iptable, $ips3.":".$ips{$_}); push(@kountiptable, $ipkount.":".$ips3); # # dump out the data as it is coming to us # print "\n"; print "\n"; print ""; print "\n"; } print "
$ips{$_}$_
"; print "
"; print "IP Address"; # #sort by the IP address # print ""; foreach(sort @iptable) { ($k,$j)=split(':', $_); # # remove the leading zeros from the IP address before printing # $k=&shorten_ip_address($k); print "\n"; } print "
$j$k
"; print "
"; print "Kount"; # # sort by the number of hits per IP address # print ""; foreach(sort @kountiptable) { ($k,$j)=split(':', $_); # # the next RE is OK because we will never have (0) zero hits # $k=~s/^0*//g; # # remove the leading zeros from the IP address # $j=&shorten_ip_address($j); print "\n"; } print "
$k$j
"; print "
"; print "

Count by 1st 3 bytes of IP address

\n"; print ""; foreach (keys %ip3s) { print "\n"; print "\n"; print ""; print "\n"; } print "
$ip3s{$_}$_
"; exit; sub shorten_ip_address() { # # remove the leading zeros in an IP address # 001.001.001.001 -> 1.1.1.1 # 099.099.099.099 -> 99.99.99.99 # 100.099.099.001 -> 100.99.99.1 # 100.099.001.001 -> 100.99.1.1 # my $oldip=@_[0]; my $j=$oldip; #print "oldip=$oldip
"; # # remove leading zeros from the first digit of the IP address # $j=~s/^00([0-9])\./$1./; $j=~s/^0([0-9][0-9])\./$1./; # # remove leading zeros from the middle two digits of the IP address # for some reason the s///g doesnt work # $j=~s/\.00([0-9])\./.$1./; $j=~s/\.00([0-9])\./.$1./; $j=~s/\.0([0-9][0-9])\./.$1./; $j=~s/\.0([0-9][0-9])\./.$1./; # # remove leading zeros from the last part of the IP address # $j=~s/\.00([0-9])$/.$1/; $j=~s/\.0([0-9][0-9])$/.$1/; #print "j=$j
"; return $j; } sub lenthen_ip_address() { # # remove the leading zeros in an IP address # 1.1.1.1 -> 001.001.001.001 # 99.99.99.99 -> 099.099.099.099 # 100.99.99.1 -> 100.099.099.001 # 100.99.1.1 -> 100.099.001.001 # my $oldip=@_[0]; my $ips3=$oldip; #print "ips3=$ips3
"; # # convert the last ip digit from # 0 -> 000 # 10 -> 010 # xxx -> no change # $ips3=~s/(\.)([0-9])$/.0$2/; $ips3=~s/(\.)([0-9][0-9])$/.0$2/; # # do the middle two digits # for some reason s///g did not work # so i had to use two s///'s # $ips3=~s/(\.)([0-9])(\.)/.0$2./; $ips3=~s/(\.)([0-9])(\.)/.0$2./; $ips3=~s/(\.)([0-9][0-9])(\.)/.0$2./; $ips3=~s/(\.)([0-9][0-9])(\.)/.0$2./; # # convert the first IP digit # $ips3=~s/^([0-9])\./0$1./; $ips3=~s/^([0-9][0-9])\./0$1./; #print "ips3=$ips3
"; return $ips3; } sub add_leading_zeros() { # # convert an integer to a long number with leading zeros so we can sort it as ascii text # my $num=@_[0]; my $digits=@_[1]; #print "in=$num
"; if ($digits !~ /^[0-9][0-9]*$/ ) { print "error digits must be numeric. digits='$digits'
\n"; } if ($digits < 1 ) { print "error digits must be one or more. digits='$digits'
\n"; } while(length($num) < $digits ) { $num="0".$num; } #print "out=$num
"; return $num; }