2 # This script is part of debbugs, and is released
3 # under the terms of the GPL version 2, or any later
4 # version at your option.
5 # See the file README and COPYING for more information.
7 # [Other people have contributed to this file; their copyrights should
9 # Copyright 2004-2006 by Anthony Towns <ajt@debian.org>
10 # Copyright 2007 by Don Armstrong <don@donarmstrong.com>.
16 # Sanitize environent for taint
18 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
21 binmode(STDOUT,':encoding(UTF-8)');
22 use POSIX qw(strftime nice);
24 use Debbugs::Config qw(:globals :text :config);
28 use Debbugs::Common qw(getparsedaddrs make_list getmaintainers getpseudodesc);
30 use Debbugs::Bugs qw(get_bugs bug_filter newest_bug);
31 use Debbugs::Packages qw(getsrcpkgs getpkgsrc get_versions);
33 use Debbugs::Status qw(splitpackages);
35 use Debbugs::CGI qw(:all);
37 use Debbugs::CGI::Pkgreport qw(:all);
39 use Debbugs::Text qw(:templates);
42 my $q = new CGI::Simple;
44 if ($q->request_method() eq 'HEAD') {
45 print $q->header(-type => "text/html",
51 my $default_params = {ordering => 'normal',
58 our %param = cgi_parameters(query => $q,
59 single => [qw(ordering archive repeatmerged),
60 qw(bug-rev pend-rev sev-rev),
61 qw(maxdays mindays version),
62 qw(data which dist newest),
65 default => $default_params,
68 my ($form_options,$param) = ({},undef);
69 ($form_options,$param)= form_options_and_normal_param(\%param)
70 if $param{form_options};
72 %param = %{$param} if defined $param;
74 if (exists $param{form_options} and defined $param{form_options}) {
75 delete $param{form_options};
76 delete $param{submit} if exists $param{submit};
77 for my $default (keys %{$default_params}) {
78 if (exists $param{$default} and
79 not ref($default_params->{$default}) and
80 $default_params->{$default} eq $param{$default}
82 delete $param{$default};
85 for my $incexc (qw(include exclude)) {
86 next unless exists $param{$incexc};
87 # normalize tag to tags
88 $param{$incexc} = [map {s/^tag:/tags:/; $_} grep /\S\:\S/, make_list($param{$incexc})];
90 for my $key (keys %package_search_keys) {
91 next unless exists $param{key};
92 $param{$key} = [map {split /\s*,\s*/} make_list($param{$key})];
94 # kill off keys for which empty values are meaningless
95 for my $key (qw(package src submitter affects severity status dist)) {
96 next unless exists $param{$key};
97 $param{$key} = [grep {defined $_ and length $_}
98 make_list($param{$key})];
100 print $q->redirect(munge_url('pkgreport.cgi?',%param));
104 # normalize innclude/exclude keys; currently this is in two locations,
105 # which is suboptimal. Closes: #567407
106 for my $incexc (qw(include exclude)) {
107 next unless exists $param{$incexc};
108 # normalize tag to tags
109 $param{$incexc} = [map {s/^tag:/tags:/; $_} make_list($param{$incexc})];
114 # map from yes|no to 1|0
115 for my $key (qw(repeatmerged bug-rev pend-rev sev-rev)) {
116 if (exists $param{$key}){
117 if ($param{$key} =~ /^no$/i) {
120 elsif ($param{$key}) {
126 if (lc($param{archive}) eq 'no') {
129 elsif (lc($param{archive}) eq 'yes') {
134 if (exists $param{dist} and $param{dist} eq '') {
138 my $include = $param{'&include'} || $param{'include'} || "";
139 my $exclude = $param{'&exclude'} || $param{'exclude'} || "";
141 my $users = $param{'users'} || "";
143 my $ordering = $param{'ordering'};
144 my $raw_sort = ($param{'raw'} || "no") eq "yes";
145 my $old_view = ($param{'oldview'} || "no") eq "yes";
146 my $age_sort = ($param{'age'} || "no") eq "yes";
147 unless (defined $ordering) {
148 $ordering = "normal";
149 $ordering = "oldview" if $old_view;
150 $ordering = "raw" if $raw_sort;
151 $ordering = 'age' if $age_sort;
153 $param{ordering} = $ordering;
155 our ($bug_order) = $ordering =~ /(age(?:rev)?)/;
156 $bug_order = '' if not defined $bug_order;
158 my $bug_rev = ($param{'bug-rev'} || "no") eq "yes";
159 my $pend_rev = ($param{'pend-rev'} || "no") eq "yes";
160 my $sev_rev = ($param{'sev-rev'} || "no") eq "yes";
162 my @inc_exc_mapping = ({name => 'pending',
180 key => 'includesubj',
184 key => 'excludesubj',
187 for my $incexcmap (@inc_exc_mapping) {
188 push @{$param{$incexcmap->{incexc}}}, map {"$incexcmap->{name}:$_"}
189 map{split /\s*,\s*/} make_list($param{$incexcmap->{key}})
190 if exists $param{$incexcmap->{key}};
191 delete $param{$incexcmap->{key}};
195 my $maxdays = ($param{'maxdays'} || -1);
196 my $mindays = ($param{'mindays'} || 0);
197 my $version = $param{'version'} || undef;
200 our %hidden = map { $_, 1 } qw(status severity classification);
204 "pri" => [map { "pending=$_" }
205 qw(pending forwarded pending-fixed fixed done absent)],
206 "ttl" => ["Outstanding","Forwarded","Pending Upload",
207 "Fixed in NMU","Resolved","From other Branch"],
208 "def" => "Unknown Pending Status",
209 "ord" => [0,1,2,3,4,5,6],
213 "pri" => [map { "severity=$_" } @gSeverityList],
214 "ttl" => [map { $gSeverityDisplay{$_} } @gSeverityList],
215 "def" => "Unknown Severity",
216 "ord" => [0..@gSeverityList],
218 "classification" => [ {
219 "nam" => "Classification",
220 "pri" => [qw(pending=pending+tag=wontfix
221 pending=pending+tag=moreinfo
222 pending=pending+tag=patch
223 pending=pending+tag=confirmed
225 "ttl" => ["Will Not Fix","More information needed",
226 "Patch Available","Confirmed"],
227 "def" => "Unclassified",
228 "ord" => [2,3,4,1,0,5],
230 "oldview" => [ qw(status severity) ],
231 "normal" => [ qw(status severity classification) ],
234 if (exists $param{which} and exists $param{data}) {
235 $param{$param{which}} = [exists $param{$param{which}}?(make_list($param{$param{which}})):(),
236 make_list($param{data}),
238 delete $param{which};
242 if (defined $param{maintenc}) {
243 $param{maint} = maint_decode($param{maintenc});
244 delete $param{maintenc}
247 if (exists $param{pkg}) {
248 $param{package} = $param{pkg};
252 if (not grep {exists $param{$_}} keys %package_search_keys and exists $param{users}) {
253 $param{usertag} = [make_list($param{users})];
260 for my $user (map {split /[\s*,\s*]+/} make_list($param{users}||[])) {
261 next unless length($user);
262 add_user($user,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
265 if (defined $param{usertag}) {
266 for my $usertag (make_list($param{usertag})) {
268 my ($u, $t) = split /:/, $usertag, 2;
269 Debbugs::User::read_usertags(\%select_ut, $u);
270 unless (defined $t && $t ne "") {
271 $t = join(",", keys(%select_ut));
273 add_user($u,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
274 push @{$param{tag}}, split /,/, $t;
278 quitcgi("You have to choose something to select by") unless grep {exists $param{$_}} keys %package_search_keys;
281 my $Archived = $param{archive} ? " Archived" : "";
283 my $this = munge_url('pkgreport.cgi?',
292 # addusers for source and binary packages being searched for
293 my $pkgsrc = getpkgsrc();
294 my $srcpkg = getsrcpkgs();
295 for my $package (# For binary packages, add the binary package
296 # and corresponding source package
297 make_list($param{package}||[]),
298 (map {defined $pkgsrc->{$_}?($pkgsrc->{$_}):()}
299 make_list($param{package}||[]),
301 # For source packages, add the source package
302 # and corresponding binary packages
303 make_list($param{src}||[]),
304 (map {defined $srcpkg->{$_}?($srcpkg->{$_}):()}
305 make_list($param{src}||[]),
308 next unless defined $package;
309 add_user($package.'@'.$config{usertag_package_domain},
310 \%ut,\%bugusertags,\%seen_users,\%cats,\%hidden)
311 if defined $config{usertag_package_domain};
315 # walk through the keys and make the right get_bugs query.
317 my $form_option_variables = {};
318 $form_option_variables->{search_key_order} = [@package_search_key_order];
320 # Set the title sanely and clean up parameters
322 my @temp = @package_search_key_order;
323 while (my ($key,$value) = splice @temp, 0, 2) {
324 next unless exists $param{$key};
326 for my $entry (make_list($param{$key})) {
327 # we'll handle newest below
328 next if $key eq 'newest';
330 if (exists $param{dist} and ($key eq 'package' or $key eq 'src')) {
331 my %versions = get_versions(package => $entry,
332 (exists $param{dist}?(dist => $param{dist}):()),
333 (exists $param{arch}?(arch => $param{arch}):(arch => $config{default_architectures})),
334 ($key eq 'src'?(arch => q(source)):()),
339 if (keys %versions > 1) {
340 $verdesc = 'versions '. join(', ',
341 map { $_ .' ['.join(', ',
342 sort @{$versions{$_}}
347 $verdesc = 'version '.join(', ',
351 $extra= " ($verdesc)" if keys %versions;
353 if ($key eq 'maint' and $entry eq '') {
354 push @entries, "no one (packages without maintainers)"
357 push @entries, $entry.$extra;
360 push @title,$value.' '.join(' or ', @entries) if @entries;
362 if (defined $param{newest}) {
363 my $newest_bug = newest_bug();
364 @bugs = ($newest_bug - $param{newest} + 1) .. $newest_bug;
365 push @title, 'in '.@bugs.' newest reports';
366 $param{bugs} = [exists $param{bugs}?make_list($param{bugs}):(),
371 my $title = $gBugs.' '.join(' and ', map {/ or /?"($_)":$_} @title);
375 @bugs = get_bugs((map {exists $param{$_}?($_,$param{$_}):()}
376 grep {$_ ne 'newest'}
377 keys %package_search_keys, 'archive'),
381 # shove in bugs which affect this package if there is a package or a
382 # source given (by default), but no affects options given
383 if (not exists $param{affects} and not exists $param{noaffects} and
384 (exists $param{src} or
385 exists $param{package})) {
386 push @bugs, get_bugs((map {my $key = $_;
387 exists $param{$key}?($key =~ /^(?:package|src)$/?'affects':$key,
388 ($key eq 'src'?[map {"src:$_"}make_list($param{$key})]:$param{$_})):()}
389 grep {$_ ne 'newest'}
390 keys %package_search_keys, 'archive'),
395 # filter out included or excluded bugs
398 if (defined $param{version}) {
399 $title .= " at version $param{version}";
401 elsif (defined $param{dist}) {
402 $title .= " in $param{dist}";
405 $title = html_escape($title);
407 my @names; my @prior; my @order;
408 determine_ordering(cats => \%cats,
410 ordering => \$ordering,
417 # strip out duplicate bugs
419 @bugs{@bugs} = @bugs;
422 my $result = pkg_htmlizebugs(bugs => \@bugs,
427 ordering => $ordering,
428 bugusertags => \%bugusertags,
430 bug_order => $bug_order,
431 repeatmerged => $param{repeatmerged},
436 (exists $param{dist})?(dist => $param{dist}):(),
439 print "Content-Type: text/html; charset=utf-8\n\n";
441 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
442 print "<HTML><HEAD>\n" .
443 "<TITLE>$title -- $gProject$Archived $gBug report logs</TITLE>\n" .
444 qq(<link rel="stylesheet" href="$gWebHostBugDir/css/bugs.css" type="text/css">) .
446 '<BODY onload="pagemain();">' .
448 print qq(<DIV id="status_mask"></DIV>\n);
449 print "<H1>" . "$gProject$Archived $gBug report logs: $title" .
454 my $pkg = $param{package} if defined $param{package};
455 my $src = $param{src} if defined $param{src};
457 my $pseudodesc = getpseudodesc();
458 if (defined $pseudodesc and defined $pkg and exists $pseudodesc->{$pkg}) {
462 # output information about the packages
464 for my $package (make_list($param{package}||[])) {
465 print generate_package_info(binary => 1,
471 for my $package (make_list($param{src}||[])) {
472 print generate_package_info(binary => 0,
479 if (exists $param{maint} or exists $param{maintenc}) {
480 print "<p>Note that maintainers may use different Maintainer fields for\n";
481 print "different packages, so there may be other reports filed under\n";
482 print "different addresses.\n";
484 if (exists $param{submitter}) {
485 print "<p>Note that people may use different email accounts for\n";
486 print "different bugs, so there may be other reports filed under\n";
487 print "different addresses.\n";
492 print fill_in_template(template=>'cgi/pkgreport_javascript');
494 print qq(<h2 class="outstanding"><!--<a class="options" href="javascript:toggle(1)">-->Options<!--</a>--></h2>\n);
496 print option_form(template => 'cgi/pkgreport_options',
498 form_options => $form_options,
499 variables => $form_option_variables,
503 print fill_in_template(template=>'html/html_tail',
504 hole_var => {'&strftime' => \&POSIX::strftime,
507 print "</body></html>\n";