[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-WebCGI] A CGI Dispatcher



Friends:

   I'd like to put out the appended script for comment.  The 
motivation for writing it was primarily as an illustration of how one 
uses one master CGI as a dispatcher to prevent the problems which 
come from having multiple MacPerl CGIs on a public web server, and 
immediately the request from Philip Thompson for a way to allow 
students to execute Perl CGIs on a Mac server without having to 
convert them to the MacPerl "CGI Script" mini-application.

   The one thing one needs to do to use this master CGI is to alter 
the URL by which you call it.  Where you might normally have a URL 
like:

http://example.com/cgi-bin/myscript.cgi

...using this dispatcher, you have:

http://example.com/cgi-bin/dispatcher.cgi$myscript.cgi

   The dispatcher, appended here, needs to be saved as a "CGI Script". 
The "servant" scripts that it runs need be saved as plain text.

   I deliberately didn't include the -w switch nor "use strict" as 
these would be applied to the servant script and that might be 
undesireable.

   Any warnings, suggestions, comments, etc. gratefully received.

-David Steffen-


---=== BEGIN MacPerl SCRIPT ===---

#!/usr/bin/perl
#
# cgi_dispatch.cgi
# by David Steffen
# Last Modified 03/29/2000
#
# Perl CGI Script which implements a dispatcher
# ... for multiple, virtual CGIs.
#
# In this version, $do_what corresponds to the
# ...full path from the base HTML directory to the
# ...name of a perl script to be executed as a virtual
# ...CGI and is passed in $ENV{PATH_INFO}

# This next value needs to be set for your server
# It is the full path to the home CGI directory
$home_dir = 'Tyrosine:Documents:Quid Pro Quo:html:cgi-bin';

# Get the path to the script to be executed
$do_what = $ENV{"PATH_INFO"};
# ...add the rest of the full path
$inpfile = $home_dir . ':' . $do_what;
# ...and open the file.
open(INFILE, $inpfile) || die "Can't open $inpfile: $!";
# Convert Unix or PC newlines to Mac if necessary
@lines = <INFILE>;
$script = join('', @lines);
$script =~ s/\x0D?\x0A/\x0D/g;

# Run the script
eval $script;
# Display any execution errors to the user.
# (Good for students, but maybe not for users.)
print $@ if $@;

exit 0;

__END__

---=== END MacPerl SCRIPT ===---
David Steffen, Ph.D.
President, Biomedical Computing, Inc. <http://www.biomedcomp.com/>
Phone: (713) 610-9770 FAX: (713) 610-9769 E-mail: steffen@biomedcomp.com

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org