#!/bin/sh # $Header: /xxx2.cgi /main/f2admintools/1 2000/12/06 15:54:0 bediger $ # Fully-qualified path names of certain key executables. # If PATH env var is unset by HTTP daemon, or by mistake, these need to # be fully qualified. May change from platform to platform. ENVPROG=/usr/bin/printenv if [ ! -x "$ENVPROG" ] then for DIR in /bin /usr/bin /usr/sbin do for FILE in printenv env do if [ -f $DIR/$FILE -a -x $DIR/$FILE ] then ENVPROG=$DIR/$FILE fi done done fi DATEPROG=/bin/date if [ ! -x "$DATEPROG" ] then DATEPROG=`which date 2>/dev/null` fi PWDPROG=/bin/pwd if [ ! -x "$PWDPROG" ] then PWDPROG=`which pwd 2>/dev/null` fi # what actually gets put on the output by the tty driver, eh? echo 'Content-type: text/html ' echo ' ' echo '' if [ -n "$HTTP_REFERER" ] then REFERER=`basename $HTTP_REFERER` echo "Refered from: $REFERER" else echo 'CGI Playground!!!!' fi echo '' echo '

CGI sh script - $Header: /xxx2.cgi /main/f2admintools/1 2000/12/06 15:54:0 bediger $

' UNAMEPROG=`which uname 2> /dev/null` if [ -x "$UNAMEPROG" ] then echo '
' echo "

System Type

" echo '
'
	$UNAMEPROG -a
	echo '
' fi if [ -n "$REMOTE_HOST" ] then echo "

Remote host at $REMOTE_HOST

" NSLOOKUPPROG=`which nslookup 2>/dev/null` if [ -n "$NSLOOKUPPROG" ] then echo '

'
		$NSLOOKUPPROG $REMOTE_HOST 2>&1
		echo '

' fi else echo '

No remote host data

' fi if [ -n "$REMOTE_ADDR" ] then echo "

Remote address is $REMOTE_ADDR

" NSLOOKUPPROG=`which nslookup 2>/dev/null` if [ -n "$NSLOOKUPPROG" ] then echo '

'
		$NSLOOKUPPROG $REMOTE_ADDR 2>&1
		echo '

' fi fi IDPROG=`which id 2>/dev/null` WHOPROG=`which whoami 2>/dev/null` if [ -x "$IDPROG" -o -x "$WHOPROG" ] then echo '
' echo "

Identity of CGI-BIN program

" if [ -x "$IDPROG" ] then echo "

id program ($IDPROG) says this ran as " `$IDPROG` "

" fi if [ -x "$WHOPROG" ] then echo "

whoami program ($WHOPROG) says this ran as " `$WHOPROG` "

" fi # Try one more stunt to get additional identity information WHOPROG=`which who 2>/dev/null` if [ -x "$WHOPROG" ] then WHO=`$WHOPROG am i 2>/dev/null` if [ ! -z "$WHO" ] then echo "

who am i says: $WHO

" fi fi fi echo '
' if [ -x "$PWDPROG" ] then echo "

Current Working Directory

" echo "

pwd program ($PWDPROG) says working directory is "`$PWDPROG`"

" else echo "

pwd program "$PWDPROG"

doesn't exist or is not marked executable" fi echo '
' # Solaris 2.6 and HP-UX 10.20 have "ulimit". SunOS 4.1.3 does not. # NetBSD 1.3.2 does not. Red Hat Linux 5.0 does not. Still, it's # nice to know this stuff when you can. LIMITPROG=`which ulimit 2>/dev/null` if [ -x "$LIMITPROG" ] then echo "

Limits

" echo '
'
	$LIMITPROG -a
	echo '
' echo '
' fi QUOTAPROG=`which quota 2>/dev/null` if [ -x "$QUOTAPROG" ] then if [ -x "$PWDPROG" ] then CWD=`$PWDPROG` echo "

Disk quota of $CWD

" else echo "

Disk quota

" fi echo '
'
	$QUOTAPROG
	echo '
' echo '
' fi DUPROG=`which du` if [ -x "$DUPROG" ] then CWD= echo "

Disk usage

" echo '
'
	$DUPROG -k -s
	echo '
' echo '
' fi # This next information seems more useful under Solaris than Linux if test -d /proc/$$/fd then echo "

File Descriptors

