1. mikespook
  2. RhodeCode

Commits

Marcin Kuzminski  committed 79e4d6b

Added HTTP_X_FORWARDED_FOR as another method of extracting IP for pull/push logs.
- moved all to base controller

  • Participants
  • Parent commits 9d27481
  • Branches beta

Comments (0)

Files changed (3)

File rhodecode/lib/base.py

View file
 
         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:

File rhodecode/lib/middleware/simplegit.py

View file
         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

File rhodecode/lib/middleware/simplehg.py

View file
         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