X-Git-Url: https://git.donarmstrong.com/?p=debbugs.git;a=blobdiff_plain;f=cgi%2Fversion.cgi;h=e3df1fc1cd2decd453e54c67681a91d07f6b61f2;hp=8d575ffbe948639e5679b60263b8debbfba52b05;hb=6321024b3c612ef7626eef85499a34ee35f7372c;hpb=1639566d7762d46bb4e13b26db7bd76f671667df diff --git a/cgi/version.cgi b/cgi/version.cgi index 8d575ff..e3df1fc 100755 --- a/cgi/version.cgi +++ b/cgi/version.cgi @@ -5,7 +5,7 @@ use strict; # Hack to work on merkel where suexec is in place BEGIN{ - if ($ENV{HTTP_HOST} eq 'merkel.debian.org') { + if (defined $ENV{HTTP_HOST} and $ENV{HTTP_HOST} eq 'merkel.debian.org') { unshift @INC, qw(/home/don/perl/usr/share/perl5 /home/don/perl/usr/lib/perl5 /home/don/source); $ENV{DEBBUGS_CONFIG_FILE}="/home/don/config_internal"; } @@ -14,13 +14,17 @@ BEGIN{ use CGI::Simple; -use CGI::Alert 'don@donarmstrong.com'; +# by default send this message nowhere +# use CGI::Alert q(nobody@example.com); use Debbugs::Config qw(:config); -use Debbugs::CGI qw(htmlize_packagelinks html_escape cgi_parameters); + +our $VERSION=1; + +use Debbugs::CGI qw(htmlize_packagelinks html_escape cgi_parameters munge_url :cache); use Debbugs::Versions; use Debbugs::Versions::Dpkg; -use Debbugs::Packages qw(getversions makesourceversions); +use Debbugs::Packages qw(get_versions makesourceversions); use HTML::Entities qw(encode_entities); use File::Temp qw(tempdir); use IO::File; @@ -31,10 +35,10 @@ my %img_types = (svg => 'image/svg+xml', png => 'image/png', ); -my $q = new CGI::Simple; +my $q = CGI::Simple->new(); my %cgi_var = cgi_parameters(query => $q, - single => [qw(package format ignore_boring width height collapse)], + single => [qw(package format ignore_boring width height collapse info)], default => {package => 'spamass-milter', found => [], fixed => [], @@ -43,20 +47,12 @@ my %cgi_var = cgi_parameters(query => $q, format => 'png', width => undef, height => undef, + info => 0, }, ); - -# we want to first load the appropriate file, -# then figure out which versions are there in which architectures, -my %versions; -my %version_to_dist; -for my $dist (@{$config{distributions}}) { - $versions{$dist} = [getversions($cgi_var{package},$dist)]; - # make version_to_dist - foreach my $version (@{$versions{$dist}}){ - push @{$version_to_dist{$version}}, $dist; - } -} +my $this = munge_url('version.cgi?', + %cgi_var, + ); if (defined $cgi_var{width}) { $cgi_var{width} =~ /(\d+)/; @@ -75,22 +71,102 @@ else { $cgi_var{format} = 'png'; } +my $etag; +if ($cgi_var{info} and not defined $cgi_var{dot}) { + $etag = etag_does_not_match(cgi=>$q, + additional_data=>[grep {defined $_ ? $_ : ()} + @cgi_var{(qw(package ignore_boring), + qw(collapse)) + }, + $this, + $VERSION], + ); + if (not $etag) { + print $q->header(-status => 304); + print "304: Not modified\n"; + exit 0; + } + print $q->header(-status => 200, + -cache_control => 'public, max-age=86400', + -etag => $etag, + -content_type => 'text/html', + ); + print < + +END + print ''.html_escape($cgi_var{package}).' Version Graph'."\n"; + print "\n"; + print '['.($cgi_var{ignore_boring}?"Don't i":'I').'gnore boring] '; + print '['.($cgi_var{collapse}?"Don't c":'C').'ollapse] '; + print '[Dot]
'; + print ''; + print < + +END + exit 0; +} + +# we want to first load the appropriate file, +# then figure out which versions are there in which architectures, +my %versions; +my %version_to_dist; +for my $dist (@{$config{distributions}}) { + $versions{$dist} = [get_versions(package => [split /\s*,\s*/, $cgi_var{package}], + dist => $dist, + source => 1, + )]; + # make version_to_dist + foreach my $version (@{$versions{$dist}}){ + push @{$version_to_dist{$version}}, $dist; + } +} + # then figure out which are affected. # turn found and fixed into full versions -@{$cgi_var{found}} = makesourceversions($cgi_var{package},undef,@{$cgi_var{found}}); -@{$cgi_var{fixed}} = makesourceversions($cgi_var{package},undef,@{$cgi_var{fixed}}); -my @interesting_versions = makesourceversions($cgi_var{package},undef,keys %version_to_dist); +@{$cgi_var{found}} = map {makesourceversions($_,undef,@{$cgi_var{found}})} split/\s*,\s*/, $cgi_var{package}; +@{$cgi_var{fixed}} = map {makesourceversions($_,undef,@{$cgi_var{fixed}})} split/\s*,\s*/, $cgi_var{package}; +my @interesting_versions = map {makesourceversions($_,undef,keys %version_to_dist)} split/\s*,\s*/, $cgi_var{package}; # We need to be able to rip out leaves which the versions that do not affect the current versions of unstable/testing my %sources; @sources{map {m{(.+)/}; $1} @{$cgi_var{found}}} = (1) x @{$cgi_var{found}}; @sources{map {m{(.+)/}; $1} @{$cgi_var{fixed}}} = (1) x @{$cgi_var{fixed}}; @sources{map {m{(.+)/}; $1} @interesting_versions} = (1) x @interesting_versions; -my $version = Debbugs::Versions->new(\&Debbugs::Versions::Dpkg::vercmp); + +# at this point, we know enough to calculate the etag. + +my @versions_files; foreach my $source (keys %sources) { - my $srchash = substr $source, 0, 1; - my $version_fh = new IO::File "$config{version_packages_dir}/$srchash/$source", 'r'; - $version->load($version_fh); + my $srchash = substr $source, 0, 1; + next unless -e "$config{version_packages_dir}/$srchash/$source"; + push @versions_files, "$config{version_packages_dir}/$srchash/$source"; +} + +$etag = etag_does_not_match(cgi=>$q, + additional_data=>[@cgi_var{(qw(package ignore_boring), + qw(collapse)) + }, + $this, + $VERSION], + files => [@versions_files + ], + ); +if (not $etag) { + print $q->header(-status => 304); + print "304: Not modified\n"; + exit 0; +} + +my $version = Debbugs::Versions->new(\&Debbugs::Versions::Dpkg::vercmp); +for my $version_fn (@versions_files) { + my $version_fh = IO::File->new($version_fn, 'r') or + warn "Unable to open $version_fn for reading: $!"; + $version->load($version_fh); } # Here, we need to generate a short version to full version map my %version_map; @@ -157,7 +233,7 @@ if ($cgi_var{collapse}) { # are in the same state as their parent, and are not in a suite foreach my $key (keys %reversed_nodes) { my ($short_version) = $key =~ m{/(.+)$}; - if (not exists $version_to_dist{$short_version} + if (not exists $version_to_dist{$key} and @{$reversed_nodes{$key}} <= 1 and defined $version->{parent}{$key} and $all_states{$key} eq $all_states{$version->{parent}{$key}} @@ -212,8 +288,8 @@ foreach my $key (keys %all_states) { or $all_states{$key} eq 'absent'); next if $cgi_var{ignore_boring} and not version_relevant($version,$key,\@interesting_versions); my @attributes = @{$state{$all_states{$key}}}; - if (length $short_version and exists $version_to_dist{$short_version}) { - push @attributes, 'label="'.$key.'\n'."(".join(', ',@{$version_to_dist{$short_version}}).")\""; + if (exists $version_to_dist{$key}) { + push @attributes, 'label="'.$key.'\n'."(".join(', ',@{$version_to_dist{$key}}).")\""; } my $node_attributes = qq("$key" [).join(',',@attributes).qq(]\n); $dot .= $node_attributes; @@ -249,20 +325,28 @@ $dot .= "}\n"; my $temp_dir = tempdir(CLEANUP => 1); if (not defined $cgi_var{dot}) { - my $dot_fh = new IO::File "$temp_dir/temp.dot",'w' or + my $dot_fh = IO::File->new("$temp_dir/temp.dot",'w') or die "Unable to open $temp_dir/temp.dot for writing: $!"; print {$dot_fh} $dot or die "Unable to print output to the dot file: $!"; close $dot_fh or die "Unable to close the dot file: $!"; system('dot','-T'.$cgi_var{format},"$temp_dir/temp.dot",'-o',"$temp_dir/temp.$cgi_var{format}") == 0 or print "Content-Type: text\n\nDot failed." and die "Dot failed: $?"; - my $img_fh = new IO::File "$temp_dir/temp.$cgi_var{format}", 'r' or + my $img_fh = IO::File->new("$temp_dir/temp.$cgi_var{format}", 'r') or die "Unable to open $temp_dir/temp.$cgi_var{format} for reading: $!"; - print "Content-Type: $img_types{$cgi_var{format}}\n\n"; + print $q->header(-status => 200, + -cache_control => 'public, max-age=300', + -etag => $etag, + -content_type => $img_types{$cgi_var{format}}, + ); print <$img_fh>; close $img_fh; } else { - print "Content-Type: text\n\n"; + print $q->header(-status => 200, + -cache_control => 'public, max-age=300', + -etag => $etag, + -content_type => 'text', + ); print $dot; }