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", '400 Bad Request')
279 unless grep {exists $param{$_}} keys %package_search_keys;
282 my $Archived = $param{archive} ? " Archived" : "";
284 my $this = munge_url('pkgreport.cgi?',
293 # addusers for source and binary packages being searched for
294 my $pkgsrc = getpkgsrc();
295 my $srcpkg = getsrcpkgs();
296 for my $package (# For binary packages, add the binary package
297 # and corresponding source package
298 make_list($param{package}||[]),
299 (map {defined $pkgsrc->{$_}?($pkgsrc->{$_}):()}
300 make_list($param{package}||[]),
302 # For source packages, add the source package
303 # and corresponding binary packages
304 make_list($param{src}||[]),
305 (map {defined $srcpkg->{$_}?($srcpkg->{$_}):()}
306 make_list($param{src}||[]),
309 next unless defined $package;
310 add_user($package.'@'.$config{usertag_package_domain},
311 \%ut,\%bugusertags,\%seen_users,\%cats,\%hidden)
312 if defined $config{usertag_package_domain};
316 # walk through the keys and make the right get_bugs query.
318 my $form_option_variables = {};
319 $form_option_variables->{search_key_order} = [@package_search_key_order];
321 # Set the title sanely and clean up parameters
323 my @temp = @package_search_key_order;
324 while (my ($key,$value) = splice @temp, 0, 2) {
325 next unless exists $param{$key};
327 for my $entry (make_list($param{$key})) {
328 # we'll handle newest below
329 next if $key eq 'newest';
331 if (exists $param{dist} and ($key eq 'package' or $key eq 'src')) {
332 my %versions = get_versions(package => $entry,
333 (exists $param{dist}?(dist => $param{dist}):()),
334 (exists $param{arch}?(arch => $param{arch}):(arch => $config{default_architectures})),
335 ($key eq 'src'?(arch => q(source)):()),
340 if (keys %versions > 1) {
341 $verdesc = 'versions '. join(', ',
342 map { $_ .' ['.join(', ',
343 sort @{$versions{$_}}
348 $verdesc = 'version '.join(', ',
352 $extra= " ($verdesc)" if keys %versions;
354 if ($key eq 'maint' and $entry eq '') {
355 push @entries, "no one (packages without maintainers)"
358 push @entries, $entry.$extra;
361 push @title,$value.' '.join(' or ', @entries) if @entries;
363 if (defined $param{newest}) {
364 my $newest_bug = newest_bug();
365 @bugs = ($newest_bug - $param{newest} + 1) .. $newest_bug;
366 push @title, 'in '.@bugs.' newest reports';
367 $param{bugs} = [exists $param{bugs}?make_list($param{bugs}):(),
372 my $title = $gBugs.' '.join(' and ', map {/ or /?"($_)":$_} @title);
376 @bugs = get_bugs((map {exists $param{$_}?($_,$param{$_}):()}
377 grep {$_ ne 'newest'}
378 keys %package_search_keys, 'archive'),
382 # shove in bugs which affect this package if there is a package or a
383 # source given (by default), but no affects options given
384 if (not exists $param{affects} and not exists $param{noaffects} and
385 (exists $param{src} or
386 exists $param{package})) {
387 push @bugs, get_bugs((map {my $key = $_;
388 exists $param{$key}?($key =~ /^(?:package|src)$/?'affects':$key,
389 ($key eq 'src'?[map {"src:$_"}make_list($param{$key})]:$param{$_})):()}
390 grep {$_ ne 'newest'}
391 keys %package_search_keys, 'archive'),
396 # filter out included or excluded bugs
399 if (defined $param{version}) {
400 $title .= " at version $param{version}";
402 elsif (defined $param{dist}) {
403 $title .= " in $param{dist}";
406 $title = html_escape($title);
408 my @names; my @prior; my @order;
409 determine_ordering(cats => \%cats,
411 ordering => \$ordering,
418 # strip out duplicate bugs
420 @bugs{@bugs} = @bugs;
423 my $result = pkg_htmlizebugs(bugs => \@bugs,
428 ordering => $ordering,
429 bugusertags => \%bugusertags,
431 bug_order => $bug_order,
432 repeatmerged => $param{repeatmerged},
437 (exists $param{dist})?(dist => $param{dist}):(),
440 print "Cache-Control: public, max-age=300\n";
441 print "Content-Type: text/html; charset=utf-8\n\n";
443 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
444 print "<HTML><HEAD>\n" .
445 "<TITLE>$title -- $gProject$Archived $gBug report logs</TITLE>\n" .
446 qq(<link rel="stylesheet" href="$gWebHostBugDir/css/bugs.css" type="text/css">) .
448 '<BODY onload="pagemain();">' .
450 print qq(<DIV id="status_mask"></DIV>\n);
451 print "<H1>" . "$gProject$Archived $gBug report logs: $title" .
456 my $pkg = $param{package} if defined $param{package};
457 my $src = $param{src} if defined $param{src};
459 my $pseudodesc = getpseudodesc();
460 if (defined $pseudodesc and defined $pkg and exists $pseudodesc->{$pkg}) {
464 # output information about the packages
466 for my $package (make_list($param{package}||[])) {
467 print generate_package_info(binary => 1,
473 for my $package (make_list($param{src}||[])) {
474 print generate_package_info(binary => 0,
481 if (exists $param{maint} or exists $param{maintenc}) {
482 print "<p>Note that maintainers may use different Maintainer fields for\n";
483 print "different packages, so there may be other reports filed under\n";
484 print "different addresses.\n";
486 if (exists $param{submitter}) {
487 print "<p>Note that people may use different email accounts for\n";
488 print "different bugs, so there may be other reports filed under\n";
489 print "different addresses.\n";
494 print fill_in_template(template=>'cgi/pkgreport_javascript');
496 print qq(<h2 class="outstanding"><!--<a class="options" href="javascript:toggle(1)">-->Options<!--</a>--></h2>\n);
498 print option_form(template => 'cgi/pkgreport_options',
500 form_options => $form_options,
501 variables => $form_option_variables,
505 print fill_in_template(template=>'html/html_tail',
506 hole_var => {'&strftime' => \&POSIX::strftime,
509 print "</body></html>\n";