#!/bin/sh # CGItest v1.2.6 (c) 15.2.99 by Andreas Ley (u) 4.8.2004 # Test CGIs offline usage() { echo "Usage: `basename $0` [-p pathinfo] [-q querystring] [-P file] cgi-script" >&2 echo "-p call the cgi-script with the given pathinfo" >&2 echo "-q call the cgi-script with the given querystring" >&2 echo "-P post the given file to the cgi-script" >&2 echo "-s call the cgi-script with SSL environment" >&2 exit 1 } # # Option parsing # set -- `getopt p:q:P:shx $*` || usage while :; do case $1 in -h) sed '1d;s/^# *//;/^$/q' $0; usage;; -x) set -x; shift;; -p) pathinfo=$2; shift 2;; -q) querystring=$2; shift 2;; -P) post=$2; shift 2;; -s) ssl=true; shift;; --) shift; break;; esac done test $# -lt 1 && usage if test ! -x $1; then echo "$1: cannot execute" >&2 exit 1 fi if test -n "${post}"; then if test ! -r ${post}; then echo "${post}: cannot read" >&2 exit 1 fi case ${post} in /*) :;; *) post=`pwd`/${post};; esac fi PATH=/usr/machine/bin:$PATH:/usr/segment/bin unset CDPATH path="/usr/local/bin:/usr/bin:/bin" host=`getfqdn` addr=`host ${host} | awk '$2=="A"{print$NF;exit}'` root=/usr/local/etc/httpd cgibin=true test -d /var/www && root=/var/www && cgibin=false server=`sed -n '2s/# \([^ ]*\) \([^ ]*\) .*/\1\/\2/p' $0` serveradmin="`awk '$1=="ServerAdmin"{print$2}' ${root}/conf/httpd.conf`" serveradmin="${serveradmin:-webmaster@rz.uni-karlsruhe.de}" servername="`awk '$1=="ServerName"{print$2}' ${root}/conf/httpd.conf`" servername="${servername:-${host}}" case ${pathinfo} in /*) :;; *) pathinfo=/${pathinfo};; esac pathtranslated="${root}/htdocs${pathinfo}" home=`cd ${HOME} && /bin/pwd` dir=`dirname $1` file=`cd ${dir} && /bin/pwd`/`basename $1` shift case ${file} in ${home}/.cgi-bin/*/*) if ${cgibin}; then echo "ERROR: Script must lie directly below ~/.cgi-bin" >&2 cd ${HOME}/.cgi-bin path="/usr/sbin:/usr/bin:/sbin:/bin" pathtranslated="${HOME}/.public_html${pathinfo}" script=`echo ${file} | sed "s%\`dirname ${HOME}\`/\([^/]*\)/.cgi-bin%/~\1/cgi-bin%"` file="${root}/cgi-bin/user" else script=${file} echo "ERROR: Script must have .cgi extension and lie in ~/.public_html" >&2 echo "WARNING: Unable to set Script-Path-related environment correctly" >&2 fi;; ${home}/.cgi-bin/*) if ${cgibin}; then cd ${HOME}/.cgi-bin path="/usr/sbin:/usr/bin:/sbin:/bin" pathtranslated="${HOME}/.public_html${pathinfo}" script=`echo ${file} | sed "s%\`dirname ${HOME}\`/\([^/]*\)/.cgi-bin%/~\1/cgi-bin%"` file="${root}/cgi-bin/user" else script=${file} echo "ERROR: Script must have .cgi extension and lie in ~/.public_html" >&2 echo "WARNING: Unable to set Script-Path-related environment correctly" >&2 fi;; ${home}/.public_html/*.cgi) case `stat -O -p ${dir}` in *[2367]|*[2367]?) echo "ERROR: Script must lie in directory writable only for owner!" >&2;; esac case `stat -O -p ${file}` in *[2367]|*[2367]?) echo "ERROR: Script must be writable only for owner!" >&2;; esac uid=`id -u` gid=`id -g` test `stat -u ${file}` = ${uid} || \ echo "ERROR: You're not the owner of the script!" >&2 test `stat -g ${file}` = ${gid} || \ echo "ERROR: The script's group is not your group!" >&2 test `stat -u ${dir}` = ${uid} || \ echo "ERROR: You're not the owner of the script's directory!" >&2 test `stat -g ${dir}` = ${gid} || \ echo "ERROR: The script's directory's group is not your group!" >&2 test ${uid} -lt 100 && \ echo "ERROR: Your user id is below 100!" >&2 test ${gid} -lt 100 && \ echo "ERROR: Your group id is below 100!" >&2 cd ${dir} script=`echo ${file} | sed "s%\`dirname ${HOME}\`/\([^/]*\)/.public_html%/~\1%"`;; ${home}/.public_html/*) echo "ERROR: Script must have .cgi extension" >&2 script=`echo ${file} | sed "s%\`dirname ${HOME}\`/\([^/]*\)/.public_html%/~\1%"`;; *) script=${file} echo "ERROR: Script must have .cgi extension and lie in ~/.public_html" >&2 echo "WARNING: Unable to set Script-Path-related environment correctly" >&2;; esac # # Set environment, call cgi-script # if test -z "${ssl}"; then if test -z "${post}"; then exec env - \ AUTH_TYPE= \ CONTENT_LENGTH= \ CONTENT_TYPE= \ DOCUMENT_ROOT="${root}/htdocs" \ GATEWAY_INTERFACE="CGI/1.1" \ HTTP_ACCEPT="*/*" \ PATH="${path}" \ PATH_INFO="${pathinfo}" \ PATH_TRANSLATED="${pathtranslated}" \ QUERY_STRING="${querystring}" \ REMOTE_ADDR="${addr}" \ REMOTE_HOST="${host}" \ REMOTE_PORT="7168" \ REMOTE_USER= \ REQUEST_METHOD="GET" \ REQUEST_URI="${script}${pathinfo}" \ SCRIPT_FILENAME="${file}" \ SCRIPT_NAME="${script}" \ SCRIPT_URL="${script}${pathinfo}" \ SCRIPT_URI="http://${servername}${script}${pathinfo}" \ SERVER_ADMIN="${serveradmin}" \ SERVER_NAME="${servername}" \ SERVER_PORT="80" \ SERVER_PROTOCOL="HTTP/1.0" \ SERVER_SIGNATURE= \ SERVER_SOFTWARE="${server}" \ TZ="CET-1CES" \ ${file} ${1+"$@"} else exec env - \ AUTH_TYPE= \ CONTENT_LENGTH="`stat -s ${post}`" \ CONTENT_TYPE="application/x-www-form-urlencoded" \ DOCUMENT_ROOT="${root}/htdocs" \ GATEWAY_INTERFACE="CGI/1.1" \ HTTP_ACCEPT="*/*" \ PATH="${path}" \ PATH_INFO="${pathinfo}" \ PATH_TRANSLATED="${pathtranslated}" \ QUERY_STRING="${querystring}" \ REMOTE_ADDR="${addr}" \ REMOTE_HOST="${host}" \ REMOTE_PORT="7168" \ REMOTE_USER= \ REQUEST_METHOD="POST" \ REQUEST_URI="${script}${pathinfo}" \ SCRIPT_FILENAME="${file}" \ SCRIPT_NAME="${script}" \ SCRIPT_URL="${script}${pathinfo}" \ SCRIPT_URI="http://${servername}${script}${pathinfo}" \ SERVER_ADMIN="${serveradmin}" \ SERVER_NAME="${servername}" \ SERVER_PORT="80" \ SERVER_PROTOCOL="HTTP/1.0" \ SERVER_SIGNATURE= \ SERVER_SOFTWARE="${server}" \ TZ="CET-1CES" \ ${file} ${1+"$@"} <${post} fi else if test -z "${post}"; then exec env - \ AUTH_TYPE= \ CONTENT_LENGTH= \ CONTENT_TYPE= \ DOCUMENT_ROOT="${root}/htdocs" \ GATEWAY_INTERFACE="CGI/1.1" \ HTTPS="on" \ HTTP_ACCEPT="*/*" \ PATH="${path}" \ PATH_INFO="${pathinfo}" \ PATH_TRANSLATED="${pathtranslated}" \ QUERY_STRING="${querystring}" \ REMOTE_ADDR="${addr}" \ REMOTE_HOST="${host}" \ REMOTE_PORT="7168" \ REMOTE_USER= \ REQUEST_METHOD="GET" \ REQUEST_URI="${script}${pathinfo}" \ SCRIPT_FILENAME="${file}" \ SCRIPT_NAME="${script}" \ SCRIPT_URL="${script}${pathinfo}" \ SCRIPT_URI="http://${servername}${script}${pathinfo}" \ SERVER_ADMIN="${serveradmin}" \ SERVER_NAME="${servername}" \ SERVER_PORT="80" \ SERVER_PROTOCOL="HTTP/1.0" \ SERVER_SIGNATURE= \ SERVER_SOFTWARE="${server}" \ SSL_CIPHER="RC4-MD5" \ SSL_CIPHER_ALGKEYSIZE="128" \ SSL_CIPHER_EXPORT="false" \ SSL_CIPHER_USEKEYSIZE="128" \ SSL_CLIENT_VERIFY="NONE" \ SSL_PROTOCOL="SSLv3" \ TZ="CET-1CES" \ ${file} ${1+"$@"} else exec env - \ AUTH_TYPE= \ CONTENT_LENGTH="`stat -s ${post}`" \ CONTENT_TYPE="application/x-www-form-urlencoded" \ DOCUMENT_ROOT="${root}/htdocs" \ GATEWAY_INTERFACE="CGI/1.1" \ HTTPS="on" \ HTTP_ACCEPT="*/*" \ PATH="${path}" \ PATH_INFO="${pathinfo}" \ PATH_TRANSLATED="${pathtranslated}" \ QUERY_STRING="${querystring}" \ REMOTE_ADDR="${addr}" \ REMOTE_HOST="${host}" \ REMOTE_PORT="7168" \ REMOTE_USER= \ REQUEST_METHOD="POST" \ REQUEST_URI="${script}${pathinfo}" \ SCRIPT_FILENAME="${file}" \ SCRIPT_NAME="${script}" \ SCRIPT_URL="${script}${pathinfo}" \ SCRIPT_URI="http://${servername}${script}${pathinfo}" \ SERVER_ADMIN="${serveradmin}" \ SERVER_NAME="${servername}" \ SERVER_PORT="80" \ SERVER_PROTOCOL="HTTP/1.0" \ SERVER_SIGNATURE= \ SERVER_SOFTWARE="${server}" \ SSL_CIPHER="RC4-MD5" \ SSL_CIPHER_ALGKEYSIZE="128" \ SSL_CIPHER_EXPORT="false" \ SSL_CIPHER_USEKEYSIZE="128" \ SSL_CLIENT_VERIFY="NONE" \ SSL_PROTOCOL="SSLv3" \ TZ="CET-1CES" \ ${file} ${1+"$@"} <${post} fi fi