#!/usr/local/bin/perl
$|=1;
##################################################################
# (C)1999 Bignosebird.com
# This software is FREEWARE! Do with it as you wish. It is yours
# to share and enjoy. Modify it, improve it, and have fun with it!
# It is distributed strictly as a learning aid and bignosebird.com
# disclaims all warranties- including but not limited to:
# fitness for a particular purpose, merchantability, loss of
# business, harm to your system, etc... ALWAYS BACK UP YOUR
# SYSTEM BEFORE INSTALLING ANY SCRIPT OR PROGRAM FROM ANY
# SOURCE!
##################################################################
$result=$ENV{'QUERY_STRING'};
&set_params;
if ($logem{$result} eq "Y")
{¬ification("L");}
if ($email{$result} eq "Y")
{¬ification("M");}
print "Content-type: text/html\n\n";
print "$msg{$result}\n";
sub set_params
{
##################################################################
#
# This is where all of the various parameters for the script are
# set.
#
#The full path to your error log (not server log!) file.
$errorlog="/usr/local/apache/share/cgi-bin/birdtrap.dat";
#The e-mail address of the person to notify when an error occurs.
#Be sure to put the \ backslash before the \@ at sign!!!
$notify="your\@yourdomain.com";
#The name of your site
$sitename="YourSite.Com";
#The link the reader should follow home.
$returnlink="http://yoursite.com/";
#This is the URL to the directory holding your images.
$imageurl="http://yoursite.com/eimages";
#The name of your sendmail program, one of the two below should work.
#Make sure you always use the -t option or the script will fail.
# $mailprog="/usr/sbin/sendmail -t";
$mailprog="/usr/lib/sendmail -t";
#This is just a link back to BigNoseBird.Com. Leaving it in is
#always appreciated. ;-)
$cpr=<<_CPR_;
BirdTrap Server Error Handler, another free script
from BigNoseBird.Com
_CPR_
#By default, e-mail is turned off for all errors.
#Windows APACHE users MUST leave the mail feature off.
#Change the N to Y if you want to receive e-mail when a particular
#error occurs.
%email=('000','N',
'400','N',
'401','N',
'403','N',
'404','N',
'500','N');
#By default, all errors are saved to the log file.
#Change the Y to N if you do not wish to log a particular type of
#error.
%logem=('000','Y',
'400','Y',
'401','Y',
'403','Y',
'404','Y',
'500','Y');
#These are the Subject Lines for the e-mail notification
#You can modify these without causing any problems.
%sbjct=( '000', 'UNKNOWN ERROR',
'400', 'BAD REQUEST',
'401', 'NO AUTHORIZATION',
'403', 'FORBIDDEN URL',
'404', 'MISSING URL',
'500', 'CONFIGURATION ERROR');
###################################################################
# Leave the next 3 lines alone!
if ($result ne "400" && $result ne "401"
&& $result ne "403" && $result ne "404" && $result ne "500")
{$result="000";}
###################################################################
#
# EDIT THE HTML ERROR MESSAGES BELOW TO SUITE YOUR NEEDS. DO NOT
# CHANGE OR MOVE THE OPENING AND CLOSING TAGS SUCH AS __40X__
#
#HTML CODE TO APPEAR WHEN A BAD REQUEST OCCURS
$msg{'400'} =<<__400__;
|
|
$sitename
ERROR $result
The URL that you requested, $ENV{'REDIRECT_URL'}
was a bad request.
Please Click Here to Return to our Home Page.
$cpr
|
__400__
##################################################################
#HTML CODE TO APPEAR WHEN AN UNAUTHORIZED PAGE ACCESS ATTEMP OCCURS
$msg{'401'} =<<__401__;
|
|
$sitename
ERROR $result
The URL that you requested, $ENV{'REDIRECT_URL'}
requires preauthorization to access.
Please Click Here to Return to our Home Page.
$cpr
|
__401__
##################################################################
#HTML CODE TO APPEAR WHEN A FORBIDDEN ATTEMPT IS MADE
$msg{'403'} =<<__403__;
|
|
$sitename
ERROR $result
Access to the URL that you requested, $ENV{'REDIRECT_URL'},
is forbidden.
Please Click Here to Return to our Home Page.
$cpr
|
__403__
##################################################################
#HTML CODE TO APPEAR WHEN A DOCUMENT NOT FOUND HAPPENS
$msg{'404'} =<<__404__;
|
|
$sitename
ERROR $result
The URL that you requested, $ENV{'REDIRECT_URL'}
could not be found. Perhaps you either mistyped the
URL or we have a broken link.
We have logged this error and will correct the
problem if it is a broken link, and notify you
after the webmaster has been flogged.
Please Click Here to Return to our Home Page.
$cpr
|
__404__
##################################################################
#HTML CODE TO APPEAR WHEN A SERVER CONFIGURATION ERROR OCCURS
$msg{'500'} =<<__500__;
|
|
$sitename
ERROR $result
The URL that you requested, $ENV{'REDIRECT_URL'}
resulted in a server configuration error. It is
possible that the condition causing the problem will
be gone by the time you finish reading this.
We have logged this error and will correct the
problem.
Please Click Here to Return to our Home Page.
$cpr
|
__500__
##################################################################
#HTML CODE TO APPEAR WHEN AN UNKNOWN ERROR OCCURS
$msg{'000'} =<<__000__;
|
|
$sitename
ERROR $result
The URL that you requested, $ENV{'REDIRECT_URL'}
resulted in an unknown error code.
It is possible that the condition causing the problem will
be gone by the time you finish reading this.
We have logged this error and will correct the
problem.
Please Click Here to Return to our Home Page.
$cpr
|
__000__
}
##################################################################
# this routine either sends e-mail or writes to a log depending
# on whether it was called with an "L" or "M"
sub notification
{
local($action) = @_;
$date=localtime(time);
if ($action eq "L")
{ open (BL,">>$errorlog");}
else
{open (BL,"| $mailprog");
print BL "To: $notify\n";
print BL "From: $notify\n";
print BL "Subject: $sbjct{$result}\n";
}
print BL <<_BL_;
ON YOUR SITE, $sitename
ERROR CODE $result $sbjct{$result}
OCCURRED ON $date
WHEN THE URL $ENV{'REDIRECT_URL'} WAS REQUESTED
BY A USER AT $ENV{'REMOTE_ADDR'}
THE BROWSER WAS $ENV{'HTTP_USER_AGENT'}
------------------------------------------------------------------------------
_BL_
close (BL);
}