Host Log
2002-05-13 18:21:50
Category: perl:cgi
Description: This is an example of how to descretely log the ip, date, and time users accessed your website.
Author: Snap
Viewed: 2319
Rating: (1 votes)


#!/usr/bin/perl
 
##########################################
#                                        #
#   Written by Snap                      #
#           (iam@someoneshouse.com)      #
#                                        #
#   For Metalshell                       #
#       http://www.metalshell.com        #
#                                        #
#  This is an example of how to          #
#  descretely log user information as    #
#  they come in on your web site.  All   #
#  information is logged for private     #
#  viewing, with minimal output to the   #
#  user.  This can be easily             #
#  customized/changed.                   #
##########################################
 
#Change the following to the path/name you want the counter to be
$cFile="cgi-bin/counterfile";
 
#Change the following to the path/name you want your users info stored
$logFile="cgi-bin/logfile";
 
#Just the basic counter, can be used in conjunction with
#the "counter" example
open(OFILE,"$cFile");
$ctr=<OFILE>;
$ctr++;
close(OFILE);
 
open(WFILE,">$cFile") || `cat /dev/null > $cFile;chmod 666 $cFile`;
print WFILE $ctr;
close(WFILE);
 
#Change this to whatever date variables you want to pass
#but remember to change the search strings accordingly
#currently to set to format "DayofWeek Month Day Year"
$date=`date +%A%t%B%%%d%t%Y`;
$date=~s/       /, /gi;
$date=~s/%/ /gi;
 
#Again, this is customizeable
#current settings: 12hour format "hour:minute am/pm"
$time=`date +%l%%%M%t%p`;
$time=~s/%/:/gi;
$time=~s/       / /gi;
 
#Get rid of annoying returns(asthetics)
chomp $date;
chomp $time;
 
#Record to your log File
open(LOGGER,">>$logFile") || `cat /dev/null > $logFile;chmod 666 $logFile`;;
print LOGGER "\nNumber $ctr showed up on $date at $time from $ENV{REMOTE_ADDR}\n";
close(LOGGER);
 
#Checks to see if host can be resovled
$res=$ENV;
if($res eq ""){
$response="";
}elsif($res ne ""){
$response="Resolved: $res";
}
 
#This is the only output from the script, just to let them know you're watching
print "<center>You have been logged from: $ENV{REMOTE_ADDR}<br>$res</center>";