forked from ScoDoc/installmgr
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
59b7f8bef2 | |||
b1f907aaaa | |||
297c0a8308 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -177,3 +177,5 @@ copy
|
|||||||
incoming_dumps/
|
incoming_dumps/
|
||||||
upload-dump-*
|
upload-dump-*
|
||||||
counter
|
counter
|
||||||
|
# Le .env contient le token et ne DOIT PAS être sous git
|
||||||
|
.env
|
||||||
|
@ -12,20 +12,21 @@ bp = Blueprint("routes", __name__)
|
|||||||
# --------------------------------------------------------------
|
# --------------------------------------------------------------
|
||||||
DIR = "/opt/installmgr/"
|
DIR = "/opt/installmgr/"
|
||||||
REPOSIT_DIR = "/opt/installmgr/incoming_dumps"
|
REPOSIT_DIR = "/opt/installmgr/incoming_dumps"
|
||||||
MAX_REPOSIT_SIZE = 300 * 20 * 1024 # kB (here, max 300 dumps of 20MB)
|
MAX_REPOSIT_SIZE = 2000 * 20 * 1024 # kB (here, max 2000 dumps of 20MB)
|
||||||
|
|
||||||
ALERT_MAIL_FROM = "root@scodoc.org"
|
ALERT_MAIL_FROM = "root@scodoc.org"
|
||||||
ALERT_MAIL_TO = "emmanuel.viennet@gmail.com"
|
ALERT_MAIL_TO = "viennet"
|
||||||
|
|
||||||
LOG_FILENAME = os.path.join(DIR, "upload-dump-errors.log")
|
LOG_FILENAME = os.path.join(DIR, "upload-dump-errors.log")
|
||||||
UPLOAD_LOG_FILENAME = os.path.join(DIR, "upload-dump-log.json")
|
UPLOAD_LOG_FILENAME = os.path.join(DIR, "upload-dump-log.json")
|
||||||
DEBUG = False # if false, don't publish error messages
|
DEBUG = False # if false, don't publish error messages
|
||||||
|
|
||||||
# Les paquets publiés:
|
# Les paquets publiés:
|
||||||
DEBIAN_PACKAGES_EXP = "/srv/packages/pool/main/s/scodoc9/scodoc9_*.deb"
|
#DEBIAN_PACKAGES_EXP = "/srv/packages/pool/main/s/scodoc9/scodoc9_*.deb"
|
||||||
|
DEBIAN_PACKAGES_EXP = "/srv/bookworm/pool/main/s/scodoc9/scodoc9_*.deb"
|
||||||
RELEASE_LOG_FILE = "/home/viennet/scodoc-releases.log"
|
RELEASE_LOG_FILE = "/home/viennet/scodoc-releases.log"
|
||||||
|
|
||||||
GITEA_URL = "https://scodoc.org/git"
|
GITEA_URL = "https://git.scodoc.org/"
|
||||||
GITEA_REPO = "ScoDoc/ScoDoc"
|
GITEA_REPO = "ScoDoc/ScoDoc"
|
||||||
GITEA_LABEL_ID = None
|
GITEA_LABEL_ID = None
|
||||||
|
|
||||||
@ -188,29 +189,27 @@ def report():
|
|||||||
)
|
)
|
||||||
|
|
||||||
if response.status_code != 201:
|
if response.status_code != 201:
|
||||||
log.write("gitea error\n")
|
log.write(f"gitea error: status code={response.status_code}\n")
|
||||||
try:
|
try:
|
||||||
log.write("sending notification to {}\n".format(ALERT_MAIL_TO))
|
log.write("sending notification to {}\n".format(ALERT_MAIL_TO))
|
||||||
email.send_email(
|
email.send_email(
|
||||||
"[report] Gitea error !",
|
"[report] Gitea error !",
|
||||||
ALERT_MAIL_FROM,
|
ALERT_MAIL_FROM,
|
||||||
[ALERT_MAIL_TO],
|
[ALERT_MAIL_TO],
|
||||||
"Error "
|
f"""Error {response.status_code}
|
||||||
+ response.status_code
|
while creating the gitea ticket :
|
||||||
+ " while creating the gitea ticket :\n"
|
{response.text}
|
||||||
+ response.text
|
|
||||||
+ "\n\nTicket info : "
|
Ticket info : {ticket.get("title")}
|
||||||
+ ticket.get("title")
|
|
||||||
+ "\n"
|
{ticket_body}
|
||||||
+ ticket_body
|
|
||||||
+ "\n- Utilisateur : "
|
Utilisateur : {user.get("name", "Nom inconnu")} <{user.get("email", "Adresse email inconnue")}>
|
||||||
+ user.get("name", "Nom inconnu")
|
"""
|
||||||
+ " <"
|
|
||||||
+ user.get("email", "Adresse email inconnue")
|
|
||||||
+ ">",
|
|
||||||
)
|
)
|
||||||
except:
|
except Exception as exc:
|
||||||
log.write("exception while sending email !\n")
|
log.write("exception while sending email (1) !\n")
|
||||||
|
log.write(f"{type(exc).__name__}, Exception message: {exc}\n")
|
||||||
log.close()
|
log.close()
|
||||||
return (
|
return (
|
||||||
jsonify(
|
jsonify(
|
||||||
@ -222,26 +221,20 @@ def report():
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
log.write("sending notification to {}\n".format(ALERT_MAIL_TO))
|
log.write(f"sending notification to {ALERT_MAIL_TO}\n")
|
||||||
email.send_email(
|
email.send_email(
|
||||||
"[report] Ticket # "
|
f"""[report] Ticket #{response.json()["id"]} créé: {ticket.get("title")}""",
|
||||||
+ response.json()["id"]
|
|
||||||
+ " créé avec succès ! : "
|
|
||||||
+ ticket.get("title"),
|
|
||||||
ALERT_MAIL_FROM,
|
ALERT_MAIL_FROM,
|
||||||
[ALERT_MAIL_TO],
|
[ALERT_MAIL_TO],
|
||||||
"Nouveau ticket utilisateur :\n"
|
f"""Nouveau ticket utilisateur :
|
||||||
+ meta
|
{meta}
|
||||||
+ "\n- Lien du ticket : "
|
Lien du ticket : {response.json()["html_url"]}
|
||||||
+ response.json()["url"]
|
Utilisateur : {user.get("name", "Nom inconnu")} <{user.get("email", "Adresse email inconnue")}>
|
||||||
+ "\n- Utilisateur : "
|
"""
|
||||||
+ user.get("name", "Nom inconnu")
|
|
||||||
+ " <"
|
|
||||||
+ user.get("email", "Adresse email inconnue")
|
|
||||||
+ ">",
|
|
||||||
)
|
)
|
||||||
except:
|
except Exception as exc:
|
||||||
log.write("exception while sending email !\n")
|
log.write("exception while sending email (2) !\n")
|
||||||
|
log.write(f"{type(exc).__name__}, Exception message: {exc}\n")
|
||||||
log.close()
|
log.close()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -251,7 +244,7 @@ def report():
|
|||||||
+ response.json()["html_url"]
|
+ response.json()["html_url"]
|
||||||
+ "'>"
|
+ "'>"
|
||||||
+ 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émentatires sont nécéssaires."
|
+ "</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."
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
201,
|
201,
|
||||||
@ -262,12 +255,13 @@ def report():
|
|||||||
def upload_scodoc9():
|
def upload_scodoc9():
|
||||||
"""Réception d'un fichier de dump"""
|
"""Réception d'un fichier de dump"""
|
||||||
log = open(LOG_FILENAME, "a")
|
log = open(LOG_FILENAME, "a")
|
||||||
log.write("haallo\n")
|
log.write("upload_scodoc9\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(f"{fulltime} request from {remote_addr}\n")
|
||||||
|
log.write(f"{request.form}")
|
||||||
log.flush()
|
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"])
|
||||||
@ -287,7 +281,7 @@ def upload_scodoc9():
|
|||||||
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(f"reverse DNS lookup failed for {remote_addr}")
|
||||||
remote_host = ""
|
remote_host = ""
|
||||||
|
|
||||||
the_file = request.files["file"]
|
the_file = request.files["file"]
|
||||||
@ -300,6 +294,7 @@ def upload_scodoc9():
|
|||||||
"sent_by": request.form["sent_by"],
|
"sent_by": request.form["sent_by"],
|
||||||
"sco_version": request.form.get("sco_version", ""), # release
|
"sco_version": request.form.get("sco_version", ""), # release
|
||||||
"sco_subversion": request.form.get("sco_subversion", ""),
|
"sco_subversion": request.form.get("sco_subversion", ""),
|
||||||
|
"traceback_str": request.form.get("traceback_str", ""),
|
||||||
"dump_filename": fulltime + "_" + clean_deptname + ".gz",
|
"dump_filename": fulltime + "_" + clean_deptname + ".gz",
|
||||||
"dump_size": len(data),
|
"dump_size": len(data),
|
||||||
"message": request.form.get("message", ""),
|
"message": request.form.get("message", ""),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user