Mercurial > kallithea
changeset 2374:be2163ef127e beta
Add ip reference into BaseController
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 03 Jun 2012 00:37:12 +0200 |
parents | 1828eb7fa688 |
children | bc2d8c03c050 |
files | rhodecode/lib/base.py |
diffstat | 1 files changed, 13 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/lib/base.py Sat Jun 02 18:01:56 2012 +0200 +++ b/rhodecode/lib/base.py Sun Jun 03 00:37:12 2012 +0200 @@ -30,6 +30,16 @@ log = logging.getLogger(__name__) +def _get_ip_addr(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')) + ) + + class BasicAuth(AuthBasicAuthenticator): def __init__(self, realm, authfunc, auth_http_code=None): @@ -117,15 +127,7 @@ 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') - ) - ) + return _get_ip_addr(environ) def __call__(self, environ, start_response): start = time.time() @@ -153,6 +155,7 @@ self.sa = meta.Session self.scm_model = ScmModel(self.sa) + self.ip_addr = '' def __call__(self, environ, start_response): """Invoke the Controller""" @@ -161,6 +164,7 @@ # available in environ['pylons.routes_dict'] start = time.time() try: + self.ip_addr = _get_ip_addr(environ) # make sure that we update permissions each time we call controller api_key = request.GET.get('api_key') cookie_store = CookieStoreWrapper(session.get('rhodecode_user'))