#!/bin/sh
#
# staffmenu.sh - menu for staff
#


# these will get substituted at install if up against left margin

ISPUTIL="/var/lib/ISPutil"
HOSTNAME=`hostname`
DNSDOMAINNAME=`dnsdomainname`
EDITOR="/usr/bin/pico -t"
VISUAL="$EDITOR"
QUOTA="/usr/bin/quota"
SUPER="/usr/bin/super"
AWK="/usr/bin/awk"
CHAT="/usr/local/bin/vchat -s peak"

# these will not get substituted at install because not against margin

 TITLE="$HOSTNAME.$DNSDOMAINNAME Staff"


#
# the actual menus
#

ureports()
{
RDONE=
while [ -z $RDONE ]; do
	reset
	dialog --title " $TITLE" \
        --menu "Reports and Lists" 14 50 7 \
	"BACK"   "Back out of menu" \
        "DISK"   "Disk quotas" \
        "FIRST"  "Users by firstname" \
	"IDNUM"  "Users by UID number" \
        "NEW"    "New (unvalidated) users" \
        "ONLINE" "Online users" \
        "UNAME"  "Users by username" \
        "X=EXIT" "Exit Menu" 2> /tmp/stmenu.$$
        if [ $? = 1 -o $? = 255 ]; then
                /bin/rm -f /tmp/stmenu.$$
                exit
        fi
        rchoice=`cat /tmp/stmenu.$$`
        /bin/rm -f /tmp/stmenu.$$

        if [ "$rchoice" = "BACK" ]; then
        RDONE=DONE
        fi
        if [ "$rchoice" = "DISK" ]; then
        $SUPER repquota -a >/tmp/stmenu.$$
        dialog --title "User disk quotas" \
        --textbox /tmp/stmenu.$$ 18 76
        /bin/rm -f /tmp/stmenu.$$
        fi
        if [ "$rchoice" = "FIRST" ]; then
	cat /etc/passwd | sort -fdbit ":" +4 \
		| $AWK -f $ISPUTIL/util/rusrlist.awk > /tmp/stmenu.$$
	dialog --title "${HOSTNAME}'s Users" \
	--textbox /tmp/stmenu.$$ 22 76
	/bin/rm -f /tmp/stmenu.$$   
        fi
        if [ "$rchoice" = "IDNUM" ]; then
	cat /etc/passwd | sort -rfndbit ":" +2 \
		| $AWK -f $ISPUTIL/util/rusrlist.awk > /tmp/stmenu.$$
	dialog --title "${HOSTNAME}'s Users" \
	--textbox /tmp/stmenu.$$ 22 76
	/bin/rm -f /tmp/stmenu.$$
        fi
        if [ "$rchoice" = "NEW" ]; then
	cat /etc/passwd | sort -fndbit ":" +2 \
		| $AWK -f $ISPUTIL/util/nusrlist.awk > /tmp/stmenu.$$
	dialog --title "${HOSTNAME}: Unvalidated Users" \
	--textbox /tmp/stmenu.$$ 22 76
	/bin/rm -f /tmp/stmenu.$$      
        fi
	if [ "$rchoice" = "ONLINE" ]; then
	/usr/bin/finger @dialup1 > /tmp/stmenu.$$
        dialog --title "Users Online" \
        --textbox /tmp/stmenu.$$ 22 76
        /bin/rm -f /tmp/stmenu.$$
        fi
        if [ "$rchoice" = "UNAME" ]; then
	cat /etc/passwd | sort -fdbit ":" \
		| $AWK -f $ISPUTIL/util/rusrlist.awk > /tmp/stmenu.$$
	dialog --title "${HOSTNAME}'s Users" \
	--textbox /tmp/stmenu.$$ 22 76
	/bin/rm -f /tmp/stmenu.$$
        fi
        if [ "$rchoice" = "X=EXIT" ]; then
        RDONE=DONE
        fi
done
}


