#!/usr/bin/perl # Daily Log (c) - 1999, Eastwright Corporation # Release 2.01 # Eastwright Internet Services: http://www.eastwright.com/internet/ # # Installation: # 1. Change first line to full pathname of perl program # 2. Change $mailprog variable to full pathname of sendmail program # 3. Change $admin variable to your email address # 4. Change $subject, $from, $logdata, $hitsfile variables if needed # 5. Upload log.pl to your WEB server # 6. Set permissions for log.pl to 755 and for directory it resides to 777 # 7. Include the following HTML code into the WEB page you want log for: # # where pathtolog - path to the log.pl script. # 8. Wait for log report to arrive into your mailbox - it will be sent upon # first hit after your server's midnight... # 9. Let us know how do you like this script :o) # # Eastwright Internet Services # eis@eastwright.com # ========================================= the variables you must edit # Email address to send daily logs to $admin="you\@somedomain.com"; # =====================================the variables you may have to edit # Full path to sendmail $mailprog = '/bin/sendmail'; # =====================================the variables you may want to edit # Subject for your daily log emails $subject = "Hits log for My Site"; # ============================= the variables you probably leave as they are # File name to store configuration data # make sure there is no file with the same name $logdata='logdata.log'; # File name to store daily hits log # make sure there is no file with the same name $hitsfile='hits.log'; # Email address which will appear as sender's address in your # daily log emails $from = $admin; # ============================= the code, let it work as it is.... # ======================================================= main $time = `date +"%T %Z"`; chop ($time); $date=`date +"%D"`; chop($date); $date=~ s/\//-/g; print "Content-type:\ text/plain\n\n "; if (!open(LOG, "<$logdata")) { open(LOG, ">$logdata") || die; print LOG "$date\n"; close(LOG); &inithits; } else { $prevhitdate = ; close(LOG); chop($prevhitdate); if ($prevhitdate ne $date) { open(LOG, ">$logdata") || die; print LOG "$date\n"; close(LOG); &mailhits; &inithits; } } open(HITS, ">>$hitsfile") || die; print HITS "Time: $time "; print HITS "Host: $ENV{'REMOTE_HOST'} "; print HITS "Addr: $ENV{'REMOTE_ADDR'} "; print HITS "Page: $ENV{'HTTP_FROM'} "; print HITS "From: $ENV{'HTTP_REFERER'}\n"; close(HITS); print " "; exit; # ======================================================= inithits sub inithits { open(HITS, ">$hitsfile") || die; print HITS "Hits for $date\n"; close(HITS); } # ======================================================= mailhits sub mailhits { open(HITS, "<$hitsfile") || die; @hits = ; close(HITS); open (MAIL, "|$mailprog -t") || die; print MAIL "To: $admin\n"; print MAIL "From: $admin\n"; print MAIL "Subject: $subject\n"; # print MAIL "$date\n"; print MAIL "-" x 75 . "\n\n"; foreach $line(@hits) { print MAIL "$line"; } print MAIL "======================================\n"; print MAIL "Have a nice day!\nEastwright Internet Service (www.eastwright.com)\n"; print MAIL"\n\n"; close (MAIL); }