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