homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Accredited PayPal World Seller

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

There's gotta be a way

 6:12 pm on Feb 21, 2001 (gmt 0)

This is the meat of Apache Guardian. [xav.com] I use this script on all my sites as it warns me of all kinds of situations. One very irritating side effect is that it notifies me of a particular error that I cant seem to fix. Best I can tell the error I get is related to some kind of cache server between my site and the user.

The errors are produced by:


Is there a simple statement I could add into the script to exclude these two errors?

The important stuff below:

# Enter your email address:

$email = 'f00@f00sh0use.com';

# Enter the URL of your main page:

$main_page = '/index.html';

# Enter the URL to your search page, if you have one. If not, just
# delete this line:

$search_page = '/index.html';

# 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";
@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";
{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";}

# Next print an explanation for the visitor:
print "Content-type: text/html\n\n";
print <<EOM;
<HEAD><TITLE>Files Have Been Moved: $code</TITLE>
<H2><TT>$code (Apache Error $ENV{'QUERY_STRING'})</TT></H2>
if ($ENV{'QUERY_STRING'} eq '401')
elsif ($ENV{'QUERY_STRING'} eq '404')
elsif ($ENV{'QUERY_STRING'} eq '500')
print "</B></BLOCKQUOTE>\n</BODY>\n</HTML>\n";



 6:42 am on Feb 23, 2001 (gmt 0)

What is the error message it sends you? What does the email look like?


 7:04 am on Feb 23, 2001 (gmt 0)

The error it sends is a 404 and it prints out the standard apache guardian email.

this is the line that triggers the email:
$code = "Lost File" if ($ENV{'QUERY_STRING'} eq '404');

These are the files that produce the error:


These are evidently some kind of class files something is looking for but aren't there and never will be. The errors occur while the user is usinga java applet on my site.


 4:36 pm on Feb 27, 2001 (gmt 0)

I tried it this way but it didn't work:

$code = "Mysterious Reason";
$code = "Lost File" if ($ENV{'QUERY_STRING'} eq '404');

if {{pano$COMClassObject.class
panoBeanInfo.class }

(relax, kick back dont do anything)}

else { freak out };

$code = "Restricted Access" if ($ENV{'QUERY_STRING'} eq '401');
$code = "Failed Script" if ($ENV{'QUERY_STRING'} eq '500');


 5:07 pm on Feb 27, 2001 (gmt 0)

You could try putting:

if ($ENV{'REDIRECT_URL'} eq 'pano$COMClassObject.class')

at the start of the script. I don't know if this would cure the problem, but it's worth a try.


 4:08 pm on Feb 28, 2001 (gmt 0)

No it didn't work either.

I went back to xav.com and got their advanced script which I have exhausted everything I know to do and it doesn't work either.

I will post the entire thing as a last resort (cant link to it cuz its on ftp). I really hate to give up Guardian cuz it really serves a simple but extremely useful purpose.

I just can't continue to receive 500 emails a day and this keeps increasing as my traffic does too.

To be clear this script works fine but it never ceases to email in the declared areas.

This is the advanced script:


# Apache Guardian, Version 1.1
# For latest version and help files, visit:
# __________________________________________________________________

# Apache Guardian deals with the following errors:

$ErrorDef[401] = "Authorization Required";
$ErrorDef[403] = "Permission Denied";
$ErrorDef[404] = "Document Not Found";
$ErrorDef[500] = "Internal Server Error";

# This script allows you to customize the error pages that the visitor
# sees. It also, at your option, can send you an email message when
# the error occurs:

$Mail4[401] = 1; # Set these to 0 to disable email for
$Mail4[403] = 1; # the particular error code. The custom
$Mail4[404] = 1; # error pages will still be displayed.
$Mail4[500] = 1;

# Sometimes you have parts of the web page you watch closely for broken
# links, and other parts of the web page that have gone to hell and are
# full of broken links. You can choose to NOT send email if an error
# occurs from one of these messed up areas - of course, the custom pages
# will still be displayed to the visitor:

$BAD_AREA[0] = "http://www.xav.com/beta/";
$BAD_AREA[1] = "http://www.xav.com/test/";
$BAD_AREA[2] = "http://www.xav.com/scripts/apache/";

# Continue as necessary, with increasing numbers inside the []
# brackets. If you don't need this feature, just leave this area
# alone.
# Enter your email address. Remember to use single quotes around the
# address:

$Email = 'noc@xav.com';

# To help people out when they get an error, there are some common
# URL's that you should offer them. These are your main web page,
# your internal search engine (if you have one), and the sign-up
# page to get into a password-locked area (if one exists). If you
# don't have one of those pages, just leave the variable blank:

$Main_Page = "http://www.mmaildirect.com/";
$Search_Page = "http://www.xav.com/search.html";
$Signup_Page = "http://www.xav.com/signup.html";

# Enter the location of sendmail on your system. You can type
# "whereis sendmail" in Unix to find out, or ask your system admin.

$Mail_Program = '/usr/sbin/sendmail';

$Enable_Reverse_DNS = 1; # Set to zero to disable - may speed things up

# No further editing is necessary, but feel free to play around...
# __________________________________________________________________

# First give the visitor some kind of explanation:


$ErrorType = $ENV{'QUERY_STRING'};

if ($ErrorType == 401)
elsif ($ErrorType == 403)
elsif ($ErrorType == 404)
elsif ($ErrorType == 500)


# Should we bother to send email?

foreach (@BAD_AREA)
{exit if ($ENV{'REDIRECT_URL'} =~ /^$_/);}
exit unless ($Mail4[$ErrorType]);

# The script is now done. Everything below is a sub procedure. You
# can edit the sub procedures to give your error pages a custom look.

sub PrintHeader
print "Content-type: text/html\n\n";
print <<EOM;

<TITLE>Apache Guardian</TITLE>

} # End Print Header.

