import sys, traceback,string,time import init_webgo,database from mod_python import * DEBUG = 1 def handler(req): # "Content-type: text/html\n\n" req.content_type = "text/html"#was:text/html try: # use explicit exception handling #reinitialize database #init_webgo.main() #load form, then delegate request form = util.FieldStorage(req) try: sessionid=form["sessionid"] username=form["username"] except: sessionid="" username="" try: myuser = database.Users.byUsername(username) valid_user = True except: #no such user valid_user = False if username != "" and valid_user: if (myuser.timeout > int(time.time())) and (sessionid == myuser.sessionid): myuser.set_timeout() 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) elif ("play" in form.keys()) or ("refresh" in form.keys()): playgame = apache.import_module("playgame") playgame.main(req,form) elif "logout" in form.keys(): logout = apache.import_module("logout") logout.main(req,form) else: #call login.py login = apache.import_module("login") login.main(req,form) else: #call login.py login = apache.import_module("login") login.main(req,form) else: 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) return apache.OK except: errtime = '----- '+ time.ctime(time.time()) +' -----\n' errlog = open('/tmp/cgi_errors.log', 'a') errlog.write(errtime) errlog.write(ErrorMsg()) data = """
Sorry, a problem was encountered running WebGo.
Please check the error log on the server for details.
""" data += ErrorMsg() data+="\n" req.write(data) return apache.OK def ErrorMsg(escape=0): """ returns: string simualtes the traceback output and if argemument