def authorize(request, *args, **kwargs): user_ip = get_client_ip(request) if settings.LOCKSS_DEBUG_IPS: logger.warn("CACHED MIRRORS: {}".format(Mirror.get_cached_mirrors())) logger.warn("CLIENT IP: {}".format(user_ip)) logger.warn("request.META: {}\n".format(request.META)) for mirror in Mirror.get_cached_mirrors(): if user_ip == mirror['ip']: return view_func(request, *args, **kwargs) return HttpResponseForbidden()
def authorize(request, *args, **kwargs): user_ip = get_client_ip(request) if settings.LOCKSS_DEBUG_IPS: logger.warn("CACHED MIRRORS: {}".format( Mirror.get_cached_mirrors())) logger.warn("CLIENT IP: {}".format(user_ip)) logger.warn("request.META: {}\n".format(request.META)) for mirror in Mirror.get_cached_mirrors(): if user_ip == mirror['ip']: return view_func(request, *args, **kwargs) return HttpResponseForbidden()
def test_get_client_ip(self): request = self.factory.get('/some/route', REMOTE_ADDR="1.2.3.4") self.assertEqual(get_client_ip(request), "1.2.3.4")
def client_ip(request): return HttpResponse(get_client_ip(request))