use Fcntl qw/O_RDONLY/;
use Mail::Address;
use MLDBM qw/DB_File/;
+use POSIX qw/ceil/;
$config_path = '/etc/debbugs';
$lib_path = '/usr/lib/debbugs';
my %common_exclude = ();
my $common_raw_sort = 0;
my $common_bug_reverse = 0;
-my $common_pending_reverse = 0;
-my $common_severity_reverse = 0;
-my @common_pending_include = ();
-my @common_pending_exclude = ();
-my @common_severity_include = ();
-my @common_severity_exclude = ();
+my %common_reverse = (
+ 'pending' => 0,
+ 'severity' => 0,
+);
+my %common = (
+ 'show_list_header' => 1,
+ 'show_list_footer' => 1,
+);
+
+sub exact_field_match {
+ my ($field, $values, $status) = @_;
+ my @values = @$values;
+ my @ret = grep {$_ eq $status->{$field} } @values;
+ $#ret != -1;
+}
+sub contains_field_match {
+ my ($field, $values, $status) = @_;
+ foreach my $data (@$values) {
+ return 1 if (index($status->{$field}, $data) > -1);
+ }
+ return 0;
+}
+
+sub detect_user_agent {
+ my $userAgent = $ENV{HTTP_USER_AGENT};
+ return { 'name' => 'links' } if ( $userAgent =~ m,^ELinks,);
+ return { 'name' => 'lynx' } if ( $userAgent =~ m,^Lynx,);
+ return { 'name' => 'wget' } if ( $userAgent =~ m,^Wget,);
+ return { 'name' => 'gecko' } if ( $userAgent =~ m,^Mozilla.* Gecko/,);
+ return { 'name' => 'ie' } if ( $userAgent =~ m,^.*MSIE.*,);
+ return { 'name' => 'unknown' };
+}
+my %field_match = (
+ 'subject' => \&contains_field_match,
+ 'tags' => sub {
+ my ($field, $values, $status) = @_;
+ my %values = map {$_=>1} @$values;
+ foreach my $t (split /\s+/, $status->{$field}) {
+ return 1 if (defined $values{$t});
+ }
+ return 0;
+ },
+ 'severity' => \&exact_field_match,
+ 'pending' => \&exact_field_match,
+ 'originator' => \%contains_field_match,
+ 'forwarded' => \%contains_field_match,
+ 'owner' => \%contains_field_match,
+);
+my @common_grouping = ( 'severity', 'pending' );
+my %common_grouping_order = (
+ 'pending' => [ qw( pending forwarded pending-fixed fixed done absent ) ],
+ 'severity' => \@debbugs::gSeverityList,
+);
+my %common_grouping_display = (
+ 'pending' => 'Status',
+ 'severity' => 'Severity',
+);
+my %common_headers = (
+ 'pending' => {
+ "pending" => "outstanding",
+ "pending-fixed" => "pending upload",
+ "fixed" => "fixed in NMU",
+ "done" => "resolved",
+ "forwarded" => "forwarded to upstream software authors",
+ "absent" => "not applicable to this version",
+ },
+ 'severity' => \%debbugs::gSeverityDisplay,
+);
my $common_version;
my $common_dist;
my $debug = 0;
+sub array_option($) {
+ my ($val) = @_;
+ my @vals;
+ @vals = ( $val ) if (ref($val) eq "" && $val );
+ @vals = ( $$val ) if (ref($val) eq "SCALAR" && $$val );
+ @vals = @{$val} if (ref($val) eq "ARRAY" );
+ return @vals;
+}
+
+sub filter_include_exclude($\%) {
+ my ($val, $filter_map) = @_;
+ my @vals = array_option($val);
+ my @data = map {
+ if (/^([^:]*):(.*)$/) { if ($1 eq 'subj') { ['subject', $2]; } else { [$1, $2] } } else { ['tags', $_] }
+ } split /[\s,]+/, join ',', @vals;
+ foreach my $data (@data) {
+ &quitcgi("Invalid filter key: '$data->[0]'") if (!exists($field_match{$data->[0]}));
+ push @{$filter_map->{$data->[0]}}, $data->[1];
+ }
+}
+
+sub filter_option($$\%) {
+ my ($key, $val, $filter_map) = @_;
+ my @vals = array_option($val);
+ foreach $val (@vals) {
+ push @{$filter_map->{$key}}, $val;
+ }
+}
+
sub set_option {
my ($opt, $val) = @_;
+ if ($opt =~ m/^show_list_(foot|head)er$/) { $common{$opt} = $val; }
if ($opt eq "archive") { $common_archive = $val; }
if ($opt eq "repeatmerged") { $common_repeatmerged = $val; }
if ($opt eq "exclude") {
- my @vals;
- @vals = ( $val ) if (ref($val) eq "" && $val );
- @vals = ( $$val ) if (ref($val) eq "SCALAR" && $$val );
- @vals = @{$val} if (ref($val) eq "ARRAY" );
- %common_exclude = map {
- if (/^(.*):(.*)$/) { ($1, $2) } else { ($_, 1) }
- } split /[\s,]+/, join ',', @vals;
+ filter_include_exclude($val, %common_exclude);
}
if ($opt eq "include") {
- my @vals;
- @vals = ( $val, ) if (ref($val) eq "" && $val );
- @vals = ( $$val, ) if (ref($val) eq "SCALAR" && $$val );
- @vals = @{$val} if (ref($val) eq "ARRAY" );
- %common_include = map {
- if (/^(.*):(.*)$/) { ($1, $2) } else { ($_, 1) }
- } split /[\s,]+/, join ',', @vals;
+ filter_include_exclude($val, %common_include);
}
if ($opt eq "raw") { $common_raw_sort = $val; }
if ($opt eq "bug-rev") { $common_bug_reverse = $val; }
- if ($opt eq "pend-rev") { $common_pending_reverse = $val; }
- if ($opt eq "sev-rev") { $common_severity_reverse = $val; }
+ if ($opt eq "pend-rev") { $common_reverse{pending} = $val; }
+ if ($opt eq "sev-rev") { $common_reverse{severity} = $val; }
if ($opt eq "pend-exc") {
- my @vals;
- @vals = ( $val ) if (ref($val) eq "" && $val );
- @vals = ( $$val ) if (ref($val) eq "SCALAR" && $$val );
- @vals = @{$val} if (ref($val) eq "ARRAY" );
- @common_pending_exclude = @vals if (@vals);
+ filter_option('pending', $val, %common_exclude);
}
if ($opt eq "pend-inc") {
- my @vals;
- @vals = ( $val, ) if (ref($val) eq "" && $val );
- @vals = ( $$val, ) if (ref($val) eq "SCALAR" && $$val );
- @vals = @{$val} if (ref($val) eq "ARRAY" );
- @common_pending_include = @vals if (@vals);
+ filter_option('pending', $val, %common_include);
}
if ($opt eq "sev-exc") {
- my @vals;
- @vals = ( $val ) if (ref($val) eq "" && $val );
- @vals = ( $$val ) if (ref($val) eq "SCALAR" && $$val );
- @vals = @{$val} if (ref($val) eq "ARRAY" );
- @common_severity_exclude = @vals if (@vals);
+ filter_option('severity', $val, %common_exclude);
}
if ($opt eq "sev-inc") {
- my @vals;
- @vals = ( $val ) if (ref($val) eq "" && $val );
- @vals = ( $$val ) if (ref($val) eq "SCALAR" && $$val );
- @vals = @{$val} if (ref($val) eq "ARRAY" );
- @common_severity_include = @vals if (@vals);
+ filter_option('severity', $val, %common_include);
}
if ($opt eq "version") { $common_version = $val; }
if ($opt eq "dist") { $common_dist = $val; }
if ($status{severity} eq 'normal') {
$showseverity = '';
- } elsif (grep($status{severity} eq $_, @debbugs::gStrongSeverities)) {
+ } elsif (isstrongseverity($status{severity})) {
$showseverity = "<strong>Severity: $status{severity}</strong>;\n";
} else {
$showseverity = "Severity: <em>$status{severity}</em>;\n";
$result .= $showseverity;
$result .= "Reported by: <a href=\"" . submitterurl($status{originator})
. "\">" . htmlsanit($status{originator}) . "</a>";
+ $result .= ";\nOwned by: " . htmlsanit($status{owner})
+ if length $status{owner};
$result .= ";\nTags: <strong>"
. htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
. "</strong>"
}
} elsif (length($status{done})) {
$result .= ";\n<strong>Done:</strong> " . htmlsanit($status{done});
+ $days = ceil($debbugs::gRemoveAge - -M buglog($status{id}));
+ $result .= ";\n<strong>Will Be Archived:</strong>" . ( $days == 0 ? " today" : $days == 1 ? " in $days day" : " in $days days" );
}
unless (length($status{done})) {
return @{getbugs(sub { 1 })};
}
+sub bugmatches(\%\%) {
+ my ($hash, $status) = @_;
+ foreach my $key( keys( %$hash ) ) {
+ my $value = $hash->{$key};
+ my $sub = $field_match{$key};
+ return 1 if ($sub->($key, $value, $status));
+ }
+ return 0;
+}
+sub bugfilter($%) {
+ my ($bug, %status) = @_;
+ local (%seenmerged);
+ if (%common_include) {
+ return 1 if (!bugmatches(%common_include, %status));
+ }
+ if (%common_exclude) {
+ return 1 if (bugmatches(%common_exclude, %status));
+ }
+ my @merged = sort {$a<=>$b} $bug, split(/ /, $status{mergedwith});
+ return 1 unless ($common_repeatmerged || !$seenmerged{$merged[0]});
+ $seenmerged{$merged[0]} = 1;
+ return 0;
+}
+
sub htmlizebugs {
$b = $_[0];
my @bugs = @$b;
- my @rawsort;
-
- my %section = ();
+ my $anydone = 0;
- my %displayshowpending = ("pending", "outstanding",
- "pending-fixed", "pending upload",
- "fixed", "fixed in NMU",
- "done", "resolved",
- "forwarded", "forwarded to upstream software authors",
- "absent", "not applicable to this version");
+ my @status = ();
+ my %count;
+ my ($header, $footer);
if (@bugs == 0) {
return "<HR><H2>No reports found!</H2></HR>\n";
foreach my $bug (@bugs) {
my %status = %{getbugstatus($bug)};
next unless %status;
- if (%common_include) {
- my $okay = 0;
- foreach my $t (split /\s+/, $status{tags}) {
- $okay = 1, last if (defined $common_include{$t});
- }
- if (defined $common_include{subj}) {
- if (index($status{subject}, $common_include{subj}) > -1) {
- $okay = 1;
- }
- }
- next unless ($okay);
- }
- if (%common_exclude) {
- my $okay = 1;
- foreach my $t (split /\s+/, $status{tags}) {
- $okay = 0, last if (defined $common_exclude{$t});
- }
- if (defined $common_exclude{subj}) {
- if (index($status{subject}, $common_exclude{subj}) > -1) {
- $okay = 0;
- }
- }
- next unless ($okay);
- }
- next if @common_pending_include and
- not grep { $_ eq $status{pending} } @common_pending_include;
- next if @common_severity_include and
- not grep { $_ eq $status{severity} } @common_severity_include;
- next if grep { $_ eq $status{pending} } @common_pending_exclude;
- next if grep { $_ eq $status{severity} } @common_severity_exclude;
-
- my @merged = sort {$a<=>$b} ($bug, split(/ /, $status{mergedwith}));
- next unless ($common_repeatmerged || !$seenmerged{$merged[0]});
- $seenmerged{$merged[0]} = 1;
+ next if bugfilter($bug, %status);
my $html = sprintf "<li><a href=\"%s\">#%d: %s</a>\n<br>",
bugurl($bug), $bug, htmlsanit($status{subject});
$html .= htmlindexentrystatus(\%status) . "\n";
- $section{$status{pending} . "_" . $status{severity}} .= $html;
- push @rawsort, $html if $common_raw_sort;
+ my $key = join( '_', map( {$status{$_}} @common_grouping ) );
+ $section{$key} .= $html;
+ $count{"_$key"}++;
+ foreach my $grouping ( @common_grouping ) {
+ $count{"${grouping}_$status{$grouping}"}++;
+ }
+ $anydone = 1 if $status{pending} eq 'done';
+ push @status, [ $bug, \%status, $html ];
}
my $result = "";
- my $anydone = 0;
if ($common_raw_sort) {
- $result .= "<UL>\n" . join("", @rawsort ) . "</UL>\n";
+ $result .= "<UL>\n" . join("", map( { $_->[ 2 ] } @status ) ) . "</UL>\n";
} else {
- my @pendingList = qw(pending forwarded pending-fixed fixed done absent);
- @pendingList = reverse @pendingList if $common_pending_reverse;
-#print STDERR join(",",@pendingList)."\n";
-#print STDERR join(",",@common_pending_include).":$#common_pending_include\n";
- foreach my $pending (@pendingList) {
- my @severityList = @debbugs::gSeverityList;
- @severityList = reverse @severityList if $common_severity_reverse;
-#print STDERR join(",",@severityList)."\n";
-
-# foreach my $severity(@debbugs::gSeverityList) {
- foreach my $severity(@severityList) {
- $severity = $debbugs::gDefaultSeverity if ($severity eq '');
- next unless defined $section{${pending} . "_" . ${severity}};
- $result .= "<HR><H2>$debbugs::gSeverityDisplay{$severity} - $displayshowpending{$pending}</H2>\n";
- #$result .= "(A list of <a href=\"http://${debbugs::gWebDomain}/db/si/$pending$severity\">all such bugs</a> is available).\n";
- #$result .= "(A list of all such bugs used to be available).\n";
- $result .= "<UL>\n";
- $result .= $section{$pending . "_" . $severity};
+ my (@order, @headers);
+ for( my $i = 0; $i < @common_grouping; $i++ ) {
+ my $grouping_name = $common_grouping[ $i ];
+ my @items = @{ $common_grouping_order{ $grouping_name } };
+ @items = reverse( @items ) if ( $common_reverse{ $grouping_name } );
+ my @neworder = ();
+ my @newheaders = ();
+ if ( @order ) {
+ foreach my $grouping ( @items ) {
+ push @neworder, map( { "${_}_$grouping" } @order );
+ push @newheaders, map( { "$_ - $common_headers{$grouping_name}{$grouping}" } @headers );
+ }
+ @order = @neworder;
+ @headers = @newheaders;
+ } else {
+ push @order, @items;
+ push @headers, map( { $common_headers{$common_grouping[$i]}{$_} } @items );
+ }
+ }
+ $header .= "<ul>\n";
+ for ( my $i = 0; $i < @order; $i++ ) {
+ my $order = $order[ $i ];
+ next unless defined $section{$order};
+ my $count = $count{"_$order"};
+ my $bugs = $count == 1 ? "bug" : "bugs";
+ $header .= "<li><a href=\"#$order\">$headers[$i]</a> ($count $bugs)</li>\n";
+ }
+ $header .= "</ul>\n";
+ for ( my $i = 0; $i < @order; $i++ ) {
+ my $order = $order[ $i ];
+ next unless defined $section{$order};
+ my $count = $count{"_$order"};
+ my $bugs = $count == 1 ? "bug" : "bugs";
+ $result .= "<HR><H2><a name=\"$order\"></a>$headers[$i] ($count $bugs)</H2>\n";
+ $result .= "<UL>\n";
+ $result .= $section{$order};
$result .= "</UL>\n";
- $anydone = 1 if ($pending eq "done");
- }
+ }
+ $footer .= "<ul>\n";
+ foreach my $grouping ( @common_grouping ) {
+ my $local_result = '';
+ foreach my $key ( @{$common_grouping_order{ $grouping }} ) {
+ my $count = $count{"${grouping}_$key"};
+ next if !$count;
+ $local_result .= "<li>$count $common_headers{$grouping}{$key}</li>\n";
+ }
+ if ( $local_result ) {
+ $footer .= "<li>$common_grouping_display{$grouping}<ul>\n$local_result</ul></li>\n";
+ }
+ }
+ $footer .= "</ul>\n";
}
- }
+ $result = $header . $result if ( $common{show_list_header} );
$result .= $debbugs::gHTMLExpireNote if $gRemoveAge and $anydone;
+ $result .= $footer if ( $common{show_list_footer} );
return $result;
}
my %status;
- my $location = getbuglocation( $bugnum, "status" );
+ my $location = getbuglocation( $bugnum, 'summary' );
return {} if ( !$location );
%status = %{ readbug( $bugnum, $location ) };
+ $status{ id } = $bugnum;
$status{found_versions} = [];
$status{fixed_versions} = [];
sub buglog {
my $bugnum = shift;
my $location = getbuglocation($bugnum, 'log');
+ return undef unless defined $location;
return getbugcomponent($bugnum, 'log', $location);
}