4 use Fcntl qw/O_RDONLY/;
6 $config_path = '/etc/debbugs';
7 $lib_path = '/usr/lib/debbugs';
8 require "$lib_path/errorlib";
10 my $common_archive = 0;
11 my $common_repeatmerged = 1;
12 my %common_include = ();
13 my %common_exclude = ();
14 my $common_raw_sort = 0;
15 my $common_bug_reverse = 0;
16 my $common_pending_reverse = 0;
17 my $common_severity_reverse = 0;
19 my @common_pending_include = ();
20 my @common_pending_exclude = ();
21 my @common_severity_include = ();
22 my @common_severity_exclude = ();
28 if ($opt eq "archive") { $common_archive = $val; }
29 if ($opt eq "repeatmerged") { $common_repeatmerged = $val; }
30 if ($opt eq "exclude") {
32 @vals = ( $val ) if (ref($val) eq "" && $val );
33 @vals = ( $$val ) if (ref($val) eq "SCALAR" && $$val );
34 @vals = @{$val} if (ref($val) eq "ARRAY" );
35 %common_exclude = map {
36 if (/^(.*):(.*)$/) { ($1, $2) } else { ($_, 1) }
37 } split /[\s,]+/, join ',', @vals;
39 if ($opt eq "include") {
41 @vals = ( $val, ) if (ref($val) eq "" && $val );
42 @vals = ( $$val, ) if (ref($val) eq "SCALAR" && $$val );
43 @vals = @{$val} if (ref($val) eq "ARRAY" );
44 %common_include = map {
45 if (/^(.*):(.*)$/) { ($1, $2) } else { ($_, 1) }
46 } split /[\s,]+/, join ',', @vals;
48 if ($opt eq "raw") { $common_raw_sort = $val; }
49 if ($opt eq "bug-rev") { $common_bug_reverse = $val; }
50 if ($opt eq "pend-rev") { $common_pending_reverse = $val; }
51 if ($opt eq "sev-rev") { $common_severity_reverse = $val; }
52 if ($opt eq "pend-exc") {
54 @vals = ( $val ) if (ref($val) eq "" && $val );
55 @vals = ( $$val ) if (ref($val) eq "SCALAR" && $$val );
56 @vals = @{$val} if (ref($val) eq "ARRAY" );
57 @common_pending_exclude = @vals if (@vals);
59 if ($opt eq "pend-inc") {
61 @vals = ( $val, ) if (ref($val) eq "" && $val );
62 @vals = ( $$val, ) if (ref($val) eq "SCALAR" && $$val );
63 @vals = @{$val} if (ref($val) eq "ARRAY" );
64 @common_pending_include = @vals if (@vals);
66 if ($opt eq "sev-exc") {
68 @vals = ( $val ) if (ref($val) eq "" && $val );
69 @vals = ( $$val ) if (ref($val) eq "SCALAR" && $$val );
70 @vals = @{$val} if (ref($val) eq "ARRAY" );
71 @common_severity_exclude = @vals if (@vals);
73 if ($opt eq "sev-inc") {
75 @vals = ( $val ) if (ref($val) eq "" && $val );
76 @vals = ( $$val ) if (ref($val) eq "SCALAR" && $$val );
77 @vals = @{$val} if (ref($val) eq "ARRAY" );
78 @common_severity_include = @vals if (@vals);
83 my ($in, $key, $val, %ret);
84 if (defined $ENV{"QUERY_STRING"} && $ENV{"QUERY_STRING"} ne "") {
85 $in=$ENV{QUERY_STRING};
86 } elsif(defined $ENV{"REQUEST_METHOD"}
87 && $ENV{"REQUEST_METHOD"} eq "POST")
89 read(STDIN,$in,$ENV{CONTENT_LENGTH});
93 foreach (split(/[&;]/,$in)) {
95 ($key, $val) = split(/=/,$_,2);
96 $key=~s/%(..)/pack("c",hex($1))/ge;
97 $val=~s/%(..)/pack("c",hex($1))/ge;
98 if ( exists $ret{$key} ) {
99 if ( !exists $ret{"&$key"} ) {
100 $ret{"&$key"} = [ $ret{$key} ];
102 push @{$ret{"&$key"}},$val;
106 $debug = 1 if (defined $ret{"debug"} && $ret{"debug"} eq "aj");
112 print "Content-Type: text/html\n\n";
113 print "<HTML><HEAD><TITLE>Error</TITLE></HEAD><BODY>\n";
114 print "An error occurred. Dammit.\n";
115 print "Error was: $msg.\n";
116 print "</BODY></HTML>\n";
122 # my $Archive = $common_archive ? "archive" : "";
123 # print header . start_html("Sorry");
124 # print "Sorry bug #$msg doesn't seem to be in the $Archive database.\n";
129 # Split a package string from the status file into a list of package names.
132 return unless defined $pkgs;
133 return map lc, split /[ \t?,()]+/, $pkgs;
139 return () unless defined $addr;
140 return @{$_parsedaddrs{$addr}} if exists $_parsedaddrs{$addr};
141 @{$_parsedaddrs{$addr}} = Mail::Address->parse($addr);
142 return @{$_parsedaddrs{$addr}};
145 # Generate a comma-separated list of HTML links to each package given in
146 # $pkgs. $pkgs may be empty, in which case an empty string is returned, or
147 # it may be a comma-separated list of package names.
148 sub htmlpackagelinks {
150 return unless defined $pkgs and $pkgs ne '';
152 my @pkglist = splitpackages($pkgs);
154 my $openstrong = $strong ? '<strong>' : '';
155 my $closestrong = $strong ? '</strong>' : '';
157 return 'Package' . (@pkglist > 1 ? 's' : '') . ': ' .
160 '<a href="' . pkgurl($_) . '">' .
161 $openstrong . htmlsanit($_) . $closestrong . '</a>'
166 # Generate a comma-separated list of HTML links to each maintainer given in
167 # $maints, which should be a comma-separated list of RFC822 addresses.
169 my ($prefixfunc, $maints) = @_;
170 if (defined $maints and $maints ne '') {
171 my @maintaddrs = getparsedaddrs($maints);
172 my $prefix = (ref $prefixfunc) ? $prefixfunc->(scalar @maintaddrs)
175 join ', ', map { sprintf '<a href="%s">%s</a>',
176 mainturl($_->address),
177 htmlsanit($_->format) || '(unknown)'
180 my $prefix = (ref $prefixfunc) ? $prefixfunc->(1) : $prefixfunc;
181 return sprintf '%s<a href="%s">(unknown)</a>', $prefix, mainturl('');
187 my %status = %{getbugstatus($ref)};
188 return htmlindexentrystatus(%status) if (%status);
192 sub htmlindexentrystatus {
198 if ($status{severity} eq 'normal') {
200 } elsif (grep($status{severity} eq $_, @debbugs::gStrongSeverities)) {
201 $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
203 $showseverity = "Severity: <em>$status{severity}</em>;\n";
206 $result .= htmlpackagelinks($status{"package"}, 1);
207 $result .= $showseverity;
208 $result .= "Reported by: <a href=\"" . submitterurl($status{originator})
209 . "\">" . htmlsanit($status{originator}) . "</a>";
210 $result .= ";\nTags: <strong>"
211 . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
213 if (length($status{tags}));
215 my @merged= split(/ /,$status{mergedwith});
216 my $mseparator= ";\nmerged with ";
217 for my $m (@merged) {
218 $result .= $mseparator."<A href=\"" . bugurl($m) . "\">#$m</A>";
222 if (length($status{done})) {
223 $result .= ";\n<strong>Done:</strong> " . htmlsanit($status{done});
225 if (length($status{forwarded})) {
226 $result .= ";\n<strong>Forwarded</strong> to "
227 . maybelink($status{forwarded});
229 my $daysold = int((time - $status{date}) / 86400); # seconds to days
233 $font = "em" if ($daysold > 30);
234 $font = "strong" if ($daysold > 60);
235 $efont = "</$font>" if ($font);
236 $font = "<$font>" if ($font);
238 my $yearsold = int($daysold / 365);
239 $daysold -= $yearsold * 365;
241 $result .= ";\n $font";
243 push @age, "1 year" if ($yearsold == 1);
244 push @age, "$yearsold years" if ($yearsold > 1);
245 push @age, "1 day" if ($daysold == 1);
246 push @age, "$daysold days" if ($daysold > 1);
247 $result .= join(" and ", @age);
248 $result .= " old$efont";
258 my $ref = shift || "";
259 my $params = "submitter=" . emailfromrfc822($ref);
260 $params .= "&archive=yes" if ($common_archive);
261 $params .= "&repeatmerged=no" unless ($common_repeatmerged);
262 return urlsanit("pkgreport.cgi" . "?" . $params);
266 my $ref = shift || "";
267 my $params = "maint=" . emailfromrfc822($ref);
268 $params .= "&archive=yes" if ($common_archive);
269 $params .= "&repeatmerged=no" unless ($common_repeatmerged);
270 return urlsanit("pkgreport.cgi" . "?" . $params);
275 my $params = "pkg=$ref";
276 $params .= "&archive=yes" if ($common_archive);
277 $params .= "&repeatmerged=no" unless ($common_repeatmerged);
279 return urlsanit("pkgreport.cgi" . "?" . "$params");
284 my $params = "src=$ref";
285 $params .= "&archive=yes" if ($common_archive);
286 $params .= "&repeatmerged=no" unless ($common_repeatmerged);
287 return urlsanit("pkgreport.cgi" . "?" . "$params");
294 my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
295 $url =~ s/([<>&"])/\&$saniarray{$1};/g;
300 my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
301 my $in = shift || "";
302 $in =~ s/([<>&"])/\&$saniarray{$1};/g;
308 if ($in =~ /^[a-zA-Z0-9+.-]+:/) { # RFC 1738 scheme
309 return qq{<a href="$in">} . htmlsanit($in) . '</a>';
311 return htmlsanit($in);
317 my $params = "bug=$ref";
318 foreach my $val (@_) {
319 $params .= "\&msg=$1" if ($val =~ /^msg=([0-9]+)/);
320 $params .= "\&archive=yes" if (!$common_archive && $val =~ /^archive.*$/);
322 $params .= "&archive=yes" if ($common_archive);
323 $params .= "&repeatmerged=no" unless ($common_repeatmerged);
325 return urlsanit("bugreport.cgi" . "?" . "$params");
330 my $params = "bug=$ref";
332 foreach my $val (@_) {
333 $params .= "\&$1=$2" if ($val =~ /^(msg|att)=([0-9]+)/);
334 $filename = $1 if ($val =~ /^filename=(.*)$/);
336 $params .= "&archive=yes" if ($common_archive);
338 $pathinfo = "/$filename" if $filename ne '';
340 return urlsanit("bugreport.cgi$pathinfo?$params");
345 return urlsanit("bugreport.cgi" . "?" . "bug=$ref&mbox=yes");
349 return @{getbugs(sub { 1 })};
359 my %displayshowpending = ("pending", "outstanding",
360 "pending-fixed", "pending upload",
361 "fixed", "fixed in NMU",
363 "forwarded", "forwarded to upstream software authors");
366 return "<HR><H2>No reports found!</H2></HR>\n";
369 if ( $common_bug_reverse ) {
370 @bugs = sort {$b<=>$a} @bugs;
372 @bugs = sort {$a<=>$b} @bugs;
375 foreach my $bug (@bugs) {
376 my %status = %{getbugstatus($bug)};
378 if (%common_include) {
380 foreach my $t (split /\s+/, $status{tags}) {
381 $okay = 1, last if (defined $common_include{$t});
383 if (defined $common_include{subj}) {
384 if (index($status{subject}, $common_include{subj}) > -1) {
390 if (%common_exclude) {
392 foreach my $t (split /\s+/, $status{tags}) {
393 $okay = 0, last if (defined $common_exclude{$t});
395 if (defined $common_exclude{subj}) {
396 if (index($status{subject}, $common_exclude{subj}) > -1) {
402 next if @common_pending_include and
403 not grep { $_ eq $status{pending} } @common_pending_include;
404 next if @common_severity_include and
405 not grep { $_ eq $status{severity} } @common_severity_include;
406 next if grep { $_ eq $status{pending} } @common_pending_exclude;
407 next if grep { $_ eq $status{severity} } @common_severity_exclude;
409 my @merged = sort {$a<=>$b} ($bug, split(/ /, $status{mergedwith}));
410 next unless ($common_repeatmerged || !$seenmerged{$merged[0]});
411 $seenmerged{$merged[0]} = 1;
413 my $html = sprintf "<li><a href=\"%s\">#%d: %s</a>\n<br>",
414 bugurl($bug), $bug, htmlsanit($status{subject});
415 $html .= htmlindexentrystatus(\%status) . "\n";
416 $section{$status{pending} . "_" . $status{severity}} .= $html;
417 push @rawsort, $html if $common_raw_sort;
422 if ($common_raw_sort) {
423 $result .= "<UL>\n" . join("", @rawsort ) . "</UL>\n";
425 my @pendingList = qw(pending forwarded pending-fixed fixed done);
426 @pendingList = reverse @pendingList if $common_pending_reverse;
427 #print STDERR join(",",@pendingList)."\n";
428 #print STDERR join(",",@common_pending_include).":$#common_pending_include\n";
429 foreach my $pending (@pendingList) {
430 my @severityList = @debbugs::gSeverityList;
431 @severityList = reverse @severityList if $common_severity_reverse;
432 #print STDERR join(",",@severityList)."\n";
434 # foreach my $severity(@debbugs::gSeverityList) {
435 foreach my $severity(@severityList) {
436 $severity = $debbugs::gDefaultSeverity if ($severity eq '');
437 next unless defined $section{${pending} . "_" . ${severity}};
438 $result .= "<HR><H2>$debbugs::gSeverityDisplay{$severity} - $displayshowpending{$pending}</H2>\n";
439 #$result .= "(A list of <a href=\"http://${debbugs::gWebDomain}/db/si/$pending$severity\">all such bugs</a> is available).\n";
440 #$result .= "(A list of all such bugs used to be available).\n";
442 $result .= $section{$pending . "_" . $severity};
443 $result .= "</UL>\n";
444 $anydone = 1 if ($pending eq "done");
449 $result .= $debbugs::gHTMLExpireNote if $gRemoveAge and $anydone;
455 if ($common_archive) {
456 open I, "<$debbugs::gSpoolDir/index.archive"
457 or &quitcgi("$debbugs::gSpoolDir/index.archive: $!");
459 open I, "<$debbugs::gSpoolDir/index.db"
460 or &quitcgi("$debbugs::gSpoolDir/index.db: $!");
466 if (m/^(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+\[\s*([^]]*)\s*\]\s+(\w+)\s+(.*)$/) {
467 my @x = $bugfunc->(pkg => $1, bug => $2, status => $4,
468 submitter => $5, severity => $6, tags => $7);
470 $count{$_}++ foreach @x;
483 if (!$common_archive && defined $opt &&
484 -e "$debbugs::gSpoolDir/by-$opt.idx")
487 print STDERR "optimized\n" if ($debug);
488 tie %lookup, DB_File => "$debbugs::gSpoolDir/by-$opt.idx", O_RDONLY
489 or die "$0: can't open $debbugs::gSpoolDir/by-$opt.idx ($!)\n";
490 while ($key = shift) {
491 my $bugs = $lookup{$key};
493 push @result, (unpack 'N*', $bugs);
497 print STDERR "done optimized\n" if ($debug);
499 if ( $common_archive ) {
500 open I, "<$debbugs::gSpoolDir/index.archive"
501 or &quitcgi("$debbugs::gSpoolDir/index.archive: $!");
503 open I, "<$debbugs::gSpoolDir/index.db"
504 or &quitcgi("$debbugs::gSpoolDir/index.db: $!");
507 if (m/^(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+\[\s*([^]]*)\s*\]\s+(\w+)\s+(.*)$/) {
508 if ($bugfunc->(pkg => $1, bug => $2, status => $4,
509 submitter => $5, severity => $6, tags => $7))
517 @result = sort {$a <=> $b} @result;
521 sub emailfromrfc822 {
523 $email =~ s/\s*\(.*\)\s*//;
524 $email = $1 if ($email =~ m/<(.*)>/);
532 while ($input =~ m/\W/) {
533 $encoded.=$`.sprintf("-%02x_",unpack("C",$&));
538 $encoded =~ s/-2e_/\./g;
539 $encoded =~ s/^([^,]+)-20_-3c_(.*)-40_(.*)-3e_/$1,$2,$3,/;
540 $encoded =~ s/^(.*)-40_(.*)-20_-28_([^,]+)-29_$/,$1,$2,$3/;
541 $encoded =~ s/-20_/_/g;
542 $encoded =~ s/-([^_]+)_-/-$1/g;
548 return $_maintainer if $_maintainer;
551 open(MM,"$gMaintainerFile") or &quitcgi("open $gMaintainerFile: $!");
553 next unless m/^(\S+)\s+(\S.*\S)\s*$/;
559 if (defined $gMaintainerFileOverride) {
560 open(MM,"$gMaintainerFileOverride") or &quitcgi("open $gMaintainerFileOverride: $!");
562 next unless m/^(\S+)\s+(\S.*\S)\s*$/;
569 $_maintainer = \%maintainer;
576 return $_pkgsrc if $_pkgsrc;
577 return {} unless defined $gPackageSource;
581 open(MM,"$gPackageSource") or &quitcgi("open $gPackageSource: $!");
583 next unless m/^(\S+)\s+(\S+)\s+(\S.*\S)\s*$/;
584 ($a,$b,$c)=($1,$2,$3);
587 $pkgcomponent{$a}= $b;
591 $_pkgcomponent = \%pkgcomponent;
595 sub getpkgcomponent {
596 return $_pkgcomponent if $_pkgcomponent;
598 return $_pkgcomponent;
603 return $_pseudodesc if $_pseudodesc;
606 open(PSEUDO, "< $gPseudoDescFile") or &quitcgi("open $gPseudoDescFile: $!");
608 next unless m/^(\S+)\s+(\S.*\S)\s*$/;
609 $pseudodesc{lc $1} = $2;
612 $_pseudodesc = \%pseudodesc;
621 my $location = getbuglocation( $bugnum, "status" );
622 return {} if ( !$location );
623 %status = %{ readbug( $bugnum, $location ) };
625 $status{tags} = $status{keywords};
627 $status{"package"} =~ s/\s*$//;
628 $status{"package"} = 'unknown' if ($status{"package"} eq '');
629 $status{"severity"} = 'normal' if ($status{"severity"} eq '');
631 $status{"pending"} = 'pending';
632 $status{"pending"} = 'forwarded' if (length($status{"forwarded"}));
633 $status{"pending"} = 'pending-fixed' if ($status{"tags"} =~ /\bpending\b/);
634 $status{"pending"} = 'fixed' if ($status{"tags"} =~ /\bfixed\b/);
635 $status{"pending"} = 'done' if (length($status{"done"}));
643 my %pkgsrc = %{getpkgsrc()};
645 foreach ( keys %pkgsrc ) {
646 push @pkgs, $_ if $pkgsrc{$_} eq $src;
653 my $location = getbuglocation($bugnum, 'log');
654 return getbugcomponent($bugnum, 'log', $location);