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 if (defined $debbugs_dir) {
43 unshift @INC, $debbugs_dir.'/lib/';
48 binmode(STDOUT,':encoding(UTF-8)');
49 use POSIX qw(strftime nice);
50 use List::AllUtils qw(uniq);
52 use Debbugs::Config qw(:globals :text :config);
56 use Debbugs::Common qw(getparsedaddrs make_list getmaintainers getpseudodesc);
58 use Debbugs::Bugs qw(get_bugs bug_filter newest_bug);
59 use Debbugs::Packages qw(source_to_binary binary_to_source get_versions);
60 use Debbugs::Collection::Bug;
62 use Debbugs::Status qw(splitpackages);
64 use Debbugs::CGI qw(:all);
66 use Debbugs::CGI::Pkgreport qw(:all);
68 use Debbugs::Text qw(:templates);
74 if (defined $config{database}) {
75 $s = Debbugs::DB->connect($config{database}) or
76 die "Unable to connect to DB";
77 @schema_arg = ('schema',$s);
81 my $q = new CGI::Simple;
83 if ($q->request_method() eq 'HEAD') {
84 print $q->header(-type => "text/html",
90 my $default_params = {ordering => 'normal',
97 our %param = cgi_parameters(query => $q,
98 single => [qw(ordering archive repeatmerged),
99 qw(bug-rev pend-rev sev-rev),
100 qw(maxdays mindays version),
104 default => $default_params,
107 my ($form_options,$param) = ({},undef);
108 ($form_options,$param)= form_options_and_normal_param(\%param)
109 if $param{form_options};
111 %param = %{$param} if defined $param;
113 if (exists $param{form_options} and defined $param{form_options}) {
114 delete $param{form_options};
115 delete $param{submit} if exists $param{submit};
116 for my $default (keys %{$default_params}) {
117 if (exists $param{$default} and
118 not ref($default_params->{$default}) and
119 $default_params->{$default} eq $param{$default}
121 delete $param{$default};
124 for my $incexc (qw(include exclude)) {
125 next unless exists $param{$incexc};
126 # normalize tag to tags
127 $param{$incexc} = [map {s/^tag:/tags:/; $_} grep /\S\:\S/, make_list($param{$incexc})];
129 for my $key (keys %package_search_keys) {
130 next unless exists $param{key};
131 $param{$key} = [map {split /\s*,\s*/} make_list($param{$key})];
133 # kill off keys for which empty values are meaningless
134 for my $key (qw(package src submitter affects severity status dist)) {
135 next unless exists $param{$key};
136 $param{$key} = [grep {defined $_ and length $_}
137 make_list($param{$key})];
139 print $q->redirect(munge_url('pkgreport.cgi?',%param));
143 # normalize innclude/exclude keys; currently this is in two locations,
144 # which is suboptimal. Closes: #567407
145 for my $incexc (qw(include exclude)) {
146 next unless exists $param{$incexc};
147 # normalize tag to tags
148 $param{$incexc} = [map {s/^tag:/tags:/; $_} make_list($param{$incexc})];
153 # map from yes|no to 1|0
154 for my $key (qw(repeatmerged bug-rev pend-rev sev-rev)) {
155 if (exists $param{$key}){
156 if ($param{$key} =~ /^no$/i) {
159 elsif ($param{$key}) {
165 if (lc($param{archive}) eq 'no') {
168 elsif (lc($param{archive}) eq 'yes') {
173 if (exists $param{dist} and $param{dist} eq '') {
177 my $include = $param{'&include'} || $param{'include'} || "";
178 my $exclude = $param{'&exclude'} || $param{'exclude'} || "";
180 my $users = $param{'users'} || "";
182 my $ordering = $param{'ordering'};
183 my $raw_sort = ($param{'raw'} || "no") eq "yes";
184 my $old_view = ($param{'oldview'} || "no") eq "yes";
185 my $age_sort = ($param{'age'} || "no") eq "yes";
186 unless (defined $ordering) {
187 $ordering = "normal";
188 $ordering = "oldview" if $old_view;
189 $ordering = "raw" if $raw_sort;
190 $ordering = 'age' if $age_sort;
192 $param{ordering} = $ordering;
194 our ($bug_order) = $ordering =~ /(age(?:rev)?)/;
195 $bug_order = '' if not defined $bug_order;
197 my $bug_rev = ($param{'bug-rev'} || "no") eq "yes";
198 my $pend_rev = ($param{'pend-rev'} || "no") eq "yes";
199 my $sev_rev = ($param{'sev-rev'} || "no") eq "yes";
201 my @inc_exc_mapping = ({name => 'pending',
219 key => 'includesubj',
223 key => 'excludesubj',
226 for my $incexcmap (@inc_exc_mapping) {
227 push @{$param{$incexcmap->{incexc}}}, map {"$incexcmap->{name}:$_"}
228 map{split /\s*,\s*/} make_list($param{$incexcmap->{key}})
229 if exists $param{$incexcmap->{key}};
230 delete $param{$incexcmap->{key}};
234 my $maxdays = ($param{'maxdays'} || -1);
235 my $mindays = ($param{'mindays'} || 0);
236 my $version = $param{'version'} || undef;
239 our %hidden = map { $_, 1 } qw(status severity classification);
243 "pri" => [map { "pending=$_" }
244 qw(pending forwarded pending-fixed fixed done absent)],
245 "ttl" => ["Outstanding","Forwarded","Pending Upload",
246 "Fixed in NMU","Resolved","From other Branch"],
247 "def" => "Unknown Pending Status",
248 "ord" => [0,1,2,3,4,5,6],
252 "pri" => [map { "severity=$_" } @gSeverityList],
253 "ttl" => [map { $gSeverityDisplay{$_} } @gSeverityList],
254 "def" => "Unknown Severity",
255 "ord" => [0..@gSeverityList],
257 "classification" => [ {
258 "nam" => "Classification",
259 "pri" => [qw(pending=pending+tag=wontfix
260 pending=pending+tag=moreinfo
261 pending=pending+tag=patch
262 pending=pending+tag=confirmed
264 "ttl" => ["Will Not Fix","More information needed",
265 "Patch Available","Confirmed"],
266 "def" => "Unclassified",
267 "ord" => [2,3,4,1,0,5],
269 "oldview" => [ qw(status severity) ],
270 "normal" => [ qw(status severity classification) ],
271 raw => [{nam => 'Raw',def => 'Raw'}],
274 if (exists $param{which} and exists $param{data}) {
275 $param{$param{which}} = [exists $param{$param{which}}?(make_list($param{$param{which}})):(),
276 make_list($param{data}),
278 delete $param{which};
282 if (defined $param{maintenc}) {
283 $param{maint} = maint_decode($param{maintenc});
284 delete $param{maintenc}
287 if (exists $param{pkg}) {
288 $param{package} = $param{pkg};
292 if (not grep {exists $param{$_}} keys %package_search_keys and exists $param{users}) {
293 $param{usertag} = [make_list($param{users})];
301 for my $user (map {split /[\s*,\s*]+/} make_list($param{users}||[])) {
302 next unless length($user);
304 add_user($user,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
307 if (defined $param{usertag}) {
308 for my $usertag (make_list($param{usertag})) {
310 my ($u, $t) = split /:/, $usertag, 2;
311 Debbugs::User::read_usertags(\%select_ut, $u);
312 unless (defined $t && $t ne "") {
313 $t = join(",", keys(%select_ut));
316 add_user($u,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
317 push @{$param{tag}}, split /,/, $t;
321 quitcgi("You have to choose something to select by", '400 Bad Request')
322 unless grep {exists $param{$_}} keys %package_search_keys;
325 my $Archived = $param{archive} ? " Archived" : "";
327 my $this = munge_url('pkgreport.cgi?',
336 # addusers for source and binary packages being searched for
337 if (defined $config{usertag_package_domain}) {
338 my @possible_packages;
339 if (exists $param{package} and
340 defined $param{package}
342 # For binary packages, add the binary package and corresponding source package
343 push @possible_packages,
344 make_list($param{package});
345 push @possible_packages,
346 binary_to_source(source_only => 1,
347 binary=>$param{package},
351 if (exists $param{src} and
354 # For source packages, add the source package and corresponding binary packages
355 push @possible_packages,
356 make_list($param{src});
357 push @possible_packages,
358 source_to_binary(binary_only => 1,
359 source => $param{src},
360 dist => [@{$config{distributions}}],
364 for my $package (@possible_packages) {
365 next unless defined $package and length $package;
367 $package.'@'.$config{usertag_package_domain};
368 add_user($package.'@'.$config{usertag_package_domain},
369 \%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
373 # walk through the keys and make the right get_bugs query.
375 my $form_option_variables = {};
376 $form_option_variables->{search_key_order} = [@package_search_key_order];
378 # Set the title sanely and clean up parameters
380 my @temp = @package_search_key_order;
381 while (my ($key,$value) = splice @temp, 0, 2) {
382 next unless exists $param{$key};
384 for my $entry (make_list($param{$key})) {
385 # we'll handle newest below
387 if (exists $param{dist} and ($key eq 'package' or $key eq 'src')) {
388 my %versions = get_versions(package => $entry,
389 (exists $param{dist}?(dist => $param{dist}):()),
390 (exists $param{arch}?(arch => $param{arch}):(arch => $config{default_architectures})),
391 ($key eq 'src'?(arch => q(source)):()),
397 if (keys %versions > 1) {
398 $verdesc = 'versions '. join(', ',
399 map { $_ .' ['.join(', ',
400 sort @{$versions{$_}}
405 $verdesc = 'version '.join(', ',
409 $extra= " ($verdesc)" if keys %versions;
411 if ($key eq 'maint' and $entry eq '') {
412 push @entries, "no one (packages without maintainers)"
415 push @entries, $entry.$extra;
418 if ($key eq 'newest') {
419 push @title, 'in '.join(' or ',@entries).' newest reports';
421 push @title,$value.' '.join(' or ', @entries) if @entries;
425 my $title = $gBugs.' '.join(' and ', map {/ or /?"($_)":$_} @title);
429 @bugs = get_bugs((map {exists $param{$_}?($_,$param{$_}):()}
430 keys %package_search_keys, 'archive'),
435 # shove in bugs which affect this package if there is a package or a
436 # source given (by default), but no affects options given
437 if (not exists $param{affects} and not exists $param{noaffects} and
438 (exists $param{src} or
439 exists $param{package})) {
440 push @bugs, get_bugs((map {my $key = $_;
441 exists $param{$key}?($key =~ /^(?:package|src)$/?'affects':$key,
442 ($key eq 'src'?[map {"src:$_"}make_list($param{$key})]:$param{$_})):()}
443 grep {$_ ne 'newest'}
444 keys %package_search_keys, 'archive'),
450 # filter out included or excluded bugs
453 if (defined $param{version}) {
454 $title .= " at version $param{version}";
456 elsif (defined $param{dist}) {
457 $title .= " in $param{dist}";
460 $title = html_escape($title);
462 my @names; my @prior; my @order;
463 determine_ordering(cats => \%cats,
465 ordering => \$ordering,
472 # strip out duplicate bugs
474 @bugs{@bugs} = @bugs;
477 my $bugs = Debbugs::Collection::Bug->
480 users => [map {my $u = Debbugs::User->new($_);
481 $u->has_bug_tags()?($u):()
485 $bugs->load_related_packages_and_versions();
487 my $result = pkg_htmlizebugs(bugs => $bugs,
492 ordering => $ordering,
493 bugusertags => \%bugusertags,
495 bug_order => $bug_order,
496 repeatmerged => $param{repeatmerged},
502 (exists $param{dist})?(dist => $param{dist}):(),
505 print "Cache-Control: public, max-age=300\n";
506 print "Content-Type: text/html; charset=utf-8\n\n";
508 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
509 print "<HTML><HEAD>\n" .
510 "<TITLE>$title -- $gProject$Archived $gBug report logs</TITLE>\n" .
511 qq(<link rel="stylesheet" href="$gWebHostBugDir/css/bugs.css" type="text/css">) .
513 '<BODY onload="pagemain();">' .
515 print qq(<DIV id="status_mask"></DIV>\n);
516 print "<H1>" . "$gProject$Archived $gBug report logs: $title" .
521 my $pkg = $param{package} if defined $param{package};
522 my $src = $param{src} if defined $param{src};
524 my $pseudodesc = getpseudodesc();
525 if (defined $pseudodesc and defined $pkg and exists $pseudodesc->{$pkg}) {
529 # output information about the packages
531 for my $package (make_list($param{package}||[])) {
532 print generate_package_info(binary => 1,
539 for my $package (make_list($param{src}||[])) {
540 print generate_package_info(binary => 0,
548 if (exists $param{maint} or exists $param{maintenc}) {
549 print "<p>Note that maintainers may use different Maintainer fields for\n";
550 print "different packages, so there may be other reports filed under\n";
551 print "different addresses.\n";
553 if (exists $param{submitter}) {
554 print "<p>Note that people may use different email accounts for\n";
555 print "different bugs, so there may be other reports filed under\n";
556 print "different addresses.\n";
561 print fill_in_template(template=>'cgi/pkgreport_javascript');
563 print qq(<h2 class="outstanding"><!--<a class="options" href="javascript:toggle(1)">-->Options<!--</a>--></h2>\n);
566 [uniq((grep {!$hidden{$_}} keys %cats),
568 print option_form(template => 'cgi/pkgreport_options',
570 form_options => $form_options,
571 variables => $form_option_variables,
575 print fill_in_template(template=>'html/html_tail',
576 hole_var => {'&strftime' => \&POSIX::strftime,
579 print "</body></html>\n";