From e23d2d2080a904ddd6d989a878f3c9b164f0a075 Mon Sep 17 00:00:00 2001 From: Frank Lichtenheld Date: Wed, 22 Feb 2006 22:20:20 +0000 Subject: [PATCH] Display the index pages from within dispatcher.pl. That reduces the complexity of the Apache setup --- bin/create_index_pages | 10 +++--- cgi-bin/dispatcher.pl | 15 +++++---- conf/apache.conf | 11 +------ lib/Packages/DoIndex.pm | 73 +++++++++++++++++++++++++++++++++++++++++ lib/Packages/DoShow.pm | 2 +- 5 files changed, 89 insertions(+), 22 deletions(-) create mode 100644 lib/Packages/DoIndex.pm diff --git a/bin/create_index_pages b/bin/create_index_pages index d9dc8b4..8b20ebd 100755 --- a/bin/create_index_pages +++ b/bin/create_index_pages @@ -61,7 +61,7 @@ foreach my $s (@SUITES) { open $pages{$key}{$lang}{index}{fh}, '>', "$wwwdir/$key/index.$lang.html.new" or die "can't open index file for output: $!"; my $index_title = sprintf( _g( "List of sections in \"%s\"" ), - $s ); + $key ); print {$pages{$key}{$lang}{index}{fh}} header( title => $index_title, title_keywords => "debian, $s", desc => encode_entities( $index_title, '"' ), @@ -105,7 +105,7 @@ foreach my $s (@SUITES) { or die "can't open index file for output: $!"; my $title = sprintf( _g( "Software Packages in \"%s\"" ), - $s ); + $key ); print {$pages{$key}{fh}} header( title => $title, title_keywords => "debian, $s", desc => encode_entities( $title, '"' ), @@ -117,7 +117,7 @@ foreach my $s (@SUITES) { open $pages{$key}{$sec}{fh}, '>', "$wwwdir/$key/$sec/index.en.html.new" or die "can't open index file for output: $!"; $title = sprintf( _g( "Software Packages in \"%s\", section %s" ), - $s, $sec ); + $key, $sec ); print {$pages{$key}{$sec}{fh}} header( title => $title, title_keywords => "debian, $s, $sec", desc => encode_entities( $title, '"' ), @@ -130,7 +130,7 @@ foreach my $s (@SUITES) { open $pages{$key}{$ssec}{fh}, '>', "$wwwdir/$key/$ssec/index.en.html.new" or die "can't open index file for output: $!"; $title = sprintf( _g( "Software Packages in \"%s\", subsection %s" ), - $s, $ssec ); + $key, $ssec ); print {$pages{$key}{$ssec}{fh}} header( title => $title, title_keywords => "debian, $s, $ssec", desc => encode_entities( $title, '"' ), @@ -143,7 +143,7 @@ foreach my $s (@SUITES) { open $pages{$key}{$prio}{fh}, '>', "$wwwdir/$key/$prio/index.en.html.new" or die "can't open index file for output: $!"; $title = sprintf( _g( "Software Packages in \"%s\", priority %s" ), - $s, $prio ); + $key, $prio ); print {$pages{$key}{$prio}{fh}} header( title => $title, title_keywords => "debian, $s, $prio", desc => encode_entities( $title, '"' ), diff --git a/cgi-bin/dispatcher.pl b/cgi-bin/dispatcher.pl index b0913ea..99c5479 100755 --- a/cgi-bin/dispatcher.pl +++ b/cgi-bin/dispatcher.pl @@ -32,6 +32,7 @@ use Packages::I18N::Locale; use Packages::DoSearch; use Packages::DoSearchContents; use Packages::DoShow; +use Packages::DoIndex; use Packages::DoDownload; use Packages::DoFilelist; @@ -75,17 +76,19 @@ my $source = 0; if (my $path = $input->path_info() || $input->param('PATH_INFO')) { my @components = grep { $_ } map { lc $_ } split /\/+/, $path; - debug( "components[0]=$components[0]", 2 ) if @components>0; + push @components, 'index' if $path =~ m,/$,; + + debug( "components[0]=$components[0]", 2 ) if DEBUG and @components>0; if (@components > 0 and $components[0] eq 'source') { shift @components; $input->param( 'source', 1 ); } - if (@components > 0 and $components[0] eq 'search') { + if (@components > 1 and $components[0] eq 'search') { shift @components; $what_to_do = 'search'; # Done fatal_error( _g( "search doesn't take any more path elements" ) ) - if @components > 0; + if @components; } elsif (@components == 0) { fatal_error( _g( "We're supposed to display the homepage here, instead of getting dispatch.pl" ) ); } elsif (@components == 1) { @@ -93,7 +96,7 @@ if (my $path = $input->path_info() || $input->param('PATH_INFO')) { } else { for ($components[-1]) { - /^(changelog|copyright|download|filelist)$/ && do { + /^(index|changelog|copyright|download|filelist)$/ && do { pop @components; $what_to_do = $1; last; @@ -220,8 +223,6 @@ my $pet1 = new Benchmark; my $petd = timediff($pet1, $pet0); debug( "Parameter evaluation took ".timestr($petd) ) if DEBUG; -print $input->header( -charset => $charset ); - my (%html_header, $menu, $page_content); unless (@Packages::CGI::fatal_errors) { no strict 'refs'; @@ -244,6 +245,8 @@ unless (@Packages::CGI::fatal_errors) { ); } +print $input->header( -charset => $charset ); + print Packages::HTML::header( %html_header ); print $menu||''; diff --git a/conf/apache.conf b/conf/apache.conf index 5c1248c..29a9b83 100644 --- a/conf/apache.conf +++ b/conf/apache.conf @@ -103,22 +103,13 @@ RewriteEngine on RewriteLog /var/log/apache/rewrite.log - RewriteLogLevel 9 + RewriteLogLevel 0 # we never want to rewrite those URLs RewriteRule ^/cgi-(bin|old)/ - [L] RewriteRule ^/Pics/ - [L] RewriteRule ^/[^/]+\.css - [L] - RewriteCond %{DOCUMENT_ROOT}/%{SCRIPT_FILENAME} "-f" - RewriteRule ^. - [L] - - RewriteCond %{DOCUMENT_ROOT}/%{SCRIPT_FILENAME}.en.html "-f" - RewriteRule ^. - [L] - - RewriteCond %{DOCUMENT_ROOT}/%{SCRIPT_FILENAME} "-d" - RewriteRule ^. - [L] - # RewriteRule ^/$ http://www.debian.org/distrib/packages RewriteRule ^/([^/+]*)([+])([^/]*)$ "/$1%%{%}2B$3" [N] RewriteRule ^/src:([^/]+)$ /search/source/$1 [R,L,NE] diff --git a/lib/Packages/DoIndex.pm b/lib/Packages/DoIndex.pm new file mode 100644 index 0000000..3e6041d --- /dev/null +++ b/lib/Packages/DoIndex.pm @@ -0,0 +1,73 @@ +package Packages::DoIndex; + +use strict; +use warnings; + +use CGI qw( :cgi ); +use Exporter; + +use Deb::Versions; +use Packages::Config qw( $TOPDIR ); +use Packages::I18N::Locale; +use Packages::CGI; + +our @ISA = qw( Exporter ); +our @EXPORT = qw( do_index ); + +sub do_index { + my ($params, $opts, $html_header) = @_; + + if ($params->{errors}{suite}) { + fatal_error( _g( "suite not valid or not specified" ) ); + } + if (@{$opts->{suite}} > 1) { + fatal_error( sprintf( _g( "more than one suite specified for show_static (%s)" ), "@{$opts->{suite}}" ) ); + } + if (@{$opts->{subsection}} > 1) { + fatal_error( sprintf( _g( "more than one suite specified for show_static (%s)" ), "@{$opts->{suite}}" ) ); + } + + my $wwwdir = "$TOPDIR/www"; + my $path = "$opts->{suite}[0]/"; + $path .= "$opts->{archive}[0]/" if @{$opts->{archive}} == 1; + $path .= "$opts->{subsection}[0]/" if @{$opts->{subsection}}; + # we don't have translated index pages for subsections yet + $opts->{lang} = 'en' if @{$opts->{subsection}}; + $path .= "index.$opts->{lang}.html"; + + unless (@Packages::CGI::fatal_errors) { + my $buffer; + if (open( INDEX, '<', "$wwwdir/$path" )) { + my $charset = get_charset( $opts->{lang} ); + print header( -charset => $charset ); + + binmode INDEX; + while (read INDEX, $buffer, 4096) { + print $buffer; + } + close INDEX; + exit; + } else { + fatal_error( sprintf( _g( "couldn't read index file %s: %s" ), + $path, $! ) ); + } + } + + %$html_header = ( title => _g('Error'), + lang => $opts->{lang}, + print_title => 1, + print_search_field => 'packages', + search_field_values => { + keywords => _g('search for a package'), + searchon => 'default', + arch => 'any', + suite => 'all', + section => 'all', + exact => 1, + debug => $Packages::Search::debug, + }, + ); +} + +1; + diff --git a/lib/Packages/DoShow.pm b/lib/Packages/DoShow.pm index 08eb376..b5a1287 100644 --- a/lib/Packages/DoShow.pm +++ b/lib/Packages/DoShow.pm @@ -163,7 +163,7 @@ sub do_show { my $v_str = $version; my $multiple_versions = grep { $_ ne $version } values %$versions; - $v_str .= " (and others)" if $multiple_versions; + $v_str .= _g(" and others") if $multiple_versions; my $title .= sprintf( _g( "Package: %s (%s)" ), $pkg, $v_str ); $title .= " ".marker( $archive ) if $archive ne 'us'; $title .= " ".marker( $subsection ) if $subsection eq 'non-US' -- 2.39.2