X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=general%2Fseeerror;fp=general%2Fseeerror;h=a6d357de4f697ceabbf58908a6d999b8fb581128;hb=03e69f4317ba6a4b8f0c7dae9813c9d20511b1e9;hp=0000000000000000000000000000000000000000;hpb=175696b26ca4203a7da4899e0f08dc56d9852477;p=matthijs%2Fupstream%2Fblosxom-plugins.git diff --git a/general/seeerror b/general/seeerror new file mode 100644 index 0000000..a6d357d --- /dev/null +++ b/general/seeerror @@ -0,0 +1,50 @@ +# Blosxom Plugin: seeerror -*- perl -*- +# Author: Todd Larason (jtl@molehill.org) +# Version: 0+1i +# Blosxom Home/Docs/Licensing: http://www.raelity.org/blosxom +# Categories plugin Home/Docs/Licensing: +# http://molelog.molehill.org/blox/Computers/Internet/Web/Blosxom/SeeError/ + +package seeerror; + +# ------------------------- Configuration Variables -------------------------- +# Directory to create the temporary files in. +# Criteria: +# * It MUST exist +# * It MUST be writable +# * It SHOULD be readable outside Blosxom +$tmp_dir ||= "/tmp"; + +# Attempt to deal with fatal errors? Should only be enabled if you need it. +$handle_die = 0 + unless defined $handle_die; +# ---------------------------------------------------------------------------- + +use FileHandle; +use CGI; + +my $tmp_file = sprintf "$tmp_dir/bloserr-$$-$^T-%s.txt", CGI::remote_host(); +open STDERR,"> $tmp_file"; + +if ($handle_die) { + $SIG{__DIE__} = sub { + print "content-type: text/html\n\n

Possibly-Fatal Error

$@"; + }; +} + +sub start {1;} +sub end { + close STDERR; # force a flush + my $fh = new FileHandle; + $fh->open("< $tmp_file"); + my $errors = join '',<$fh>; + $fh->close; + if ($errors) { + $errors =~ s:&:&:g; + $errors =~ s:<:<:g; + print "

Error Output

$errors
"; + } + unlink($tmp_file); + return 1; +} +1;