#!/usr/bin/perl # Apache Guardian, Version 1.0 # Copyright 1997 by Fluid Dynamics # You are free to use the script, but please ask before you # distribute it. # # For latest version and help files, visit: # http://www.xav.com/scripts/guardian # __________________________________________________________________ # Enter your email address: $email = 'lakehouse@lakehouse.com'; # Enter the URL of your main page: $main_page = '/'; # Enter the URL to your search page, if you have one. If not, just # delete this line: $search_page = '/cgi-bin/search.cgi'; # Enter the location of sendmail on your system if it differs from # the default: $mailprog = '/usr/sbin/sendmail'; # No further editing is necessary, but feel free to play around... # # __________________________________________________________________ # First label the error: $code = "Mysterious Reason"; $code = "Lost File" if ($ENV{'QUERY_STRING'} eq '404'); $code = "Restricted Access" if ($ENV{'QUERY_STRING'} eq '401'); $code = "Failed Script" if ($ENV{'QUERY_STRING'} eq '500'); # Next mail a summary to the site administrator: open(MAIL,"|$mailprog -t"); print MAIL "To: $email\n"; print MAIL "From: guardian\@xav.com (Apache Guardian)\n"; print MAIL "Subject: Guardian Report [$code]\n"; print MAIL "X-Priority: 1 (Highest)\n\n"; print MAIL "Flags tripped for attempted access to $ENV{'REDIRECT_URL'}\n"; print MAIL "by $ENV{'REMOTE_HOST'}.\n\n"; if ($ENV{'HTTP_REFERER'}) { @terms = split(/\//,$ENV{'HTTP_REFERER'}); print MAIL "Visitor linked in from $ENV{'HTTP_REFERER'}. "; print MAIL "You may wish to contact the administrator of $terms[0]//$terms[2].\n\n"; } else {print MAIL "No referring URL was logged in association with this visit.\n\n";} print MAIL "Details follow:\n\n"; foreach $key (sort keys %ENV) {print MAIL "$key: $ENV{$key}\n";} close(MAIL); # Next print an explanation for the visitor: print "Content-type: text/html\n\n"; print < Apache Guardian: $code

$code (Apache Error $ENV{'QUERY_STRING'})

\n EOM if ($ENV{'QUERY_STRING'} eq '401') {&explain_401;} elsif ($ENV{'QUERY_STRING'} eq '404') {&explain_404;} elsif ($ENV{'QUERY_STRING'} eq '500') {&explain_500;} else {&default;} print "
\n\n\n"; sub explain_401 { print <site administrator.

Otherwise, please return to the page you were at before. EOM } sub explain_404 { print <main page or drop us a quick note. EOM if ($search_page) { print "\n

You may also search\n"; print "for the document with our site's internal search engine.\n"; } } sub explain_500 { print <perl -w $ENV{'REDIRECT_SCRIPT_FILENAME'}. Alternately, if you are a visitor, please try again at a later time. The site administrator has already been notified of the error; it may be helpful if you could contact us with any additional information about your form input. EOM } sub default { print <main page, or contact the site administrator with any additional details about what you did to reach this error message. EOM }