#!/usr/bin/perl -w use CGI qw(:standard); use Time::localtime; use Time::Local; print header(-type => "image/gif", -expires => "+1d"); print "GIF89a\x01\x00\x01\x00\x80\x00\x00\xff\xff\xff\x00\x00\x00\x21\xf9\x04\x01\x00\x00\x00\x00\x2c\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3b"; # update hit stats file my $file = "data/counter.data"; my $now_stamp = time; my $now = localtime($now_stamp); my $early_today_stamp = timelocal(0, 0, 0, $now->mday, $now->mon, $now->year); if ((!(-f $file)) || (-M $file > (($now_stamp-$early_today_stamp)/(24*60*60)))) { my $year = $now->year+1900; my $month = $now->mon+1; my $day = $now->mday; if ($month < 10) {$month = "0$month";} if ($day < 10) {$day = "0$day";} AppendFile($file, "\n$month/$day/$year ."); } else { AppendFile($file, "."); } # update user stats file local @browser_types; local @browser_count; local @host_types; local @host_count; $file = "data/user.data"; my $toappend = ""; ParseReferFile($file); my $browser = $ENV{HTTP_USER_AGENT}; if ($browser ne "") { my $thisnum = -1; for (my $n=0; $n<=$#browser_types; $n++) { my $type = $browser_types[$n]; if (lc($browser) eq lc($type)) {$thisnum = $n;} } if ($thisnum < 0) { $toappend .= "b\t$browser\n"; } else { $toappend .= "+b$thisnum\n"; } } my $host = $ENV{REMOTE_HOST}; if ($host ne "") { my $thisnum = -1; for (my $n=0; $n<=$#host_types; $n++) { my $type = $host_types[$n]; if (lc($host) eq lc($type)) {$thisnum = $n;} } if ($thisnum < 0) { $toappend .= "h\t$host\n"; } else { $toappend .= "+h$thisnum\n"; } } if ($toappend ne "") { AppendFile($file, $toappend); } sub ParseReferFile { foreach my $line (split(/\n/, ReadFile($_[0]))) { if ($line =~ /^\+b(\d+)$/) { $browser_count[$1]++; } elsif ($line =~ /^\+b(\d+)\+(\d+)$/) { $browser_count[$1] += $2; } elsif ($line =~ /^b\t(.*)/) { push(@browser_types, $1); $browser_count[$#browser_types] = 1; } elsif ($line =~ /^\+h(\d+)$/) { $host_count[$1]++; } elsif ($line =~ /^\+h(\d+)\+(\d+)$/) { $host_count[$1] += $2; } elsif ($line =~ /^h\t(.*)/) { push(@host_types, $1); $host_count[$#host_types] = 1; } } } sub ReadFile { # USAGE: $file_contents = ReadFile($file_name); unless (open(FILE,"< $_[0]")) {return 0;} my $readin = join "", ; close FILE; $readin =~ s/\r//g; return ($readin); } sub AppendFile { # USAGE: AppendFile ($filename, $contents) my $data = $_[1]; unless (open(FILE,">> $_[0]")) {return 0;} print FILE $data; close FILE; return 1; }