Mercurial > kallithea
changeset 2184:79e4d6b9c1f0 beta
Added HTTP_X_FORWARDED_FOR as another method of extracting IP for pull/push logs.
- moved all to base controller
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 12 Apr 2012 22:49:13 +0200 |
parents | 9d27481228a1 |
children | eac0d6194783 |
files | rhodecode/lib/base.py rhodecode/lib/middleware/simplegit.py rhodecode/lib/middleware/simplehg.py |
diffstat | 3 files changed, 13 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/lib/base.py Wed Apr 11 23:10:46 2012 +0200 +++ b/rhodecode/lib/base.py Thu Apr 12 22:49:13 2012 +0200 @@ -116,6 +116,17 @@ return True + def _get_ip_addr(self, environ): + proxy_key = 'HTTP_X_REAL_IP' + proxy_key2 = 'HTTP_X_FORWARDED_FOR' + def_key = 'REMOTE_ADDR' + + return environ.get(proxy_key2, + environ.get(proxy_key, + environ.get(def_key, '0.0.0.0') + ) + ) + def __call__(self, environ, start_response): start = time.time() try:
--- a/rhodecode/lib/middleware/simplegit.py Wed Apr 11 23:10:46 2012 +0200 +++ b/rhodecode/lib/middleware/simplegit.py Thu Apr 12 22:49:13 2012 +0200 @@ -99,9 +99,7 @@ if not is_git(environ): return self.application(environ, start_response) - proxy_key = 'HTTP_X_REAL_IP' - def_key = 'REMOTE_ADDR' - ipaddr = environ.get(proxy_key, environ.get(def_key, '0.0.0.0')) + ipaddr = self._get_ip_addr(environ) username = None # skip passing error to error controller environ['pylons.status_code_redirect'] = True
--- a/rhodecode/lib/middleware/simplehg.py Wed Apr 11 23:10:46 2012 +0200 +++ b/rhodecode/lib/middleware/simplehg.py Thu Apr 12 22:49:13 2012 +0200 @@ -69,9 +69,7 @@ if not is_mercurial(environ): return self.application(environ, start_response) - proxy_key = 'HTTP_X_REAL_IP' - def_key = 'REMOTE_ADDR' - ipaddr = environ.get(proxy_key, environ.get(def_key, '0.0.0.0')) + ipaddr = self._get_ip_addr(environ) # skip passing error to error controller environ['pylons.status_code_redirect'] = True