#!/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 # # 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 $GN_ROOT/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: # # $GN_ROOT/path/to/restricted/dir/.cache # # The .cache file to serve if authorization is granted. # # $GN_ROOT/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 [ $DEBUG -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 [ "$out_format" = "html" ] ; then echo "$@" 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 "$USAGE" ;; 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 "$out_format" in html) cat << 'EOM'
Please enter password.
Access to this directory is restricted. Please enter password. EOM ;; cache) PASSWORD=`sed -e '/^#/d' -e '/^$/d' -e q "${GN_ROOT}${dir}/.passwd"` if [ "X$password" != "X$PASSWORD" ] ; then send_error "Password incorrect." fi cat "${GN_ROOT}${dir}/.cache" ;; esac exit 0