#!/usr/bin/perl

$er_dir = "/kunden/mp3chartlist.org/forum4you/vbforum/errdocs";
$er_name = "$ENV{'REDIRECT_STATUS'}.html";
$flock = 0;
$logfile = "/kunden/mp3chartlist.org/forum4you/forum_errors.log";

print "Content-type:text/html\n\n";

@months=("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
($sec,$min,$hr,$mday,$mon,$year) = (localtime(time))[0,1,2,3,4,5];
$year += 1900;

$email=0;
$log=0;
$query = "$ENV{'QUERY_STRING'}";
$query =~ tr/[A-Z]/[a-z]/;
@queries=split(/&/,$query);
foreach $val (@queries){
	if($val eq "email"){
	$email=1;
	}
	if($val eq "log"){
	$log=1;
	}
}

if ($log){
open(ACCESS,">>$logfile");
if($flock){
flock(ACCESS,2);
}
print ACCESS "$ENV{'REMOTE_ADDR'} - - [$mday/$months[$mon]/$year:$hr:$min:$sec] \"$ENV{'REQUEST_METHOD'} $ENV{'REQUEST_URI'}\" $ENV{'REDIRECT_STATUS'} $size \"$ENV{'HTTP_REFERER'}\" \"$ENV{'HTTP_USER_AGENT'}\"\n";
close(ACCESS);
}

open(HTML,"$er_dir/$er_name") or &Error("Can't open error page $er_name");
@data=<HTML>;
close(HTML);

$p=join("\n",@data);
foreach $key (sort(keys %ENV)) {
$p =~ s/<!$key>/$ENV{$key}/gi;
}

print "$p";


sub Error{
($msg) = @_;
print "<html><body bgcolor=\'#FFFFFF\'>";
print "<h2>Cgi Error!</h2>\n";
print $msg;
print "\n</body></html>";
exit;
}
