Text File

#!/bin/sh # # @(#) pwmenu 1.3 94/12/04 01:15:43 # # pwmenu - A gn "exec7" script to password-protect a menu. # # Chip Rosenthal # Unicom Systems Development # <chip@chinacat.unicom.com> # http://www.unicom.com/ # # Edit at tabstops=4. # # Please adjust the GN_ROOT definition accordingly. # # This should be used with a menu entry such as: # # # This menu file is in /subdir # Name=A Restricted Menu (password required for access) # Path=exec7:/path/to/restricted/dir:/subdir/pwmenu # ContentType=text/html # # Two files are required by this script: # # /path/to/restricted/dir/.cache # # The .cache file to serve if authorization is granted. # # /path/to/restricted/dir/.passwd # # A plain text file with a single line -- the password # that must be given to access this directory. (Blank # lines and "#" comment lines may appear in this file.) #

USAGE="usage: $0 directory [password]" GN_ROOT=/pub/web DEBUG=0

if [ -ne 0 ] ; then # Enable debugging. exec 2>/tmp/pwmenu.log set -xv /local/bin/forktest $0 "$@" 1>&2 else # Force stderr into sync with stdout. exec 2>&1 fi

send_error() { if [ "" = "html" ] ; then echo "<HTML><BODY>$@</BODY></HTML>" else echo "i$@ i/ www.unicom.com 80" fi exit 0 }

case "$#" in 1) dir="$1" password= out_format=html ;; 2) dir="$1" password="$2" out_format=cache ;; *) out_format=cache ; send_error "" ;; esac

test -f "${GN_ROOT}${dir}/.cache" || \ send_error "Error - cannot locate cache file." test -f "${GN_ROOT}${dir}/.passwd" || \ send_error "Error - cannot locate password file."

case "" in

html) cat << 'EOM' <HTML> <HEADER> <TITLE>Please enter password.</TITLE> </HEADER> <BODY> Access to this directory is restricted. Please enter password. <ISINDEX> </BODY> </HTML> EOM ;;

cache) PASSWORD=`sed -e '/^#/d' -e '/^$/d' -e q "${GN_ROOT}${dir}/.passwd"` if [ "X" != "X" ] ; then send_error "Password incorrect." fi cat "${GN_ROOT}${dir}/.cache" ;;

esac

exit 0