#!/usr/bin/perl --
use strict;
use vars qw! %actions %criteria %const @str %FORM @DataFields %system @sendmail %MimeType !;
(%actions, %criteria, %const, @str, %FORM, @DataFields, %system, @sendmail, %MimeType) = ();

$const{'PRINT_HTTP_STATUS_HEADER'} = 0;
my $VERSION = '2.0.0.0010';
my $all_code = <<'END_OF_CODE';
my $err = '';
Err: {
	local $_;
	if (($0 =~ m!(.+)(\\|/)!) and ($0 !~ m!safeperl\d*$!i)) {
		my $dir = $1;
		unless (chdir($dir)) {
			$err = "unable to change directory to folder '$dir' - $!";
			next Err;
			}
		}

	delete $INC{'./ag-shared.txt'}; #fix stupid mod-perl bug
	require './ag-shared.txt';

	$err = &ag_init($VERSION);
	next Err if ($err);

	$err = &handle_error();
	next Err if ($err);

	last Err;
	}
continue {
	print "HTTP/1.0 200 OK\015\012" if ($const{'PRINT_HTTP_STATUS_HEADER'});
	print "Content-Type: text/html\015\012\015\012" unless ($const{'has_http_header'});
	&syslog($err);
	&ppstr(1,$err);
	}

END_OF_CODE
eval $all_code;

if ($@) {
	my $errstr = $@;
	$errstr =~ s!\"!\&quot;!g;
	$errstr =~ s!\<!\&lt;!g;
	$errstr =~ s!\>!\&gt;!g;

print "Content-Type: text/html\015\012\015\012";
print <<"EOM";

<form method="post" action="http://www.xav.com/bug.pl">
<input type="hidden" name="product" value="guardian" />
<input type="hidden" name="version" value="$VERSION" />
<input type="hidden" name="Perl Version" value="$]" />
<input type="hidden" name="Script Path" value="$0" />
<input type="hidden" name="Perl Error" value="$errstr" />

<hr />
<p><b>Perl Execution Error</b> in $0:</p>
<blockquote>
	<p>$errstr</p>
</blockquote>
<p>Please report this error to the script author:</p>
<blockquote>
	<p><input type="submit" value="Report Error" /></p>
</blockquote>
<hr />

EOM
	my ($name, $value);
	while (($name, $value) = each %FORM) {
		print qq!<input type="hidden" name="Form: $name" value="$value" />\n!;
		}
	print '</form>';
	}


1;
