Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/feedback/views/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import uuid, logging
from django.utils.translation import gettext_lazy as _
from django.utils import timezone
import ipaddress

logger = logging.getLogger(__name__)

Expand All @@ -28,8 +29,21 @@ def index(request):
if request.user.is_superuser or settings.DEBUG == True:
authfilter = {}
else:
if not request.META['REMOTE_ADDR'].startswith('130.83.'):
remote_addr = request.META.get('REMOTE_ADDR')

allowed_networks = settings.TU_IP_RANGE

is_allowed = False
if remote_addr:
try:
client_ip = ipaddress.ip_address(remote_addr)
is_allowed = any(client_ip in network for network in allowed_networks)
except ValueError:
is_allowed = False

if not is_allowed:
return render(request, 'public/unauth.html')

authfilter = {'sichtbarkeit': 'ALL'}

# Semesterliste laden
Expand Down
7 changes: 7 additions & 0 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# determine if this is a production system
import os
import sys
import ipaddress
from django.utils.translation import gettext_lazy as _

DEBUG = True
Expand Down Expand Up @@ -248,6 +249,12 @@
THRESH_SHOW = 5
THRESH_VALID = 20

TU_IP_RANGE = [
ipaddress.ip_network('130.83.0.0/16'),
ipaddress.ip_network('2001:41b8:800::/40'),
]


DEFAULT_FROM_EMAIL = "Feedback-Team <feedback@fachschaft.informatik.tu-darmstadt.de>"
SERVER_EMAIL = DEFAULT_FROM_EMAIL

Expand Down
Loading