#!/bin/bash
test -e $HOME/.lock
  if [ $? = 0 ]; then
    clear
    echo You have been locked out.
    echo
    echo REASON:
    cat $HOME/.lock
    echo -=] Press ENTER to Continue [=-
    read paws
    clear
        echo "=--=--------------------=--="
        echo "=--= Closing Connection =--="
        echo "=--=--------------------=--="
    exit
  else
test -e $HOME/.lock.cfg.ed
if [ $? = 0 ]; then
   test -e $HOME/.def.editor
     if [ $? = 0 ]; then
        export EDITOR=`cat $HOME/.def.editor`
     else
       echo blah > /dev/null 2> /dev/null
     fi
else
test -e $HOME/.def.editor
if [ $? = 0 ]; then
 export EDITOR=`cat $HOME/.def.editor`
   else
 dialog --title "Error: EDITOR" \
        --msgbox "You have not selected a default editor. You will now be \
                  given a list of editors which you can use. This will become \
                  your default editor every time you logon. You may change \
                  the editor later by typing lmenu.cfg.ed from the shell. \
                  Or by selecting Configuration and then Editor from the \
                  menu shell. To get to the menu shell from the regular \
                  shell, you may type lmenu from the shell. Thank you." 12 70
 /bin/lmenu.cfg.ed
export EDITOR=`cat $HOME/.def.editor`
fi
fi


test -e $HOME/.lock.cfg.mail
if [ $? = 0 ]; then
   test -e $HOME/.def.mailread
     if [ $? = 0 ]; then
        export EDITOR=`cat $HOME/.def.mailread`
     else
       echo blah > /dev/null 2> /dev/null
     fi
else
test -e $HOME/.def.mailread
if [ $? = 0 ]; then
  export MAILREAD=`cat $HOME/.def.mailread`
     else
  dialog --title "Error: MAIL READER" \
         --msgbox "You have not selected a default mail reader. You will now \
                   be given a list of mail readers which you can use. This will \
                   become your default mail reader every time you logon. You may \
                   change the mail reader later by typing lmenu.cfg.mail from the \
                   shell. Or by selecting Configuration and then Mail Reader from the \
                   menu shell. To get to the menu shell from the regular \
                   shell, you may type lmenu from the shell. Thank you." 12 70                   
 /bin/lmenu.cfg.mail
export MAILREAD=`cat $HOME/.def.mailread`
fi
fi

test -e $HOME/.lock.cfg.ftp
if [ $? = 0 ]; then
   test -e $HOME/.def.ftp
     if [ $? = 0 ]; then
        export EDITOR=`cat $HOME/.def.ftp`
     else
       echo blah > /dev/null 2> /dev/null
     fi
else
test -e $HOME/.def.ftp
if [ $? = 0 ]; then
  export FTPCLIENT=`cat $HOME/.def.ftp`
     else
  dialog --title "Error: FTP CLIENT" \
         --msgbox "You have not selected a default FTP Client. You will now \
                   be given a list of FTP Clients which you can use. This will \
                   become your default FTP Client every time you logon. You may \
                   change the FTP Client later by typing lmenu.cfg.ftp from the \
                   shell. Or by selecting Configuration and then FTP Client from the \
                   menu shell. To get to the menu shell from the regular \
                   shell, you may type lmenu from the shell. Thank you." 12 70                   
 /bin/lmenu.cfg.ftp
export FTPCLIENT=`cat $HOME/.def.ftp`
fi
fi

test -e $HOME/.lock.cfg.shell
if [ $? = 0 ]; then
   test -e $HOME/.def.shell
     if [ $? = 0 ]; then
        export EDITOR=`cat $HOME/.def.shell`
     else
       echo blah > /dev/null 2> /dev/null
     fi
else
test -e $HOME/.def.shell
if [ $? = 0 ]; then
  export DEFSHL=`cat $HOME/.def.shell`
     else
  dialog --title "Error: DEFAULT SHELL" \
         --msgbox "You have not selected a default Shell. You will now \
                   be given a list of Shells which you can use. This will \
                   become your default Shell every time you logon. You may \
                   change the Shell later by typing lmenu.cfg.shell from the \
                   shell. Or by selecting Configuration and then Default Shell \
                   from the menu shell. To get to the menu shell from the regular \
                   shell, you may type lmenu from the shell. Thank you." 12 70                   
 /bin/lmenu.cfg.shell
export DEFSHL=`cat $HOME/.def.shell`
fi
fi

main()
{
clear
while [ 0 ]; do
dialog --title "Welcome to `cat /etc/HOSTNAME`" \
--menu "Main Menu" 18 65 11 \
"I" "IRC       (Internet Relay Chat)" \
"T" "Telnet    (Connect to a remote Computer)" \
"F" "FTP       (File Transfer Protocol)" \
"U" "Usenet    (Internet Discussion Forums)" \
"E" "E-Mail    (Electronic Mail)" \
"W" "WWW       (World Wide Web)" \
"S" "Shell     (UNIX Shell)" \
"P" "SLIP/PPP  (Enable SLIP/PPP Connection)" \
"M" "Misc      (Miscellaneous [finger, talk, etc])" \
"C" "Config    (Personal Configuration)" \
"L" "Logout    (Exit the System)" 2> $HOME/.tmpchoice
if [ $? = 1 -o $? = 255 ]; then
   rm -f $HOME/.tmpmsg $HOME/.tmpchoice
   logout
fi
mainchoice="`cat $HOME/.tmpchoice`"
rm -f $HOME/.tmpchoice $HOME/.tmpmsg

if [ "$mainchoice" = "I" ]; then
    test -e $HOME/.lock.irc
      if [ $? = 0 ]; then
        clear
        echo Access Denied!
        echo
        echo REASON: 
        cat $HOME/.lock.irc
        echo -=] Press ENTER to Continue [=-
        read paws
      else        
	clear
        dialog --inputbox "Please enter any parameters for IRC or just Press Enter." \
        8 70 2> $HOME/.ircchoice
        ircchoice="`cat $HOME/.ircchoice`"
        rm -f $HOME/.ircchoice
        irc $ircchoice       
	echo -=[Press ENTER to Continue]=-
	read paws
fi
fi

if [ "$mainchoice" = "T" ]; then
    test -e $HOME/.lock.telnet
       if [ $? = 0 ]; then
          clear
          echo Access Denied!
          echo 
          echo REASON:
          cat $HOME/.lock.telnet
          echo -=] Press ENTER to Continue [=-
          read paws
       else
 	clear
        dialog --inputbox "Please enter a Telnet site address." 8 70 2> $HOME/.telchoice
        telchoice="`cat $HOME/.telchoice`"
        rm -f $HOME/.telchoice
        clear
        telnet $telchoice
        echo -=[Press ENTER to Continue]=-
        read paws
fi
fi

if [ "$mainchoice" = "F" ]; then
    test -e $HOME/.lock.ftp
       if [ $? = 0 ]; then
         clear
         echo Access Denied!
         echo
         echo REASON: 
         cat $HOME/.lock.ftp
         echo -=] Press ENTER to Continue [=-
         read paws
       else
	clear
        dialog --inputbox "Please Enter an FTP site address." 8 60 2> $HOME/.ftpchoice
        ftpchoice="`cat $HOME/.ftpchoice`"
        rm -f $HOME/.ftpchoice        
	$FTPCLIENT $ftpchoice
	echo -=[Press ENTER to Continue]=-
	read paws
fi
fi

if [ "$mainchoice" = "U" ]; then 
    test -e $HOME/.lock.usenet
       if [ $? = 0 ]; then
         clear
         echo Access Denied!
         echo 
         echo REASON: 
         cat $HOME/.lock.usenet
         echo -=] Press ENTER to Continue [=-
         read paws
       else
        clear
	dialog --inputbox "Please Enter any options for the Newsreader" 8 60 2> $HOME/.newschoice
        newschoice="`cat $HOME/.newschoice`"
        rm -rf $HOME/.newschoice
        rtin $newschoice
	echo -=[Press ENTER to Continue]=-
	read paws
fi
fi

if [ "$mainchoice" = "E" ]; then
    test -e $HOME/.lock.mail
       if [ $? = 0 ]; then
         clear
         echo Access Denied!
         echo
         echo REASON:
         cat $HOME/.lock.mail
         echo -=] Press ENTER to Continue [=-
         read paws
       else
	clear
	dialog --inputbox "Please Enter any options for the Mail Reader" 8 60 2> $HOME/.mailchoice
        mailchoice="`cat $HOME/.mailchoice`"
        rm -rf $HOME/.mailchoice
        $MAILREAD $mailchoice
	echo -=[Press ENTER to Continue]=-
	read paws
fi
fi

if [ "$mainchoice" = "W" ]; then
    test -e $HOME/.lock.www
       if [ $? = 0 ]; then
         clear
         echo Access Denied! 
         echo
         echo REASON:
         cat $HOME/.lock.www
         echo -=] Press ENTER to Continue [=-
         read paws
       else
        dialog --inputbox "Please Enter WWW URL to Go to." 8 60 2> $HOME/.urlchoice
	urlchoice="`cat $HOME/.urlchoice`"
        rm -f $HOME/.urlchoice
        lynx $urlchoice
	echo -=[Press ENTER to Continue]=-
	read paws
fi
fi

if [ "$mainchoice" = "S" ]; then
     test -e $HOME/.lock.shell
         if [ $? = 0 ]; then
           clear
           echo Access Denied!
           echo
           echo REASON:
           cat $HOME/.lock.shell         
           echo -=] Press ENTER to Continu [=-
           read paws
         else
        dialog --inputbox "Please enter program to run or just enter for shell" 8 60 2> $HOME/.shparam
        shparam="`cat $HOME/.shparam`"
        rm -f $HOME/.shparam
        if [ "$shparam" = "" ]; then
           clear
          export PS1="Type ""exit"" to Return: \h:\w\$ "
          $DEFSHL
          export PS1="\h:\w\$ "
        else
          clear
          $shparam
	fi
        echo -=[Press ENTER to Continue]=-
	read paws
fi
fi

if [ "$mainchoice" = "P" ]; then
    test -e $HOME/.lock.slip-ppp
      if [ $? = 0 ]; then
        clear
        echo Access Denied!
        echo
        echo REASON:
        cat $HOME/.lock.slip-ppp
        echo -=] Press ENTER to Continue [=-
        read paws
      else
   dialog --title "SLIP/PPP" \
   --msgbox "SLIP and PPP are NOT available on this system." 5 60
fi
fi

if [ "$mainchoice" = "M" ]; then
     test -e $HOME/.lock.misc
       if [ $? = 0 ]; then
         clear
          echo Access Denied!
          echo
          echo REASON:
          cat $HOME/.lock.misc
          echo -=] Press ENTER to Continue [=-
          read paws
       else
     /bin/lmenu.misc
fi
fi

if [ "$mainchoice" = "C" ]; then
    test -e $HOME/.lock.cfg
    if [ $? = 0 ]; then
      clear
      echo Access Denied!
      echo
      echo REASON:
      cat $HOME/.lock.cfg
      echo -=] Press ENTER to Continue [=-
      read paws
    else
      /bin/lmenu.cfg
    fi
fi

if [ "$mainchoice" = "L" ]; then
    test -e $HOME/.lock.logout
       if [ $? = 0 ]; then
         clear
          echo Access Denied!
          echo
          echo REASON:
          cat $HOME/.lock.logout
          echo -=] Press ENTER to Continue [=-
          read paws
       else
	clear
        echo "=--=--------------------=--="
        echo "=--= Closing Connection =--="
        echo "=--=--------------------=--="
	exit
fi
fi
clear
done
}
main
fi
