|
@@ -43,7 +43,7 @@ logging.basicConfig(
|
|
|
|
|
|
|
|
# --- Extensions --------------------------------------------------------------
|
|
# --- Extensions --------------------------------------------------------------
|
|
|
|
|
|
|
|
-from db import db, Job, Run, Destination
|
|
|
|
|
|
|
+from db import db, Job, Run, Destination, Setting
|
|
|
|
|
|
|
|
db.init_app(app)
|
|
db.init_app(app)
|
|
|
|
|
|
|
@@ -390,6 +390,67 @@ def _get_pub_key(dest):
|
|
|
from jobs.transfer import get_public_key
|
|
from jobs.transfer import get_public_key
|
|
|
return get_public_key(dest.key_name, app.config["DATA_DIR"])
|
|
return get_public_key(dest.key_name, app.config["DATA_DIR"])
|
|
|
|
|
|
|
|
|
|
+# --- Paramètres --------------------------------------------------------------
|
|
|
|
|
+
|
|
|
|
|
+_SETTING_KEYS = [
|
|
|
|
|
+ "smtp_host", "smtp_port", "smtp_user", "smtp_password",
|
|
|
|
|
+ "smtp_from", "smtp_to", "smtp_tls", "smtp_ssl",
|
|
|
|
|
+ "notify_on_success", "notify_on_error",
|
|
|
|
|
+]
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _get_setting(key, default=""):
|
|
|
|
|
+ s = Setting.query.filter_by(key=key).first()
|
|
|
|
|
+ return s.value if s else default
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+@app.route("/settings", methods=["GET", "POST"])
|
|
|
|
|
+def settings():
|
|
|
|
|
+ if request.method == "POST":
|
|
|
|
|
+ action = request.form.get("action")
|
|
|
|
|
+
|
|
|
|
|
+ if action == "test_smtp":
|
|
|
|
|
+ from notifications import send_test_email
|
|
|
|
|
+ try:
|
|
|
|
|
+ send_test_email(
|
|
|
|
|
+ host=request.form.get("smtp_host", "").strip(),
|
|
|
|
|
+ port=int(request.form.get("smtp_port", 587) or 587),
|
|
|
|
|
+ user=request.form.get("smtp_user", "").strip(),
|
|
|
|
|
+ password=request.form.get("smtp_password", ""),
|
|
|
|
|
+ from_addr=request.form.get("smtp_from", "").strip(),
|
|
|
|
|
+ to_addr=request.form.get("smtp_to", "").strip(),
|
|
|
|
|
+ use_ssl=request.form.get("smtp_ssl") == "1",
|
|
|
|
|
+ use_tls=request.form.get("smtp_tls") == "1",
|
|
|
|
|
+ )
|
|
|
|
|
+ flash("Email de test envoyé avec succès.", "success")
|
|
|
|
|
+ except Exception as exc:
|
|
|
|
|
+ flash(f"Échec du test SMTP : {exc}", "error")
|
|
|
|
|
+ else:
|
|
|
|
|
+ for key in _SETTING_KEYS:
|
|
|
|
|
+ if key in ("smtp_tls", "smtp_ssl", "notify_on_success", "notify_on_error"):
|
|
|
|
|
+ value = "1" if request.form.get(key) == "1" else "0"
|
|
|
|
|
+ else:
|
|
|
|
|
+ value = request.form.get(key, "").strip()
|
|
|
|
|
+ s = Setting.query.filter_by(key=key).first()
|
|
|
|
|
+ if s is None:
|
|
|
|
|
+ s = Setting(key=key, value=value)
|
|
|
|
|
+ db.session.add(s)
|
|
|
|
|
+ else:
|
|
|
|
|
+ s.value = value
|
|
|
|
|
+ db.session.commit()
|
|
|
|
|
+ flash("Paramètres enregistrés.", "success")
|
|
|
|
|
+
|
|
|
|
|
+ return redirect(url_for("settings"))
|
|
|
|
|
+
|
|
|
|
|
+ cfg = {k: _get_setting(k) for k in _SETTING_KEYS}
|
|
|
|
|
+ # valeurs par défaut pour l'affichage
|
|
|
|
|
+ cfg.setdefault("smtp_port", "587")
|
|
|
|
|
+ cfg["smtp_tls"] = cfg.get("smtp_tls") or "1"
|
|
|
|
|
+ cfg["smtp_ssl"] = cfg.get("smtp_ssl") or "0"
|
|
|
|
|
+ cfg["notify_on_error"] = cfg.get("notify_on_error") or "1"
|
|
|
|
|
+ return render_template("settings.html", cfg=cfg)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
# --- API v1 ------------------------------------------------------------------
|
|
# --- API v1 ------------------------------------------------------------------
|
|
|
|
|
|
|
|
@app.route("/api/v1/health")
|
|
@app.route("/api/v1/health")
|