#!/perl/bin/perl #/usr/local/bin/perl # Use as
# the 'who' opens a unique log file, which should exist beforehand # logfile must not be in cgi-bin for some servers to handle it # properly my $picfile = "smiley.gif"; my $date = gmtime(); @pairs = split(/&/, $ENV{QUERY_STRING}); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ tr/\r\n|//d; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $input{$name} = $value; } my $trackerlog="tracker.log"; if (exists $input{'who'}) { $trackerlog= "../logs/" . $input{'who'} . ".log" ; #thats the log file delete $input{'who'}; #don't need it anymore } if (exists $input{'pic'}) { $picfile = "../images/" . $input{'pic'}; #change the graphic delete $input{'pic'}; #don't need it anymore } if (open(LOGFILE,">>$trackerlog")) { #Note: silent on failure # while ( not flock(LOGFILE,2)) {sleep(1);} print LOGFILE "$date|$ENV{'REMOTE_HOST'}|$ENV{'HTTP_REFERER'}|$ENV{'HTTP_USER_AGENT'}"; while (($key,$val)=each %input) { print LOGFILE "|$key=$val"; } print LOGFILE "\n"; close (LOGFILE); } else {$picfile="none";} binmode( STDOUT ); print "Content-type:image/gif\n\n"; open(PIC,"+<$picfile") or die "can't find $picfile\n"; binmode PIC; @picdata = ; print @picdata; close PIC; 1