forked from mirrors/bookwyrm
Adds ip block middleware
This commit is contained in:
parent
252fff8bfe
commit
16854a52bc
3 changed files with 19 additions and 0 deletions
|
@ -1 +1,3 @@
|
||||||
|
""" look at all this nice middleware! """
|
||||||
from timezone_middleware import TimezoneMiddleware
|
from timezone_middleware import TimezoneMiddleware
|
||||||
|
from ip_middleware import IPBlocklistMiddleware
|
||||||
|
|
16
bookwyrm/middleware/ip_middleware.py
Normal file
16
bookwyrm/middleware/ip_middleware.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
""" Block IP addresses """
|
||||||
|
from django.http import Http404
|
||||||
|
from bookwyrm import models
|
||||||
|
|
||||||
|
|
||||||
|
class IPBlocklistMiddleware:
|
||||||
|
"""check incoming traffic against an IP block-list"""
|
||||||
|
|
||||||
|
def __init__(self, get_response):
|
||||||
|
self.get_response = get_response
|
||||||
|
|
||||||
|
def __call__(self, request):
|
||||||
|
address = request.META.get("REMOTE_ADDR")
|
||||||
|
if models.IPBlockList.objects.filter(address=address).exists():
|
||||||
|
raise Http404()
|
||||||
|
return self.get_response(request)
|
|
@ -78,6 +78,7 @@ MIDDLEWARE = [
|
||||||
"django.middleware.csrf.CsrfViewMiddleware",
|
"django.middleware.csrf.CsrfViewMiddleware",
|
||||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||||
"bookwyrm.middleware.TimezoneMiddleware",
|
"bookwyrm.middleware.TimezoneMiddleware",
|
||||||
|
"bookwyrm.middleware.IPBlocklistMiddleware",
|
||||||
"django.contrib.messages.middleware.MessageMiddleware",
|
"django.contrib.messages.middleware.MessageMiddleware",
|
||||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue