]> git.donarmstrong.com Git - debbugs.git/blob - cgi/bugreport.cgi
32491206437103638d4e3ec050ab099a1150378d
[debbugs.git] / cgi / bugreport.cgi
1 #!/usr/bin/perl -wT
2
3 package debbugs;
4
5 use strict;
6 use POSIX qw(strftime tzset);
7
8 #require '/usr/lib/debbugs/errorlib';
9 require '/usr/lib/debbugs/common.pl';
10 #require '/debian/home/ajt/newajbug/common.pl';
11
12 require '/etc/debbugs/config';
13 require '/etc/debbugs/text';
14
15 use vars(qw($gHTMLTail $gWebDomain));
16
17 sub readparse {
18         # Parse query string. I could use CGI.pm here, but it is 6 thousand
19         # lines long and very expensive. I want light-weight.
20         my ($in, $key, $val, %ret);
21         if (defined $ENV{"QUERY_STRING"} && $ENV{"QUERY_STRING"} ne "") {
22                 $in=$ENV{QUERY_STRING};
23         } elsif(defined $ENV{"REQUEST_METHOD"} 
24                 && $ENV{"REQUEST_METHOD"} eq "POST") 
25         {
26                 read(STDIN,$in,$ENV{CONTENT_LENGTH});
27         } else {
28                 return;
29         }
30         foreach (split(/&/,$in)) {
31                 s/\+/ /g;
32                 ($key, $val) = split(/=/,$_,2);
33                 $key=~s/%(..)/pack("c",hex($1))/ge;
34                 $val=~s/%(..)/pack("c",hex($1))/ge;
35                 $ret{$key}=$val;
36         }
37         return %ret;
38 }
39
40 my %param = readparse();
41
42 my $tail_html;
43
44 my %maintainer = getmaintainers();
45
46 my $ref = $param{'bug'} || quit("No bug number");
47 my $msg = $param{'msg'} || "";
48 my $boring = ($param{'boring'} || 'no') eq 'yes'; 
49 my $reverse = ($param{'reverse'} || 'no') eq 'yes';
50
51 my %status = getbugstatus($ref) or &quit("Couldn't get bug status: $!");
52
53 my $indexentry;
54 my $descriptivehead;
55 my $submitted;
56 my $showseverity;
57
58 my $tpack;
59 my $tmain;
60
61 $ENV{"TZ"} = 'UTC';
62 tzset();
63
64 my $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
65 $tail_html = $debbugs::gHTMLTail;
66 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
67
68 $|=1;
69
70 $tpack = lc $status{'package'};
71 $tpack =~ s/[^-+._a-z0-9()].*$//;
72
73 if  ($status{severity} eq 'normal') {
74         $showseverity = '';
75 #} elsif (grep($status{severity} eq $_, @strongseverities)) {
76 #       $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
77 } else {
78         $showseverity = "Severity: <em>$status{severity}</em>;\n";
79 }
80
81 $indexentry .= $showseverity;
82 $indexentry .= "Package: <A HREF=\"" . pkgurl($status{package}) . "\">"
83             .htmlsanit($status{package})."</A>;\n";
84
85 $indexentry .= ";Reported by: ".htmlsanit($status{originator});
86 $indexentry .= ";\nTags: <strong>"
87                 . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
88                 . "</strong>"
89                         if length($status{tags});
90
91 my @merged= split(/ /,$status{mergedwith});
92 if (@merged) {
93         my $mseparator= ";\nmerged with ";
94         for my $m (@merged) {
95                 $indexentry .= $mseparator."<A href=\"" . bugurl($m) . "\">#$m</A>";
96                 $mseparator= ",\n";
97         }
98 }
99
100 my $dummy = strftime "%a, %e %b %Y %T UTC", localtime($status{date});
101 $submitted = ";\ndated ".$dummy;
102
103 if (length($status{done})) {
104         $indexentry .= ";\n<strong>Done:</strong> ".htmlsanit($status{done});
105 } elsif (length($status{forwarded})) {
106         $indexentry .= ";\n<strong>Forwarded</strong> to ".htmlsanit($status{forwarded});
107 }
108
109 my ($short, $tmaint);
110 $short = $ref; $short =~ s/^\d+/#$&/;
111 $tmaint = defined($maintainer{$tpack}) ? $maintainer{$tpack} : '(unknown)';
112 $descriptivehead= $indexentry.$submitted.";\nMaintainer for $status{package} is\n".
113             '<A href="http://'.$debbugs::gWebDomain.'/db/ma/l'.&maintencoded($tmaint).'.html">'.htmlsanit($tmaint).'</A>.';
114
115 my $buglog = buglog($ref);
116 open L, "<$buglog" or &quit("open log for $ref: $!");
117
118 my $log='';
119
120 my $xmessage = 1;
121 my $suppressnext = 0;
122
123 my $this = '';
124
125 my $cmsg = 1;
126
127 my $normstate= 'kill-init';
128 my $linenum = 0;
129 while(my $line = <L>) {
130         $linenum++;
131         if ($line =~ m/^.$/ and 1 <= ord($line) && ord($line) <= 7) {
132                 # state transitions
133                 my $newstate;
134                 my $statenum = ord($line);
135
136                 $newstate = 'autocheck'     if ($statenum == 1);
137                 $newstate = 'recips'        if ($statenum == 2);
138                 $newstate = 'kill-end'      if ($statenum == 3);
139                 $newstate = 'go'            if ($statenum == 5);
140                 $newstate = 'html'          if ($statenum == 6);
141                 $newstate = 'incoming-recv' if ($statenum == 7);
142
143                 # disallowed transitions:
144                 $_ = "$normstate $newstate";
145                 unless (m/^(go|go-nox|html) kill-end$/
146                     || m/^(kill-init|kill-end) (incoming-recv|autocheck|recips|html)$/
147                     || m/^kill-body go$/)
148                 {
149                         &quit("$ref: Transition from $normstate to $newstate at $linenum disallowed");
150                 }
151
152                 if ($newstate eq 'go') {
153                         $this .= "<pre>\n";
154                 }
155
156                 if ($newstate eq 'html') {
157                         $this = '';
158                 }
159
160                 if ($newstate eq 'kill-end') {
161
162                         $this .= "</pre>\n"
163                                 if $normstate eq 'go' || $normstate eq 'go-nox';
164
165                         if ($normstate eq 'html') {
166                                 $this .= "  <em><A href=\"" . bugurl($ref, "msg=$xmessage") . "\">Full text</A> available.</em>";
167                         }
168
169                         my $show = 1;
170                         $show = $boring
171                                 if ($suppressnext && $normstate ne 'html');
172
173                         $show = ($xmessage == $msg) if ($msg);
174
175                         if ($show) {
176                                 if ($reverse) {
177                                         $log = "$this\n<hr>$log";
178                                 } else {
179                                         $log .= "$this\n<hr>\n";
180                                 }
181                         }
182
183                         $xmessage++ if ($normstate ne 'html');
184
185                         $suppressnext = $normstate eq 'html';
186                 }
187                 
188                 $normstate = $newstate;
189                 next;
190         }
191
192         $_ = $line;
193         if ($normstate eq 'incoming-recv') {
194                 my $pl= $_;
195                 $pl =~ s/\n+$//;
196                 m/^Received: \(at (\S+)\) by (\S+)\;/
197                         || &quit("bad line \`$pl' in state incoming-recv");
198                 $this = "<h2>Message received at ".htmlsanit("$1\@$2")
199                         . ":</h2><br>\n<pre>\n$_";
200                 $normstate= 'go';
201         } elsif ($normstate eq 'html') {
202                 $this .= $_;
203         } elsif ($normstate eq 'go') {
204                 $this .= htmlsanit($_);
205         } elsif ($normstate eq 'go-nox') {
206                 next if !s/^X//;
207                 $this .= htmlsanit($_);
208         } elsif ($normstate eq 'recips') {
209                 if (m/^-t$/) {
210                         $this = "<h2>Message sent:</h2><br>\n";
211                 } else {
212                         s/\04/, /g; s/\n$//;
213                         $this = "<h2>Message sent to ".htmlsanit($_).":</h2><br>\n";
214                 }
215                 $normstate= 'kill-body';
216         } elsif ($normstate eq 'autocheck') {
217                 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
218                 $normstate= 'autowait';
219                 $this = "<h2>Message received at $2:</h2><br>\n";
220         } elsif ($normstate eq 'autowait') {
221                 next if !m/^$/;
222                 $normstate= 'go-nox';
223                 $this .= "<pre>\n";
224         } else {
225                 &quit("$ref state $normstate line \`$_'");
226         }
227 }
228 &quit("$ref state $normstate at end") unless $normstate eq 'kill-end';
229 close(L);
230
231 print "Content-Type: text/html\n\n";
232
233 print "<HTML><HEAD><TITLE>\n" . 
234     "$debbugs::gProject $debbugs::gBug report logs - $short\n" .
235     "</TITLE></HEAD>\n" .
236     '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
237     "\n";
238 print "<H1>" .  "$debbugs::gProject $debbugs::gBug report logs -  $short" .
239       "<BR>" . htmlsanit($status{subject}) . "</H1>\n";
240
241 print "$descriptivehead\n";
242 print "<HR>";
243 print "$log";
244 print $tail_html;
245
246 print "</BODY></HTML>\n";
247
248 exit 0;