moviewyrm/bookwyrm/middleware/ip_middleware.py

17 lines
482 B
Python
Raw Normal View History

2021-09-17 18:43:47 +00:00
""" 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")
2021-09-17 19:59:16 +00:00
if models.IPBlocklist.objects.filter(address=address).exists():
2021-09-17 18:43:47 +00:00
raise Http404()
return self.get_response(request)