Fix: The auto-detected ip was wrong as the forwarded address was always 127.0.0.1

This commit is contained in:
Amritanshu 2013-12-03 00:52:24 +05:30
parent 107be1af8c
commit 82f290a206
1 changed files with 6 additions and 2 deletions

View File

@ -16,7 +16,11 @@ def update_view(request):
password = request.registry.settings['webfaction.password']
current_ip = request.GET.get('ip',None)
if current_ip is None:
current_ip = request.remote_addr
if 'X-Forwarded-For' in request.headers:
current_ip = request.headers['X-Forwarded-For']
else:
current_ip = request.remote_addr
domain = request.GET['domain']
db = load(file)
@ -28,7 +32,7 @@ def update_view(request):
db[domain] = current_ip
update(file, db)
log.info('{0} updated to {1} at {3}'.format(domain, current_ip))
log.info('{0} updated to {1}'.format(domain, current_ip))
else:
log.info('{0} not updated'.format(domain))
return {}