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] !~ /^\//) {
43 use if defined $debbugs_dir, lib => $debbugs_dir;
45 binmode(STDOUT,':encoding(UTF-8)');
46 use POSIX qw(strftime nice);
47 use List::AllUtils qw(uniq);
49 use Debbugs::Config qw(:globals :text :config);
53 use Debbugs::Common qw(getparsedaddrs make_list getmaintainers getpseudodesc);
55 use Debbugs::Bugs qw(get_bugs bug_filter newest_bug);
56 use Debbugs::Packages qw(source_to_binary binary_to_source get_versions);
57 use Debbugs::Collection::Bug;
59 use Debbugs::Status qw(splitpackages);
61 use Debbugs::CGI qw(:all);
63 use Debbugs::CGI::Pkgreport qw(:all);
65 use Debbugs::Text qw(:templates);
71 if (defined $config{database}) {
72 $s = Debbugs::DB->connect($config{database}) or
73 die "Unable to connect to DB";
74 @schema_arg = ('schema',$s);
78 my $q = new CGI::Simple;
80 if ($q->request_method() eq 'HEAD') {
81 print $q->header(-type => "text/html",
87 my $default_params = {ordering => 'normal',
94 our %param = cgi_parameters(query => $q,
95 single => [qw(ordering archive repeatmerged),
96 qw(bug-rev pend-rev sev-rev),
97 qw(maxdays mindays version),
101 default => $default_params,
104 my ($form_options,$param) = ({},undef);
105 ($form_options,$param)= form_options_and_normal_param(\%param)
106 if $param{form_options};
108 %param = %{$param} if defined $param;
110 if (exists $param{form_options} and defined $param{form_options}) {
111 delete $param{form_options};
112 delete $param{submit} if exists $param{submit};
113 for my $default (keys %{$default_params}) {
114 if (exists $param{$default} and
115 not ref($default_params->{$default}) and
116 $default_params->{$default} eq $param{$default}
118 delete $param{$default};
121 for my $incexc (qw(include exclude)) {
122 next unless exists $param{$incexc};
123 # normalize tag to tags
124 $param{$incexc} = [map {s/^tag:/tags:/; $_} grep /\S\:\S/, make_list($param{$incexc})];
126 for my $key (keys %package_search_keys) {
127 next unless exists $param{key};
128 $param{$key} = [map {split /\s*,\s*/} make_list($param{$key})];
130 # kill off keys for which empty values are meaningless
131 for my $key (qw(package src submitter affects severity status dist)) {
132 next unless exists $param{$key};
133 $param{$key} = [grep {defined $_ and length $_}
134 make_list($param{$key})];
136 print $q->redirect(munge_url('pkgreport.cgi?',%param));
140 # normalize innclude/exclude keys; currently this is in two locations,
141 # which is suboptimal. Closes: #567407
142 for my $incexc (qw(include exclude)) {
143 next unless exists $param{$incexc};
144 # normalize tag to tags
145 $param{$incexc} = [map {s/^tag:/tags:/; $_} make_list($param{$incexc})];
150 # map from yes|no to 1|0
151 for my $key (qw(repeatmerged bug-rev pend-rev sev-rev)) {
152 if (exists $param{$key}){
153 if ($param{$key} =~ /^no$/i) {
156 elsif ($param{$key}) {
162 if (lc($param{archive}) eq 'no') {
165 elsif (lc($param{archive}) eq 'yes') {
170 if (exists $param{dist} and $param{dist} eq '') {
174 my $include = $param{'&include'} || $param{'include'} || "";
175 my $exclude = $param{'&exclude'} || $param{'exclude'} || "";
177 my $users = $param{'users'} || "";
179 my $ordering = $param{'ordering'};
180 my $raw_sort = ($param{'raw'} || "no") eq "yes";
181 my $old_view = ($param{'oldview'} || "no") eq "yes";
182 my $age_sort = ($param{'age'} || "no") eq "yes";
183 unless (defined $ordering) {
184 $ordering = "normal";
185 $ordering = "oldview" if $old_view;
186 $ordering = "raw" if $raw_sort;
187 $ordering = 'age' if $age_sort;
189 $param{ordering} = $ordering;
191 our ($bug_order) = $ordering =~ /(age(?:rev)?)/;
192 $bug_order = '' if not defined $bug_order;
194 my $bug_rev = ($param{'bug-rev'} || "no") eq "yes";
195 my $pend_rev = ($param{'pend-rev'} || "no") eq "yes";
196 my $sev_rev = ($param{'sev-rev'} || "no") eq "yes";
198 my @inc_exc_mapping = ({name => 'pending',
216 key => 'includesubj',
220 key => 'excludesubj',
223 for my $incexcmap (@inc_exc_mapping) {
224 push @{$param{$incexcmap->{incexc}}}, map {"$incexcmap->{name}:$_"}
225 map{split /\s*,\s*/} make_list($param{$incexcmap->{key}})
226 if exists $param{$incexcmap->{key}};
227 delete $param{$incexcmap->{key}};
231 my $maxdays = ($param{'maxdays'} || -1);
232 my $mindays = ($param{'mindays'} || 0);
233 my $version = $param{'version'} || undef;
236 our %hidden = map { $_, 1 } qw(status severity classification);
240 "pri" => [map { "pending=$_" }
241 qw(pending forwarded pending-fixed fixed done absent)],
242 "ttl" => ["Outstanding","Forwarded","Pending Upload",
243 "Fixed in NMU","Resolved","From other Branch"],
244 "def" => "Unknown Pending Status",
245 "ord" => [0,1,2,3,4,5,6],
249 "pri" => [map { "severity=$_" } @gSeverityList],
250 "ttl" => [map { $gSeverityDisplay{$_} } @gSeverityList],
251 "def" => "Unknown Severity",
252 "ord" => [0..@gSeverityList],
254 "classification" => [ {
255 "nam" => "Classification",
256 "pri" => [qw(pending=pending+tag=wontfix
257 pending=pending+tag=moreinfo
258 pending=pending+tag=patch
259 pending=pending+tag=confirmed
261 "ttl" => ["Will Not Fix","More information needed",
262 "Patch Available","Confirmed"],
263 "def" => "Unclassified",
264 "ord" => [2,3,4,1,0,5],
266 "oldview" => [ qw(status severity) ],
267 "normal" => [ qw(status severity classification) ],
268 raw => [{nam => 'Raw',def => 'Raw'}],
271 if (exists $param{which} and exists $param{data}) {
272 $param{$param{which}} = [exists $param{$param{which}}?(make_list($param{$param{which}})):(),
273 make_list($param{data}),
275 delete $param{which};
279 if (defined $param{maintenc}) {
280 $param{maint} = maint_decode($param{maintenc});
281 delete $param{maintenc}
284 if (exists $param{pkg}) {
285 $param{package} = $param{pkg};
289 if (not grep {exists $param{$_}} keys %package_search_keys and exists $param{users}) {
290 $param{usertag} = [make_list($param{users})];
298 for my $user (map {split /[\s*,\s*]+/} make_list($param{users}||[])) {
299 next unless length($user);
301 add_user($user,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
304 if (defined $param{usertag}) {
305 for my $usertag (make_list($param{usertag})) {
307 my ($u, $t) = split /:/, $usertag, 2;
308 Debbugs::User::read_usertags(\%select_ut, $u);
309 unless (defined $t && $t ne "") {
310 $t = join(",", keys(%select_ut));
313 add_user($u,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
314 push @{$param{tag}}, split /,/, $t;
318 quitcgi("You have to choose something to select by", '400 Bad Request')
319 unless grep {exists $param{$_}} keys %package_search_keys;
322 my $Archived = $param{archive} ? " Archived" : "";
324 my $this = munge_url('pkgreport.cgi?',
333 # addusers for source and binary packages being searched for
334 if (defined $config{usertag_package_domain}) {
335 my @possible_packages;
336 if (exists $param{package} and
337 defined $param{package}
339 # For binary packages, add the binary package and corresponding source package
340 push @possible_packages,
341 make_list($param{package});
342 push @possible_packages,
343 binary_to_source(source_only => 1,
344 binary=>$param{package},
348 if (exists $param{src} and
351 # For source packages, add the source package and corresponding binary packages
352 push @possible_packages,
353 make_list($param{src});
354 push @possible_packages,
355 source_to_binary(binary_only => 1,
356 source => $param{src},
357 dist => [@{$config{distributions}}],
361 for my $package (@possible_packages) {
362 next unless defined $package and length $package;
364 $package.'@'.$config{usertag_package_domain};
365 add_user($package.'@'.$config{usertag_package_domain},
366 \%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
370 # walk through the keys and make the right get_bugs query.
372 my $form_option_variables = {};
373 $form_option_variables->{search_key_order} = [@package_search_key_order];
375 # Set the title sanely and clean up parameters
377 my @temp = @package_search_key_order;
378 while (my ($key,$value) = splice @temp, 0, 2) {
379 next unless exists $param{$key};
381 for my $entry (make_list($param{$key})) {
382 # we'll handle newest below
384 if (exists $param{dist} and ($key eq 'package' or $key eq 'src')) {
385 my %versions = get_versions(package => $entry,
386 (exists $param{dist}?(dist => $param{dist}):()),
387 (exists $param{arch}?(arch => $param{arch}):(arch => $config{default_architectures})),
388 ($key eq 'src'?(arch => q(source)):()),
394 if (keys %versions > 1) {
395 $verdesc = 'versions '. join(', ',
396 map { $_ .' ['.join(', ',
397 sort @{$versions{$_}}
402 $verdesc = 'version '.join(', ',
406 $extra= " ($verdesc)" if keys %versions;
408 if ($key eq 'maint' and $entry eq '') {
409 push @entries, "no one (packages without maintainers)"
412 push @entries, $entry.$extra;
415 if ($key eq 'newest') {
416 push @title, 'in '.join(' or ',@entries).' newest reports';
418 push @title,$value.' '.join(' or ', @entries) if @entries;
422 my $title = $gBugs.' '.join(' and ', map {/ or /?"($_)":$_} @title);
426 @bugs = get_bugs((map {exists $param{$_}?($_,$param{$_}):()}
427 keys %package_search_keys, 'archive'),
432 # shove in bugs which affect this package if there is a package or a
433 # source given (by default), but no affects options given
434 if (not exists $param{affects} and not exists $param{noaffects} and
435 (exists $param{src} or
436 exists $param{package})) {
437 push @bugs, get_bugs((map {my $key = $_;
438 exists $param{$key}?($key =~ /^(?:package|src)$/?'affects':$key,
439 ($key eq 'src'?[map {"src:$_"}make_list($param{$key})]:$param{$_})):()}
440 grep {$_ ne 'newest'}
441 keys %package_search_keys, 'archive'),
447 # filter out included or excluded bugs
450 if (defined $param{version}) {
451 $title .= " at version $param{version}";
453 elsif (defined $param{dist}) {
454 $title .= " in $param{dist}";
457 $title = html_escape($title);
459 my @names; my @prior; my @order;
460 determine_ordering(cats => \%cats,
462 ordering => \$ordering,
469 # strip out duplicate bugs
471 @bugs{@bugs} = @bugs;
474 my $bugs = Debbugs::Collection::Bug->
477 users => [map {my $u = Debbugs::User->new($_);
478 $u->has_bug_tags()?($u):()
482 $bugs->load_related_packages_and_versions();
484 my $result = pkg_htmlizebugs(bugs => $bugs,
489 ordering => $ordering,
490 bugusertags => \%bugusertags,
492 bug_order => $bug_order,
493 repeatmerged => $param{repeatmerged},
499 (exists $param{dist})?(dist => $param{dist}):(),
502 print "Cache-Control: public, max-age=300\n";
503 print "Content-Type: text/html; charset=utf-8\n\n";
505 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
506 print "<HTML><HEAD>\n" .
507 "<TITLE>$title -- $gProject$Archived $gBug report logs</TITLE>\n" .
508 qq(<link rel="stylesheet" href="$gWebHostBugDir/css/bugs.css" type="text/css">) .
510 '<BODY onload="pagemain();">' .
512 print qq(<DIV id="status_mask"></DIV>\n);
513 print "<H1>" . "$gProject$Archived $gBug report logs: $title" .
518 my $pkg = $param{package} if defined $param{package};
519 my $src = $param{src} if defined $param{src};
521 my $pseudodesc = getpseudodesc();
522 if (defined $pseudodesc and defined $pkg and exists $pseudodesc->{$pkg}) {
526 # output information about the packages
528 for my $package (make_list($param{package}||[])) {
529 print generate_package_info(binary => 1,
536 for my $package (make_list($param{src}||[])) {
537 print generate_package_info(binary => 0,
545 if (exists $param{maint} or exists $param{maintenc}) {
546 print "<p>Note that maintainers may use different Maintainer fields for\n";
547 print "different packages, so there may be other reports filed under\n";
548 print "different addresses.\n";
550 if (exists $param{submitter}) {
551 print "<p>Note that people may use different email accounts for\n";
552 print "different bugs, so there may be other reports filed under\n";
553 print "different addresses.\n";
558 print fill_in_template(template=>'cgi/pkgreport_javascript');
560 print qq(<h2 class="outstanding"><!--<a class="options" href="javascript:toggle(1)">-->Options<!--</a>--></h2>\n);
563 [uniq((grep {!$hidden{$_}} keys %cats),
565 print option_form(template => 'cgi/pkgreport_options',
567 form_options => $form_options,
568 variables => $form_option_variables,
572 print fill_in_template(template=>'html/html_tail',
573 hole_var => {'&strftime' => \&POSIX::strftime,
576 print "</body></html>\n";