]> git.donarmstrong.com Git - debbugs.git/blob - cgi/pkgreport.cgi
455df20cea2896c7f2645c601d59a14584ce50a4
[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 binmode(STDOUT,':encoding(UTF-8)');
22 use POSIX qw(strftime nice);
23
24 use Debbugs::Config qw(:globals :text :config);
25
26 use Debbugs::User;
27
28 use Debbugs::Common qw(getparsedaddrs make_list getmaintainers getpseudodesc);
29
30 use Debbugs::Bugs qw(get_bugs bug_filter newest_bug);
31 use Debbugs::Packages qw(getsrcpkgs getpkgsrc get_versions);
32
33 use Debbugs::Status qw(splitpackages);
34
35 use Debbugs::CGI qw(:all);
36
37 use Debbugs::CGI::Pkgreport qw(:all);
38
39 use Debbugs::Text qw(:templates);
40
41 use CGI::Simple;
42 my $q = new CGI::Simple;
43
44 if ($q->request_method() eq 'HEAD') {
45      print $q->header(-type => "text/html",
46                       -charset => 'utf-8',
47                      );
48      exit 0;
49 }
50
51 my $default_params = {ordering => 'normal',
52                       archive  => 0,
53                       repeatmerged => 0,
54                       include      => [],
55                       exclude      => [],
56                      };
57
58 our %param = cgi_parameters(query => $q,
59                             single => [qw(ordering archive repeatmerged),
60                                        qw(bug-rev pend-rev sev-rev),
61                                        qw(maxdays mindays version),
62                                        qw(data which dist newest),
63                                        qw(noaffects),
64                                       ],
65                             default => $default_params,
66                            );
67
68 my ($form_options,$param) = ({},undef);
69 ($form_options,$param)= form_options_and_normal_param(\%param)
70      if $param{form_options};
71
72 %param = %{$param} if defined $param;
73
74 if (exists $param{form_options} and defined $param{form_options}) {
75      delete $param{form_options};
76      delete $param{submit} if exists $param{submit};
77      for my $default (keys %{$default_params}) {
78           if (exists $param{$default} and
79               not ref($default_params->{$default}) and
80               $default_params->{$default} eq $param{$default}
81              ) {
82                delete $param{$default};
83           }
84      }
85      for my $incexc (qw(include exclude)) {
86           next unless exists $param{$incexc};
87           # normalize tag to tags
88           $param{$incexc} = [map {s/^tag:/tags:/; $_} grep /\S\:\S/, make_list($param{$incexc})];
89      }
90      for my $key (keys %package_search_keys) {
91           next unless exists $param{key};
92           $param{$key} = [map {split /\s*,\s*/} make_list($param{$key})];
93      }
94      # kill off keys for which empty values are meaningless
95      for my $key (qw(package src submitter affects severity status dist)) {
96           next unless exists $param{$key};
97           $param{$key} = [grep {defined $_ and length $_}
98                           make_list($param{$key})];
99      }
100      print $q->redirect(munge_url('pkgreport.cgi?',%param));
101      exit 0;
102 }
103
104 # normalize innclude/exclude keys; currently this is in two locations,
105 # which is suboptimal. Closes: #567407
106 for my $incexc (qw(include exclude)) {
107     next unless exists $param{$incexc};
108     # normalize tag to tags
109     $param{$incexc} = [map {s/^tag:/tags:/; $_} make_list($param{$incexc})];
110 }
111
112
113
114 # map from yes|no to 1|0
115 for my $key (qw(repeatmerged bug-rev pend-rev sev-rev)) {
116      if (exists $param{$key}){
117           if ($param{$key} =~ /^no$/i) {
118                $param{$key} = 0;
119           }
120           elsif ($param{$key}) {
121                $param{$key} = 1;
122           }
123      }
124 }
125
126 if (lc($param{archive}) eq 'no') {
127      $param{archive} = 0;
128 }
129 elsif (lc($param{archive}) eq 'yes') {
130      $param{archive} = 1;
131 }
132
133 # fixup dist
134 if (exists $param{dist} and $param{dist} eq '') {
135      delete $param{dist};
136 }
137
138 my $include = $param{'&include'} || $param{'include'} || "";
139 my $exclude = $param{'&exclude'} || $param{'exclude'} || "";
140
141 my $users = $param{'users'} || "";
142
143 my $ordering = $param{'ordering'};
144 my $raw_sort = ($param{'raw'} || "no") eq "yes";
145 my $old_view = ($param{'oldview'} || "no") eq "yes";
146 my $age_sort = ($param{'age'} || "no") eq "yes";
147 unless (defined $ordering) {
148    $ordering = "normal";
149    $ordering = "oldview" if $old_view;
150    $ordering = "raw" if $raw_sort;
151    $ordering = 'age' if $age_sort;
152 }
153 $param{ordering} = $ordering;
154
155 our ($bug_order) = $ordering =~ /(age(?:rev)?)/;
156 $bug_order = '' if not defined $bug_order;
157
158 my $bug_rev = ($param{'bug-rev'} || "no") eq "yes";
159 my $pend_rev = ($param{'pend-rev'} || "no") eq "yes";
160 my $sev_rev = ($param{'sev-rev'} || "no") eq "yes";
161
162 my @inc_exc_mapping = ({name   => 'pending',
163                         incexc => 'include',
164                         key    => 'pend-inc',
165                        },
166                        {name   => 'pending',
167                         incexc => 'exclude',
168                         key    => 'pend-exc',
169                        },
170                        {name   => 'severity',
171                         incexc => 'include',
172                         key    => 'sev-inc',
173                        },
174                        {name   => 'severity',
175                         incexc => 'exclude',
176                         key    => 'sev-exc',
177                        },
178                        {name   => 'subject',
179                         incexc => 'include',
180                         key    => 'includesubj',
181                        },
182                        {name   => 'subject',
183                         incexc => 'exclude',
184                         key    => 'excludesubj',
185                        },
186                       );
187 for my $incexcmap (@inc_exc_mapping) {
188      push @{$param{$incexcmap->{incexc}}}, map {"$incexcmap->{name}:$_"}
189           map{split /\s*,\s*/} make_list($param{$incexcmap->{key}})
190                if exists $param{$incexcmap->{key}};
191      delete $param{$incexcmap->{key}};
192 }
193
194
195 my $maxdays = ($param{'maxdays'} || -1);
196 my $mindays = ($param{'mindays'} || 0);
197 my $version = $param{'version'} || undef;
198
199
200 our %hidden = map { $_, 1 } qw(status severity classification);
201 our %cats = (
202     "status" => [ {
203         "nam" => "Status",
204         "pri" => [map { "pending=$_" }
205             qw(pending forwarded pending-fixed fixed done absent)],
206         "ttl" => ["Outstanding","Forwarded","Pending Upload",
207                   "Fixed in NMU","Resolved","From other Branch"],
208         "def" => "Unknown Pending Status",
209         "ord" => [0,1,2,3,4,5,6],
210     } ],
211     "severity" => [ {
212         "nam" => "Severity",
213         "pri" => [map { "severity=$_" } @gSeverityList],
214         "ttl" => [map { $gSeverityDisplay{$_} } @gSeverityList],
215         "def" => "Unknown Severity",
216         "ord" => [0..@gSeverityList],
217     } ],
218     "classification" => [ {
219         "nam" => "Classification",
220         "pri" => [qw(pending=pending+tag=wontfix 
221                      pending=pending+tag=moreinfo
222                      pending=pending+tag=patch
223                      pending=pending+tag=confirmed
224                      pending=pending)],
225         "ttl" => ["Will Not Fix","More information needed",
226                   "Patch Available","Confirmed"],
227         "def" => "Unclassified",
228         "ord" => [2,3,4,1,0,5],
229     } ],
230     "oldview" => [ qw(status severity) ],
231     "normal" => [ qw(status severity classification) ],
232 );
233
234 if (exists $param{which} and exists $param{data}) {
235      $param{$param{which}} = [exists $param{$param{which}}?(make_list($param{$param{which}})):(),
236                               make_list($param{data}),
237                              ];
238      delete $param{which};
239      delete $param{data};
240 }
241
242 if (defined $param{maintenc}) {
243      $param{maint} = maint_decode($param{maintenc});
244      delete $param{maintenc}
245 }
246
247 if (exists $param{pkg}) {
248      $param{package} = $param{pkg};
249      delete $param{pkg};
250 }
251
252 if (not grep {exists $param{$_}} keys %package_search_keys and exists $param{users}) {
253      $param{usertag} = [make_list($param{users})];
254 }
255
256 my %bugusertags;
257 my %ut;
258 my %seen_users;
259
260 for my $user (map {split /[\s*,\s*]+/} make_list($param{users}||[])) {
261     next unless length($user);
262     add_user($user,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
263 }
264
265 if (defined $param{usertag}) {
266      for my $usertag (make_list($param{usertag})) {
267           my %select_ut = ();
268           my ($u, $t) = split /:/, $usertag, 2;
269           Debbugs::User::read_usertags(\%select_ut, $u);
270           unless (defined $t && $t ne "") {
271                $t = join(",", keys(%select_ut));
272           }
273           add_user($u,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
274           push @{$param{tag}}, split /,/, $t;
275      }
276 }
277
278 quitcgi("You have to choose something to select by", '400 Bad Request')
279   unless grep {exists $param{$_}} keys %package_search_keys;
280
281
282 my $Archived = $param{archive} ? " Archived" : "";
283
284 my $this = munge_url('pkgreport.cgi?',
285                       %param,
286                      );
287
288 my %indexentry;
289 my %strings = ();
290
291 my @bugs;
292
293 # addusers for source and binary packages being searched for
294 my $pkgsrc = getpkgsrc();
295 my $srcpkg = getsrcpkgs();
296 for my $package (# For binary packages, add the binary package
297                  # and corresponding source package
298                  make_list($param{package}||[]),
299                  (map {defined $pkgsrc->{$_}?($pkgsrc->{$_}):()}
300                   make_list($param{package}||[]),
301                  ),
302                  # For source packages, add the source package
303                  # and corresponding binary packages
304                  make_list($param{src}||[]),
305                  (map {defined $srcpkg->{$_}?($srcpkg->{$_}):()}
306                   make_list($param{src}||[]),
307                  ),
308                 ) {
309      next unless defined $package;
310      add_user($package.'@'.$config{usertag_package_domain},
311               \%ut,\%bugusertags,\%seen_users,\%cats,\%hidden)
312           if defined $config{usertag_package_domain};
313 }
314
315
316 # walk through the keys and make the right get_bugs query.
317
318 my $form_option_variables = {};
319 $form_option_variables->{search_key_order} = [@package_search_key_order];
320
321 # Set the title sanely and clean up parameters
322 my @title;
323 my @temp = @package_search_key_order;
324 while (my ($key,$value) = splice @temp, 0, 2) {
325      next unless exists $param{$key};
326      my @entries = ();
327      for my $entry (make_list($param{$key})) {
328           # we'll handle newest below
329           next if $key eq 'newest';
330           my $extra = '';
331           if (exists $param{dist} and ($key eq 'package' or $key eq 'src')) {
332                my %versions = get_versions(package => $entry,
333                                            (exists $param{dist}?(dist => $param{dist}):()),
334                                            (exists $param{arch}?(arch => $param{arch}):(arch => $config{default_architectures})),
335                                            ($key eq 'src'?(arch => q(source)):()),
336                                            no_source_arch => 1,
337                                            return_archs => 1,
338                                           );
339                my $verdesc;
340                if (keys %versions > 1) {
341                     $verdesc = 'versions '. join(', ',
342                                     map { $_ .' ['.join(', ',
343                                                     sort @{$versions{$_}}
344                                                    ).']';
345                                    } keys %versions);
346                }
347                else {
348                     $verdesc = 'version '.join(', ',
349                                                keys %versions
350                                               );
351                }
352                $extra= " ($verdesc)" if keys %versions;
353           }
354           if ($key eq 'maint' and $entry eq '') {
355                push @entries, "no one (packages without maintainers)"
356           }
357           else {
358                push @entries, $entry.$extra;
359           }
360      }
361      push @title,$value.' '.join(' or ', @entries) if @entries;
362 }
363 if (defined $param{newest}) {
364      my $newest_bug = newest_bug();
365      @bugs = ($newest_bug - $param{newest} + 1) .. $newest_bug;
366      push @title, 'in '.@bugs.' newest reports';
367      $param{bugs} = [exists $param{bugs}?make_list($param{bugs}):(),
368                      @bugs,
369                     ];
370 }
371
372 my $title = $gBugs.' '.join(' and ', map {/ or /?"($_)":$_} @title);
373 @title = ();
374
375 #yeah for magick!
376 @bugs = get_bugs((map {exists $param{$_}?($_,$param{$_}):()}
377                   grep {$_ ne 'newest'}
378                   keys %package_search_keys, 'archive'),
379                  usertags => \%ut,
380                 );
381
382 # shove in bugs which affect this package if there is a package or a
383 # source given (by default), but no affects options given
384 if (not exists $param{affects} and not exists $param{noaffects} and
385     (exists $param{src} or
386      exists $param{package})) {
387     push @bugs, get_bugs((map {my $key = $_;
388                                exists $param{$key}?($key =~ /^(?:package|src)$/?'affects':$key,
389                                                   ($key eq 'src'?[map {"src:$_"}make_list($param{$key})]:$param{$_})):()}
390                           grep {$_ ne 'newest'}
391                           keys %package_search_keys, 'archive'),
392                          usertags => \%ut,
393                         );
394 }
395
396 # filter out included or excluded bugs
397
398
399 if (defined $param{version}) {
400      $title .= " at version $param{version}";
401 }
402 elsif (defined $param{dist}) {
403      $title .= " in $param{dist}";
404 }
405
406 $title = html_escape($title);
407
408 my @names; my @prior; my @order;
409 determine_ordering(cats => \%cats,
410                    param => \%param,
411                    ordering => \$ordering,
412                    names => \@names,
413                    prior => \@prior,
414                    title => \@title,
415                    order => \@order,
416                   );
417
418 # strip out duplicate bugs
419 my %bugs;
420 @bugs{@bugs} = @bugs;
421 @bugs = keys %bugs;
422
423 my $result = pkg_htmlizebugs(bugs => \@bugs,
424                              names => \@names,
425                              title => \@title,
426                              order => \@order,
427                              prior => \@prior,
428                              ordering => $ordering,
429                              bugusertags => \%bugusertags,
430                              bug_rev => $bug_rev,
431                              bug_order => $bug_order,
432                              repeatmerged => $param{repeatmerged},
433                              include => $include,
434                              exclude => $exclude,
435                              this => $this,
436                              options => \%param,
437                              (exists $param{dist})?(dist    => $param{dist}):(),
438                             );
439
440 print "Cache-Control: public, max-age=300\n";
441 print "Content-Type: text/html; charset=utf-8\n\n";
442
443 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
444 print "<HTML><HEAD>\n" . 
445     "<TITLE>$title -- $gProject$Archived $gBug report logs</TITLE>\n" .
446     qq(<link rel="stylesheet" href="$gWebHostBugDir/css/bugs.css" type="text/css">) .
447     "</HEAD>\n" .
448     '<BODY onload="pagemain();">' .
449     "\n";
450 print qq(<DIV id="status_mask"></DIV>\n);
451 print "<H1>" . "$gProject$Archived $gBug report logs: $title" .
452       "</H1>\n";
453
454 my $showresult = 1;
455
456 my $pkg = $param{package} if defined $param{package};
457 my $src = $param{src} if defined $param{src};
458
459 my $pseudodesc = getpseudodesc();
460 if (defined $pseudodesc and defined $pkg and exists $pseudodesc->{$pkg}) {
461      delete $param{dist};
462 }
463
464 # output information about the packages
465
466 for my $package (make_list($param{package}||[])) {
467      print generate_package_info(binary => 1,
468                                  package => $package,
469                                  options => \%param,
470                                  bugs    => \@bugs,
471                                 );
472 }
473 for my $package (make_list($param{src}||[])) {
474      print generate_package_info(binary => 0,
475                                  package => $package,
476                                  options => \%param,
477                                  bugs    => \@bugs,
478                                 );
479 }
480
481 if (exists $param{maint} or exists $param{maintenc}) {
482     print "<p>Note that maintainers may use different Maintainer fields for\n";
483     print "different packages, so there may be other reports filed under\n";
484     print "different addresses.\n";
485 }
486 if (exists $param{submitter}) {
487     print "<p>Note that people may use different email accounts for\n";
488     print "different bugs, so there may be other reports filed under\n";
489     print "different addresses.\n";
490 }
491
492 print $result;
493
494 print fill_in_template(template=>'cgi/pkgreport_javascript');
495
496 print qq(<h2 class="outstanding"><!--<a class="options" href="javascript:toggle(1)">-->Options<!--</a>--></h2>\n);
497
498 print option_form(template => 'cgi/pkgreport_options',
499                   param    => \%param,
500                   form_options => $form_options,
501                   variables => $form_option_variables,
502                  );
503
504 print "<hr>\n";
505 print fill_in_template(template=>'html/html_tail',
506                        hole_var => {'&strftime' => \&POSIX::strftime,
507                                    },
508                       );
509 print "</body></html>\n";
510