edx/edx-platform — pull request #2776 by aboudreault (2014-03-02 00:06:34+00:00)
Title: Extended Embargo feature to support site access restriction and ip network

Devs, this is a pull request for the recruitment task (working with @antoviaque): Restrict access to the LMS by IP address. My initial implementation of the feature is in https://github.com/edx/edx-platform/pull/2717. However, by the time I coded the feature.... the Embargo feature has been merged in master. Since both features was similar, @jzoldak suggested that we should merged work and we agreed that it was making sense.

## Additions
The main goal of my addition is to be able to restrict the main site access by Ip addresses and/or networks. Since the goal of the initial Embargo feature was to restrict by courses... I needed to modify some parts to fit my need. Here are my my 3 additions to EmbargoMiddleware:

* Support of IP network in whitelist and blacklist. (We can now whitelist/blacklist with a network ip: like 10.0.0.0/24, 10.0.0.2/32, 10.1.0.0/16).
* New feature: EMBARGO_SITE. This enable the the main site restriction using the same rules in the database (configured with django admin).
* For EMBARGO_SITE, we can define a redirect url in settings: EMBARGO_SITE_REDIRECT_URL to specify an external url to be redirected rather than a 403 response.

## Notes

* My additions are entirely backward compatible if you were already using the Embargo feature.
* The logic order to accept/deny a request has not changed (Blacklist --> State (geoip) --> Whitelist). * * There is no change in the DB schema.
* New tests have been added and all passed.

## Requirements Change

@jtauber : I've added a package in the requirements: ipaddr (http://code.google.com/p/ipaddr-py/), which is to manage ip addresses and networks. It is licensed under Apache 2. Let me know if there is any issue.

@e0d : A new package has been added in requirements for the middleware: ipaddr (http://code.google.com/p/ipaddr-py/). However, I don't think it needs any system requirement.

Don't hesitate if you have question or need any clarification.

Thanks
Alan