#!/export/home/ubdocs/cgibin/perl5/bin/perl # weblog.cgi # # Version 2.03 -- 27 Jan 1997 # http://www.all-yours.net/scripts/ # Perl (release 4 or 5) script for Unix servers # This script saves access date+time, the visitor's host name, their IP # address and browser type, and the refering page (if any) to a log file # on your server (default name = logfile.txt). This file will be automatically # mailed to your mailbox. You can change the mailing interval according # to your needs (default value is every 50 accesses to the page to be # logged). The script will autocreate the logfile, if it does not exist. # ----- BEGIN INSTALLATION INSTRUCTIONS ----- # - Save this script to a file mail-log.cgi # - Cut installation instructions (optional) # - Change the first script line, if your server's Perl executable # is not located in /usr/local/bin/perl # - Customize the settings below (*SETTINGS*) # * Change e-mail address for $recipient # * Set $log_page to 1 if you also want to log the page that # called this script. Recommended in case you want to log accesses # to more than one HTML page. # * Set $max_entries to your needs, if you want to have more or less # than 50 log entries mailed to your mailbox each time. # * Change path/filename for log file, if necessary # (default = logfile.txt in your cgi directory) # * Change values for $check_host and $interval, if necessary # * Change filename for host/time file, if necessary (default = hosttime.txt) # - ASCII-upload mail-log.cgi to your cgi directory (cgi-bin, cgi-local...) # Make it executable (chmod mail-log.cgi 755) # - add the following line (Server Sde Include) to the page(s) to be logged # (after the
tag): # # HTML pages with Server Side Include tags often need to have the # file extension ".shtml" !!!! (don't forget to update # all links to this page(s) accordingly) # (You should test the script with a test.shtml page first) # - Load the logged page(s) with your browser. # - View your new logfile # It should look something like this: # # Time: 05/30/96 14:44:07 EDT # Host: your.host.and.domain # Addr: 123.45.67.89 # With: Mozilla/1.22 (compatible; MSIE 2.0; Windows 95) # Page: test.shtml # From: [no entry here, if you accessed your page directly (otherwise Yahoo etc.)] # ----- END INSTALLATION INSTRUCTIONS ----- # ----------------------------------------------------------------------- # *SETTINGS* to customize this script: # Do you want the log to be mailed to you ? # 1 = mail the log to me # 0 = do not mail the log to me $enable_mail = 0; # Your email address (within single quotes!): $recipient = 'matanya@cse.bridgeport.edu'; # Do you want to log your visitor's IP number? # The script attemps to call a domain name server in order to resolve # IP addresses (such as 132.45.323.5) to a host name (such as yourdomain.com) # However, resolving IP addressses doesn't work 100 per cent so you # might also want to log rhe IP addresses. # 1 = IP addresses will be logged # 0 = IP addresses will be discarded $log_IP = 1; # Number of logged visits mailed to your mailbox at a time: $max_entries = 50; # Change logfile name if necessary: $logfile = 'weblog/logfile.txt'; # server's sendmail directory: $mailprogam = '/usr/lib/sendmail'; # If you set $check_host = "1" the script attempts not # to log multiple page reloads. # When a page was accessed from the same host by using the same # browser, this visit will only be logged after the time # interval specified in $interval. # Example: You set $interval to 1800 (seconds). If there was no # access from a different host in the meantime, a visitor from the # same host who uses the same browser will only be logged when s/he # accesses your page 30 minutes after visitor one. # In other words: If someone reloads the page many times, in most cases # s/he needs to wait 30 minutes after each reload to make your log file # grow. When you set $check_host to 0 even the reloads will be logged. $check_host = 1; # set to zero if you don't like this feature # If you set the $check_host variable to 1, specify a time interval to # ignore page reloads $interval = 600; # seconds! # If you set the $check_host variable to 1, change the name of the file # that temporarily stores host and time information (if necessary) $hostfile = 'weblog/hostfile.txt'; # this is the dummy gif file that will be shown when the script will # start. $dumimage = 'weblog/dummy.gif'; # don't change anything past this line unless you know what you are doing # ----------------------------------------------------------------------- # create a date+time string ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); if ($sec < 10) { $sec = "0$sec"; } if ($min < 10) { $min = "0$min"; } if ($hour < 10) { $hour = "0$hour"; } if ($mon < 10) { $mon = "0$mon"; } if ($mday < 10) { $mday = "0$mday"; } $month = ($mon + 1); $shortdate = "$month/$mday/$year $hour\:$min\:$sec"; # Some of Perl's network info functions required here ($part1,$part2,$part3,$part4)=split(/\./,$ENV{REMOTE_ADDR}); $IP_adr=pack("C4",$part1,$part2,$part3,$part4); ($host_name)=(gethostbyaddr("$IP_adr", 2)); print "Content-type: image/gif\n\n"; open(PIC, $dumimage); print