1998-09-16 01:49:26 +04:00
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
#
|
1999-11-02 02:33:56 +03:00
|
|
|
# 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.
|
|
|
|
#
|
1998-09-16 01:49:26 +04:00
|
|
|
# The Original Code is the Bugzilla Bug Tracking System.
|
1999-11-02 02:33:56 +03:00
|
|
|
#
|
1998-09-16 01:49:26 +04:00
|
|
|
# The Initial Developer of the Original Code is Netscape Communications
|
1999-11-02 02:33:56 +03:00
|
|
|
# Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
1998-09-16 01:49:26 +04:00
|
|
|
# Contributor(s): Terry Weissman <terry@mozilla.org>
|
2000-03-29 01:31:24 +04:00
|
|
|
# Dan Mosedale <dmose@mozilla.org>
|
2002-08-27 08:28:05 +04:00
|
|
|
# Jacob Steenhagen <jake@bugzilla.org>
|
2001-10-23 19:44:53 +04:00
|
|
|
# Bradley Baetz <bbaetz@cs.mcgill.ca>
|
2001-11-17 13:29:55 +03:00
|
|
|
# Christopher Aillon <christopher@aillon.com>
|
2002-09-22 21:15:13 +04:00
|
|
|
# Joel Peshkin <bugreport@peshkin.net>
|
1998-09-16 01:49:26 +04:00
|
|
|
|
|
|
|
# Contains some global variables and routines used throughout bugzilla.
|
|
|
|
|
|
|
|
use strict;
|
1999-10-19 03:57:58 +04:00
|
|
|
|
2002-08-19 17:59:45 +04:00
|
|
|
use Bugzilla::Util;
|
2002-08-29 13:25:54 +04:00
|
|
|
# Bring ChmodDataFile in until this is all moved to the module
|
|
|
|
use Bugzilla::Config qw(:DEFAULT ChmodDataFile);
|
2002-08-19 17:59:45 +04:00
|
|
|
|
1999-10-19 03:57:58 +04:00
|
|
|
# Shut up misguided -w warnings about "used only once". For some reason,
|
|
|
|
# "use vars" chokes on me when I try it here.
|
|
|
|
|
|
|
|
sub globals_pl_sillyness {
|
|
|
|
my $zz;
|
2001-06-01 06:14:23 +04:00
|
|
|
$zz = @main::SqlStateStack;
|
2002-03-12 16:55:07 +03:00
|
|
|
$zz = $main::contenttypes;
|
1999-10-19 03:57:58 +04:00
|
|
|
$zz = @main::default_column_list;
|
2000-01-29 23:22:44 +03:00
|
|
|
$zz = $main::defaultqueryname;
|
2002-02-14 04:25:25 +03:00
|
|
|
$zz = @main::enterable_products;
|
2000-01-15 01:35:49 +03:00
|
|
|
$zz = %main::keywordsbyname;
|
1999-10-19 03:57:58 +04:00
|
|
|
$zz = @main::legal_bug_status;
|
|
|
|
$zz = @main::legal_components;
|
2000-01-15 01:35:49 +03:00
|
|
|
$zz = @main::legal_keywords;
|
1999-10-19 03:57:58 +04:00
|
|
|
$zz = @main::legal_opsys;
|
|
|
|
$zz = @main::legal_platform;
|
|
|
|
$zz = @main::legal_priority;
|
|
|
|
$zz = @main::legal_product;
|
|
|
|
$zz = @main::legal_severity;
|
|
|
|
$zz = @main::legal_target_milestone;
|
|
|
|
$zz = @main::legal_versions;
|
|
|
|
$zz = @main::milestoneurl;
|
2002-02-14 04:25:25 +03:00
|
|
|
$zz = %main::proddesc;
|
1999-10-19 03:57:58 +04:00
|
|
|
$zz = @main::prodmaxvotes;
|
2002-02-03 12:28:48 +03:00
|
|
|
$zz = $main::template;
|
2002-03-12 16:55:07 +03:00
|
|
|
$zz = $main::userid;
|
2002-02-03 12:28:48 +03:00
|
|
|
$zz = $main::vars;
|
1999-10-19 03:57:58 +04:00
|
|
|
}
|
|
|
|
|
2000-01-29 23:22:44 +03:00
|
|
|
#
|
|
|
|
# Here are the --LOCAL-- variables defined in 'localconfig' that we'll use
|
|
|
|
# here
|
|
|
|
#
|
|
|
|
|
2002-08-29 13:25:54 +04:00
|
|
|
# XXX - Move this to Bugzilla::Config once code which uses these has moved out
|
|
|
|
# of globals.pl
|
2000-01-29 23:22:44 +03:00
|
|
|
do 'localconfig';
|
|
|
|
|
2000-05-20 05:22:07 +04:00
|
|
|
use DBI;
|
1998-09-16 01:49:26 +04:00
|
|
|
|
|
|
|
use Date::Format; # For time2str().
|
2000-01-21 00:31:22 +03:00
|
|
|
use Date::Parse; # For str2time().
|
2001-07-04 09:28:39 +04:00
|
|
|
#use Carp; # for confess
|
2000-03-29 01:31:24 +04:00
|
|
|
use RelationSet;
|
1998-09-16 01:49:26 +04:00
|
|
|
|
2002-03-12 16:55:07 +03:00
|
|
|
# Use standard Perl libraries for cross-platform file/directory manipulation.
|
|
|
|
use File::Spec;
|
|
|
|
|
2001-10-23 19:44:53 +04:00
|
|
|
# Some environment variables are not taint safe
|
2002-10-16 14:49:56 +04:00
|
|
|
#delete @::ENV{'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
|
2001-07-04 08:41:27 +04:00
|
|
|
|
2002-03-23 06:51:05 +03:00
|
|
|
# Cwd.pm in perl 5.6.1 gives a warning if $::ENV{'PATH'} isn't defined
|
|
|
|
# Set this to '' so that we don't get warnings cluttering the logs on every
|
|
|
|
# system call
|
|
|
|
$::ENV{'PATH'} = '';
|
|
|
|
|
2002-03-28 10:57:05 +03:00
|
|
|
# Ignore SIGTERM and SIGPIPE - this prevents DB corruption. If the user closes
|
|
|
|
# their browser window while a script is running, the webserver sends these
|
|
|
|
# signals, and we don't want to die half way through a write.
|
|
|
|
$::SIG{TERM} = 'IGNORE';
|
|
|
|
$::SIG{PIPE} = 'IGNORE';
|
|
|
|
|
2002-10-02 02:07:17 +04:00
|
|
|
$::defaultqueryname = "(Default query)"; # This string not exposed in UI
|
2000-02-17 08:15:23 +03:00
|
|
|
$::unconfirmedstate = "UNCONFIRMED";
|
2000-02-18 00:41:39 +03:00
|
|
|
$::dbwritesallowed = 1;
|
1998-09-16 01:49:26 +04:00
|
|
|
|
2001-07-04 09:28:39 +04:00
|
|
|
#sub die_with_dignity {
|
|
|
|
# my ($err_msg) = @_;
|
|
|
|
# print $err_msg;
|
|
|
|
# confess($err_msg);
|
|
|
|
#}
|
|
|
|
#$::SIG{__DIE__} = \&die_with_dignity;
|
2001-07-04 08:41:27 +04:00
|
|
|
|
1998-09-16 01:49:26 +04:00
|
|
|
sub ConnectToDatabase {
|
2000-02-18 00:41:39 +03:00
|
|
|
my ($useshadow) = (@_);
|
1998-09-16 01:49:26 +04:00
|
|
|
if (!defined $::db) {
|
2000-10-30 22:17:43 +03:00
|
|
|
my $name = $::db_name;
|
2000-03-20 21:48:59 +03:00
|
|
|
if ($useshadow && Param("shadowdb") && Param("queryagainstshadowdb")) {
|
2000-02-18 00:41:39 +03:00
|
|
|
$name = Param("shadowdb");
|
|
|
|
$::dbwritesallowed = 0;
|
|
|
|
}
|
2002-01-22 09:49:22 +03:00
|
|
|
$::db = DBI->connect("DBI:mysql:host=$::db_host;database=$name;port=$::db_port", $::db_user, $::db_pass)
|
2001-10-13 05:36:17 +04:00
|
|
|
|| die "Bugzilla is currently broken. Please try again later. " .
|
2001-03-08 02:59:15 +03:00
|
|
|
"If the problem persists, please contact " . Param("maintainer") .
|
|
|
|
". The error you should quote is: " . $DBI::errstr;
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:50:25 +03:00
|
|
|
sub ReconnectToShadowDatabase {
|
2000-03-20 21:48:59 +03:00
|
|
|
if (Param("shadowdb") && Param("queryagainstshadowdb")) {
|
2000-02-18 03:50:25 +03:00
|
|
|
SendSQL("USE " . Param("shadowdb"));
|
|
|
|
$::dbwritesallowed = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-19 00:38:23 +03:00
|
|
|
my $shadowchanges = 0;
|
|
|
|
sub SyncAnyPendingShadowChanges {
|
|
|
|
if ($shadowchanges) {
|
2001-06-07 01:17:42 +04:00
|
|
|
my $pid;
|
|
|
|
FORK: {
|
|
|
|
if ($pid = fork) { # create a fork
|
|
|
|
# parent code runs here
|
|
|
|
$shadowchanges = 0;
|
|
|
|
return;
|
|
|
|
} elsif (defined $pid) {
|
|
|
|
# child process code runs here
|
2002-04-01 02:56:41 +04:00
|
|
|
my $redir = ($^O =~ /MSWin32/i) ? "NUL" : "/dev/null";
|
|
|
|
open STDOUT,">$redir";
|
|
|
|
open STDERR,">$redir";
|
2001-06-10 21:15:56 +04:00
|
|
|
exec("./syncshadowdb","--") or die "Unable to exec syncshadowdb: $!";
|
|
|
|
# the idea was that passing the second parameter tricks it into
|
|
|
|
# using execvp instead of running a shell. Not really necessary since
|
|
|
|
# there are no shell meta-characters, but it passes our tinderbox
|
|
|
|
# test that way. :) http://bugzilla.mozilla.org/show_bug.cgi?id=21253
|
2001-06-07 01:17:42 +04:00
|
|
|
} elsif ($! =~ /No more process/) {
|
|
|
|
# recoverable fork error, try again in 5 seconds
|
|
|
|
sleep 5;
|
|
|
|
redo FORK;
|
|
|
|
} else {
|
|
|
|
# something weird went wrong
|
|
|
|
die "Can't create background process to run syncshadowdb: $!";
|
|
|
|
}
|
|
|
|
}
|
2000-02-19 00:38:23 +03:00
|
|
|
}
|
|
|
|
}
|
2000-07-14 00:04:15 +04:00
|
|
|
|
2000-02-19 00:38:23 +03:00
|
|
|
|
2000-12-12 06:47:40 +03:00
|
|
|
# This is used to manipulate global state used by SendSQL(),
|
|
|
|
# MoreSQLData() and FetchSQLData(). It provides a way to do another
|
|
|
|
# SQL query without losing any as-yet-unfetched data from an existing
|
|
|
|
# query. Just push the current global state, do your new query and fetch
|
|
|
|
# any data you need from it, then pop the current global state.
|
|
|
|
#
|
|
|
|
@::SQLStateStack = ();
|
|
|
|
|
|
|
|
sub PushGlobalSQLState() {
|
|
|
|
push @::SQLStateStack, $::currentquery;
|
|
|
|
push @::SQLStateStack, [ @::fetchahead ];
|
|
|
|
}
|
|
|
|
|
|
|
|
sub PopGlobalSQLState() {
|
|
|
|
die ("PopGlobalSQLState: stack underflow") if ( $#::SQLStateStack < 1 );
|
|
|
|
@::fetchahead = @{pop @::SQLStateStack};
|
|
|
|
$::currentquery = pop @::SQLStateStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub SavedSQLStates() {
|
|
|
|
return ($#::SqlStateStack + 1) / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-01-27 00:47:55 +03:00
|
|
|
my $dosqllog = (-e "data/sqllog") && (-w "data/sqllog");
|
|
|
|
|
|
|
|
sub SqlLog {
|
|
|
|
if ($dosqllog) {
|
|
|
|
my ($str) = (@_);
|
|
|
|
open(SQLLOGFID, ">>data/sqllog") || die "Can't write to data/sqllog";
|
|
|
|
if (flock(SQLLOGFID,2)) { # 2 is magic 'exclusive lock' const.
|
2000-12-12 06:47:40 +03:00
|
|
|
|
|
|
|
# if we're a subquery (ie there's pushed global state around)
|
|
|
|
# indent to indicate the level of subquery-hood
|
|
|
|
#
|
|
|
|
for (my $i = SavedSQLStates() ; $i > 0 ; $i--) {
|
|
|
|
print SQLLOGFID "\t";
|
|
|
|
}
|
|
|
|
|
2000-01-27 00:47:55 +03:00
|
|
|
print SQLLOGFID time2str("%D %H:%M:%S $$", time()) . ": $str\n";
|
|
|
|
}
|
|
|
|
flock(SQLLOGFID,8); # '8' is magic 'unlock' const.
|
|
|
|
close SQLLOGFID;
|
|
|
|
}
|
|
|
|
}
|
2000-12-12 06:47:40 +03:00
|
|
|
|
1998-09-16 01:49:26 +04:00
|
|
|
sub SendSQL {
|
2000-02-18 00:41:39 +03:00
|
|
|
my ($str, $dontshadow) = (@_);
|
2002-01-20 04:44:52 +03:00
|
|
|
|
|
|
|
# Don't use DBI's taint stuff yet, because:
|
|
|
|
# a) We don't want out vars to be tainted (yet)
|
|
|
|
# b) We want to know who called SendSQL...
|
|
|
|
# Is there a better way to do b?
|
|
|
|
if (is_tainted($str)) {
|
2002-01-22 18:12:11 +03:00
|
|
|
die "Attempted to send tainted string '$str' to the database";
|
2002-01-20 04:44:52 +03:00
|
|
|
}
|
|
|
|
|
2000-02-18 00:41:39 +03:00
|
|
|
my $iswrite = ($str =~ /^(INSERT|REPLACE|UPDATE|DELETE)/i);
|
|
|
|
if ($iswrite && !$::dbwritesallowed) {
|
|
|
|
die "Evil code attempted to write stuff to the shadow database.";
|
|
|
|
}
|
2000-03-20 21:48:59 +03:00
|
|
|
if ($str =~ /^LOCK TABLES/i && $str !~ /shadowlog/ && $::dbwritesallowed) {
|
2000-02-18 03:43:56 +03:00
|
|
|
$str =~ s/^LOCK TABLES/LOCK TABLES shadowlog WRITE, /i;
|
2000-02-18 00:41:39 +03:00
|
|
|
}
|
2001-08-13 23:11:35 +04:00
|
|
|
# If we are shutdown, we don't want to run queries except in special cases
|
|
|
|
if (Param('shutdownhtml')) {
|
2001-08-15 06:38:02 +04:00
|
|
|
if ($0 =~ m:[\\/]((do)?editparams.cgi|syncshadowdb)$:) {
|
2001-08-13 23:11:35 +04:00
|
|
|
$::ignorequery = 0;
|
|
|
|
} else {
|
|
|
|
$::ignorequery = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2000-01-27 00:47:55 +03:00
|
|
|
SqlLog($str);
|
2000-05-20 05:22:07 +04:00
|
|
|
$::currentquery = $::db->prepare($str);
|
2001-10-12 01:58:07 +04:00
|
|
|
if (!$::currentquery->execute) {
|
2001-10-13 05:36:17 +04:00
|
|
|
my $errstr = $::db->errstr;
|
|
|
|
# Cut down the error string to a reasonable.size
|
2001-10-14 05:34:08 +04:00
|
|
|
$errstr = substr($errstr, 0, 2000) . ' ... ' . substr($errstr, -2000)
|
|
|
|
if length($errstr) > 4000;
|
2001-10-13 05:36:17 +04:00
|
|
|
die "$str: " . $errstr;
|
2001-10-12 01:58:07 +04:00
|
|
|
}
|
2000-01-27 00:47:55 +03:00
|
|
|
SqlLog("Done");
|
2000-02-18 00:41:39 +03:00
|
|
|
if (!$dontshadow && $iswrite && Param("shadowdb")) {
|
|
|
|
my $q = SqlQuote($str);
|
|
|
|
my $insertid;
|
|
|
|
if ($str =~ /^(INSERT|REPLACE)/i) {
|
|
|
|
SendSQL("SELECT LAST_INSERT_ID()");
|
|
|
|
$insertid = FetchOneColumn();
|
|
|
|
}
|
|
|
|
SendSQL("INSERT INTO shadowlog (command) VALUES ($q)", 1);
|
|
|
|
if ($insertid) {
|
|
|
|
SendSQL("SET LAST_INSERT_ID = $insertid");
|
|
|
|
}
|
2000-02-19 00:38:23 +03:00
|
|
|
$shadowchanges++;
|
2000-02-18 00:41:39 +03:00
|
|
|
}
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub MoreSQLData {
|
2001-08-13 23:11:35 +04:00
|
|
|
# $::ignorequery is set in SendSQL
|
|
|
|
if ($::ignorequery) {
|
|
|
|
return 0;
|
|
|
|
}
|
1998-09-16 01:49:26 +04:00
|
|
|
if (defined @::fetchahead) {
|
2001-10-13 05:36:17 +04:00
|
|
|
return 1;
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
2000-05-20 05:22:07 +04:00
|
|
|
if (@::fetchahead = $::currentquery->fetchrow_array) {
|
2001-10-13 05:36:17 +04:00
|
|
|
return 1;
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub FetchSQLData {
|
2001-08-13 23:11:35 +04:00
|
|
|
# $::ignorequery is set in SendSQL
|
|
|
|
if ($::ignorequery) {
|
|
|
|
return;
|
|
|
|
}
|
1998-09-16 01:49:26 +04:00
|
|
|
if (defined @::fetchahead) {
|
2001-10-13 05:36:17 +04:00
|
|
|
my @result = @::fetchahead;
|
|
|
|
undef @::fetchahead;
|
|
|
|
return @result;
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
2000-05-20 05:22:07 +04:00
|
|
|
return $::currentquery->fetchrow_array;
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub FetchOneColumn {
|
|
|
|
my @row = FetchSQLData();
|
|
|
|
return $row[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@::default_column_list = ("severity", "priority", "platform", "owner",
|
|
|
|
"status", "resolution", "summary");
|
|
|
|
|
|
|
|
sub AppendComment {
|
2002-10-13 08:26:24 +04:00
|
|
|
my ($bugid, $who, $comment, $isprivate, $timestamp, $work_time) = @_;
|
|
|
|
$work_time ||= 0;
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
# Use the date/time we were given if possible (allowing calling code
|
|
|
|
# to synchronize the comment's timestamp with those of other records).
|
|
|
|
$timestamp = ($timestamp ? SqlQuote($timestamp) : "NOW()");
|
|
|
|
|
1999-04-21 21:45:22 +04:00
|
|
|
$comment =~ s/\r\n/\n/g; # Get rid of windows-style line endings.
|
|
|
|
$comment =~ s/\r/\n/g; # Get rid of mac-style line endings.
|
2002-10-13 08:26:24 +04:00
|
|
|
|
|
|
|
# allowing negatives though so people can back out errors in time reporting
|
|
|
|
if (defined $work_time) {
|
|
|
|
# regexp verifies one or more digits, optionally followed by a period and
|
|
|
|
# zero or more digits, OR we have a period followed by one or more digits
|
|
|
|
if ($work_time !~ /^-?(?:\d+(?:\.\d*)?|\.\d+)$/) {
|
|
|
|
ThrowUserError("need_numeric_value");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else { $work_time = 0 };
|
|
|
|
|
|
|
|
if ($comment =~ /^\s*$/) { # Nothin' but whitespace
|
1998-09-16 01:49:26 +04:00
|
|
|
return;
|
|
|
|
}
|
2000-01-21 00:31:22 +03:00
|
|
|
|
|
|
|
my $whoid = DBNameToIdAndCheck($who);
|
2002-08-20 01:17:28 +04:00
|
|
|
my $privacyval = $isprivate ? 1 : 0 ;
|
2002-10-13 08:26:24 +04:00
|
|
|
SendSQL("INSERT INTO longdescs (bug_id, who, bug_when, thetext, isprivate, work_time) " .
|
2002-09-28 22:42:54 +04:00
|
|
|
"VALUES($bugid, $whoid, $timestamp, " . SqlQuote($comment) . ", " .
|
2002-10-13 08:26:24 +04:00
|
|
|
$privacyval . ", " . SqlQuote($work_time) . ")");
|
2000-01-21 00:42:23 +03:00
|
|
|
|
|
|
|
SendSQL("UPDATE bugs SET delta_ts = now() WHERE bug_id = $bugid");
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
|
2000-01-22 07:24:42 +03:00
|
|
|
sub GetFieldID {
|
|
|
|
my ($f) = (@_);
|
|
|
|
SendSQL("SELECT fieldid FROM fielddefs WHERE name = " . SqlQuote($f));
|
|
|
|
my $fieldid = FetchOneColumn();
|
2002-08-10 11:34:17 +04:00
|
|
|
die "Unknown field id: $f" if !$fieldid;
|
2000-01-22 07:24:42 +03:00
|
|
|
return $fieldid;
|
|
|
|
}
|
1998-09-16 01:49:26 +04:00
|
|
|
|
2002-08-29 13:25:54 +04:00
|
|
|
# XXXX - this needs to go away
|
1998-09-16 01:49:26 +04:00
|
|
|
sub GenerateVersionTable {
|
2002-08-12 09:43:05 +04:00
|
|
|
SendSQL("SELECT versions.value, products.name " .
|
|
|
|
"FROM versions, products " .
|
|
|
|
"WHERE products.id = versions.product_id " .
|
|
|
|
"ORDER BY versions.value");
|
1998-09-16 01:49:26 +04:00
|
|
|
my @line;
|
|
|
|
my %varray;
|
|
|
|
my %carray;
|
|
|
|
while (@line = FetchSQLData()) {
|
|
|
|
my ($v,$p1) = (@line);
|
|
|
|
if (!defined $::versions{$p1}) {
|
|
|
|
$::versions{$p1} = [];
|
|
|
|
}
|
|
|
|
push @{$::versions{$p1}}, $v;
|
|
|
|
$varray{$v} = 1;
|
|
|
|
}
|
2002-08-12 09:43:05 +04:00
|
|
|
SendSQL("SELECT components.name, products.name " .
|
|
|
|
"FROM components, products " .
|
|
|
|
"WHERE products.id = components.product_id " .
|
|
|
|
"ORDER BY components.name");
|
1998-09-16 01:49:26 +04:00
|
|
|
while (@line = FetchSQLData()) {
|
|
|
|
my ($c,$p) = (@line);
|
|
|
|
if (!defined $::components{$p}) {
|
|
|
|
$::components{$p} = [];
|
|
|
|
}
|
|
|
|
my $ref = $::components{$p};
|
|
|
|
push @$ref, $c;
|
|
|
|
$carray{$c} = 1;
|
|
|
|
}
|
|
|
|
|
2000-03-24 03:43:40 +03:00
|
|
|
my $dotargetmilestone = 1; # This used to check the param, but there's
|
|
|
|
# enough code that wants to pretend we're using
|
|
|
|
# target milestones, even if they don't get
|
|
|
|
# shown to the user. So we cache all the data
|
|
|
|
# about them anyway.
|
1999-02-03 05:46:51 +03:00
|
|
|
|
|
|
|
my $mpart = $dotargetmilestone ? ", milestoneurl" : "";
|
2002-08-12 09:43:05 +04:00
|
|
|
SendSQL("select name, description, votesperuser, disallownew$mpart from products ORDER BY name");
|
1998-10-07 00:23:40 +04:00
|
|
|
while (@line = FetchSQLData()) {
|
1999-10-08 03:54:52 +04:00
|
|
|
my ($p, $d, $votesperuser, $dis, $u) = (@line);
|
1998-10-07 00:23:40 +04:00
|
|
|
$::proddesc{$p} = $d;
|
2002-02-14 04:25:25 +03:00
|
|
|
if (!$dis) {
|
|
|
|
push @::enterable_products, $p;
|
1999-03-03 21:16:24 +03:00
|
|
|
}
|
1999-02-03 05:46:51 +03:00
|
|
|
if ($dotargetmilestone) {
|
|
|
|
$::milestoneurl{$p} = $u;
|
|
|
|
}
|
1999-10-08 03:54:52 +04:00
|
|
|
$::prodmaxvotes{$p} = $votesperuser;
|
1998-10-07 00:23:40 +04:00
|
|
|
}
|
|
|
|
|
1998-09-16 01:49:26 +04:00
|
|
|
my $cols = LearnAboutColumns("bugs");
|
|
|
|
|
|
|
|
@::log_columns = @{$cols->{"-list-"}};
|
2000-01-22 07:24:42 +03:00
|
|
|
foreach my $i ("bug_id", "creation_ts", "delta_ts", "lastdiffed") {
|
1998-09-16 01:49:26 +04:00
|
|
|
my $w = lsearch(\@::log_columns, $i);
|
|
|
|
if ($w >= 0) {
|
|
|
|
splice(@::log_columns, $w, 1);
|
|
|
|
}
|
|
|
|
}
|
1999-03-24 01:32:21 +03:00
|
|
|
@::log_columns = (sort(@::log_columns));
|
1998-09-16 01:49:26 +04:00
|
|
|
|
|
|
|
@::legal_priority = SplitEnumType($cols->{"priority,type"});
|
|
|
|
@::legal_severity = SplitEnumType($cols->{"bug_severity,type"});
|
|
|
|
@::legal_platform = SplitEnumType($cols->{"rep_platform,type"});
|
1998-12-03 19:10:52 +03:00
|
|
|
@::legal_opsys = SplitEnumType($cols->{"op_sys,type"});
|
1998-09-16 01:49:26 +04:00
|
|
|
@::legal_bug_status = SplitEnumType($cols->{"bug_status,type"});
|
|
|
|
@::legal_resolution = SplitEnumType($cols->{"resolution,type"});
|
2000-07-14 07:20:17 +04:00
|
|
|
|
|
|
|
# 'settable_resolution' is the list of resolutions that may be set
|
|
|
|
# directly by hand in the bug form. Start with the list of legal
|
|
|
|
# resolutions and remove 'MOVED' and 'DUPLICATE' because setting
|
|
|
|
# bugs to those resolutions requires a special process.
|
|
|
|
#
|
|
|
|
@::settable_resolution = @::legal_resolution;
|
|
|
|
my $w = lsearch(\@::settable_resolution, "DUPLICATE");
|
1998-09-16 01:49:26 +04:00
|
|
|
if ($w >= 0) {
|
2000-07-14 07:20:17 +04:00
|
|
|
splice(@::settable_resolution, $w, 1);
|
|
|
|
}
|
|
|
|
my $z = lsearch(\@::settable_resolution, "MOVED");
|
|
|
|
if ($z >= 0) {
|
|
|
|
splice(@::settable_resolution, $z, 1);
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
my @list = sort { uc($a) cmp uc($b)} keys(%::versions);
|
|
|
|
@::legal_product = @list;
|
|
|
|
my $tmpname = "data/versioncache.$$";
|
|
|
|
open(FID, ">$tmpname") || die "Can't create $tmpname";
|
|
|
|
|
2001-10-20 03:49:37 +04:00
|
|
|
print FID "#\n";
|
|
|
|
print FID "# DO NOT EDIT!\n";
|
|
|
|
print FID "# This file is automatically generated at least once every\n";
|
|
|
|
print FID "# hour by the GenerateVersionTable() sub in globals.pl.\n";
|
|
|
|
print FID "# Any changes you make will be overwritten.\n";
|
|
|
|
print FID "#\n";
|
|
|
|
|
2002-10-16 14:49:56 +04:00
|
|
|
require Data::Dumper;
|
2002-08-29 13:25:54 +04:00
|
|
|
print FID Data::Dumper->Dump([\@::log_columns, \%::versions],
|
|
|
|
['*::log_columns', '*::versions']);
|
1998-09-16 01:49:26 +04:00
|
|
|
|
|
|
|
foreach my $i (@list) {
|
|
|
|
if (!defined $::components{$i}) {
|
2001-07-01 06:00:56 +04:00
|
|
|
$::components{$i} = [];
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
@::legal_versions = sort {uc($a) cmp uc($b)} keys(%varray);
|
2002-08-29 13:25:54 +04:00
|
|
|
print FID Data::Dumper->Dump([\@::legal_versions, \%::components],
|
|
|
|
['*::legal_versions', '*::components']);
|
1998-09-16 01:49:26 +04:00
|
|
|
@::legal_components = sort {uc($a) cmp uc($b)} keys(%carray);
|
2002-08-29 13:25:54 +04:00
|
|
|
|
|
|
|
print FID Data::Dumper->Dump([\@::legal_components, \@::legal_product,
|
|
|
|
\@::legal_priority, \@::legal_severity,
|
|
|
|
\@::legal_platform, \@::legal_opsys,
|
|
|
|
\@::legal_bug_status, \@::legal_resolution],
|
|
|
|
['*::legal_components', '*::legal_product',
|
|
|
|
'*::legal_priority', '*::legal_severity',
|
|
|
|
'*::legal_platform', '*::legal_opsys',
|
|
|
|
'*::legal_bug_status', '*::legal_resolution']);
|
|
|
|
|
|
|
|
print FID Data::Dumper->Dump([\@::settable_resolution, \%::proddesc,
|
|
|
|
\@::enterable_products, \%::prodmaxvotes],
|
|
|
|
['*::settable_resolution', '*::proddesc',
|
|
|
|
'*::enterable_products', '*::prodmaxvotes']);
|
1998-09-16 01:49:26 +04:00
|
|
|
|
1999-02-03 05:46:51 +03:00
|
|
|
if ($dotargetmilestone) {
|
2000-03-21 19:47:06 +03:00
|
|
|
# reading target milestones in from the database - matthew@zeroknowledge.com
|
2002-08-12 09:43:05 +04:00
|
|
|
SendSQL("SELECT milestones.value, products.name " .
|
|
|
|
"FROM milestones, products " .
|
|
|
|
"WHERE products.id = milestones.product_id " .
|
|
|
|
"ORDER BY milestones.sortkey, milestones.value");
|
2000-03-21 19:47:06 +03:00
|
|
|
my @line;
|
|
|
|
my %tmarray;
|
|
|
|
@::legal_target_milestone = ();
|
|
|
|
while(@line = FetchSQLData()) {
|
|
|
|
my ($tm, $pr) = (@line);
|
|
|
|
if (!defined $::target_milestone{$pr}) {
|
|
|
|
$::target_milestone{$pr} = [];
|
|
|
|
}
|
|
|
|
push @{$::target_milestone{$pr}}, $tm;
|
|
|
|
if (!exists $tmarray{$tm}) {
|
|
|
|
$tmarray{$tm} = 1;
|
|
|
|
push(@::legal_target_milestone, $tm);
|
|
|
|
}
|
1999-01-28 00:17:10 +03:00
|
|
|
}
|
2000-03-21 19:47:06 +03:00
|
|
|
|
2002-08-29 13:25:54 +04:00
|
|
|
print FID Data::Dumper->Dump([\%::target_milestone,
|
|
|
|
\@::legal_target_milestone,
|
|
|
|
\%::milestoneurl],
|
|
|
|
['*::target_milestone',
|
|
|
|
'*::legal_target_milestone',
|
|
|
|
'*::milestoneurl']);
|
1999-01-28 00:17:10 +03:00
|
|
|
}
|
2000-01-07 00:16:15 +03:00
|
|
|
|
|
|
|
SendSQL("SELECT id, name FROM keyworddefs ORDER BY name");
|
|
|
|
while (MoreSQLData()) {
|
|
|
|
my ($id, $name) = FetchSQLData();
|
2000-07-14 19:31:43 +04:00
|
|
|
push(@::legal_keywords, $name);
|
2000-07-14 00:04:15 +04:00
|
|
|
$name = lc($name);
|
2000-01-07 00:16:15 +03:00
|
|
|
$::keywordsbyname{$name} = $id;
|
|
|
|
}
|
2002-08-29 13:25:54 +04:00
|
|
|
|
|
|
|
print FID Data::Dumper->Dump([\@::legal_keywords, \%::keywordsbyname],
|
|
|
|
['*::legal_keywords', '*::keywordsbyname']);
|
2000-01-07 00:16:15 +03:00
|
|
|
|
1998-09-16 01:49:26 +04:00
|
|
|
print FID "1;\n";
|
|
|
|
close FID;
|
2002-08-29 13:25:54 +04:00
|
|
|
|
1998-09-16 01:49:26 +04:00
|
|
|
rename $tmpname, "data/versioncache" || die "Can't rename $tmpname to versioncache";
|
2002-04-07 07:56:46 +04:00
|
|
|
ChmodDataFile('data/versioncache', 0666);
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-14 00:04:15 +04:00
|
|
|
sub GetKeywordIdFromName {
|
|
|
|
my ($name) = (@_);
|
|
|
|
$name = lc($name);
|
|
|
|
return $::keywordsbyname{$name};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-09-16 01:49:26 +04:00
|
|
|
|
|
|
|
# Returns the modification time of a file.
|
|
|
|
|
|
|
|
sub ModTime {
|
|
|
|
my ($filename) = (@_);
|
|
|
|
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
|
|
|
|
$atime,$mtime,$ctime,$blksize,$blocks)
|
|
|
|
= stat($filename);
|
|
|
|
return $mtime;
|
|
|
|
}
|
|
|
|
|
2001-06-08 01:26:49 +04:00
|
|
|
$::VersionTableLoaded = 0;
|
1998-09-16 01:49:26 +04:00
|
|
|
sub GetVersionTable {
|
2001-06-08 01:26:49 +04:00
|
|
|
return if $::VersionTableLoaded;
|
1998-09-16 01:49:26 +04:00
|
|
|
my $mtime = ModTime("data/versioncache");
|
|
|
|
if (!defined $mtime || $mtime eq "") {
|
|
|
|
$mtime = 0;
|
|
|
|
}
|
|
|
|
if (time() - $mtime > 3600) {
|
2002-04-02 02:52:40 +04:00
|
|
|
use Token;
|
|
|
|
Token::CleanTokenTable();
|
1998-09-16 01:49:26 +04:00
|
|
|
GenerateVersionTable();
|
|
|
|
}
|
|
|
|
require 'data/versioncache';
|
|
|
|
if (!defined %::versions) {
|
|
|
|
GenerateVersionTable();
|
|
|
|
do 'data/versioncache';
|
|
|
|
|
|
|
|
if (!defined %::versions) {
|
1999-06-15 08:29:05 +04:00
|
|
|
die "Can't generate file data/versioncache";
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
}
|
2001-06-08 01:26:49 +04:00
|
|
|
$::VersionTableLoaded = 1;
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
|
2002-04-02 02:52:40 +04:00
|
|
|
# Validates a given username as a new username
|
|
|
|
# returns 1 if valid, 0 if invalid
|
|
|
|
sub ValidateNewUser {
|
|
|
|
my ($username, $old_username) = @_;
|
|
|
|
|
|
|
|
if(DBname_to_id($username) != 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-08-30 19:24:12 +04:00
|
|
|
my $sqluname = SqlQuote($username);
|
|
|
|
|
2002-04-02 02:52:40 +04:00
|
|
|
# Reject if the new login is part of an email change which is
|
|
|
|
# still in progress
|
2002-08-30 19:24:12 +04:00
|
|
|
#
|
|
|
|
# substring/locate stuff: bug 165221; this used to use regexes, but that
|
|
|
|
# was unsafe and required weird escaping; using substring to pull out
|
|
|
|
# the new/old email addresses and locate() to find the delimeter (':')
|
|
|
|
# is cleaner/safer
|
2002-04-02 02:52:40 +04:00
|
|
|
SendSQL("SELECT eventdata FROM tokens WHERE tokentype = 'emailold'
|
2002-08-30 19:24:12 +04:00
|
|
|
AND SUBSTRING(eventdata, 1, (LOCATE(':', eventdata) - 1)) = $sqluname
|
|
|
|
OR SUBSTRING(eventdata, (LOCATE(':', eventdata) + 1)) = $sqluname");
|
|
|
|
|
2002-04-02 02:52:40 +04:00
|
|
|
if (my ($eventdata) = FetchSQLData()) {
|
|
|
|
# Allow thru owner of token
|
|
|
|
if($old_username && ($eventdata eq "$old_username:$username")) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1998-09-16 01:49:26 +04:00
|
|
|
sub InsertNewUser {
|
1999-08-19 04:06:01 +04:00
|
|
|
my ($username, $realname) = (@_);
|
2000-12-23 02:01:30 +03:00
|
|
|
|
2001-07-11 09:29:21 +04:00
|
|
|
# Generate a new random password for the user.
|
|
|
|
my $password = GenerateRandomPassword();
|
|
|
|
my $cryptpassword = Crypt($password);
|
|
|
|
|
|
|
|
|
|
|
|
# Insert the new user record into the database.
|
1999-08-19 04:06:01 +04:00
|
|
|
$username = SqlQuote($username);
|
|
|
|
$realname = SqlQuote($realname);
|
2001-07-11 09:29:21 +04:00
|
|
|
$cryptpassword = SqlQuote($cryptpassword);
|
2002-09-22 21:15:13 +04:00
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL("INSERT INTO profiles (login_name, realname, cryptpassword)
|
|
|
|
VALUES ($username, $realname, $cryptpassword)");
|
2001-03-20 00:03:52 +03:00
|
|
|
PopGlobalSQLState();
|
2001-07-11 09:29:21 +04:00
|
|
|
|
|
|
|
# Return the password to the calling code so it can be included
|
|
|
|
# in an email sent to the user.
|
|
|
|
return $password;
|
|
|
|
}
|
|
|
|
|
2002-02-04 15:23:05 +03:00
|
|
|
# Removes all entries from logincookies for $userid, except for the
|
|
|
|
# optional $keep, which refers the logincookies.cookie primary key.
|
|
|
|
# (This is useful so that a user changing their password stays logged in)
|
|
|
|
sub InvalidateLogins {
|
|
|
|
my ($userid, $keep) = @_;
|
|
|
|
|
|
|
|
my $remove = "DELETE FROM logincookies WHERE userid = $userid";
|
|
|
|
if (defined $keep) {
|
|
|
|
$remove .= " AND cookie != " . SqlQuote($keep);
|
|
|
|
}
|
|
|
|
SendSQL($remove);
|
|
|
|
}
|
|
|
|
|
2001-07-11 09:29:21 +04:00
|
|
|
sub GenerateRandomPassword {
|
|
|
|
my ($size) = @_;
|
|
|
|
|
|
|
|
# Generated passwords are eight characters long by default.
|
|
|
|
$size ||= 8;
|
|
|
|
|
2001-08-11 05:51:05 +04:00
|
|
|
# The list of characters that can appear in a randomly generated password.
|
|
|
|
# Note that users can put any character into a password they choose themselves.
|
|
|
|
my @pwchars = (0..9, 'A'..'Z', 'a'..'z', '-', '_', '!', '@', '#', '$', '%', '^', '&', '*');
|
2001-07-11 09:29:21 +04:00
|
|
|
|
|
|
|
# The number of characters in the list.
|
|
|
|
my $pwcharslen = scalar(@pwchars);
|
|
|
|
|
|
|
|
# Generate the password.
|
|
|
|
my $password = "";
|
|
|
|
for ( my $i=0 ; $i<$size ; $i++ ) {
|
|
|
|
$password .= $pwchars[rand($pwcharslen)];
|
|
|
|
}
|
|
|
|
|
|
|
|
# Return the password.
|
1998-09-16 01:49:26 +04:00
|
|
|
return $password;
|
|
|
|
}
|
|
|
|
|
2001-10-23 19:44:53 +04:00
|
|
|
sub CanSeeBug {
|
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
my ($id, $userid) = @_;
|
2001-10-23 19:44:53 +04:00
|
|
|
|
|
|
|
# Query the database for the bug, retrieving a boolean value that
|
|
|
|
# represents whether or not the user is authorized to access the bug.
|
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
# if no groups are found --> user is permitted to access
|
|
|
|
# if no user is found for any group --> user is not permitted to access
|
|
|
|
my $query = "SELECT bugs.bug_id, reporter, assigned_to, qa_contact," .
|
|
|
|
" reporter_accessible, cclist_accessible," .
|
|
|
|
" cc.who IS NOT NULL," .
|
2002-10-02 07:06:06 +04:00
|
|
|
" COUNT(DISTINCT(bug_group_map.group_id)) as cntbugingroups," .
|
2002-09-22 21:15:13 +04:00
|
|
|
" COUNT(DISTINCT(user_group_map.group_id)) as cntuseringroups" .
|
|
|
|
" FROM bugs" .
|
|
|
|
" LEFT JOIN cc ON bugs.bug_id = cc.bug_id" .
|
|
|
|
" AND cc.who = $userid" .
|
|
|
|
" LEFT JOIN bug_group_map ON bugs.bug_id = bug_group_map.bug_id" .
|
|
|
|
" LEFT JOIN user_group_map ON" .
|
|
|
|
" user_group_map.group_id = bug_group_map.group_id" .
|
|
|
|
" AND user_group_map.isbless = 0" .
|
|
|
|
" AND user_group_map.user_id = $userid" .
|
|
|
|
" WHERE bugs.bug_id = $id GROUP BY bugs.bug_id";
|
2001-10-23 19:44:53 +04:00
|
|
|
PushGlobalSQLState();
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL($query);
|
|
|
|
my ($found_id, $reporter, $assigned_to, $qa_contact,
|
|
|
|
$rep_access, $cc_access,
|
|
|
|
$found_cc, $found_groups, $found_members)
|
|
|
|
= FetchSQLData();
|
2001-10-23 19:44:53 +04:00
|
|
|
PopGlobalSQLState();
|
2002-09-22 21:15:13 +04:00
|
|
|
return (
|
|
|
|
($found_groups == 0)
|
|
|
|
|| (($userid > 0) &&
|
|
|
|
(
|
|
|
|
($assigned_to == $userid)
|
|
|
|
|| ($qa_contact == $userid)
|
|
|
|
|| (($reporter == $userid) && $rep_access)
|
|
|
|
|| ($found_cc && $cc_access)
|
|
|
|
|| ($found_groups == $found_members)
|
|
|
|
))
|
|
|
|
);
|
2001-10-23 19:44:53 +04:00
|
|
|
}
|
2001-07-11 09:29:21 +04:00
|
|
|
|
|
|
|
sub ValidatePassword {
|
|
|
|
# Determines whether or not a password is valid (i.e. meets Bugzilla's
|
2002-10-06 15:52:37 +04:00
|
|
|
# requirements for length and content).
|
2001-07-11 09:29:21 +04:00
|
|
|
# If a second password is passed in, this function also verifies that
|
|
|
|
# the two passwords match.
|
|
|
|
my ($password, $matchpassword) = @_;
|
|
|
|
|
2002-10-06 15:52:37 +04:00
|
|
|
if (length($password) < 3) {
|
|
|
|
ThrowUserError("password_too_short");
|
|
|
|
} elsif (length($password) > 16) {
|
|
|
|
ThrowUserError("password_too_long");
|
|
|
|
} elsif ($matchpassword && $password ne $matchpassword) {
|
|
|
|
ThrowUserError("passwords_dont_match");
|
2001-07-11 09:29:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub Crypt {
|
|
|
|
# Crypts a password, generating a random salt to do it.
|
|
|
|
# Random salts are generated because the alternative is usually
|
|
|
|
# to use the first two characters of the password itself, and since
|
|
|
|
# the salt appears in plaintext at the beginning of the crypted
|
|
|
|
# password string this has the effect of revealing the first two
|
|
|
|
# characters of the password to anyone who views the crypted version.
|
|
|
|
|
|
|
|
my ($password) = @_;
|
|
|
|
|
|
|
|
# The list of characters that can appear in a salt. Salts and hashes
|
|
|
|
# are both encoded as a sequence of characters from a set containing
|
|
|
|
# 64 characters, each one of which represents 6 bits of the salt/hash.
|
|
|
|
# The encoding is similar to BASE64, the difference being that the
|
|
|
|
# BASE64 plus sign (+) is replaced with a forward slash (/).
|
|
|
|
my @saltchars = (0..9, 'A'..'Z', 'a'..'z', '.', '/');
|
|
|
|
|
|
|
|
# Generate the salt. We use an 8 character (48 bit) salt for maximum
|
|
|
|
# security on systems whose crypt uses MD5. Systems with older
|
|
|
|
# versions of crypt will just use the first two characters of the salt.
|
|
|
|
my $salt = '';
|
|
|
|
for ( my $i=0 ; $i < 8 ; ++$i ) {
|
|
|
|
$salt .= $saltchars[rand(64)];
|
|
|
|
}
|
|
|
|
|
|
|
|
# Crypt the password.
|
|
|
|
my $cryptedpassword = crypt($password, $salt);
|
|
|
|
|
|
|
|
# Return the crypted password.
|
|
|
|
return $cryptedpassword;
|
|
|
|
}
|
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
# ConfirmGroup(userid) is called prior to any activity that relies
|
|
|
|
# on user_group_map to ensure that derived group permissions are up-to-date.
|
|
|
|
# Permissions must be rederived if ANY groups have a last_changed newer
|
|
|
|
# than the profiles.refreshed_when value.
|
|
|
|
sub ConfirmGroup {
|
|
|
|
my ($user) = (@_);
|
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL("SELECT userid FROM profiles, groups WHERE userid = $user " .
|
|
|
|
"AND profiles.refreshed_when <= groups.last_changed ");
|
|
|
|
my $ret = FetchSQLData();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
if ($ret) {
|
|
|
|
DeriveGroup($user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# DeriveGroup removes and rederives all derived group permissions for
|
|
|
|
# the specified user.
|
|
|
|
sub DeriveGroup {
|
|
|
|
my ($user) = (@_);
|
|
|
|
PushGlobalSQLState();
|
|
|
|
|
|
|
|
SendSQL("LOCK TABLES profiles WRITE, user_group_map WRITE, group_group_map READ, groups READ");
|
|
|
|
|
|
|
|
# avoid races, we are only as up to date as the BEGINNING of this process
|
|
|
|
SendSQL("SELECT login_name, NOW() FROM profiles WHERE userid = $user");
|
|
|
|
my ($login, $starttime) = FetchSQLData();
|
|
|
|
|
|
|
|
# first remove any old derived stuff for this user
|
|
|
|
SendSQL("DELETE FROM user_group_map WHERE user_id = $user " .
|
|
|
|
"AND isderived = 1");
|
|
|
|
|
|
|
|
my %groupidsadded = ();
|
|
|
|
# add derived records for any matching regexps
|
|
|
|
SendSQL("SELECT id, userregexp FROM groups WHERE userregexp != ''");
|
|
|
|
while (MoreSQLData()) {
|
|
|
|
my ($groupid, $rexp) = FetchSQLData();
|
|
|
|
if ($login =~ m/$rexp/i) {
|
|
|
|
PushGlobalSQLState();
|
|
|
|
$groupidsadded{$groupid} = 1;
|
|
|
|
SendSQL("INSERT INTO user_group_map " .
|
|
|
|
"(user_id, group_id, isbless, isderived) " .
|
|
|
|
"VALUES ($user, $groupid, 0, 1)");
|
|
|
|
PopGlobalSQLState();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get a list of the groups of which the user is a member.
|
|
|
|
my %groupidschecked = ();
|
|
|
|
my @groupidstocheck = ();
|
|
|
|
SendSQL("SELECT group_id FROM user_group_map WHERE user_id = $user
|
|
|
|
AND NOT isbless");
|
|
|
|
while (MoreSQLData()) {
|
|
|
|
my ($groupid) = FetchSQLData();
|
|
|
|
push(@groupidstocheck,$groupid);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Each group needs to be checked for inherited memberships once.
|
|
|
|
while (@groupidstocheck) {
|
|
|
|
my $group = shift @groupidstocheck;
|
|
|
|
if (!defined($groupidschecked{"$group"})) {
|
|
|
|
$groupidschecked{"$group"} = 1;
|
|
|
|
SendSQL("SELECT grantor_id FROM group_group_map WHERE"
|
|
|
|
. " member_id = $group AND NOT isbless");
|
|
|
|
while (MoreSQLData()) {
|
|
|
|
my ($groupid) = FetchSQLData();
|
|
|
|
if (!defined($groupidschecked{"$groupid"})) {
|
|
|
|
push(@groupidstocheck,$groupid);
|
|
|
|
}
|
|
|
|
if (!$groupidsadded{$groupid}) {
|
|
|
|
$groupidsadded{$groupid} = 1;
|
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL("INSERT INTO user_group_map"
|
|
|
|
. " (user_id, group_id, isbless, isderived)"
|
|
|
|
. " VALUES ($user, $groupid, 0, 1)");
|
|
|
|
PopGlobalSQLState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SendSQL("UPDATE profiles SET refreshed_when = " .
|
|
|
|
SqlQuote($starttime) . "WHERE userid = $user");
|
|
|
|
SendSQL("UNLOCK TABLES");
|
|
|
|
PopGlobalSQLState();
|
|
|
|
};
|
|
|
|
|
2001-07-11 09:29:21 +04:00
|
|
|
|
2000-04-26 05:44:28 +04:00
|
|
|
sub DBID_to_real_or_loginname {
|
2000-04-21 22:45:55 +04:00
|
|
|
my ($id) = (@_);
|
2001-03-20 00:03:52 +03:00
|
|
|
PushGlobalSQLState();
|
2000-04-26 05:44:28 +04:00
|
|
|
SendSQL("SELECT login_name,realname FROM profiles WHERE userid = $id");
|
|
|
|
my ($l, $r) = FetchSQLData();
|
2001-03-20 00:03:52 +03:00
|
|
|
PopGlobalSQLState();
|
2000-05-08 22:23:55 +04:00
|
|
|
if (!defined $r || $r eq "") {
|
2000-04-26 05:44:28 +04:00
|
|
|
return $l;
|
2000-04-21 22:45:55 +04:00
|
|
|
} else {
|
2000-04-26 05:44:28 +04:00
|
|
|
return "$l ($r)";
|
2000-04-21 22:45:55 +04:00
|
|
|
}
|
|
|
|
}
|
1998-09-16 01:49:26 +04:00
|
|
|
|
|
|
|
sub DBID_to_name {
|
|
|
|
my ($id) = (@_);
|
2001-07-04 08:41:27 +04:00
|
|
|
# $id should always be a positive integer
|
|
|
|
if ($id =~ m/^([1-9][0-9]*)$/) {
|
|
|
|
$id = $1;
|
|
|
|
} else {
|
|
|
|
$::cachedNameArray{$id} = "__UNKNOWN__";
|
|
|
|
}
|
1998-09-16 01:49:26 +04:00
|
|
|
if (!defined $::cachedNameArray{$id}) {
|
2001-03-20 00:03:52 +03:00
|
|
|
PushGlobalSQLState();
|
1998-09-16 01:49:26 +04:00
|
|
|
SendSQL("select login_name from profiles where userid = $id");
|
|
|
|
my $r = FetchOneColumn();
|
2001-03-20 00:03:52 +03:00
|
|
|
PopGlobalSQLState();
|
2000-05-08 22:23:55 +04:00
|
|
|
if (!defined $r || $r eq "") {
|
1998-09-16 01:49:26 +04:00
|
|
|
$r = "__UNKNOWN__";
|
|
|
|
}
|
|
|
|
$::cachedNameArray{$id} = $r;
|
|
|
|
}
|
|
|
|
return $::cachedNameArray{$id};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub DBname_to_id {
|
|
|
|
my ($name) = (@_);
|
2001-03-20 00:03:52 +03:00
|
|
|
PushGlobalSQLState();
|
1998-09-16 01:49:26 +04:00
|
|
|
SendSQL("select userid from profiles where login_name = @{[SqlQuote($name)]}");
|
|
|
|
my $r = FetchOneColumn();
|
2001-03-20 00:03:52 +03:00
|
|
|
PopGlobalSQLState();
|
2001-07-04 08:41:27 +04:00
|
|
|
# $r should be a positive integer, this makes Taint mode happy
|
|
|
|
if (defined $r && $r =~ m/^([1-9][0-9]*)$/) {
|
|
|
|
return $1;
|
|
|
|
} else {
|
1998-09-16 01:49:26 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub DBNameToIdAndCheck {
|
2002-04-25 01:41:51 +04:00
|
|
|
my ($name) = (@_);
|
1998-09-16 01:49:26 +04:00
|
|
|
my $result = DBname_to_id($name);
|
|
|
|
if ($result > 0) {
|
|
|
|
return $result;
|
|
|
|
}
|
2002-04-25 01:41:51 +04:00
|
|
|
|
2002-08-16 02:57:21 +04:00
|
|
|
$::vars->{'name'} = $name;
|
|
|
|
ThrowUserError("invalid_username");
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
2002-08-12 09:43:05 +04:00
|
|
|
sub get_product_id {
|
|
|
|
my ($prod) = @_;
|
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL("SELECT id FROM products WHERE name = " . SqlQuote($prod));
|
|
|
|
my ($prod_id) = FetchSQLData();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return $prod_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_product_name {
|
|
|
|
my ($prod_id) = @_;
|
|
|
|
die "non-numeric prod_id '$prod_id' passed to get_product_name"
|
|
|
|
unless ($prod_id =~ /^\d+$/);
|
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL("SELECT name FROM products WHERE id = $prod_id");
|
|
|
|
my ($prod) = FetchSQLData();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return $prod;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_component_id {
|
|
|
|
my ($prod_id, $comp) = @_;
|
2002-09-28 22:42:54 +04:00
|
|
|
return undef unless ($prod_id =~ /^\d+$/);
|
2002-08-12 09:43:05 +04:00
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL("SELECT id FROM components " .
|
|
|
|
"WHERE product_id = $prod_id AND name = " . SqlQuote($comp));
|
|
|
|
my ($comp_id) = FetchSQLData();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return $comp_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_component_name {
|
|
|
|
my ($comp_id) = @_;
|
|
|
|
die "non-numeric comp_id '$comp_id' passed to get_component_name"
|
|
|
|
unless ($comp_id =~ /^\d+$/);
|
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL("SELECT name FROM components WHERE id = $comp_id");
|
|
|
|
my ($comp) = FetchSQLData();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return $comp;
|
|
|
|
}
|
|
|
|
|
2000-03-10 21:01:32 +03:00
|
|
|
# This routine quoteUrls contains inspirations from the HTML::FromText CPAN
|
|
|
|
# module by Gareth Rees <garethr@cre.canon.co.uk>. It has been heavily hacked,
|
|
|
|
# all that is really recognizable from the original is bits of the regular
|
|
|
|
# expressions.
|
2002-07-03 06:45:13 +04:00
|
|
|
# This has been rewritten to be faster, mainly by substituting 'as we go'.
|
|
|
|
# If you want to modify this routine, read the comments carefully
|
2000-03-10 21:01:32 +03:00
|
|
|
|
|
|
|
sub quoteUrls {
|
2002-02-20 02:22:24 +03:00
|
|
|
my ($text) = (@_);
|
2000-03-10 21:01:32 +03:00
|
|
|
return $text unless $text;
|
|
|
|
|
2002-07-03 06:45:13 +04:00
|
|
|
# We use /g for speed, but uris can have other things inside them
|
|
|
|
# (http://foo/bug#3 for example). Filtering that out filters valid
|
|
|
|
# bug refs out, so we have to do replacements.
|
|
|
|
# mailto can't contain space or #, so we don't have to bother for that
|
|
|
|
# Do this by escaping \0 to \1\0, and replacing matches with \0\0$count\0\0
|
|
|
|
# \0 is used because its unliklely to occur in the text, so the cost of
|
|
|
|
# doing this should be very small
|
|
|
|
# Also, \0 won't appear in the value_quote'd bug title, so we don't have
|
|
|
|
# to worry about bogus substitutions from there
|
|
|
|
|
|
|
|
# escape the 2nd escape char we're using
|
|
|
|
my $chr1 = chr(1);
|
|
|
|
$text =~ s/\0/$chr1\0/g;
|
|
|
|
|
|
|
|
# However, note that adding the title (for buglinks) can affect things
|
|
|
|
# In particular, attachment matches go before bug titles, so that titles
|
|
|
|
# with 'attachment 1' don't double match.
|
|
|
|
# Dupe checks go afterwards, because that uses ^ and \Z, which won't occur
|
|
|
|
# if it was subsituted as a bug title (since that always involve leading
|
|
|
|
# and trailing text)
|
|
|
|
|
|
|
|
# Because of entities, its easier (and quicker) to do this before escaping
|
2000-03-10 21:01:32 +03:00
|
|
|
|
|
|
|
my @things;
|
2002-07-03 06:45:13 +04:00
|
|
|
my $count = 0;
|
|
|
|
my $tmp;
|
|
|
|
|
|
|
|
# non-mailto protocols
|
|
|
|
my $protocol_re = qr/(afs|cid|ftp|gopher|http|https|mid|news|nntp|prospero|telnet|wais)/i;
|
|
|
|
|
|
|
|
$text =~ s~\b(${protocol_re}: # The protocol:
|
|
|
|
[^\s<>\"]+ # Any non-whitespace
|
|
|
|
[\w\/]) # so that we end in \w or /
|
|
|
|
~($tmp = html_quote($1)) &&
|
|
|
|
($things[$count++] = "<a href=\"$tmp\">$tmp</a>") &&
|
|
|
|
("\0\0" . ($count-1) . "\0\0")
|
|
|
|
~egox;
|
|
|
|
|
|
|
|
# We have to quote now, otherwise our html is itsself escaped
|
|
|
|
# THIS MEANS THAT A LITERAL ", <, >, ' MUST BE ESCAPED FOR A MATCH
|
|
|
|
|
|
|
|
$text = html_quote($text);
|
|
|
|
|
|
|
|
# mailto:
|
|
|
|
# Use |<nothing> so that $1 is defined regardless
|
|
|
|
$text =~ s~\b(mailto:|)?([\w\.\-\+\=]+\@[\w\-]+(?:\.[\w\-]+)+)\b
|
|
|
|
~<a href=\"mailto:$2\">$1$2</a>~igx;
|
|
|
|
|
|
|
|
# attachment links - handle both cases separatly for simplicity
|
|
|
|
$text =~ s~((?:^Created\ an\ |\b)attachment\s*\(id=(\d+)\))
|
|
|
|
~<a href=\"attachment.cgi?id=$2&action=view\">$1</a>~igx;
|
|
|
|
|
|
|
|
$text =~ s~\b(attachment\s*\#?\s*(\d+))
|
|
|
|
~<a href=\"attachment.cgi?id=$2&action=view\">$1</a>~igx;
|
|
|
|
|
|
|
|
# This handles bug a, comment b type stuff. Because we're using /g
|
|
|
|
# we have to do this in one pattern, and so this is semi-messy.
|
|
|
|
# Also, we can't use $bug_re?$comment_re? because that will match the
|
|
|
|
# empty string
|
|
|
|
my $bug_re = qr/bug\s*\#?\s*(\d+)/i;
|
|
|
|
my $comment_re = qr/comment\s*\#?\s*(\d+)/i;
|
|
|
|
$text =~ s~\b($bug_re(?:\s*,?\s*$comment_re)?|$comment_re)
|
|
|
|
~ # We have several choices. $1 here is the link, and $2-4 are set
|
|
|
|
# depending on which part matched
|
|
|
|
(defined($2) ? GetBugLink($2,$1,$3) :
|
|
|
|
"<a href=\"#c$4\">$1</a>")
|
|
|
|
~egox;
|
|
|
|
|
|
|
|
# Duplicate markers
|
|
|
|
$text =~ s~(?<=^\*\*\*\ This\ bug\ has\ been\ marked\ as\ a\ duplicate\ of\ )
|
|
|
|
(\d+)
|
|
|
|
(?=\ \*\*\*\Z)
|
|
|
|
~GetBugLink($1, $1)
|
|
|
|
~egmx;
|
|
|
|
|
|
|
|
# Now remove the encoding hacks
|
|
|
|
$text =~ s/\0\0(\d+)\0\0/$things[$1]/eg;
|
|
|
|
$text =~ s/$chr1\0/\0/g;
|
2000-03-10 21:01:32 +03:00
|
|
|
|
2001-01-25 01:24:06 +03:00
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
2002-07-03 06:45:13 +04:00
|
|
|
# GetBugLink creates a link to a bug, including its title.
|
2002-09-06 07:59:06 +04:00
|
|
|
# It takes either two or three parameters:
|
2002-07-03 06:45:13 +04:00
|
|
|
# - The bug number
|
|
|
|
# - The link text, to place between the <a>..</a>
|
|
|
|
# - An optional comment number, for linking to a particular
|
|
|
|
# comment in the bug
|
2001-01-25 01:24:06 +03:00
|
|
|
|
|
|
|
sub GetBugLink {
|
2002-07-03 06:45:13 +04:00
|
|
|
my ($bug_num, $link_text, $comment_num) = @_;
|
2001-11-12 16:43:59 +03:00
|
|
|
detaint_natural($bug_num) || die "GetBugLink() called with non-integer bug number";
|
|
|
|
|
|
|
|
# If we've run GetBugLink() for this bug number before, %::buglink
|
|
|
|
# will contain an anonymous array ref of relevent values, if not
|
|
|
|
# we need to get the information from the database.
|
|
|
|
if (! defined $::buglink{$bug_num}) {
|
|
|
|
# Make sure any unfetched data from a currently running query
|
|
|
|
# is saved off rather than overwritten
|
|
|
|
PushGlobalSQLState();
|
2001-01-25 01:24:06 +03:00
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("SELECT bugs.bug_status, resolution, short_desc " .
|
2001-11-12 16:43:59 +03:00
|
|
|
"FROM bugs WHERE bugs.bug_id = $bug_num");
|
|
|
|
|
|
|
|
# If the bug exists, save its data off for use later in the sub
|
|
|
|
if (MoreSQLData()) {
|
2002-09-22 21:15:13 +04:00
|
|
|
my ($bug_state, $bug_res, $bug_desc) = FetchSQLData();
|
2001-11-12 16:43:59 +03:00
|
|
|
# Initialize these variables to be "" so that we don't get warnings
|
|
|
|
# if we don't change them below (which is highly likely).
|
|
|
|
my ($pre, $title, $post) = ("", "", "");
|
2000-12-12 06:47:40 +03:00
|
|
|
|
2001-11-12 16:43:59 +03:00
|
|
|
$title = $bug_state;
|
|
|
|
if ($bug_state eq $::unconfirmedstate) {
|
|
|
|
$pre = "<i>";
|
|
|
|
$post = "</i>";
|
|
|
|
}
|
|
|
|
elsif (! IsOpenedState($bug_state)) {
|
|
|
|
$pre = "<strike>";
|
|
|
|
$title .= " $bug_res";
|
|
|
|
$post = "</strike>";
|
|
|
|
}
|
2002-09-22 21:15:13 +04:00
|
|
|
if (CanSeeBug($bug_num, $::userid)) {
|
2001-11-12 16:43:59 +03:00
|
|
|
$title .= " - $bug_desc";
|
|
|
|
}
|
|
|
|
$::buglink{$bug_num} = [$pre, value_quote($title), $post];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
# Even if there's nothing in the database, we want to save a blank
|
|
|
|
# anonymous array in the %::buglink hash so the query doesn't get
|
|
|
|
# run again next time we're called for this bug number.
|
|
|
|
$::buglink{$bug_num} = [];
|
|
|
|
}
|
|
|
|
# All done with this sidetrip
|
|
|
|
PopGlobalSQLState();
|
|
|
|
}
|
2001-01-25 01:24:06 +03:00
|
|
|
|
2001-11-12 16:43:59 +03:00
|
|
|
# Now that we know we've got all the information we're gonna get, let's
|
|
|
|
# return the link (which is the whole reason we were called :)
|
|
|
|
my ($pre, $title, $post) = @{$::buglink{$bug_num}};
|
|
|
|
# $title will be undefined if the bug didn't exist in the database.
|
|
|
|
if (defined $title) {
|
2002-07-03 06:45:13 +04:00
|
|
|
my $linkval = "show_bug.cgi?id=$bug_num";
|
|
|
|
if (defined $comment_num) {
|
|
|
|
$linkval .= "#c$comment_num";
|
|
|
|
}
|
|
|
|
return qq{$pre<a href="$linkval" title="$title">$link_text</a>$post};
|
2001-11-12 16:43:59 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return qq{$link_text};
|
|
|
|
}
|
2000-03-10 21:01:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
sub GetLongDescriptionAsText {
|
2000-01-22 07:24:42 +03:00
|
|
|
my ($id, $start, $end) = (@_);
|
2000-01-21 00:31:22 +03:00
|
|
|
my $result = "";
|
|
|
|
my $count = 0;
|
2002-08-20 01:17:28 +04:00
|
|
|
my $anyprivate = 0;
|
2000-01-22 07:24:42 +03:00
|
|
|
my ($query) = ("SELECT profiles.login_name, longdescs.bug_when, " .
|
2002-08-20 01:17:28 +04:00
|
|
|
" longdescs.thetext, longdescs.isprivate " .
|
2002-02-20 02:22:24 +03:00
|
|
|
"FROM longdescs, profiles " .
|
|
|
|
"WHERE profiles.userid = longdescs.who " .
|
|
|
|
"AND longdescs.bug_id = $id ");
|
2000-01-22 07:24:42 +03:00
|
|
|
|
|
|
|
if ($start && $start =~ /[1-9]/) {
|
|
|
|
# If the start is all zeros, then don't do this (because we want to
|
2000-03-10 21:26:23 +03:00
|
|
|
# not emit a leading "Additional Comments" line in that case.)
|
2000-01-22 07:24:42 +03:00
|
|
|
$query .= "AND longdescs.bug_when > '$start'";
|
|
|
|
$count = 1;
|
|
|
|
}
|
|
|
|
if ($end) {
|
|
|
|
$query .= "AND longdescs.bug_when <= '$end'";
|
|
|
|
}
|
|
|
|
|
|
|
|
$query .= "ORDER BY longdescs.bug_when";
|
|
|
|
SendSQL($query);
|
2000-01-21 00:31:22 +03:00
|
|
|
while (MoreSQLData()) {
|
2002-10-13 08:26:24 +04:00
|
|
|
my ($who, $when, $text, $isprivate, $work_time) = (FetchSQLData());
|
2000-01-21 00:31:22 +03:00
|
|
|
if ($count) {
|
2000-09-13 21:45:48 +04:00
|
|
|
$result .= "\n\n------- Additional Comments From $who".Param('emailsuffix')." ".
|
2000-01-21 00:31:22 +03:00
|
|
|
time2str("%Y-%m-%d %H:%M", str2time($when)) . " -------\n";
|
|
|
|
}
|
2002-08-20 01:17:28 +04:00
|
|
|
if (($isprivate > 0) && Param("insidergroup")) {
|
|
|
|
$anyprivate = 1;
|
|
|
|
}
|
2000-01-21 00:31:22 +03:00
|
|
|
$result .= $text;
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
|
2002-08-20 01:17:28 +04:00
|
|
|
return ($result, $anyprivate);
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
|
2002-02-20 02:22:24 +03:00
|
|
|
sub GetComments {
|
|
|
|
my ($id) = (@_);
|
|
|
|
my @comments;
|
|
|
|
SendSQL("SELECT profiles.realname, profiles.login_name,
|
|
|
|
date_format(longdescs.bug_when,'%Y-%m-%d %H:%i'),
|
2002-10-13 08:26:24 +04:00
|
|
|
longdescs.thetext, longdescs.work_time,
|
2002-08-20 01:17:28 +04:00
|
|
|
isprivate,
|
|
|
|
date_format(longdescs.bug_when,'%Y%m%d%H%i%s')
|
2002-02-20 02:22:24 +03:00
|
|
|
FROM longdescs, profiles
|
|
|
|
WHERE profiles.userid = longdescs.who
|
|
|
|
AND longdescs.bug_id = $id
|
|
|
|
ORDER BY longdescs.bug_when");
|
|
|
|
|
|
|
|
while (MoreSQLData()) {
|
|
|
|
my %comment;
|
2002-10-13 08:26:24 +04:00
|
|
|
($comment{'name'}, $comment{'email'}, $comment{'time'},
|
|
|
|
$comment{'body'}, $comment{'work_time'},
|
2002-08-20 01:17:28 +04:00
|
|
|
$comment{'isprivate'}, $comment{'when'}) = FetchSQLData();
|
2002-02-20 02:22:24 +03:00
|
|
|
|
|
|
|
$comment{'email'} .= Param('emailsuffix');
|
|
|
|
$comment{'name'} = $comment{'name'} || $comment{'email'};
|
|
|
|
|
|
|
|
push (@comments, \%comment);
|
|
|
|
}
|
|
|
|
|
|
|
|
return \@comments;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-09-16 01:49:26 +04:00
|
|
|
# Fills in a hashtable with info about the columns for the given table in the
|
|
|
|
# database. The hashtable has the following entries:
|
|
|
|
# -list- the list of column names
|
|
|
|
# <name>,type the type for the given name
|
|
|
|
|
|
|
|
sub LearnAboutColumns {
|
|
|
|
my ($table) = (@_);
|
|
|
|
my %a;
|
|
|
|
SendSQL("show columns from $table");
|
|
|
|
my @list = ();
|
|
|
|
my @row;
|
|
|
|
while (@row = FetchSQLData()) {
|
|
|
|
my ($name,$type) = (@row);
|
|
|
|
$a{"$name,type"} = $type;
|
|
|
|
push @list, $name;
|
|
|
|
}
|
|
|
|
$a{"-list-"} = \@list;
|
|
|
|
return \%a;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# If the above returned a enum type, take that type and parse it into the
|
|
|
|
# list of values. Assumes that enums don't ever contain an apostrophe!
|
|
|
|
|
|
|
|
sub SplitEnumType {
|
|
|
|
my ($str) = (@_);
|
|
|
|
my @result = ();
|
|
|
|
if ($str =~ /^enum\((.*)\)$/) {
|
|
|
|
my $guts = $1 . ",";
|
|
|
|
while ($guts =~ /^\'([^\']*)\',(.*)$/) {
|
|
|
|
push @result, $1;
|
|
|
|
$guts = $2;
|
2001-10-13 05:36:17 +04:00
|
|
|
}
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
return @result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# This routine is largely copied from Mysql.pm.
|
|
|
|
|
|
|
|
sub SqlQuote {
|
|
|
|
my ($str) = (@_);
|
1999-01-28 00:17:10 +03:00
|
|
|
# if (!defined $str) {
|
|
|
|
# confess("Undefined passed to SqlQuote");
|
|
|
|
# }
|
1998-09-16 01:49:26 +04:00
|
|
|
$str =~ s/([\\\'])/\\$1/g;
|
|
|
|
$str =~ s/\0/\\0/g;
|
2001-07-04 08:41:27 +04:00
|
|
|
# If it's been SqlQuote()ed, then it's safe, so we tell -T that.
|
2001-10-23 19:44:53 +04:00
|
|
|
trick_taint($str);
|
1998-09-16 01:49:26 +04:00
|
|
|
return "'$str'";
|
|
|
|
}
|
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
|
|
|
|
# UserInGroup returns information aboout the current user if no second
|
|
|
|
# parameter is specified
|
1999-03-11 19:30:54 +03:00
|
|
|
sub UserInGroup {
|
2002-09-22 21:15:13 +04:00
|
|
|
my ($groupname, $userid) = (@_);
|
|
|
|
if (!$userid) {
|
|
|
|
return $::vars->{'user'}{'groups'}{$_[0]};
|
|
|
|
}
|
|
|
|
PushGlobalSQLState();
|
|
|
|
$userid ||= $::userid;
|
|
|
|
SendSQL("SELECT groups.id FROM groups, user_group_map
|
|
|
|
WHERE groups.id = user_group_map.group_id
|
|
|
|
AND user_group_map.user_id = $userid
|
|
|
|
AND isbless = 0
|
|
|
|
AND groups.name = " . SqlQuote($groupname));
|
|
|
|
my $result = FetchOneColumn();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return defined($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub UserCanBlessGroup {
|
|
|
|
my ($groupname) = (@_);
|
|
|
|
PushGlobalSQLState();
|
|
|
|
# check if user explicitly can bless group
|
|
|
|
SendSQL("SELECT groups.id FROM groups, user_group_map
|
|
|
|
WHERE groups.id = user_group_map.group_id
|
|
|
|
AND user_group_map.user_id = $::userid
|
|
|
|
AND isbless = 1
|
|
|
|
AND groups.name = " . SqlQuote($groupname));
|
|
|
|
my $result = FetchOneColumn();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
if ($result) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
PushGlobalSQLState();
|
|
|
|
# check if user is a member of a group that can bless this group
|
|
|
|
# this group does not count
|
|
|
|
SendSQL("SELECT groups.id FROM groups, user_group_map,
|
|
|
|
group_group_map
|
|
|
|
WHERE groups.id = grantor_id
|
|
|
|
AND user_group_map.user_id = $::userid
|
|
|
|
AND user_group_map.isbless = 0
|
|
|
|
AND group_group_map.isbless = 1
|
|
|
|
AND user_group_map.group_id = member_id
|
|
|
|
AND groups.name = " . SqlQuote($groupname));
|
|
|
|
$result = FetchOneColumn();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub UserCanBlessAnything {
|
|
|
|
PushGlobalSQLState();
|
|
|
|
# check if user explicitly can bless a group
|
|
|
|
SendSQL("SELECT group_id FROM user_group_map
|
|
|
|
WHERE user_id = $::userid AND isbless = 1");
|
|
|
|
my $result = FetchOneColumn();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
if ($result) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
PushGlobalSQLState();
|
|
|
|
# check if user is a member of a group that can bless this group
|
|
|
|
SendSQL("SELECT groups.id FROM groups, user_group_map,
|
|
|
|
group_group_map
|
|
|
|
WHERE groups.id = grantor_id
|
|
|
|
AND user_group_map.user_id = $::userid
|
|
|
|
AND group_group_map.isbless = 1
|
|
|
|
AND user_group_map.group_id = member_id");
|
|
|
|
$result = FetchOneColumn();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
if ($result) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
1999-03-11 19:30:54 +03:00
|
|
|
}
|
|
|
|
|
2001-08-11 05:18:24 +04:00
|
|
|
sub BugInGroup {
|
|
|
|
my ($bugid, $groupname) = (@_);
|
|
|
|
PushGlobalSQLState();
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("SELECT bug_group_map.bug_id != 0 FROM bug_group_map, groups
|
|
|
|
WHERE bug_group_map.bug_id = $bugid
|
|
|
|
AND bug_group_map.group_id = groups.id
|
|
|
|
AND groups.name = " . SqlQuote($groupname));
|
|
|
|
my $bugingroup = FetchOneColumn();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return $bugingroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub BugInGroupId {
|
|
|
|
my ($bugid, $groupid) = (@_);
|
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL("SELECT bug_id != 0 FROM bug_group_map
|
|
|
|
WHERE bug_id = $bugid
|
|
|
|
AND group_id = $groupid");
|
2001-08-11 05:18:24 +04:00
|
|
|
my $bugingroup = FetchOneColumn();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return $bugingroup;
|
|
|
|
}
|
|
|
|
|
2000-03-10 19:25:03 +03:00
|
|
|
sub GroupExists {
|
|
|
|
my ($groupname) = (@_);
|
2002-06-03 17:36:39 +04:00
|
|
|
PushGlobalSQLState();
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("SELECT id FROM groups WHERE name=" . SqlQuote($groupname));
|
|
|
|
my $id = FetchOneColumn();
|
2002-06-03 17:36:39 +04:00
|
|
|
PopGlobalSQLState();
|
2002-09-22 21:15:13 +04:00
|
|
|
return $id;
|
2000-03-10 19:25:03 +03:00
|
|
|
}
|
1999-03-11 19:30:54 +03:00
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
sub GroupNameToId {
|
2001-08-11 05:18:24 +04:00
|
|
|
my ($groupname) = (@_);
|
|
|
|
PushGlobalSQLState();
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("SELECT id FROM groups WHERE name=" . SqlQuote($groupname));
|
|
|
|
my $id = FetchOneColumn();
|
2001-08-11 05:18:24 +04:00
|
|
|
PopGlobalSQLState();
|
2002-09-22 21:15:13 +04:00
|
|
|
return $id;
|
2001-08-11 05:18:24 +04:00
|
|
|
}
|
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
sub GroupIdToName {
|
|
|
|
my ($groupid) = (@_);
|
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL("SELECT name FROM groups WHERE id = $groupid");
|
|
|
|
my $name = FetchOneColumn();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-06 07:16:52 +04:00
|
|
|
# Determines whether or not a group is active by checking
|
|
|
|
# the "isactive" column for the group in the "groups" table.
|
2002-09-22 21:15:13 +04:00
|
|
|
# Note: This function selects groups by id rather than by name.
|
2001-06-06 07:16:52 +04:00
|
|
|
sub GroupIsActive {
|
2002-09-22 21:15:13 +04:00
|
|
|
my ($groupid) = (@_);
|
|
|
|
$groupid ||= 0;
|
2002-06-03 17:36:39 +04:00
|
|
|
PushGlobalSQLState();
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("SELECT isactive FROM groups WHERE id=$groupid");
|
2001-06-06 07:16:52 +04:00
|
|
|
my $isactive = FetchOneColumn();
|
2002-06-03 17:36:39 +04:00
|
|
|
PopGlobalSQLState();
|
2001-06-06 07:16:52 +04:00
|
|
|
return $isactive;
|
|
|
|
}
|
|
|
|
|
2000-01-23 04:03:15 +03:00
|
|
|
# Determines if the given bug_status string represents an "Opened" bug. This
|
2002-09-06 07:59:06 +04:00
|
|
|
# routine ought to be parameterizable somehow, as people tend to introduce
|
2000-01-23 04:03:15 +03:00
|
|
|
# new states into Bugzilla.
|
|
|
|
|
|
|
|
sub IsOpenedState {
|
|
|
|
my ($state) = (@_);
|
2001-09-15 01:50:08 +04:00
|
|
|
if (grep($_ eq $state, OpenStates())) {
|
2000-01-23 04:03:15 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-09-15 01:50:08 +04:00
|
|
|
# This sub will return an array containing any status that
|
|
|
|
# is considered an open bug.
|
|
|
|
|
|
|
|
sub OpenStates {
|
|
|
|
return ('NEW', 'REOPENED', 'ASSIGNED', $::unconfirmedstate);
|
|
|
|
}
|
|
|
|
|
2000-01-23 04:03:15 +03:00
|
|
|
|
1999-10-08 03:54:52 +04:00
|
|
|
sub RemoveVotes {
|
2000-02-17 08:15:23 +03:00
|
|
|
my ($id, $who, $reason) = (@_);
|
|
|
|
my $whopart = "";
|
|
|
|
if ($who) {
|
|
|
|
$whopart = " AND votes.who = $who";
|
|
|
|
}
|
2001-08-16 06:46:15 +04:00
|
|
|
SendSQL("SELECT profiles.login_name, profiles.userid, votes.count, " .
|
|
|
|
"products.votesperuser, products.maxvotesperbug " .
|
|
|
|
"FROM profiles " .
|
|
|
|
"LEFT JOIN votes ON profiles.userid = votes.who " .
|
|
|
|
"LEFT JOIN bugs USING(bug_id) " .
|
2002-08-12 09:43:05 +04:00
|
|
|
"LEFT JOIN products ON products.id = bugs.product_id " .
|
2000-02-17 08:15:23 +03:00
|
|
|
"WHERE votes.bug_id = $id " .
|
|
|
|
$whopart);
|
1999-10-08 03:54:52 +04:00
|
|
|
my @list;
|
|
|
|
while (MoreSQLData()) {
|
2001-08-25 04:12:12 +04:00
|
|
|
my ($name, $userid, $oldvotes, $votesperuser, $maxvotesperbug) = (FetchSQLData());
|
|
|
|
push(@list, [$name, $userid, $oldvotes, $votesperuser, $maxvotesperbug]);
|
1999-10-08 03:54:52 +04:00
|
|
|
}
|
|
|
|
if (0 < @list) {
|
2000-02-17 08:15:23 +03:00
|
|
|
foreach my $ref (@list) {
|
2001-08-25 04:12:12 +04:00
|
|
|
my ($name, $userid, $oldvotes, $votesperuser, $maxvotesperbug) = (@$ref);
|
|
|
|
my $s;
|
|
|
|
|
|
|
|
$maxvotesperbug = $votesperuser if ($votesperuser < $maxvotesperbug);
|
2001-08-16 06:46:15 +04:00
|
|
|
|
|
|
|
# If this product allows voting and the user's votes are in
|
|
|
|
# the acceptable range, then don't do anything.
|
2001-08-25 04:12:12 +04:00
|
|
|
next if $votesperuser && $oldvotes <= $maxvotesperbug;
|
2001-08-16 06:46:15 +04:00
|
|
|
|
|
|
|
# If the user has more votes on this bug than this product
|
|
|
|
# allows, then reduce the number of votes so it fits
|
|
|
|
my $newvotes = $votesperuser ? $maxvotesperbug : 0;
|
2001-08-25 04:12:12 +04:00
|
|
|
|
|
|
|
my $removedvotes = $oldvotes - $newvotes;
|
|
|
|
|
|
|
|
$s = $oldvotes == 1 ? "" : "s";
|
|
|
|
my $oldvotestext = "You had $oldvotes vote$s on this bug.";
|
|
|
|
|
|
|
|
$s = $removedvotes == 1 ? "" : "s";
|
|
|
|
my $removedvotestext = "You had $removedvotes vote$s removed from this bug.";
|
|
|
|
|
|
|
|
my $newvotestext;
|
2001-08-16 06:46:15 +04:00
|
|
|
if ($newvotes) {
|
|
|
|
SendSQL("UPDATE votes SET count = $newvotes " .
|
|
|
|
"WHERE bug_id = $id AND who = $userid");
|
2001-08-25 04:12:12 +04:00
|
|
|
$s = $newvotes == 1 ? "" : "s";
|
|
|
|
$newvotestext = "You still have $newvotes vote$s on this bug."
|
2001-08-16 06:46:15 +04:00
|
|
|
} else {
|
|
|
|
SendSQL("DELETE FROM votes WHERE bug_id = $id AND who = $userid");
|
2001-08-25 04:12:12 +04:00
|
|
|
$newvotestext = "You have no more votes remaining on this bug.";
|
2001-08-16 06:46:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Notice that we did not make sure that the user fit within the $votesperuser
|
2001-08-25 04:12:12 +04:00
|
|
|
# range. This is considered to be an acceptable alternative to losing votes
|
2001-08-16 06:46:15 +04:00
|
|
|
# during product moves. Then next time the user attempts to change their votes,
|
|
|
|
# they will be forced to fit within the $votesperuser limit.
|
|
|
|
|
|
|
|
# Now lets send the e-mail to alert the user to the fact that their votes have
|
|
|
|
# been reduced or removed.
|
2000-09-12 20:29:38 +04:00
|
|
|
my $sendmailparm = '-ODeliveryMode=deferred';
|
|
|
|
if (Param('sendmailnow')) {
|
|
|
|
$sendmailparm = '';
|
|
|
|
}
|
2002-02-17 11:22:31 +03:00
|
|
|
if (open(SENDMAIL, "|/usr/lib/sendmail $sendmailparm -t -i")) {
|
2000-02-17 08:15:23 +03:00
|
|
|
my %substs;
|
2001-08-25 04:12:12 +04:00
|
|
|
|
2000-02-17 08:15:23 +03:00
|
|
|
$substs{"to"} = $name;
|
|
|
|
$substs{"bugid"} = $id;
|
|
|
|
$substs{"reason"} = $reason;
|
2001-08-25 04:12:12 +04:00
|
|
|
|
|
|
|
$substs{"votesremoved"} = $removedvotes;
|
|
|
|
$substs{"votesold"} = $oldvotes;
|
|
|
|
$substs{"votesnew"} = $newvotes;
|
|
|
|
|
|
|
|
$substs{"votesremovedtext"} = $removedvotestext;
|
|
|
|
$substs{"votesoldtext"} = $oldvotestext;
|
|
|
|
$substs{"votesnewtext"} = $newvotestext;
|
|
|
|
|
|
|
|
$substs{"count"} = $removedvotes . "\n " . $newvotestext;
|
|
|
|
|
2000-02-17 17:57:57 +03:00
|
|
|
my $msg = PerformSubsts(Param("voteremovedmail"),
|
|
|
|
\%substs);
|
|
|
|
print SENDMAIL $msg;
|
2000-02-17 08:15:23 +03:00
|
|
|
close SENDMAIL;
|
|
|
|
}
|
1999-10-08 03:54:52 +04:00
|
|
|
}
|
2000-02-17 08:15:23 +03:00
|
|
|
SendSQL("SELECT SUM(count) FROM votes WHERE bug_id = $id");
|
|
|
|
my $v = FetchOneColumn();
|
|
|
|
$v ||= 0;
|
|
|
|
SendSQL("UPDATE bugs SET votes = $v, delta_ts = delta_ts " .
|
|
|
|
"WHERE bug_id = $id");
|
1999-10-08 03:54:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-20 19:18:30 +04:00
|
|
|
# Take two comma or space separated strings and return what
|
|
|
|
# values were removed from or added to the new one.
|
|
|
|
sub DiffStrings {
|
|
|
|
my ($oldstr, $newstr) = @_;
|
|
|
|
|
2001-08-19 22:26:21 +04:00
|
|
|
# Split the old and new strings into arrays containing their values.
|
|
|
|
$oldstr =~ s/[\s,]+/ /g;
|
|
|
|
$newstr =~ s/[\s,]+/ /g;
|
|
|
|
my @old = split(" ", $oldstr);
|
|
|
|
my @new = split(" ", $newstr);
|
|
|
|
|
2001-07-20 19:18:30 +04:00
|
|
|
my (@remove, @add) = ();
|
|
|
|
|
|
|
|
# Find values that were removed
|
2001-08-19 22:26:21 +04:00
|
|
|
foreach my $value (@old) {
|
|
|
|
push (@remove, $value) if !grep($_ eq $value, @new);
|
2001-07-20 19:18:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Find values that were added
|
2001-08-19 22:26:21 +04:00
|
|
|
foreach my $value (@new) {
|
|
|
|
push (@add, $value) if !grep($_ eq $value, @old);
|
2001-07-20 19:18:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
my $removed = join (", ", @remove);
|
|
|
|
my $added = join (", ", @add);
|
|
|
|
|
|
|
|
return ($removed, $added);
|
|
|
|
}
|
|
|
|
|
1998-09-16 01:49:26 +04:00
|
|
|
sub PerformSubsts {
|
|
|
|
my ($str, $substs) = (@_);
|
|
|
|
$str =~ s/%([a-z]*)%/(defined $substs->{$1} ? $substs->{$1} : Param($1))/eg;
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
2002-10-13 08:26:24 +04:00
|
|
|
sub FormatTimeUnit {
|
|
|
|
# Returns a number with 2 digit precision, unless the last digit is a 0
|
|
|
|
# then it returns only 1 digit precision
|
|
|
|
my ($time) = (@_);
|
|
|
|
|
|
|
|
my $newtime = sprintf("%.2f", $time);
|
|
|
|
|
|
|
|
if ($newtime =~ /0\Z/) {
|
|
|
|
$newtime = sprintf("%.1f", $time);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $newtime;
|
|
|
|
|
|
|
|
}
|
2002-02-03 12:28:48 +03:00
|
|
|
###############################################################################
|
|
|
|
# Global Templatization Code
|
|
|
|
|
|
|
|
# Use the template toolkit (http://www.template-toolkit.org/) to generate
|
|
|
|
# the user interface using templates in the "template/" subdirectory.
|
|
|
|
use Template;
|
|
|
|
|
|
|
|
# Create the global template object that processes templates and specify
|
|
|
|
# configuration parameters that apply to all templates processed in this script.
|
2002-04-27 06:16:32 +04:00
|
|
|
|
|
|
|
# IMPORTANT - If you make any configuration changes here, make sure to make
|
|
|
|
# them in t/004.template.t and checksetup.pl. You may also need to change the
|
|
|
|
# date settings were last changed - see the comments in checksetup.pl for
|
|
|
|
# details
|
2002-03-01 08:57:43 +03:00
|
|
|
$::template ||= Template->new(
|
2002-02-03 12:28:48 +03:00
|
|
|
{
|
|
|
|
# Colon-separated list of directories containing templates.
|
2002-08-17 08:40:53 +04:00
|
|
|
INCLUDE_PATH => "template/en/custom:template/en/default" ,
|
2002-02-03 12:28:48 +03:00
|
|
|
|
|
|
|
# Remove white-space before template directives (PRE_CHOMP) and at the
|
|
|
|
# beginning and end of templates and template blocks (TRIM) for better
|
|
|
|
# looking, more compact content. Use the plus sign at the beginning
|
|
|
|
# of directives to maintain white space (i.e. [%+ DIRECTIVE %]).
|
|
|
|
PRE_CHOMP => 1 ,
|
|
|
|
TRIM => 1 ,
|
|
|
|
|
2002-04-28 22:43:14 +04:00
|
|
|
COMPILE_DIR => 'data/',
|
2002-04-27 06:16:32 +04:00
|
|
|
|
2002-02-03 12:28:48 +03:00
|
|
|
# Functions for processing text within templates in various ways.
|
2002-05-07 13:45:32 +04:00
|
|
|
# IMPORTANT! When adding a filter here that does not override a
|
|
|
|
# built-in filter, please also add a stub filter to checksetup.pl
|
|
|
|
# and t/004template.t.
|
2002-02-03 12:28:48 +03:00
|
|
|
FILTERS =>
|
|
|
|
{
|
|
|
|
# Render text in strike-through style.
|
|
|
|
strike => sub { return "<strike>" . $_[0] . "</strike>" } ,
|
2002-02-13 05:27:24 +03:00
|
|
|
|
|
|
|
# Returns the text with backslashes, single/double quotes,
|
|
|
|
# and newlines/carriage returns escaped for use in JS strings.
|
|
|
|
js => sub
|
|
|
|
{
|
|
|
|
my ($var) = @_;
|
|
|
|
$var =~ s/([\\\'\"])/\\$1/g;
|
|
|
|
$var =~ s/\n/\\n/g;
|
|
|
|
$var =~ s/\r/\\r/g;
|
|
|
|
return $var;
|
2002-03-12 16:55:07 +03:00
|
|
|
} ,
|
2002-04-24 22:27:43 +04:00
|
|
|
|
2002-07-19 18:03:58 +04:00
|
|
|
# HTML collapses newlines in element attributes to a single space,
|
|
|
|
# so form elements which may have whitespace (ie comments) need
|
|
|
|
# to be encoded using 
|
|
|
|
# See bugs 4928, 22983 and 32000 for more details
|
|
|
|
html_linebreak => sub
|
|
|
|
{
|
|
|
|
my ($var) = @_;
|
|
|
|
$var =~ s/\r\n/\
/g;
|
|
|
|
$var =~ s/\n\r/\
/g;
|
|
|
|
$var =~ s/\r/\
/g;
|
|
|
|
$var =~ s/\n/\
/g;
|
|
|
|
return $var;
|
|
|
|
} ,
|
|
|
|
|
2002-04-24 22:27:43 +04:00
|
|
|
# This subroutine in CGI.pl escapes characters in a variable
|
|
|
|
# or value string for use in a query string. It escapes all
|
|
|
|
# characters NOT in the regex set: [a-zA-Z0-9_\-.]. The 'uri'
|
|
|
|
# filter should be used for a full URL that may have
|
|
|
|
# characters that need encoding.
|
2002-10-26 05:57:09 +04:00
|
|
|
url_quote => \&Bugzilla::Util::url_quote,
|
2002-09-25 11:11:45 +04:00
|
|
|
|
|
|
|
# In CSV, quotes are doubled, and any value containing a quote or a
|
|
|
|
# comma is enclosed in quotes.
|
|
|
|
csv => sub
|
|
|
|
{
|
|
|
|
my ($var) = @_;
|
|
|
|
$var =~ s/"/""/;
|
|
|
|
if ($var =~ /",/) {
|
|
|
|
$var = "\"$var\"";
|
|
|
|
}
|
|
|
|
return $var;
|
|
|
|
} ,
|
2002-02-03 12:28:48 +03:00
|
|
|
} ,
|
|
|
|
}
|
2002-09-09 05:10:54 +04:00
|
|
|
) || die("Template creation failed: " . Template->error());
|
2002-02-03 12:28:48 +03:00
|
|
|
|
|
|
|
# Use the Toolkit Template's Stash module to add utility pseudo-methods
|
|
|
|
# to template variables.
|
|
|
|
use Template::Stash;
|
|
|
|
|
|
|
|
# Add "contains***" methods to list variables that search for one or more
|
|
|
|
# items in a list and return boolean values representing whether or not
|
|
|
|
# one/all/any item(s) were found.
|
|
|
|
$Template::Stash::LIST_OPS->{ contains } =
|
|
|
|
sub {
|
|
|
|
my ($list, $item) = @_;
|
|
|
|
return grep($_ eq $item, @$list);
|
|
|
|
};
|
|
|
|
|
|
|
|
$Template::Stash::LIST_OPS->{ containsany } =
|
|
|
|
sub {
|
|
|
|
my ($list, $items) = @_;
|
|
|
|
foreach my $item (@$items) {
|
|
|
|
return 1 if grep($_ eq $item, @$list);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
2002-05-30 05:44:33 +04:00
|
|
|
# Add a "substr" method to the Template Toolkit's "scalar" object
|
|
|
|
# that returns a substring of a string.
|
|
|
|
$Template::Stash::SCALAR_OPS->{ substr } =
|
|
|
|
sub {
|
|
|
|
my ($scalar, $offset, $length) = @_;
|
|
|
|
return substr($scalar, $offset, $length);
|
|
|
|
};
|
|
|
|
|
|
|
|
# Add a "truncate" method to the Template Toolkit's "scalar" object
|
|
|
|
# that truncates a string to a certain length.
|
|
|
|
$Template::Stash::SCALAR_OPS->{ truncate } =
|
|
|
|
sub {
|
|
|
|
my ($string, $length, $ellipsis) = @_;
|
|
|
|
$ellipsis ||= "";
|
|
|
|
|
|
|
|
return $string if !$length || length($string) <= $length;
|
|
|
|
|
|
|
|
my $strlen = $length - length($ellipsis);
|
|
|
|
my $newstr = substr($string, 0, $strlen) . $ellipsis;
|
|
|
|
return $newstr;
|
|
|
|
};
|
|
|
|
|
|
|
|
###############################################################################
|
2002-03-12 16:55:07 +03:00
|
|
|
|
2002-09-18 03:28:24 +04:00
|
|
|
# Constructs a format object from URL parameters. You most commonly call it
|
|
|
|
# like this:
|
|
|
|
# my $format = GetFormat("foo/bar", $::FORM{'format'}, $::FORM{'ctype'});
|
|
|
|
sub GetFormat {
|
|
|
|
my ($template, $format, $ctype) = @_;
|
2002-03-12 16:55:07 +03:00
|
|
|
|
2002-09-18 03:28:24 +04:00
|
|
|
$ctype ||= "html";
|
2002-10-07 10:44:07 +04:00
|
|
|
$format ||= "";
|
2002-03-12 16:55:07 +03:00
|
|
|
|
2002-09-18 03:28:24 +04:00
|
|
|
# Security - allow letters and a hyphen only
|
|
|
|
$ctype =~ s/[^a-zA-Z\-]//g;
|
|
|
|
$format =~ s/[^a-zA-Z\-]//g;
|
2002-09-27 03:25:12 +04:00
|
|
|
trick_taint($ctype);
|
|
|
|
trick_taint($format);
|
2002-03-12 16:55:07 +03:00
|
|
|
|
2002-09-18 03:28:24 +04:00
|
|
|
$template .= ($format ? "-$format" : "");
|
|
|
|
$template .= ".$ctype.tmpl";
|
2002-03-12 16:55:07 +03:00
|
|
|
|
2002-09-18 03:28:24 +04:00
|
|
|
return
|
|
|
|
{
|
|
|
|
'template' => $template ,
|
|
|
|
'extension' => $ctype ,
|
|
|
|
'ctype' => $::contenttypes->{$ctype} || "text/plain" ,
|
|
|
|
};
|
2002-03-12 16:55:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
2002-02-03 12:28:48 +03:00
|
|
|
# Define the global variables and functions that will be passed to the UI
|
|
|
|
# template. Additional values may be added to this hash before templates
|
|
|
|
# are processed.
|
|
|
|
$::vars =
|
|
|
|
{
|
|
|
|
# Function for retrieving global parameters.
|
|
|
|
'Param' => \&Param ,
|
|
|
|
|
2002-07-26 22:16:39 +04:00
|
|
|
# Function to create date strings
|
2002-07-26 22:20:58 +04:00
|
|
|
'time2str' => \&time2str ,
|
2002-07-26 22:16:39 +04:00
|
|
|
|
2002-02-03 12:28:48 +03:00
|
|
|
# Function for processing global parameters that contain references
|
|
|
|
# to other global parameters.
|
|
|
|
'PerformSubsts' => \&PerformSubsts ,
|
2002-02-13 05:27:24 +03:00
|
|
|
|
|
|
|
# Generic linear search function
|
2002-08-19 17:59:45 +04:00
|
|
|
'lsearch' => \&Bugzilla::Util::lsearch ,
|
2002-03-01 09:01:12 +03:00
|
|
|
|
2002-09-21 19:17:09 +04:00
|
|
|
# quoteUrls - autolinkifies text
|
|
|
|
'quoteUrls' => \"eUrls ,
|
|
|
|
|
2002-03-01 09:01:12 +03:00
|
|
|
# UserInGroup - you probably want to cache this
|
|
|
|
'UserInGroup' => \&UserInGroup ,
|
2002-04-26 00:42:59 +04:00
|
|
|
|
|
|
|
# SyncAnyPendingShadowChanges - called in the footer to sync the shadowdb
|
|
|
|
'SyncAnyPendingShadowChanges' => \&SyncAnyPendingShadowChanges ,
|
2002-04-27 10:57:16 +04:00
|
|
|
|
|
|
|
# User Agent - useful for detecting in templates
|
|
|
|
'user_agent' => $ENV{'HTTP_USER_AGENT'} ,
|
2002-08-29 13:25:54 +04:00
|
|
|
|
|
|
|
# Bugzilla version
|
|
|
|
'VERSION' => $Bugzilla::Config::VERSION,
|
2002-02-03 12:28:48 +03:00
|
|
|
};
|
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
|
1998-09-16 01:49:26 +04:00
|
|
|
1;
|