[Zope] my custom log method for logging users
Erik Myllymaki
Erik Myllymaki <erik@pacific-shores.com>
Thu, 27 Dec 2001 15:32:03 -0800
I have rewritten log function in http_server so that I can log usernames and
passwords. I got this mostly from a post in the archives but since I am
using login manager with basic cookie authentication it needs to grab the
cookie and do some work on it. The only problem I am having is that the
base64.decode function throws a binascii.error when a user has some special
characters in her username:password. This happens with the underscore
character for sure, and maybe others...I haven't checkd for sure.
Any ideas? I assume it is supposed to do this (or there is a bug in the
base64 module), so what would anyone suggest as a solution?
def log (self, bytes):
user_agent=self.get_header('user-agent')
if not user_agent: user_agent=''
referer=self.get_header('referer')
if not referer: referer=''
k=self.get_header('cookie')
cookie_name = '__ac'
cookies={}
cookie='?'
lname = '?'
password = '?'
if k:
parse_cookie(k, cookies)
cookie=cookies.get(cookie_name, '')
try : [lname, password] =
split(decodestring(split(cookie)[-1]),':',1)
except : pass
self.channel.server.logger.log (
self.channel.addr[0],
' - "%s:%s" - %s - [%s] "%s" %d %d "%s" "%s"\n' % (
lname,
password,
cookie,
self.log_date_string (time.time()),
self.request,
self.reply_code,
bytes,
referer,
user_agent,
)
)
TIA
--
Erik Myllymaki
erik@pacific-shores.com