]> git.donarmstrong.com Git - debbugs.git/blob - cgi/pkgreport.cgi
Indiciate what machine has built webpages (closes: #507022)
[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 use POSIX qw(strftime nice);
17
18 use Debbugs::Config qw(:globals :text :config);
19
20 use Debbugs::User;
21
22 use Debbugs::Common qw(getparsedaddrs make_list getmaintainers getpseudodesc);
23
24 use Debbugs::Bugs qw(get_bugs bug_filter newest_bug);
25 use Debbugs::Packages qw(getsrcpkgs getpkgsrc get_versions);
26
27 use Debbugs::Status qw(splitpackages);
28
29 use Debbugs::CGI qw(:all);
30
31 use Debbugs::CGI::Pkgreport qw(:all);
32
33 use Debbugs::Text qw(:templates);
34
35 use CGI::Simple;
36 my $q = new CGI::Simple;
37
38 if ($q->request_method() eq 'HEAD') {
39      print $q->header(-type => "text/html",
40                       -charset => 'utf-8',
41                      );
42      exit 0;
43 }
44
45 my $default_params = {ordering => 'normal',
46                       archive  => 0,
47                       repeatmerged => 0,
48                       include      => [],
49                       exclude      => [],
50                      };
51
52 our %param = cgi_parameters(query => $q,
53                             single => [qw(ordering archive repeatmerged),
54                                        qw(bug-rev pend-rev sev-rev),
55                                        qw(maxdays mindays version),
56                                        qw(data which dist newest),
57                                       ],
58                             default => $default_params,
59                            );
60
61 my ($form_options,$param) = ({},undef);
62 ($form_options,$param)= form_options_and_normal_param(\%param)
63      if $param{form_options};
64
65 %param = %{$param} if defined $param;
66
67 if (exists $param{form_options} and defined $param{form_options}) {
68      delete $param{form_options};
69      delete $param{submit} if exists $param{submit};
70      for my $default (keys %{$default_params}) {
71           if (exists $param{$default} and
72               not ref($default_params->{$default}) and
73               $default_params->{$default} eq $param{$default}
74              ) {
75                delete $param{$default};
76           }
77      }
78      for my $incexc (qw(include exclude)) {
79           next unless exists $param{$incexc};
80           $param{$incexc} = [grep /\S\:\S/, make_list($param{$incexc})];
81      }
82      for my $key (keys %package_search_keys) {
83           next unless exists $param{key};
84           $param{$key} = [map {split /\s*,\s*/} make_list($param{$key})];
85      }
86      # kill off keys for which empty values are meaningless
87      for my $key (qw(package src submitter affects severity status dist)) {
88           next unless exists $param{$key};
89           $param{$key} = [grep {defined $_ and length $_}
90                           make_list($param{$key})];
91      }
92      print $q->redirect(munge_url('pkgreport.cgi?',%param));
93      exit 0;
94 }
95
96 # map from yes|no to 1|0
97 for my $key (qw(repeatmerged bug-rev pend-rev sev-rev)) {
98      if (exists $param{$key}){
99           if ($param{$key} =~ /^no$/i) {
100                $param{$key} = 0;
101           }
102           elsif ($param{$key}) {
103                $param{$key} = 1;
104           }
105      }
106 }
107
108 if (lc($param{archive}) eq 'no') {
109      $param{archive} = 0;
110 }
111 elsif (lc($param{archive}) eq 'yes') {
112      $param{archive} = 1;
113 }
114
115 # fixup dist
116 if (exists $param{dist} and $param{dist} eq '') {
117      delete $param{dist};
118 }
119
120 my $include = $param{'&include'} || $param{'include'} || "";
121 my $exclude = $param{'&exclude'} || $param{'exclude'} || "";
122
123 my $users = $param{'users'} || "";
124
125 my $ordering = $param{'ordering'};
126 my $raw_sort = ($param{'raw'} || "no") eq "yes";
127 my $old_view = ($param{'oldview'} || "no") eq "yes";
128 my $age_sort = ($param{'age'} || "no") eq "yes";
129 unless (defined $ordering) {
130    $ordering = "normal";
131    $ordering = "oldview" if $old_view;
132    $ordering = "raw" if $raw_sort;
133    $ordering = 'age' if $age_sort;
134 }
135 $param{ordering} = $ordering;
136
137 our ($bug_order) = $ordering =~ /(age(?:rev)?)/;
138 $bug_order = '' if not defined $bug_order;
139
140 my $bug_rev = ($param{'bug-rev'} || "no") eq "yes";
141 my $pend_rev = ($param{'pend-rev'} || "no") eq "yes";
142 my $sev_rev = ($param{'sev-rev'} || "no") eq "yes";
143
144 my @inc_exc_mapping = ({name   => 'pending',
145                         incexc => 'include',
146                         key    => 'pend-inc',
147                        },
148                        {name   => 'pending',
149                         incexc => 'exclude',
150                         key    => 'pend-exc',
151                        },
152                        {name   => 'severity',
153                         incexc => 'include',
154                         key    => 'sev-inc',
155                        },
156                        {name   => 'severity',
157                         incexc => 'exclude',
158                         key    => 'sev-exc',
159                        },
160                        {name   => 'subject',
161                         incexc => 'include',
162                         key    => 'includesubj',
163                        },
164                        {name   => 'subject',
165                         incexc => 'exclude',
166                         key    => 'excludesubj',
167                        },
168                       );
169 for my $incexcmap (@inc_exc_mapping) {
170      push @{$param{$incexcmap->{incexc}}}, map {"$incexcmap->{name}:$_"}
171           map{split /\s*,\s*/} make_list($param{$incexcmap->{key}})
172                if exists $param{$incexcmap->{key}};
173      delete $param{$incexcmap->{key}};
174 }
175
176
177 my $maxdays = ($param{'maxdays'} || -1);
178 my $mindays = ($param{'mindays'} || 0);
179 my $version = $param{'version'} || undef;
180
181
182 our %hidden = map { $_, 1 } qw(status severity classification);
183 our %cats = (
184     "status" => [ {
185         "nam" => "Status",
186         "pri" => [map { "pending=$_" }
187             qw(pending forwarded pending-fixed fixed done absent)],
188         "ttl" => ["Outstanding","Forwarded","Pending Upload",
189                   "Fixed in NMU","Resolved","From other Branch"],
190         "def" => "Unknown Pending Status",
191         "ord" => [0,1,2,3,4,5,6],
192     } ],
193     "severity" => [ {
194         "nam" => "Severity",
195         "pri" => [map { "severity=$_" } @gSeverityList],
196         "ttl" => [map { $gSeverityDisplay{$_} } @gSeverityList],
197         "def" => "Unknown Severity",
198         "ord" => [0..@gSeverityList],
199     } ],
200     "classification" => [ {
201         "nam" => "Classification",
202         "pri" => [qw(pending=pending+tag=wontfix 
203                      pending=pending+tag=moreinfo
204                      pending=pending+tag=patch
205                      pending=pending+tag=confirmed
206                      pending=pending)],
207         "ttl" => ["Will Not Fix","More information needed",
208                   "Patch Available","Confirmed"],
209         "def" => "Unclassified",
210         "ord" => [2,3,4,1,0,5],
211     } ],
212     "oldview" => [ qw(status severity) ],
213     "normal" => [ qw(status severity classification) ],
214 );
215
216 if (exists $param{which} and exists $param{data}) {
217      $param{$param{which}} = [exists $param{$param{which}}?(make_list($param{$param{which}})):(),
218                               make_list($param{data}),
219                              ];
220      delete $param{which};
221      delete $param{data};
222 }
223
224 if (defined $param{maintenc}) {
225      $param{maint} = maint_decode($param{maintenc});
226      delete $param{maintenc}
227 }
228
229
230 if (not grep {exists $param{$_}} keys %package_search_keys and exists $param{users}) {
231      $param{usertag} = [make_list($param{users})];
232 }
233
234 if (exists $param{pkg}) {
235      $param{package} = $param{pkg};
236      delete $param{pkg};
237 }
238
239 my %bugusertags;
240 my %ut;
241 my %seen_users;
242
243 for my $user (map {split /[\s*,\s*]+/} make_list($param{users}||[])) {
244     next unless length($user);
245     add_user($user,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
246 }
247
248 if (defined $param{usertag}) {
249      for my $usertag (make_list($param{usertag})) {
250           my %select_ut = ();
251           my ($u, $t) = split /:/, $usertag, 2;
252           Debbugs::User::read_usertags(\%select_ut, $u);
253           unless (defined $t && $t ne "") {
254                $t = join(",", keys(%select_ut));
255           }
256           add_user($u,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
257           push @{$param{tag}}, split /,/, $t;
258      }
259 }
260
261 quitcgi("You have to choose something to select by") unless grep {exists $param{$_}} keys %package_search_keys;
262
263
264 my $Archived = $param{archive} ? " Archived" : "";
265
266 my $this = munge_url('pkgreport.cgi?',
267                       %param,
268                      );
269
270 my %indexentry;
271 my %strings = ();
272
273 my @bugs;
274
275 # addusers for source and binary packages being searched for
276 my $pkgsrc = getpkgsrc();
277 my $srcpkg = getsrcpkgs();
278 for my $package (# For binary packages, add the binary package
279                  # and corresponding source package
280                  make_list($param{package}||[]),
281                  (map {defined $pkgsrc->{$_}?($pkgsrc->{$_}):()}
282                   make_list($param{package}||[]),
283                  ),
284                  # For source packages, add the source package
285                  # and corresponding binary packages
286                  make_list($param{src}||[]),
287                  (map {defined $srcpkg->{$_}?($srcpkg->{$_}):()}
288                   make_list($param{src}||[]),
289                  ),
290                 ) {
291      next unless defined $package;
292      add_user($package.'@'.$config{usertag_package_domain},
293               \%ut,\%bugusertags,\%seen_users,\%cats,\%hidden)
294           if defined $config{usertag_package_domain};
295 }
296
297
298 # walk through the keys and make the right get_bugs query.
299
300 my $form_option_variables = {};
301 $form_option_variables->{search_key_order} = [@package_search_key_order];
302
303 # Set the title sanely and clean up parameters
304 my @title;
305 my @temp = @package_search_key_order;
306 while (my ($key,$value) = splice @temp, 0, 2) {
307      next unless exists $param{$key};
308      my @entries = ();
309      for my $entry (make_list($param{$key})) {
310           # we'll handle newest below
311           next if $key eq 'newest';
312           my $extra = '';
313           if (exists $param{dist} and ($key eq 'package' or $key eq 'src')) {
314                my %versions = get_versions(package => $entry,
315                                            (exists $param{dist}?(dist => $param{dist}):()),
316                                            (exists $param{arch}?(arch => $param{arch}):(arch => $config{default_architectures})),
317                                            ($key eq 'src'?(arch => q(source)):()),
318                                            no_source_arch => 1,
319                                            return_archs => 1,
320                                           );
321                my $verdesc;
322                if (keys %versions > 1) {
323                     $verdesc = 'versions '. join(', ',
324                                     map { $_ .' ['.join(', ',
325                                                     sort @{$versions{$_}}
326                                                    ).']';
327                                    } keys %versions);
328                }
329                else {
330                     $verdesc = 'version '.join(', ',
331                                                keys %versions
332                                               );
333                }
334                $extra= " ($verdesc)" if keys %versions;
335           }
336           if ($key eq 'maint' and $entry eq '') {
337                push @entries, "no one (packages without maintainers)"
338           }
339           else {
340                push @entries, $entry.$extra;
341           }
342      }
343      push @title,$value.' '.join(' or ', @entries) if @entries;
344 }
345 if (defined $param{newest}) {
346      my $newest_bug = newest_bug();
347      @bugs = ($newest_bug - $param{newest} + 1) .. $newest_bug;
348      push @title, 'in '.@bugs.' newest reports';
349      $param{bugs} = [exists $param{bugs}?make_list($param{bugs}):(),
350                      @bugs,
351                     ];
352 }
353
354 my $title = $gBugs.' '.join(' and ', map {/ or /?"($_)":$_} @title);
355 @title = ();
356
357 #yeah for magick!
358 @bugs = get_bugs((map {exists $param{$_}?($_,$param{$_}):()}
359                   grep {$_ ne 'newest'}
360                   keys %package_search_keys, 'archive'),
361                  usertags => \%ut,
362                 );
363
364 if (defined $param{version}) {
365      $title .= " at version $param{version}";
366 }
367 elsif (defined $param{dist}) {
368      $title .= " in $param{dist}";
369 }
370
371 $title = html_escape($title);
372
373 my @names; my @prior; my @order;
374 determine_ordering(cats => \%cats,
375                    param => \%param,
376                    ordering => \$ordering,
377                    names => \@names,
378                    prior => \@prior,
379                    title => \@title,
380                    order => \@order,
381                   );
382
383 # strip out duplicate bugs
384 my %bugs;
385 @bugs{@bugs} = @bugs;
386 @bugs = keys %bugs;
387
388 my $result = pkg_htmlizebugs(bugs => \@bugs,
389                              names => \@names,
390                              title => \@title,
391                              order => \@order,
392                              prior => \@prior,
393                              ordering => $ordering,
394                              bugusertags => \%bugusertags,
395                              bug_rev => $bug_rev,
396                              bug_order => $bug_order,
397                              repeatmerged => $param{repeatmerged},
398                              include => $include,
399                              exclude => $exclude,
400                              this => $this,
401                              options => \%param,
402                              (exists $param{dist})?(dist    => $param{dist}):(),
403                             );
404
405 print "Content-Type: text/html; charset=utf-8\n\n";
406
407 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
408 print "<HTML><HEAD>\n" . 
409     "<TITLE>$title -- $gProject$Archived $gBug report logs</TITLE>\n" .
410     qq(<link rel="stylesheet" href="$gWebHostBugDir/css/bugs.css" type="text/css">) .
411     "</HEAD>\n" .
412     '<BODY onload="pagemain();">' .
413     "\n";
414 print qq(<DIV id="status_mask"></DIV>\n);
415 print "<H1>" . "$gProject$Archived $gBug report logs: $title" .
416       "</H1>\n";
417
418 my $showresult = 1;
419
420 my $pkg = $param{package} if defined $param{package};
421 my $src = $param{src} if defined $param{src};
422
423 my $pseudodesc = getpseudodesc();
424 if (defined $pseudodesc and defined $pkg and exists $pseudodesc->{$pkg}) {
425      delete $param{dist};
426 }
427
428 # output infomration about the packages
429
430 for my $package (make_list($param{package}||[])) {
431      print generate_package_info(binary => 1,
432                                  package => $package,
433                                  options => \%param,
434                                  bugs    => \@bugs,
435                                 );
436 }
437 for my $package (make_list($param{src}||[])) {
438      print generate_package_info(binary => 0,
439                                  package => $package,
440                                  options => \%param,
441                                  bugs    => \@bugs,
442                                 );
443 }
444
445 if (exists $param{maint} or exists $param{maintenc}) {
446     print "<p>Note that maintainers may use different Maintainer fields for\n";
447     print "different packages, so there may be other reports filed under\n";
448     print "different addresses.\n";
449 }
450 if (exists $param{submitter}) {
451     print "<p>Note that people may use different email accounts for\n";
452     print "different bugs, so there may be other reports filed under\n";
453     print "different addresses.\n";
454 }
455
456 # my $archive_links;
457 # my @archive_links;
458 # my %archive_values = (both => 'archived and unarchived',
459 #                     0    => 'not archived',
460 #                     1    => 'archived',
461 #                    );
462 # while (my ($key,$value) = each %archive_values) {
463 #      next if $key eq lc($param{archive});
464 #      push @archive_links, qq(<a href=").
465 #         html_escape(pkg_url((
466 #                      map {
467 #                           $_ eq 'archive'?():($_,$param{$_})
468 #                      } keys %param),
469 #                           archive => $key
470 #                          )).qq(">$value reports </a>);
471 # }
472 # print '<p>See the '.join (' or ',@archive_links)."</p>\n";
473
474 print $result;
475
476 print pkg_javascript() . "\n";
477
478 print qq(<h2 class="outstanding"><!--<a class="options" href="javascript:toggle(1)">-->Options<!--</a>--></h2>\n);
479
480 print option_form(template => 'cgi/pkgreport_options',
481                   param    => \%param,
482                   form_options => $form_options,
483                   variables => $form_option_variables,
484                  );
485
486 # print "<h2 class=\"outstanding\"><a class=\"options\" href=\"javascript:toggle(1)\">Options</a></h2>\n";
487 # print "<div id=\"a_1\">\n";
488 # printf "<form action=\"%s\" method=POST>\n", myurl();
489
490 # print "<table class=\"forms\">\n";
491
492 # my ($checked_any, $checked_sui, $checked_ver) = ("", "", "");
493 # if (defined $dist) {
494 #   $checked_sui = "CHECKED";
495 # } elsif (defined $version) {
496 #   $checked_ver = "CHECKED";
497 # } else {
498 #   $checked_any = "CHECKED";
499 # }
500
501 # print "<tr><td>Show bugs applicable to</td>\n";
502 # print "    <td><input id=\"b_1_1\" name=vt value=none type=radio onchange=\"enable(1);\" $checked_any>anything</td></tr>\n";
503 # print "<tr><td></td>";
504 # print "    <td><input id=\"b_1_2\" name=vt value=bysuite type=radio onchange=\"enable(1);\" $checked_sui>" . pkg_htmlselectsuite(1,2,1) . " for " . pkg_htmlselectarch(1,2,2) . "</td></tr>\n";
505
506 # if (defined $pkg) {
507 #     my $v = html_escape($version) || "";
508 #     my $pkgsane = html_escape($pkg->[0]);
509 #     print "<tr><td></td>";
510 #     print "    <td><input id=\"b_1_3\" name=vt value=bypkg type=radio onchange=\"enable(1);\" $checked_ver>$pkgsane version <input id=\"b_1_3_1\" name=version value=\"$v\"></td></tr>\n";
511 # } elsif (defined $src) {
512 #     my $v = html_escape($version) || "";
513 #     my $srcsane = html_escape($src->[0]);
514 #     print "<tr><td></td>";
515 #     print "    <td><input name=vt value=bysrc type=radio onchange=\"enable(1);\" $checked_ver>$srcsane version <input id=\"b_1_3_1\" name=version value=\"$v\"></td></tr>\n";
516 # }
517 # print "<tr><td>&nbsp;</td></tr>\n";
518
519 # my $includetags = html_escape(join(" ", grep { !m/^subj:/i } map {split /[\s,]+/} ref($include)?@{$include}:$include));
520 # my $excludetags = html_escape(join(" ", grep { !m/^subj:/i } map {split /[\s,]+/} ref($exclude)?@{$exclude}:$exclude));
521 # my $includesubj = html_escape(join(" ", map { s/^subj://i; $_ } grep { m/^subj:/i } map {split /[\s,]+/} ref($include)?@{$include}:$include));
522 # my $excludesubj = html_escape(join(" ", map { s/^subj://i; $_ } grep { m/^subj:/i } map {split /[\s,]+/} ref($exclude)?@{$exclude}:$exclude));
523 # my $vismindays = ($mindays == 0 ? "" : $mindays);
524 # my $vismaxdays = ($maxdays == -1 ? "" : $maxdays);
525
526 # my $sel_rmy = ($param{repeatmerged} ? " selected" : "");
527 # my $sel_rmn = ($param{repeatmerged} ? "" : " selected");
528 # my $sel_ordraw = ($ordering eq "raw" ? " selected" : "");
529 # my $sel_ordold = ($ordering eq "oldview" ? " selected" : "");
530 # my $sel_ordnor = ($ordering eq "normal" ? " selected" : "");
531 # my $sel_ordage = ($ordering eq "age" ? " selected" : "");
532
533 # my $chk_bugrev = ($bug_rev ? " checked" : "");
534 # my $chk_pendrev = ($pend_rev ? " checked" : "");
535 # my $chk_sevrev = ($sev_rev ? " checked" : "");
536
537 # print <<EOF;
538 # <tr><td>Only include bugs tagged with </td><td><input name=include value="$includetags"> or that have <input name=includesubj value="$includesubj"> in their subject</td></tr>
539 # <tr><td>Exclude bugs tagged with </td><td><input name=exclude value="$excludetags"> or that have <input name=excludesubj value="$excludesubj"> in their subject</td></tr>
540 # <tr><td>Only show bugs older than</td><td><input name=mindays value="$vismindays" size=5> days, and younger than <input name=maxdays value="$vismaxdays" size=5> days</td></tr>
541
542 # <tr><td>&nbsp;</td></tr>
543
544 # <tr><td>Merged bugs should be</td><td>
545 # <select name=repeatmerged>
546 # <option value=yes$sel_rmy>displayed separately</option>
547 # <option value=no$sel_rmn>combined</option>
548 # </select>
549 # <tr><td>Categorise bugs by</td><td>
550 # <select name=ordering>
551 # <option value=raw$sel_ordraw>bug number only</option>
552 # <option value=old$sel_ordold>status and severity</option>
553 # <option value=normal$sel_ordnor>status, severity and classification</option>
554 # <option value=age$sel_ordage>status, severity, classification, and age</option>
555 # EOF
556
557 # {
558 # my $any = 0;
559 # my $o = $param{"ordering"} || "";
560 # for my $n (keys %cats) {
561 #     next if ($n eq "normal" || $n eq "oldview");
562 #     next if defined $hidden{$n};
563 #     unless ($any) {
564 #         $any = 1;
565 #       print "<option disabled>------</option>\n";
566 #     }
567 #     my @names = map { ref($_) eq "HASH" ? $_->{"nam"} : $_ } @{$cats{$n}};
568 #     my $name;
569 #     if (@names == 1) { $name = $names[0]; }
570 #     else { $name = " and " . pop(@names); $name = join(", ", @names) . $name; }
571
572 #     printf "<option value=\"%s\"%s>%s</option>\n",
573 #         $n, ($o eq $n ? " selected" : ""), $name;
574 # }
575 # }
576
577 # print "</select></td></tr>\n";
578
579 # printf "<tr><td>Order bugs by</td><td>%s</td></tr>\n",
580 #     pkg_htmlselectyesno("pend-rev", "outstanding bugs first", "done bugs first", $pend_rev);
581 # printf "<tr><td></td><td>%s</td></tr>\n",
582 #     pkg_htmlselectyesno("sev-rev", "highest severity first", "lowest severity first", $sev_rev);
583 # printf "<tr><td></td><td>%s</td></tr>\n",
584 #     pkg_htmlselectyesno("bug-rev", "oldest bugs first", "newest bugs first", $bug_rev);
585
586 # print <<EOF;
587 # <tr><td>&nbsp;</td></tr>
588 # <tr><td colspan=2><input value="Reload page" type="submit"> with new settings</td></tr>
589 # EOF
590
591 # print "</table></form></div>\n";
592
593 print "<hr>\n";
594 print fill_in_template(template=>'html/html_tail',
595                        hole_var => {'&strftime' => \&POSIX::strftime,
596                                    },
597                       );
598 print "</body></html>\n";
599