#!/opt/local/bin/perl
$image_file = "../gfx/tracking.jpg";
#$image_file = "/dev/null";
$log_file = "cRyPtIcFiLeNaMe";
$show_title = "Stats for $ENV{'REMOTE_ADDR'}";
$omit_title = "Omitting $ENV{'REMOTE_ADDR'}";
$info = "Recorded by track, version 0.01, by Kevin Peterson";
if($ENV{'QUERY_STRING'} eq 'show') {
&record();
&show_log();
} elsif ($ENV{'QUERY_STRING'} eq 'sesame') {
&omit_log();
} else {
&record();
print "Content-type: image/jpeg\n\n";
open(IMAGE, $image_file) or $open_error = "an error occured: $!";
while ( read IMAGE, $buf, 16384) {
print $buf;
}
}
exit (0);
sub show_log() {
print "Content-type: text/html\n\n";
print "\n";
print "
$show_title\n";
print "\n$show_title
\n$info
\n\n";
if(open(LOG, $log_file)) {
while($line = ) {
if(index($line, $ENV{'REMOTE_ADDR'}) > 0) {
print $line;
}
}
} else {
print "an error occured |
\n";
}
print "\n
\n\n";
}
sub omit_log() {
print "Content-type: text/html\n\n";
print "\n";
print "$omit_title\n";
print "\n$omit_title
\n$info
\n\n";
if(open(LOG, $log_file)) {
while($line = ) {
unless(index($line, $ENV{'REMOTE_ADDR'}) > 0) {
print $line;
}
}
} else {
print "an error occured |
\n";
}
print "\n
\n\n";
}
sub record() {
($sec, $min, $hour, $mday, $mon, $year) = localtime(time);
if 0 {
#if(open(LOG, ">>$log_file")) {
printf LOG "%04d%02d%02d | ", $year + 1900, $mon + 1, $mday;
printf LOG "%02d:%02d:%02d | ", $hour, $min, $sec;
print LOG "$ENV{'REMOTE_ADDR'} | ";
print LOG "$ENV{'REMOTE_HOST'} | ";
print LOG "$ENV{'QUERY_STRING'} | ";
print LOG "$ENV{'HTTP_USER_AGENT'} | ";
print LOG "
\n";
close LOG;
}
}