#!/bin/ash

# Do not change the shell! This is specially written for ash. BASH is huge
# (and slow!)

# ***************************************************************************
# * 1-bbs Script to run a BBS    Version 0.10 Januar 29, 1995               *
# * Author: Christoph Lameter (waterf!clameter@caprica.com)                 *
# * Copyright: GPL                                                          *
# ***************************************************************************

# Section that MUST be customized. Other textfiles to be displayed are all
# embedded in this File! You have to look through all of it!

# name is the name of the BBS
NAME="The Noname BBS"
# TMP is for something that we have to store for processing
TMP=/tmp/c$LOGNAME
# QUEUE is for queueing Files
QUEUE=/tmp/q$LOGNAME
# FILES is the location where our Files are
FILES=/Library
# INFO is the location where informational text are to be looked up
INFO=$FILES/Noname
# DESCR is the location to store the computed descriptions
DESCR=/tmp

# End of MUST customize section

# Allow Sysop to initiate chat with user on sending signal kill -10 to the ash shell.
trap Chat 10

Games ()
{ local EXIT
  EXIT="No"
  while [ "$EXIT" = "No" ]; do
   if dialog --title "Games in Textmode. Press CTRL-C to stop them!" --menu "Select a Game:" 23 75 17 \
    Tetris "Character Based Tetris Version"\
    hang "Hangman. Very simple and classic Game"\
    Backgammon "Play Backgammon with the Computer"\
    Battlestar "Text based adventure Game"\
    Canfield "A modified version of Solitaire"\
    Cribbage "Card based classical Game of Cribbage"\
    Fish "Classical Childrens Card Game"\
    Monopoly "Monopoly Game"\
    Paranoia "A game based on questionaires"\
    Rain "Rain on your screen (Fast Modem required!)"\
    Sail "Adventure with old cannon boats"\
    Trek "Star Trek Game"\
    Worms "Need worms on your Screen?"\
    Wump "Hunt the Wumpus!" 2>$TMP; then
    case "`cat $TMP`" in
     Tetris) tetris ;;
     hang) hangman ;;
     Backgammon) backgammon ;;
     Battlestar) battlestar ;;
     Canfield) canfield ;;
     Cribbage) cribbage ;;
     Fish) fish ;;
     Monopoly) monop ;;
     Paranoia) paranoia ;;
     Rain) rain ;;
     Sail) sail ;;
     Trek) trek ;;
     Worms) worms ;;
     Wump) wump ;;
    esac
   else
    EXIT="Yes"
   fi
  done
}

Programs ()
{ local EXIT
  EXIT="No"
  while [ "$EXIT" = "No" ]; do
   if dialog --title "Application Programs" --menu "Select an Application: $1" 14 60 8 \
    bible "Bible Retrieval System"\
    MC "Midnight Commander (a la Norton Commander)"\
    SC "Spreadsheet Calculator"\
    JED "Colorful Text-Editor Emacs Compatible"\
    JOE "Text-Editor Wordstar Compatible"\
    VI "Standard UNIX Visual Editor (Uggh!)"\
    EX "Standard UNIX Line Editor (Worse!)"\
    JOVE "Emacs Compatible Editor"  2>$TMP; then
    case "`cat $TMP`" in
     bible) bible ;;
     MC) mc ;;
     SC) sc ;;
     JED) jed ;;
     JOE) joe ;;
     VI) vi ;;
     EX) ex ;;
     JOVE) jove ;;
    esac
   else
    EXIT="Yes"
   fi
  done
}

Statistics ()
{ local EXIT
  EXIT="No"
  while [ "$EXIT" = "No" ]; do
   if dialog --title "System Statistics" --menu "Select a kind of statistic" 13 60 7 \
    top "Shows current activity and memory. Quit with Q"\
    last "Shows last logons"\
    ps "Process Status"\
    who "Who is using the system"\
    free "Shows Memory Status"  2>$TMP; then
    case "`cat $TMP`" in
     top) top ;;
     last) last -20|less ;;
     ps) ps ax|less ;;
     free) free|less ;;
     who) who|less ;;
    esac
   else
    EXIT="Yes"
   fi
 done
}

Chat ()
{ talk clameter
}

