Changeset - a9a6c74ad2a6
[Not reviewed]
default
0 2 0
Marcin Kuzminski - 15 years ago 2010-07-01 20:10:22
marcin@python-works.com
added ip loggin into mercurial middleware
2 files changed with 8 insertions and 2 deletions:
0 comments (0 inline, 0 general)
pylons_app/lib/middleware/simplehg.py
Show inline comments
 
@@ -95,13 +95,16 @@ class SimpleHg(object):
 
                    if not HasPermissionAnyMiddleware('repository.write',
 
                                                      'repository.admin')\
 
                                                        (user, repo_name):
 
                        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
 
            #===================================================================
 
            environ['PATH_INFO'] = '/'#since we wrap into hgweb, reset the path
 
            self.baseui = make_ui(self.config['hg_app_repo_conf'])
 
@@ -159,20 +162,21 @@ class SimpleHg(object):
 
        for qry in environ['QUERY_STRING'].split('&'):
 
            if qry.startswith('cmd'):
 
                cmd = qry.split('=')[-1]
 
                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()
 
            user_log.user_id = user.user_id
 
            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',
 
                                            user.username, action, repo)
 
        except Exception as e:
 
            sa.rollback()
pylons_app/templates/admin/admin_log.html
Show inline comments
 
@@ -3,20 +3,22 @@
 
<table class="table_disp">
 
	<tr class="header">
 
		<td>${_('Username')}</td>
 
		<td>${_('Repository')}</td>
 
		<td>${_('Action')}</td>
 
		<td>${_('Date')}</td>
 
		<td>${_('From IP')}</td>
 
	</tr>
 

	
 
	%for cnt,l in enumerate(c.users_log):
 
	<tr class="parity${cnt%2}">
 
		<td>${l.user.username}</td>
 
		<td>${l.repository}</td>
 
		<td>${l.action}</td>
 
		<td>${l.action_date}</td>
 
		<td>${l.user_ip}</td>
 
	</tr>
 
	%endfor
 

	
 
</table>
 
<div>
 
		<script type="text/javascript">
0 comments (0 inline, 0 general)