Giter VIP home page Giter VIP logo

django-admin-ip-restrictor's Introduction

Django Admin IP Restrictor

https://travis-ci.org/sdonk/django-admin-ip-restrictor.svg?branch=master

A Django middleware to restrict the access to the Django admin based on incoming IPs

Requirements

  • Python >= 3.5
  • Django >= 1.11,<3
  • django-ipware=>2,<3

Usage

First install the package:

$ pip install django-admin-ip-restrictor

Then add the middleware to your settings:

MIDDLEWARE = [
    ...
    'admin_ip_restrictor.middleware.AdminIPRestrictorMiddleware'
]

Set these variables in your settings.py to control who has access to the admin (IPV4 and IPV6 can be mixed):

RESTRICT_ADMIN=True
ALLOWED_ADMIN_IPS=['127.0.0.1', '::1']
ALLOWED_ADMIN_IP_RANGES=['127.0.0.0/24', '::/1']
RESTRICTED_APP_NAMES=['admin']
TRUST_PRIVATE_IP=True

Use RESTRICTED_APP_NAMES to restrict the access to more apps. Admin app is always included.

If using environment variables make sure that the variables receive the right type of value. django-admin-ip-restrictor automatically converts the following formats:

$ export RESTRICT_ADMIN='true'
$ export ALLOWED_ADMIN_IPS='127.0.0.1,::1'
$ export ALLOWED_ADMIN_IP_RANGES='127.0.0.0/24,::/1'
$ export RESTRICTED_APP_NAMES='wagtail_admin,foo'

For RESTRICT_ADMIN also these values can be used: True, 1, false, False, 0

Use TRUST_PRIVATE_IP to skip checking IP addresses from a trusted private network.

Changelog

Full changelog at https://github.com/sdonk/django-admin-ip-restrictor/blob/master/CHANGELOG.rst

Run tests

Install tox:

$ pip install tox

Install pyenv, use https://github.com/pyenv/pyenv#installation as reference.

Install Python versions in pyenv:

$ pyenv install 3.5.9
$ pyenv install 3.6.10
$ pyenv install 3.7.6
$ pyenv install 3.8.1

Specify the Python versions you want to test with:

$ pyenv local 3.5.9 3.6.10 3.7.6 3.8.1

Run tests:

$ tox

Contribute

Fork the project and submit a PR!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.