Hello

Here is a patch for lib/python/ZServer/FCGIServer.py so the username is
also logged when accessing Zope via FastCGI. Currently it is always
displayed as a dash.


Stef



-- 
---------------------------------------------------------------
addr://Kasinostrasse 30, CH-5001 Aarau   fon://++41 62 823 9355
http://www.terreactive.com               fax://++41 62 823 9356
---------------------------------------------------------------
10 Jahre Kompetenz in IT-Sicherheit.                1996 - 2006
Wir sichern Ihren Erfolg.                        terreActive AG
---------------------------------------------------------------
--- /usr/opt/zope/lib/python/ZServer/FCGIServer.py.orig	2004-12-02 00:01:48 +0100
+++ /usr/opt/zope/lib/python/ZServer/FCGIServer.py	2006-02-07 15:05:06 +0100
@@ -47,6 +47,7 @@
 import socket, string, os, sys, time
 import thread
 from types import StringTypes
+import base64
 
 tz_for_log = compute_timezone_for_log()
 
@@ -455,11 +456,24 @@
             method=self.env['REQUEST_METHOD']
         else:
             method="GET"
+        if self.env.has_key('HTTP_AUTHORIZATION'):
+            http_authorization=self.env['HTTP_AUTHORIZATION']
+            if string.lower(http_authorization[:6]) == 'basic ':
+                try: decoded=base64.decodestring(http_authorization[6:])
+                except base64.binascii.Error: decoded=''
+                t = string.split(decoded, ':', 1)
+                if len(t) < 2:
+                    user_name = '-'
+                else:
+                    user_name = t[0]
+        else:
+            user_name='-'
         if self.addr:
             self.server.logger.log (
                 self.addr[0],
-                '%s - - [%s] "%s %s" %d %d "%s" "%s"' % (
+                '%s - %s [%s] "%s %s" %d %d "%s" "%s"' % (
                     self.addr[1],
+                    user_name,
                     time.strftime (
                     '%d/%b/%Y:%H:%M:%S ',
                     time.localtime(time.time())
@@ -471,7 +485,8 @@
         else:
             self.server.logger.log (
                 '127.0.0.1 ',
-                '- - [%s] "%s %s" %d %d "%s" "%s"' % (
+                '- %s [%s] "%s %s" %d %d "%s" "%s"' % (
+                    user_name,
                     time.strftime (
                     '%d/%b/%Y:%H:%M:%S ',
                     time.localtime(time.time())
_______________________________________________
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )

Reply via email to