Cover V03, I03
Article
Listing 1
Listing 2
Sidebar 1

may94.tar


Listing 2: menu

:
# Main Login Menu Template - Listing 2
# Fred Lenk 11/5/93
#
# The overall goal of this login menu, and the way it is run from the .profile
# is to never give the rsh customer access to the Unix command line.  This
# provides a good deal of security as well as "protecting" users untrained
# in Unix computers.  We essentially give the customers pushbutton access to
# the utilities they are authorized to use.
#
#
# This menu is run after executing the user's $HOME/.profile.  In the case of
# restricted shell (rsh) users, the menu is located in the $HOME/bin directory
# as $HOME/bin/.menu and is linked to a master copy of the login menu named
# /usr/public/menu.  The menu is started as the last action in the .profile
# with the login PID as the only parameter:
#   exec $HOME/bin/.menu $$.
# On Oracle DB hosts, this login menu is started as:
#   exec /usr/lbin/Xoraenv $HOME/bin/.menu $$
# where Xoraenv is Oracle's oraenv customized for the particular host.
# The PID is used to insure that when the user leaves or otherwise is detached
# from the host, the user's login process is killed.  This prevents
# unauthorized access to the command line, and deminishes the possibility
# that the next person to attach to the tty port will not accidentally
# attach to the earlier user's session.
#
# The echoto utility may be used to maintain login and program usage logs.
# Example of recording usage:
#   echoto $record_use "ProgramID start $LOGNAME `ftim` `date '+%D %T'`"
#   begtim=`ftim`
#   Run_Unix_Command_Here
#   endtim=`ftim`
#   diftim=`expr $endtim - $begtim`
#   echoto $record_use "ProgramID stop $LOGNAME $endtim `date '+%D %T'` SECONDS: $diftim"
# Suggestion: Always make sure each record added to the $record_use log file
# has the same number of parameters always in the exact same positions.  This
# will allow the SysAdmin to easily & efficiently retrieve all kinds of data.
#
# ANNOUNCEMENTS: This script expects that announcements will be kept in
# /usr/public/msgs as numbered files (1.msg, 2.msg, ... n.msg).  The file
# /usr/public/msgs/describe is a short file listing the available messages.
#     1) Announcement about this
#     2) Announcement about that
#     3) Announcement about the other
# The selection number corresponds to the file name.  As provided in this
# script, the number of announcements is limited to about 20.
#
###############################################################################
# Custom C utilities used by this program:                                    #
#                                                                             #
# ftim     : Displays time in seconds since 1/1/70 00:00:00 GMT + TZ.         #
#          : Used when recording time to log files.  Such time stamps are     #
#          : easier to manipulate and compare than those produced by `date`.  #
#          : See fcvtim and fgotim for conversion utilities.                  #
# menucat  : a safe restricted version of Unix's cat which hard-codes         #
#          : directories from which files may be read.  Only needed for       #
#          : rsh users.
# termlock : password protected terminal locker which inactivates system      #
#          : idle-out timer, but provides 1 hour timeout.                     #
# echoto   : utility which substitutes for >> which is illegal in rsh. Only   #
#          : needed for rsh users.
# pager    : A simple to use, custom, read-only file browser, with download   #
#          : capabilities.  Use any secure file viewer available on host.     #
###############################################################################
#                                                                             #
###############################################################################
#ESTABLISH GLOBAL VARIABLES AND DO OTHER MENU INITIALIZATION ROUTINES HERE
#
PID=$1 # passed from SCO rsh user's .profile used for sure kill on exit
version="11/04/93"
sttystring=`stty -g` #get stty mode while still good
public="/usr/public"
msgs="$public/msgs"
#record_use is db flat file to record logins, program usage.  Must be in
#  a directory writeable by all
#record_use="/usr/spool/uucppublic/record_use"  #production log file
record_use="/tmp/menulog.log"  #test & debug
#Record user's login (Main Login Menu access) time
logintim=`ftim`
echoto $record_use "LOG IN $LOGNAME $logintim `date '+%D %T'`"
#Save info about user's last Main Login Menu access.
rm .termtype
echoto .termtype "$logintim $TERM"

echo  " LOGIN MENU COMING UP `fcvtim $logintim`.  Just a moment..."

bold=`tput smso`
norm=`tput sgr0`
blink=`tput blink`
uline=`tput smul`
reverse=`tput rev`
back=`tput rmso`
#User has terminal which recognizes ANSI color commands
#  The TERM "ansicolor" is a ficticious term type.  SysAdmin substitutes
#  appropriate TERM(s) here
[ "$TERM" = "ansicolor" ] && {
bold=`echo -n "\033[1;33;44m"`  # yellow on blue
norm=`echo -n "\033[1;37;45m"`  # white on pink
back=`echo -n "\033[45m"`       # pink background
reverse=`echo -n "\033[1;37;41m"`  # white on red
#uline=`echo -n "\033[1;33;42m"`  # yellow on green
#uline=`echo -n "\033[0;31;47m"`  # red on white
uline=`echo -n "\033[0;34;47m"`  # blue on white
}

###############################################################################
#     TO MINIMIZE MAINTENANCE, AVOID CREATING NEW GLOBAL VARIABLES OR MENU   #
#     INITIALIZATION ROUTINES PAST THIS POINT.                                #
###############################################################################
# AS YOUR PROJECT REQUIRES MORE AND MORE UTILITIES, ADD SHORT DESCRIPTIONS
# TO THIS MAIN MENU DISPLAY.
#
MainMenu () {
echo
echo "${bold}                                MAIN LOGIN MENU                                "
echo "                                                                               "
echo "${bold}  `date`                                     v.${version}  ${norm}"
echo "
a)                  n)                  A)                  N) NEWS
b)                  o)                  B)                  O)
c)                  p)                  C)                  P)
d)                  q)                  D)                  Q)
e)                  r)                  E)                  R)
f)                  s)                  F)                  S) USER STATUS
g)                  t)                  G)                  T) TERMLOCK
h)                  u)                  H) ANNOUNCEMENTS    U)
i)                  v)                  I)                  V)
j)                  w)                  J)                  W)
k)                  x) EXIT             K)                  X) EXIT
l)                  y) HELP             L)                  Y)
m)  z) REDISPLAY        M)                  Z) CHG PASSWORD
n)  "

echo "Number of Announcements =`ls ${msgs}/*.msg | wc -l|awk '{print \" \"$1}'`"

gotnews=`news -s`
if [ "$gotnews" = "No news." ]
then
echo -n
#dont do anything
else
echo "${blink}${gotnews}${norm}  Use selection \"N\" to read News."
fi
echo "Please enter selection, then press <ENTER>:"
echo " > ${reverse}     \b\b\b\b\b\c"

}
#end Main Login Menu display

##############################################################################
# AS YOU ADD MORE UTILITIES TO THE MAIN MENU ABOVE, YOU SHOULD ADD HELP
# INFORMATION FOR EACH UTILITY.  BRIEFLY DESCRIBE WHATEVER IT IS THE USER
# NEEDS TO KNOW IN ORDER TO USE THE COMMAND.
#
RunHelp() {
echo "On which command would you like assistance? >${bold} ${norm}\b\c"
read cmd
echo $cmd
clear
echo;echo
case "${cmd}"
in

"x" | "X" | "exit")
echo "EXIT the Login Menu and terminate your login session."
;;

"y")
echo "HELP\n"
echo "Use this selection if you need more information about any of the selections
echo "available from the Login Menu.\n"
echo "If you are having problems running your programs, use the Announcements"
echo "selection and select the announcement regarding Program Problems.\n"
echo "The Trouble Desk telephone is 800/555-1212."
"
;;

"z")
echo "REDISPLAY\n"
echo "Refresh Login Menu screen when disturbed by other programs."
echo "or bad datacommunications."
;;

##### UPPER CASE SELECTIONS GO HERE... #####

"H")
echo "ANNOUNCEMENTS\n"
echo "Read system messages.  You should always check to see if there"
echo "are any new messages to make sure you know about special"
echo "service problems, new features, etc.  Announcements are"
echo "removed and updated periodically."
;;

"N")
echo "NEWS FACILITY\n"
echo "This selection allows the user to read messages from the"
echo "Database and System Administrators.  These messages are of a"
echo "nature that they only need to be read once."
;;

"S")
echo "USER STATISTICS\n"
echo "Tell the current login terminal type, current login name and"
echo "time user logged in, current time, who else is currently logged"
echo "in."
echo
;;

"T")
echo "TERMLOCK\n"
echo "Lock your terminal so you can leave it securely for a few minutes."
echo "Standard computer security requires that you never leave your"
echo "terminal while it is logged in, unless you can lock it with a"
echo "password.  You must remember your password or you too will"
echo "not be able to access your terminal."
;;

"Z")
echo "CHANGE PASSWORD\n"
echo "Change your Unix system password.  This does not alter your"
echo "application database password or login.  The user is responsible"
echo "for remembering his own password.  The system administrator"
echo "does not even know your password."
;;

*)
echo "\n  <${cmd}>   Invalid Help Selection."
;;
esac

echo
#end of HELP
}
##############################################################################
##############################################################################

##############################################################################
# THE FOLLOWING SECTION IS THE TRICKIEST.  HERE IS WHERE YOU ADD ANY UNIX
# STATEMENTS REQUIRED TO ACCOMPLISH YOUR WORK.  BE WARNED THAT IF A USER
# TERMINATES A ROUTINE, UTILITY, OR PROGRAM WITH THE UNIX DEL (char 127d),
# THIS MENU MAY ALSO TERMINATE DUE TO THE TRAP.  THIS IS A SECURITY
# PRECAUTION.
#
#
DoSomething() {

cdate=`date '+%m %d %H:%M'`
# With some routines, it may be necessary to break out of the routine
# and DoSomething() and redisplay the Main Login Menu.  In these
# cases, use "break 2".
case "${selection}"
in

"x" | "X" | "exit")
ExitMenu
exit
;;

"y")
RunHelp
;;

"z")
Clear
;;

"N") #example showing how to record start/stop of applications
Clear
echoto $record_use "DoNews start $LOGNAME `ftim` `date '+%D %T'`"
begtim=`ftim`
DoNews
endtim=`ftim`
diftim=`math $endtim - $begtim`
echoto $record_use "DoNews stop $LOGNAME $endtim `date '+%D %T'` SECONDS: $diftim"
;;

"H")
#system messages and announcements
while .
do
echo $norm
Clear
echo "Current system messages are:"
menucat ${msgs}/describe  #a short file listing announcements
echo -n "Please type number of a message to read, or x to quit: "
read ans
if [ "$ans" = "x" -o "$ans" = "X" -o "$ans" =
"q" -o "$ans" = "" ]
then
break
else
pager ${msgs}/${ans}.msg
fi
done
;;

"S")
#Usefull to developers to show what's in user's environment.
Clear
echo "TERM=$TERM"
who -u|grep $LOGNAME|awk '{print "User:" $1 "  TTY:" $2 " Since:"
$3 " " $4 " " $5  "  PST8PDT"}'
echo "Current Time: `date`"
echo "Ulimit: `ulimit`"
echo -n "Press <ENTER> to list environment..."
read junk
env
echo -n "Press <ENTER> to list current users..."
read junk
echo "CURRENT USERS:"
IFS=""
for i in `who|awk '{print $1"\t"$3" "$4" "$5}'`
do
echo "\t$i"
done
echo
;;

"T")
Clear
echo "\nThis selection will prevent others from using this terminal"
echo "while you are away from your terminal.  You will be asked"
echo "to enter a password, which you must remember.  Do you"
echo -n "wish to lock your terminal at this time? (y/n) >"
read ans
if [ "$ans" = "y" ]
then
#FLenk added following warning 7/15/92
echo "\n${uline}${blink}ATTENTION:${norm}"
echo "A 60 minute time limitation has been incorporated into the"
echo "terminal lock program.  That means after 60 minutes, if"
echo "the terminal has not been unlocked, that terminal (and"
echo "the user) will be detached from the host."
echo "\nPlease press <ENTER> to continue. \c"
read junk
termlock
fi
;;

"Z")
Clear
echo "Change Password utility.  You must remember your new"
echo "password because not even the administrator will know"
echo "the changed password!"
echo
echo "You should keep the following in mind when selecting a new"
echo "password:  Should the system become the object of a determined"
echo "illegal user, in the process of cracking login/passwords,"
echo "he/she will try first and last names, and slight variations,"
echo "english language words found in the dictionary, logins "
echo "without passwords.  You should consider including punctuation"
echo "characters, upper/lower case letters.  Passwords should have"
echo "between 6-11 characters.  I like to use words I've found in"
echo "books on American Indian history."
echo "\nBeginning password routine now.\n"
passwd
;;

*)
echo "Selection not presently implemented."
;;
esac

#end of dosomething function
}

############################################################################
############################################################################
############################################################################
#  ADDITIONAL SHELL FUNCTIONS MAY BE ADDED STARTING HERE
############################################################################
ExitMenu() {
#we get here if there is a termination of menu
echo "\n\n\n"
logofftim=`ftim`
usedtim=`expr $logofftim - $logintim`
echoto $record_use "LOG OFF $LOGNAME $logofftim `date '+%D %T'` SECONDS: $usedtim"
echo "Online for $usedtim seconds, about `expr $usedtim \/ 60` minutes."
echo "Login Menu Terminating.  You may disconnect from network connections"
echo "at this time, then terminate your PC terminal emulation if"
echo "necessary."
sleep 2 #8/21/92 FLenk added for datacomm delays

(sleep 2;kill -9 $PID) &  # make sure login process is killed in 2 seconds
exit                      # but first exit this menu
}
##############################################################################
Clear() {
tset
echo -n "$norm$back"
clear
}

##############################################################################
#If there's any news, display each message indivdually.
DoNews() {

OIFS=$IFS
IFS='
'
for i in `ls -t /usr/news/* $HOME/.news_time 2>&1`
do
case $i
in *' not found') ;;
*/.news_time)
echo "No More News."
break
;;
"total*")
#do nothing for total line
;;
*)
echoto junk "`news $i`"
pager junk
rm junk
;;
esac
done
touch $HOME/.news_time
IFS=$OIFS
}

##############################################################################
#Insurance against rogue applications.  SCO Unix may display warning.
FixStty() {
stty $sttystring
#stty sane echoe  #prevents SCO warnings about KBM_XT
}
##############################################################################
#You can get fancy with terminals with musically programmable speakers.
MenuBeep() {
echo -n "\007"
} #end func
##############################################################################

##############################################################################
##############################################################################
##############################################################################
# MAIN PROGRAM LOOP - THE DRIVER FOR ALL PREVIOUS FUNCTIONS

#following trap executes the exit function for exits or bailouts.
trap  "ExitMenu"  1 2 3 15

while .
do
Clear
MainMenu
read selection
echo -n $norm
#echo $selection
DoSomething
FixStty   #just in case application has bombed out
echo "${bold}              ***** PRESS ${blink}<ENTER>${norm}${bold} TO RETURN TO LOGIN
MENU *****                ${norm}\r\c"
MenuBeep
read junk
done
######################################################################
#end of Menu