7 if (defined $ENV{REMOTE_ADDR} and $ENV{REMOTE_ADDR} =~ m/^(72\.17\.168\.57|60\.238\.143\.248|61\.224\.27\.141|146\.82\.138\.7|61\.214\.28\.119|84\.189\.46\.3|82\.124\.165\.25|220\.181\.26\.108|220\.95\.221\.\d+|82\.120\.77\.220|80\.68\.89\.71|66\.227\.249\.188|194\.46\.224\.153|66\.246\.72\.81|60\.42\.181\.163)$/) {
8 print "Content-Type: text/html\n\nGo away.";
13 use POSIX qw(strftime tzset);
19 #require '/usr/lib/debbugs/errorlib';
20 require './common.pl';
22 require '/etc/debbugs/config';
23 require '/etc/debbugs/text';
25 use vars(qw($gEmailDomain $gHTMLTail $gSpoolDir $gWebDomain));
27 # for read_log_records
29 use Debbugs::MIME qw(convert_to_utf8 decode_rfc1522);
31 use Scalar::Util qw(looks_like_number);
33 my %param = readparse();
37 my $ref = $param{'bug'} || quitcgi("No bug number");
38 $ref =~ /(\d+)/ or quitcgi("Invalid bug number");
41 my $msg = $param{'msg'} || "";
42 my $att = $param{'att'};
43 my $boring = ($param{'boring'} || 'no') eq 'yes';
44 my $terse = ($param{'terse'} || 'no') eq 'yes';
45 my $reverse = ($param{'reverse'} || 'no') eq 'yes';
46 my $mbox = ($param{'mbox'} || 'no') eq 'yes';
47 my $mime = ($param{'mime'} || 'yes') eq 'yes';
49 my $trim_headers = ($param{trim} || ($msg?'no':'yes')) eq 'yes';
51 # Not used by this script directly, but fetch these so that pkgurl() and
52 # friends can propagate them correctly.
53 my $archive = ($param{'archive'} || 'no') eq 'yes';
54 my $repeatmerged = ($param{'repeatmerged'} || 'yes') eq 'yes';
55 set_option('archive', $archive);
56 set_option('repeatmerged', $repeatmerged);
58 my $buglog = buglog($ref);
60 if (defined $ENV{REQUEST_METHOD} and $ENV{REQUEST_METHOD} eq 'HEAD' and not defined($att) and not $mbox) {
61 print "Content-Type: text/html; charset=utf-8\n";
62 my @stat = stat $buglog;
64 my $mtime = strftime '%a, %d %b %Y %T GMT', gmtime($stat[9]);
65 print "Last-Modified: $mtime\n";
71 sub display_entity ($$$$\$\@);
72 sub display_entity ($$$$\$\@) {
78 my $attachments = shift;
80 my $head = $entity->head;
81 my $disposition = $head->mime_attr('content-disposition');
82 $disposition = 'inline' if not defined $disposition or $disposition eq '';
83 my $type = $entity->effective_type;
84 my $filename = $entity->head->recommended_filename;
85 $filename = '' unless defined $filename;
86 $filename = decode_rfc1522($filename);
88 if ($top and not $terse) {
89 my $header = $entity->head;
90 $$this .= "<pre class=\"headers\">\n";
93 foreach (qw(From To Cc Subject Date)) {
94 my $head_field = $head->get($_);
95 next unless defined $head_field and $head_field ne '';
96 push @headers, qq(<b>$_:</b> ) . htmlsanit(decode_rfc1522($head_field));
98 $$this .= join(qq(), @headers) unless $terse;
100 $$this .= htmlsanit(decode_rfc1522($entity->head->stringify));
102 $$this .= "</pre>\n";
105 unless (($top and $type =~ m[^text(?:/plain)?(?:;|$)]) or
106 ($type =~ m[^multipart/])) {
107 push @$attachments, $entity;
108 my @dlargs = ($ref, "msg=$xmessage", "att=$#$attachments");
109 push @dlargs, "filename=$filename" if $filename ne '';
110 my $printname = $filename;
111 $printname = 'Message part ' . ($#$attachments + 1) if $filename eq '';
112 $$this .= '<pre class="mime">[<a href="' . bugurl(@dlargs) . qq{">$printname</a> } .
113 "($type, $disposition)]</pre>\n";
115 if ($msg and defined($att) and $att eq $#$attachments) {
116 my $head = $entity->head;
117 chomp(my $type = $entity->effective_type);
118 my $body = $entity->stringify_body;
119 print "Content-Type: $type";
120 my ($charset) = $head->get('Content-Type:') =~ m/charset\s*=\s*\"?([\w-]+)\"?/i;
121 print qq(; charset="$charset") if defined $charset;
123 if ($filename ne '') {
127 print qq{Content-Disposition: inline; filename="$qf"\n};
130 my $decoder = new MIME::Decoder($head->mime_encoding);
131 $decoder->decode(new IO::Scalar(\$body), \*STDOUT);
136 return if not $top and $disposition eq 'attachment' and not defined($att);
137 return unless ($type =~ m[^text/?] and
138 $type !~ m[^text/(?:html|enriched)(?:;|$)]) or
139 $type =~ m[^application/pgp(?:;|$)] or
142 if ($entity->is_multipart) {
143 my @parts = $entity->parts;
144 foreach my $part (@parts) {
145 display_entity($part, $ref, 0, $xmessage,
146 $$this, @$attachments);
149 } elsif ($entity->parts) {
150 # We must be dealing with a nested message.
151 $$this .= "<blockquote>\n";
152 my @parts = $entity->parts;
153 foreach my $part (@parts) {
154 display_entity($part, $ref, 1, $xmessage,
155 $$this, @$attachments);
158 $$this .= "</blockquote>\n";
161 my $content_type = $entity->head->get('Content-Type:') || "text/html";
162 my ($charset) = $content_type =~ m/charset\s*=\s*\"?([\w-]+)\"?/i;
163 my $body = $entity->bodyhandle->as_string;
164 $body = convert_to_utf8($body,$charset) if defined $charset;
165 $body = htmlsanit($body);
167 $body =~ s,((ftp|http|https)://[\S~-]+?/?)((\>\;)?[)]?[']?[:.\,]?(\s|$)),<a href=\"$1\">$1</a>$3,go;
168 # Add links to bug closures
169 $body =~ s[(closes:\s*(?:bug)?\#?\s?\d+(?:,?\s*(?:bug)?\#?\s?\d+)*)
170 ][my $temp = $1; $temp =~ s{(\d+)}{qq(<a href=").bugurl($1).qq(">$1</a>)}ge; $temp;]gxie;
171 $$this .= qq(<pre class="message">$body</pre>\n);
176 my %maintainer = %{getmaintainers()};
177 my %pkgsrc = %{getpkgsrc()};
188 my $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
189 $tail_html = $debbugs::gHTMLTail;
190 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
192 my %status = %{getbugstatus($ref)};
195 Content-Type: text/html; charset=utf-8
197 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
199 <head><title>$short - $debbugs::gProject $debbugs::gBug report logs</title></head>
201 <h1>$debbugs::gProject $debbugs::gBug report logs - $short</h1>
202 <p>There is no record of $debbugs::gBug $short.
203 Try the <a href="http://$gWebDomain/">search page</a> instead.</p>
204 $tail_html</body></html>
211 $tpack = lc $status{'package'};
212 my @tpacks = splitpackages($tpack);
214 if ($status{severity} eq 'normal') {
216 } elsif (isstrongseverity($status{severity})) {
217 $showseverity = "Severity: <em class=\"severity\">$status{severity}</em>;\n";
219 $showseverity = "Severity: $status{severity};\n";
222 $indexentry .= "<div class=\"msgreceived\">\n";
223 $indexentry .= htmlpackagelinks($status{package}, 0) . ";\n";
225 foreach my $pkg (@tpacks) {
226 my $tmaint = defined($maintainer{$pkg}) ? $maintainer{$pkg} : '(unknown)';
227 my $tsrc = defined($pkgsrc{$pkg}) ? $pkgsrc{$pkg} : '(unknown)';
230 htmlmaintlinks(sub { $_[0] == 1 ? "Maintainer for $pkg is\n"
231 : "Maintainers for $pkg are\n" },
233 $indexentry .= ";\nSource for $pkg is\n".
234 '<a href="'.srcurl($tsrc)."\">$tsrc</a>" if ($tsrc ne "(unknown)");
235 $indexentry .= ".\n";
238 $indexentry .= "<br>";
239 $indexentry .= htmladdresslinks("Reported by: ", \&submitterurl,
240 $status{originator}) . ";\n";
241 $indexentry .= sprintf "Date: %s.\n",
242 (strftime "%a, %e %b %Y %T UTC", localtime($status{date}));
244 $indexentry .= "<br>Owned by: " . htmlsanit($status{owner}) . ".\n"
245 if length $status{owner};
247 $indexentry .= "</div>\n";
251 $indexentry .= "<h3>$showseverity";
252 $indexentry .= sprintf "Tags: %s;\n",
253 htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
254 if length($status{tags});
255 $indexentry .= "<br>" if (length($showseverity) or length($status{tags}));
257 my @merged= split(/ /,$status{mergedwith});
259 my $descmerged = 'Merged with ';
261 for my $m (@merged) {
262 $descmerged .= $mseparator."<a href=\"" . bugurl($m) . "\">#$m</a>";
265 push @descstates, $descmerged;
268 if (@{$status{found_versions}}) {
269 my $foundtext = 'Found in ';
270 $foundtext .= (@{$status{found_versions}} == 1) ? 'version ' : 'versions ';
271 $foundtext .= join ', ', map htmlsanit($_), @{$status{found_versions}};
272 push @descstates, $foundtext;
275 if (@{$status{fixed_versions}}) {
276 my $fixedtext = '<strong>Fixed</strong> in ';
277 $fixedtext .= (@{$status{fixed_versions}} == 1) ? 'version ' : 'versions ';
278 $fixedtext .= join ', ', map htmlsanit($_), @{$status{fixed_versions}};
279 if (length($status{done})) {
280 $fixedtext .= ' by ' . htmlsanit(decode_rfc1522($status{done}));
282 push @descstates, $fixedtext;
283 } elsif (length($status{done})) {
284 push @descstates, "<strong>Done:</strong> ".htmlsanit(decode_rfc1522($status{done}));
285 } elsif (length($status{forwarded})) {
286 push @descstates, "<strong>Forwarded</strong> to ".maybelink($status{forwarded});
290 my @blockedby= split(/ /, $status{blockedby});
291 if (@blockedby && $status{"pending"} ne 'fixed' && ! length($status{done})) {
292 for my $b (@blockedby) {
293 my %s = %{getbugstatus($b)};
294 next if $s{"pending"} eq 'fixed' || length $s{done};
295 push @descstates, "Fix blocked by <a href=\"" . bugurl($b) . "\">#$b</a>: ".htmlsanit($s{subject});
299 my @blocks= split(/ /, $status{blocks});
300 if (@blocks && $status{"pending"} ne 'fixed' && ! length($status{done})) {
301 for my $b (@blocks) {
302 my %s = %{getbugstatus($b)};
303 next if $s{"pending"} eq 'fixed' || length $s{done};
304 push @descstates, "Blocking fix for <a href=\"" . bugurl($b) . "\">#$b</a>: ".htmlsanit($s{subject});
308 if ($buglog !~ m#^\Q$gSpoolDir/db#) {
309 push @descstates, "Bug is archived. No further changes may be made";
312 $indexentry .= join(";\n<br>", @descstates) . ".\n" if @descstates;
313 $indexentry .= "</h3>\n";
315 my $descriptivehead = $indexentry;
318 if ($buglog =~ m/\.gz$/) {
319 my $oldpath = $ENV{'PATH'};
320 $ENV{'PATH'} = '/bin:/usr/bin';
321 $buglogfh = new IO::File "zcat $buglog |" or &quitcgi("open log for $ref: $!");
322 $ENV{'PATH'} = $oldpath;
324 $buglogfh = new IO::File "<$buglog" or &quitcgi("open log for $ref: $!");
330 @records = read_log_records($buglogfh);
333 quitcgi("Bad bug log for $debbugs::gBug $ref. Unable to read records: $@");
337 =head2 handle_email_message
339 handle_email_message($record->{text},
341 msg_number => $msg_number,
344 Returns a decoded e-mail message and displays entities/attachments as
350 sub handle_email_message{
351 my ($email,%options) = @_;
354 my $parser = new MIME::Parser;
355 # Because we are using memory, not tempfiles, there's no need to
356 # clean up here like in Debbugs::MIME
357 $parser->tmp_to_core(1);
358 $parser->output_to_core(1);
359 my $entity = $parser->parse_data( $email);
360 my @attachments = ();
361 display_entity($entity, $options{ref}, 1, $options{msg_number}, $output, @attachments);
369 bug_links($starting_bug,$stoping_bugs,);
371 Creates a set of links to bugs, starting with bug number
372 $starting_bug, and finishing with $stoping_bug; if only one bug is
373 passed, makes a link to only a single bug.
375 The content of the link is the bug number.
380 my ($start,$stop,$query_arguments) = @_;
381 $stop = $stop || $start;
382 $query_arguments ||= '';
384 for my $bug ($start..$stop) {
385 push @output,'<a href="'.bugurl($bug,'').qq(">$bug</a>);
387 return join(', ',@output);
392 push @log, handle_record($record,$ref,$msg_num);
394 Deals with a record in a bug log as returned by
395 L<Debbugs::Log::read_log_records>; returns the log information that
396 should be output to the browser.
401 my ($record,$bug_number,$msg_number,$seen_msg_ids) = @_;
404 local $_ = $record->{type};
406 $output .= decode_rfc1522($record->{text});
407 # Link to forwarded http:// urls in the midst of the report
408 # (even though these links already exist at the top)
409 $output =~ s,((?:ftp|http|https)://[\S~-]+?/?)([\)\'\:\.\,]?(?:\s|\.<|$)),<a href=\"$1\">$1</a>$2,go;
410 # Add links to the cloned bugs
411 $output =~ s{(Bug )(\d+)( cloned as bugs? )(\d+)(?:\-(\d+)|)}{$1.bug_links($2).$3.bug_links($4,$5)}eo;
412 # Add links to merged bugs
413 $output =~ s{(?<=Merged )([\d\s]+)(?=\.)}{join(' ',map {bug_links($_)} (split /\s+/, $1))}eo;
414 # Add links to reassigned packages
415 $output =~ s{(Bug reassigned from package \`)([^\']+)(' to \`)([^\']+)(')}
416 {$1.q(<a href=").pkgurl($2).qq(">$2</a>).$3.q(<a href=").pkgurl($4).qq(">$4</a>).$5}eo;
417 $output .= '<a href="' . bugurl($ref, 'msg='.($msg_number+1)) . '">Full text</a> and <a href="' .
418 bugurl($ref, 'msg='.($msg_number+1), 'mbox') . '">rfc822 format</a> available.';
420 $output = "<div class=\"msgreceived\">\n" . $output . "</div>\n";
423 my ($msg_id) = $record->{text} =~ /^Message-Id:\s+<(.+)>/im;
424 if (defined $msg_id and exists $$seen_msg_ids{$msg_id}) {
427 elsif (defined $msg_id) {
428 $$seen_msg_ids{$msg_id} = 1;
430 $output .= 'View this message in <a href="' . bugurl($ref, "msg=$msg_number", "mbox") . '">rfc822 format</a>';
431 $output .= handle_email_message($record->{text},
433 msg_number => $msg_number,
436 elsif (/autocheck/) {
439 elsif (/incoming-recv/) {
440 my ($msg_id) = $record->{text} =~ /^Message-Id:\s+<(.+)>/im;
441 if (defined $msg_id and exists $$seen_msg_ids{$msg_id}) {
444 elsif (defined $msg_id) {
445 $$seen_msg_ids{$msg_id} = 1;
447 # Incomming Mail Message
448 my ($received,$hostname) = $record->{text} =~ m/Received: \(at (\S+)\) by (\S+)\;/;
449 $output .= qq|<p class="msgreceived"><a name="msg$msg_number">Message received</a> at |.
450 htmlsanit("$received\@$hostname") . q| (<a href="| . bugurl($ref, "msg=$msg_number") . '">full text</a>'.q|, <a href="| . bugurl($ref, "msg=$msg_number") . ';mbox=yes">mbox</a>)'.":</p>\n";
451 $output .= handle_email_message($record->{text},
453 msg_number => $msg_number,
457 die "Unknown record type $_";
465 if (looks_like_number($msg) and ($msg-1) <= $#records) {
466 @records = ($records[$msg-1]);
472 print qq(Content-Disposition: attachment; filename="bug_${ref}.mbox"\n);
473 print "Content-Type: text/plain\n\n";
477 print qq(Content-Disposition: attachment; filename="bug_${ref}_message_${msg_num}.mbox"\n);
478 print "Content-Type: message/rfc822\n\n";
480 for my $record (@records) {
481 next if $record->{type} !~ /^(?:recips|incoming-recv)$/;
482 next if not $boring and $record->{type} eq 'recips' and @records > 1;
483 my @lines = split( "\n", $record->{text}, -1 );
484 if ( $lines[ 1 ] =~ m/^From / ) {
485 my $tmp = $lines[ 0 ];
486 $lines[ 0 ] = $lines[ 1 ];
489 if ( !( $lines[ 0 ] =~ m/^From / ) ) {
490 my $date = strftime "%a %b %d %T %Y", localtime;
491 unshift @lines, "From unknown $date";
493 map { s/^(>*From )/>$1/ } @lines[ 1 .. $#lines ];
494 print join( "\n", @lines ) . "\n";
501 for my $record (@records) {
507 $skip_next = 1 if $record->{type} eq 'html' and not $boring;
508 push @log, handle_record($record,$ref,$msg_num,\%seen_msg_ids);
512 @log = reverse @log if $reverse;
513 $log = join('<hr>',@log);
516 print "Content-Type: text/html; charset=utf-8\n\n";
518 my $title = htmlsanit($status{subject});
520 my $dummy2 = $debbugs::gWebHostBugDir;
522 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
523 print "<HTML><HEAD>\n" .
524 "<TITLE>$short - $title - $debbugs::gProject $debbugs::gBug report logs</TITLE>\n" .
525 '<meta http-equiv="Content-Type" content="text/html;charset=utf-8">'.
526 "<link rel=\"stylesheet\" href=\"$debbugs::gWebHostBugDir/css/bugs.css\" type=\"text/css\">" .
530 print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto:$ref\@$gEmailDomain\">$short</A>" .
531 "<BR>" . $title . "</H1>\n";
533 print "$descriptivehead\n";
534 printf "<div class=\"msgreceived\"><p>View this report as an <a href=\"%s\">mbox folder</a>.</p></div>\n", bugurl($ref, "mbox");
538 print "<p class=\"msgreceived\">Send a report that <a href=\"/cgi-bin/bugspam.cgi?bug=$ref\">this bug log contains spam</a>.</p>\n<HR>\n";
541 print "</BODY></HTML>\n";