2005-09-14 17:08:44 +02:00
|
|
|
import sys, traceback,string,time
|
|
|
|
import init_webgo,psql
|
2005-09-06 19:52:46 +02:00
|
|
|
|
2005-09-12 13:28:11 +02:00
|
|
|
from mod_python import *
|
2005-09-06 19:52:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
DEBUG = 1
|
|
|
|
|
|
|
|
|
|
|
|
def handler(req):
|
|
|
|
# "Content-type: text/html\n\n"
|
2005-09-12 13:28:11 +02:00
|
|
|
req.content_type = "text/html"#was:text/html
|
2005-09-06 19:52:46 +02:00
|
|
|
try: # use explicit exception handling
|
|
|
|
#reinitialize database
|
2005-09-11 19:11:09 +02:00
|
|
|
#init_webgo.main()
|
2005-09-12 13:28:11 +02:00
|
|
|
|
2005-09-12 15:51:18 +02:00
|
|
|
|
2005-09-12 13:28:11 +02:00
|
|
|
#load form, then delegate request
|
|
|
|
form = util.FieldStorage(req)
|
2005-09-14 17:08:44 +02:00
|
|
|
try:
|
|
|
|
sessionid=form["sessionid"]
|
|
|
|
username=form["username"]
|
|
|
|
except:
|
|
|
|
sessionid=""
|
|
|
|
username=""
|
|
|
|
|
|
|
|
#if sessionid=sesssionid and time < timeout:
|
|
|
|
# set_timeout
|
|
|
|
if (psql.get_user_info(username,'timeout') > int(time.time())) and (sessionid == psql.get_user_info(username,'sessionid')):
|
2005-09-20 09:05:05 +02:00
|
|
|
psql.set_user_timeout(username)
|
|
|
|
if "create" in form.keys():
|
|
|
|
gamecreation = apache.import_module("gamecreation")
|
|
|
|
gamecreation.main(req,form)
|
|
|
|
elif "delete" in form.keys():
|
|
|
|
deletegame = apache.import_module("deletegame")
|
|
|
|
deletegame.main(req,form)
|
2005-09-20 11:51:12 +02:00
|
|
|
elif ("play" in form.keys()) or ("refresh" in form.keys()):
|
2005-09-20 09:05:05 +02:00
|
|
|
playgame = apache.import_module("playgame")
|
|
|
|
playgame.main(req,form)
|
|
|
|
else:
|
|
|
|
#call login.py
|
|
|
|
login = apache.import_module("login")
|
|
|
|
login.main(req,form)
|
2005-09-12 13:28:11 +02:00
|
|
|
else:
|
2005-10-03 23:45:39 +02:00
|
|
|
if "createaccount" in form.keys():
|
|
|
|
createaccount = apache.import_module("createaccount")
|
|
|
|
createaccount.main(req,form)
|
|
|
|
else:#call login.py
|
|
|
|
login = apache.import_module("login")
|
|
|
|
login.main(req,form)
|
2005-09-20 09:05:05 +02:00
|
|
|
|
2005-09-12 15:51:18 +02:00
|
|
|
return apache.OK
|
2005-09-06 19:52:46 +02:00
|
|
|
except:
|
|
|
|
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
|