Init ()
# Generates the Main Directory of the File Base.
# Generates special Files that refer to commands
# Generates the main INDEX File with entries to omit any FTP specialities.
{ echo "New"    >$FILES/New
  echo "Queue"  >$FILES/Queue
  echo "Search" >$FILES/Search
  echo "Upload" >$FILES/Upload
# Protect the Files
  chmod o-w $FILES/New $FILES/Queue $FILES/Search $FILES/Upload
# Generate first INDEX (append otherwise another INDEX might be destroyed!)
  cat >>$FILES/INDEX <<EOF
bin -
etc -
incoming -
lib -
usr -
lost+found -
welcome.msg -
New Check for New Files
Queue Download/Manage Queued Files
Search Search for Files
Upload Upload Files
EOF
# Generate links for guest account and the installation of new users
  ln -s $0 /home/guest/.profile
  cp User.Profile /etc/skel/.profile
}

Selected ()
{ local EXIT
# A file was selected. Name in Parameter 1
  EXIT="No"
  while [ "$EXIT" = "No" ]; do
   if dialog --title "File Download" --menu "Select Action on File: $1" 13 60 7 \
    D "Display Contents (Determines appropriate action)"\
    V "View the File as an Ascii-File"\
    Q "Queue the File for later Download"\
    Z "Z-Modem Download"\
    Y "Y-Modem Download"\
    X "X-Modem Download" 2>$TMP; then
    case "`cat $TMP`" in
     D) FILE=$1;
      case "$FILE" in
#     Unix Compression Methods     
        *.tar.gz | *.tgz | *.tar.z | *.tar.Z)
              tar tzvf $1 >$TMP; FILE=$TMP;;
       *.tar)
              tar tvf $1 >$TMP; FILE=$TMP;;
       *.gz | *.z | *.Z )
              zcat $1 >$TMP; FILE=$TMP;;
#    Dos Compression Methods
       *.zip | *.ZIP)
              unzip -l $1 >$TMP; FILE=$TMP;;
       *.exe | *.EXE)
              strings -n15 $1 >$TMP; FILE=$TMP;;
      esac
        dialog --title "Viewing File: $1" --textbox $FILE 23 79
      ;;
     Q) echo `pwd`/$1 >>$QUEUE;
        dialog --msgbox "Filename $1 has been queued for download." 6 60
      ;;
     Z) sz $1
      ;;
     Y) sy $1
      ;;
     X) sx $1
      ;;
     V) less $1
      ;;
    esac
   else
    EXIT="Yes"
   fi
  done
}

SearchFiles ()
{ # SearchFiles <Search Criteria>
  find . -type f $* -not -iname "INDEX*" >$TMP
  dialog --title "Result of Search Operation" --textbox $TMP 23 79
}

New ()
{ local EXIT
  EXIT="No"
  while [ "$EXIT" = "No" ]; do
   if dialog --title "New Files" --menu "Select the desired time period: $1" 13 60 7 \
    D "Check new files in the last X-days"\
    W "New files last week (max 7 days old)"\
    M "New files last month (max 31 days old)"\
    Y "New files last year (max 365 days old)"\
    6 "New files last 6 months (max 133 days old)" 2>$TMP; then
    case "`cat $TMP`" in
     D) if dialog --title "New File Search" --inputbox "Number of days to look for:" 7 60 2>$TMP; then
          SearchFiles -mtime -`cat $TMP`;
        fi ;;
     W) SearchFiles -mtime -7 ;;
     M) SearchFiles -mtime -31 ;;
     Y) SearchFiles -mtime -365 ;;
     6) SearchFiles -mtime -133 ;;
    esac
   else
    EXIT="Yes"
   fi
  done
}

Search ()
{ local EXIT
  EXIT="No"
  while [ "$EXIT" = "No" ]; do
   if dialog --title "Search Files" --menu "Select the desired way of searching: $1" 10 60 4 \
    F "Search for Filename"\
    M "Search for a match in description or filename" 2>$TMP; then
    case "`cat $TMP`" in
     F) if dialog --title "Filename Search" --inputbox "Input filename or pattern:" 7 60 2>$TMP; then
          find * -type f -not -iname "INDEX*" -iname `cat $TMP` >$TMP
          DisplayFiles $TMP
        fi ;;
     M) if dialog --title "Description Search" --inputbox "Keyword or item to look for" 7 60 2>$TMP; then
          grep -i `cat $TMP` `find * -name INDEX` >$TMP
          if [ -s $TMP ]; then
# Some processing needs to be done here. Remove the "INDEX: " from each line
            DisplayFiles $TMP;
          else
            dialog --title "Search files" --msgbox "** No matching files found **"  6 30 
          fi
        fi ;;
    esac
   else
    EXIT="Yes"
   fi
  done
}

