#!/bin/sh

datafile=`echo "/fs/www/${PATH_INFO}" | sed 's/\.\.//g'`
tmpfile="/tmp/randref.$$"

if [ -f "$datafile" ]; then
	grep -v '^[# ]' "$datafile" | grep -v '^$' > "$tmpfile"
	
	count=`wc -l < "$tmpfile"`
	which=`/u/dsandler/bin/rand -n -i $count`

	#line=`head -$which "$tmpfile" | tail -1`
	line=`/u/dsandler/bin/line -n "$which" < "$tmpfile"`
	
	rm "$tmpfile"

	if [ "$line" != "" ]; then

		echo "Status: 301 Content Moved Temporarily"
		echo "Expires: 0"
		echo "Location: $line"
		echo

		exit 0

	fi
fi

echo Content-type: text/html
echo
echo "<h1>Bogus randref request</h1>"


