#!/usr/local/bin/perl ################################################################## # # pixel logger Version 1.1 # # Written By : Sammy Afifi sammy@technotrade.com # Date Last Modified : 5/17/1999 # # Logs the current date, time, username, host, IP address # Script is called by placing it in an IMG SRC tag # # Ex : IMG SRC="pixel.cgi" width=1 height=1 # # After logging, it reads pixel.gif and returns it to the user's browser # # * Option to send e-mail when user logs in # * turn on/off pixel.gif caching # * logging can be turned on/off # * can log everything to one file or a daily YYYYMMDD.txt file # * sends the Referer, Browser version via e-mail # ################################################################## ################################################################## # base directory on server to place log files "" for current dir. # # This is a server path (not a url http://) $basedir = ""; ################################################################## # You may need to create this file ahead of time and chmod it to 666 # # used if you select log type 1 # $filename = "users.txt"; ################################################################## # You may need to chmod the directory where log files will be placed to 666 # # used for log type 2 # $dfilename = &time_to_string(time,2) . ".txt"; $logtype = 1; # 0 = don't log to file # 1 = log all hits to 1 file # 2 = log all hits to a daily file $mailprog = '/usr/sbin/sendmail'; # where sendmail is on your server. # don't know ? ask your ISP # some servers : /usr/sbin/sendmail # also try /bin/sendmail ################################################################## # pixel.gif caching # # if you select no caching then each time the user goes to # the page with pixel.cgi on it, they'll be forced to reload # the script, which means it will log the hit (if you selected logging) # and will e-mail you again (if you selected email). This can # sometimes become a nuisance because even if the user select # on their browser, it will force a reload of pixel.cgi # $cacheimage = 1; # 0 = no caching # 1 = caching enabled ################################################################## # You can also have pixel.cgi send you an e-mail when a member logs # in to your protected area # # Another option is to have it send you an ICQ message by using # your ICQ mail address (ICQ#@pager.mirabilis.com) # # $sendemail = 1; # 0 = don't send e-mail, 1 = send mail $emailto = 'info@loopasonic.com'; $emailfrom = 'info@loopasonic.com (premium logins)'; $emailsubject = 'login at loopasonic Premium'; $pixelgif = "pixel.gif"; # location of the pixel.gif file # the path to the .gif file (not the URL) # use "pixel.gif" if it's in the same directory # as the cgi script ################################################################## # # no need to change anything beyond this line # $logfilename = $basedir . $filename if ($logtype == 1); $logfilename = $basedir . $dfilename if ($logtype == 2); $user = $ENV{'REMOTE_USER'}; $mytime = &time_to_string(time,1); if ($logtype > 0) { open(S,">>$logfilename"); flock(S,2); print S "$mytime | $user | $ENV{'REMOTE_HOST'}|$ENV{'REMOTE_ADDR'}\n"; close(S); } if ($sendemail) { &send_email(" Time : $mytime Username : $user Host : $ENV{'REMOTE_HOST'} IP : $ENV{'REMOTE_ADDR'} Referer : $ENV{'HTTP_REFERER'} Browser : $ENV{'HTTP_USER_AGENT'} "); } print "Content-type: image/gif\n"; if ($cacheimage == 0) { print "Expires: \n"; print "Pragma: no-cache\n"; } print "\n"; open(P,"$basedir$pixelgif"); while ($line =

) { print $line; } close(P); ########################################################### sub time_to_string { local($ct,$ttype) = @_; $timedifference = 10800; local($sec,$min,$hour,$mday,$mon,$yday,$wday,$isdst) = localtime($ct - $timedifference); $min = "0" . $min if ($min < 10); $hour = "0" . $hour if ($hour < 10); $mon++; $sec = "0" . $sec if ($sec < 10); $mon = "0" . $mon if ($mon < 10); $mday = "0" . $mday if ($mday < 10); $yday = 1900 + $yday; return("$yday/$mon/$mday $hour:$min:$sec") if ($ttype == 1); return("$yday$mon$mday") if ($ttype == 2); } #################################################### sub send_email { local($extratext) = @_; open(MAIL, "|$mailprog -t") || &printdie("Can't open $mailprog!\n"); print MAIL "To: $emailto\n"; print MAIL "From: $emailfrom\n"; print MAIL "Subject: $emailsubject\n\n"; print MAIL "$extratext\n"; close(MAIL); } #################################################### sub printdie { local($pd) = @_; print "Content-type: text/plain\n\n\n"; print $pd; exit; }