Commit bcfde177 authored by mkanat%kerio.com's avatar mkanat%kerio.com

Bug 283989: CGI.pl global init code should be moved to Bugzilla::CGI

Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=wurblzap, a=justdave
parent bf0a551f
...@@ -33,6 +33,59 @@ use Bugzilla::Constants; ...@@ -33,6 +33,59 @@ use Bugzilla::Constants;
use Bugzilla::DB; use Bugzilla::DB;
use Bugzilla::Template; use Bugzilla::Template;
use Bugzilla::User; 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; my $_template;
sub template { sub template {
......
...@@ -25,9 +25,18 @@ use strict; ...@@ -25,9 +25,18 @@ use strict;
package Bugzilla::CGI; 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 CGI qw(-no_xhtml -oldstyle_urls :private_tempfiles :unique_headers SERVER_PUSH);
use base qw(CGI); use base qw(CGI);
use CGI::Carp qw(fatalsToBrowser);
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::Util; use Bugzilla::Util;
......
...@@ -33,6 +33,7 @@ use base qw(Exporter); ...@@ -33,6 +33,7 @@ use base qw(Exporter);
detaint_signed detaint_signed
html_quote url_quote value_quote xml_quote html_quote url_quote value_quote xml_quote
css_class_quote css_class_quote
i_am_cgi
lsearch max min lsearch max min
diff_arrays diff_strings diff_arrays diff_strings
trim wrap_comment find_wrap_point trim wrap_comment find_wrap_point
...@@ -130,6 +131,12 @@ sub xml_quote { ...@@ -130,6 +131,12 @@ sub xml_quote {
return $var; 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 { sub lsearch {
my ($list,$item) = (@_); my ($list,$item) = (@_);
my $count = 0; my $count = 0;
...@@ -376,6 +383,9 @@ Bugzilla::Util - Generic utility functions for bugzilla ...@@ -376,6 +383,9 @@ Bugzilla::Util - Generic utility functions for bugzilla
value_quote($var); value_quote($var);
xml_quote($var); xml_quote($var);
# Functions that tell you about your environment
my $is_cgi = i_am_cgi();
# Functions for searching # Functions for searching
$loc = lsearch(\@arr, $val); $loc = lsearch(\@arr, $val);
$val = max($a, $b, $c); $val = max($a, $b, $c);
...@@ -480,6 +490,12 @@ This is similar to C<html_quote>, except that ' is escaped to &apos;. This ...@@ -480,6 +490,12 @@ This is similar to C<html_quote>, except that ' is escaped to &apos;. This
is kept separate from html_quote partly for compatibility with previous code is kept separate from html_quote partly for compatibility with previous code
(for &apos;) and partly for future handling of non-ASCII characters. (for &apos;) 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 =back
=head2 Searching =head2 Searching
......
...@@ -32,14 +32,6 @@ use lib "."; ...@@ -32,14 +32,6 @@ use lib ".";
# use Carp; # for confess # 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::Util;
use Bugzilla::Config; use Bugzilla::Config;
use Bugzilla::Constants; use Bugzilla::Constants;
...@@ -60,28 +52,10 @@ sub CGI_pl_sillyness { ...@@ -60,28 +52,10 @@ sub CGI_pl_sillyness {
$zz = $::buffer; $zz = $::buffer;
} }
use CGI::Carp qw(fatalsToBrowser);
require 'globals.pl'; require 'globals.pl';
use vars qw($template $vars); 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, # Implementations of several of the below were blatently stolen from CGI.pm,
# by Lincoln D. Stein. # by Lincoln D. Stein.
......
[%# 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 %]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment