Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

ip based restrictions for repoze.what.

Project Description

It is a repoze.what plugin that provides an ip_from predicate.

Installation

easy_install:

$ <env>/bin/easy_install repoze.what.plugins.ip

pip:

$ <env>/bin/pip install repoze.what.plugins.ip

Source

The source code can be found at code.google.com.

Usage

ip_from([allowed=None], [proxies=None]) checks whether REMOTE_ADDR in the environment points to an allowed IP address. If HTTP_X_FORWARDED_FOR is set in the environment (meaning proxy access) then REMOTE_ADDR is treated as a proxy address and HTTP_X_FORWARDED_FOR as an originating IP address.

allowed optional, default - None
A list of IPs to allow access. Can be a string which is then interpreted as a single IP address
proxies optional, default - None

If a list or tuple provided then treated as a list of authorized proxy IP addresses.

If a string or unicode provided then treated as a single IP address.

Any other value - bool(proxies) == True means that all proxies are accepted

You can filter the incoming IP address:

>>> from repoze.what.plugins.ip import ip_from
>>> p = ip_from(allowed=['192.168.1.1'])
>>> env = {'REMOTE_ADDR': '192.168.1.1'}
>>> p.is_met(env)
True
>>> env = {'REMOTE_ADDR': '192.168.1.10'}
>>> p.is_met(env)
False

By default proxy access is disabled. You can enable it with proxies=True:

>>> p = ip_from(allowed=['192.168.0.0/24'], proxies=True)
>>> env = {
...     'REMOTE_ADDR': '192.168.1.1',           # proxy
...     'HTTP_X_FORWARDED_FOR': '192.168.1.5'   # origin
... }
>>> p.is_met(env)
True

And you can also explicitly specify proxies to allow:

>>> p = ip_from(allowed='192.168.1.5', proxies=['192.168.0.0/24'])
>>> env = {
...     'REMOTE_ADDR': '192.168.1.1',           # proxy
...     'HTTP_X_FORWARDED_FOR': '192.168.1.5'   # origin
... }
>>> p.is_met(env)
True
Release History

Release History

This version
History Node

0.2

History Node

0.1.4.1

History Node

0.1.4

History Node

0.1.3.2

History Node

0.1.3.1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
repoze.what.plugins.ip-0.2-py2.5.egg (36.9 kB) Copy SHA256 Checksum SHA256 2.5 Egg Jun 24, 2010
repoze.what.plugins.ip-0.2-py2.6.egg (36.8 kB) Copy SHA256 Checksum SHA256 2.6 Egg Jun 24, 2010
repoze.what.plugins.ip-0.2.tar.gz (17.8 kB) Copy SHA256 Checksum SHA256 Source Jun 24, 2010

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting