[Zope-Checkins] SVN: Zope/branches/2.9/ Collector #2185: Log username for FCGI requests.

Tres Seaver tseaver at palladion.com
Wed Sep 6 11:23:51 EDT 2006


Log message for revision 70001:
  Collector #2185: Log username for FCGI requests.
  
  

Changed:
  U   Zope/branches/2.9/doc/CHANGES.txt
  U   Zope/branches/2.9/lib/python/ZServer/FCGIServer.py

-=-
Modified: Zope/branches/2.9/doc/CHANGES.txt
===================================================================
--- Zope/branches/2.9/doc/CHANGES.txt	2006-09-06 15:19:04 UTC (rev 70000)
+++ Zope/branches/2.9/doc/CHANGES.txt	2006-09-06 15:23:51 UTC (rev 70001)
@@ -8,6 +8,8 @@
 
    Bugs fixed
 
+      - Collector #2185: Log username for FCGI requests.
+
       - Collector #2152: Fixed MailHost documentation; simple_send does not
         process or validate its arguments in any way.
 

Modified: Zope/branches/2.9/lib/python/ZServer/FCGIServer.py
===================================================================
--- Zope/branches/2.9/lib/python/ZServer/FCGIServer.py	2006-09-06 15:19:04 UTC (rev 70000)
+++ Zope/branches/2.9/lib/python/ZServer/FCGIServer.py	2006-09-06 15:23:51 UTC (rev 70001)
@@ -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())



More information about the Zope-Checkins mailing list