]> git.donarmstrong.com Git - debbugs.git/blob - cgi/pkgreport.cgi
fix captialization of cache control
[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") unless grep {exists $param{$_}} keys %package_search_keys;
279
280
281 my $Archived = $param{archive} ? " Archived" : "";
282
283 my $this = munge_url('pkgreport.cgi?',
284                       %param,
285                      );
286
287 my %indexentry;
288 my %strings = ();
289
290 my @bugs;
291
292 # addusers for source and binary packages being searched for
293 my $pkgsrc = getpkgsrc();
294 my $srcpkg = getsrcpkgs();
295 for my $package (# For binary packages, add the binary package
296                  # and corresponding source package
297                  make_list($param{package}||[]),
298                  (map {defined $pkgsrc->{$_}?($pkgsrc->{$_}):()}
299                   make_list($param{package}||[]),
300                  ),
301                  # For source packages, add the source package
302                  # and corresponding binary packages
303                  make_list($param{src}||[]),
304                  (map {defined $srcpkg->{$_}?($srcpkg->{$_}):()}
305                   make_list($param{src}||[]),
306                  ),
307                 ) {
308      next unless defined $package;
309      add_user($package.'@'.$config{usertag_package_domain},
310               \%ut,\%bugusertags,\%seen_users,\%cats,\%hidden)
311           if defined $config{usertag_package_domain};
312 }
313
314
315 # walk through the keys and make the right get_bugs query.
316
317 my $form_option_variables = {};
318 $form_option_variables->{search_key_order} = [@package_search_key_order];
319
320 # Set the title sanely and clean up parameters
321 my @title;
322 my @temp = @package_search_key_order;
323 while (my ($key,$value) = splice @temp, 0, 2) {
324      next unless exists $param{$key};
325      my @entries = ();
326      for my $entry (make_list($param{$key})) {
327           # we'll handle newest below
328           next if $key eq 'newest';
329           my $extra = '';
330           if (exists $param{dist} and ($key eq 'package' or $key eq 'src')) {
331                my %versions = get_versions(package => $entry,
332                                            (exists $param{dist}?(dist => $param{dist}):()),
333                                            (exists $param{arch}?(arch => $param{arch}):(arch => $config{default_architectures})),
334                                            ($key eq 'src'?(arch => q(source)):()),
335                                            no_source_arch => 1,
336                                            return_archs => 1,
337                                           );
338                my $verdesc;
339                if (keys %versions > 1) {
340                     $verdesc = 'versions '. join(', ',
341                                     map { $_ .' ['.join(', ',
342                                                     sort @{$versions{$_}}
343                                                    ).']';
344                                    } keys %versions);
345                }
346                else {
347                     $verdesc = 'version '.join(', ',
348                                                keys %versions
349                                               );
350                }
351                $extra= " ($verdesc)" if keys %versions;
352           }
353           if ($key eq 'maint' and $entry eq '') {
354                push @entries, "no one (packages without maintainers)"
355           }
356           else {
357                push @entries, $entry.$extra;
358           }
359      }
360      push @title,$value.' '.join(' or ', @entries) if @entries;
361 }
362 if (defined $param{newest}) {
363      my $newest_bug = newest_bug();
364      @bugs = ($newest_bug - $param{newest} + 1) .. $newest_bug;
365      push @title, 'in '.@bugs.' newest reports';
366      $param{bugs} = [exists $param{bugs}?make_list($param{bugs}):(),
367                      @bugs,
368                     ];
369 }
370
371 my $title = $gBugs.' '.join(' and ', map {/ or /?"($_)":$_} @title);
372 @title = ();
373
374 #yeah for magick!
375 @bugs = get_bugs((map {exists $param{$_}?($_,$param{$_}):()}
376                   grep {$_ ne 'newest'}
377                   keys %package_search_keys, 'archive'),
378                  usertags => \%ut,
379                 );
380
381 # shove in bugs which affect this package if there is a package or a
382 # source given (by default), but no affects options given
383 if (not exists $param{affects} and not exists $param{noaffects} and
384     (exists $param{src} or
385      exists $param{package})) {
386     push @bugs, get_bugs((map {my $key = $_;
387                                exists $param{$key}?($key =~ /^(?:package|src)$/?'affects':$key,
388                                                   ($key eq 'src'?[map {"src:$_"}make_list($param{$key})]:$param{$_})):()}
389                           grep {$_ ne 'newest'}
390                           keys %package_search_keys, 'archive'),
391                          usertags => \%ut,
392                         );
393 }
394
395 # filter out included or excluded bugs
396
397
398 if (defined $param{version}) {
399      $title .= " at version $param{version}";
400 }
401 elsif (defined $param{dist}) {
402      $title .= " in $param{dist}";
403 }
404
405 $title = html_escape($title);
406
407 my @names; my @prior; my @order;
408 determine_ordering(cats => \%cats,
409                    param => \%param,
410                    ordering => \$ordering,
411                    names => \@names,
412                    prior => \@prior,
413                    title => \@title,
414                    order => \@order,
415                   );
416
417 # strip out duplicate bugs
418 my %bugs;
419 @bugs{@bugs} = @bugs;
420 @bugs = keys %bugs;
421
422 my $result = pkg_htmlizebugs(bugs => \@bugs,
423                              names => \@names,
424                              title => \@title,
425                              order => \@order,
426                              prior => \@prior,
427                              ordering => $ordering,
428                              bugusertags => \%bugusertags,
429                              bug_rev => $bug_rev,
430                              bug_order => $bug_order,
431                              repeatmerged => $param{repeatmerged},
432                              include => $include,
433                              exclude => $exclude,
434                              this => $this,
435                              options => \%param,
436                              (exists $param{dist})?(dist    => $param{dist}):(),
437                             );
438
439 print "Cache-Control: public, max-age=300\n";
440 print "Content-Type: text/html; charset=utf-8\n\n";
441
442 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
443 print "<HTML><HEAD>\n" . 
444     "<TITLE>$title -- $gProject$Archived $gBug report logs</TITLE>\n" .
445     qq(<link rel="stylesheet" href="$gWebHostBugDir/css/bugs.css" type="text/css">) .
446     "</HEAD>\n" .
447     '<BODY onload="pagemain();">' .
448     "\n";
449 print qq(<DIV id="status_mask"></DIV>\n);
450 print "<H1>" . "$gProject$Archived $gBug report logs: $title" .
451       "</H1>\n";
452
453 my $showresult = 1;
454
455 my $pkg = $param{package} if defined $param{package};
456 my $src = $param{src} if defined $param{src};
457
458 my $pseudodesc = getpseudodesc();
459 if (defined $pseudodesc and defined $pkg and exists $pseudodesc->{$pkg}) {
460      delete $param{dist};
461 }
462
463 # output information about the packages
464
465 for my $package (make_list($param{package}||[])) {
466      print generate_package_info(binary => 1,
467                                  package => $package,
468                                  options => \%param,
469                                  bugs    => \@bugs,
470                                 );
471 }
472 for my $package (make_list($param{src}||[])) {
473      print generate_package_info(binary => 0,
474                                  package => $package,
475                                  options => \%param,
476                                  bugs    => \@bugs,
477                                 );
478 }
479
480 if (exists $param{maint} or exists $param{maintenc}) {
481     print "<p>Note that maintainers may use different Maintainer fields for\n";
482     print "different packages, so there may be other reports filed under\n";
483     print "different addresses.\n";
484 }
485 if (exists $param{submitter}) {
486     print "<p>Note that people may use different email accounts for\n";
487     print "different bugs, so there may be other reports filed under\n";
488     print "different addresses.\n";
489 }
490
491 print $result;
492
493 print fill_in_template(template=>'cgi/pkgreport_javascript');
494
495 print qq(<h2 class="outstanding"><!--<a class="options" href="javascript:toggle(1)">-->Options<!--</a>--></h2>\n);
496
497 print option_form(template => 'cgi/pkgreport_options',
498                   param    => \%param,
499                   form_options => $form_options,
500                   variables => $form_option_variables,
501                  );
502
503 print "<hr>\n";
504 print fill_in_template(template=>'html/html_tail',
505                        hole_var => {'&strftime' => \&POSIX::strftime,
506                                    },
507                       );
508 print "</body></html>\n";
509