#!/usr/bin/perl -w
###############################################
# Custom Error 500 email and logger script
# Transload this file to any directory and
# call it 500.cgi and chmod 755
# this script will create a plain text file in the
# same directory it is run in called 500_list.txt
# and log the pages that give you errors
# This line goes inside your root .htaccess file
# ErrorDocument 500 http://your-site.com/500.cgi
################################################
# This script will email you the first time anybody
# on your site receives a 500 Error. Any other
# errors will be logged inside the 500_list.txt
# To start the script over again just delete the
# 500_list.txt file
################################################
# You need to change the two email addresses to
# your own email addresses and add your own html
################################################
use strict;
use CGI qw(:standard);
use Date::Format;
use Socket;
my $now = time2str("%c", time);
my $file = '500_list.txt';
my $size = -s "$file";
my $refer = $ENV{HTTP_REFERER};
my $sendmail = '/usr/sbin/sendmail -t';
my $recipient = 'your_email@yahoo.com';
my $sender = 'you@your_server.com';
my $mail_body = "A 500 Error has accured from\n$refer";
# check if file is empty,
if ($size == 0) {
open(DAT,">$file") || die("Cannot Open File");
print DAT "$now\n$refer\n\n";
close(DAT);
open(MAIL, "|$sendmail -oi -t") or die "Can't open pipe to $sendmail: $!\n";
print MAIL "To: $recipient\n";
print MAIL "From: $sender\n";
print MAIL "Subject: 500 Error\n\n";
print MAIL "$mail_body";
close(MAIL) or die "Can't close pipe to $sendmail: $!\n";
}
else
{
open(DAT,">>$file") || die("Cannot Open File");
print DAT "$now\n$refer\n\n";
close(DAT);
}
print header;
print start_html(-title=>'500 Error',-bgcolor=>'#ffffff', text=>'#000000');
print <