|
|
| 1 |
#!/usr/bin/perl -wT |
| 2 |
# -*- Mode: perl; indent-tabs-mode: nil -*- |
| 3 |
# |
| 4 |
# The contents of this file are subject to the Mozilla Public |
| 5 |
# License Version 1.1 (the "License"); you may not use this file |
| 6 |
# except in compliance with the License. You may obtain a copy of |
| 7 |
# the License at http://www.mozilla.org/MPL/ |
| 8 |
# |
| 9 |
# Software distributed under the License is distributed on an "AS |
| 10 |
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
| 11 |
# implied. See the License for the specific language governing |
| 12 |
# rights and limitations under the License. |
| 13 |
# |
| 14 |
# The Original Code is the Bugzilla Bug Tracking System. |
| 15 |
# |
| 16 |
# The Initial Developer of the Original Code is Netscape Communications |
| 17 |
# Corporation. Portions created by Netscape are |
| 18 |
# Copyright (C) 1998 Netscape Communications Corporation. All |
| 19 |
# Rights Reserved. |
| 20 |
# |
| 21 |
# Contributor(s): Terry Weissman <terry@mozilla.org> |
| 22 |
|
| 23 |
use strict; |
| 24 |
|
| 25 |
use lib qw(.); |
| 26 |
use vars qw ($template $vars); |
| 27 |
# Suppress "used only once" warnings. |
| 28 |
use vars |
| 29 |
qw( |
| 30 |
%proddesc |
| 31 |
%classdesc |
| 32 |
); |
| 33 |
|
| 34 |
use Bugzilla; |
| 35 |
use Bugzilla::Constants; |
| 36 |
use Bugzilla::GNOME; |
| 37 |
use Digest::MD5 qw(md5_hex); |
| 38 |
|
| 39 |
require "CGI.pl"; |
| 40 |
|
| 41 |
use vars qw($vars @legal_product @legal_gnome_target @legal_gnome_version |
| 42 |
@legal_priority @legal_severity); |
| 43 |
|
| 44 |
my $cgi = Bugzilla->cgi; |
| 45 |
my $dbh = Bugzilla->dbh; |
| 46 |
|
| 47 |
############################################################################### |
| 48 |
# Begin Data/Security Validation |
| 49 |
############################################################################### |
| 50 |
|
| 51 |
# Check whether or not the user is currently logged in. |
| 52 |
Bugzilla->login(LOGIN_REQUIRED); |
| 53 |
GetVersionTable(); |
| 54 |
|
| 55 |
UserInGroup("edittraces") |
| 56 |
|| ThrowUserError("auth_failure", {group => "edittraces", |
| 57 |
action => "edit", |
| 58 |
object => "traces"}); |
| 59 |
|
| 60 |
my $action = trim($cgi->param('action') || ''); |
| 61 |
my $hash = trim($cgi->param('hash') || ''); |
| 62 |
my $old_hash = trim($cgi->param('old_hash') || ''); |
| 63 |
trick_taint($hash); trick_taint($old_hash); |
| 64 |
|
| 65 |
my $report = "traces/list.html.tmpl"; |
| 66 |
my $cur_trace; |
| 67 |
|
| 68 |
print $cgi->header(); |
| 69 |
|
| 70 |
sub ValidateForm { |
| 71 |
my %cur_trace; |
| 72 |
|
| 73 |
my $id = trim($cgi->param('dupe_of') || ''); |
| 74 |
ValidateBugID($id); |
| 75 |
|
| 76 |
my $trace = trim($cgi->param('trace') || ''); |
| 77 |
trick_taint($trace); |
| 78 |
my $version = trim($cgi->param('version') || ''); |
| 79 |
trick_taint($version); |
| 80 |
$version = undef unless $version; |
| 81 |
|
| 82 |
my $product_id = trim($cgi->param('product_id') || undef); |
| 83 |
|
| 84 |
my $product; |
| 85 |
if ($product_id) { |
| 86 |
detaint_natural($product_id) || ThrowCodeError("invalid_product_id"); |
| 87 |
$product = get_product_name($product_id); |
| 88 |
CanEnterProductOrWarn($product); |
| 89 |
} |
| 90 |
|
| 91 |
CheckFormField($cgi, 'gnome_version', \@legal_gnome_version) |
| 92 |
if $cgi->param('gnome_version'); |
| 93 |
my $gnome_version = $cgi->param('gnome_version'); |
| 94 |
$gnome_version = undef unless $gnome_version; |
| 95 |
trick_taint($gnome_version) if $gnome_version; |
| 96 |
|
| 97 |
my $functions = join(' ', get_traces_from_string($trace)); |
| 98 |
my $hash = md5_hex($functions); |
| 99 |
|
| 100 |
%cur_trace = ( |
| 101 |
hash => $hash, |
| 102 |
dupe_of => $id, |
| 103 |
product_id => $product_id, |
| 104 |
user_id => Bugzilla->user->id, |
| 105 |
version => $version, |
| 106 |
gnome_version => $gnome_version, |
| 107 |
trace => $trace, |
| 108 |
|
| 109 |
functions => $functions, |
| 110 |
product => $product, |
| 111 |
); |
| 112 |
|
| 113 |
return \%cur_trace; |
| 114 |
} |
| 115 |
|
| 116 |
if ($action eq 'add') { |
| 117 |
$report = "traces/show.html.tmpl"; |
| 118 |
|
| 119 |
$cur_trace = ValidateForm(); |
| 120 |
|
| 121 |
$cur_trace->{'is_dupe'} = $dbh->selectrow_array( |
| 122 |
'SELECT 1 FROM traces WHERE hash = ?', undef, $cur_trace->{'hash'}); |
| 123 |
|
| 124 |
if ($cgi->param('do_add') && $cur_trace->{'functions'} ne '' |
| 125 |
&& !$cur_trace->{'is_dupe'}) |
| 126 |
{ |
| 127 |
$dbh->do('INSERT INTO traces (hash, dupe_of, product_id, user_id, |
| 128 |
version, gnome_version, trace) |
| 129 |
VALUES (?, ?, ?, ?, ?, ?, ?)', |
| 130 |
undef, ($cur_trace->{'hash'}, $cur_trace->{'dupe_of'}, |
| 131 |
$cur_trace->{'product_id'}, $cur_trace->{'user_id'}, |
| 132 |
$cur_trace->{'version'}, $cur_trace->{'gnome_version'}, |
| 133 |
$cur_trace->{'trace'})); |
| 134 |
|
| 135 |
$vars->{'message'} = 'trace_created'; |
| 136 |
$action = 'edit'; |
| 137 |
$old_hash = ''; |
| 138 |
} |
| 139 |
else { |
| 140 |
$vars->{'cur_trace'} = $cur_trace; |
| 141 |
} |
| 142 |
} |
| 143 |
if ($action eq 'edit') { |
| 144 |
$report = "traces/show.html.tmpl"; |
| 145 |
|
| 146 |
if ($old_hash) { |
| 147 |
# Validate: |
| 148 |
$cur_trace = ValidateForm(); |
| 149 |
my $trace_info = Bugzilla::GNOME->get_traces_info($old_hash); |
| 150 |
ThrowUserError('trace_nonexistent') unless @{$trace_info}; |
| 151 |
|
| 152 |
$cur_trace->{'old_hash'} = $old_hash; |
| 153 |
|
| 154 |
if ($cur_trace->{'old_hash'} eq $cur_trace->{'hash'}) { |
| 155 |
$cur_trace->{'is_dupe'} = 0 |
| 156 |
} else { |
| 157 |
$cur_trace->{'is_dupe'} = $dbh->selectrow_array( |
| 158 |
'SELECT 1 FROM traces WHERE hash = ?', undef, $cur_trace->{'hash'}); |
| 159 |
} |
| 160 |
|
| 161 |
if ($cgi->param('do_edit') && $cur_trace->{'functions'} ne '' |
| 162 |
&& !$cur_trace->{'is_dupe'}) |
| 163 |
{ |
| 164 |
$dbh->do('UPDATE traces |
| 165 |
SET hash = ?, dupe_of = ?, product_id = ?, user_id = ?, |
| 166 |
version = ?, gnome_version = ?, trace = ? |
| 167 |
WHERE hash = ?', |
| 168 |
undef, ($cur_trace->{'hash'}, $cur_trace->{'dupe_of'}, |
| 169 |
$cur_trace->{'product_id'}, $cur_trace->{'user_id'}, |
| 170 |
$cur_trace->{'version'}, $cur_trace->{'gnome_version'}, |
| 171 |
$cur_trace->{'trace'}, |
| 172 |
$cur_trace->{'old_hash'})); |
| 173 |
|
| 174 |
# Very important (old_hash has been changed in the database to hash!): |
| 175 |
$cur_trace->{'old_hash'} = $cur_trace->{'hash'}; |
| 176 |
|
| 177 |
$trace_info = Bugzilla::GNOME->get_traces_info($cur_trace->{'hash'}); |
| 178 |
$cur_trace = $trace_info->[0]; # get the data again from the database.. just for testing purposes |
| 179 |
$vars->{'message'} = 'trace_updated'; |
| 180 |
} |
| 181 |
|
| 182 |
} else { |
| 183 |
my $trace_info = Bugzilla::GNOME->get_traces_info($hash); |
| 184 |
ThrowUserError('trace_nonexistent') unless @{$trace_info}; |
| 185 |
|
| 186 |
$cur_trace = $trace_info->[0]; |
| 187 |
$cur_trace->{'old_hash'} = $cur_trace->{'hash'}; |
| 188 |
} |
| 189 |
} |
| 190 |
elsif ($action eq "delete") { |
| 191 |
my $trace_info = Bugzilla::GNOME->get_traces_info($hash); |
| 192 |
ThrowUserError('trace_nonexistent') unless @{$trace_info}; |
| 193 |
|
| 194 |
$cur_trace = $trace_info->[0]; |
| 195 |
|
| 196 |
if ($cgi->param('do_delete')) { |
| 197 |
$dbh->do('DELETE FROM traces WHERE hash = ?', undef, ($hash)); |
| 198 |
$vars->{'message'} = 'trace_deleted'; |
| 199 |
} |
| 200 |
else { |
| 201 |
$action = 'delete'; |
| 202 |
$report = 'traces/confirm-delete.html.tmpl'; |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
$vars->{'legal_gnome_versions'} = \@legal_gnome_version; |
| 207 |
my %products = reverse GetSelectableProducts(1); |
| 208 |
$vars->{'products'} = \%products; |
| 209 |
$vars->{'action'} = $action; |
| 210 |
|
| 211 |
if ($cur_trace && %{$cur_trace}) { |
| 212 |
if (defined $cur_trace->{'dupe_of'}) { |
| 213 |
$cur_trace->{'dupe_of_bug'} = |
| 214 |
new Bugzilla::Bug($cur_trace->{'dupe_of'}, Bugzilla->user->id); |
| 215 |
} |
| 216 |
|
| 217 |
if (!defined $cur_trace->{'functions'} |
| 218 |
&& defined $cur_trace->{'trace'}) |
| 219 |
{ |
| 220 |
$cur_trace->{'functions'} = |
| 221 |
join(' ', get_traces_from_string($cur_trace->{'trace'})); |
| 222 |
} |
| 223 |
$vars->{'cur_trace'} = $cur_trace; |
| 224 |
} |
| 225 |
|
| 226 |
$template->process($report, $vars) |
| 227 |
|| ThrowTemplateError($template->error()); |
| 228 |
|
| 229 |
|