"""Tools > Share accounts: the Samba passwords the imaging clients use (pxe-upload, blancco, clonezilla). Logic in services/share_accounts.py.""" from flask import Blueprint, flash, redirect, render_template, request, url_for from services import share_accounts as sa from services.audit import audit bp = Blueprint("share_accounts", __name__, url_prefix="/tools/share-accounts") USED_BY = { "pxe-upload": "WinPE and Shop Floor setup on every imaging PC; image and app uploads", "blancco": "Blancco saving erasure reports to the blancco-reports share", "clonezilla": "Clonezilla back up and restore (in the PXE boot menu)", } @bp.route("/") def page(): return render_template("share_accounts.html", accounts=sa.public(), used_by=USED_BY, busy=sa.busy(), rule=sa.PASSWORD_RULE) @bp.route("/", methods=["POST"]) def save(account): pw = request.form.get("password", "") if pw != request.form.get("confirm", ""): flash(f"{account}: the two passwords differ; nothing changed.", "danger") return redirect(url_for("share_accounts.page")) force = request.form.get("force") == "1" try: done = sa.set_password(account, pw, force=force) except sa.ApplyFailed as e: audit("SHARE_PASSWORD_FAILED", f"{account}: {e}") flash(f"{account} password stored, but applying it failed: {e}. " "Fix the cause and save it again.", "danger") return redirect(url_for("share_accounts.page")) except (ValueError, RuntimeError, OSError) as e: flash(f"{account} password not changed: {e}", "danger") return redirect(url_for("share_accounts.page")) audit("SHARE_PASSWORD", f"{account}{' (while PCs were imaging)' if force else ''}: " + "; ".join(done)) flash(f"{account} password changed. " + "; ".join(done) + ".", "success") return redirect(url_for("share_accounts.page"))