##// END OF EJS Templates
added ip loggin into mercurial middleware
marcink -
r331:a9a6c74a default
parent child Browse files
Show More
@@ -98,7 +98,10 b' class SimpleHg(object):'
98 return HTTPForbidden()(environ, start_response)
98 return HTTPForbidden()(environ, start_response)
99
99
100 #log action
100 #log action
101 self.__log_user_action(user, action, repo_name)
101 proxy_key = 'HTTP_X_REAL_IP'
102 def_key = 'REMOTE_ADDR'
103 ipaddr = environ.get(proxy_key, environ.get(def_key, '0.0.0.0'))
104 self.__log_user_action(user, action, repo_name, ipaddr)
102
105
103 #===================================================================
106 #===================================================================
104 # MERCURIAL REQUEST HANDLING
107 # MERCURIAL REQUEST HANDLING
@@ -162,7 +165,7 b' class SimpleHg(object):'
162 if mapping.has_key(cmd):
165 if mapping.has_key(cmd):
163 return mapping[cmd]
166 return mapping[cmd]
164
167
165 def __log_user_action(self, user, action, repo):
168 def __log_user_action(self, user, action, repo, ipaddr):
166 sa = meta.Session
169 sa = meta.Session
167 try:
170 try:
168 user_log = UserLog()
171 user_log = UserLog()
@@ -170,6 +173,7 b' class SimpleHg(object):'
170 user_log.action = action
173 user_log.action = action
171 user_log.repository = repo.replace('/', '')
174 user_log.repository = repo.replace('/', '')
172 user_log.action_date = datetime.now()
175 user_log.action_date = datetime.now()
176 user_log.user_ip = ipaddr
173 sa.add(user_log)
177 sa.add(user_log)
174 sa.commit()
178 sa.commit()
175 log.info('Adding user %s, action %s on %s',
179 log.info('Adding user %s, action %s on %s',
@@ -6,6 +6,7 b''
6 <td>${_('Repository')}</td>
6 <td>${_('Repository')}</td>
7 <td>${_('Action')}</td>
7 <td>${_('Action')}</td>
8 <td>${_('Date')}</td>
8 <td>${_('Date')}</td>
9 <td>${_('From IP')}</td>
9 </tr>
10 </tr>
10
11
11 %for cnt,l in enumerate(c.users_log):
12 %for cnt,l in enumerate(c.users_log):
@@ -14,6 +15,7 b''
14 <td>${l.repository}</td>
15 <td>${l.repository}</td>
15 <td>${l.action}</td>
16 <td>${l.action}</td>
16 <td>${l.action_date}</td>
17 <td>${l.action_date}</td>
18 <td>${l.user_ip}</td>
17 </tr>
19 </tr>
18 %endfor
20 %endfor
19
21
General Comments 0
You need to be logged in to leave comments. Login now