" echo '
'
	for name in /proc/$$/fd/*
	do
    	file $name
	done
	echo '

' fi if [ -x "$DATEPROG" ] then echo "

Time

" echo 'Date on this server: ' `$DATEPROG` '' echo '

' fi echo '


' echo "

HTTP Referrer

" if [ -n "$HTTP_REFERER" ] then echo "Referred by $HTTP_REFERER" else echo "No HTTP referrer data" fi echo '
' echo "

Command line

" echo "

CGI-BIN program called as \"$0\"

" echo "
"
if [ $# -gt 0 ]
then
	echo $*
else
	echo "No arguments"
fi
echo "
" echo '
' echo "

CGI Specified environment variables

" echo "" echo "" echo "" echo "" echo "" echo "" echo "" echo "" echo "" echo "" echo "" echo "" echo "" echo "" echo "" echo "" echo "" echo "" echo "" echo "" echo "
SERVER_SOFTWARE$SERVER_SOFTWARE
SERVER_NAME$SERVER_NAME
GATEWAY_INTERFACE$GATEWAY_INTERFACE
SERVER_PROTOCOL$SERVER_PROTOCOL
SERVER_PORT$SERVER_PORT
REQUEST_METHOD$REQUEST_METHOD
PATH_INFO$PATH_INFO
PATH_TRANSLATED$PATH_TRANSLATED
SCRIPT_NAME$SCRIPT_NAME
QUERY_STRING$QUERY_STRING
REMOTE_HOST$REMOTE_HOST
REMOTE_ADDR$REMOTE_ADDR
AUTH_TYPE$AUTH_TYPE
REMOTE_USER$REMOTE_USER
REMOTE_IDENT$REMOTE_IDENT
CONTENT_TYPE$CONTENT_TYPE
CONTENT_LENGTH$CONTENT_LENGTH
HTTP_ACCEPT$HTTP_ACCEPT
HTTP_USER_AGENT$HTTP_USER_AGENT
" echo '
' echo "

All Environment variables

" if [ -x "$ENVPROG" ] then echo "
"

	if $ENVPROG 2>&1
	then
		echo 
	else
		echo "Printing environment variables failed: printenv returned \"$?\""
	fi
	echo "
" else echo "

Environment printing program \"$ENVPROG\" missing or not marked executable

" fi echo '
' TIMEOUT="" echo "

Request method: $REQUEST_METHOD

" if [ "$REQUEST_METHOD" = "POST" ] then echo "

Apparently called by a POST, here's what's on stdin:

" echo "
"
	cat > /tmp/post_$$
	cat /tmp/post_$$
	echo "
" echo '

stdin massaged into lines

' echo '

' echo "

"
	#./url_decode.pl `cat /tmp/post_$$`
	cat /tmp/post_$$ | tr '&+' '\012 '
	echo ""
	echo "
" echo "

CONTENT_LENGTH is $CONTENT_LENGTH.
" echo " Count of chars on stdin: " `cat /tmp/post_$$ | wc -c` '

' echo >> /tmp/post_$$; # see if you can guess what this does # Hidden bonus function: if url-encoded name/value pair with name 'timeout' # exists, sleep for as man seconds as that pair's value part. TIMEOUT=`cat /tmp/post_$$ | tr '&+' '\012 ' | grep 'timeout=' |sed 's/timeout=//'` rm /tmp/post_$$; elif [ "$REQUEST_METHOD" = "GET" ] then echo '

Apparently called by a GET

' if [ -n "$QUERY_STRING" ] then echo "

QUERY_STRING is "$QUERY_STRING"

" echo '

QUERY_STRING massaged into lines

'
		echo "$QUERY_STRING" | tr '&+' '\012 '
		#echo ""
		#./url_decode.pl "$QUERY_STRING"
		echo "

" else echo "

No or zero-length QUERY_STRING

" fi TIMEOUT=`echo "$QUERY_STRING" | tr '&+' '\012 ' | grep 'timeout=' |sed 's/timeout=//'` else echo '

' "Some unknown REQUEST_METHOD: \"$REQUEST_METHOD\"" '

' fi echo '
' if [ ! -z "$TIMEOUT" ] then echo "

Sleeping for $TIMEOUT seconds
" sleep $TIMEOUT echo "

Done!

" fi echo "" echo "" exit 0