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(source_to_binary binary_to_source 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);
69 if (defined $config{database}) {
70 $s = Debbugs::DB->connect($config{database}) or
71 die "Unable to connect to DB";
72 @schema_arg = ('schema',$s);
76 my $q = new CGI::Simple;
78 if ($q->request_method() eq 'HEAD') {
79 print $q->header(-type => "text/html",
85 my $default_params = {ordering => 'normal',
92 our %param = cgi_parameters(query => $q,
93 single => [qw(ordering archive repeatmerged),
94 qw(bug-rev pend-rev sev-rev),
95 qw(maxdays mindays version),
99 default => $default_params,
102 my ($form_options,$param) = ({},undef);
103 ($form_options,$param)= form_options_and_normal_param(\%param)
104 if $param{form_options};
106 %param = %{$param} if defined $param;
108 if (exists $param{form_options} and defined $param{form_options}) {
109 delete $param{form_options};
110 delete $param{submit} if exists $param{submit};
111 for my $default (keys %{$default_params}) {
112 if (exists $param{$default} and
113 not ref($default_params->{$default}) and
114 $default_params->{$default} eq $param{$default}
116 delete $param{$default};
119 for my $incexc (qw(include exclude)) {
120 next unless exists $param{$incexc};
121 # normalize tag to tags
122 $param{$incexc} = [map {s/^tag:/tags:/; $_} grep /\S\:\S/, make_list($param{$incexc})];
124 for my $key (keys %package_search_keys) {
125 next unless exists $param{key};
126 $param{$key} = [map {split /\s*,\s*/} make_list($param{$key})];
128 # kill off keys for which empty values are meaningless
129 for my $key (qw(package src submitter affects severity status dist)) {
130 next unless exists $param{$key};
131 $param{$key} = [grep {defined $_ and length $_}
132 make_list($param{$key})];
134 print $q->redirect(munge_url('pkgreport.cgi?',%param));
138 # normalize innclude/exclude keys; currently this is in two locations,
139 # which is suboptimal. Closes: #567407
140 for my $incexc (qw(include exclude)) {
141 next unless exists $param{$incexc};
142 # normalize tag to tags
143 $param{$incexc} = [map {s/^tag:/tags:/; $_} make_list($param{$incexc})];
148 # map from yes|no to 1|0
149 for my $key (qw(repeatmerged bug-rev pend-rev sev-rev)) {
150 if (exists $param{$key}){
151 if ($param{$key} =~ /^no$/i) {
154 elsif ($param{$key}) {
160 if (lc($param{archive}) eq 'no') {
163 elsif (lc($param{archive}) eq 'yes') {
168 if (exists $param{dist} and $param{dist} eq '') {
172 my $include = $param{'&include'} || $param{'include'} || "";
173 my $exclude = $param{'&exclude'} || $param{'exclude'} || "";
175 my $users = $param{'users'} || "";
177 my $ordering = $param{'ordering'};
178 my $raw_sort = ($param{'raw'} || "no") eq "yes";
179 my $old_view = ($param{'oldview'} || "no") eq "yes";
180 my $age_sort = ($param{'age'} || "no") eq "yes";
181 unless (defined $ordering) {
182 $ordering = "normal";
183 $ordering = "oldview" if $old_view;
184 $ordering = "raw" if $raw_sort;
185 $ordering = 'age' if $age_sort;
187 $param{ordering} = $ordering;
189 our ($bug_order) = $ordering =~ /(age(?:rev)?)/;
190 $bug_order = '' if not defined $bug_order;
192 my $bug_rev = ($param{'bug-rev'} || "no") eq "yes";
193 my $pend_rev = ($param{'pend-rev'} || "no") eq "yes";
194 my $sev_rev = ($param{'sev-rev'} || "no") eq "yes";
196 my @inc_exc_mapping = ({name => 'pending',
214 key => 'includesubj',
218 key => 'excludesubj',
221 for my $incexcmap (@inc_exc_mapping) {
222 push @{$param{$incexcmap->{incexc}}}, map {"$incexcmap->{name}:$_"}
223 map{split /\s*,\s*/} make_list($param{$incexcmap->{key}})
224 if exists $param{$incexcmap->{key}};
225 delete $param{$incexcmap->{key}};
229 my $maxdays = ($param{'maxdays'} || -1);
230 my $mindays = ($param{'mindays'} || 0);
231 my $version = $param{'version'} || undef;
234 our %hidden = map { $_, 1 } qw(status severity classification);
238 "pri" => [map { "pending=$_" }
239 qw(pending forwarded pending-fixed fixed done absent)],
240 "ttl" => ["Outstanding","Forwarded","Pending Upload",
241 "Fixed in NMU","Resolved","From other Branch"],
242 "def" => "Unknown Pending Status",
243 "ord" => [0,1,2,3,4,5,6],
247 "pri" => [map { "severity=$_" } @gSeverityList],
248 "ttl" => [map { $gSeverityDisplay{$_} } @gSeverityList],
249 "def" => "Unknown Severity",
250 "ord" => [0..@gSeverityList],
252 "classification" => [ {
253 "nam" => "Classification",
254 "pri" => [qw(pending=pending+tag=wontfix
255 pending=pending+tag=moreinfo
256 pending=pending+tag=patch
257 pending=pending+tag=confirmed
259 "ttl" => ["Will Not Fix","More information needed",
260 "Patch Available","Confirmed"],
261 "def" => "Unclassified",
262 "ord" => [2,3,4,1,0,5],
264 "oldview" => [ qw(status severity) ],
265 "normal" => [ qw(status severity classification) ],
266 raw => [{nam => 'Raw',def => 'Raw'}],
269 if (exists $param{which} and exists $param{data}) {
270 $param{$param{which}} = [exists $param{$param{which}}?(make_list($param{$param{which}})):(),
271 make_list($param{data}),
273 delete $param{which};
277 if (defined $param{maintenc}) {
278 $param{maint} = maint_decode($param{maintenc});
279 delete $param{maintenc}
282 if (exists $param{pkg}) {
283 $param{package} = $param{pkg};
287 if (not grep {exists $param{$_}} keys %package_search_keys and exists $param{users}) {
288 $param{usertag} = [make_list($param{users})];
295 for my $user (map {split /[\s*,\s*]+/} make_list($param{users}||[])) {
296 next unless length($user);
297 add_user($user,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
300 if (defined $param{usertag}) {
301 for my $usertag (make_list($param{usertag})) {
303 my ($u, $t) = split /:/, $usertag, 2;
304 Debbugs::User::read_usertags(\%select_ut, $u);
305 unless (defined $t && $t ne "") {
306 $t = join(",", keys(%select_ut));
308 add_user($u,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
309 push @{$param{tag}}, split /,/, $t;
313 quitcgi("You have to choose something to select by", '400 Bad Request')
314 unless grep {exists $param{$_}} keys %package_search_keys;
317 my $Archived = $param{archive} ? " Archived" : "";
319 my $this = munge_url('pkgreport.cgi?',
328 # addusers for source and binary packages being searched for
329 if (defined $config{usertag_package_domain}) {
330 my @possible_packages;
331 if (exists $param{package} and
332 defined $param{package}
334 # For binary packages, add the binary package and corresponding source package
335 push @possible_packages,
336 make_list($param{package});
337 push @possible_packages,
338 binary_to_source(source_only => 1,
339 binary=>$param{package},
343 if (exists $param{src} and
346 # For source packages, add the source package and corresponding binary packages
347 push @possible_packages,
348 make_list($param{src});
349 push @possible_packages,
350 source_to_binary(binary_only => 1,
351 source => $param{src},
352 dist => [@{$config{distributions}}],
356 for my $package (@possible_packages) {
357 next unless defined $package and length $package;
358 add_user($package.'@'.$config{usertag_package_domain},
359 \%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
363 # walk through the keys and make the right get_bugs query.
365 my $form_option_variables = {};
366 $form_option_variables->{search_key_order} = [@package_search_key_order];
368 # Set the title sanely and clean up parameters
370 my @temp = @package_search_key_order;
371 while (my ($key,$value) = splice @temp, 0, 2) {
372 next unless exists $param{$key};
374 for my $entry (make_list($param{$key})) {
375 # we'll handle newest below
377 if (exists $param{dist} and ($key eq 'package' or $key eq 'src')) {
378 my %versions = get_versions(package => $entry,
379 (exists $param{dist}?(dist => $param{dist}):()),
380 (exists $param{arch}?(arch => $param{arch}):(arch => $config{default_architectures})),
381 ($key eq 'src'?(arch => q(source)):()),
387 if (keys %versions > 1) {
388 $verdesc = 'versions '. join(', ',
389 map { $_ .' ['.join(', ',
390 sort @{$versions{$_}}
395 $verdesc = 'version '.join(', ',
399 $extra= " ($verdesc)" if keys %versions;
401 if ($key eq 'maint' and $entry eq '') {
402 push @entries, "no one (packages without maintainers)"
405 push @entries, $entry.$extra;
408 if ($key eq 'newest') {
409 push @title, 'in '.join(' or ',@entries).' newest reports';
411 push @title,$value.' '.join(' or ', @entries) if @entries;
415 my $title = $gBugs.' '.join(' and ', map {/ or /?"($_)":$_} @title);
419 @bugs = get_bugs((map {exists $param{$_}?($_,$param{$_}):()}
420 keys %package_search_keys, 'archive'),
425 # shove in bugs which affect this package if there is a package or a
426 # source given (by default), but no affects options given
427 if (not exists $param{affects} and not exists $param{noaffects} and
428 (exists $param{src} or
429 exists $param{package})) {
430 push @bugs, get_bugs((map {my $key = $_;
431 exists $param{$key}?($key =~ /^(?:package|src)$/?'affects':$key,
432 ($key eq 'src'?[map {"src:$_"}make_list($param{$key})]:$param{$_})):()}
433 grep {$_ ne 'newest'}
434 keys %package_search_keys, 'archive'),
440 # filter out included or excluded bugs
443 if (defined $param{version}) {
444 $title .= " at version $param{version}";
446 elsif (defined $param{dist}) {
447 $title .= " in $param{dist}";
450 $title = html_escape($title);
452 my @names; my @prior; my @order;
453 determine_ordering(cats => \%cats,
455 ordering => \$ordering,
462 # strip out duplicate bugs
464 @bugs{@bugs} = @bugs;
467 my $result = pkg_htmlizebugs(bugs => \@bugs,
472 ordering => $ordering,
473 bugusertags => \%bugusertags,
475 bug_order => $bug_order,
476 repeatmerged => $param{repeatmerged},
482 (exists $param{dist})?(dist => $param{dist}):(),
485 print "Cache-Control: public, max-age=300\n";
486 print "Content-Type: text/html; charset=utf-8\n\n";
488 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
489 print "<HTML><HEAD>\n" .
490 "<TITLE>$title -- $gProject$Archived $gBug report logs</TITLE>\n" .
491 qq(<link rel="stylesheet" href="$gWebHostBugDir/css/bugs.css" type="text/css">) .
493 '<BODY onload="pagemain();">' .
495 print qq(<DIV id="status_mask"></DIV>\n);
496 print "<H1>" . "$gProject$Archived $gBug report logs: $title" .
501 my $pkg = $param{package} if defined $param{package};
502 my $src = $param{src} if defined $param{src};
504 my $pseudodesc = getpseudodesc();
505 if (defined $pseudodesc and defined $pkg and exists $pseudodesc->{$pkg}) {
509 # output information about the packages
511 for my $package (make_list($param{package}||[])) {
512 print generate_package_info(binary => 1,
519 for my $package (make_list($param{src}||[])) {
520 print generate_package_info(binary => 0,
528 if (exists $param{maint} or exists $param{maintenc}) {
529 print "<p>Note that maintainers may use different Maintainer fields for\n";
530 print "different packages, so there may be other reports filed under\n";
531 print "different addresses.\n";
533 if (exists $param{submitter}) {
534 print "<p>Note that people may use different email accounts for\n";
535 print "different bugs, so there may be other reports filed under\n";
536 print "different addresses.\n";
541 print fill_in_template(template=>'cgi/pkgreport_javascript');
543 print qq(<h2 class="outstanding"><!--<a class="options" href="javascript:toggle(1)">-->Options<!--</a>--></h2>\n);
546 [uniq((grep {!$hidden{$_}} keys %cats),
548 print option_form(template => 'cgi/pkgreport_options',
550 form_options => $form_options,
551 variables => $form_option_variables,
555 print fill_in_template(template=>'html/html_tail',
556 hole_var => {'&strftime' => \&POSIX::strftime,
559 print "</body></html>\n";