#!/bin/bash

DIRNAME=/usr/local/etc/httpd/htdocs/kristen_hall/guest/guest.accept

filter()
{
  sed -e "s/+/ /g" -e "s/%0D/<BR>/g" -e "s/%2[cC]/,/g" -e "s/%3D/=/g" | \
  sed -e "s/%2B/+/g" -e "s/%0A//g" -e "s/%3C/\&lt;/g" -e "s/%3E/\&gt;/g" | \
  sed -e "s/%21/!/g" -e "s/%23/#/g" -e "s/%24/$/g" -e "s/%25/%/g" | \
  sed -e "s/%26/\&amp;/g" -e "s/%27/'/g" -e "s/%28/(/g" -e "s/%29/)/g" | \
  sed -e "s/%5E/^/g" -e "s/%7E/~/g" -e "s/%60/\`/" -e "s/%2F/\//g" | \
  sed -e "s/%3F/?/g" -e "s/%7C/|/g" -e "s/%5C/\&#92;/g" -e "s/%5B/\&#91;/g" | \
  sed -e "s/%5D/\&#93;/g" -e "s/%7B/{/g" -e "s/%7D/}/g" -e "s/%22/\&#34;/g" | \
  sed -e "s/%3A/:/g" -e "s/%3B/\&#59;/g" -e "s/%20/ /g"
}

read l1
NAME=`echo "${l1%%&*}" | filter`
MESSAGE=`echo "${l1##*&}" | filter`
NAME="${NAME#name=}"
MESSAGE="${MESSAGE#message=}"

DATESTR=`date +"%Y %b %m %d %H %M %S"`
year=`echo $DATESTR | cut -f1 -d" "`
monthname=`echo $DATESTR | cut -f2 -d" "`
month=`echo $DATESTR | cut -f3 -d" "`
day=`echo $DATESTR | cut -f4 -d" "`
hour=`echo $DATESTR | cut -f5 -d" "`
minute=`echo $DATESTR | cut -f6 -d" "`
second=`echo $DATESTR | cut -f7 -d" "`

FILENAME="$year$month$day$hour$minute$second"
filename=$DIRNAME/$FILENAME

echo $year $month $day $hour $minute >$filename
echo "$NAME" >>$filename
echo "$MESSAGE" >>$filename


echo Content-type: text/html
echo
echo "<HTML>"
echo '<META HTTP-EQUIV="REFRESH" CONTENT="0;URL=http://home.intranet.org/kristen_hall/guest/entries.html">'
echo "</HTML>"

