Compare commits

..

No commits in common. "master" and "report" have entirely different histories.

3 changed files with 41 additions and 37 deletions

1
.env Normal file
View File

@ -0,0 +1 @@
GITEA_TOKEN=

4
.gitignore vendored
View File

@ -176,6 +176,4 @@ copy
incoming_dumps/
upload-dump-*
counter
# Le .env contient le token et ne DOIT PAS être sous git
.env
counter

View File

@ -12,21 +12,20 @@ bp = Blueprint("routes", __name__)
# --------------------------------------------------------------
DIR = "/opt/installmgr/"
REPOSIT_DIR = "/opt/installmgr/incoming_dumps"
MAX_REPOSIT_SIZE = 2000 * 20 * 1024 # kB (here, max 2000 dumps of 20MB)
MAX_REPOSIT_SIZE = 300 * 20 * 1024 # kB (here, max 300 dumps of 20MB)
ALERT_MAIL_FROM = "root@scodoc.org"
ALERT_MAIL_TO = "viennet"
ALERT_MAIL_TO = "emmanuel.viennet@gmail.com"
LOG_FILENAME = os.path.join(DIR, "upload-dump-errors.log")
UPLOAD_LOG_FILENAME = os.path.join(DIR, "upload-dump-log.json")
DEBUG = False # if false, don't publish error messages
# Les paquets publiés:
#DEBIAN_PACKAGES_EXP = "/srv/packages/pool/main/s/scodoc9/scodoc9_*.deb"
DEBIAN_PACKAGES_EXP = "/srv/bookworm/pool/main/s/scodoc9/scodoc9_*.deb"
DEBIAN_PACKAGES_EXP = "/srv/packages/pool/main/s/scodoc9/scodoc9_*.deb"
RELEASE_LOG_FILE = "/home/viennet/scodoc-releases.log"
GITEA_URL = "https://git.scodoc.org/"
GITEA_URL = "https://scodoc.org/git"
GITEA_REPO = "ScoDoc/ScoDoc"
GITEA_LABEL_ID = None
@ -189,27 +188,29 @@ def report():
)
if response.status_code != 201:
log.write(f"gitea error: status code={response.status_code}\n")
log.write("gitea error\n")
try:
log.write("sending notification to {}\n".format(ALERT_MAIL_TO))
email.send_email(
"[report] Gitea error !",
ALERT_MAIL_FROM,
[ALERT_MAIL_TO],
f"""Error {response.status_code}
while creating the gitea ticket :
{response.text}
Ticket info : {ticket.get("title")}
{ticket_body}
Utilisateur : {user.get("name", "Nom inconnu")} <{user.get("email", "Adresse email inconnue")}>
"""
"Error "
+ response.status_code
+ " while creating the gitea ticket :\n"
+ response.text
+ "\n\nTicket info : "
+ ticket.get("title")
+ "\n"
+ ticket_body
+ "\n- Utilisateur : "
+ user.get("name", "Nom inconnu")
+ " <"
+ user.get("email", "Adresse email inconnue")
+ ">",
)
except Exception as exc:
log.write("exception while sending email (1) !\n")
log.write(f"{type(exc).__name__}, Exception message: {exc}\n")
except:
log.write("exception while sending email !\n")
log.close()
return (
jsonify(
@ -221,20 +222,26 @@ Utilisateur : {user.get("name", "Nom inconnu")} <{user.get("email", "Adresse ema
)
try:
log.write(f"sending notification to {ALERT_MAIL_TO}\n")
log.write("sending notification to {}\n".format(ALERT_MAIL_TO))
email.send_email(
f"""[report] Ticket #{response.json()["id"]} créé: {ticket.get("title")}""",
"[report] Ticket # "
+ response.json()["id"]
+ " créé avec succès ! : "
+ ticket.get("title"),
ALERT_MAIL_FROM,
[ALERT_MAIL_TO],
f"""Nouveau ticket utilisateur :
{meta}
Lien du ticket : {response.json()["html_url"]}
Utilisateur : {user.get("name", "Nom inconnu")} <{user.get("email", "Adresse email inconnue")}>
"""
"Nouveau ticket utilisateur :\n"
+ meta
+ "\n- Lien du ticket : "
+ response.json()["url"]
+ "\n- Utilisateur : "
+ user.get("name", "Nom inconnu")
+ " <"
+ user.get("email", "Adresse email inconnue")
+ ">",
)
except Exception as exc:
log.write("exception while sending email (2) !\n")
log.write(f"{type(exc).__name__}, Exception message: {exc}\n")
except:
log.write("exception while sending email !\n")
log.close()
return (
@ -244,7 +251,7 @@ Utilisateur : {user.get("name", "Nom inconnu")} <{user.get("email", "Adresse ema
+ response.json()["html_url"]
+ "'>"
+ response.json()["html_url"]
+ "</a>. Vous êtes susceptible d'être contacté(e) par email à l'adresse liée à votre compte ScoDoc si des informations supplémentaires sont nécessaires."
+ "</a>. Vous êtes susceptible d'être contacté(e) par email à l'adresse liée à votre compte ScoDoc si des informations supplémentatires sont nécéssaires."
}
),
201,
@ -255,13 +262,12 @@ Utilisateur : {user.get("name", "Nom inconnu")} <{user.get("email", "Adresse ema
def upload_scodoc9():
"""Réception d'un fichier de dump"""
log = open(LOG_FILENAME, "a")
log.write("upload_scodoc9\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(f"{fulltime} request from {remote_addr}\n")
log.write(f"{request.form}")
log.flush()
# Avec seulement alphanum et tiret:
clean_deptname = re.sub(r"[^A-Za-z-]", "", request.form["dept_name"])
@ -281,7 +287,7 @@ def upload_scodoc9():
try:
remote_host = socket.gethostbyaddr(remote_addr)[0]
except:
log.write(f"reverse DNS lookup failed for {remote_addr}")
log.write("reverse DNS lookup failed for {}".format(remote_addr))
remote_host = ""
the_file = request.files["file"]
@ -294,7 +300,6 @@ def upload_scodoc9():
"sent_by": request.form["sent_by"],
"sco_version": request.form.get("sco_version", ""), # release
"sco_subversion": request.form.get("sco_subversion", ""),
"traceback_str": request.form.get("traceback_str", ""),
"dump_filename": fulltime + "_" + clean_deptname + ".gz",
"dump_size": len(data),
"message": request.form.get("message", ""),