#!/usr/bin/python
import sys
import os
import re
import cgitb; cgitb.enable()

map = {}
mapFile = open("moved.txt")
for line in mapFile.readlines():
	try:
		key, value = line.split("\t",1)
		map[key.strip()] = value.strip()
	except: pass

requested = os.environ["REDIRECT_URL"]

matched = 0
for key in map.keys():
	if re.search(key, requested):
		print "Status: 302"
		print "Location: %s\n" % re.sub(key, map[key], requested)
		matched = 1
		break

if not matched:
	print """Content-type: text/html\n
<html>
<head>
<title>Not Found</title>
<style>
body {
	font-family: verdana, sans-serif;
	font-size: 9pt; 
}
</style>
</head>
<body>
<div style="margin-top:10%; text-align: center">
<img src="/images/404.png">
"""
	print """
<p>
Sorry, there ain't no "%s" here.
<p>
<a href="/">fettig.net</a>
</div>
</body>
</html>
""" % requested
