#!/bin/perl
use CGI qw(:standard);
##########################################
##
## EDIT THIS SECTION ONLY to suit your requirements
##
##
##
$CounterFile = "/u/twma/WWW/free/2ma2/counter";
$LogFile = "/u/twma/WWW/free/2ma2/visitors.log";
$MAXLOGSIZE = 50;
$MailTo = "twma";
$TWMAIP = "130.95.16.89";
$LECTURES = "/u/twma/WWW/free/2ma2/lectures";
$WORKSHOPS = "/u/twma/WWW/free/2ma2/workshops";
$ErrorMessage = qq/
<\/head>
Sorry, we are experiencing some technical difficulties....
Please try again soon.
<\/body><\/html>
/;
##############################################
$remote = $ENV{'REMOTE_ADDR'};
$host = $ENV{'REMOTE_HOST'};
print header;
open(COUNTERFILE, "+<$CounterFile") ||
(print $ErrorMessage) &&
`Mail -s "Web Error: can't open counter file" $MailTo < /dev/null` &&
close(COUNTERFILE) &&
exit;
($count,$lastip) = split(/:/,);
chomp $lastip;
if (($remote ne $TWMAIP) && ($remote ne $lastip )) {
$count++;
seek(COUNTERFILE,0,0);
print COUNTERFILE $count,":",$remote;
close(COUNTERFILE);
open(LOGFILE,"+<$LogFile") ||
(print $ErrorMessage) &&
`Mail -s "Web Error: can\'t open log file" $MailTo < /dev/null` &&
close(LOGFILE) &&
exit;
$i=0;
while () {
$logentry[$i++] = $_;
}
$start = $i - $MAXLOGSIZE + 1;
$start = 0 if ( $start < 0 );
seek(LOGFILE,0,0);
for ($j=$start; $j<=$i; $j++) {
print LOGFILE $logentry[$j];
}
$date = localtime();
print LOGFILE "$count\t$date\t$remote\t$host\n";
truncate(LOGFILE,tell(LOGFILE));
close(LOGFILE);
} else {
close(COUNTERFILE);
}
print start_html('main page');
print <
You are number $count visitor. Please click here to view the
recent visitors.
EOF
print `cat $LECTURES`;
print `cat $LECTURES.tab`;
print `cat $WORKSHOPS`;
print `cat $WORKSHOPS.tab`;
print end_html;