use HTTP_X_FORWARDED_FOR as ip of set

This commit is contained in:
j 2013-08-30 10:38:45 +02:00
parent 8ceae868b1
commit 7c6757f417

View file

@ -106,7 +106,10 @@ class SessionData(models.Model):
data, created = cls.objects.get_or_create(session_key=session_key)
if request.user.is_authenticated():
data.user = request.user
data.ip = request.META['REMOTE_ADDR']
if 'HTTP_X_FORWARDED_FOR' in request.META:
data.ip = request.META['HTTP_X_FORWARDED_FOR']
else:
data.ip = request.META['REMOTE_ADDR']
if data.ip.startswith('::ffff:'):
data.ip = data.ip[len('::ffff:'):]
data.useragent = request.META['HTTP_USER_AGENT']