]> git.donarmstrong.com Git - debbugs.git/blob - cgi/bugreport.cgi
d114b1dff6cd0a88b6a140bd8c9e70f940918436
[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 .= ";\nKeywords: ".htmlsanit($status{keywords}) 
87                         if length($status{keywords});
88
89 my @merged= split(/ /,$status{mergedwith});
90 if (@merged) {
91         my $mseparator= ";\nmerged with ";
92         for my $m (@merged) {
93                 $indexentry .= $mseparator."<A href=\"" . bugurl($m) . "\">#$m</A>";
94                 $mseparator= ",\n";
95         }
96 }
97
98 my $dummy = strftime "%a, %e %b %Y %T UTC", localtime($status{date});
99 $submitted = ";\ndated ".$dummy;
100
101 if (length($status{done})) {
102         $indexentry .= ";\n<strong>Done:</strong> ".htmlsanit($status{done});
103 } elsif (length($status{forwarded})) {
104         $indexentry .= ";\n<strong>Forwarded</strong> to ".htmlsanit($status{forwarded});
105 }
106
107 my ($short, $tmaint);
108 $short = $ref; $short =~ s/^\d+/#$&/;
109 $tmaint = defined($maintainer{$tpack}) ? $maintainer{$tpack} : '(unknown)';
110 $descriptivehead= $indexentry.$submitted.";\nMaintainer for $status{package} is\n".
111             '<A href="http://'.$debbugs::gWebDomain.'/db/ma/l'.&maintencoded($tmaint).'.html">'.htmlsanit($tmaint).'</A>.';
112
113 my $buglog = buglog($ref);
114 open L, "<$buglog" or &quit("open log for $ref: $!");
115
116 my $log='';
117
118 my $xmessage = 1;
119 my $suppressnext = 0;
120
121 my $this = '';
122
123 my $cmsg = 1;
124
125 my $normstate= 'kill-init';
126 my $linenum = 0;
127 while(my $line = <L>) {
128         $linenum++;
129         if ($line =~ m/^.$/ and 1 <= ord($line) && ord($line) <= 7) {
130                 # state transitions
131                 my $newstate;
132                 my $statenum = ord($line);
133
134                 $newstate = 'autocheck'     if ($statenum == 1);
135                 $newstate = 'recips'        if ($statenum == 2);
136                 $newstate = 'kill-end'      if ($statenum == 3);
137                 $newstate = 'go'            if ($statenum == 5);
138                 $newstate = 'html'          if ($statenum == 6);
139                 $newstate = 'incoming-recv' if ($statenum == 7);
140
141                 # disallowed transitions:
142                 $_ = "$normstate $newstate";
143                 unless (m/^(go|go-nox|html) kill-end$/
144                     || m/^(kill-init|kill-end) (incoming-recv|autocheck|recips|html)$/
145                     || m/^kill-body go$/)
146                 {
147                         &quit("$ref: Transition from $normstate to $newstate at $linenum disallowed");
148                 }
149
150                 if ($newstate eq 'go') {
151                         $this .= "<pre>\n";
152                 }
153
154                 if ($newstate eq 'html') {
155                         $this = '';
156                 }
157
158                 if ($newstate eq 'kill-end') {
159
160                         $this .= "</pre>\n"
161                                 if $normstate eq 'go' || $normstate eq 'go-nox';
162
163                         if ($normstate eq 'html') {
164                                 $this .= "  <em><A href=\"" . bugurl($ref, "msg=$xmessage") . "\">Full text</A> available.</em>";
165                         }
166
167                         my $show = 1;
168                         $show = $boring
169                                 if ($suppressnext && $normstate ne 'html');
170
171                         $show = ($xmessage == $msg) if ($msg);
172
173                         if ($show) {
174                                 if ($reverse) {
175                                         $log = "$this\n<hr>$log";
176                                 } else {
177                                         $log .= "$this\n<hr>\n";
178                                 }
179                         }
180
181                         $xmessage++ if ($normstate ne 'html');
182
183                         $suppressnext = $normstate eq 'html';
184                 }
185                 
186                 $normstate = $newstate;
187                 next;
188         }
189
190         $_ = $line;
191         if ($normstate eq 'incoming-recv') {
192                 my $pl= $_;
193                 $pl =~ s/\n+$//;
194                 m/^Received: \(at (\S+)\) by (\S+)\;/
195                         || &quit("bad line \`$pl' in state incoming-recv");
196                 $this = "<h2>Message received at ".htmlsanit("$1\@$2")
197                         . ":</h2><br>\n<pre>\n$_";
198                 $normstate= 'go';
199         } elsif ($normstate eq 'html') {
200                 $this .= $_;
201         } elsif ($normstate eq 'go') {
202                 $this .= htmlsanit($_);
203         } elsif ($normstate eq 'go-nox') {
204                 next if !s/^X//;
205                 $this .= htmlsanit($_);
206         } elsif ($normstate eq 'recips') {
207                 if (m/^-t$/) {
208                         $this = "<h2>Message sent:</h2><br>\n";
209                 } else {
210                         s/\04/, /g; s/\n$//;
211                         $this = "<h2>Message sent to ".htmlsanit($_).":</h2><br>\n";
212                 }
213                 $normstate= 'kill-body';
214         } elsif ($normstate eq 'autocheck') {
215                 next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
216                 $normstate= 'autowait';
217                 $this = "<h2>Message received at $2:</h2><br>\n";
218         } elsif ($normstate eq 'autowait') {
219                 next if !m/^$/;
220                 $normstate= 'go-nox';
221                 $this .= "<pre>\n";
222         } else {
223                 &quit("$ref state $normstate line \`$_'");
224         }
225 }
226 &quit("$ref state $normstate at end") unless $normstate eq 'kill-end';
227 close(L);
228
229 print "Content-Type: text/html\n\n";
230
231 print "<HTML><HEAD><TITLE>\n" . 
232     "$debbugs::gProject $debbugs::gBug report logs - $short\n" .
233     "</TITLE></HEAD>\n" .
234     '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
235     "\n";
236 print "<H1>" .  "$debbugs::gProject $debbugs::gBug report logs -  $short" .
237       "<BR>" . htmlsanit($status{subject}) . "</H1>\n";
238
239 print "$descriptivehead\n";
240 print "<HR>";
241 print "$log";
242 print $tail_html;
243
244 print "</BODY></HTML>\n";
245
246 exit 0;