changeset 331:a9a6c74ad2a6

added ip loggin into mercurial middleware
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 01 Jul 2010 20:10:22 +0200
parents 4c9a295d80a4
children 40b409af53a5
files pylons_app/lib/middleware/simplehg.py pylons_app/templates/admin/admin_log.html
diffstat 2 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pylons_app/lib/middleware/simplehg.py	Thu Jul 01 20:02:06 2010 +0200
+++ b/pylons_app/lib/middleware/simplehg.py	Thu Jul 01 20:10:22 2010 +0200
@@ -98,7 +98,10 @@
                         return HTTPForbidden()(environ, start_response)
                 
                 #log action    
-                self.__log_user_action(user, action, repo_name)            
+                proxy_key = 'HTTP_X_REAL_IP'
+                def_key = 'REMOTE_ADDR'
+                ipaddr = environ.get(proxy_key, environ.get(def_key, '0.0.0.0'))
+                self.__log_user_action(user, action, repo_name, ipaddr)            
             
             #===================================================================
             # MERCURIAL REQUEST HANDLING
@@ -162,7 +165,7 @@
                 if mapping.has_key(cmd):
                     return mapping[cmd]
     
-    def __log_user_action(self, user, action, repo):
+    def __log_user_action(self, user, action, repo, ipaddr):
         sa = meta.Session
         try:
             user_log = UserLog()
@@ -170,6 +173,7 @@
             user_log.action = action
             user_log.repository = repo.replace('/', '')
             user_log.action_date = datetime.now()
+            user_log.user_ip = ipaddr
             sa.add(user_log)
             sa.commit()
             log.info('Adding user %s, action %s on %s',
--- a/pylons_app/templates/admin/admin_log.html	Thu Jul 01 20:02:06 2010 +0200
+++ b/pylons_app/templates/admin/admin_log.html	Thu Jul 01 20:10:22 2010 +0200
@@ -6,6 +6,7 @@
 		<td>${_('Repository')}</td>
 		<td>${_('Action')}</td>
 		<td>${_('Date')}</td>
+		<td>${_('From IP')}</td>
 	</tr>
 
 	%for cnt,l in enumerate(c.users_log):
@@ -14,6 +15,7 @@
 		<td>${l.repository}</td>
 		<td>${l.action}</td>
 		<td>${l.action_date}</td>
+		<td>${l.user_ip}</td>
 	</tr>
 	%endfor