From ba0c3385a4d4391335de4915301e9b454d224fa6 Mon Sep 17 00:00:00 2001 From: Vitor Choi Feitosa Date: Tue, 4 Oct 2016 18:18:57 -0300 Subject: [PATCH] Verificando IP de origem com django-ipware --- requirements/requirements.txt | 1 + sigi/apps/whois/views.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 7faa83b..abfd1d4 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -20,3 +20,4 @@ reportlab==2.7 requests==2.8.1 six==1.10.0 djangorestframework==2.4.8 +django-ipware==1.1.6 diff --git a/sigi/apps/whois/views.py b/sigi/apps/whois/views.py index 4115b1e..aad3675 100644 --- a/sigi/apps/whois/views.py +++ b/sigi/apps/whois/views.py @@ -6,6 +6,7 @@ from django.views.decorators.csrf import csrf_exempt from rest_framework import status, permissions from rest_framework.response import Response from rest_framework.decorators import api_view, permission_classes +from ipware.ip import get_ip import re from urlparse import urlparse @@ -20,7 +21,7 @@ class WhitelistPermission(permissions.BasePermission): """ def has_permission(self, request, view): - ip_addr = request.META['REMOTE_ADDR'] + ip_addr = get_ip(request) if ip_addr in WHOIS_WHITELIST: return True else: