#! /bin/sh
if [ $# = "0" ]; then
   echo -e "1gopher.zcrayfish.soy gopher root\\t/\\tgopher.zcrayfish.soy\\t70"
   echo " * * * gopher guest book * * * "|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
   echo "                 __            "|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
   echo "                /\ \           "|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
   echo "     ____    ___\ \ \____      "|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
   echo "    / __ \  / __ \ \  __ \     "|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
   echo "   /\ \_\ \/\ \_\ \ \ \_\ \    "|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
   echo "   \ \____ \ \____ \ \____/    "|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
   echo "    \/____\ \/____\ \/___/     "|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
   echo "      /\____/ /\____/          "|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
   echo "      \____/  \____/           "|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
   echo ""|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
   echo -e "7Leave your comment on the gopher guest book!\\t/guestbook.mole\\tgopher.zcrayfish.soy\\t70"
   echo ""|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
   echo "I rarely read these, so if you're looking for a reply, hit me up"|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
   echo "on IRC or send me an email!"|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
   echo ""|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'

   echo -e "1Previous years guestbook archive\\t/guestbook_archive/\\tgopher.zcrayfish.soy\\t70"
   echo ""|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
   echo Guest book entries appear below here, newest entries are at the bottom:|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
   echo ------------------------------------------------------------------------|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
   cat /srv/gopher/guestbook.txt|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
   exit
fi
echo >> /srv/gopher/guestbook.txt
#echo $@ | sed 's/00X0.000000000000P 0/\n/g' | fmt -su -w 72 >> /srv/gopher/guestbook.txt
echo "$@" | sed 's/00X0.000000000000P 0/\n/g' | fold -w 72 -s >> /srv/gopher/guestbook.txt
echo >> /srv/gopher/guestbook.txt
timestamp=$(date -u)

REALHOSTNAME=$(host "$REMOTE_ADDR" | awk '{ printf $5}')

if [[ "$REALHOSTNAME" == "3(NXDOMAIN)" ]]; then
  REALHOSTNAME="$REMOTE_HOST"
fi

#  echo $timestamp $REALIP:httpuser|fmt -su -w 72 >> /srv/gopher/guestbook.txt
#  echo $timestamp $REALIP:httpuser|fold -w 72 -s >> /srv/gopher/guestbook.txt
#  echo $REALHOSTNAME|fmt -su -w 72 >> /srv/gopher/guestbook.txt
#  echo $REALHOSTNAME|fold -w 72 -s >> /srv/gopher/guestbook.txt
#else
#    echo Posted $timestamp by $REMOTE_ADDR|fmt -su -w 72 >> /srv/gopher/guestbook.txt
#    echo Posted $timestamp by $REMOTE_ADDR|fold -w 72 -s >> /srv/gopher/guestbook.txt




    echo Posted $timestamp by:|fold -w 72 -s >> /srv/gopher/guestbook.txt
#    echo $REMOTE_HOST|fmt -su -w 72 >> /srv/gopher/guestbook.txt
    echo "$REALHOSTNAME"|fold -w 72 -s >> /srv/gopher/guestbook.txt
#fi

echo ------------------------------------------------------------------------ >> /srv/gopher/guestbook.txt
echo -e "1gopher.zcrayfish.soy gopher root\\t/\\tgopher.zcrayfish.soy\\t70"
echo -e "1Back to the gopher guest book...\\t/guestbook.mole\\tgopher.zcrayfish.soy\\t70"
echo -e "i	fake	(NULL)	1"
echo The following message has been posted:|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
#echo $@|fmt -su -w 72|sed 's/00X0.000000000000P 0/\n/g'|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
echo "$@"|fold -w 72 -s|sed 's/00X0.000000000000P 0/\n/g'|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
echo Message length: approximately $# words.|sed 's/$/\tfake\t(NULL)\t1/'|sed 's/^/i/'
exit