#!/bin/sh
#set path=(/bin /usr/bin /usr/ucb /usr/local/bin)
PATH=/bin:/usr/bin:/usr/etc:/usr/ucb:/usr/local/bin; export PATH
umask 002
MUDTMP="/tmp/mud.$$"
MUDMAILHDR="/tmp/mudhdr.$$"
ADMIN="muds@arcwelder.micro.umn.edu"
#Ask: Enter the common name of the MUD (i.e. "Moral Decay"):
read mudname
#Ask: Enter the TCP address of the MUD:
read tcpname
#Ask: Enter the port number of the MUD:
read port
#Ask: Enter Administrator's E-mail address:
read xaddr
#Ask: Enter Guest account name and password:
read guest
#Ask: Enter type of MUD:
read xtype
#Ask: Enter theme:
read theme
#Ask: Enter hours available (skip for constant availability):
read hours
#Ask: Enter type of MUD if ADULT:
read adult
#
# Strip out special characters to avoid crackers (and cheese :-))
#
adminaddr=`echo ${xaddr}|tr -cd '[^A-Za-z0-1@._-+=#&:;,~]' `
type=`echo ${xtype}|tr -cd '[^A-Za-z0-1@._-+=#&:;,~]' `
link=`echo ${mudname}|tr -cd '[^A-Za-z0-1@._-+=#&:;,~]'`
ip=`echo ${tcpname}|tr -d '[0-9\.]'`
FILE="new/$type/.$link"

if [ -f /tmp/${MUDTMP} ]; then
        rm -f $MUDTMP
fi

if [ -z "$ip" ] ; then
	echo "You have apparently used an IP address rather than a TCP name"
	echo "to indicate the MUD address.  It is important to use TCP names"
	echo "to describe the MUD.  For instance, an IP address might change"
	echo "when a computer is moved or rerouted, but the TCP name will"
	echo "remain the same.  There are other, more technical reasons, too."
	echo "Please register the MUD with its valid TCP name."
        exit 0
fi

if [ -z "$mudname" ] ; then
        echo "Thanks for taking a look around."
        echo "Please stop by again when you wish to register a MUD."
        exit 0
fi

if [ -z "$adminaddr" ] ; then
       echo "I must have an administrators E-mail address"
       echo "Please fill this in with a valid address and try again"
       exit 0
fi

if [ -z "$tcpname" ] ; then
       echo "Well how can I find it without a tcp name?"
       echo "Please fill in a valid tcp name and try again"
       exit 0
fi

if [ -z "$type" ] ; then
       echo "I need to know what type of MUD this is."
       echo "Please enter the type such as LPmud or Tinymush, etc."
       exit 0
fi


echo "Subject: MUD Registration: $mudname"  >> $MUDMAILHDR
echo "Reply-To: <$adminaddr>"               >> $MUDMAILHDR
echo ""                                     >> $MUDMAILHDR 
echo "#$mudname: `date`"                    >> $MUDTMP
echo "#Type of MUD: $type"                  >> $MUDTMP
echo "#Hours of operation: $hours"          >> $MUDTMP
echo "#Theme: $theme"                       >> $MUDTMP
echo "#Adult? $adult"                       >> $MUDTMP
echo "Name=$mudname"                        >> $MUDTMP
echo "Type=8"                              >> $MUDTMP
echo "Host=$tcpname"                        >> $MUDTMP
echo "Abstract=$theme"                      >> $MUDTMP
echo "Admin=$adminaddr"                     >> $MUDTMP
echo "Port=$port"                           >> $MUDTMP
echo "Path=$guest"                          >> $MUDTMP
cat $MUDTMP
echo "Your registration will be authenticated as soon as possible"

cat $MUDMAILHDR $MUDTMP | /bin/mail ${ADMIN}

if [ -d new/$type ]; then
   touch $MUDTMP
else
   mkdir new/$type
   chmod 777 new/$type
fi

if [ -f $FILE ]; then
   cat $MUDTMP >> $FILE
   rm -f $MUDTMP
   rm -f $MUDMAILHDR
else
   mv $MUDTMP $FILE
fi

chmod 666 $FILE

if [ -f new/.cache ]; then
   rm -f new/.cache
fi

if [ -f new/.cache+ ]; then
   rm -f new/.cache+
fi
