use Bugzilla::DB;
use Bugzilla::Template;
use Bugzilla::User;
+use Bugzilla::Error;
+use Bugzilla::Util;
+
+use File::Basename;
+
+#####################################################################
+# Constants
+#####################################################################
+
+# Scripts that are not stopped by shutdownhtml being in effect.
+use constant SHUTDOWNHTML_EXEMPT => [
+ 'doeditparams.cgi',
+ 'editparams.cgi',
+ 'checksetup.pl',
+];
+
+#####################################################################
+# Global Code
+#####################################################################
+
+# If Bugzilla is shut down, do not allow anything to run, just display a
+# message to the user about the downtime. Scripts listed in
+# SHUTDOWNHTML_EXEMPT are exempt from this message.
+#
+# This code must go here. It cannot go anywhere in Bugzilla::CGI, because
+# it uses Template, and that causes various dependency loops.
+if (Param("shutdownhtml")
+ && lsearch(SHUTDOWNHTML_EXEMPT, basename($0)) == -1)
+{
+ my $template = Bugzilla->template;
+ my $vars = {};
+ $vars->{'message'} = 'shutdown';
+ # Generate and return a message about the downtime, appropriately
+ # for if we're a command-line script or a CGI sript.
+ my $extension;
+ if (i_am_cgi() && (!Bugzilla->cgi->param('format')
+ || Bugzilla->cgi->param('format') eq 'html')) {
+ $extension = 'html';
+ }
+ else {
+ $extension = 'txt';
+ }
+ print Bugzilla->cgi->header() if i_am_cgi();
+ my $t_output;
+ $template->process("global/message.$extension.tmpl", $vars, \$t_output)
+ || ThrowTemplateError($template->error);
+ print $t_output . "\n";
+ exit;
+}
+
+#####################################################################
+# Subroutines and Methods
+#####################################################################
my $_template;
sub template {
package Bugzilla::CGI;
+BEGIN {
+ if ($^O =~ /MSWin32/i) {
+ # Help CGI find the correct temp directory as the default list
+ # isn't Windows friendly (Bug 248988)
+ $ENV{'TMPDIR'} = $ENV{'TEMP'} || $ENV{'TMP'} || "$ENV{'WINDIR'}\\TEMP";
+ }
+}
+
use CGI qw(-no_xhtml -oldstyle_urls :private_tempfiles :unique_headers SERVER_PUSH);
use base qw(CGI);
+use CGI::Carp qw(fatalsToBrowser);
use Bugzilla::Error;
use Bugzilla::Util;
detaint_signed
html_quote url_quote value_quote xml_quote
css_class_quote
+ i_am_cgi
lsearch max min
diff_arrays diff_strings
trim wrap_comment find_wrap_point
return $var;
}
+sub i_am_cgi () {
+ # I use SERVER_SOFTWARE because it's required to be
+ # defined for all requests in the CGI spec.
+ return exists $ENV{'SERVER_SOFTWARE'} ? 1 : 0;
+}
+
sub lsearch {
my ($list,$item) = (@_);
my $count = 0;
value_quote($var);
xml_quote($var);
+ # Functions that tell you about your environment
+ my $is_cgi = i_am_cgi();
+
# Functions for searching
$loc = lsearch(\@arr, $val);
$val = max($a, $b, $c);
is kept separate from html_quote partly for compatibility with previous code
(for ') and partly for future handling of non-ASCII characters.
+=item C<i_am_cgi()>
+
+Tells you whether or not you are being run as a CGI script in a web
+server. For example, it would return false if the caller is running
+in a command-line script.
+
=back
=head2 Searching
# use Carp; # for confess
-BEGIN {
- if ($^O =~ /MSWin32/i) {
- # Help CGI find the correct temp directory as the default list
- # isn't Windows friendly (Bug 248988)
- $ENV{'TMPDIR'} = $ENV{'TEMP'} || $ENV{'TMP'} || "$ENV{'WINDIR'}\\TEMP";
- }
-}
-
use Bugzilla::Util;
use Bugzilla::Config;
use Bugzilla::Constants;
$zz = $::buffer;
}
-use CGI::Carp qw(fatalsToBrowser);
-
require 'globals.pl';
use vars qw($template $vars);
-# If Bugzilla is shut down, do not go any further, just display a message
-# to the user about the downtime. (do)editparams.cgi is exempted from
-# this message, of course, since it needs to be available in order for
-# the administrator to open Bugzilla back up.
-if (Param("shutdownhtml") && $0 !~ m:(^|[\\/])(do)?editparams\.cgi$:) {
- $::vars->{'message'} = "shutdown";
-
- # Return the appropriate HTTP response headers.
- print Bugzilla->cgi->header();
-
- # Generate and return an HTML message about the downtime.
- $::template->process("global/message.html.tmpl", $::vars)
- || ThrowTemplateError($::template->error());
- exit;
-}
-
# Implementations of several of the below were blatently stolen from CGI.pm,
# by Lincoln D. Stein.
--- /dev/null
+[%# 1.0@bugzilla.org %]
+[%# The contents of this file are subject to the Mozilla Public
+ # License Version 1.1 (the "License"); you may not use this file
+ # except in compliance with the License. You may obtain a copy of
+ # the License at http://www.mozilla.org/MPL/
+ #
+ # Software distributed under the License is distributed on an "AS
+ # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ # implied. See the License for the specific language governing
+ # rights and limitations under the License.
+ #
+ # The Original Code is the Bugzilla Bug Tracking System.
+ #
+ # The Initial Developer of the Original Code is Max Kanat-Alexander.
+ # Portions created by Max Kanat-Alexander are Copyright (C) 2005
+ # Max Kanat-Alexander. All Rights Reserved.
+ #
+ # Contributor(s): Max Kanat-Alexander <mkanat@kerio.com>
+ #%]
+
+[% PROCESS global/variables.none.tmpl %]
+
+[%# Yes, this may show some HTML. But it's the best we
+ # can do at the moment. %]
+[% PROCESS global/messages.html.tmpl %]
+[% message %]