Mercurial > p > roundup > code
comparison roundup/cgi/client.py @ 2233:3d9bb1a052d1
fix random seeding for forking server
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 22 Apr 2004 22:16:36 +0000 |
| parents | ca2664e095be |
| children | f624fc20f8fe |
comparison
equal
deleted
inserted
replaced
| 2232:9bcfdd39bef8 | 2233:3d9bb1a052d1 |
|---|---|
| 1 # $Id: client.py,v 1.171 2004-04-20 21:57:10 richard Exp $ | 1 # $Id: client.py,v 1.172 2004-04-22 22:16:36 richard Exp $ |
| 2 | 2 |
| 3 """WWW request handler (also used in the stand-alone server). | 3 """WWW request handler (also used in the stand-alone server). |
| 4 """ | 4 """ |
| 5 __docformat__ = 'restructuredtext' | 5 __docformat__ = 'restructuredtext' |
| 6 | 6 |
| 7 import os, os.path, cgi, StringIO, urlparse, re, traceback, mimetypes, urllib | 7 import os, os.path, cgi, StringIO, urlparse, re, traceback, mimetypes, urllib |
| 8 import binascii, Cookie, time, random, stat, rfc822 | 8 import binascii, Cookie, time, random, stat, rfc822 |
| 9 | |
| 9 | 10 |
| 10 from roundup import roundupdb, date, hyperdb, password | 11 from roundup import roundupdb, date, hyperdb, password |
| 11 from roundup.i18n import _ | 12 from roundup.i18n import _ |
| 12 from roundup.cgi import templating, cgitb | 13 from roundup.cgi import templating, cgitb |
| 13 from roundup.cgi.actions import * | 14 from roundup.cgi.actions import * |
| 95 # Note: index page stuff doesn't appear here: | 96 # Note: index page stuff doesn't appear here: |
| 96 # columns, sort, sortdir, filter, group, groupdir, search_text, | 97 # columns, sort, sortdir, filter, group, groupdir, search_text, |
| 97 # pagesize, startwith | 98 # pagesize, startwith |
| 98 | 99 |
| 99 def __init__(self, instance, request, env, form=None): | 100 def __init__(self, instance, request, env, form=None): |
| 101 # re-seed the random number generator | |
| 102 random.seed() | |
| 100 if __debug__: | 103 if __debug__: |
| 101 hyperdb.traceMark() | 104 hyperdb.traceMark() |
| 102 self.start = time.time() | 105 self.start = time.time() |
| 103 self.instance = instance | 106 self.instance = instance |
| 104 self.request = request | 107 self.request = request |
| 610 def set_cookie(self, user): | 613 def set_cookie(self, user): |
| 611 """Set up a session cookie for the user. | 614 """Set up a session cookie for the user. |
| 612 | 615 |
| 613 Also store away the user's login info against the session. | 616 Also store away the user's login info against the session. |
| 614 """ | 617 """ |
| 615 # TODO generate a much, much stronger session key ;) | 618 sessions = self.db.getSessionManager() |
| 616 self.session = binascii.b2a_base64(repr(random.random())).strip() | 619 |
| 620 # generate a session key | |
| 621 s = '%s%s'%(time.time(), random.random()) | |
| 622 print s | |
| 623 self.session = binascii.b2a_base64(s).strip() | |
| 624 while sessions.exists(self.session): | |
| 625 s = '%s%s'%(time.time(), random.random()) | |
| 626 self.session = binascii.b2a_base64(s).strip() | |
| 617 | 627 |
| 618 # clean up the base64 | 628 # clean up the base64 |
| 619 if self.session[-1] == '=': | 629 if self.session[-1] == '=': |
| 620 if self.session[-2] == '=': | 630 if self.session[-2] == '=': |
| 621 self.session = self.session[:-2] | 631 self.session = self.session[:-2] |
| 622 else: | 632 else: |
| 623 self.session = self.session[:-1] | 633 self.session = self.session[:-1] |
| 624 | 634 |
| 625 # insert the session in the sessiondb | 635 # insert the session in the sessiondb |
| 626 sessions = self.db.getSessionManager() | |
| 627 sessions.set(self.session, user=user) | 636 sessions.set(self.session, user=user) |
| 628 self.db.commit() | 637 self.db.commit() |
| 629 | 638 |
| 630 # expire us in a long, long time | 639 # expire us in a long, long time |
| 631 expire = Cookie._getdate(86400*365) | 640 expire = Cookie._getdate(86400*365) |