tsale()
{
TDONE=
while [ -z $TDONE ]; do
        reset
	dialog --title " $TITLE" \
		--menu "Online Time Sales" 10 50 4 \
		"BACK"   "Back out of menu" \
		"1"      "1 block of 15 hours" \
		"2"  "2 blocks of 15 hours" \
		"3"    "3 blocks of 15 hours" \
	        "X=EXIT" "Exit this menu" 2> /tmp/stmenu.$$
        if [ $? = 1 -o $? = 255 ]; then
                /bin/rm -f /tmp/stmenu.$$
                exit
        fi
	mchoice=`cat /tmp/stmenu.$$`
        /bin/rm -f /tmp/stmenu.$$
        if [ "$mchoice" = "BACK" ]; then
        TDONE=DONE
        fi
        if [ "$mchoice" = "1" ]; then
        $SUPER selltime.sh
        fi
        if [ "$mchoice" = "2" ]; then
        $SUPER selltime2.sh
        fi
        if [ "$mchoice" = "3" ]; then
        $SUPER selltime3.sh
        fi
        if [ "$mchoice" = "X=EXIT" ]; then
        TDONE=DONE
        fi
done
}


msale()
{
MSDONE=
while [ -z $MSDONE ]; do
        reset
	dialog --title " $TITLE" \
		--menu "Sell Months of Access" 10 55 4 \
		"BACK"   "Back out of menu" \
		"1"      "1 month internet access" \
		"2"  "2 months internet access" \
		"3"    "3 months internet access" \
	        "X=EXIT" "Exit this menu" 2> /tmp/stmenu.$$
        if [ $? = 1 -o $? = 255 ]; then
                /bin/rm -f /tmp/stmenu.$$
                exit
        fi
	mchoice=`cat /tmp/stmenu.$$`
        /bin/rm -f /tmp/stmenu.$$
        if [ "$mchoice" = "BACK" ]; then
        MSDONE=DONE
        fi
        if [ "$mchoice" = "1" ]; then
        $SUPER sellmonth.sh
        fi
        if [ "$mchoice" = "2" ]; then
        $SUPER sellmonth2.sh
        fi
        if [ "$mchoice" = "3" ]; then
        $SUPER sellmonth3.sh
        fi
        if [ "$mchoice" = "X=EXIT" ]; then
        MSDONE=DONE
        fi
done
}


modify()
{
MDONE=
while [ -z $MDONE ]; do
        reset
	if [ -z $DISPLAY ]; then
	        dialog --title " $TITLE" \
	        --menu "User Account Admninistration" 15 50 8 \
		"BACK"   "Back out of menu" \
		"KITS"   "Kits for users" \
		"LISTS"  "Lists and Reports" \
		"MONTHS" "Sell Months of Access" \
		"NEW"    "New user account" \
		"PPP"    "PPP user" \
		"SLIP"   "SLIP user" \
		"TIME"   "Sell Online Time" \
	        "X=EXIT" "Exit this menu" 2> /tmp/stmenu.$$
	else
	        dialog --title " $TITLE" \
	        --menu "User Account Admninistration" 16 50 9 \
		"BACK"   "Back out of menu" \
		"DB"     "Database (Xwindows)" \
		"KITS"   "Kits for users" \
		"LISTS"  "Lists and Reports" \
		"MONTHS" "Sell Months of Access" \
		"NEW"    "New user account" \
		"PPP"    "PPP user" \
		"SLIP"   "SLIP user" \
		"TIME"   "Sell Online Time" \
	        "X=EXIT" "Exit this menu" 2> /tmp/stmenu.$$
	fi
        if [ $? = 1 -o $? = 255 ]; then
                /bin/rm -f /tmp/stmenu.$$
                exit
        fi
	mchoice=`cat /tmp/stmenu.$$`
        /bin/rm -f /tmp/stmenu.$$

        if [ "$mchoice" = "BACK" ]; then
        MDONE=DONE
        fi
        if [ "$mchoice" = "DB" ]; then
        $SUPER launch clients
        fi
        if [ "$mchoice" = "KITS" ]; then
        $ISPUTIL/util/kitsmenu.sh
        fi
        if [ "$mchoice" = "LISTS" ]; then
        ureports
        fi
        if [ "$mchoice" = "MONTHS" ]; then
        msale
        fi
        if [ "$mchoice" = "NEW" ]; then
        $SUPER user_new
        fi
        if [ "$mchoice" = "PPP" ]; then
        $SUPER makeppp.sh
        fi
        if [ "$mchoice" = "SLIP" ]; then
        $SUPER makeslip.sh
        fi
        if [ "$mchoice" = "TIME" ]; then
        tsale
        fi
        if [ "$mchoice" = "X=EXIT" ]; then
        MDONE=DONE
        fi
done
}


