cgi-wrapper-0.3/ 40755 1750 1750 0 7333266103 11335 5ustar ecuecucgi-wrapper-0.3/wrapper100755 1750 1750 6306 7333264457 13057 0ustar ecuecu#!/usr/bin/perl -w # # universal CGI wrapper # Nicolas Jombart # (c) 2001, Hervé Schauer Consultants # $Id: wrapper,v 1.4 2001/07/25 20:24:00 jombart Exp $ # # # parses a request, check validity of params and values # according to the configuration file, and call the script # one of the parameters MUST be _script_=your-script # (the name of the script to be called) # # # THIS SOFTWARE IS MADE AVAILABLE "AS IS", AND THE AUTHOR DISCLAIMS ALL # WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO THIS SOFTWARE, INCLUDING # WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER # RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF # CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. use CGI; use strict; my $call = new CGI; my @params = $call->param(); my %param_ok = (); my $url = ""; my $tmp = ""; my @conf_line = (); my %conf_rx = (); my %conf_min = (); my %conf_max = (); my %required = (); my $key = ""; my $param = ""; my $rx = ""; my $min = 0; my $max = 0; my $tocheck; my $filename = "wrapper.conf"; my $script_name = ""; # read configuration file open(CONF,"$filename") or die "Can't open $filename : $!\n"; while() { # skip comments and new lines. next if m/^(#| |\n)/; # configuration format @conf_line = /^(.*):(.*):(.*):(.*)$/; $key = $1; $rx = $2; $min = $3; $max = $4; if ($1 =~ /^\*(.*)/) { $key = $1; $required{$key} = 1; } else { $required{$key} = 0; } $conf_rx{$key} = $rx; $conf_min{$key} = $min; $max = $min if $max < $min; $conf_max{$key} = $max; } close CONF; # check all parameters foreach $param (@params) { $tocheck = $call->param($param); foreach $key (keys %conf_rx) { # store in %params_ok if ok next unless ($key eq $param); # skip if lenght less than minimum next if (length($tocheck) < $conf_min{$key}); # cut to maximum length if((length($tocheck) > $conf_max{$key}) && ($conf_max{$key} != 0)) { $tocheck = substr($tocheck,0,$conf_max{$key}); } if($tocheck =~ m/$conf_rx{$key}/) { $param_ok{$key}=$tocheck; last; } else { # log the error print STDERR $call->remote_host()." argument $key value $tocheck doesn't match the regexp.\n"; } } } # check REQUIRED parameters foreach(keys %conf_rx) { if(($required{$_}==1)&&!defined($param_ok{$_})) { print "Content-type: text/html\n"; print "Erreur : le parametre $_ n'est pas correct.\n"; exit(0); } # writing the URL $script_name = $param_ok{"_script_"}; if(!defined($param_ok{"_script_"})) { $script_name=$conf_rx{"_script_"}; } foreach(keys %param_ok) { $url .= $_ . "=" . $param_ok{$_} . "&"; } # call the real CGI script my $pid = open(SCRIPT,"-|"); die "open: $!\n" unless defined($pid); if($pid != 0) { # parent : write the result to stdout my @res = grep(/./,