File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414import uuid , logging
1515from django .utils .translation import gettext_lazy as _
1616from django .utils import timezone
17+ import ipaddress
1718
1819logger = 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
Original file line number Diff line number Diff line change 44# determine if this is a production system
55import os
66import sys
7+ import ipaddress
78from django .utils .translation import gettext_lazy as _
89
910DEBUG = True
248249THRESH_SHOW = 5
249250THRESH_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+
251258DEFAULT_FROM_EMAIL = "Feedback-Team <feedback@fachschaft.informatik.tu-darmstadt.de>"
252259SERVER_EMAIL = DEFAULT_FROM_EMAIL
253260
You can’t perform that action at this time.
0 commit comments