2 # -*- coding: utf-8 -*-
10 # HTML Debug of errors
13 # Limit maximum CPU time
14 # The Postscript output format can sometimes take hours
15 resource.setrlimit(resource.RLIMIT_CPU,(180,180))
18 # Some odd requests can cause extreme memory usage
19 resource.setrlimit(resource.RLIMIT_AS,(4000000000, 4000000000))
21 # Routine to output HTTP headers
22 def output_headers(content_type, filename = "", length = 0):
23 print "Cache-Control: no-cache, no-store, must-revalidate')"
24 print "Pragma: no-cache"
26 print "Content-Type: %s" % content_type
28 print "Content-Disposition: attachment; filename=\"%s\"" % filename
30 print "Content-Length: %d" % length
33 # Routine to report an error
34 def output_error(message):
35 output_headers("text/html")
38 print "<title>Error</title>"
41 print "<h1>Error</h1>"
42 print "<p>%s</p>" % message
46 # Make sure we have a user agent
47 if not os.environ.has_key('HTTP_USER_AGENT'):
48 os.environ['HTTP_USER_AGENT'] = 'NONE'
50 # Get the load average
51 loadavg = float(open("/proc/loadavg").readline().split(" ")[0])
53 output_headers("text/html")
56 print "<title>tile.openstreetmap.org debug</title>"
59 print "<h1>tile.openstreetmap.org debug</h1>"
60 print "<h2>Server Stats</h2>"
61 print "<p><b>Load Average:</b>%s</p>" % loadavg
62 print "<h2>Browser Request Headers</h2>"
64 for param in os.environ.keys():
65 print "<b>%20s</b>: %s<br />" % (param, os.environ[param])