Mercurial > kallithea
comparison rhodecode/lib/base.py @ 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 | 79e4d6b9c1f0 |
children | 1bc579bcd67a |
comparison
equal
deleted
inserted
replaced
2373:1828eb7fa688 | 2374:be2163ef127e |
---|---|
26 from rhodecode.model.db import Repository | 26 from rhodecode.model.db import Repository |
27 from rhodecode.model.notification import NotificationModel | 27 from rhodecode.model.notification import NotificationModel |
28 from rhodecode.model.scm import ScmModel | 28 from rhodecode.model.scm import ScmModel |
29 | 29 |
30 log = logging.getLogger(__name__) | 30 log = logging.getLogger(__name__) |
31 | |
32 | |
33 def _get_ip_addr(environ): | |
34 proxy_key = 'HTTP_X_REAL_IP' | |
35 proxy_key2 = 'HTTP_X_FORWARDED_FOR' | |
36 def_key = 'REMOTE_ADDR' | |
37 | |
38 return environ.get(proxy_key2, | |
39 environ.get(proxy_key, environ.get(def_key, '0.0.0.0')) | |
40 ) | |
31 | 41 |
32 | 42 |
33 class BasicAuth(AuthBasicAuthenticator): | 43 class BasicAuth(AuthBasicAuthenticator): |
34 | 44 |
35 def __init__(self, realm, authfunc, auth_http_code=None): | 45 def __init__(self, realm, authfunc, auth_http_code=None): |
115 return False | 125 return False |
116 | 126 |
117 return True | 127 return True |
118 | 128 |
119 def _get_ip_addr(self, environ): | 129 def _get_ip_addr(self, environ): |
120 proxy_key = 'HTTP_X_REAL_IP' | 130 return _get_ip_addr(environ) |
121 proxy_key2 = 'HTTP_X_FORWARDED_FOR' | |
122 def_key = 'REMOTE_ADDR' | |
123 | |
124 return environ.get(proxy_key2, | |
125 environ.get(proxy_key, | |
126 environ.get(def_key, '0.0.0.0') | |
127 ) | |
128 ) | |
129 | 131 |
130 def __call__(self, environ, start_response): | 132 def __call__(self, environ, start_response): |
131 start = time.time() | 133 start = time.time() |
132 try: | 134 try: |
133 return self._handle_request(environ, start_response) | 135 return self._handle_request(environ, start_response) |
151 .get_unread_cnt_for_user(c.rhodecode_user.user_id) | 153 .get_unread_cnt_for_user(c.rhodecode_user.user_id) |
152 self.cut_off_limit = int(config.get('cut_off_limit')) | 154 self.cut_off_limit = int(config.get('cut_off_limit')) |
153 | 155 |
154 self.sa = meta.Session | 156 self.sa = meta.Session |
155 self.scm_model = ScmModel(self.sa) | 157 self.scm_model = ScmModel(self.sa) |
158 self.ip_addr = '' | |
156 | 159 |
157 def __call__(self, environ, start_response): | 160 def __call__(self, environ, start_response): |
158 """Invoke the Controller""" | 161 """Invoke the Controller""" |
159 # WSGIController.__call__ dispatches to the Controller method | 162 # WSGIController.__call__ dispatches to the Controller method |
160 # the request is routed to. This routing information is | 163 # the request is routed to. This routing information is |
161 # available in environ['pylons.routes_dict'] | 164 # available in environ['pylons.routes_dict'] |
162 start = time.time() | 165 start = time.time() |
163 try: | 166 try: |
167 self.ip_addr = _get_ip_addr(environ) | |
164 # make sure that we update permissions each time we call controller | 168 # make sure that we update permissions each time we call controller |
165 api_key = request.GET.get('api_key') | 169 api_key = request.GET.get('api_key') |
166 cookie_store = CookieStoreWrapper(session.get('rhodecode_user')) | 170 cookie_store = CookieStoreWrapper(session.get('rhodecode_user')) |
167 user_id = cookie_store.get('user_id', None) | 171 user_id = cookie_store.get('user_id', None) |
168 username = get_container_username(environ, config) | 172 username = get_container_username(environ, config) |