Upload ()
{ # Uploading of Files to the water Fountain
  # File is placed in /flib/incoming.
  # Description appended to /flib/incoming/INDEX
  # Mail is sent to sysop to notify of the upload if successful.
  if dialog --title "File upload (Z-Modem only!!)" --inputbox "Description of file" 10 79 2>$TMP; then
   if [ -s $TMP ]; then
     mv $TMP $QUEUE
     if dialog --title "$NAME: File upload" --yesno "Select OK to start upload. CANCEL cancels the upload" 6 79 2>$TMP; then
     cd incoming
     rz -bpv
     cat $QUEUE /tmp/rzlog | mail -s "File upload" sysop
     dialog --title "File Upload" --msgbox "Upload complete. Sysop will be notified." 5 50
     rm $QUEUE
     cd ..
    fi
   else
    dialog --title "$NAME: File upload" --msgbox "No uploads without a description!" 5 40
   fi
  fi
}

Queue ()
{ # Queue Management for downloads etc.
  if [ -s $QUEUE ]; then
   EXIT="No"
   while [ "$EXIT" = "No" ]; do
    if dialog --title "Queue manager" --menu "Select a queue action" 11 40 5 \
      D "Download all files"\
      Q "Download files and logoff"\
      L "List contents of download queue"\
      X "Kill list of downloads"\
      E "Edit download list" 2>$TMP; then
     case "`cat $TMP`" in
       D) sz `cat $TMP`;
          if dialog --title "Queue Manager" --yesno "All files downloaded. Download ok?" 5 40; then
            rm $QUEUE
          else
            dialog --title "Queue Manager" --msgbox "The list of files has been kept." 5 50
          fi
         ;;
       Q) sz `cat $QUEUE`;
# find  some way of logging out here....
        ;;
       L) dialog  --title "Queue Manager" --textbox $QUEUE 23 79
       ;;
       X) rm $QUEUE;
          EXIT="Yes";
          dialog --title "Queue Manger" --msgbox "Filelist discarded" 5 30
        ;;
       E) pico -t -w $QUEUE
        ;;
      esac
    else
     EXIT="Yes"
    fi
   done
  else
   dialog --title "Queue Manager" --msgbox "No files in queue!" 5 50
  fi
}

GetAwkFile ()
{ cat >$TMP << \EOF
BEGIN { IGNORECASE=1; found=1;l=length(FILE)+2;COMP=tolower(FILE) }
tolower($1) == COMP {
       found=0;
       i=l
       while ( substr($0,i,1) == " " ) i++;
       if (substr($0,i) != "-")
       { gsub("'","-");
         print "'" FILE "' '" substr($0,i,53) "' \\";
         REST=substr($0,i+53)
         while (length(REST)>0)
         { print "' ' '" substr(REST,0,53) "' \\";
           REST=substr(REST,53);
         }
       }         
  }
END { if (found) print "'" FILE "' '<No Description>' \\" }
EOF
}

ConstructIndex ()
{ local CDIR
  CDIR=`pwd`
  echo "Please wait: Constructing File Index"
  GetAwkFile
  umask 000
# built dialog command to show the complete directory
  echo -n 'if dialog --title "$NAME: Files Section" --menu "Directory:'$CDIR'" 24 79 18 ' >$DESCR/$1
  for FILE in *; do
   if [ "$FILE" != "INDEX" -a "$FILE" != "INDEX~" ]; then
    if [ -r INDEX ]; then
     awk -f $TMP -v FILE=$FILE INDEX >>$DESCR/$1
    else
     echo -n "$FILE '<No INDEX>' " >>$DESCR/$1
    fi
   fi
  done 
  echo " 2>/tmp/R$1; then
 echo -n '*'
else
 echo 'Cancel' >/tmp/R$1
fi
" >>$DESCR/$1
}

