1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
##############################################################
# This script was wrtitten for Debian.
#
# It is here to provide some checks for better communication
# with the user.
#
##############################################################
use strict;
use warnings;
# print the error message in html,
# after a valid HTTP header.
# Then exit with error code 1.
sub error_html($)
{
my $message = shift;
my $cgi = $ENV{SCRIPT_NAME};
print "Content-type: text/html\n\n";
print <<EOF;
<html>
<head>
</head>
<body>
<h1>An error occurs in $cgi</h1>
<pre>
$message
</pre>
</body>
</html>
EOF
exit 1;
}
# print the error message
# on STDERR and then exit with
# error code 1.
sub error_stderr($)
{
my $message = shift;
warn $message;
exit 1;
}
# Determine which error_ function to use
# according to the environement.
sub error($)
{
my $message = shift;
# if we are called from a browser.
if (defined $ENV{SERVER_NAME} and
defined $ENV{HTTP_HOST} and
defined $ENV{SERVER_PROTOCOL}) {
error_html($message);
}
# else we are in a shell
else {
error_stderr($message);
}
}
# Currently the only job to do is to
# be sure that localconfig is redable.
my $localconfig = '/etc/bugzilla/localconfig';
error "File $localconfig is not readable.\n$0 cannot run properly.\n"
unless -r $localconfig;
|