Mercurial > p > roundup > code
comparison roundup/cgi/client.py @ 2928:81c99c857b57
applied patch [SF#1067690]
| author | Alexander Smishlajev <a1s@users.sourceforge.net> |
|---|---|
| date | Thu, 18 Nov 2004 16:21:07 +0000 |
| parents | 29563959c026 |
| children | 46fdfcf42806 |
comparison
equal
deleted
inserted
replaced
| 2927:9ecca789544f | 2928:81c99c857b57 |
|---|---|
| 1 # $Id: client.py,v 1.201 2004-11-18 14:05:35 a1s Exp $ | 1 # $Id: client.py,v 1.202 2004-11-18 16:21:07 a1s 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 base64, binascii, cgi, codecs, mimetypes, os |
| 8 import binascii, Cookie, time, random, stat, rfc822 | 8 import random, re, rfc822, stat, time, urllib, urlparse |
| 9 import codecs | 9 import Cookie |
| 10 | |
| 11 | 10 |
| 12 from roundup import roundupdb, date, hyperdb, password | 11 from roundup import roundupdb, date, hyperdb, password |
| 13 from roundup.cgi import templating, cgitb, TranslationService | 12 from roundup.cgi import templating, cgitb, TranslationService |
| 14 from roundup.cgi.actions import * | 13 from roundup.cgi.actions import * |
| 15 from roundup.cgi.exceptions import * | 14 from roundup.cgi.exceptions import * |
| 148 self.additional_headers = {} | 147 self.additional_headers = {} |
| 149 self.response_code = 200 | 148 self.response_code = 200 |
| 150 | 149 |
| 151 # parse cookies (used in charset and session lookups) | 150 # parse cookies (used in charset and session lookups) |
| 152 self.cookie = Cookie.SimpleCookie(self.env.get('HTTP_COOKIE', '')) | 151 self.cookie = Cookie.SimpleCookie(self.env.get('HTTP_COOKIE', '')) |
| 152 | |
| 153 self.user = None | |
| 154 self.userid = None | |
| 153 | 155 |
| 154 def setTranslator(self, translator=None): | 156 def setTranslator(self, translator=None): |
| 155 """Replace the translation engine | 157 """Replace the translation engine |
| 156 | 158 |
| 157 'translator' | 159 'translator' |
| 292 """ | 294 """ |
| 293 sessions = self.db.getSessionManager() | 295 sessions = self.db.getSessionManager() |
| 294 last_clean = sessions.get('last_clean', 'last_use', 0) | 296 last_clean = sessions.get('last_clean', 'last_use', 0) |
| 295 | 297 |
| 296 # time to clean? | 298 # time to clean? |
| 297 week = 60*60*24*7 | 299 #week = 60*60*24*7 |
| 298 hour = 60*60 | 300 hour = 60*60 |
| 299 now = time.time() | 301 now = time.time() |
| 300 if now - last_clean < hour: | 302 if now - last_clean < hour: |
| 301 return | 303 return |
| 302 | 304 |
| 373 # by a front-end HTTP server) | 375 # by a front-end HTTP server) |
| 374 if self.env.has_key('REMOTE_USER'): | 376 if self.env.has_key('REMOTE_USER'): |
| 375 user = self.env['REMOTE_USER'] | 377 user = self.env['REMOTE_USER'] |
| 376 else: | 378 else: |
| 377 user = 'anonymous' | 379 user = 'anonymous' |
| 380 | |
| 381 # try handling Basic Auth ourselves | |
| 382 if (user == 'anonymous') and self.env['HTTP_AUTHORIZATION']: | |
| 383 scheme, challenge = self.env['HTTP_AUTHORIZATION'].split(' ', 1) | |
| 384 if scheme.lower() == 'basic': | |
| 385 try: | |
| 386 decoded = base64.decodestring(challenge) | |
| 387 except TypeError: | |
| 388 # invalid challenge | |
| 389 pass | |
| 390 username, password = decoded.split(':') | |
| 391 try: | |
| 392 LoginAction(self).verifyLogin(username, password) | |
| 393 except LoginError, err: | |
| 394 self.make_user_anonymous() | |
| 395 self.response_code = 403 | |
| 396 raise Unauthorised, err | |
| 397 | |
| 398 user = username | |
| 378 | 399 |
| 379 # look up the user session cookie (may override the REMOTE_USER) | 400 # look up the user session cookie (may override the REMOTE_USER) |
| 380 cookie = self.cookie | 401 cookie = self.cookie |
| 381 if (cookie.has_key(self.cookie_name) and | 402 if (cookie.has_key(self.cookie_name) and |
| 382 cookie[self.cookie_name].value != 'deleted'): | 403 cookie[self.cookie_name].value != 'deleted'): |