Directory ()
{ local CACHE
  local EXIT
  local PWD
# List the contents of a directory on Screen and allow choosing of an item.
  PWD=`pwd`
# First Parameter is the directory
  cd $1
# Compose name of the cache file
  CACHE=`pwd | tr / .`
  if   [ ! -r $DESCR/$CACHE     ]; then ConstructIndex $CACHE
  elif [ $PWD -nt $DESCR/$CACHE ]; then ConstructIndex $CACHE
  fi
  # loop getting user input
  EXIT="No"
  while [ "$EXIT" = "No" ]; do
   . $DESCR/$CACHE
   FILE=`cat /tmp/R$CACHE`
   rm /tmp/R$CACHE
   if [ "$FILE" != "Cancel" ]; then
    if [ ! -r $FILE ]; then
      dialog --title "Access Limitation" --msgbox "Permission Denied. Only for registered Users!" 5 60
    elif [ -d $FILE ]; then
# A Directory was selected. Enter this directory
      Directory $FILE
    elif [ -x $FILE ]; then
      ./$FILE
    else
     case $FILE in
      New) New ;;
      Queue) Queue ;;
      Search) Search ;;
      Upload) Upload ;;
      *) if [ "$2" = "V" ]; then
           dialog --title "Viewing File: $FILE" --textbox $FILE 23 79
         else
           Selected $FILE
         fi ;;
     esac
    fi
   else
    EXIT="Yes"
   fi
  done
  cd $PWD
}

SystemNews ()
{ echo "\
The Verse for this day:
" >$TMP
  verse >>$TMP
  echo "\

Important News of $NAME follows:
---------------------------------------------
--- January 23, 1995
System upgrade to 486 DX4 100 with Ethernet. 1.8 GB Harddrive Capacity now.

--- January 13, 1995
More space available. Better Backup facilities.
Added 1 GB Harddrive and a 420Meg Backup Tape. That will take care of
the space squeze. Now lots of space is there. I hope to upgrade the
Motherboard soon since I am running out of available slots.

Hooray! Today we got connected to the UseNet. Christian Conferences, Linux
stuff etc are now available for you to read and post!

--- January 4, 1994
Allmost all Files of the old Water Fountain are now online in a
structured way so that Files can actually be easily located.
(Only missing TrueType and Tech Section).
A UUCP Feed should come online in the next day. We will actually have
newsgroups and a mail facility here!
Traffic on the BBS has hit an all time low with one call per day. But I
hope traffic will pick up as soon as the mail/news functions are working.

--- December 12, 1994
Installed a Bible reading and research system. It is accessible directly
if you login as guest. Otherwise you can find the interactive bible in the
"Programs" Section. Adapted a program from Dos for UNIX to have access to
a daily devotional verse. Added nice greetings to guest account and a
farewell address to all accounts.
$NAME gets nicer and nicer...

And I am currently looking into ways to hook this thing up to the internet.
I will restrict guest file-download to Christian Files and require fees as
soon as I get on it because I have to pay monthly fees for that service.

--- December 10, 1994
Finally I got around to restructure the "Christianity" File Area and most of
the Dos Area(No Games yet, sorry). Most of
the Files available on the Old Water Fountain are there again structured
according to their respective Topic. I hope this makes it easier to find
something.

The CD with NASA Pictures is running in the CD-Rom. If you like the original
pictures from Voyager etc then download some before I change it again.

--- December 6, 1994
I am sorry. When I upgrades the System the ANSI-Emulations were not properly
installed resulting in a CARRIER DROP when anyone tried to log in in the
last few days. Ouch! Sorry. Forgive me.

--- December 4, 1994
The application process has been revised and is functional again.

--- Old Important News 
Effective September 23 all accounts of $NAME have been
transferred to the InfoXchange (818)792-2271. Please call the InfoXchange
to access your old account.
This is an experimental system. You will have difficulties until everything
is setup smoothly.

" >>$TMP
           dialog --title "$NAME: System News" --textbox $TMP 20 79
}

TerminalHelp ()
{
# No valid terminal Emulation yet. We cannot display any fancy menus.
# Retreat to plain text mode
echo "\

Available Terminal Emulations on $NAME
--------------------------------------------------------------------------
pcansi   ANSI PC Compatible. With Color and Border etc. Choose this.
pcansibw ANSI PC Compatible. No Colors, but Borders. Choose for BW Laptop.
console  Full VT100 Emulation using Colors and Borders.
         The best! Choose this if you Communications Program can handle it!
vt100    VT100 Emulation supporting just black and white. No Border chars.
         Choose if you Comm-Pgm has a crippled VT100 Emulation
ansi     Ugly Emulation of ANSI. Not complete. No Color, No Borders.
         Avoid if at all possible.
dumb     No control characters at all. Use for cases of extreme
         incompatibility.

Others       :  vt200,vt300,
For Xterm use:  vs100 or vs100s

Play around with these to find a good fit. If you can get Color and Graphics
to work then you will have a nice looking user interface!
"
}

