Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
3802e8f5
Commit
3802e8f5
authored
Mar 03, 2014
by
Sarina Canelake
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2779 from edx/sarina/embargo-logging
Add logging to embargo middleware
parents
030004bc
f79cefe1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
1 deletions
+8
-1
common/djangoapps/embargo/middleware.py
+8
-1
No files found.
common/djangoapps/embargo/middleware.py
View file @
3802e8f5
...
...
@@ -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'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment