#!/usr/local/bin/perl # You may have to change the line above to refer to where perl # is located on your system. At the Unix prompt, type whereis perl # and a list of locations of perl on your server will be shown. # Change the line above to match one of those locations. ###################################################################### # # (C) Copywrite 1999 Volatile Graphix, Inc. All rights reserved. # This script may not be copied or modified in any way without # permission in writing from Volatile Graphix, Inc. # ###################################################################### ###################################################################### # # Change $normal to equal the name of the page you wish to redirect # normal people to. If it is in a different directory than this file, # include the relative path # AAC - This CGI lives in /FORD/ use ../ to move up one level $normal = "../ford-trucks.html"; # If you change the name of the data directory, make $writedir equal # to the new name $writedir = "data"; ###################################################################### ############# NO EDITING NECESSARY BELOW HERE ######################## ############# NO EDITING NECESSARY BELOW HERE ######################## ############# NO EDITING NECESSARY BELOW HERE ######################## ###################################################################### $enginelist = "engine.list"; $loc = "http://" . $ENV{'SERVER_NAME'}; $myname = $ENV{'SCRIPT_NAME'} . "l"; # the letter l not the number 1 $myname =~ s/^\/.*\///; $gethost = "$ENV{'REMOTE_HOST'}"; $getaddr = "$ENV{'REMOTE_ADDR'}"; $ref = "$ENV{'HTTP_REFERER'}"; $localdirectory = $ENV{'SCRIPT_NAME'}; $localdirectory =~ s/^(.+)\/.+\.htm$/$1/; if ($localdirectory =~ /\.htm$/) { $localdirectory =~ s/.+.htm$//; } @exclude = ("204.123.9.65", # @exclude is for certain applications "204.123.9.66", # sponsored by search engines such "204.123.9.67", # as Babelfish that translate pages into "204.123.9.68", # other languages and display them. You "204.123.9.106", # don't want humans seeing this, so I "204.123.9.107",); # made an exclude list. if ($gethost eq "") { $gethost = $getaddr; } open (ENGINELIST, "$writedir\/$enginelist"); flock(ENGINELIST, 2); @enginelist=; flock(ENGINELIST, 8); close (ENGINELIST); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); # set time if (length ($min) eq 1) {$min= '0'.$min;} $mon++; $date="$mon/$mday/$year, $hour:$min"; # MAIN PROGRAM ###################################################################### ###################################################################### # Detect if requestor is a robot or a normal person &detect; # Display normal page to normal person or entrance page to robot if ($isRobot eq 1) { &robot; } else { &normal; } exit; ###################################################################### # DETECT IF REQUESTOR IS ROBOT OR NORMAL ###################################################################### ###################################################################### sub detect{ $isRobot = 0; foreach $line (@enginelist) { chomp $line; if (($gethost =~ /$line/i) or ($getaddr =~ /$line/i)) { $isRobot = 1; if ($gethost =~ /babelfish/i) { $isRobot = 0; } foreach $ip (@exclude) { if ($getaddr =~ /$ip/i) { $isRobot = 0; } } } } } ###################################################################### # SERVE NORMAL PAGE TO NORMAL REQUESTOR ###################################################################### ###################################################################### sub normal{ # Obtain the normal page HTML open (NORMAL, "<$normal") or &cantFindNormal; flock(NORMAL, 2); @HTML = ; flock(NORMAL, 8); close (NORMAL); # Log the access open (ACCESSLOG, "<$writedir/access.log"); flock(ACCESSLOG, 2); @accesslog = ; flock(ACCESSLOG, 8); close (ACCESSLOG); open (ACCESSLOG, ">$writedir/access.log"); flock(ACCESSLOG, 2); print ACCESSLOG " $date -- $gethost -- $myname -- $ref\n"; $count=1; foreach $occurance (@accesslog){ print ACCESSLOG $occurance; last if $count eq 10000; $count++; } flock(ACCESSLOG, 8); close (ACCESSLOG); # Display the HTML print STDOUT "Content-type: text/html\n\n"; print STDOUT "\n"; print STDOUT @HTML; } ###################################################################### # SERVE ROBOT PAGE TO ROBOT REQUESTOR ###################################################################### ###################################################################### sub robot{ # Obtain the entrance page HTML open (ROBOT, "<$writedir/$myname"); flock(ROBOT, 2); @HTML = ; flock(ROBOT, 8); close (ROBOT); # Get list of URLs from data directory opendir (LIST, "$writedir"); @urls = readdir(LIST); closedir (LIST); splice (@urls, 0, 2); # Log the access open (ACCESSLOG, "<$writedir/access.log"); flock(ACCESSLOG, 2); @accesslog = ; flock(ACCESSLOG, 8); close (ACCESSLOG); open (ACCESSLOG, ">$writedir/access.log"); flock(ACCESSLOG, 2); print ACCESSLOG "\# $date -- $gethost -- $myname -- $ref\n"; $count=1; foreach $occurance (@accesslog){ print ACCESSLOG $occurance; last if $count eq 10000; $count++; } flock(ACCESSLOG, 8); close (ACCESSLOG); # Display the HTML print STDOUT "Content-type: text/html\n\n"; print STDOUT @HTML; print STDOUT "\n

\n\n"; foreach $listing (@urls){ if ($listing =~ /.html$/){ $listing =~ s/.html$/.htm/; print STDOUT "$loc$localdirectory/$listing
$loc$localdirectory/$listing
\n"; } } } ###################################################################### # ERROR MESSAGE IF SCRIPT CAN'T FIND NORMAL PAGE ###################################################################### ###################################################################### sub cantFindNormal{ # Log the access open (ACCESSLOG, "<$writedir/access.log"); flock(ACCESSLOG, 2); @accesslog = ; flock(ACCESSLOG, 8); close (ACCESSLOG); open (ACCESSLOG, ">$writedir/access.log"); flock(ACCESSLOG, 2); print ACCESSLOG "E $date -- $gethost -- $myname -- $ref\n"; $count=1; foreach $occurance (@accesslog){ print ACCESSLOG $occurance; last if $count eq 10000; $count++; } flock(ACCESSLOG, 8); close (ACCESSLOG); $myname =~ s/^\///; $myname =~ s/l$//; # Display the HTML print STDOUT "Content-type: text/html\n\n"; print STDOUT "\n"; print STDOUT "Error\n\n"; print STDOUT "

Error

\n"; print STDOUT "

$myname does not exist in this directory.

\n\n"; print STDOUT ""; exit; } ######################################################################