73 lines
1.6 KiB
Python
73 lines
1.6 KiB
Python
|
#!/usr/bin/python
|
||
|
"""
|
||
|
simple cgi wrapper for a cgi script, prints the error of the script as html
|
||
|
taken from http://gnosis.cx/publish/programming/feature_5min_python.html
|
||
|
modified a little
|
||
|
"""
|
||
|
|
||
|
from mod_python import apache
|
||
|
|
||
|
import sys, traceback
|
||
|
import init_webgo
|
||
|
|
||
|
DEBUG = 1
|
||
|
|
||
|
|
||
|
def handler(req):
|
||
|
# "Content-type: text/html\n\n"
|
||
|
req.content_type = "text/html"
|
||
|
try: # use explicit exception handling
|
||
|
#reinitialize database
|
||
|
init_webgo.main()
|
||
|
|
||
|
login = apache.import_module("login")
|
||
|
login.main(req)
|
||
|
return apache.OK
|
||
|
except:
|
||
|
import time
|
||
|
errtime = '----- '+ time.ctime(time.time()) +' -----\n'
|
||
|
errlog = open('/tmp/cgi_errors.log', 'a')
|
||
|
errlog.write(errtime)
|
||
|
errlog.write(ErrorMsg())
|
||
|
data = """<html><head><title>CGI Error Encountered!</title></head>
|
||
|
<body><p>Sorry, a problem was encountered running WebGo.</p>
|
||
|
<p>Please check the error log on the server for details.</p>
|
||
|
<hr><pre>"""
|
||
|
data += ErrorMsg()
|
||
|
data+="</pre>\n</body></html>"
|
||
|
req.write(data)
|
||
|
return apache.OK
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
def ErrorMsg(escape=0):
|
||
|
"""
|
||
|
returns: string
|
||
|
|
||
|
simualtes the traceback output and if argemument
|
||
|
<escape> set to 1 (true) the string will be
|
||
|
converted to fit into html documents without problems.
|
||
|
from Dirk Holtwick
|
||
|
"""
|
||
|
import traceback, sys, string
|
||
|
|
||
|
type=None
|
||
|
value=None
|
||
|
tb=None
|
||
|
limit=None
|
||
|
type, value, tb = sys.exc_info()
|
||
|
body = "Traceback (innermost last):\n"
|
||
|
list = traceback.format_tb(tb, limit) + traceback.format_exception_only(type, value)
|
||
|
body = body + "%-20s %s" % (
|
||
|
string.join(list[:-1], ""),
|
||
|
list[-1],
|
||
|
)
|
||
|
if escape:
|
||
|
import cgi
|
||
|
body = cgi.escape(body)
|
||
|
return body
|
||
|
|
||
|
|
||
|
|
||
|
#start(req)
|