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