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 # if we're running out of git, we want to use the git base directory as the
22 # first INC directory. If you're not running out of git, don't do that.
23 use File::Basename qw(dirname);
28 abs_path(dirname(abs_path(__FILE__)) . '/../');
29 # clear the taint; we'll assume that the absolute path to __FILE__ is the
30 # right path if there's a .git directory there
31 ($debbugs_dir) = $debbugs_dir =~ /([[:print:]]+)/;
32 if (defined $debbugs_dir and
33 -d $debbugs_dir . '/.git/') {
37 # if the first directory in @INC is not an absolute directory, assume that
38 # someone has overridden us via -I.
39 if ($INC[0] !~ /^\//) {
42 use if defined $debbugs_dir, lib => $debbugs_dir;
44 binmode(STDOUT,':encoding(UTF-8)');
45 use POSIX qw(strftime nice);
46 use List::AllUtils qw(uniq);
48 use Debbugs::Config qw(:globals :text :config);
52 use Debbugs::Common qw(getparsedaddrs make_list getmaintainers getpseudodesc);
54 use Debbugs::Bugs qw(get_bugs bug_filter newest_bug);
55 use Debbugs::Packages qw(getsrcpkgs getpkgsrc get_versions);
57 use Debbugs::Status qw(splitpackages);
59 use Debbugs::CGI qw(:all);
61 use Debbugs::CGI::Pkgreport qw(:all);
63 use Debbugs::Text qw(:templates);
68 if (defined $config{database}) {
69 $s = Debbugs::DB->connect($config{database}) or
70 die "Unable to connect to DB";
74 my $q = new CGI::Simple;
76 if ($q->request_method() eq 'HEAD') {
77 print $q->header(-type => "text/html",
83 my $default_params = {ordering => 'normal',
90 our %param = cgi_parameters(query => $q,
91 single => [qw(ordering archive repeatmerged),
92 qw(bug-rev pend-rev sev-rev),
93 qw(maxdays mindays version),
94 qw(data which dist newest),
97 default => $default_params,
100 my ($form_options,$param) = ({},undef);
101 ($form_options,$param)= form_options_and_normal_param(\%param)
102 if $param{form_options};
104 %param = %{$param} if defined $param;
106 if (exists $param{form_options} and defined $param{form_options}) {
107 delete $param{form_options};
108 delete $param{submit} if exists $param{submit};
109 for my $default (keys %{$default_params}) {
110 if (exists $param{$default} and
111 not ref($default_params->{$default}) and
112 $default_params->{$default} eq $param{$default}
114 delete $param{$default};
117 for my $incexc (qw(include exclude)) {
118 next unless exists $param{$incexc};
119 # normalize tag to tags
120 $param{$incexc} = [map {s/^tag:/tags:/; $_} grep /\S\:\S/, make_list($param{$incexc})];
122 for my $key (keys %package_search_keys) {
123 next unless exists $param{key};
124 $param{$key} = [map {split /\s*,\s*/} make_list($param{$key})];
126 # kill off keys for which empty values are meaningless
127 for my $key (qw(package src submitter affects severity status dist)) {
128 next unless exists $param{$key};
129 $param{$key} = [grep {defined $_ and length $_}
130 make_list($param{$key})];
132 print $q->redirect(munge_url('pkgreport.cgi?',%param));
136 # normalize innclude/exclude keys; currently this is in two locations,
137 # which is suboptimal. Closes: #567407
138 for my $incexc (qw(include exclude)) {
139 next unless exists $param{$incexc};
140 # normalize tag to tags
141 $param{$incexc} = [map {s/^tag:/tags:/; $_} make_list($param{$incexc})];
146 # map from yes|no to 1|0
147 for my $key (qw(repeatmerged bug-rev pend-rev sev-rev)) {
148 if (exists $param{$key}){
149 if ($param{$key} =~ /^no$/i) {
152 elsif ($param{$key}) {
158 if (lc($param{archive}) eq 'no') {
161 elsif (lc($param{archive}) eq 'yes') {
166 if (exists $param{dist} and $param{dist} eq '') {
170 my $include = $param{'&include'} || $param{'include'} || "";
171 my $exclude = $param{'&exclude'} || $param{'exclude'} || "";
173 my $users = $param{'users'} || "";
175 my $ordering = $param{'ordering'};
176 my $raw_sort = ($param{'raw'} || "no") eq "yes";
177 my $old_view = ($param{'oldview'} || "no") eq "yes";
178 my $age_sort = ($param{'age'} || "no") eq "yes";
179 unless (defined $ordering) {
180 $ordering = "normal";
181 $ordering = "oldview" if $old_view;
182 $ordering = "raw" if $raw_sort;
183 $ordering = 'age' if $age_sort;
185 $param{ordering} = $ordering;
187 our ($bug_order) = $ordering =~ /(age(?:rev)?)/;
188 $bug_order = '' if not defined $bug_order;
190 my $bug_rev = ($param{'bug-rev'} || "no") eq "yes";
191 my $pend_rev = ($param{'pend-rev'} || "no") eq "yes";
192 my $sev_rev = ($param{'sev-rev'} || "no") eq "yes";
194 my @inc_exc_mapping = ({name => 'pending',
212 key => 'includesubj',
216 key => 'excludesubj',
219 for my $incexcmap (@inc_exc_mapping) {
220 push @{$param{$incexcmap->{incexc}}}, map {"$incexcmap->{name}:$_"}
221 map{split /\s*,\s*/} make_list($param{$incexcmap->{key}})
222 if exists $param{$incexcmap->{key}};
223 delete $param{$incexcmap->{key}};
227 my $maxdays = ($param{'maxdays'} || -1);
228 my $mindays = ($param{'mindays'} || 0);
229 my $version = $param{'version'} || undef;
232 our %hidden = map { $_, 1 } qw(status severity classification);
236 "pri" => [map { "pending=$_" }
237 qw(pending forwarded pending-fixed fixed done absent)],
238 "ttl" => ["Outstanding","Forwarded","Pending Upload",
239 "Fixed in NMU","Resolved","From other Branch"],
240 "def" => "Unknown Pending Status",
241 "ord" => [0,1,2,3,4,5,6],
245 "pri" => [map { "severity=$_" } @gSeverityList],
246 "ttl" => [map { $gSeverityDisplay{$_} } @gSeverityList],
247 "def" => "Unknown Severity",
248 "ord" => [0..@gSeverityList],
250 "classification" => [ {
251 "nam" => "Classification",
252 "pri" => [qw(pending=pending+tag=wontfix
253 pending=pending+tag=moreinfo
254 pending=pending+tag=patch
255 pending=pending+tag=confirmed
257 "ttl" => ["Will Not Fix","More information needed",
258 "Patch Available","Confirmed"],
259 "def" => "Unclassified",
260 "ord" => [2,3,4,1,0,5],
262 "oldview" => [ qw(status severity) ],
263 "normal" => [ qw(status severity classification) ],
264 raw => [{nam => 'Raw',def => 'Raw'}],
267 if (exists $param{which} and exists $param{data}) {
268 $param{$param{which}} = [exists $param{$param{which}}?(make_list($param{$param{which}})):(),
269 make_list($param{data}),
271 delete $param{which};
275 if (defined $param{maintenc}) {
276 $param{maint} = maint_decode($param{maintenc});
277 delete $param{maintenc}
280 if (exists $param{pkg}) {
281 $param{package} = $param{pkg};
285 if (not grep {exists $param{$_}} keys %package_search_keys and exists $param{users}) {
286 $param{usertag} = [make_list($param{users})];
293 for my $user (map {split /[\s*,\s*]+/} make_list($param{users}||[])) {
294 next unless length($user);
295 add_user($user,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
298 if (defined $param{usertag}) {
299 for my $usertag (make_list($param{usertag})) {
301 my ($u, $t) = split /:/, $usertag, 2;
302 Debbugs::User::read_usertags(\%select_ut, $u);
303 unless (defined $t && $t ne "") {
304 $t = join(",", keys(%select_ut));
306 add_user($u,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
307 push @{$param{tag}}, split /,/, $t;
311 quitcgi("You have to choose something to select by", '400 Bad Request')
312 unless grep {exists $param{$_}} keys %package_search_keys;
315 my $Archived = $param{archive} ? " Archived" : "";
317 my $this = munge_url('pkgreport.cgi?',
326 # addusers for source and binary packages being searched for
327 my $pkgsrc = getpkgsrc();
328 my $srcpkg = getsrcpkgs();
329 for my $package (# For binary packages, add the binary package
330 # and corresponding source package
331 make_list($param{package}||[]),
332 (map {defined $pkgsrc->{$_}?($pkgsrc->{$_}):()}
333 make_list($param{package}||[]),
335 # For source packages, add the source package
336 # and corresponding binary packages
337 make_list($param{src}||[]),
338 (map {defined $srcpkg->{$_}?($srcpkg->{$_}):()}
339 make_list($param{src}||[]),
342 next unless defined $package;
343 add_user($package.'@'.$config{usertag_package_domain},
344 \%ut,\%bugusertags,\%seen_users,\%cats,\%hidden)
345 if defined $config{usertag_package_domain};
349 # walk through the keys and make the right get_bugs query.
351 my $form_option_variables = {};
352 $form_option_variables->{search_key_order} = [@package_search_key_order];
354 # Set the title sanely and clean up parameters
356 my @temp = @package_search_key_order;
357 while (my ($key,$value) = splice @temp, 0, 2) {
358 next unless exists $param{$key};
360 for my $entry (make_list($param{$key})) {
361 # we'll handle newest below
362 next if $key eq 'newest';
364 if (exists $param{dist} and ($key eq 'package' or $key eq 'src')) {
365 my %versions = get_versions(package => $entry,
366 (exists $param{dist}?(dist => $param{dist}):()),
367 (exists $param{arch}?(arch => $param{arch}):(arch => $config{default_architectures})),
368 ($key eq 'src'?(arch => q(source)):()),
373 if (keys %versions > 1) {
374 $verdesc = 'versions '. join(', ',
375 map { $_ .' ['.join(', ',
376 sort @{$versions{$_}}
381 $verdesc = 'version '.join(', ',
385 $extra= " ($verdesc)" if keys %versions;
387 if ($key eq 'maint' and $entry eq '') {
388 push @entries, "no one (packages without maintainers)"
391 push @entries, $entry.$extra;
394 push @title,$value.' '.join(' or ', @entries) if @entries;
396 if (defined $param{newest}) {
397 my $newest_bug = newest_bug();
398 @bugs = ($newest_bug - $param{newest} + 1) .. $newest_bug;
399 push @title, 'in '.@bugs.' newest reports';
400 $param{bugs} = [exists $param{bugs}?make_list($param{bugs}):(),
405 my $title = $gBugs.' '.join(' and ', map {/ or /?"($_)":$_} @title);
409 @bugs = get_bugs((map {exists $param{$_}?($_,$param{$_}):()}
410 grep {$_ ne 'newest'}
411 keys %package_search_keys, 'archive'),
413 defined $s?(schema => $s):(),
416 # shove in bugs which affect this package if there is a package or a
417 # source given (by default), but no affects options given
418 if (not exists $param{affects} and not exists $param{noaffects} and
419 (exists $param{src} or
420 exists $param{package})) {
421 push @bugs, get_bugs((map {my $key = $_;
422 exists $param{$key}?($key =~ /^(?:package|src)$/?'affects':$key,
423 ($key eq 'src'?[map {"src:$_"}make_list($param{$key})]:$param{$_})):()}
424 grep {$_ ne 'newest'}
425 keys %package_search_keys, 'archive'),
427 defined $s?(schema => $s):(),
431 # filter out included or excluded bugs
434 if (defined $param{version}) {
435 $title .= " at version $param{version}";
437 elsif (defined $param{dist}) {
438 $title .= " in $param{dist}";
441 $title = html_escape($title);
443 my @names; my @prior; my @order;
444 determine_ordering(cats => \%cats,
446 ordering => \$ordering,
453 # strip out duplicate bugs
455 @bugs{@bugs} = @bugs;
458 my $result = pkg_htmlizebugs(bugs => \@bugs,
463 ordering => $ordering,
464 bugusertags => \%bugusertags,
466 bug_order => $bug_order,
467 repeatmerged => $param{repeatmerged},
472 defined $s?(schema => $s):(),
473 (exists $param{dist})?(dist => $param{dist}):(),
476 print "Cache-Control: public, max-age=300\n";
477 print "Content-Type: text/html; charset=utf-8\n\n";
479 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
480 print "<HTML><HEAD>\n" .
481 "<TITLE>$title -- $gProject$Archived $gBug report logs</TITLE>\n" .
482 qq(<link rel="stylesheet" href="$gWebHostBugDir/css/bugs.css" type="text/css">) .
484 '<BODY onload="pagemain();">' .
486 print qq(<DIV id="status_mask"></DIV>\n);
487 print "<H1>" . "$gProject$Archived $gBug report logs: $title" .
492 my $pkg = $param{package} if defined $param{package};
493 my $src = $param{src} if defined $param{src};
495 my $pseudodesc = getpseudodesc();
496 if (defined $pseudodesc and defined $pkg and exists $pseudodesc->{$pkg}) {
500 # output information about the packages
502 for my $package (make_list($param{package}||[])) {
503 print generate_package_info(binary => 1,
509 for my $package (make_list($param{src}||[])) {
510 print generate_package_info(binary => 0,
517 if (exists $param{maint} or exists $param{maintenc}) {
518 print "<p>Note that maintainers may use different Maintainer fields for\n";
519 print "different packages, so there may be other reports filed under\n";
520 print "different addresses.\n";
522 if (exists $param{submitter}) {
523 print "<p>Note that people may use different email accounts for\n";
524 print "different bugs, so there may be other reports filed under\n";
525 print "different addresses.\n";
530 print fill_in_template(template=>'cgi/pkgreport_javascript');
532 print qq(<h2 class="outstanding"><!--<a class="options" href="javascript:toggle(1)">-->Options<!--</a>--></h2>\n);
535 [uniq((grep {!$hidden{$_}} keys %cats),
537 print option_form(template => 'cgi/pkgreport_options',
539 form_options => $form_options,
540 variables => $form_option_variables,
544 print fill_in_template(template=>'html/html_tail',
545 hole_var => {'&strftime' => \&POSIX::strftime,
548 print "</body></html>\n";