sub PrintFooter
print <<EOM;


} # End Print Footer.

sub Error401
print <<EOM;
<IMG SRC="/images/apache.gif" HEIGHT=140 WIDTH=173 ALT="Leave... Now">
<H3><U>HTTP/1.1 401 Authorization Required</U></H3>
<B>The document you requested is password locked for a reason. If you
have misplaced your password, or have a compelling reason to view
the restricted information, please contact the <A
HREF="mailto:$Email">site administrator</A>. Otherwise, leave.</B>

} # End Error 401.

sub Error403
print <<EOM;

<IMG SRC="/images/apache.gif" HEIGHT=140 WIDTH=173 ALT="Leave... Now">
<H3><U>HTTP/1.1 403 Forbidden</U></H3>
<B>You do not have permission to view this file. If this is a CGI script,
and you are the administration, you may have to enter "chmod 755 filename"
to work the script. If you are a wayward visitor trying to view restricted
information, leave.</B>

} # End Error 403.

sub Error404
print <<EOM;

<IMG SRC="/images/apache.gif" HEIGHT=140 WIDTH=173 ALT="">
<H3><U>HTTP/1.1 404 File Not Found</U></H3>
<B>The file you were searching for was not found. You may wish to return
to the <A HREF="http://www.mmaildirect.com/">main page</A> to restart your
search, or contact the <A HREF="mailto:$Email">site administrator</A> for

} # End Error 404.

sub Error500
{print <<EOM;

<IMG SRC="/images/apache.gif" HEIGHT=140 WIDTH=173 ALT="Leave... Now">
<H3><U>HTTP/1.1 500 Internal Server Error</U></H3>
<B>The script has suffered an internal error. You may want to try the
submission again, or let our <A HREF="mailto:$Email">server administrator</A>

} # End Error 500.

sub Error
{print <<EOM;

Something went horribly wrong.

} # End Error.

sub SendMail
$TimeStamp = localtime(time);
$URL = "http://" . $ENV{'SERVER_NAME'} . $ENV{'REDIRECT_URL'};
if ($Enable_Reverse_DNS)
if (($ENV{'REMOTE_HOST'} eq $ENV{'REMOTE_ADDR'}) && ($ENV{'REMOTE_ADDR'} =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/))
$Address = pack('C4',$1,$2,$3,$4);
$DNS_Address = (gethostbyaddr($Address,2))[0];
$ENV{'REMOTE_HOST'} = $DNS_Address if $DNS_Address;
$ENV{'REMOTE_HOST'} =~ tr/[A-Z]/[a-z]/;

