# Welcome to django-request-filters
**django-request-filters** is a package developed for django to detect and block the users those are using VPN, Proxy, TOR or Relay.
This package uses [vpnapi.io](https://vpnapi.io/) API to detect the status of the user's IP address.
### **Installation**
---
Use pip to install from PyPI:
`pip install django-request-filters`
### **Documentation**
##### Settings:
1. Visit [vpnapi.io](https://vpnapi.io/) and create an account and obtain your API Key.
2. In **settings.py** add the variable `VPNAPI_KEY` and set it's value to your API key obtained in step 1.
```python
VPNAPI_KEY = 'Your vpnapi API key'
```
3. Add a **view** that will display to the users when they have blocked (optional setup):
If you want to show your designed page to blocked users, you can follow this step.
* Define a vew function:
```python
# For example we defined a view function in views.py
from django.shortcuts import render
from request_filters.decorators.ip_check import exempt_IPCheckMiddleware
@exempt_IPCheckMiddleware
def blockView(request):
return render(request, 'block_view.html')
```
As we must need to display the view function to blocked users, so the `exempt_IPCheckMiddleware` must be used in that view function.
* Add the path of the view function in **settings.py**:
```python
IP_BLOCK_VIEW = "app_name.views.blockView"
```
If you do not defined any view function for blocked users, then by default it will show a simple HTML page contains a text "We can't allow your request, because you are using VPN or Proxy or Tor or Relay." with *status code* 418.
4. Add additional settings in **settings.py** (optional):
* `BLOCK_VPN (optional default: True)`
If set to `True` all the users want accessing the site with VPN will be disallowed.
If set to `False`, users can access the site using VPN.
* `BLOCK_PROXY (optional default: True)`
If set to `True` all the users want accessing the site with Proxy will be disallowed.
If set to `False`, users can access the site using Proxy.
* `BLOCK_TOR (optional default: True)`
If set to `True` all the users want accessing the site with TOR will be disallowed.
If set to `False`, users can access the site using TOR.
* `BLOCK_RELAY (optional default: True)`
If set to `True` all the users want accessing the site with Relay will be disallowed.
If set to `False`, users can access the site using Relay.
##### Using Middleware (Use case 1):
Use *MIDDLEWARE* to block the anonymous users (i.e. those are using VPN, Proxy, TOR or Relay) to access all the view function (i.e. all the requests).
1. Add *MIDDLEWARE*:
In **settings.py** add `'request_filters.middlewares.ip_check.IPCheckMiddleware'` into MIDDLEWARE.
```python
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
.....................
.....................
'request_filters.middlewares.ip_check.IPCheckMiddleware' # We have added this new middleware
]
```
2. Exempt from some view functions
Adding the *middleware* will block the anonymous users, so that those users can visit any views.
If you want to allow anonymous users to visit only some specific views, you can do that by using the `exempt_IPCheckMiddleware` decorator on the view function.
```python
from request_filters.decorators.ip_check import exempt_IPCheckMiddleware
@exempt_IPCheckMiddleware
def home(request):
.........
.........
```
Here, for the above code sample, all the users (including anonymous users) can visit the *home view*.
You can use this method, when you want to block the anonymous users for almost all the view functions.
##### Using only Decorator (Use case 2):
You can also controll uses' request using decorator and without using Middleware.
* `prevent_anonymous_ip`
Import this decorator by - `from request_filters.decorators.ip_check import prevent_anonymous_ip`
If you add this decorator to a view function, this view function will not acessable to anonymous users.
This decorator has some optional parameter -
* `block_vpn (optional default: settings.BLOCK_VPN)`
If set to `True` VPN users can't visit the view function.
If set to `False`, VPN users can visit the view.
* `block_proxy (optional default: settings.BLOCK_PROXY)`
If set to `True` Proxy users can't visit the view function.
If set to `False`, Proxy users can visit the view.
* `block_tor (optional default: settings.BLOCK_TOR)`
If set to `True` TOR users can't visit the view function.
If set to `False`, TOR users can visit the view.
* `block_relay (optional default: settings.BLOCK_RELAY)`
If set to `True` Relay users can't visit the view function.
If set to `False`, Relay users can visit the view.
You can use this method, when you want to block the anonymous users only for few view functions.
### **Contributing**
---
To contribute to django-request-filters [create a fork](https://github.com/Samiddha99/django-request-filters) on GitHub. Clone your fork, make some changes, and submit a pull request.
### **Issues**
---
Use the GitHub [issue tracker](https://github.com/Samiddha99/django-request-filters/issues) for django-request-filters to submit bugs, issues, and feature requests.
Raw data
{
"_id": null,
"home_page": "",
"name": "django-request-filters",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": "Samiddha Chakrabarti <samiddha99@protonmail.com>",
"keywords": "Proxy,Relay,TOR,VPN,cybersecurity,djabgo security,django,python,security",
"author": "",
"author_email": "Samiddha Chakrabarti <samiddha99@protonmail.com>",
"download_url": "https://files.pythonhosted.org/packages/88/58/2b1169abd376a19f55cc371a14a51c20adb4ce2cb78c0a22bbc73a96c95b/django_request_filters-0.0.4.tar.gz",
"platform": null,
"description": "# Welcome to django-request-filters\n\n**django-request-filters** is a package developed for django to detect and block the users those are using VPN, Proxy, TOR or Relay.\n\nThis package uses [vpnapi.io](https://vpnapi.io/) API to detect the status of the user's IP address.\n\n### **Installation**\n\n---\n\nUse pip to install from PyPI:\n\n `pip install django-request-filters`\n\n### **Documentation**\n\n##### Settings:\n\n1. Visit [vpnapi.io](https://vpnapi.io/) and create an account and obtain your API Key.\n2. In **settings.py** add the variable `VPNAPI_KEY` and set it's value to your API key obtained in step 1.\n\n ```python\n VPNAPI_KEY = 'Your vpnapi API key'\n ```\n3. Add a **view** that will display to the users when they have blocked (optional setup):\n If you want to show your designed page to blocked users, you can follow this step.\n\n * Define a vew function:\n\n ```python\n # For example we defined a view function in views.py\n from django.shortcuts import render\n from request_filters.decorators.ip_check import exempt_IPCheckMiddleware\n\n @exempt_IPCheckMiddleware\n def blockView(request):\n return render(request, 'block_view.html')\n ```\n\n As we must need to display the view function to blocked users, so the `exempt_IPCheckMiddleware` must be used in that view function.\n * Add the path of the view function in **settings.py**:\n\n ```python\n IP_BLOCK_VIEW = \"app_name.views.blockView\"\n ```\n\n If you do not defined any view function for blocked users, then by default it will show a simple HTML page contains a text \"We can't allow your request, because you are using VPN or Proxy or Tor or Relay.\" with *status code* 418.\n4. Add additional settings in **settings.py** (optional):\n\n * `BLOCK_VPN (optional default: True)`\n If set to `True` all the users want accessing the site with VPN will be disallowed.\n If set to `False`, users can access the site using VPN.\n * `BLOCK_PROXY (optional default: True)`\n If set to `True` all the users want accessing the site with Proxy will be disallowed.\n If set to `False`, users can access the site using Proxy.\n * `BLOCK_TOR (optional default: True)`\n If set to `True` all the users want accessing the site with TOR will be disallowed.\n If set to `False`, users can access the site using TOR.\n * `BLOCK_RELAY (optional default: True)`\n If set to `True` all the users want accessing the site with Relay will be disallowed.\n If set to `False`, users can access the site using Relay.\n\n##### Using Middleware (Use case 1):\n\nUse *MIDDLEWARE* to block the anonymous users (i.e. those are using VPN, Proxy, TOR or Relay) to access all the view function (i.e. all the requests).\n\n1. Add *MIDDLEWARE*:\n In **settings.py** add `'request_filters.middlewares.ip_check.IPCheckMiddleware'` into MIDDLEWARE.\n\n```python\nMIDDLEWARE = [\n\t'django.middleware.security.SecurityMiddleware',\n\t'django.contrib.sessions.middleware.SessionMiddleware',\n\t'django.middleware.common.CommonMiddleware',\n \t'django.middleware.csrf.CsrfViewMiddleware',\n\t.....................\n\t.....................\n\t'request_filters.middlewares.ip_check.IPCheckMiddleware' # We have added this new middleware\n]\n```\n\n2. Exempt from some view functions\n Adding the *middleware* will block the anonymous users, so that those users can visit any views.\n If you want to allow anonymous users to visit only some specific views, you can do that by using the `exempt_IPCheckMiddleware` decorator on the view function.\n\n ```python\n from request_filters.decorators.ip_check import exempt_IPCheckMiddleware\n\n @exempt_IPCheckMiddleware\n def home(request):\n .........\n .........\n ```\n\n Here, for the above code sample, all the users (including anonymous users) can visit the *home view*.\n\nYou can use this method, when you want to block the anonymous users for almost all the view functions.\n\n##### Using only Decorator (Use case 2):\n\nYou can also controll uses' request using decorator and without using Middleware.\n\n* `prevent_anonymous_ip`\n Import this decorator by - `from request_filters.decorators.ip_check import prevent_anonymous_ip`\n If you add this decorator to a view function, this view function will not acessable to anonymous users.\n This decorator has some optional parameter -\n * `block_vpn (optional default: settings.BLOCK_VPN)`\n If set to `True` VPN users can't visit the view function.\n If set to `False`, VPN users can visit the view.\n * `block_proxy (optional default: settings.BLOCK_PROXY)`\n If set to `True` Proxy users can't visit the view function.\n If set to `False`, Proxy users can visit the view.\n * `block_tor (optional default: settings.BLOCK_TOR)`\n If set to `True` TOR users can't visit the view function.\n If set to `False`, TOR users can visit the view.\n * `block_relay (optional default: settings.BLOCK_RELAY)`\n If set to `True` Relay users can't visit the view function.\n If set to `False`, Relay users can visit the view.\n\nYou can use this method, when you want to block the anonymous users only for few view functions.\n\n### **Contributing**\n\n---\n\nTo contribute to django-request-filters [create a fork](https://github.com/Samiddha99/django-request-filters) on GitHub. Clone your fork, make some changes, and submit a pull request.\n\n### **Issues**\n\n---\n\nUse the GitHub [issue tracker](https://github.com/Samiddha99/django-request-filters/issues) for django-request-filters to submit bugs, issues, and feature requests.\n",
"bugtrack_url": null,
"license": "",
"summary": "Block the users those are using VPN, Proxy, TOR or Relay.",
"version": "0.0.4",
"project_urls": {
"Bug Tracker": "https://github.com/Samiddha99/django-request-filters/issues",
"Homepage": "https://pypi.org/project/django-request-filters",
"Source code": "https://github.com/Samiddha99/django-request-filters"
},
"split_keywords": [
"proxy",
"relay",
"tor",
"vpn",
"cybersecurity",
"djabgo security",
"django",
"python",
"security"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a1c48f1eb969ec3b11ee88b510a639fb97e168e9bf924e73b2a802d1eb7b2132",
"md5": "2254c63fd5466b1d9415c1c7e8171d0c",
"sha256": "1d0aaa1f2c7965ee60052f40deab7d7e12e2c6fb4f6d24bedb99b8ac748d7d3a"
},
"downloads": -1,
"filename": "django_request_filters-0.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2254c63fd5466b1d9415c1c7e8171d0c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 6829,
"upload_time": "2023-07-14T02:55:02",
"upload_time_iso_8601": "2023-07-14T02:55:02.324374Z",
"url": "https://files.pythonhosted.org/packages/a1/c4/8f1eb969ec3b11ee88b510a639fb97e168e9bf924e73b2a802d1eb7b2132/django_request_filters-0.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "88582b1169abd376a19f55cc371a14a51c20adb4ce2cb78c0a22bbc73a96c95b",
"md5": "0219d5fee6206c7f4990fadcd70c7220",
"sha256": "af19363d97897cd7b623df309ac26f360ec061e8ea145cf9794e1a92085e5e12"
},
"downloads": -1,
"filename": "django_request_filters-0.0.4.tar.gz",
"has_sig": false,
"md5_digest": "0219d5fee6206c7f4990fadcd70c7220",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 113781,
"upload_time": "2023-07-14T02:55:06",
"upload_time_iso_8601": "2023-07-14T02:55:06.784443Z",
"url": "https://files.pythonhosted.org/packages/88/58/2b1169abd376a19f55cc371a14a51c20adb4ce2cb78c0a22bbc73a96c95b/django_request_filters-0.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-14 02:55:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Samiddha99",
"github_project": "django-request-filters",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "django-request-filters"
}