CGI Wrapper Script


The following shell script may be used to catch and display errors from any perl CGI script. The script is completely generic and can be multiplied any number of times via hard links (symbolic links are normally not allowed for CGI scripts).
 #!/bin/sh
 #=======================================================================
 #	Wrapper to catch CGI errors
 #=======================================================================
 dir=`dirname $0`
 stub=`basename $0 .cgi`
 
 tmp1="/tmp/$stub.$$.out"
 tmp2="/tmp/$stub.$$.err"
 
 >>$tmp1
 >>$tmp2
 
 
 pl="$dir/$stub.pl"
 if [ -f "$pl" ]; then
     if [ ! -x "$pl" ]; then
 	echo "Content-type: text/plain"
 	echo "Status: 500"
 	echo
 	echo "$pl is not executable"
     else
 	"$pl" >$tmp1 2>$tmp2
     fi
 else
     perl -e 'use Local; ::cgirun("cgi/'$stub'")' >$tmp1 2>$tmp2
 fi
 if [ -s $tmp2 ]; then
     echo "Content-type: text/plain"
     echo	
     echo ">>>Errors:"
     cat $tmp2
     echo
     echo ">>>Output:"
 fi
 cat $tmp1
 rm -f $tmp1 $tmp2
 exit 0
Note. The script use two independent methods for starting the wrapped perl script:

1 First it tries to find a perl script named basename.pl where basename is the name of the wrapper script. 1 If such a file is not found it assumes that the basename may be used by the cgirun function in the Local.pm configuration perl module using cgi/basename as argument.

Finally, when developing new CGI perl scripts it is often wise to limit the execution time allowed. To achieve a CPU time limit of for example 20 seconds the following line may be added:

 ulimit -t 20
Back to the main installation instruction.

The KixFw development team would appreciate any comments or questions. Include your details if you wish to be contacted. kix4kixfw
 
 

2008-12-22 22:49


Home of kixfw.sourceforge.net
Contact kixfw project