GuestWelcome ()
{  echo "\
                Welcome to $NAME
                -----------------------------
$NAME is a Mailbox with an emphasis on Christianity.
The Menu-System on $NAME can be operated with the Cursor-Keys
or the + and - Button. Highlight the option you want and press RETURN. Or
use them to scroll text as for example this message. If this does not work
then please check your terminal emulation and call back.
" >$TMP
  verse >>$TMP
  echo "
The Guest account allows you:
- unlimited free downloads of Software related to Christianity
- Access to the Bible Retrieval System. KJV interactive.
- Access to a number of Games.
- Application for Membership.
- Talking and Sending Messages to the Sysop.

Other features are available only after registering:
- Dos / Windows Information and Software
- A complete downloadable UNIX Compatible Operating System
- UseNet / E-Mail (partially functional)
- Internet Services (Gopher,Lynx, Ftp, Telnet etc..) (planned)
- SLIP/CSLIP/PPP Access (Waiting for the first one to try it with)
- UNIX Shell Account

This is a G-Rated system. Please notify the Sysop immediately should
you encounter any inappropriate material from another User on this
system.

Above all: Glory be to God in the highest.

May this operation be furthering the Kingdom of God.
You are welcome in the Name of Jesus Christ our Savior.

 Your Sysop,
    Christoph Lameter
" >>$TMP

  dialog --title "Welcome to $NAME" --textbox $TMP 24 79
}

GuestCommentWarning ()
{ echo "\
You are trying to write a comment to the sysop from the guest account!

ATTENTION THERE ARE CERTAIN THINGS YOU SHOULD BE AWARE OF:
----------------------------------------------------------

1. The Guest account is anonymous. You can only SEND mail. The Sysop CANNOT
   REPLY to you. Bear that in mind! Do not ask for a response via E-Mail.

2. If you cannot login to your account because you have forgotten your
password then please leave a message with sufficient information for the
Sysop to prove that you are the right person making the request. For
example include Phone, Date of Birth and Address!
Then PLEASE SPECIFY a NEW PASSWORD. The Sysop has no way of finding out
what your password is. It can only be replaced with a new one. Try to
dialin a few days later and try your new password.

3. If you have trouble with your account then please leave at least enough
information (like a telephone number) so that the Sysop can call you and
talk with you.
" >>$TMP
  dialog --title "Comment to Sysop. Tips and Warnings." --textbox $TMP 20 79
}

Applicationhelp()
{ echo "\
Application to $NAME
---------------------------------

$NAME is a system dedicated to communication betwen Christians.
It is open to non-Christians but a considerate use of this system and
respect before each other is expected from everyone.
If you are just interested in downloading Files then stay with the guest
account. You can download as much as you want by loggin in with guest.
If you want to really participate in E-Mail, FidoNet, UseNet-News and
Internet Services then please apply. Also if you are willing to share
software, find support in your faith then you are very welcome.

This text must be scrolled to read it fully! Try PgUp and PgDn. If that does
not work try Cursor Up and Cursor down. + and - should also work.

Incomplete Applications will not processed. Do not expect an answer if you
do not at least give a phone number for me to call!

For detailed Information on $NAME exit to the main menu and
read the Information-Section!!!!

Money Matters
-------------
$NAME is a nonprofit undertaking for the sole joy and fun of
the participants. Certain costs as phone-lines, material time are incurred
and I expect from regular users a participation in the costs of running
this bbs in the form of donations. The minimum donation should be $1/month.

Application Process
-------------------
The application process is as follows. Fill in the application form here
online. It will be mailed to the System Operator Christoph Lameter. He
will evaluate your application and then give you a phone call to verify
your true existance. This BBS is no replacement for personal
relationships!
In the application process you will be able to write something about
yourself. This will be posted when you are announced on the BBS as a new
user.
" >$TMP
  dialog --title "How and Why become a member of $NAME" --textbox $TMP 20 79
}

Application ()
{ local EXIT
  local UNAME
  local STREET
  local CITY
  local PHONE
  local DOB
  EXIT="No"
  UNAME="?"
  STREET="?"
  CITY="?"
  PHONE="?"
  DOB="?"
  while [ "$EXIT" = "No" ]; do
   dialog --title "Application for Membership" --menu "Application for Membership on this BBS" 16 70 9 \
	1 "Information about the Application Process" \
        3 "Full Name     :$UNAME" \
	4 "Street Address:$STREET" \
	5 "City Address  :$CITY" \
	6 "Phone-Number  :$PHONE" \
	7 "Date of Birth :$DOB" \
	R "Apply with above Information" \
	X "No I do not want to apply for Membership" 2>$TMP
   if [ $? = 1 ]; then
    EXIT="Shell"
   elif [ $? -lt 0 ]; then
    EXIT="Logoff"
   else
    case "`cat $TMP`" in
      "X") EXIT="Leave" ;;
      "1") Applicationhelp ;;
      "3") if dialog --title "Application for Membership" --inputbox "Please enter your full name here" 8 50 2>$TMP;
           then
            if [ -l "`cat $TMP`" -lt 7 ]; then
              dialog --title "Application for Membership" --msgbox "The name is a little bit short. I expect at least 7 Characters!" 7 70
             else
              UNAME=`cat $TMP`
             fi
           fi ;;
      "4") if dialog --title "Application for Membership" \
                --inputbox "Please enter your street address: NNN XXXX-Street # NNN" 8 70 2>$TMP;
           then
            if [ -l "`cat $TMP`" -lt 12 ]; then
              dialog --title "Application for Membership" \
                 --msgbox "The street address is a little bit short. I expect at least 12 Characters!" 7 78
            else
              STREET=`cat $TMP`
            fi
           fi ;;
      "5")  if dialog --title "Application for Membership" --inputbox "Please enter your city address: CITY, STATE ZIP" 8 60 2>$TMP;
           then
            if [ -l "`cat $TMP`" -lt 12 ]; then
              dialog --title "Application for Membership" --msgbox "The city address is a little bit short. I expect at least 12 Characters!" 7 78
             else
              CITY=`cat $TMP`
             fi
           fi;;
      "6") if dialog --title "Application for Membership" --inputbox "Please enter your phone number: (AAA)PPP-NNNN)" 8 60 2>$TMP;
           then
            if [ -l "`cat $TMP`" -lt 9 ]; then
              dialog --title "Application for Membership" --msgbox "The phone number is a little bit short. I expect at least 9 Characters!" 7 65
             else
              PHONE=`cat $TMP`
             fi
           fi ;;
      "7") if dialog --title "Application for Membership" --inputbox "Please enter your Date of Birth : MM/DD/YY" 8 50 2>$TMP;
           then
            if [ -l "`cat $TMP`" -lt 8 ]; then
              dialog --title "Application for Membership" --msgbox "The Date of Birth is a little bit short. I expect at least 8 Characters!" 7 67
             else
              DOB=`cat $TMP`
             fi
           fi ;;
      "R") if [ "$UNAME" = "?" ]; then
            dialog --title "Application for Membership" --msgbox "No Application without your Name!" 7 50
           elif [ "$STREET" = "?" ]; then
            dialog --title "Application for Membership" --msgbox "No Application without your Street Address!" 7 50
           elif [ "$CITY" = "?" ]; then
            dialog --title "Application for Membership" --msgbox "You forgot to enter your City Address!" 7 50
           elif [ "$PHONE" = "?" ]; then
            dialog --title "Application for Membership" --msgbox "No Application without your phone number!" 7 50
           elif [ "$DOB" = "?" ]; then
            dialog --title "Application for Membership" --msgbox "You forgot to enter your Date of Birth!" 7 50
           else
            echo -e "\
Application for Membership in $NAME
------------------------------------------------
Dear Christoph Lameter,
I hereby apply for membership with $NAME. I have read and
understood all conditions of use and I will adhere to them as they were
intended to regulate the functioning of this Bulletin Board.

Information about myself:
Full Name      : $UNAME
Street Address : $STREET
City Address   : $CITY
Phone Number   : $PHONE
Data of Birth  : $DOB

Some important information about myself or what I plan to do with the Water
Fountain (please fill in here as you wish:)
" >$TMP
            pico +17 -t -w $TMP
            if dialog --title "Application for Membership" --yesno "Send your Application in?" 5 40; then
             mail -s "Application for Membership" clameter <$TMP
             EXIT="Done"
            fi
           fi ;;
     esac
   fi
  done
}

