2002-08-29 13:25:54 +04:00
|
|
|
# -*- 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.
|
|
|
|
#
|
|
|
|
# Contributor(s): Terry Weissman <terry@mozilla.org>
|
|
|
|
# Dawn Endico <endico@mozilla.org>
|
|
|
|
# Dan Mosedale <dmose@mozilla.org>
|
|
|
|
# Joe Robins <jmrobins@tgix.com>
|
|
|
|
# Jake <jake@bugzilla.org>
|
|
|
|
# J. Paul Reed <preed@sigkill.com>
|
|
|
|
# Bradley Baetz <bbaetz@student.usyd.edu.au>
|
|
|
|
# Christopher Aillon <christopher@aillon.com>
|
2004-07-21 02:41:22 +04:00
|
|
|
# Erik Stambaugh <erik@dasbistro.com>
|
2005-10-12 12:51:55 +04:00
|
|
|
# Frédéric Buclin <LpSolit@gmail.com>
|
2002-08-29 13:25:54 +04:00
|
|
|
|
|
|
|
package Bugzilla::Config;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
use base qw(Exporter);
|
|
|
|
|
2003-11-22 06:50:42 +03:00
|
|
|
# Under mod_perl, get this from a .htaccess config variable,
|
|
|
|
# and/or default from the current 'real' dir
|
|
|
|
# At some stage after this, it may be possible for these dir locations
|
|
|
|
# to go into localconfig. localconfig can't be specified in a config file,
|
|
|
|
# except possibly with mod_perl. If you move localconfig, you need to change
|
|
|
|
# the define here.
|
|
|
|
# $libpath is really only for mod_perl; its not yet possible to move the
|
|
|
|
# .pms elsewhere.
|
|
|
|
# $webdotdir must be in the webtree somewhere. Even if you use a local dot,
|
|
|
|
# we output images to there. Also, if $webdot dir is not relative to the
|
2005-02-02 19:06:51 +03:00
|
|
|
# bugzilla root directory, you'll need to change showdependencygraph.cgi to
|
2003-11-22 06:50:42 +03:00
|
|
|
# set image_url to the correct location.
|
|
|
|
# The script should really generate these graphs directly...
|
2005-02-02 19:06:51 +03:00
|
|
|
# Note that if $libpath is changed, some stuff will break, notably dependency
|
2003-11-22 06:50:42 +03:00
|
|
|
# graphs (since the path will be wrong in the HTML). This will be fixed at
|
|
|
|
# some point.
|
|
|
|
|
2005-09-16 02:16:53 +04:00
|
|
|
# constant paths
|
2003-11-22 06:50:42 +03:00
|
|
|
our $libpath = '.';
|
|
|
|
our $templatedir = "$libpath/template";
|
2005-09-16 02:16:53 +04:00
|
|
|
|
|
|
|
# variable paths
|
|
|
|
our $project;
|
|
|
|
our $localconfig;
|
|
|
|
our $datadir;
|
|
|
|
if ($ENV{'PROJECT'} && $ENV{'PROJECT'} =~ /^(\w+)$/) {
|
|
|
|
$project = $1;
|
|
|
|
$localconfig = "$libpath/localconfig.$project";
|
|
|
|
$datadir = "$libpath/data/$project";
|
|
|
|
} else {
|
|
|
|
$localconfig = "$libpath/localconfig";
|
|
|
|
$datadir = "$libpath/data";
|
|
|
|
}
|
|
|
|
our $attachdir = "$datadir/attachments";
|
2003-11-22 06:50:42 +03:00
|
|
|
our $webdotdir = "$datadir/webdot";
|
2006-02-28 17:39:33 +03:00
|
|
|
our $extensionsdir = "$libpath/extensions";
|
2003-11-22 06:50:42 +03:00
|
|
|
|
2005-10-12 12:51:55 +04:00
|
|
|
our @parampanels = ();
|
|
|
|
|
2002-08-29 13:25:54 +04:00
|
|
|
# Module stuff
|
|
|
|
@Bugzilla::Config::EXPORT = qw(Param);
|
|
|
|
|
|
|
|
# Don't export localvars by default - people should have to explicitly
|
|
|
|
# ask for it, as a (probably futile) attempt to stop code using it
|
|
|
|
# when it shouldn't
|
|
|
|
# ChmodDataFile is here until that stuff all moves out of globals.pl
|
|
|
|
# into this file
|
2003-11-22 06:50:42 +03:00
|
|
|
@Bugzilla::Config::EXPORT_OK = qw(ChmodDataFile);
|
|
|
|
|
2002-08-29 13:25:54 +04:00
|
|
|
%Bugzilla::Config::EXPORT_TAGS =
|
|
|
|
(
|
2005-10-12 12:51:55 +04:00
|
|
|
admin => [qw(UpdateParams SetParam WriteParams)],
|
2005-02-16 21:11:07 +03:00
|
|
|
db => [qw($db_driver $db_host $db_port $db_name $db_user $db_pass $db_sock)],
|
2005-09-16 02:16:53 +04:00
|
|
|
locations => [qw($libpath $localconfig $attachdir $datadir $templatedir
|
2006-02-28 17:39:33 +03:00
|
|
|
$webdotdir $project $extensionsdir)],
|
2005-10-12 12:51:55 +04:00
|
|
|
params => [qw(@parampanels)],
|
2002-08-29 13:25:54 +04:00
|
|
|
);
|
2005-10-12 12:51:55 +04:00
|
|
|
Exporter::export_ok_tags('admin', 'db', 'locations', 'params');
|
2002-08-29 13:25:54 +04:00
|
|
|
|
|
|
|
# Bugzilla version
|
2006-04-23 09:23:28 +04:00
|
|
|
$Bugzilla::Config::VERSION = "2.23.1+";
|
2002-08-29 13:25:54 +04:00
|
|
|
|
|
|
|
use vars qw(@param_list);
|
2002-10-16 14:49:56 +04:00
|
|
|
|
|
|
|
# Data::Dumper is required as needed, below. The problem is that then when
|
|
|
|
# the code locally sets $Data::Dumper::Foo, this triggers 'used only once'
|
|
|
|
# warnings.
|
|
|
|
# We can't predeclare another package's vars, though, so just use them
|
|
|
|
{
|
|
|
|
local $Data::Dumper::Sortkeys;
|
|
|
|
local $Data::Dumper::Terse;
|
|
|
|
local $Data::Dumper::Indent;
|
|
|
|
}
|
|
|
|
|
2002-08-29 13:25:54 +04:00
|
|
|
# INITIALISATION CODE
|
2006-05-22 22:11:53 +04:00
|
|
|
do $localconfig;
|
2002-08-29 13:25:54 +04:00
|
|
|
my %params;
|
2005-10-12 12:51:55 +04:00
|
|
|
# Load in the param definitions
|
|
|
|
foreach my $item ((glob "$libpath/Bugzilla/Config/*.pm")) {
|
|
|
|
$item =~ m#/([^/]+)\.pm$#;
|
|
|
|
my $module = $1;
|
|
|
|
next if ($module eq 'Common');
|
|
|
|
require "Bugzilla/Config/$module.pm";
|
|
|
|
my @new_param_list = "Bugzilla::Config::$module"->get_param_list();
|
|
|
|
foreach my $item (@new_param_list) {
|
|
|
|
$params{$item->{'name'}} = $item;
|
|
|
|
}
|
|
|
|
push(@parampanels, $module);
|
|
|
|
push(@param_list, @new_param_list);
|
2002-08-29 13:25:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# END INIT CODE
|
|
|
|
|
|
|
|
# Subroutines go here
|
|
|
|
|
|
|
|
sub Param {
|
|
|
|
my ($param) = @_;
|
|
|
|
|
2006-05-22 22:11:53 +04:00
|
|
|
my %param_values = %{Bugzilla->params};
|
|
|
|
|
2002-08-29 13:25:54 +04:00
|
|
|
# By this stage, the param must be in the hash
|
2002-12-22 02:39:48 +03:00
|
|
|
die "Can't find param named $param" unless (exists $params{$param});
|
2002-08-29 13:25:54 +04:00
|
|
|
|
2002-12-22 02:39:48 +03:00
|
|
|
# When module startup code runs (which is does even via -c, when using
|
|
|
|
# |use|), we may try to grab params which don't exist yet. This affects
|
|
|
|
# tests, so have this as a fallback for the -c case
|
2006-05-22 22:11:53 +04:00
|
|
|
return $params{$param}->{default}
|
|
|
|
if ($^C && not exists $param_values{$param});
|
2002-12-22 02:39:48 +03:00
|
|
|
|
|
|
|
# If we have a value for the param, return it
|
2006-05-22 22:11:53 +04:00
|
|
|
return $param_values{$param} if exists $param_values{$param};
|
2002-12-22 02:39:48 +03:00
|
|
|
|
|
|
|
# Else error out
|
2004-02-09 02:17:11 +03:00
|
|
|
die "No value for param $param (try running checksetup.pl again)";
|
2002-08-29 13:25:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub SetParam {
|
|
|
|
my ($name, $value) = @_;
|
|
|
|
|
|
|
|
die "Unknown param $name" unless (exists $params{$name});
|
|
|
|
|
|
|
|
my $entry = $params{$name};
|
|
|
|
|
|
|
|
# sanity check the value
|
2002-11-19 10:19:34 +03:00
|
|
|
|
|
|
|
# XXX - This runs the checks. Which would be good, except that
|
2005-11-26 00:57:13 +03:00
|
|
|
# check_shadowdb creates the database as a side effect, and so the
|
|
|
|
# checker fails the second time around...
|
2002-11-19 10:19:34 +03:00
|
|
|
if ($name ne 'shadowdb' && exists $entry->{'checker'}) {
|
2002-08-29 13:25:54 +04:00
|
|
|
my $err = $entry->{'checker'}->($value, $entry);
|
|
|
|
die "Param $name is not valid: $err" unless $err eq '';
|
|
|
|
}
|
|
|
|
|
2006-05-22 22:11:53 +04:00
|
|
|
Bugzilla->params->{$name} = $value;
|
2002-08-29 13:25:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub UpdateParams {
|
|
|
|
# --- PARAM CONVERSION CODE ---
|
|
|
|
|
|
|
|
# Note that this isn't particuarly 'clean' in terms of separating
|
|
|
|
# the backend code (ie this) from the actual params.
|
|
|
|
# We don't care about that, though
|
|
|
|
|
2006-05-22 22:11:53 +04:00
|
|
|
my $param = Bugzilla->params;
|
|
|
|
|
2002-08-29 13:25:54 +04:00
|
|
|
# Old bugzilla versions stored the version number in the params file
|
|
|
|
# We don't want it, so get rid of it
|
2006-05-22 22:11:53 +04:00
|
|
|
delete $param->{'version'};
|
2002-08-29 13:25:54 +04:00
|
|
|
|
2004-08-28 12:58:14 +04:00
|
|
|
# Change from usebrowserinfo to defaultplatform/defaultopsys combo
|
2006-05-22 22:11:53 +04:00
|
|
|
if (exists $param->{'usebrowserinfo'}) {
|
|
|
|
if (!$param->{'usebrowserinfo'}) {
|
|
|
|
if (!exists $param->{'defaultplatform'}) {
|
|
|
|
$param->{'defaultplatform'} = 'Other';
|
2004-08-28 12:58:14 +04:00
|
|
|
}
|
2006-05-22 22:11:53 +04:00
|
|
|
if (!exists $param->{'defaultopsys'}) {
|
|
|
|
$param->{'defaultopsys'} = 'Other';
|
2004-08-28 12:58:14 +04:00
|
|
|
}
|
|
|
|
}
|
2006-05-22 22:11:53 +04:00
|
|
|
delete $param->{'usebrowserinfo'};
|
2004-08-28 12:58:14 +04:00
|
|
|
}
|
|
|
|
|
2002-08-29 13:25:54 +04:00
|
|
|
# Change from a boolean for quips to multi-state
|
2006-05-22 22:11:53 +04:00
|
|
|
if (exists $param->{'usequip'} && !exists $param->{'enablequips'}) {
|
|
|
|
$param->{'enablequips'} = $param->{'usequip'} ? 'on' : 'off';
|
|
|
|
delete $param->{'usequip'};
|
2002-08-29 13:25:54 +04:00
|
|
|
}
|
|
|
|
|
2002-11-24 22:56:34 +03:00
|
|
|
# Change from old product groups to controls for group_control_map
|
|
|
|
# 2002-10-14 bug 147275 bugreport@peshkin.net
|
2006-05-22 22:11:53 +04:00
|
|
|
if (exists $param->{'usebuggroups'} && !exists $param->{'makeproductgroups'}) {
|
|
|
|
$param->{'makeproductgroups'} = $param->{'usebuggroups'};
|
2002-11-24 22:56:34 +03:00
|
|
|
}
|
2006-05-22 22:11:53 +04:00
|
|
|
if (exists $param->{'usebuggroupsentry'}
|
|
|
|
&& !exists $param->{'useentrygroupdefault'}) {
|
|
|
|
$param->{'useentrygroupdefault'} = $param->{'usebuggroupsentry'};
|
2002-11-24 22:56:34 +03:00
|
|
|
}
|
|
|
|
|
2003-03-22 07:47:35 +03:00
|
|
|
# Modularise auth code
|
2006-05-22 22:11:53 +04:00
|
|
|
if (exists $param->{'useLDAP'} && !exists $param->{'loginmethod'}) {
|
|
|
|
$param->{'loginmethod'} = $param->{'useLDAP'} ? "LDAP" : "DB";
|
2003-03-22 07:47:35 +03:00
|
|
|
}
|
|
|
|
|
2004-07-21 02:41:22 +04:00
|
|
|
# set verify method to whatever loginmethod was
|
2006-05-22 22:11:53 +04:00
|
|
|
if (exists $param->{'loginmethod'} && !exists $param->{'user_verify_class'}) {
|
|
|
|
$param->{'user_verify_class'} = $param->{'loginmethod'};
|
|
|
|
delete $param->{'loginmethod'};
|
2004-07-21 02:41:22 +04:00
|
|
|
}
|
|
|
|
|
2005-03-10 19:21:35 +03:00
|
|
|
# Remove quip-display control from parameters
|
|
|
|
# and give it to users via User Settings (Bug 41972)
|
2006-05-22 22:11:53 +04:00
|
|
|
if ( exists $param->{'enablequips'}
|
|
|
|
&& !exists $param->{'quip_list_entry_control'})
|
2005-03-10 19:21:35 +03:00
|
|
|
{
|
|
|
|
my $new_value;
|
2006-05-22 22:11:53 +04:00
|
|
|
($param->{'enablequips'} eq 'on') && do {$new_value = 'open';};
|
|
|
|
($param->{'enablequips'} eq 'approved') && do {$new_value = 'moderated';};
|
|
|
|
($param->{'enablequips'} eq 'frozen') && do {$new_value = 'closed';};
|
|
|
|
($param->{'enablequips'} eq 'off') && do {$new_value = 'closed';};
|
|
|
|
$param->{'quip_list_entry_control'} = $new_value;
|
|
|
|
delete $param->{'enablequips'};
|
2005-03-10 19:21:35 +03:00
|
|
|
}
|
|
|
|
|
2002-08-29 13:25:54 +04:00
|
|
|
# --- DEFAULTS FOR NEW PARAMS ---
|
|
|
|
|
|
|
|
foreach my $item (@param_list) {
|
|
|
|
my $name = $item->{'name'};
|
2006-05-22 22:11:53 +04:00
|
|
|
$param->{$name} = $item->{'default'} unless exists $param->{$name};
|
2002-08-29 13:25:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# --- REMOVE OLD PARAMS ---
|
|
|
|
|
|
|
|
my @oldparams = ();
|
|
|
|
|
|
|
|
# Remove any old params
|
2006-05-22 22:11:53 +04:00
|
|
|
foreach my $item (keys %$param) {
|
2002-08-29 13:25:54 +04:00
|
|
|
if (!grep($_ eq $item, map ($_->{'name'}, @param_list))) {
|
2002-10-16 14:49:56 +04:00
|
|
|
require Data::Dumper;
|
|
|
|
|
2002-08-29 13:25:54 +04:00
|
|
|
local $Data::Dumper::Terse = 1;
|
|
|
|
local $Data::Dumper::Indent = 0;
|
2006-05-22 22:11:53 +04:00
|
|
|
push (@oldparams, [$item, Data::Dumper->Dump([$param->{$item}])]);
|
|
|
|
delete $param->{$item};
|
2002-08-29 13:25:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return @oldparams;
|
|
|
|
}
|
|
|
|
|
2002-10-16 14:49:56 +04:00
|
|
|
sub WriteParams {
|
|
|
|
require Data::Dumper;
|
2002-08-29 13:25:54 +04:00
|
|
|
|
2002-10-16 14:49:56 +04:00
|
|
|
# This only has an affect for Data::Dumper >= 2.12 (ie perl >= 5.8.0)
|
|
|
|
# Its just cosmetic, though, so that doesn't matter
|
|
|
|
local $Data::Dumper::Sortkeys = 1;
|
2002-08-29 13:25:54 +04:00
|
|
|
|
2002-10-16 14:49:56 +04:00
|
|
|
require File::Temp;
|
2002-08-29 13:25:54 +04:00
|
|
|
my ($fh, $tmpname) = File::Temp::tempfile('params.XXXXX',
|
2003-11-22 06:50:42 +03:00
|
|
|
DIR => $datadir );
|
2002-08-29 13:25:54 +04:00
|
|
|
|
2006-05-22 22:11:53 +04:00
|
|
|
print $fh (Data::Dumper->Dump([Bugzilla->params], ['*param']))
|
2002-08-29 13:25:54 +04:00
|
|
|
|| die "Can't write param file: $!";
|
|
|
|
|
|
|
|
close $fh;
|
|
|
|
|
2003-11-22 06:50:42 +03:00
|
|
|
rename $tmpname, "$datadir/params"
|
|
|
|
|| die "Can't rename $tmpname to $datadir/params: $!";
|
2002-08-29 13:25:54 +04:00
|
|
|
|
2003-11-22 06:50:42 +03:00
|
|
|
ChmodDataFile("$datadir/params", 0666);
|
2002-08-29 13:25:54 +04:00
|
|
|
}
|
|
|
|
|
2005-06-09 13:32:25 +04:00
|
|
|
# Some files in the data directory must be world readable if and only if
|
|
|
|
# we don't have a webserver group. Call this function to do this.
|
2002-08-29 13:25:54 +04:00
|
|
|
# This will become a private function once all the datafile handling stuff
|
|
|
|
# moves into this package
|
|
|
|
|
|
|
|
# This sub is not perldoc'd for that reason - noone should know about it
|
|
|
|
sub ChmodDataFile {
|
|
|
|
my ($file, $mask) = @_;
|
|
|
|
my $perm = 0770;
|
2003-11-22 06:50:42 +03:00
|
|
|
if ((stat($datadir))[2] & 0002) {
|
2002-08-29 13:25:54 +04:00
|
|
|
$perm = 0777;
|
|
|
|
}
|
|
|
|
$perm = $perm & $mask;
|
|
|
|
chmod $perm,$file;
|
|
|
|
}
|
|
|
|
|
2002-10-16 14:49:56 +04:00
|
|
|
1;
|
|
|
|
|
|
|
|
__END__
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
Bugzilla::Config - Configuration parameters for Bugzilla
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
# Getting parameters
|
|
|
|
use Bugzilla::Config;
|
|
|
|
|
|
|
|
my $fooSetting = Param('foo');
|
|
|
|
|
|
|
|
# Administration functions
|
|
|
|
use Bugzilla::Config qw(:admin);
|
|
|
|
|
|
|
|
my @removed_params = UpgradeParams();
|
|
|
|
SetParam($param, $value);
|
|
|
|
WriteParams();
|
|
|
|
|
|
|
|
# Localconfig variables may also be imported
|
|
|
|
use Bugzilla::Config qw(:db);
|
|
|
|
print "Connecting to $db_name as $db_user with $db_pass\n";
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
This package contains ways to access Bugzilla configuration parameters.
|
|
|
|
|
|
|
|
=head1 FUNCTIONS
|
|
|
|
|
|
|
|
=head2 Parameters
|
|
|
|
|
|
|
|
Parameters can be set, retrieved, and updated.
|
|
|
|
|
|
|
|
=over 4
|
|
|
|
|
|
|
|
=item C<Param($name)>
|
|
|
|
|
|
|
|
Returns the Param with the specified name. Either a string, or, in the case
|
|
|
|
of multiple-choice parameters, an array reference.
|
|
|
|
|
|
|
|
=item C<SetParam($name, $value)>
|
|
|
|
|
|
|
|
Sets the param named $name to $value. Values are checked using the checker
|
|
|
|
function for the given param if one exists.
|
|
|
|
|
|
|
|
=item C<UpdateParams()>
|
|
|
|
|
|
|
|
Updates the parameters, by transitioning old params to new formats, setting
|
|
|
|
defaults for new params, and removing obsolete ones.
|
|
|
|
|
|
|
|
Any removed params are returned in a list, with elements [$item, $oldvalue]
|
|
|
|
where $item is the entry in the param list.
|
|
|
|
|
|
|
|
=item C<WriteParams()>
|
|
|
|
|
|
|
|
Writes the parameters to disk.
|
|
|
|
|
2002-08-29 13:25:54 +04:00
|
|
|
=back
|
|
|
|
|
2005-10-12 12:51:55 +04:00
|
|
|
=over
|
2002-10-16 14:49:56 +04:00
|
|
|
|
|
|
|
=item *
|
|
|
|
|
|
|
|
The new value for the parameter
|
|
|
|
|
|
|
|
=item *
|
|
|
|
|
|
|
|
A reference to the entry in the param list for this parameter
|
|
|
|
|
|
|
|
Functions should return error text, or the empty string if there was no error.
|
|
|
|
|
|
|
|
=back
|