open(MAIL,"$Mail_Program -t");
print MAIL "To: $Email\n";
print MAIL "From: guardian\@xav.com (Apache Guardian)\n";
print MAIL "Subject: Error Report [$ErrorType:$ENV{'REDIRECT_URL'}]\n";
print MAIL "X-Priority: 1 (Highest)\n\n";

print MAIL <<EOM;
Guadian Report:

$ErrorDef[$ErrorType] [$ErrorType]
Visitor: $ENV{'REMOTE_HOST'}


print MAIL "Prior to causing this error, our visitor ";
print MAIL "was at:\n\n\t$ENV{'HTTP_REFERER'}\n\nHe may have followed ";
print MAIL "an invalid link from there.\n\n\n";
print MAIL "No referring URL was associated with this visit.\n\n\n";

print MAIL "Server Details:\n";
print MAIL "---------------\n\n";
foreach $key (sort keys %ENV)
print MAIL "$key: $ENV{$key}\n";
# Yes, its more shameless propaganda to build hits to our site:
print MAIL "\n\n\n";
print MAIL <<EOM;
Apache Guardian is copyright 1997 by Fluid Dynamics.
Visit [xav.com...]
for help files and the most recent version
} # End Send Mail.


 4:37 am on Mar 1, 2001 (gmt 0)

Put this in your .htaccess file create a "mybeanfile.htm" and see if it will work:

Redirect 302 /panoBeanInfo.class [yoursite.com...]

Redirect 302 /pano$COMClassObject.class [yoursite.com...]

Any requests for panoBeanInfo.class would be redirected to the "mybeanfile.htm" and shouldn't generate an HTTP 404.


 6:01 am on Mar 1, 2001 (gmt 0)

Hey Froggyman that works!

Only problem now is I have 16 subdirectories that have this error. Is there a way to put a wildcard in the path:

/stays the same/**/pano/panoBeanInfo.class.


 7:59 am on Mar 1, 2001 (gmt 0)

make an empty panoBeanInfo.class

If 302's work ok, then I guess it serves no useful purpose other than generating errors. Sloppy, but try it.


 7:40 pm on Mar 1, 2001 (gmt 0)

Well I did some experimenting on my own server and found that wildcards don't seem to work. You can, however, put all of your directory and subdirectory redirects into the (1) .htaccess file of the main directory. This should overide all of your other .htaccess files (at least it did for me). This way you would have only one "mybeanfile.htm" file.


 6:47 am on Mar 2, 2001 (gmt 0)

I did some more digging on this too and it turns out this is a common problem.

Sun's Java FAQ's [java.sun.com]:
"Java Plug-in 1.2.2 Software in IE4 tries to load <YourAppletName>BeanInfo.class even if your applet is not a bean. There is a bug in Java 2 SDK, Standard Edition v 1.2.2 in
the AppletClassLoader that occurs when trying to load nonexistent classes. To prevent
this problem, create an empty <YourAppletName>BeanInfo.class."

It is completely harmless aside from the error it generates (so you're not crashing your IE4 visitors, just your inbox:)). Let us know how it works out.


 6:53 am on Mar 2, 2001 (gmt 0)

Quality work, bartek!

I've been following the Trials of Boneheadicus for a long time -- I feel pretty certain you've found the answer.


 7:07 am on Mar 2, 2001 (gmt 0)

Thank you tedster...
Now we just need BH to try all this out


 3:51 pm on Mar 2, 2001 (gmt 0)

>>>>Trials of BoneHeadicus


If you call 500 emails a day a pain then it is annoying to say the least. I guess I've become somewhat dependant on Apache Guardian. It has helped me in more than one instance to fix an error I otherwise would'nt have noticed. The main thing it does for me is let me know how often pages that I've moved are being called up. Inktomi has a very long memory.

Thanks bartek and froggyman for your determination.

As for the cause of the error most of the ua's are reporting as MSIE 5.0. There really isnt a set pattern to it.

I guess I better get busy and start copy and pasting little empty class files all over the place.....Man what a mess.
Hundreds of them across multiple sites.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved