#!/bin/sh
#
# menu.sh - generic main menu
#
#	Checks user's group memberships and acts accordingly
#

ISPUTIL="/var/lib/ISPutil"

tty_now=`tty | cut -b1-9`
if [ "$tty_now" = "/dev/ttyS" ]; then
  exec super slipin.sh
fi

#if [ "$host" = "ridge" -o "$host" = "peak" ]; then
#  #if [ "$DISPLAY" = "" ]; then
#     /usr/bin/menu
#     exec reset
#  #fi
#fi


# check user's group memberships:
groups=`id -Gn`
sysop=
staff=
sales=
slipin=
for g in `id -Gn` ; do
  case "$g" in
    sysop) sysop=TRUE ;;
    staff) staff=TRUE ;;
    sales) sales=TRUE ;;
    slipin) slipin=TRUE ;;
    users) users=TRUE ;;
  esac
done

# run appropriate menu based on group memberships:
if [ "$sysop" = "TRUE" ]; then
  exec $ISPUTIL/menus/sysopmenu
fi
if [ "$staff" = "TRUE" ]; then
  exec $ISPUTIL/menus/staffmenu
fi
if [ "$sales" = "TRUE" ]; then
  exec $ISPUTIL/menus/sellermenu
fi
if [ "$users" = "TRUE" ]; then
  exec $ISPUTIL/menus/usermenu
fi
if [ "$slipin" != "TRUE" ]; then
  exec $ISPUTIL/menus/guestmenu
fi

HOSTNAME=`hostname`
DNSDOMAINNAME=`dnsdomainname`
TITLE="$HOSTNAME.$DNSDOMAINNAME User"
EDITOR="/usr/bin/pico -t"
VISUAL="$EDITOR"
SUPER="/usr/bin/super"


DONE=
while [ -z $DONE ]; do
	reset
	dialog --title " $TITLE " \
	--menu   "MAIN MENU" 16 50 9 \
	"BACK"   "Back from menu" \
	"CHAT"   "Online Chat" \
	"DISK"   "Disk quotas" \
	"HELP"   "Write for help" \
	"LOGIN"  "Change login password" \
	"ONLINE" "See who is online" \
	"PPP"    "Change account to PPP" \
	"SLIP"   "Change account to SLIP" \
	"TIME"   "Buy extra online time" \
	"X=EXIT" "Exit this menu" 2> /tmp/menu.tmp.$$
	if [ $? = 1 -o $? = 255 ]; then
		/bin/rm -f /tmp/tmpmsg.$$ /tmp/menu.tmp.$$
		exit
	fi
	choice=`cat /tmp/menu.tmp.$$`
	/bin/rm -f /tmp/menu.tmp.$$

        if [ "$choice" = "BACK" ]; then
        DONE=DONE
        fi
        if [ "$choice" = "CHAT" ]; then
        /usr/local/bin/vchat
        fi
        if [ "$choice" = "DISK" ]; then
        /usr/sbin/quota >/tmp/menu.tmp.$$
        dialog --title "Disk Quotas" \
        --textbox /tmp/menu.tmp.$$ 18 76
        /bin/rm -f /tmp/menu.tmp.$$
        fi
        if [ "$choice" = "HELP" ]; then
        /usr/bin/feedback
        fi
        if [ "$choice" = "LOGIN" ]; then
        /usr/bin/passwd
        fi
	if [ "$choice" = "ONLINE" ]; then
	/usr/bin/finger @dialup1 > /tmp/menu.tmp.$$
        dialog --title "Users Online" \
        --textbox /tmp/menu.tmp.$$ 18 76
        /bin/rm -f /tmp/menu.tmp.$$
        fi
        if [ "$choice" = "PPP" ]; then
        $SUPER ch2ppp.sh
        fi
        if [ "$choice" = "SLIP" ]; then
        $SUPER ch2slip.sh
        fi
        if [ "$choice" = "TIME" ]; then
        $SUPER buytime.sh
        fi
        if [ "$choice" = "X=EXIT" ]; then
        DONE=DONE
        fi
done
