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 os
import logging
from logging.handlers import WatchedFileHandler
from flask import Flask
from flask import g, current_app
@ -14,4 +16,12 @@ def create_app():
app = Flask(__name__)
mail.init_app(app)
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

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)
return "9.0.30"
@bp.route("/scodoc-installmgr/upload-dump", methods=["POST"])
def upload_dump():
"""
Réception d'un fichier de dump uploadé
"""
def upload_scodoc9():
"""Réception d'un fichier de dump"""
log = open(LOG_FILENAME, "a")
log.write("hello\n")
log.write("haallo\n")
now = datetime.datetime.now()
fulltime = now.isoformat()
# client addr:
remote_addr = request.environ.get("HTTP_X_REAL_IP", request.remote_addr)
log.write("{fulltime} request from {remote_addr}\n")
log.write(f"{fulltime} request from {remote_addr}\n")
log.flush()
# Avec seulement alphanum et tiret:
clean_deptname = re.sub(r"[^A-Za-z-]", "", request.form["dept_name"])
the_file = request.files["file"]
filename = the_file.filename
data = the_file.read()
if not clean_deptname:
abort(400, "missing argument: dept_name")
try:
remote_host = socket.gethostbyaddr(remote_addr)[0]
except:
log.write("reverse DNS lookup failed for {}".format(remote_addr))
remote_host = ""
the_file = request.files["file"]
filename = the_file.filename
data = the_file.read()
D = {
"dept_name": request.form["dept_name"],
"serial": request.form["serial"],
"sco_user": request.form["sco_user"],
"sent_by": request.form["sent_by"],
"sco_version": request.form["sco_version"],
"sco_subversion": request.form["sco_subversion"],
"sco_version": request.form.get("sco_version", ""), # release
"sco_subversion": request.form.get("sco_subversion", ""),
"dump_filename": fulltime + "_" + clean_deptname + ".gz",
"dump_size": len(data),
"remote_addr": remote_addr,
@ -67,8 +65,7 @@ def upload_dump():
json_descr = json.dumps(D, sort_keys=True, indent=4)
# --- 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:
# out of space !
log.write(
@ -84,6 +81,7 @@ def upload_dump():
)
except:
log.write("exception while sending email !\n")
log.close()
abort(507, "Insufficient Storage")
else:
log.write("writing dump to {}\n".format(D["dump_filename"]))
@ -107,10 +105,22 @@ def upload_dump():
)
except:
log.write("exception while sending email !\n")
log.close()
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
class Lock:
def acquire(self):