2 # $Id: search_packages.pl 91 2006-02-10 22:18:31Z jeroen $
3 # dispatcher.pl -- CGI interface for packages.debian.org
5 # Copyright (C) 2004-2006 Frank Lichtenheld
7 # use is allowed under the terms of the GNU Public License (GPL)
8 # see http://www.fsf.org/copyleft/gpl.html for a copy of the license
22 use Packages::Config qw( $DBDIR $ROOT $SEARCH_CGI $SEARCH_PAGE
23 @SUITES @SECTIONS @ARCHIVES @ARCHITECTURES );
26 use Packages::Search qw( :all );
27 use Packages::HTML ();
28 use Packages::Sections;
30 use Packages::DoSearch;
32 use Packages::DoDownload;
33 use Packages::DoFilelist;
35 &Packages::CGI::reset;
37 $ENV{PATH} = "/bin:/usr/bin";
39 # Read in all the variables set by the form
41 if ($ARGV[0] && ($ARGV[0] eq 'php')) {
42 $input = new CGI(\*STDIN);
47 my $pet0 = new Benchmark;
48 my $tet0 = new Benchmark;
49 # use this to disable debugging in production mode completly
50 my $debug_allowed = 1;
51 my $debug = $debug_allowed && $input->param("debug");
52 $debug = 0 if !defined($debug) || $debug !~ /^\d+$/o;
53 $Packages::CGI::debug = $debug;
55 &Packages::Config::init( '../' );
56 &Packages::DB::init();
58 my $what_to_do = 'show';
60 if (my $path = $input->path_info()) {
61 my @components = grep { $_ } map { lc $_ } split /\/+/, $path;
63 debug( "components[0]=$components[0]", 2 );
64 if ($components[0] eq 'search') {
66 $what_to_do = 'search';
68 if ($components[0] eq 'source') {
70 $input->param( 'source', 1 );
72 if (@components == 0) {
73 # we just hope we get the information through our parameters...
74 } elsif (@components == 1) {
75 $what_to_do = 'search';
78 for ($components[-1]) {
79 /^(changelog|copyright|download|filelist)$/ && do {
86 my %SUITES = map { $_ => 1 } @SUITES;
87 my %SUITES_ALIAS = ( woody => 'oldstable',
91 my %SECTIONS = map { $_ => 1 } @SECTIONS;
92 my %ARCHIVES = map { $_ => 1 } @ARCHIVES;
93 my %ARCHITECTURES = map { $_ => 1 } (@ARCHITECTURES, 'all');
96 my ($cgi, $params_set, $key, $val) = @_;
97 if ($params_set->{$key}++) {
98 fatal_error( "$key set more than once in path" );
100 $cgi->param( $key, $val );
105 foreach (@components) {
107 set_param_once( $input, \%params_set, 'suite', $_);
108 #possible conflicts with package names
109 # } elsif (my $s = $SUITES_ALIAS{$_}) {
110 # set_param_once( $input, \%params_set, 'suite', $s);
111 } elsif ($SECTIONS{$_}) {
112 set_param_once( $input, \%params_set, 'section', $_);
113 } elsif ($ARCHIVES{$_}) {
114 set_param_once( $input, \%params_set, 'archive', $_);
115 } elsif ($ARCHITECTURES{$_}) {
116 set_param_once( $input, \%params_set, 'arch', $_);
117 } elsif ($sections_descs{$_}) {
118 set_param_once( $input, \%params_set, 'subsection', $_);
119 } elsif ($_ eq 'source') {
120 set_param_once( $input, \%params_set, 'source', 1);
127 if (@components > 1) {
128 fatal_error( "two or more packages specified (@components)" );
130 } # else if (@components == 1)
133 $input->param( 'keywords', $components[0] );
134 $input->param( 'package', $components[0] );
138 my ( $pkg, @suites, @sections, @subsections, @archives, @archs );
140 my %params_def = ( keywords => { default => undef,
141 match => '^\s*([-+\@\s\w\/.:]+)\s*$',
143 package => { default => undef,
144 match => '^([\w.+-]+)$',
146 suite => { default => 'all', match => '^([\w-]+)$',
147 array => ',', var => \@suites,
148 replace => { all => \@SUITES } },
149 archive => { default => ($what_to_do eq 'search') ?
151 match => '^([\w-]+)$',
152 array => ',', var => \@archives,
153 replace => { all => \@ARCHIVES,
154 default => [qw(us security non-US)]} },
155 exact => { default => 0, match => '^(\w+)$', },
156 source => { default => 0, match => '^(\d+)$', },
157 searchon => { default => 'names', match => '^(\w+)$', },
158 section => { default => 'all', match => '^([\w-]+)$',
159 alias => 'release', array => ',',
161 replace => { all => \@SECTIONS } },
162 subsection => { default => 'default', match => '^([\w-]+)$',
163 array => ',', var => \@subsections,
164 replace => { default => [] } },
165 arch => { default => 'any', match => '^(\w+)$',
166 array => ',', var => \@archs, replace =>
167 { any => \@ARCHITECTURES } },
170 my %params = Packages::Search::parse_params( $input, \%params_def, \%opts );
172 $opts{h_suites} = { map { $_ => 1 } @suites };
173 $opts{h_sections} = { map { $_ => 1 } @sections };
174 $opts{h_archives} = { map { $_ => 1 } @archives };
175 $opts{h_archs} = { map { $_ => 1 } @archs };
177 if ((($opts{searchon} eq 'names') && $opts{source}) ||
178 ($opts{searchon} eq 'sourcenames')) {
180 $opts{searchon} = 'names',
181 $opts{searchon_form} = 'sourcenames';
184 my $pet1 = new Benchmark;
185 my $petd = timediff($pet1, $pet0);
186 debug( "Parameter evaluation took ".timestr($petd) );
188 print $input->header( -charset => 'utf-8' );
190 my (%html_header, $menu, $page_content);
191 unless (@Packages::CGI::fatal_errors) {
193 &{"do_$what_to_do"}( \%params, \%opts, \%html_header,
194 \$menu, \$page_content );
196 %html_header = ( title => 'Error',
199 print_search_field => 'packages',
200 search_field_values => {
201 keywords => 'search for a package',
202 searchon => 'default',
212 print Packages::HTML::header( %html_header );
221 unless (@Packages::CGI::fatal_errors) {
225 my $tet1 = new Benchmark;
226 my $tetd = timediff($tet1, $tet0);
227 print "Total page evaluation took ".timestr($tetd)."<br>"
230 my $trailer = Packages::HTML::trailer( $ROOT );
231 $trailer =~ s/LAST_MODIFIED_DATE/gmtime()/e; #FIXME