if [ "$SHELL" = "/bin/bash" ]; then
	bashaccess=
else
	bashaccess=NO
fi

DONE=
while [ -z $DONE ]; do
	reset
	if [ "$bashaccess" = "" ]; then
		dialog --title " $TITLE " \
		--menu "MAIN MENU" 16 50 8 \
		"ADMIN"	 "User administration" \
		"BACK"	 "Back out of menu" \
		"CHAT"	 "Online Chat" \
		"DISK"   "Disk Quota" \
		"LOGIN"  "Change login password" \
		"ONLINE" "See who is online" \
		"PPP"	 "Change account to PPP" \
		"SLIP"	 "Change account to SLIP" \
		"X=EXIT" "Exit this menu" \
		"UNIX"	 "Unix shell (bash)" 2> /tmp/stmenu.$$
	else
		dialog --title " $TITLE " \
		--menu "MAIN MENU" 16 50 8 \
		"ADMIN"	 "User administration" \
		"BACK"	 "Back out of menu" \
		"CHAT"	 "Online Chat" \
		"DISK"   "Disk Quota" \
		"LOGIN"  "Change login password" \
		"ONLINE" "See who is online" \
		"PPP"	 "Change account to PPP" \
		"SLIP"	 "Change account to SLIP" \
		"X=EXIT" "Exit this menu" 2> /tmp/stmenu.$$
	fi
	if [ $? = 1 -o $? = 255 ]; then
		/bin/rm -f /tmp/stmenu.$$
		exit
	fi
	choice=`cat /tmp/stmenu.$$`
	/bin/rm -f /tmp/stmenu.$$

        if [ "$choice" = "ADMIN" ]; then
          modify
        fi
        if [ "$choice" = "BACK" ]; then
          DONE=DONE
        fi
        if [ "$choice" = "CHAT" ]; then
          $CHAT
        fi
        if [ "$choice" = "PPP" ]; then
          $SUPER ch2ppp.sh
        fi
        if [ "$choice" = "SLIP" ]; then
          $SUPER ch2slip.sh
        fi
        if [ "$choice" = "DISK" ]; then
          /usr/sbin/quota -v >/tmp/stmenu.$$
          dialog --title "Disk Quotas" \
		--textbox /tmp/stmenu.$$ 18 76
          /bin/rm -f /tmp/stmenu.$$
        fi
        if [ "$choice" = "LOGIN" ]; then
          /usr/bin/passwd
        fi
	if [ "$choice" = "ONLINE" ]; then
	  /usr/bin/finger @dialup1 > /tmp/stmenu.$$
          dialog --title "Users Online" \
		--textbox /tmp/stmenu.$$ 18 76
          /bin/rm -f /tmp/stmenu.$$
        fi
#        if [ "$choice" = "TIME" ]; then
#          $SUPER buytime.sh
#        fi
        if [ "$choice" = "X=EXIT" ]; then
          DONE=DONE
        fi
        if [ "$choice" = "UNIX" ]; then
          rm -f $HOME/.menu_lock
	  exit
        fi
done
