This commit is contained in:
ScoDoc service 2021-09-19 16:01:18 +02:00
parent 7d399e63dc
commit de80f70813
2 changed files with 36 additions and 16 deletions

View File

@ -1,5 +1,7 @@
import logging import logging
import os import os
import logging
from logging.handlers import WatchedFileHandler
from flask import Flask from flask import Flask
from flask import g, current_app from flask import g, current_app
@ -14,4 +16,12 @@ def create_app():
app = Flask(__name__) app = Flask(__name__)
mail.init_app(app) mail.init_app(app)
app.register_blueprint(bp) app.register_blueprint(bp)
file_handler = WatchedFileHandler(
"/opt/installmgr/server.log", encoding="utf-8"
)
# file_handler.setFormatter(scodoc_log_formatter)
file_handler.setLevel(logging.DEBUG)
app.logger.addHandler(file_handler)
return app return app

View File

@ -24,39 +24,37 @@ def last_stable_version():
# LAST_RELEASE_TAG=$(curl "$GITEA_RELEASE_URL" | jq ".[].tag_name" | tr -d -c "0-9.\n" | sort --version-sort | tail -1) # LAST_RELEASE_TAG=$(curl "$GITEA_RELEASE_URL" | jq ".[].tag_name" | tr -d -c "0-9.\n" | sort --version-sort | tail -1)
return "9.0.30" return "9.0.30"
@bp.route("/scodoc-installmgr/upload-dump", methods=["POST"]) @bp.route("/scodoc-installmgr/upload-dump", methods=["POST"])
def upload_dump(): def upload_scodoc9():
""" """Réception d'un fichier de dump"""
Réception d'un fichier de dump uploadé
"""
log = open(LOG_FILENAME, "a") log = open(LOG_FILENAME, "a")
log.write("hello\n") log.write("haallo\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(f"{fulltime} request from {remote_addr}\n")
log.write("{fulltime} request from {remote_addr}\n") log.flush()
# 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"] if not clean_deptname:
filename = the_file.filename abort(400, "missing argument: dept_name")
data = the_file.read()
try: try:
remote_host = socket.gethostbyaddr(remote_addr)[0] remote_host = socket.gethostbyaddr(remote_addr)[0]
except: except:
log.write("reverse DNS lookup failed for {}".format(remote_addr)) log.write("reverse DNS lookup failed for {}".format(remote_addr))
remote_host = "" remote_host = ""
the_file = request.files["file"]
filename = the_file.filename
data = the_file.read()
D = { D = {
"dept_name": request.form["dept_name"], "dept_name": request.form["dept_name"],
"serial": request.form["serial"], "serial": request.form["serial"],
"sco_user": request.form["sco_user"], "sco_user": request.form["sco_user"],
"sent_by": request.form["sent_by"], "sent_by": request.form["sent_by"],
"sco_version": request.form["sco_version"], "sco_version": request.form.get("sco_version", ""), # release
"sco_subversion": request.form["sco_subversion"], "sco_subversion": request.form.get("sco_subversion", ""),
"dump_filename": fulltime + "_" + clean_deptname + ".gz", "dump_filename": fulltime + "_" + clean_deptname + ".gz",
"dump_size": len(data), "dump_size": len(data),
"remote_addr": remote_addr, "remote_addr": remote_addr,
@ -67,8 +65,7 @@ def upload_dump():
json_descr = json.dumps(D, sort_keys=True, indent=4) json_descr = json.dumps(D, sort_keys=True, indent=4)
# --- Check disk space # --- Check disk space
cur_size = int(subprocess.check_output(["du", "-skx", REPOSIT_DIR]).split("\t")[0]) cur_size = int(subprocess.check_output(["du", "-skx", REPOSIT_DIR]).decode("utf-8").split("\t")[0])
if (cur_size + len(data) / 1024) > MAX_REPOSIT_SIZE: if (cur_size + len(data) / 1024) > MAX_REPOSIT_SIZE:
# out of space ! # out of space !
log.write( log.write(
@ -84,6 +81,7 @@ def upload_dump():
) )
except: except:
log.write("exception while sending email !\n") log.write("exception while sending email !\n")
log.close()
abort(507, "Insufficient Storage") abort(507, "Insufficient Storage")
else: else:
log.write("writing dump to {}\n".format(D["dump_filename"])) log.write("writing dump to {}\n".format(D["dump_filename"]))
@ -107,10 +105,22 @@ def upload_dump():
) )
except: except:
log.write("exception while sending email !\n") log.write("exception while sending email !\n")
log.close() log.close()
return ("", 204) # ok empty response return ("", 204) # ok empty response
@bp.route("/scodoc-installmgr/scodoc9")
def scodoc9():
"""
Réception d'un fichier de dump uploadé
"""
log = open(LOG_FILENAME, "a")
log.write("hello\n")
# Lock for counter # Lock for counter
class Lock: class Lock:
def acquire(self): def acquire(self):