Add utility to get IP address

This commit is contained in:
Raphael Michel
2019-07-09 16:13:12 +02:00
parent 59daeba477
commit 5a03033255
3 changed files with 17 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
from django.conf import settings
from django.http import StreamingHttpResponse
@@ -9,3 +10,12 @@ class ChunkBasedFileResponse(StreamingHttpResponse):
streaming_content = streaming_content.chunks(self.block_size)
super().__init__(streaming_content, *args, **kwargs)
self['Content-Length'] = filelike.size
def get_client_ip(request):
ip = request.META.get('REMOTE_ADDR')
if settings.TRUST_X_FORWARDED_FOR:
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[0]
return ip

View File

@@ -130,6 +130,8 @@ if SITE_URL.endswith('/'):
CSRF_TRUSTED_ORIGINS = [urlparse(SITE_URL).hostname]
TRUST_X_FORWARDED_FOR = config.get('pretix', 'trust_x_forwarded_for', fallback=False)
PRETIX_PLUGINS_DEFAULT = config.get('pretix', 'plugins_default',
fallback='pretix.plugins.sendmail,pretix.plugins.statistics,pretix.plugins.checkinlists')
PRETIX_PLUGINS_EXCLUDE = config.get('pretix', 'plugins_exclude', fallback='').split(',')