GuestMenu ()
{ stty -isig intr undef quit undef susp undef erase ^H
  # a .profile for the Guest Account. Please realize that this is only limited
  # security! A shell can still be obtained somehow I think.
  # This script should be run from ash (limited shell!)
  export TERM=pcansi
  TMOUT=300
  EXIT="No"
  while [ "$EXIT" = "No" ]; do
   echo "------- Choose the kind of terminal emulation you need -------"
   echo "Default Emulation uses color and graphical chars in PC-ANSI mode."
   echo "If you choose an incorrect type the system might seem to hang! Dial again!"
   echo -n "Please enter a terminal type ('help'=Information, Enter = Default) :"
   read REPLY
   if [ "$REPLY" = "" ]; then
    EXIT="YES"
   elif [ "$REPLY" = "help" ]; then
    TerminalHelp
   else
    export TERM=$REPLY
    EXIT="Yes"
   fi
  done
  
  GuestWelcome

  EXIT="No"
  stty intr ^C
  while [ "$EXIT" = "No" ]; do
   dialog --title "$NAME. Blessings from Christ to all" \
	--menu "Main Menu (Guest User)" 17 70 10 \
        S "SysNews: Read news specific to this system" \
	I "Info: Get Help on how $NAME works" \
	F "Files: Download Files from the Files-Sections" \
	C "Comment: Send a message to the Sysop" \
	A "Apply for a User Account on $NAME" \
	L "Login again. Change video mode? Other user?" \
        T "Talk to Sysop (If he is logged on!)" \
        B "Bible Retrieval System (KJV)" \
        G "Play Games"\
	X "End the Work with $NAME" 2>$TMP
   if [ $? = 1 ]; then
     EXIT="Goodbye";
   else
    case "`cat $TMP`" in
      "X") EXIT="Goodbye" ;;
      "G") Games ;;
      "S") SystemNews ;;
      "I") Directory $INFO V;;
      "F") Directory $FILES ;;
      "C") GuestCommentWarning
          pico -t -w $TMP
          if dialog --title "Comment to Sysop" --yesno "Send your Message to the Sysop?" 5 40; then
            mail -s "Comment from Guest" sysop <$TMP
          fi
           ;;
      "T") talk clameter;;
      "B") clear;
           bible;;
      "A") Application ;;
      "L") login ;;
    esac
   fi
  done
}

Menu ()
{ EXIT="No"

  while [ "$EXIT" = "No" ]; do

   if test -s $MAIL; then
    MOK="!MAIL WAITING!"
   else
    MOK="No New Mail"
   fi
   dialog --title "$NAME. Blessings from Christ to all" \
	--menu "Main Menu (User:$LOGNAME)" 20 70 13 \
	M "Mail: Read and Post Mail. $MOK" \
	N "News: Read and Post News" \
        S "SystemNews: Read news specific to this system" \
	I "Info: Get Help on how $NAME works" \
	F "Files: Download and Upload Files" \
	C "Comment: Send a message to the Sysop" \
        P "Application Programs" \
        G "Play Games" \
        T "Talk to Sysop (If he is logged on...)" \
        Z "System Statistics" \
	L "Login as a different User" \
	X "Goodbye: End the Work with $NAME" 2>$TMP
   if [ $? = 1 ]; then
    dialog --title "$NAME" --yesno "Really exit to the Unix Shell" 5 50
    if [ $? = 0 ]; then
     EXIT="Shell"
    fi
   elif [ $? -lt 0 ]; then
    EXIT="Logoff"
   else
    case "`cat $TMP`" in
      "X") EXIT="Goodbye" ;;
      "S") SystemNews
 ;;
      "I") Directory $INFO V ;;
      "F") Directory $FILES ;;
      "C") pico -t -w $TMP
          mail -s "Comment from Guest" clameter <$TMP ;;
      "M") pine ;;
      "N") tin ;;
      "L") login ;;
      "G") Games ;;
      "P") Programs ;;
      "T") talk clameter;;
      "Z") Statistics ;;
     esac
   fi
  done
}

if [ "$1" = "init" ]; then
  Init
  exit
fi

if [ "$LOGNAME" = "guest" ]; then
  GuestMenu
else
 Menu
fi

rm $TMP
if [ "$EXIT" = "Goodbye" -o "$LOGNAME" = "guest" ]; then
  clear;
  echo "\
We woud like to wish you a good bye with the following words from
Numbers 6:24-26:

The LORD bless you and keep you,
The LORD make His face shine upon you,
And be gracious unto you;
The LORD lift up His countenance upon you,
And give you peace.

Farewell......
"
  exit 0;
else
  exit 1;
fi
