Commit 30b1f341 authored by Adrien Luxey's avatar Adrien Luxey
Browse files

robust IP detection

parent e05b61b6
......@@ -31,6 +31,12 @@ def guid_exists(guid):
return os.path.exists(os.path.join(
current_app.config['OUTPUT_DIR'], f"{guid}.json"))
def get_remote_ip():
if request.headers.getlist("X-Forwarded-For"):
return request.headers.getlist("X-Forwarded-For")[0]
else:
return request.remote_addr
def save_results():
form = request.form.copy()
fn = os.path.join(
......@@ -39,6 +45,6 @@ def save_results():
with open(fn, 'w') as f:
del form['guid']
form['date'] = datetime.utcnow().isoformat()
form['ip'] = request.remote_addr
form['ip'] = get_remote_ip()
form['user_agent'] = request.user_agent.string
json.dump(form, f)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment