[Erp5-report] r22585 - in /erp5/trunk/products/ERP5Type: ZopePatch.py patches/http_server.py

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Jul 21 13:59:04 CEST 2008


Author: yo
Date: Mon Jul 21 13:59:01 2008
New Revision: 22585

URL: http://svn.erp5.org?rev=22585&view=rev
Log:
Yet another monkey patch to record original IP addresses in Z2.log (when the proxy is trusted).

Added:
    erp5/trunk/products/ERP5Type/patches/http_server.py
Modified:
    erp5/trunk/products/ERP5Type/ZopePatch.py

Modified: erp5/trunk/products/ERP5Type/ZopePatch.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/ZopePatch.py?rev=22585&r1=22584&r2=22585&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/ZopePatch.py (original)
+++ erp5/trunk/products/ERP5Type/ZopePatch.py Mon Jul 21 13:59:01 2008
@@ -56,6 +56,7 @@
 from Products.ERP5Type.patches import PythonScript
 from Products.ERP5Type.patches import MailTemplates
 from Products.ERP5Type.patches import persistent_patch
+from Products.ERP5Type.patches import http_server
 
 # for python2.3 compatibility
 import threading

Added: erp5/trunk/products/ERP5Type/patches/http_server.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/patches/http_server.py?rev=22585&view=auto
==============================================================================
--- erp5/trunk/products/ERP5Type/patches/http_server.py (added)
+++ erp5/trunk/products/ERP5Type/patches/http_server.py Mon Jul 21 13:59:01 2008
@@ -1,0 +1,74 @@
+# This code is taken from the medusa in zope 2.8.
+#
+# The license term should be this one:
+#
+# Medusa is Copyright 1996-2000, Sam Rushing <rushing at nightmare.com>
+#
+#                         All Rights Reserved
+#
+# Permission to use, copy, modify, and distribute this software and
+# its documentation for any purpose and without fee is hereby
+# granted, provided that the above copyright notice appear in all
+# copies and that both that copyright notice and this permission
+# notice appear in supporting documentation, and that the name of Sam
+# Rushing not be used in advertising or publicity pertaining to
+# distribution of the software without specific, written prior
+# permission.
+
+#   Author: Sam Rushing <rushing at nightmare.com>
+#   Copyright 1996-2000 by Sam Rushing
+#                        All Rights Reserved.
+
+
+from ZServer.medusa.http_server import http_request
+from ZPublisher.HTTPRequest import trusted_proxies
+import string
+import base64
+import time
+
+def log (self, bytes):
+    # The purpose of this patch is to emit original IP addresses in Z2.log
+    # even when a reverse proxy is used. A similar thing is implemented
+    # in the ZPublisher, but not in the ZServer.
+    #
+    # <patch>
+    addr = self.channel.addr[0]
+    if trusted_proxies and addr in trusted_proxies:
+        original_addr = self.get_header('x-forwarded-for')
+        if original_addr:
+            addr = original_addr.split(', ')[0]
+    # </patch>
+
+    user_agent=self.get_header('user-agent')
+    if not user_agent: user_agent=''
+    referer=self.get_header('referer')
+    if not referer: referer=''
+
+    auth=self.get_header('Authorization')
+    name='Anonymous'
+    if auth is not None:
+        if string.lower(auth[:6]) == 'basic ':
+            try: decoded=base64.decodestring(auth[6:])
+            except base64.binascii.Error: decoded=''
+            t = string.split(decoded, ':', 1)
+            if len(t) < 2:
+                name = 'Unknown (bad auth string)'
+            else:
+                name = t[0]
+
+    self.channel.server.logger.log (
+        # <patch>
+        addr,
+        # </patch>
+        '- %s [%s] "%s" %d %d "%s" "%s"\n' % (
+            name,
+            self.log_date_string (time.time()),
+            self.request,
+            self.reply_code,
+            bytes,
+            referer,
+            user_agent
+            )
+        )
+
+http_request.log = log




More information about the Erp5-report mailing list