From f79cefe19a72e25652eff1b3e8a3b986c3f2dd72 Mon Sep 17 00:00:00 2001 From: Sarina Canelake Date: Sun, 2 Mar 2014 18:27:18 -0500 Subject: [PATCH] Add logging to embargo middleware --- common/djangoapps/embargo/middleware.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/djangoapps/embargo/middleware.py b/common/djangoapps/embargo/middleware.py index 2e2cb2b645..2330065a94 100644 --- a/common/djangoapps/embargo/middleware.py +++ b/common/djangoapps/embargo/middleware.py @@ -7,7 +7,7 @@ experiencing mysterious problems with embargoing, please check that your reverse proxy is setting any of the well known client IP address headers (ex., HTTP_X_FORWARDED_FOR). """ - +import logging import pygeoip from django.core.exceptions import MiddlewareNotUsed @@ -18,6 +18,8 @@ from util.request import course_id_from_url from embargo.models import EmbargoedCourse, EmbargoedState, IPFilter +log = logging.getLogger(__name__) + class EmbargoMiddleware(object): """ @@ -45,10 +47,15 @@ class EmbargoMiddleware(object): # if blacklisted, immediately fail if ip_addr in IPFilter.current().blacklist_ips: + log.info("Embargo: Restricting IP address %s to course %s because IP is blacklisted.", ip_addr, course_id) return redirect('embargo') country_code_from_ip = pygeoip.GeoIP(settings.GEOIP_PATH).country_code_by_addr(ip_addr) is_embargoed = country_code_from_ip in EmbargoedState.current().embargoed_countries_list # Fail if country is embargoed and the ip address isn't explicitly whitelisted if is_embargoed and ip_addr not in IPFilter.current().whitelist_ips: + log.info( + "Embargo: Restricting IP address %s to course %s because IP is from country %s.", + ip_addr, course_id, country_code_from_ip + ) return redirect('embargo')