#!/bin/sh

# The redirect code used here is "302 Found" rather than "303 See Other"
# for compatibility with older user agents.  See RFC 2616 for details.

set -f

name=`basename $0`
log="$DOCUMENT_ROOT/Log/$name"
date=`date "+%Y/%m/%d %H:%M:%S"`

file1="Share/Source/starfish-0.9.tar.gz"
file2="Share/Source/tls-1.5.0.tar.gz"

Download() {
  echo "$date $REMOTE_ADDR $REQUEST_URI" >> $log

  echo "Location: http://www.starfishsystems.ca/$1"
  echo "Status: 302 Found"
}

Unknown() {
  echo "Content-type: text/html"
  echo "Status: 404 Not Found"
  cat << "  EOF"

  <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
  <html>
  <head>
  <title>
  404 Not Found
  </title>
  <base href="http://www.starfishsystems.ca/">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  </head>
  <body>
  <h1>Not Found</h1>
  The requested URL was not found.
  </body>
  </html>

  EOF
}

#
# Main program
#

pat="name="
arg=`echo "$QUERY_STRING" | tr "&" "\n" | grep "$pat" | sed -e "s/$pat//"`

case $arg in
    starfish)
	Download $file1
	;;
    tls)
	Download $file2
	;;
    *)
	Unknown $arg
	;;
esac
