4 use Fcntl qw/O_RDONLY/;
6 my $common_archive = 0;
7 my $common_repeatmerged = 1;
8 my %common_include = ();
9 my %common_exclude = ();
15 if ($opt eq "archive") { $common_archive = $val; }
16 if ($opt eq "repeatmerged") { $common_repeatmerged = $val; }
17 if ($opt eq "exclude") { %common_exclude = %{$val}; }
18 if ($opt eq "include") { %common_include = %{$val}; }
22 my ($in, $key, $val, %ret);
23 if (defined $ENV{"QUERY_STRING"} && $ENV{"QUERY_STRING"} ne "") {
24 $in=$ENV{QUERY_STRING};
25 } elsif(defined $ENV{"REQUEST_METHOD"}
26 && $ENV{"REQUEST_METHOD"} eq "POST")
28 read(STDIN,$in,$ENV{CONTENT_LENGTH});
32 foreach (split(/&/,$in)) {
34 ($key, $val) = split(/=/,$_,2);
35 $key=~s/%(..)/pack("c",hex($1))/ge;
36 $val=~s/%(..)/pack("c",hex($1))/ge;
39 $debug = 1 if (defined $ret{"debug"} && $ret{"debug"} eq "aj");
45 print "Content-Type: text/html\n\n";
46 print "<HTML><HEAD><TITLE>Error</TITLE></HEAD><BODY>\n";
47 print "An error occurred. Dammit.\n";
48 print "Error was: $msg.\n";
49 print "</BODY></HTML>\n";
55 # my $Archive = $common_archive ? "archive" : "";
56 # print header . start_html("Sorry");
57 # print "Sorry bug #$msg doesn't seem to be in the $Archive database.\n";
64 my %status = getbugstatus($ref);
65 return htmlindexentrystatus(%status) if (%status);
69 sub htmlindexentrystatus {
75 if ($status{severity} eq 'normal') {
77 } elsif (grep($status{severity} eq $_, @debbugs::gStrongSeverities)) {
78 $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
80 $showseverity = "Severity: <em>$status{severity}</em>;\n";
83 $result .= "Package: <a href=\"" . pkgurl($status{"package"}) . "\">"
84 . "<strong>" . htmlsanit($status{"package"}) . "</strong></a>;\n"
85 if (length($status{"package"}));
86 $result .= $showseverity;
87 $result .= "Reported by: " . htmlsanit($status{originator});
88 $result .= ";\nTags: <strong>"
89 . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
91 if (length($status{tags}));
93 my @merged= split(/ /,$status{mergedwith});
94 my $mseparator= ";\nmerged with ";
96 $result .= $mseparator."<A href=\"" . bugurl($m) . "\">#$m</A>";
100 if (length($status{done})) {
101 $result .= ";\n<strong>Done:</strong> " . htmlsanit($status{done});
102 } elsif (length($status{forwarded})) {
103 $result .= ";\n<strong>Forwarded</strong> to "
104 . htmlsanit($status{forwarded});
106 my $daysold = int((time - $status{date}) / 86400); # seconds to days
110 $font = "em" if ($daysold > 30);
111 $font = "strong" if ($daysold > 60);
112 $efont = "</$font>" if ($font);
113 $font = "<$font>" if ($font);
115 my $yearsold = int($daysold / 364);
116 $daysold = $daysold - $yearsold * 364;
118 $result .= ";\n $font";
119 $result .= "1 year and " if ($yearsold == 1);
120 $result .= "$yearsold years and " if ($yearsold > 1);
121 $result .= "1 day old" if ($daysold == 1);
122 $result .= "$daysold days old" if ($daysold != 1);
133 my $ref = shift || "";
134 my $params = "submitter=" . emailfromrfc822($ref);
135 $params .= "&archive=yes" if ($common_archive);
136 $params .= "&repeatmerged=yes" if ($common_repeatmerged);
137 return urlsanit($debbugs::gCGIDomain . "pkgreport.cgi" . "?" . $params);
141 my $ref = shift || "";
142 my $params = "maint=" . emailfromrfc822($ref);
143 $params .= "&archive=yes" if ($common_archive);
144 $params .= "&repeatmerged=yes" if ($common_repeatmerged);
145 return urlsanit($debbugs::gCGIDomain . "pkgreport.cgi" . "?" . $params);
150 my $params = "pkg=$ref";
151 $params .= "&archive=yes" if ($common_archive);
152 $params .= "&repeatmerged=yes" if ($common_repeatmerged);
154 return urlsanit($debbugs::gCGIDomain . "pkgreport.cgi" . "?" . "$params");
165 my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
166 my $in = shift || "";
168 while ($in =~ m/[<>&"]/) {
169 $out .= $`. '&'. $saniarray{$&}. ';';
178 my $params = "bug=$ref";
179 foreach my $val (@_) {
180 $params .= "\&msg=$1" if ($val =~ /^msg=([0-9]+)/);
181 $params .= "\&archive=yes" if (!$common_archive && $val =~ /^archive.*$/);
183 $params .= "&archive=yes" if ($common_archive);
184 $params .= "&repeatmerged=yes" if ($common_repeatmerged);
186 return $debbugs::gCGIDomain . "bugreport.cgi" . "?" . "$params";
191 return $debbugs::gCGIDomain . "package.cgi" . "?" . "package=$ref";
197 opendir(D, "$debbugs::gSpoolDir/db") or &quit("opendir db: $!");
198 @bugs = sort {$a<=>$b} grep s/\.status$//,
199 (grep m/^[0-9]+\.status$/,
211 my %displayshowpending = ("pending", "outstanding",
213 "forwarded", "forwarded to upstream software authors");
216 return "<HR><H2>No reports found!</H2></HR>\n";
219 foreach my $bug (sort {$a<=>$b} @bugs) {
220 my %status = getbugstatus($bug);
222 my @merged = sort {$a<=>$b} ($bug, split(/ /, $status{mergedwith}));
223 next unless ($common_repeatmerged || $bug == $merged[0]);
224 if (%common_include) {
226 foreach my $t (split /\s+/, $status{tags}) {
227 $okay = 1, last if (defined $common_include{$t});
229 if (defined $common_include{subj}) {
230 if (index($status{subject}, $common_include{subj}) > -1) {
236 if (%common_exclude) {
238 foreach my $t (split /\s+/, $status{tags}) {
239 $okay = 0, last if (defined $comon_exclude{$t});
241 if (defined $common_exclude{subj}) {
242 if (index($status{subject}, $common_exclude{subj}) > -1) {
249 $section{$status{pending} . "_" . $status{severity}} .=
250 sprintf "<li><a href=\"%s\">#%d: %s</a>\n<br>",
251 bugurl($bug), $bug, htmlsanit($status{subject});
252 $section{$status{pending} . "_" . $status{severity}} .=
253 htmlindexentrystatus(\%status) . "\n";
258 foreach my $pending (qw(pending forwarded done)) {
259 foreach my $severity(@debbugs::gSeverityList) {
260 $severity = $debbugs::gDefaultSeverity if ($severity eq '');
261 next unless defined $section{${pending} . "_" . ${severity}};
262 $result .= "<HR><H2>$debbugs::gSeverityDisplay{$severity} - $displayshowpending{$pending}</H2>\n";
263 $result .= "(A list of <a href=\"http://${debbugs::gWebDomain}/db/si/$pending$severity\">all such bugs</a> is available).\n";
265 $result .= $section{$pending . "_" . $severity};
266 $result .= "</UL>\n";
267 $anydone = 1 if ($pending eq "done");
271 $result .= $debbugs::gHTMLExpireNote if ($anydone);
277 if ($common_archive) {
278 open I, "<$debbugs::gSpoolDir/index.archive" or &quit("bugindex: $!");
280 open I, "<$debbugs::gSpoolDir/index.db" or &quit("bugindex: $!");
286 if (m/^(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+\[\s*([^]]*)\s*\]\s+(\w+)\s+(.*)$/) {
287 my $x = $bugfunc->(pkg => $1, bug => $2, status => $4,
288 submitter => $5, severity => $6, tags => $7);
302 if (!$common_archive && defined $opt &&
303 -e "$debbugs::gSpoolDir/by-$opt.idx")
306 print STDERR "optimized\n" if ($debug);
307 tie %lookup, DB_File => "$debbugs::gSpoolDir/by-$opt.idx", O_RDONLY
308 or die "$0: can't open $debbugs::gSpoolDir/by-$opt.idx ($!)\n";
309 while ($key = shift) {
310 my $bugs = $lookup{$key};
312 push @result, (unpack 'N*', $bugs);
316 print STDERR "done optimized\n" if ($debug);
318 if ( $common_archive ) {
319 open I, "<$debbugs::gSpoolDir/index.archive"
320 or &quit("bugindex: $!");
322 open I, "<$debbugs::gSpoolDir/index.db"
323 or &quit("bugindex: $!");
326 if (m/^(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+\[\s*([^]]*)\s*\]\s+(\w+)\s+(.*)$/) {
327 if ($bugfunc->(pkg => $1, bug => $2, status => $4,
328 submitter => $5, severity => $6, tags => $7))
336 return sort {$a <=> $b} @result;
339 sub emailfromrfc822 {
341 $email =~ s/\s*\(.*\)\s*//;
342 $email = $1 if ($email =~ m/<(.*)>/);
350 while ($input =~ m/\W/) {
351 $encoded.=$`.sprintf("-%02x_",unpack("C",$&));
356 $encoded =~ s/-2e_/\./g;
357 $encoded =~ s/^([^,]+)-20_-3c_(.*)-40_(.*)-3e_/$1,$2,$3,/;
358 $encoded =~ s/^(.*)-40_(.*)-20_-28_([^,]+)-29_$/,$1,$2,$3/;
359 $encoded =~ s/-20_/_/g;
360 $encoded =~ s/-([^_]+)_-/-$1/g;
367 open(MM,"$gMaintainerFile") or &quit("open $gMaintainerFile: $!");
369 next unless m/^(\S+)\s+(\S.*\S)\s*$/;
384 unless (open(S,"$gSpoolDir/db/$bugnum.status")) {
385 my $archdir = sprintf "%02d", $bugnum % 100;
386 open(S,"$gSpoolDir/archive/$archdir/$bugnum.status" ) or return ();
388 my @lines = qw(originator date subject msgid package tags done
389 forwarded mergedwith severity);
392 $status{shift @lines} = $_;
395 $status{shift @lines} = '' while(@lines);
397 $status{"package"} =~ s/\s*$//;
398 $status{"package"} = 'unknown' if ($status{"package"} eq '');
399 $status{"severity"} = 'normal' if ($status{"severity"} eq '');
401 $status{"pending"} = 'pending';
402 $status{"pending"} = 'forwarded' if (length($status{"forwarded"}));
403 $status{"pending"} = 'done' if (length($status{"done"}));
412 $res = "$gSpoolDir/db/$bugnum.log";
413 return $res if ( -e $res );
415 my $archdir = sprintf "%02d", $bugnum % 100;
416 $res = "$gSpoolDir/archive/$archdir/$bugnum.log";
417 return $res if ( -e $res );