#!/usr/local/bin/perl # ============================================================================ # # Stat # Stat is a little hitcount/stats program that masquerades as a GIF image # ============================================================================ # # ============================================================================ # # Configuration # ============================================================================ # # THESE TWO VARIABLES MUST BE MODIFIED # Unless you're using the exact same files and directories I am for your site # statFile is the server path of the statistics file you want to record to my $statFile = 'cgi-bin/lameduckie/stat.txt'; # imageFile is the server path of the image file you want the script to send back my $imageFile = 'lameduckie/img_logo.gif'; # mimeType MUST reflect the type of image specified in imageFile # Do not change if you're using a gif format file, otherwise replace with the # appropriate format type from the two below: # image/jpeg # image/png my $mimeType = 'image/gif' # ============================================================================ # # Program - Don't mess! # ============================================================================ # use strict; use Socket; &writeImage; &writeStat; sub writeImage { print "Content-type: text/gif\n\n"; #MIME header for web server my $buf; open (IMAGE, $imageFile); # binmode is for the benefit of retarded NT servers binmode (STDOUT); binmode (IMAGE); print $buf while (read(IMAGE, $buf, 1024)); close (IMAGE); } sub writeStat { open(STATFILE, ">>$statFile"); my ($curTime, $date) = &getDate; # Try to get a textual host name my $host = gethostbyaddr(inet_aton($ENV{'REMOTE_HOST'}), AF_INET); print STATFILE "$curTime, $date\n"; print STATFILE "HOST: $host\n"; print STATFILE "REMOTE_HOST: $ENV{'REMOTE_HOST'}\n"; print STATFILE "HTTP_USER_AGENT: $ENV{'HTTP_USER_AGENT'}\n\n"; close STATFILE; } sub getDate { # Arrays for the days & months my @shortdays = ("Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat"); my @days = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); # Snag the current time my ($sec,$min,$hr,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); # Fix the current time $year = $year + 1900; if ($sec < 10) {$sec = "0".$sec;} # Add a second digit to seconds less than 10 if ($min < 10) {$min = "0".$min;} if ($hr >= 12) {$hr = $hr - 12; $sec = $sec."PM"; if ($hr == 0) {$hr = 12;}} # Covert to 12-hour scale else {$sec = $sec."AM"; if ($hr == 0) {$hr = 12;}} my $curTime = "$hr:$min:$sec"; my $date = "$shortdays[$wday], $months[$mon] $mday, $year"; return ($curTime, $date); }