4 usage: %(progname)s [args] 8 import os, sys, string, time, getopt
11 from pyclearsilver
import odb
19 checkval =
"%s:%s" % (username, now)
20 realcheckval =
"%s:%s:%s" % (checkval, pw_hash, vcode)
21 checkval_hash = crypt.crypt(realcheckval,config.gAuthSalt)
22 return checkval, checkval_hash
32 now = int(time.time())
34 row = authdb.browserid.newRow()
35 row.creationDate = now
39 cookie =
"V1/%09d" % row.browserid
41 return cookie, row.browserid
44 ipaddr = ncgi.hdf.getValue(
"CGI.RemoteAddress",
"")
47 ncgi.cookieSet(
"MB_B", bcookie, persist=1, path=
"/", domain=config.gDomain)
52 ncgi.cookieClear(
"MB_B",
"",
"/")
55 bcookie = ncgi.hdf.getValue(
"Cookie.MB_B",
"")
57 if not bcookie:
return None 59 version, restCookie = string.split(bcookie,
"/", 1)
60 browserid = int(restCookie)
66 version, restCookie = string.split(cookie,
"/", 1)
68 warn(
"browserauth.py",
"invalid browser cookie, version", version, cookie)
71 browserid = int(restCookie)
74 row = authdb.browserid.fetchRow((
"browserid", browserid))
75 except odb.eNoMatchingRows:
76 warn(
"browserauth.py",
"invalid browser cookie, browserid not found")
80 if row.ipaddr != ipaddr:
81 warn(
"browserauth.py",
"ipaddr mismatch", row.ipaddr, ipaddr)
83 debug(
"browserauth.py",
"cookie", browserid)
88 bcookie = ncgi.hdf.getValue(
"Cookie.MB_B",
"")
89 if not bcookie:
return None 91 ipaddr = ncgi.hdf.getValue(
"CGI.RemoteAddress",
"")
102 print __doc__ % vars()
104 def main(argv, stdout, environ):
106 optlist, args = getopt.getopt(argv[1:],
"", [
"help",
"test",
"debug"])
112 for (field, val)
in optlist:
113 if field ==
"--help":
116 elif field ==
"--debug":
118 elif field ==
"--test":
126 if __name__ ==
"__main__":
127 main(sys.argv, sys.stdout, os.environ)
def _checkBrowserCookie(authdb, cookie, ipaddr)
def clearBrowserCookie(ncgi)
def getBrowserCookie(ncgi)
def checkBrowserCookie(authdb, ncgi)
def generateBrowserCookie(authdb, ipaddr)
def main(argv, stdout, environ)
def _createCheckVal(username, issued_at, pw_hash, vcode)
def issueBrowserCookie(ncgi, authdb, domain)