package WebGUI::ErrorHandler; #------------------------------------------------------------------- # WebGUI is Copyright 2001-2002 Plain Black Software. #------------------------------------------------------------------- # Please read the legal notices (docs/legal.txt) and the license # (docs/license.txt) that came with this distribution before using # this software. #------------------------------------------------------------------- # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- use FileHandle; use WebGUI::Session; #------------------------------------------------------------------- sub fatalError { my ($key, $log, $cgi, $logfile, $config, $friendly); if (exists $session{cgi}) { $cgi = $session{cgi}; $friendly = 1 if ($session{setting}{onCriticalError} eq "friendly"); } else { use CGI; $cgi = CGI->new; } print $cgi->header; if (exists $session{config}{logfile}) { $logfile = $session{config}{logfile}; } else { use Data::Config; $config = new Data::Config '../etc/WebGUI.conf'; $logfile = $config->param('logfile'); } print "

WebGUI Fatal Error

Something unexpected happened that caused this system to fault.

" unless ($friendly); $log = FileHandle->new(">>$logfile") or print "Can't open log file."; print $0." at ".localtime(time)." reported:
" unless ($friendly); print $log localtime(time)." ".$0." ".$_[0]."\n"; print $_[0] unless ($friendly); print "

Caller

" unless ($friendly); print "Level 1
".join("
",caller(1)) unless ($friendly); print $log "\t".join(",",caller(1))."\n"; print "
"."Level 2
".join("
",caller(2)) unless ($friendly); print $log "\t".join(",",caller(2))."\n"; print "
"."Level 3
".join("
",caller(3)) unless ($friendly); print $log "\t".join(",",caller(3))."\n"; print "
"."Level 4
".join("
",caller(4)) unless ($friendly); print $log "\t".join(",",caller(4))."\n"; print "
" unless ($friendly); print "

Form Variables

" unless ($friendly); print $log "\t"; if (exists $session{form}) { foreach $key (keys %{$session{form}}) { print $key." = ".$session{form}{$key}."
" unless ($friendly); print $log $key."=".$session{form}{$key}." "; } print $log "\n"; } else { print "Cannot retrieve session information." unless ($friendly); print $log "Session not accessible for form variable dump.\n"; } print $log "\n"; $log->close; if ($friendly) { print WebGUI::International::get(416).'
'; print '
'.$session{setting}{companyName}; print '
'.$session{setting}{companyEmail}; print '
'.$session{setting}{companyURL}; } exit; } #------------------------------------------------------------------- sub warn { my ($log, $logfile, $config); if (exists $session{config}{logfile}) { $logfile = $session{config}{logfile}; } else { use Data::Config; $config = new Data::Config '../etc/WebGUI.conf'; $logfile = $config->param('logfile'); } $log = FileHandle->new(">>".$logfile) or fatalError("Can't open log file for warning."); print $log localtime(time)." ".$0." WARNING: ".$_[0]."\n"; $log->close; } 1;