#!/usr/bin/perl # ---------------------------------------------------------------------------- # Name: CGIDebug.pl # Auth: Dion Almaer (dion) # Desc: Wrapper for CGI programs so you can debug them from command line # You can fool it to send a POST/GET ... set FORM variables and # Environment variables # Date Created: Wed Nov 18 15:11:32 1998 # Version: 0.2 # $Modified: Wed Nov 18 15:58:46 1998 by dion $ # ---------------------------------------------------------------------------- # Examples: # CGIDebug -c foo.cgi -p 'name1=value1&name2=value2' # CGIDebug -c foo.cgi -p 'name1=value2' -e REMOTE_USER:dion,PATH:/bin # --------------------------------------------------------------------------- use strict; use Getopt::Std; # ---------------------------------------------------------------------------- # Global Settings # ---------------------------------------------------------------------------- getopts('g:p:c:e:'); # -- get the command line options # ---------------------------------------------------------------------------- # Main # ---------------------------------------------------------------------------- &Usage() unless (($::opt_g || $::opt_p) && $::opt_c); # -- SET ENVIRONMENT if ( $::opt_e ) { foreach ( split ',', $::opt_e ) { my ($ename, $evalue) = split ':'; $ENV{$ename} = $evalue; } } if ( $::opt_p ) { # -- POST METHOD $ENV{'REQUEST_METHOD'} = 'POST'; $ENV{'CONTENT_LENGTH'} = length($::opt_p); print "Debugging $::opt_c: Using POST with $::opt_p\n"; open (CGI, "| $::opt_c") || die "Couldn't Open $::opt_c: $!"; print CGI $::opt_p; close CGI; } elsif ( $::opt_g ) { # -- GET METHOD $ENV{'REQUEST_METHOD'} = 'GET'; $ENV{'QUERY_STRING'} = $::opt_g; print "Debugging $::opt_c: Using GET with $ENV{QUERY_STRING}\n"; system($::opt_c); } sub Usage { $0 =~ s|.*/||; print <