| 1 |
#!/usr/bin/python
|
| 2 |
# vim: expandtab
|
| 3 |
|
| 4 |
# Copyright 2002-2003 Raphael Hertzog
|
| 5 |
# Available under the terms of the General Public License version 2
|
| 6 |
# or (at your option) any later version.
|
| 7 |
|
| 8 |
import cgi, os, sys, re, string
|
| 9 |
#import cgitb; cgitb.enable()
|
| 10 |
|
| 11 |
src = {}
|
| 12 |
if os.path.isfile("../incoming/sources.map"):
|
| 13 |
f = open("../incoming/sources.map")
|
| 14 |
while 1:
|
| 15 |
line = f.readline();
|
| 16 |
if not line: break #eof
|
| 17 |
line = string.strip(line)
|
| 18 |
(binary, source) = string.split(line, None, 1)
|
| 19 |
src[binary] = source
|
| 20 |
f.close()
|
| 21 |
|
| 22 |
error = "404 File not found"
|
| 23 |
url = ""
|
| 24 |
if os.environ.has_key("REDIRECT_ERROR_NOTES"):
|
| 25 |
error = os.environ["REDIRECT_ERROR_NOTES"]
|
| 26 |
if os.environ.has_key("REDIRECT_URL"):
|
| 27 |
url = os.environ["REDIRECT_URL"]
|
| 28 |
pkgbin = ""
|
| 29 |
pkgsrc = ""
|
| 30 |
hash = ""
|
| 31 |
srcfile = ""
|
| 32 |
|
| 33 |
res = re.match(r"^/.*/(.*)\.html", url)
|
| 34 |
if res:
|
| 35 |
pkgbin = res.group(1)
|
| 36 |
if src.has_key(pkgbin):
|
| 37 |
pkgsrc = src[pkgbin]
|
| 38 |
hash = pkgsrc[0]
|
| 39 |
if pkgsrc[0:3] == "lib":
|
| 40 |
hash = pkgsrc[0:4]
|
| 41 |
srcfile = "../web/%s/%s.html" % (hash, pkgsrc)
|
| 42 |
|
| 43 |
if pkgsrc and os.path.isfile(srcfile):
|
| 44 |
print "Status: 307 Temporary Redirect"
|
| 45 |
print "Location: /%s" % pkgsrc
|
| 46 |
|
| 47 |
print "Content-Type: text/html"
|
| 48 |
print
|
| 49 |
print "<html><head><title>Error 404</title>"
|
| 50 |
if pkgsrc and os.path.isfile(srcfile):
|
| 51 |
print "<meta http-equiv='refresh' content='10;url=/%s'>" % pkgsrc
|
| 52 |
print "</head><body>"
|
| 53 |
|
| 54 |
if pkgsrc and os.path.isfile(srcfile):
|
| 55 |
print "<h1>Little error ...</h1>"
|
| 56 |
print "<p>The page you asked doesn't exist."
|
| 57 |
print "However it looks like you were trying to look for `%s' binary package." % pkgbin
|
| 58 |
print "The Package Tracking System is source based, therefore you should"
|
| 59 |
print "have looked for `%s'." % pkgsrc
|
| 60 |
print "<p><a href='/%s'>Click here to be redirected or wait 10 seconds.</a>" % pkgsrc
|
| 61 |
else:
|
| 62 |
print "<h1>Error 404</h1>"
|
| 63 |
print "I'm sorry, the page that you asked doesn't exist :<br>"
|
| 64 |
print "<pre>%s</pre>" % error
|
| 65 |
print "Maybe you've made a mistake and the package you're looking for \
|
| 66 |
does not (or no longer) exist"
|
| 67 |
|
| 68 |
print "</body></html>"
|
| 69 |
|