]> git.donarmstrong.com Git - debbugs.git/blob - cgi/pkgreport.cgi
newest is now handled by Debbugs::Bugs, so pass it there
[debbugs.git] / cgi / pkgreport.cgi
1 #!/usr/bin/perl -wT
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.
6 #
7 # [Other people have contributed to this file; their copyrights should
8 # go here too.]
9 # Copyright 2004-2006 by Anthony Towns <ajt@debian.org>
10 # Copyright 2007 by Don Armstrong <don@donarmstrong.com>.
11
12
13 use warnings;
14 use strict;
15
16 # Sanitize environent for taint
17 BEGIN{
18     delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
19 }
20
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);
24 use Cwd qw(abs_path);
25 our $debbugs_dir;
26 BEGIN {
27     $debbugs_dir =
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/') {
34     } else {
35         undef $debbugs_dir;
36     }
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] !~ /^\//) {
40     }
41 }
42 use if defined $debbugs_dir, lib => $debbugs_dir;
43
44 binmode(STDOUT,':encoding(UTF-8)');
45 use POSIX qw(strftime nice);
46 use List::AllUtils qw(uniq);
47
48 use Debbugs::Config qw(:globals :text :config);
49
50 use Debbugs::User;
51
52 use Debbugs::Common qw(getparsedaddrs make_list getmaintainers getpseudodesc);
53
54 use Debbugs::Bugs qw(get_bugs bug_filter newest_bug);
55 use Debbugs::Packages qw(source_to_binary binary_to_source get_versions);
56
57 use Debbugs::Status qw(splitpackages);
58
59 use Debbugs::CGI qw(:all);
60
61 use Debbugs::CGI::Pkgreport qw(:all);
62
63 use Debbugs::Text qw(:templates);
64
65 use Debbugs::DB;
66
67 my $s;
68 my @schema_arg = ();
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);
73 }
74
75 use CGI::Simple;
76 my $q = new CGI::Simple;
77
78 if ($q->request_method() eq 'HEAD') {
79      print $q->header(-type => "text/html",
80                       -charset => 'utf-8',
81                      );
82      exit 0;
83 }
84
85 my $default_params = {ordering => 'normal',
86                       archive  => 0,
87                       repeatmerged => 0,
88                       include      => [],
89                       exclude      => [],
90                      };
91
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),
96                                        qw(data which dist),
97                                        qw(noaffects),
98                                       ],
99                             default => $default_params,
100                            );
101
102 my ($form_options,$param) = ({},undef);
103 ($form_options,$param)= form_options_and_normal_param(\%param)
104      if $param{form_options};
105
106 %param = %{$param} if defined $param;
107
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}
115              ) {
116                delete $param{$default};
117           }
118      }
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})];
123      }
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})];
127      }
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})];
133      }
134      print $q->redirect(munge_url('pkgreport.cgi?',%param));
135      exit 0;
136 }
137
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})];
144 }
145
146
147
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) {
152                $param{$key} = 0;
153           }
154           elsif ($param{$key}) {
155                $param{$key} = 1;
156           }
157      }
158 }
159
160 if (lc($param{archive}) eq 'no') {
161      $param{archive} = 0;
162 }
163 elsif (lc($param{archive}) eq 'yes') {
164      $param{archive} = 1;
165 }
166
167 # fixup dist
168 if (exists $param{dist} and $param{dist} eq '') {
169      delete $param{dist};
170 }
171
172 my $include = $param{'&include'} || $param{'include'} || "";
173 my $exclude = $param{'&exclude'} || $param{'exclude'} || "";
174
175 my $users = $param{'users'} || "";
176
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;
186 }
187 $param{ordering} = $ordering;
188
189 our ($bug_order) = $ordering =~ /(age(?:rev)?)/;
190 $bug_order = '' if not defined $bug_order;
191
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";
195
196 my @inc_exc_mapping = ({name   => 'pending',
197                         incexc => 'include',
198                         key    => 'pend-inc',
199                        },
200                        {name   => 'pending',
201                         incexc => 'exclude',
202                         key    => 'pend-exc',
203                        },
204                        {name   => 'severity',
205                         incexc => 'include',
206                         key    => 'sev-inc',
207                        },
208                        {name   => 'severity',
209                         incexc => 'exclude',
210                         key    => 'sev-exc',
211                        },
212                        {name   => 'subject',
213                         incexc => 'include',
214                         key    => 'includesubj',
215                        },
216                        {name   => 'subject',
217                         incexc => 'exclude',
218                         key    => 'excludesubj',
219                        },
220                       );
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}};
226 }
227
228
229 my $maxdays = ($param{'maxdays'} || -1);
230 my $mindays = ($param{'mindays'} || 0);
231 my $version = $param{'version'} || undef;
232
233
234 our %hidden = map { $_, 1 } qw(status severity classification);
235 our %cats = (
236     "status" => [ {
237         "nam" => "Status",
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],
244     } ],
245     "severity" => [ {
246         "nam" => "Severity",
247         "pri" => [map { "severity=$_" } @gSeverityList],
248         "ttl" => [map { $gSeverityDisplay{$_} } @gSeverityList],
249         "def" => "Unknown Severity",
250         "ord" => [0..@gSeverityList],
251     } ],
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
258                      pending=pending)],
259         "ttl" => ["Will Not Fix","More information needed",
260                   "Patch Available","Confirmed"],
261         "def" => "Unclassified",
262         "ord" => [2,3,4,1,0,5],
263     } ],
264     "oldview" => [ qw(status severity) ],
265              "normal" => [ qw(status severity classification) ],
266              raw => [{nam => 'Raw',def => 'Raw'}],
267 );
268
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}),
272                              ];
273      delete $param{which};
274      delete $param{data};
275 }
276
277 if (defined $param{maintenc}) {
278      $param{maint} = maint_decode($param{maintenc});
279      delete $param{maintenc}
280 }
281
282 if (exists $param{pkg}) {
283      $param{package} = $param{pkg};
284      delete $param{pkg};
285 }
286
287 if (not grep {exists $param{$_}} keys %package_search_keys and exists $param{users}) {
288      $param{usertag} = [make_list($param{users})];
289 }
290
291 my %bugusertags;
292 my %ut;
293 my %seen_users;
294
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);
298 }
299
300 if (defined $param{usertag}) {
301      for my $usertag (make_list($param{usertag})) {
302           my %select_ut = ();
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));
307           }
308           add_user($u,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
309           push @{$param{tag}}, split /,/, $t;
310      }
311 }
312
313 quitcgi("You have to choose something to select by", '400 Bad Request')
314   unless grep {exists $param{$_}} keys %package_search_keys;
315
316
317 my $Archived = $param{archive} ? " Archived" : "";
318
319 my $this = munge_url('pkgreport.cgi?',
320                       %param,
321                      );
322
323 my %indexentry;
324 my %strings = ();
325
326 my @bugs;
327
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}
333        ) {
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},
340                              @schema_arg,
341                             );
342     }
343     if (exists $param{src} and
344         defined $param{src}
345        ) {
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                              @schema_arg,
353                             );
354     }
355     for my $package (@possible_packages) {
356         next unless defined $package and length $package;
357         add_user($package.'@'.$config{usertag_package_domain},
358                  \%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
359     }
360 }
361
362 # walk through the keys and make the right get_bugs query.
363
364 my $form_option_variables = {};
365 $form_option_variables->{search_key_order} = [@package_search_key_order];
366
367 # Set the title sanely and clean up parameters
368 my @title;
369 my @temp = @package_search_key_order;
370 while (my ($key,$value) = splice @temp, 0, 2) {
371      next unless exists $param{$key};
372      my @entries = ();
373      for my $entry (make_list($param{$key})) {
374           # we'll handle newest below
375           my $extra = '';
376           if (exists $param{dist} and ($key eq 'package' or $key eq 'src')) {
377                my %versions = get_versions(package => $entry,
378                                            (exists $param{dist}?(dist => $param{dist}):()),
379                                            (exists $param{arch}?(arch => $param{arch}):(arch => $config{default_architectures})),
380                                            ($key eq 'src'?(arch => q(source)):()),
381                                            no_source_arch => 1,
382                                            return_archs => 1,
383                                            @schema_arg,
384                                           );
385                my $verdesc;
386                if (keys %versions > 1) {
387                     $verdesc = 'versions '. join(', ',
388                                     map { $_ .' ['.join(', ',
389                                                     sort @{$versions{$_}}
390                                                    ).']';
391                                    } keys %versions);
392                }
393                else {
394                     $verdesc = 'version '.join(', ',
395                                                keys %versions
396                                               );
397                }
398                $extra= " ($verdesc)" if keys %versions;
399           }
400           if ($key eq 'maint' and $entry eq '') {
401                push @entries, "no one (packages without maintainers)"
402           }
403           else {
404                push @entries, $entry.$extra;
405           }
406      }
407      if ($key eq 'newest') {
408          push @title, 'in '.join(' or ',@entries).' newest reports';
409      } else {
410          push @title,$value.' '.join(' or ', @entries) if @entries;
411      }
412 }
413
414 my $title = $gBugs.' '.join(' and ', map {/ or /?"($_)":$_} @title);
415 @title = ();
416
417 #yeah for magick!
418 @bugs = get_bugs((map {exists $param{$_}?($_,$param{$_}):()}
419                   keys %package_search_keys, 'archive'),
420                  usertags => \%ut,
421                  @schema_arg,
422                 );
423
424 # shove in bugs which affect this package if there is a package or a
425 # source given (by default), but no affects options given
426 if (not exists $param{affects} and not exists $param{noaffects} and
427     (exists $param{src} or
428      exists $param{package})) {
429     push @bugs, get_bugs((map {my $key = $_;
430                                exists $param{$key}?($key =~ /^(?:package|src)$/?'affects':$key,
431                                                   ($key eq 'src'?[map {"src:$_"}make_list($param{$key})]:$param{$_})):()}
432                           grep {$_ ne 'newest'}
433                           keys %package_search_keys, 'archive'),
434                          usertags => \%ut,
435                          @schema_arg,
436                         );
437 }
438
439 # filter out included or excluded bugs
440
441
442 if (defined $param{version}) {
443      $title .= " at version $param{version}";
444 }
445 elsif (defined $param{dist}) {
446      $title .= " in $param{dist}";
447 }
448
449 $title = html_escape($title);
450
451 my @names; my @prior; my @order;
452 determine_ordering(cats => \%cats,
453                    param => \%param,
454                    ordering => \$ordering,
455                    names => \@names,
456                    prior => \@prior,
457                    title => \@title,
458                    order => \@order,
459                   );
460
461 # strip out duplicate bugs
462 my %bugs;
463 @bugs{@bugs} = @bugs;
464 @bugs = keys %bugs;
465
466 my $result = pkg_htmlizebugs(bugs => \@bugs,
467                              names => \@names,
468                              title => \@title,
469                              order => \@order,
470                              prior => \@prior,
471                              ordering => $ordering,
472                              bugusertags => \%bugusertags,
473                              bug_rev => $bug_rev,
474                              bug_order => $bug_order,
475                              repeatmerged => $param{repeatmerged},
476                              include => $include,
477                              exclude => $exclude,
478                              this => $this,
479                              options => \%param,
480                              @schema_arg,
481                              (exists $param{dist})?(dist    => $param{dist}):(),
482                             );
483
484 print "Cache-Control: public, max-age=300\n";
485 print "Content-Type: text/html; charset=utf-8\n\n";
486
487 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
488 print "<HTML><HEAD>\n" . 
489     "<TITLE>$title -- $gProject$Archived $gBug report logs</TITLE>\n" .
490     qq(<link rel="stylesheet" href="$gWebHostBugDir/css/bugs.css" type="text/css">) .
491     "</HEAD>\n" .
492     '<BODY onload="pagemain();">' .
493     "\n";
494 print qq(<DIV id="status_mask"></DIV>\n);
495 print "<H1>" . "$gProject$Archived $gBug report logs: $title" .
496       "</H1>\n";
497
498 my $showresult = 1;
499
500 my $pkg = $param{package} if defined $param{package};
501 my $src = $param{src} if defined $param{src};
502
503 my $pseudodesc = getpseudodesc();
504 if (defined $pseudodesc and defined $pkg and exists $pseudodesc->{$pkg}) {
505      delete $param{dist};
506 }
507
508 # output information about the packages
509
510 for my $package (make_list($param{package}||[])) {
511      print generate_package_info(binary => 1,
512                                  package => $package,
513                                  options => \%param,
514                                  bugs    => \@bugs,
515                                  @schema_arg,
516                                 );
517 }
518 for my $package (make_list($param{src}||[])) {
519      print generate_package_info(binary => 0,
520                                  package => $package,
521                                  options => \%param,
522                                  bugs    => \@bugs,
523                                  @schema_arg,
524                                 );
525 }
526
527 if (exists $param{maint} or exists $param{maintenc}) {
528     print "<p>Note that maintainers may use different Maintainer fields for\n";
529     print "different packages, so there may be other reports filed under\n";
530     print "different addresses.\n";
531 }
532 if (exists $param{submitter}) {
533     print "<p>Note that people may use different email accounts for\n";
534     print "different bugs, so there may be other reports filed under\n";
535     print "different addresses.\n";
536 }
537
538 print $result;
539
540 print fill_in_template(template=>'cgi/pkgreport_javascript');
541
542 print qq(<h2 class="outstanding"><!--<a class="options" href="javascript:toggle(1)">-->Options<!--</a>--></h2>\n);
543
544 $param{orderings} =
545     [uniq((grep {!$hidden{$_}} keys %cats),
546           $param{ordering})];
547 print option_form(template => 'cgi/pkgreport_options',
548                   param    => \%param,
549                   form_options => $form_options,
550                   variables => $form_option_variables,
551                  );
552
553 print "<hr>\n";
554 print fill_in_template(template=>'html/html_tail',
555                        hole_var => {'&strftime' => \&POSIX::strftime,
556                                    },
557                       );
558 print "</body></html>\n";
559