From eb41de8f7624776ec6bf2dbc3c7d18f6c29e499a Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 4 Jul 2014 14:43:49 +0530 Subject: [PATCH] added frappe.local.request_ip --- frappe/__init__.py | 1 + frappe/auth.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index a83bd48042..12f1157196 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -94,6 +94,7 @@ def init(site, sites_path=None): local.site_path = os.path.join(sites_path, site) local.request_method = request.method if request else None + local.request_ip = None local.response = _dict({"docs":[]}) local.conf = _dict(get_site_config()) diff --git a/frappe/auth.py b/frappe/auth.py index 0597e7d59e..3dc06bcd39 100644 --- a/frappe/auth.py +++ b/frappe/auth.py @@ -20,6 +20,8 @@ class HTTPRequest: if self.domain and self.domain.startswith('www.'): self.domain = self.domain[4:] + frappe.local.request_ip = frappe.get_request_header('REMOTE_ADDR') \ + or frappe.get_request_header('X-Forwarded-For') or '127.0.0.1' # language self.set_lang(frappe.get_request_header('HTTP_ACCEPT_LANGUAGE')) @@ -157,7 +159,7 @@ class LoginManager: ip_list = [i.strip() for i in ip_list] for ip in ip_list: - if frappe.get_request_header('REMOTE_ADDR', '').startswith(ip) or frappe.get_request_header('X-Forwarded-For', '').startswith(ip): + if frappe.local.request_ip.startswith(ip): return frappe.throw(_("Not allowed from this IP Address"), frappe.AuthenticationError)