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);
166 $body =~ s,((ftp|http|https)://[\S~-]+?/?)((\>\;)?[)]?[']?[:.\,]?(\s|$)),<a href=\"$1\">$1</a>$3,go;
167 # The basic idea here is that we take every subpart of
168 # this regex; if it's a digit, it's a bug number, so link
169 # it; otherwise it's some other part, so kick it back
172 $body =~ s[(?:(closes:\s*(?:bug)?\#?\s?)(?{ push @bugs, $^N })) #This sticks the recently closed parenthetical into @bugs
173 (?:(\d+)(?{ push @bugs, $^N }))(?:(?:(,?\s*(?:bug)?\#?\s?)(?{push @bugs, $^N }))(?:(\d+)(?{ push @bugs, $^N })))*
174 ][join('',map {/^\d+$/?(q(<a href=").bugurl($_).qq(">$_</a>)):$_} splice @bugs)]gxie;
175 $$this .= qq(<pre class="message">$body</pre>\n);
180 my %maintainer = %{getmaintainers()};
181 my %pkgsrc = %{getpkgsrc()};
192 my $dtime = strftime "%a, %e %b %Y %T UTC", localtime;
193 $tail_html = $debbugs::gHTMLTail;
194 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
196 my %status = %{getbugstatus($ref)};
199 Content-Type: text/html; charset=utf-8
201 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
203 <head><title>$short - $debbugs::gProject $debbugs::gBug report logs</title></head>
205 <h1>$debbugs::gProject $debbugs::gBug report logs - $short</h1>
206 <p>There is no record of $debbugs::gBug $short.
207 Try the <a href="http://$gWebDomain/">search page</a> instead.</p>
208 $tail_html</body></html>
215 $tpack = lc $status{'package'};
216 my @tpacks = splitpackages($tpack);
218 if ($status{severity} eq 'normal') {
220 } elsif (isstrongseverity($status{severity})) {
221 $showseverity = "Severity: <em class=\"severity\">$status{severity}</em>;\n";
223 $showseverity = "Severity: $status{severity};\n";
226 $indexentry .= "<div class=\"msgreceived\">\n";
227 $indexentry .= htmlpackagelinks($status{package}, 0) . ";\n";
229 foreach my $pkg (@tpacks) {
230 my $tmaint = defined($maintainer{$pkg}) ? $maintainer{$pkg} : '(unknown)';
231 my $tsrc = defined($pkgsrc{$pkg}) ? $pkgsrc{$pkg} : '(unknown)';
234 htmlmaintlinks(sub { $_[0] == 1 ? "Maintainer for $pkg is\n"
235 : "Maintainers for $pkg are\n" },
237 $indexentry .= ";\nSource for $pkg is\n".
238 '<a href="'.srcurl($tsrc)."\">$tsrc</a>" if ($tsrc ne "(unknown)");
239 $indexentry .= ".\n";
242 $indexentry .= "<br>";
243 $indexentry .= htmladdresslinks("Reported by: ", \&submitterurl,
244 $status{originator}) . ";\n";
245 $indexentry .= sprintf "Date: %s.\n",
246 (strftime "%a, %e %b %Y %T UTC", localtime($status{date}));
248 $indexentry .= "<br>Owned by: " . htmlsanit($status{owner}) . ".\n"
249 if length $status{owner};
251 $indexentry .= "</div>\n";
255 $indexentry .= "<h3>$showseverity";
256 $indexentry .= sprintf "Tags: %s;\n",
257 htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
258 if length($status{tags});
259 $indexentry .= "<br>" if (length($showseverity) or length($status{tags}));
261 my @merged= split(/ /,$status{mergedwith});
263 my $descmerged = 'Merged with ';
265 for my $m (@merged) {
266 $descmerged .= $mseparator."<a href=\"" . bugurl($m) . "\">#$m</a>";
269 push @descstates, $descmerged;
272 if (@{$status{found_versions}}) {
273 my $foundtext = 'Found in ';
274 $foundtext .= (@{$status{found_versions}} == 1) ? 'version ' : 'versions ';
275 $foundtext .= join ', ', map htmlsanit($_), @{$status{found_versions}};
276 push @descstates, $foundtext;
279 if (@{$status{fixed_versions}}) {
280 my $fixedtext = '<strong>Fixed</strong> in ';
281 $fixedtext .= (@{$status{fixed_versions}} == 1) ? 'version ' : 'versions ';
282 $fixedtext .= join ', ', map htmlsanit($_), @{$status{fixed_versions}};
283 if (length($status{done})) {
284 $fixedtext .= ' by ' . htmlsanit(decode_rfc1522($status{done}));
286 push @descstates, $fixedtext;
287 } elsif (length($status{done})) {
288 push @descstates, "<strong>Done:</strong> ".htmlsanit(decode_rfc1522($status{done}));
289 } elsif (length($status{forwarded})) {
290 push @descstates, "<strong>Forwarded</strong> to ".maybelink($status{forwarded});
294 my @blockedby= split(/ /, $status{blockedby});
295 if (@blockedby && $status{"pending"} ne 'fixed' && ! length($status{done})) {
296 for my $b (@blockedby) {
297 my %s = %{getbugstatus($b)};
298 next if $s{"pending"} eq 'fixed' || length $s{done};
299 push @descstates, "Fix blocked by <a href=\"" . bugurl($b) . "\">#$b</a>: ".htmlsanit($s{subject});
303 my @blocks= split(/ /, $status{blocks});
304 if (@blocks && $status{"pending"} ne 'fixed' && ! length($status{done})) {
305 for my $b (@blocks) {
306 my %s = %{getbugstatus($b)};
307 next if $s{"pending"} eq 'fixed' || length $s{done};
308 push @descstates, "Blocking fix for <a href=\"" . bugurl($b) . "\">#$b</a>: ".htmlsanit($s{subject});
312 if ($buglog !~ m#^\Q$gSpoolDir/db#) {
313 push @descstates, "Bug is archived. No further changes may be made";
316 $indexentry .= join(";\n<br>", @descstates) . ".\n" if @descstates;
317 $indexentry .= "</h3>\n";
319 my $descriptivehead = $indexentry;
322 if ($buglog =~ m/\.gz$/) {
323 my $oldpath = $ENV{'PATH'};
324 $ENV{'PATH'} = '/bin:/usr/bin';
325 $buglogfh = new IO::File "zcat $buglog |" or &quitcgi("open log for $ref: $!");
326 $ENV{'PATH'} = $oldpath;
328 $buglogfh = new IO::File "<$buglog" or &quitcgi("open log for $ref: $!");
334 @records = read_log_records($buglogfh);
337 quitcgi("Bad bug log for $debbugs::gBug $ref. Unable to read records: $@");
341 =head2 handle_email_message
343 handle_email_message($record->{text},
345 msg_number => $msg_number,
348 Returns a decoded e-mail message and displays entities/attachments as
354 sub handle_email_message{
355 my ($email,%options) = @_;
358 my $parser = new MIME::Parser;
359 # Because we are using memory, not tempfiles, there's no need to
360 # clean up here like in Debbugs::MIME
361 $parser->tmp_to_core(1);
362 $parser->output_to_core(1);
363 my $entity = $parser->parse_data( $email);
364 my @attachments = ();
365 display_entity($entity, $options{ref}, 1, $options{msg_number}, $output, @attachments);
373 bug_links($starting_bug,$stoping_bugs,);
375 Creates a set of links to bugs, starting with bug number
376 $starting_bug, and finishing with $stoping_bug; if only one bug is
377 passed, makes a link to only a single bug.
379 The content of the link is the bug number.
384 my ($start,$stop,$query_arguments) = @_;
385 $stop = $stop || $start;
386 $query_arguments ||= '';
388 for my $bug ($start..$stop) {
389 push @output,'<a href="'.bugurl($bug,'').qq(">$bug</a>);
391 return join(', ',@output);
396 push @log, handle_record($record,$ref,$msg_num);
398 Deals with a record in a bug log as returned by
399 L<Debbugs::Log::read_log_records>; returns the log information that
400 should be output to the browser.
405 my ($record,$bug_number,$msg_number,$seen_msg_ids) = @_;
408 local $_ = $record->{type};
410 $output .= decode_rfc1522($record->{text});
411 # Link to forwarded http:// urls in the midst of the report
412 # (even though these links already exist at the top)
413 $output =~ s,((?:ftp|http|https)://[\S~-]+?/?)([\)\'\:\.\,]?(?:\s|\.<|$)),<a href=\"$1\">$1</a>$2,go;
414 # Add links to the cloned bugs
415 $output =~ s{(Bug )(\d+)( cloned as bugs? )(\d+)(?:\-(\d+)|)}{$1.bug_links($2).$3.bug_links($4,$5)}eo;
416 # Add links to merged bugs
417 $output =~ s{(?<=Merged )([\d\s]+)(?=\.)}{join(' ',map {bug_links($_)} (split /\s+/, $1))}eo;
418 $output .= '<a href="' . bugurl($ref, 'msg='.($msg_number+1)) . '">Full text</a> and <a href="' .
419 bugurl($ref, 'msg='.($msg_number+1), 'mbox') . '">rfc822 format</a> available.';
421 $output = "<div class=\"msgreceived\">\n" . $output . "</div>\n";
424 my ($msg_id) = $record->{text} =~ /^Message-Id:\s+<(.+)>/im;
425 if (defined $msg_id and exists $$seen_msg_ids{$msg_id}) {
428 elsif (defined $msg_id) {
429 $$seen_msg_ids{$msg_id} = 1;
431 $output .= 'View this message in <a href="' . bugurl($ref, "msg=$msg_number", "mbox") . '">rfc822 format</a>';
432 $output .= handle_email_message($record->{text},
434 msg_number => $msg_number,
437 elsif (/autocheck/) {
440 elsif (/incoming-recv/) {
441 my ($msg_id) = $record->{text} =~ /^Message-Id:\s+<(.+)>/im;
442 if (defined $msg_id and exists $$seen_msg_ids{$msg_id}) {
445 elsif (defined $msg_id) {
446 $$seen_msg_ids{$msg_id} = 1;
448 # Incomming Mail Message
449 my ($received,$hostname) = $record->{text} =~ m/Received: \(at (\S+)\) by (\S+)\;/;
450 $output .= qq|<p class="msgreceived"><a name="msg$msg_number">Message received</a> at |.
451 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";
452 $output .= handle_email_message($record->{text},
454 msg_number => $msg_number,
458 die "Unknown record type $_";
466 if (looks_like_number($msg) and ($msg-1) <= $#records) {
467 @records = ($records[$msg-1]);
473 print qq(Content-Disposition: attachment; filename="bug_${ref}.mbox"\n);
474 print "Content-Type: text/plain\n\n";
478 print qq(Content-Disposition: attachment; filename="bug_${ref}_message_${msg_num}.mbox"\n);
479 print "Content-Type: message/rfc822\n\n";
481 for my $record (@records) {
482 next if $record->{type} !~ /^(?:recips|incoming-recv)$/;
483 next if not $boring and $record->{type} eq 'recips' and @records > 1;
484 my @lines = split( "\n", $record->{text}, -1 );
485 if ( $lines[ 1 ] =~ m/^From / ) {
486 my $tmp = $lines[ 0 ];
487 $lines[ 0 ] = $lines[ 1 ];
490 if ( !( $lines[ 0 ] =~ m/^From / ) ) {
491 my $date = strftime "%a %b %d %T %Y", localtime;
492 unshift @lines, "From unknown $date";
494 map { s/^(>*From )/>$1/ } @lines[ 1 .. $#lines ];
495 print join( "\n", @lines ) . "\n";
502 for my $record (@records) {
508 $skip_next = 1 if $record->{type} eq 'html' and not $boring;
509 push @log, handle_record($record,$ref,$msg_num,\%seen_msg_ids);
513 @log = reverse @log if $reverse;
514 $log = join('<hr>',@log);
517 print "Content-Type: text/html; charset=utf-8\n\n";
519 my $title = htmlsanit($status{subject});
521 my $dummy2 = $debbugs::gWebHostBugDir;
523 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
524 print "<HTML><HEAD>\n" .
525 "<TITLE>$short - $title - $debbugs::gProject $debbugs::gBug report logs</TITLE>\n" .
526 '<meta http-equiv="Content-Type" content="text/html;charset=utf-8">'.
527 "<link rel=\"stylesheet\" href=\"$debbugs::gWebHostBugDir/css/bugs.css\" type=\"text/css\">" .
531 print "<H1>" . "$debbugs::gProject $debbugs::gBug report logs - <A HREF=\"mailto:$ref\@$gEmailDomain\">$short</A>" .
532 "<BR>" . $title . "</H1>\n";
534 print "$descriptivehead\n";
535 printf "<div class=\"msgreceived\"><p>View this report as an <a href=\"%s\">mbox folder</a>.</p></div>\n", bugurl($ref, "mbox");
539 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";
542 print "</BODY></HTML>\n";