Skip to content

Commit 3bf6d37

Browse files
committed
IPv6 added
1 parent 0a70f50 commit 3bf6d37

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/feedback/views/public.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import uuid, logging
1515
from django.utils.translation import gettext_lazy as _
1616
from django.utils import timezone
17+
import ipaddress
1718

1819
logger = logging.getLogger(__name__)
1920

@@ -28,8 +29,21 @@ def index(request):
2829
if request.user.is_superuser or settings.DEBUG == True:
2930
authfilter = {}
3031
else:
31-
if not request.META['REMOTE_ADDR'].startswith('130.83.'):
32+
remote_addr = request.META.get('REMOTE_ADDR')
33+
34+
allowed_networks = settings.TU_IP_RANGE
35+
36+
is_allowed = False
37+
if remote_addr:
38+
try:
39+
client_ip = ipaddress.ip_address(remote_addr)
40+
is_allowed = any(client_ip in network for network in allowed_networks)
41+
except ValueError:
42+
is_allowed = False
43+
44+
if not is_allowed:
3245
return render(request, 'public/unauth.html')
46+
3347
authfilter = {'sichtbarkeit': 'ALL'}
3448

3549
# Semesterliste laden

src/settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# determine if this is a production system
55
import os
66
import sys
7+
import ipaddress
78
from django.utils.translation import gettext_lazy as _
89

910
DEBUG = True
@@ -248,6 +249,12 @@
248249
THRESH_SHOW = 5
249250
THRESH_VALID = 20
250251

252+
TU_IP_RANGE = [
253+
ipaddress.ip_network('130.83.0.0/16'),
254+
ipaddress.ip_network('2001:41b8:800::/40'),
255+
]
256+
257+
251258
DEFAULT_FROM_EMAIL = "Feedback-Team <feedback@fachschaft.informatik.tu-darmstadt.de>"
252259
SERVER_EMAIL = DEFAULT_FROM_EMAIL
253260

0 commit comments

Comments
 (0)