# Django Forbid <img src="https://github.com/pysnippet.png" align="right" height="64" />
[![PyPI](https://img.shields.io/pypi/v/django-forbid.svg)](https://pypi.org/project/django-forbid/)
[![Python](https://img.shields.io/pypi/pyversions/django-forbid.svg?logoColor=white)](https://pypi.org/project/django-forbid/)
[![Django](https://img.shields.io/pypi/djversions/django-forbid.svg?color=0C4B33&label=django)](https://pypi.org/project/django-forbid/)
[![Tests](https://github.com/pysnippet/django-forbid/actions/workflows/tests.yml/badge.svg)](https://github.com/pysnippet/django-forbid/actions/workflows/tests.yml)
[![Docs](https://github.com/pysnippet/django-forbid/actions/workflows/docs.yml/badge.svg)](https://github.com/pysnippet/django-forbid/actions/workflows/docs.yml)
Django Forbid aims to make website access managed and secure for the maintainers. It provides a middleware to grant or
deny user access based on device and/or location. It also supports VPN detection for banning users who want to lie about
their country and geolocation. Also, users can use only the VPN detection feature or disable it.
## Installation
```shell
python -m pip install django-forbid
```
## Configuration
Add the `django_forbid.apps.ForbidConfig` to your `INSTALLED_APPS` in your Django project's **settings.py** file.
```python
INSTALLED_APPS = [
..., # other apps
'django_forbid.apps.ForbidConfig',
]
```
Also, add the `django_forbid.middleware.ForbidMiddleware` to the `MIDDLEWARE` list of the project.
```python
MIDDLEWARE = [
..., # other middlewares
'django_forbid.middleware.ForbidMiddleware',
]
```
Configuring the `GEOIP_PATH` variable in your project's settings is important. This variable should contain the path to
the GeoLite2 database file. You should [download](https://dev.maxmind.com/geoip/geoip2/geolite2/) the database and
follow the Django [documentation](https://docs.djangoproject.com/en/2.1/ref/contrib/gis/geoip2/#settings) for proper
configuration.
## Usage
After connecting the Django Forbid to your project, you can define the set of desired zones to be forbidden or allowed.
All you need is to set the `DJANGO_FORBID` variable in your project's settings. It should be a dictionary with the
following keys:
- `DEVICES` - list of devices to permit or forbid access to
- `COUNTRIES` - list of countries to permit or forbid access to
- `TERRITORIES` - list of territories to permit or forbid access to
- `OPTIONS` - a dictionary for additional settings
- `VPN` - use VPN detection and forbid access to VPN users
- `URL` - set of URLs to redirect to when the user is located in a forbidden country or using a VPN
- `FORBIDDEN_LOC` - the URL to redirect to when the user is located in a forbidden geolocation
- `FORBIDDEN_NET` - the URL to redirect to when the user is using a forbidden network (VPN)
- `FORBIDDEN_DEV` - the URL to redirect to when the user is using a forbidden device
The available device types are: `smartphone`, `peripheral` - refers to all hardware components that are attached to a
computer, `wearable` - common types of wearable technology include smartwatches and smartglasses, `phablet` - a
smartphone having a larger screen, `console` - PlayStation, Xbox, etc., `display`, `speaker` - Google Assistant, Siri,
Alexa, etc., `desktop`, `tablet`, `camera`, `player` - iPod, Sony Walkman, Creative Zen, etc., `phone`, `car` - refers
to a car browser and `tv` - refers to TVs having internet access.
```python
DJANGO_FORBID = {
'DEVICES': ['desktop', 'smartphone', 'console', 'tablet', 'tv'],
'COUNTRIES': ['US', 'GB'],
'TERRITORIES': ['EU'],
'OPTIONS': {
'VPN': True,
'URL': {
'FORBIDDEN_LOC': 'forbidden_location',
'FORBIDDEN_NET': 'forbidden_network',
'FORBIDDEN_DEV': 'forbidden_device',
},
},
}
```
The available country codes in the required ISO 3166 alpha-2 format are
listed [here](https://www.iban.com/country-codes). And the available continent codes (territories) are: `AF` -
Africa, `AN` - Antarctica, `AS` - Asia, `EU` - Europe, `NA` - North America, `OC` - Oceania and `SA` - South America.
_None of the settings are required. If you don't specify any settings, the middleware will not do anything._
## Contribute
Any contribution is welcome. If you have any ideas or suggestions, feel free to open an issue or a pull request. And
don't forget to add tests for your changes.
## License
Copyright (C) 2023 Artyom Vancyan. [MIT](https://github.com/pysnippet/django-forbid/blob/master/LICENSE)
Raw data
{
"_id": null,
"home_page": "",
"name": "django-forbid",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "python,django,permit,forbid,access,device,secure,country,control,security,location,territory,vpn,detection,django-forbid",
"author": "Artyom Vancyan",
"author_email": "artyom@pysnippet.org",
"download_url": "https://files.pythonhosted.org/packages/7b/03/6843a1243f623916a0969efb5f27ad52c811b1c6201a6eba6a924f81ac3a/django-forbid-0.1.6.tar.gz",
"platform": "unix",
"description": "# Django Forbid <img src=\"https://github.com/pysnippet.png\" align=\"right\" height=\"64\" />\n\n[![PyPI](https://img.shields.io/pypi/v/django-forbid.svg)](https://pypi.org/project/django-forbid/)\n[![Python](https://img.shields.io/pypi/pyversions/django-forbid.svg?logoColor=white)](https://pypi.org/project/django-forbid/)\n[![Django](https://img.shields.io/pypi/djversions/django-forbid.svg?color=0C4B33&label=django)](https://pypi.org/project/django-forbid/)\n[![Tests](https://github.com/pysnippet/django-forbid/actions/workflows/tests.yml/badge.svg)](https://github.com/pysnippet/django-forbid/actions/workflows/tests.yml)\n[![Docs](https://github.com/pysnippet/django-forbid/actions/workflows/docs.yml/badge.svg)](https://github.com/pysnippet/django-forbid/actions/workflows/docs.yml)\n\nDjango Forbid aims to make website access managed and secure for the maintainers. It provides a middleware to grant or\ndeny user access based on device and/or location. It also supports VPN detection for banning users who want to lie about\ntheir country and geolocation. Also, users can use only the VPN detection feature or disable it.\n\n## Installation\n\n```shell\npython -m pip install django-forbid\n```\n\n## Configuration\n\nAdd the `django_forbid.apps.ForbidConfig` to your `INSTALLED_APPS` in your Django project's **settings.py** file.\n\n```python\nINSTALLED_APPS = [\n ..., # other apps\n 'django_forbid.apps.ForbidConfig',\n]\n```\n\nAlso, add the `django_forbid.middleware.ForbidMiddleware` to the `MIDDLEWARE` list of the project.\n\n```python\nMIDDLEWARE = [\n ..., # other middlewares\n 'django_forbid.middleware.ForbidMiddleware',\n]\n```\n\nConfiguring the `GEOIP_PATH` variable in your project's settings is important. This variable should contain the path to\nthe GeoLite2 database file. You should [download](https://dev.maxmind.com/geoip/geoip2/geolite2/) the database and\nfollow the Django [documentation](https://docs.djangoproject.com/en/2.1/ref/contrib/gis/geoip2/#settings) for proper\nconfiguration.\n\n## Usage\n\nAfter connecting the Django Forbid to your project, you can define the set of desired zones to be forbidden or allowed.\nAll you need is to set the `DJANGO_FORBID` variable in your project's settings. It should be a dictionary with the\nfollowing keys:\n\n- `DEVICES` - list of devices to permit or forbid access to\n- `COUNTRIES` - list of countries to permit or forbid access to\n- `TERRITORIES` - list of territories to permit or forbid access to\n- `OPTIONS` - a dictionary for additional settings\n - `VPN` - use VPN detection and forbid access to VPN users\n - `URL` - set of URLs to redirect to when the user is located in a forbidden country or using a VPN\n - `FORBIDDEN_LOC` - the URL to redirect to when the user is located in a forbidden geolocation\n - `FORBIDDEN_NET` - the URL to redirect to when the user is using a forbidden network (VPN)\n - `FORBIDDEN_DEV` - the URL to redirect to when the user is using a forbidden device\n\nThe available device types are: `smartphone`, `peripheral` - refers to all hardware components that are attached to a\ncomputer, `wearable` - common types of wearable technology include smartwatches and smartglasses, `phablet` - a\nsmartphone having a larger screen, `console` - PlayStation, Xbox, etc., `display`, `speaker` - Google Assistant, Siri,\nAlexa, etc., `desktop`, `tablet`, `camera`, `player` - iPod, Sony Walkman, Creative Zen, etc., `phone`, `car` - refers\nto a car browser and `tv` - refers to TVs having internet access.\n\n```python\nDJANGO_FORBID = {\n 'DEVICES': ['desktop', 'smartphone', 'console', 'tablet', 'tv'],\n 'COUNTRIES': ['US', 'GB'],\n 'TERRITORIES': ['EU'],\n 'OPTIONS': {\n 'VPN': True,\n 'URL': {\n 'FORBIDDEN_LOC': 'forbidden_location',\n 'FORBIDDEN_NET': 'forbidden_network',\n 'FORBIDDEN_DEV': 'forbidden_device',\n },\n },\n}\n```\n\nThe available country codes in the required ISO 3166 alpha-2 format are\nlisted [here](https://www.iban.com/country-codes). And the available continent codes (territories) are: `AF` -\nAfrica, `AN` - Antarctica, `AS` - Asia, `EU` - Europe, `NA` - North America, `OC` - Oceania and `SA` - South America.\n\n_None of the settings are required. If you don't specify any settings, the middleware will not do anything._\n\n## Contribute\n\nAny contribution is welcome. If you have any ideas or suggestions, feel free to open an issue or a pull request. And\ndon't forget to add tests for your changes.\n\n## License\n\nCopyright (C) 2023 Artyom Vancyan. [MIT](https://github.com/pysnippet/django-forbid/blob/master/LICENSE)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Secure your Django app by controlling the access - grant or deny user access based on device and location, including VPN detection.",
"version": "0.1.6",
"project_urls": {
"Documentation": "https://docs.pysnippet.org/django-forbid/",
"Source Code": "https://github.com/pysnippet/django-forbid/"
},
"split_keywords": [
"python",
"django",
"permit",
"forbid",
"access",
"device",
"secure",
"country",
"control",
"security",
"location",
"territory",
"vpn",
"detection",
"django-forbid"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cada2a3557abed1c62257f71e15f3db1e651e2493d61245c6d2af54390f2996f",
"md5": "fc5a092fa5a2f4714e4d2350160feb82",
"sha256": "5628f0e27894c5f5264a7d2456845f3af3ac23b8a702b228ec3f9831caee5d93"
},
"downloads": -1,
"filename": "django_forbid-0.1.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fc5a092fa5a2f4714e4d2350160feb82",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 10718,
"upload_time": "2023-06-20T15:23:57",
"upload_time_iso_8601": "2023-06-20T15:23:57.857975Z",
"url": "https://files.pythonhosted.org/packages/ca/da/2a3557abed1c62257f71e15f3db1e651e2493d61245c6d2af54390f2996f/django_forbid-0.1.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7b036843a1243f623916a0969efb5f27ad52c811b1c6201a6eba6a924f81ac3a",
"md5": "dd6af866a3ebb904e79d3dadf4f22d50",
"sha256": "029d1c3ef8c2ee3e7f31fc5699f4056eca20d05f3e49deb3c1e384ae4e86348f"
},
"downloads": -1,
"filename": "django-forbid-0.1.6.tar.gz",
"has_sig": false,
"md5_digest": "dd6af866a3ebb904e79d3dadf4f22d50",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 11280,
"upload_time": "2023-06-20T15:23:59",
"upload_time_iso_8601": "2023-06-20T15:23:59.579067Z",
"url": "https://files.pythonhosted.org/packages/7b/03/6843a1243f623916a0969efb5f27ad52c811b1c6201a6eba6a924f81ac3a/django-forbid-0.1.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-20 15:23:59",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pysnippet",
"github_project": "django-forbid",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "django-forbid"
}