retreive real client IP

This commit is contained in:
Emmanuel Viennet 2021-09-18 22:36:55 +02:00
parent af888970f2
commit f102cc22f1
3 changed files with 8 additions and 4 deletions

View File

@ -1,6 +1,6 @@
# InstallMgr # InstallMgr
Mini app Flask remplaçant les CGI Sciript de `scodoc.iutv`. Mini-app Flask remplaçant les CGI scripts de `scodoc.iutv`.
## API ## API

View File

@ -31,11 +31,13 @@ def upload_dump():
Réception d'un fichier de dump uploadé Réception d'un fichier de dump uploadé
""" """
log = open(LOG_FILENAME, "a") log = open(LOG_FILENAME, "a")
log.write("hello\n")
now = datetime.datetime.now() now = datetime.datetime.now()
fulltime = now.isoformat() fulltime = now.isoformat()
# client addr: # client addr:
remote_addr = request.environ.get("HTTP_X_Real_IP", request.remote_addr) remote_addr = request.environ.get("HTTP_X_REAL_IP", request.remote_addr)
log.write("{} request from {}\n".format(fulltime, remote_addr))
log.write("{fulltime} request from {remote_addr}\n")
# Avec seulement alphanum et tiret: # Avec seulement alphanum et tiret:
clean_deptname = re.sub(r"[^A-Za-z-]", "", request.form["dept_name"]) clean_deptname = re.sub(r"[^A-Za-z-]", "", request.form["dept_name"])
the_file = request.files["file"] the_file = request.files["file"]
@ -105,6 +107,7 @@ def upload_dump():
) )
except: except:
log.write("exception while sending email !\n") log.write("exception while sending email !\n")
log.close()
return ("", 204) # ok empty response return ("", 204) # ok empty response
@ -161,3 +164,4 @@ def version():
) )
) )
f.close() f.close()
return serial

View File

@ -19,7 +19,7 @@ User=scodoc
Group=scodoc Group=scodoc
WorkingDirectory=/opt/installmgr WorkingDirectory=/opt/installmgr
Environment=FLASK_RUN_PORT=5010 Environment=FLASK_RUN_PORT=5010
ExecStart=/opt/installmgr/venv/bin/gunicorn -b localhost:8010 -w 1 installmgr:app ExecStart=/opt/installmgr/venv/bin/gunicorn -b localhost:8010 -w 2 installmgr:app
Restart=always Restart=always
[Install] [Install]