]> git.deb.at Git - deb/packages.git/blob - lib/Packages/DoIndex.pm
Add format parameter (used by DoNewPkg and DoIndex)
[deb/packages.git] / lib / Packages / DoIndex.pm
1 package Packages::DoIndex;
2
3 use strict;
4 use warnings;
5
6 use CGI qw( :cgi );
7 use Exporter;
8
9 use Deb::Versions;
10 use Packages::Config qw( $TOPDIR );
11 use Packages::I18N::Locale;
12 use Packages::CGI;
13
14 our @ISA = qw( Exporter );
15 our @EXPORT = qw( do_index do_allpackages );
16
17 sub do_index {
18     return send_file( 'index', @_ );
19 }
20 sub do_allpackages {
21     return send_file( 'allpackages', @_ );
22 }
23
24 sub send_file {
25     my ($file, $params, $opts, $html_header) = @_;
26
27     if ($params->{errors}{suite}) {
28         fatal_error( _g( "suite not valid or not specified" ) );
29     }
30     if (@{$opts->{suite}} > 1) {
31         fatal_error( sprintf( _g( "more than one suite specified for show_static (%s)" ), "@{$opts->{suite}}" ) );
32     }
33     if (@{$opts->{subsection}} > 1) {
34         fatal_error( sprintf( _g( "more than one suite specified for show_static (%s)" ), "@{$opts->{suite}}" ) );
35     }
36
37     my $wwwdir = "$TOPDIR/www";
38     my $path = "$opts->{suite}[0]/";
39     $path .= "$opts->{archive}[0]/" if @{$opts->{archive}} == 1;
40     $path .= "$opts->{subsection}[0]/" if @{$opts->{subsection}};
41     # we don't have translated index pages for subsections yet
42     $opts->{lang} = 'en' if @{$opts->{subsection}};
43     $path .= "$file.$opts->{lang}.$opts->{format}";
44
45     unless (@Packages::CGI::fatal_errors) {
46         my $buffer;
47         if (open( INDEX, '<', "$wwwdir/$path" )) {
48             my $charset = get_charset( $opts->{lang} );
49             print header( -charset => $charset );
50
51             binmode INDEX;
52             while (read INDEX, $buffer, 4096) {
53                 print $buffer;
54             }
55             close INDEX;
56             exit;
57         } else {
58             fatal_error( sprintf( _g( "couldn't read index file %s: %s" ),
59                                   $path, $! ) );
60         }
61     }
62
63     %$html_header = ( title => _g('Error'),
64                       lang => $opts->{lang},
65                       print_title => 1,
66                       print_search_field => 'packages',
67                       search_field_values => { 
68                           keywords => _g('search for a package'),
69                           searchon => 'default',
70                           arch => 'any',
71                           suite => 'all',
72                           section => 'all',
73                           exact => 1,
74                           debug => $Packages::Search::debug,
75                       },
76                       );
77 }
78
79 1;
80