index.cgi 2.58 KB
Newer Older
1
#!/usr/bin/perl -wT
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# 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 Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
21
# Contributor(s): Jacob Steenhagen <jake@bugzilla.org>
22
#                 Frédéric Buclin <LpSolit@gmail.com>
23 24 25 26 27 28 29 30 31

###############################################################################
# Script Initialization
###############################################################################

# Make it harder for us to do dangerous things in Perl.
use strict;

# Include the Bugzilla CGI and general utility library.
32
use lib qw(. lib);
33

34
use Bugzilla;
35
use Bugzilla::Constants;
36
use Bugzilla::Error;
37 38 39 40
use Bugzilla::Update;

# Check whether or not the user is logged in
my $user = Bugzilla->login(LOGIN_OPTIONAL);
41 42 43 44 45 46 47 48 49 50 51 52 53
my $cgi = Bugzilla->cgi;
my $template = Bugzilla->template;
my $vars = {};

# And log out the user if requested. We do this first so that nothing
# else accidentally relies on the current login.
if ($cgi->param('logout')) {
    Bugzilla->logout();
    $user = Bugzilla->user;
    $vars->{'message'} = "logged_out";
    # Make sure that templates or other code doesn't get confused about this.
    $cgi->delete('logout');
}
54 55 56 57 58 59

###############################################################################
# Main Body Execution
###############################################################################

# Return the appropriate HTTP response headers.
60
print $cgi->header();
61

62
if ($user->in_group('admin')) {
63 64 65 66 67 68 69
    # If 'urlbase' is not set, display the Welcome page.
    unless (Bugzilla->params->{'urlbase'}) {
        $template->process('welcome-admin.html.tmpl')
          || ThrowTemplateError($template->error());
        exit;
    }
    # Inform the administrator about new releases, if any.
70 71 72
    $vars->{'release'} = Bugzilla::Update::get_notifications();
}

73
# Generate and return the UI (HTML page) from the appropriate template.
74
$template->process("index.html.tmpl", $vars)
75
  || ThrowTemplateError($template->error());