#!/usr/bin/perl -wT # don't forget -T for cgi scripts ##### First some setup use CGI; use strict; my $cgi = CGI->new; # some sort of processing on incomming arguments my %args; foreach my $arg (qw/surname firstname dob pet_name/) { my $tainted = $cgi->param($arg) || ""; ($args{$arg}) = ($tainted =~ m!([\w _/.-]+)!; # pick your safe # input characters } print $cgi->header; ##### Now some options/interpretations #### # a) call fish.cgi with these results and display it's output. # this script may be on another server: { use LWP::UserAgent; $SIG{ALRM} = sub {die "LWP request timed out."}; my $url = "http://www.somewhere.com.au/fish.cgi"; # add any query string you want here ie: my $clean_surname = $cgi->escape($args{surname}); $url .= "?surname=$clean_surname"; # Create a user agent object my $ua = new LWP::UserAgent; # create the request object (POST or GET) my $req = new HTTP::Request ("POST" => $url); # Set the POSTed input (if necessary) # I'm certain there's a better way to do this. my $input; foreach my $value (keys(%args)) { my $clean_value = $cgi->escape($args{$value}); $input .= "$value=$clean_value\n"; } # Set the content type if necessary $req->content_type('application/x-www-form-urlencoded'); # Give the request object the POSTed input $req->content($input); my $content; eval { alarm(60); # time out after 1 minute # Pass request to the user agent and get a response back my ($code, $msg, $headers); my $res = new HTTP::Response ($code, $msg, $headers, $content); $res = $ua->request($req); # Get our content $content = $res->content(); ### Finished call to the other script, so cancel the alarm alarm(0); }; # Check for error if($@ =~ /timed out/) { die $@; } # else do something with $content print $content; } #### # b) Call a script from some directory directly (without LWP) # and grab the results { my $otherscript = "/some/directory/somewhere/script.pl"; # pretend we're using CGI in this script and that # we've set it up (different for different versions) to # be okay with stuff like: surname=foo etc my $input; $input = "surname=$args{surname} firstname=$args{firstname}"; # etc, the foreach above is better than this of course. # if you want results here to be an array of lines, # where the first element of the array is the first line # returned and the second is the second line returned etc # s/\$results/@results/ and it'll behave that way my $results = qx/$otherscript $input/; # do something with our results: print $results; } #### # c) Call another script from some directory directly # and have it take over things from here: { my $otherscript = "/some/directory/somewhere/script.pl"; my $input; $input = "surname=$args{surname} firstname=$args{firstname}"; exec($otherscript, $input); # the end, this script won't come back from here. }