#!/bin/sh

### Configuration variables

tpldir=/var/www/data
tplfile=$tpldir/eudora-config.html

### Part 1: Get input values - no URL decoding is done

# Command to suppress dangerous shell characters and separate form inputs
fixcmd1="/usr/bin/tr ;&!\$^\\\\*(\`<>?|\\040\\011 \\012\\012XXXXXXXXXXXXX"

# Command to extract only the variables we're interested in.
fixcmd2="egrep ^username=|^platform="

tmpfile=/tmp/input$$

case $REQUEST_METHOD in
    POST)
	$fixcmd1 | $fixcmd2 > $tmpfile
	;;
    *)
	echo $QUERY_STRING | $fixcmd1 | $fixcmd2 > $tmpfile
	;;
esac

. $tmpfile
rm $tmpfile

### Part 2: Process the input

poacct=`/usr/bin/hesinfo $username pobox | awk '{printf "%s@%s\n", $3, $2}'`
poacct=`echo $poacct | sed '/.*/y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`

case $platform in
    mac)
	svcfmt="^0.^3@^2"
	;;
    pc)
	svcfmt="%1.%4@%3"
	;;
    *)
	svcfmt="unknown for $platform"
	;;
esac

myurl="http://${SERVER_NAME}:${SERVER_PORT}${SCRIPT_NAME}?platform%3D${platform}%3Busername%3D${username}"

### Part 3: Output

echo "Content-type: text/html
"

sed -e "s/@username@/$username/g" -e "s/@platform@/$platform/g" \
    -e "s/@poacct@/$poacct/g" -e "s/@svcfmt@/$svcfmt/g" \
    -e "s,@myurl@,$myurl,g" -e "s,@referer@,$HTTP_REFERER,g" < $tplfile
