#!/usr/bin/perl # perllocate.cgi - a web interface to a perl version of the Unix # locate command. This script makes it easy to query the RPM # repository and find out what packages are availible using Perl5 # Patterns. # written by Ken Estes kestes@staff.mail.com use CGI ':standard'; use File::Basename; use File::stat; sub usage { # If they are asking for help then they are clueless so reset all # their parameters for them, in case they are in a bad state. param(-name=>'Defaults', -value=>'on'); my $rpmdiff_version = `perllocate --version`; $usage =<mtime; $DB_UPDATE_TIME = localtime($mtime); } return 1; } # get_env # fatal errors need to be valid HTML sub fatal_error { my @error = @_; print header; foreach $_ (@error) { print $_; } print end_html; print "\n\n\n"; die("\n"); } sub print_query_page { my @out; push @out, start_form; push @out, ( "This page allows you to search for all packages ". "in the RPM repository which match a particular pattern.", p(), ); push @out, ( h3("Pattern",), "Enter a valid Perl5 Pattern: ", textfield(-name=>'pattern', -size=>30,), p(), ); push @out, ( defaults(-name=>'Defaults'), submit(-name=>'Submit'), p(), ); push @out, ( "Locate database created at: $DB_UPDATE_TIME\n", p(), "The time is now: $LOCALTIME\n", p(), ); push @out, ( end_form(), ); print @out; return ; } # given a pattern remove any "tainted" characters. sub clean_pattern { my ($data) = @_; my $out = '(none)'; # we do not allow single quotes in the pattern because of the way we # invoke perllocate. If we allowed \' then users could introduce # strings like "'; rm -rf /' echo 'done". Unfortunatly we can not # be too strict about other characters because most characters are # needed to specify regular expressions. $data =~ s/\'//g; if ( $data =~ m/(.*)/ ) { $out = $1; } return $out; } # show the results of running perllocate on the chosen pattern. sub print_perllocate { my($pattern, @args) = @_; $pattern =~ s/\'/\\\'/g; my $cmd = ( "perllocate -d $LOCATEDB '$pattern' 2>&1 ". " | sed -e 's!.*$MOUNT_DIR_PATTERN!$DISPLAY_PREFIX!' ". " | grep '$FILES_TO_DISPLAY_PATTERN' ". ""); print $cmd, p(); my $result = "\n".qx{$cmd}."\n"; print pre($result); return ; } # Main { set_static_vars(); get_env(); my ($pattern) = clean_pattern(param("pattern")); my (@perllocate_args) = param("perllocate arguments"); @perllocate_args = split(/\s+/, '--'.(join(" --", @perllocate_args))); push @perllocate_args, '--'; print ( header(), start_html(-title=>"perllocate"), h2({-align=>'CENTER'},"perllocate"), p(), ); if (param("Help Screen")) { usage(); } elsif ( grep {/^(\-\-)((help)|(version))$/} @perllocate_args ) { print_perllocate(@perllocate_args); } else { print_query_page(); ($pattern) && print_perllocate($pattern); } print ( end_html(), "\n\n\n", ); exit 0; }