Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
617fe10d8d | ||
|
|
7fd5ba8b54 | ||
|
|
a60cc07ab8 | ||
|
|
0c9e346b66 | ||
|
|
cf5cf8622b | ||
|
|
4c1d6387c0 | ||
|
|
91711a51fc | ||
|
|
1c90251b0f | ||
|
|
4c9ed20da4 | ||
|
|
b266bac055 | ||
|
|
051d3bc649 | ||
|
|
4041156a19 | ||
|
|
ec5cbb2e17 | ||
|
|
f551ce0ee6 | ||
|
|
0c47e1d645 | ||
|
|
db3558dcbd | ||
|
|
9d819aaa3a | ||
|
|
48ce56fe7d | ||
|
|
294d47684b | ||
|
|
e589b4aadb | ||
|
|
f6b0bbaad1 | ||
|
|
c3c6eae72d | ||
|
|
a1987aeb93 | ||
|
|
1d67c36ed2 | ||
|
|
e68f22fd88 | ||
|
|
2d234571d2 | ||
|
|
fafda84bc7 | ||
|
|
cdc3b2cd6e | ||
|
|
35247c895b | ||
|
|
e5ae10814f | ||
|
|
37a200e983 | ||
|
|
de9c0d4fbd | ||
|
|
724052ae28 | ||
|
|
e16236fa65 | ||
|
|
c52b3626b2 | ||
|
|
1ac5dc1637 | ||
|
|
f2d5324449 | ||
|
|
342abb0206 | ||
|
|
8dd8df9e9f | ||
|
|
0de90ab6d4 | ||
|
|
e60a93120c | ||
|
|
e7ad00a5e5 | ||
|
|
e70c6e27c1 |
No files matched your search
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "tesm-license"
|
||||
version = "2.2.0"
|
||||
version = "2.8.8"
|
||||
description = "TESM-Lizenzserver -- Kunden, Tickets, Lizenzen, Aktivierung"
|
||||
requires-python = ">=3.11"
|
||||
dependencies = [
|
||||
|
||||
@@ -180,7 +180,7 @@ def _reencrypt_secrets(conn: Any, keystore: Any) -> int:
|
||||
|
||||
|
||||
def _status_pills(user: Any) -> list[dict[str, str]]:
|
||||
if not user.is_authenticated or not user.has_any(("licenses.view",)):
|
||||
if not user.is_authenticated or not user.has_any(("licenses.read",)):
|
||||
return []
|
||||
from tesm_core.extension import db
|
||||
|
||||
@@ -204,7 +204,7 @@ def _status_pills(user: Any) -> list[dict[str, str]]:
|
||||
def _startup_tasks(app: Flask) -> None:
|
||||
extension = core(app)
|
||||
if not extension.config.web_process:
|
||||
logger.info("Startaufgaben uebersprungen -- kein Webprozess.")
|
||||
logger.info("Startaufgaben übersprungen – kein Webprozess.")
|
||||
return
|
||||
|
||||
from .services import activation
|
||||
|
||||
@@ -59,7 +59,7 @@ def _handle(action: str):
|
||||
)
|
||||
|
||||
if request.content_length and request.content_length > MAX_BODY_BYTES:
|
||||
return jsonify({"error": "too_large", "message": "Anfrage zu gross."}), 413
|
||||
return jsonify({"error": "too_large", "message": "Anfrage zu groß."}), 413
|
||||
|
||||
payload = request.get_json(silent=True)
|
||||
if not isinstance(payload, dict):
|
||||
|
||||
@@ -13,7 +13,7 @@ from tesm_core.extension import core, db, transaction
|
||||
from ..services import transfer
|
||||
from .common import log_event
|
||||
|
||||
bp = Blueprint("backup", __name__, url_prefix="/sicherung")
|
||||
bp = Blueprint("backup", __name__, url_prefix="/administration/backup")
|
||||
|
||||
MAX_IMPORT_BYTES = 64 * 1024 * 1024
|
||||
PREVIEW_SESSION_KEY = "_import_token"
|
||||
@@ -24,14 +24,14 @@ def _allowed_categories() -> list[transfer.Category]:
|
||||
for category in transfer.CATEGORIES:
|
||||
if category.admin_only and not current_user.is_admin:
|
||||
continue
|
||||
if category.sensitive and not current_user.has("backup.secrets"):
|
||||
if category.sensitive and not current_user.has("backup_export.secrets"):
|
||||
continue
|
||||
allowed.append(category)
|
||||
return allowed
|
||||
|
||||
|
||||
@bp.get("/")
|
||||
@permission_required("backup.view", "backup.export", "backup.execute", mode="any")
|
||||
@permission_required("backup_export.read", "backup_import.read", mode="any")
|
||||
def overview():
|
||||
conn = db()
|
||||
preview = None
|
||||
@@ -50,25 +50,25 @@ def overview():
|
||||
preview=preview,
|
||||
min_passphrase=transfer.MIN_PASSPHRASE_LENGTH,
|
||||
preview_ttl=transfer.PREVIEW_TTL_MINUTES,
|
||||
can_secrets=current_user.has("backup.secrets"),
|
||||
can_secrets=current_user.has("backup_export.secrets"),
|
||||
signing_key_path=str(core().registry["master_key_path"]),
|
||||
)
|
||||
|
||||
|
||||
@bp.post("/export")
|
||||
@permission_required("backup.export")
|
||||
@reauth_required
|
||||
@permission_required("backup_export.export")
|
||||
# Die frische Bestaetigung verlangt das Recht selbst (SENSITIVE_ACTIONS).
|
||||
def export():
|
||||
conn = db()
|
||||
allowed = {category.key for category in _allowed_categories()}
|
||||
chosen = [key for key in request.form.getlist("categories") if key in allowed]
|
||||
if not chosen:
|
||||
flash("Es wurde keine Kategorie ausgewaehlt.", "warning")
|
||||
flash("Es wurde keine Kategorie ausgewählt.", "warning")
|
||||
return redirect(url_for("backup.overview"))
|
||||
|
||||
passphrase = request.form.get("passphrase") or ""
|
||||
if passphrase != (request.form.get("passphrase_repeat") or ""):
|
||||
flash("Die beiden Passphrasen stimmen nicht ueberein.", "danger")
|
||||
flash("Die beiden Passphrasen stimmen nicht überein.", "danger")
|
||||
return redirect(url_for("backup.overview"))
|
||||
|
||||
try:
|
||||
@@ -94,18 +94,18 @@ def export():
|
||||
)
|
||||
|
||||
|
||||
@bp.post("/import/vorschau")
|
||||
@permission_required("backup.execute")
|
||||
@bp.post("/import/preview")
|
||||
@permission_required("backup_import.execute")
|
||||
@reauth_required
|
||||
def import_preview():
|
||||
conn = db()
|
||||
upload = request.files.get("backup_file")
|
||||
if upload is None or not upload.filename:
|
||||
flash("Keine Datei ausgewaehlt.", "danger")
|
||||
flash("Keine Datei ausgewählt.", "danger")
|
||||
return redirect(url_for("backup.overview"))
|
||||
raw = upload.stream.read(MAX_IMPORT_BYTES + 1)
|
||||
if len(raw) > MAX_IMPORT_BYTES:
|
||||
flash("Die Datei ist zu gross.", "danger")
|
||||
flash("Die Datei ist zu groß.", "danger")
|
||||
return redirect(url_for("backup.overview"))
|
||||
|
||||
try:
|
||||
@@ -124,28 +124,28 @@ def import_preview():
|
||||
scope="sicherung",
|
||||
)
|
||||
flash(
|
||||
f"Datei geoeffnet. Sie haben {transfer.PREVIEW_TTL_MINUTES} Minuten Zeit, die "
|
||||
"Uebernahme zu bestaetigen.",
|
||||
f"Datei geöffnet. Sie haben {transfer.PREVIEW_TTL_MINUTES} Minuten Zeit, die "
|
||||
"Übernahme zu bestätigen.",
|
||||
"success",
|
||||
)
|
||||
return redirect(url_for("backup.overview"))
|
||||
|
||||
|
||||
@bp.post("/import/uebernehmen")
|
||||
@permission_required("backup.execute")
|
||||
@bp.post("/import/apply")
|
||||
@permission_required("backup_import.execute")
|
||||
@reauth_required
|
||||
def import_apply():
|
||||
extension = core()
|
||||
conn = db()
|
||||
token = session.get(PREVIEW_SESSION_KEY, "")
|
||||
if not token:
|
||||
flash("Es liegt keine geoeffnete Sicherung vor.", "danger")
|
||||
flash("Es liegt keine geöffnete Sicherung vor.", "danger")
|
||||
return redirect(url_for("backup.overview"))
|
||||
|
||||
allowed = {category.key for category in _allowed_categories()}
|
||||
chosen = [key for key in request.form.getlist("categories") if key in allowed]
|
||||
if not chosen:
|
||||
flash("Es wurde keine Kategorie ausgewaehlt.", "warning")
|
||||
flash("Es wurde keine Kategorie ausgewählt.", "warning")
|
||||
return redirect(url_for("backup.overview"))
|
||||
|
||||
try:
|
||||
@@ -172,7 +172,7 @@ def import_apply():
|
||||
action="backup.imported",
|
||||
detail="; ".join(
|
||||
f"{key}: {counts['created']} neu, {counts['updated']} aktualisiert, "
|
||||
f"{counts['skipped']} uebersprungen"
|
||||
f"{counts['skipped']} übersprungen"
|
||||
for key, counts in report.items()
|
||||
),
|
||||
ip=client_ip(),
|
||||
@@ -182,16 +182,16 @@ def import_apply():
|
||||
lines = [
|
||||
f"{transfer.CATEGORY_BY_KEY[key].label}: {counts['created']} neu, "
|
||||
f"{counts['updated']} aktualisiert"
|
||||
+ (f", {counts['skipped']} uebersprungen" if counts["skipped"] else "")
|
||||
+ (f", {counts['skipped']} übersprungen" if counts["skipped"] else "")
|
||||
for key, counts in report.items()
|
||||
if key in transfer.CATEGORY_BY_KEY
|
||||
]
|
||||
flash("Uebernahme abgeschlossen. " + " | ".join(lines), "success")
|
||||
flash("Übernahme abgeschlossen. " + " – ".join(lines), "success")
|
||||
return redirect(url_for("backup.overview"))
|
||||
|
||||
|
||||
@bp.post("/import/verwerfen")
|
||||
@permission_required("backup.execute")
|
||||
@bp.post("/import/discard")
|
||||
@permission_required("backup_import.execute")
|
||||
def import_discard():
|
||||
token = session.pop(PREVIEW_SESSION_KEY, "")
|
||||
if token:
|
||||
|
||||
@@ -9,7 +9,7 @@ from tesm_core.extension import db, transaction
|
||||
from ..services import issuance, reporting
|
||||
from .common import customer_facing_url, log_event
|
||||
|
||||
bp = Blueprint("customers", __name__, url_prefix="/kunden")
|
||||
bp = Blueprint("customers", __name__, url_prefix="/customers")
|
||||
|
||||
FIELDS = (
|
||||
"name",
|
||||
@@ -29,13 +29,13 @@ def _form() -> dict[str, str]:
|
||||
|
||||
|
||||
@bp.get("/")
|
||||
@permission_required("customers.view")
|
||||
@permission_required("customers.read")
|
||||
def overview():
|
||||
return render_template("license/customers.html", customers=issuance.list_customers(db()))
|
||||
|
||||
|
||||
@bp.get("/<int:customer_id>")
|
||||
@permission_required("customers.view")
|
||||
@permission_required("customers.read")
|
||||
def detail(customer_id: int):
|
||||
conn = db()
|
||||
customer = issuance.get_customer(conn, customer_id)
|
||||
@@ -48,7 +48,7 @@ def detail(customer_id: int):
|
||||
]
|
||||
reported = (
|
||||
reporting.reported_for_customer(conn, customer_id)
|
||||
if current_user.has("reports.view")
|
||||
if current_user.has("reports.read")
|
||||
else {"customers": [], "source_license_id": ""}
|
||||
)
|
||||
return render_template(
|
||||
@@ -61,7 +61,7 @@ def detail(customer_id: int):
|
||||
)
|
||||
|
||||
|
||||
@bp.post("/neu")
|
||||
@bp.post("/new")
|
||||
@permission_required("customers.create")
|
||||
def create():
|
||||
try:
|
||||
@@ -83,7 +83,7 @@ def create():
|
||||
|
||||
|
||||
@bp.post("/<int:customer_id>")
|
||||
@permission_required("customers.edit")
|
||||
@permission_required("customers.write")
|
||||
def update(customer_id: int):
|
||||
try:
|
||||
with transaction() as conn:
|
||||
@@ -96,14 +96,14 @@ def update(customer_id: int):
|
||||
severity="notice",
|
||||
scope="kunde",
|
||||
)
|
||||
flash("Aenderungen gespeichert." if changes else "Keine Aenderungen.",
|
||||
flash("Änderungen gespeichert." if changes else "Keine Änderungen.",
|
||||
"success" if changes else "info")
|
||||
except issuance.IssuanceError as exc:
|
||||
flash(str(exc), "danger")
|
||||
return redirect(url_for("customers.detail", customer_id=customer_id))
|
||||
|
||||
|
||||
@bp.post("/<int:customer_id>/loeschen")
|
||||
@bp.post("/<int:customer_id>/delete")
|
||||
@permission_required("customers.delete")
|
||||
def delete(customer_id: int):
|
||||
conn = db()
|
||||
@@ -119,7 +119,7 @@ def delete(customer_id: int):
|
||||
severity="warning",
|
||||
scope="kunde",
|
||||
)
|
||||
flash("Kunde geloescht.", "success")
|
||||
flash("Kunde gelöscht.", "success")
|
||||
return redirect(url_for("customers.overview"))
|
||||
except issuance.IssuanceError as exc:
|
||||
flash(str(exc), "danger")
|
||||
|
||||
@@ -16,12 +16,12 @@ from ..services import issuance, reporting
|
||||
bp = Blueprint("dashboard", __name__)
|
||||
|
||||
|
||||
@bp.get("/uebersicht")
|
||||
@bp.get("/overview")
|
||||
@login_required
|
||||
def index():
|
||||
conn = db()
|
||||
extension = core()
|
||||
if not current_user.has("licenses.view"):
|
||||
if not current_user.has("licenses.read"):
|
||||
# Leere Huelle statt 403: die Startseite soll fuer jeden erreichbar
|
||||
# bleiben, auch fuer ein Konto ohne Lizenzrechte.
|
||||
return render_template("license/dashboard.html", summary=None, sources=[])
|
||||
@@ -30,7 +30,7 @@ def index():
|
||||
return render_template(
|
||||
"license/dashboard.html",
|
||||
summary=summary,
|
||||
sources=reporting.reporting_sources(conn) if current_user.has("reports.view") else [],
|
||||
sources=reporting.reporting_sources(conn) if current_user.has("reports.read") else [],
|
||||
own_role=(extension.license.state.role if extension.license else "master"),
|
||||
type_labels=dict(),
|
||||
)
|
||||
|
||||
@@ -38,18 +38,18 @@ from .common import (
|
||||
vendor_info,
|
||||
)
|
||||
|
||||
bp = Blueprint("licenses", __name__, url_prefix="/lizenzen")
|
||||
bp = Blueprint("licenses", __name__, url_prefix="/licenses")
|
||||
|
||||
|
||||
@bp.get("/")
|
||||
@permission_required("licenses.view")
|
||||
@permission_required("licenses.read")
|
||||
def overview():
|
||||
conn = db()
|
||||
rows = [
|
||||
{**row, **issuance.display_state(row)}
|
||||
for row in issuance.list_licenses(
|
||||
conn,
|
||||
customer_id=request.args.get("kunde", type=int),
|
||||
customer_id=request.args.get("customer", type=int),
|
||||
ticket_id=request.args.get("ticket"),
|
||||
status=request.args.get("status"),
|
||||
)
|
||||
@@ -65,7 +65,7 @@ def overview():
|
||||
|
||||
|
||||
@bp.get("/<license_id>")
|
||||
@permission_required("licenses.view")
|
||||
@permission_required("licenses.read")
|
||||
def detail(license_id: str):
|
||||
conn = db()
|
||||
row = issuance.get_license(conn, license_id)
|
||||
@@ -99,8 +99,8 @@ def detail(license_id: str):
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
@bp.post("/aus-ticket/<ticket_id>")
|
||||
@permission_required("licenses.create")
|
||||
@bp.post("/from-ticket/<ticket_id>")
|
||||
@permission_required("license_issue.execute")
|
||||
def issue(ticket_id: str):
|
||||
conn = db()
|
||||
as_trial = request.form.get("as_trial") == "1"
|
||||
@@ -124,7 +124,7 @@ def issue(ticket_id: str):
|
||||
|
||||
if result.already_existed:
|
||||
flash(
|
||||
"Zu diesem Ticket war bereits eine Lizenz offen -- sie wird angezeigt statt eine "
|
||||
"Zu diesem Ticket war bereits eine Lizenz offen – sie wird angezeigt statt eine "
|
||||
"zweite auszustellen.",
|
||||
"info",
|
||||
)
|
||||
@@ -140,9 +140,9 @@ def issue(ticket_id: str):
|
||||
return redirect(url_for("licenses.detail", license_id=result.license_id))
|
||||
|
||||
|
||||
@bp.get("/<license_id>/datei")
|
||||
@bp.get("/<license_id>/file")
|
||||
@permission_required("licenses.export")
|
||||
@reauth_required
|
||||
# Die frische Bestaetigung verlangt das Recht selbst (SENSITIVE_ACTIONS).
|
||||
def download(license_id: str):
|
||||
"""Laedt das vollstaendige Auslieferungs-Bundle herunter.
|
||||
|
||||
@@ -166,7 +166,7 @@ def download(license_id: str):
|
||||
channel="download",
|
||||
recipient=current_user.username,
|
||||
actor=current_user.username,
|
||||
detail="Vollstaendiges Bundle" if "client_key" in bundle else "Nur Lizenzdokument",
|
||||
detail="Vollständiges Bundle" if "client_key" in bundle else "Nur Lizenzdokument",
|
||||
)
|
||||
log_event("license.downloaded", target=license_id[:12], severity="notice")
|
||||
return Response(
|
||||
@@ -181,8 +181,8 @@ def download(license_id: str):
|
||||
)
|
||||
|
||||
|
||||
@bp.post("/<license_id>/neu-signieren")
|
||||
@permission_required("licenses.edit")
|
||||
@bp.post("/<license_id>/resign")
|
||||
@permission_required("license_renew.execute")
|
||||
@reauth_required
|
||||
def resign(license_id: str):
|
||||
"""Signiert eine neue Revision -- z. B. nach einer Modulerweiterung.
|
||||
@@ -202,7 +202,7 @@ def resign(license_id: str):
|
||||
try:
|
||||
days = int(request.form["extend_days"])
|
||||
except ValueError:
|
||||
flash("Die Verlaengerung muss eine Zahl sein.", "danger")
|
||||
flash("Die Verlängerung muss eine Zahl sein.", "danger")
|
||||
return redirect(url_for("licenses.detail", license_id=license_id))
|
||||
if days > 0:
|
||||
document = json.loads(str(row["license_document"]))
|
||||
@@ -212,7 +212,7 @@ def resign(license_id: str):
|
||||
changes["expires_at"] = lic.iso(base + timedelta(days=days))
|
||||
|
||||
if not changes:
|
||||
flash("Es wurde keine Aenderung angegeben.", "info")
|
||||
flash("Es wurde keine Änderung angegeben.", "info")
|
||||
return redirect(url_for("licenses.detail", license_id=license_id))
|
||||
|
||||
key = signing_key()
|
||||
@@ -233,15 +233,15 @@ def resign(license_id: str):
|
||||
)
|
||||
reporting.report_soon(core())
|
||||
flash(
|
||||
f"Neue Revision {updated['seq']} signiert. Der Client erhaelt sie beim naechsten "
|
||||
f"Neue Revision {updated['seq']} signiert. Der Client erhält sie beim nächsten "
|
||||
"Heartbeat.",
|
||||
"success",
|
||||
)
|
||||
return redirect(url_for("licenses.detail", license_id=license_id))
|
||||
|
||||
|
||||
@bp.post("/<license_id>/widerrufen")
|
||||
@permission_required("licenses.edit")
|
||||
@bp.post("/<license_id>/revoke")
|
||||
@permission_required("license_revoke.execute")
|
||||
def revoke(license_id: str):
|
||||
conn = db()
|
||||
try:
|
||||
@@ -258,14 +258,14 @@ def revoke(license_id: str):
|
||||
)
|
||||
reporting.report_soon(core())
|
||||
flash(
|
||||
"Lizenz widerrufen. Das Ticket bleibt offen -- eine neue Lizenz kann sofort "
|
||||
"Lizenz widerrufen. Das Ticket bleibt offen – eine neue Lizenz kann sofort "
|
||||
"ausgestellt werden.",
|
||||
"success",
|
||||
)
|
||||
return redirect(url_for("licenses.detail", license_id=license_id))
|
||||
|
||||
|
||||
@bp.post("/<license_id>/loeschen")
|
||||
@bp.post("/<license_id>/delete")
|
||||
@permission_required("licenses.delete")
|
||||
def delete(license_id: str):
|
||||
conn = db()
|
||||
@@ -277,7 +277,7 @@ def delete(license_id: str):
|
||||
return redirect(url_for("licenses.detail", license_id=license_id))
|
||||
log_event("license.deleted", target=license_id[:12], severity="warning")
|
||||
reporting.report_soon(core())
|
||||
flash("Lizenz geloescht.", "success")
|
||||
flash("Lizenz gelöscht.", "success")
|
||||
return redirect(url_for("licenses.overview"))
|
||||
|
||||
|
||||
@@ -286,7 +286,7 @@ def delete(license_id: str):
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
@bp.post("/<license_id>/versenden")
|
||||
@bp.post("/<license_id>/send")
|
||||
@permission_required("licenses.export")
|
||||
def send_mail(license_id: str):
|
||||
conn = db()
|
||||
@@ -295,7 +295,7 @@ def send_mail(license_id: str):
|
||||
abort(404)
|
||||
recipient = (request.form.get("recipient") or str(row["contact_email"] or "")).strip()
|
||||
if not recipient:
|
||||
flash("Es ist keine Empfaengeradresse hinterlegt.", "danger")
|
||||
flash("Es ist keine Empfängeradresse hinterlegt.", "danger")
|
||||
return redirect(url_for("licenses.detail", license_id=license_id))
|
||||
|
||||
try:
|
||||
@@ -315,7 +315,7 @@ def send_mail(license_id: str):
|
||||
"",
|
||||
f"Lizenz-ID: {license_id}",
|
||||
f"Typ: {type_labels().get(str(row['type']), str(row['type']))}",
|
||||
f"Gueltig bis: {row['expires_at']}"
|
||||
f"Gültig bis: {row['expires_at']}"
|
||||
+ (" (unbefristet)" if row["lifetime"] else ""),
|
||||
]
|
||||
if is_customer and row["ticket_id"]:
|
||||
@@ -329,7 +329,7 @@ def send_mail(license_id: str):
|
||||
"Ihre Stammdaten pflegen:",
|
||||
customer_facing_url("portal.request_link"),
|
||||
]
|
||||
lines += ["", "Freundliche Gruesse", vendor.get("name") or "Ihr Lizenzgeber"]
|
||||
lines += ["", "Freundliche Grüße", vendor.get("name") or "Ihr Lizenzgeber"]
|
||||
if vendor.get("phone"):
|
||||
lines.append(f"Telefon: {vendor['phone']}")
|
||||
if vendor.get("email"):
|
||||
@@ -369,7 +369,7 @@ def send_mail(license_id: str):
|
||||
|
||||
|
||||
@bp.route("/offline-code", methods=["GET", "POST"])
|
||||
@permission_required("licenses.execute")
|
||||
@permission_required("license_activation.execute")
|
||||
def manual_code():
|
||||
"""Verarbeitet einen Offline-Code des Kunden.
|
||||
|
||||
@@ -403,7 +403,7 @@ def manual_code():
|
||||
if outcome.ok:
|
||||
response_code = lic.encode_code(outcome.response)
|
||||
ok = True
|
||||
message = "Antwortcode erzeugt. Bitte an den Kunden zuruecksenden."
|
||||
message = "Antwortcode erzeugt. Bitte an den Kunden zurücksenden."
|
||||
log_event(
|
||||
f"license.offline_{payload.get('action')}",
|
||||
target=str(payload.get("license_id") or "")[:12],
|
||||
@@ -428,8 +428,8 @@ def manual_code():
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
@bp.get("/sub-lizenzserver")
|
||||
@permission_required("reports.view")
|
||||
@bp.get("/sub-servers")
|
||||
@permission_required("reports.read")
|
||||
def reports():
|
||||
conn = db()
|
||||
sources = reporting.reporting_sources(conn)
|
||||
@@ -440,8 +440,8 @@ def reports():
|
||||
)
|
||||
|
||||
|
||||
@bp.get("/sub-lizenzserver/<license_id>")
|
||||
@permission_required("reports.view")
|
||||
@bp.get("/sub-servers/<license_id>")
|
||||
@permission_required("reports.read")
|
||||
def report_detail(license_id: str):
|
||||
conn = db()
|
||||
row = issuance.get_license(conn, license_id)
|
||||
|
||||
@@ -36,13 +36,13 @@ from .. import is_master_edition
|
||||
from ..services import master_key
|
||||
from .common import can_issue_license_server_licenses, log_event, signing_key
|
||||
|
||||
bp = Blueprint("own_license", __name__, url_prefix="/eigene-lizenz")
|
||||
bp = Blueprint("own_license", __name__, url_prefix="/own-license")
|
||||
|
||||
MAX_UPLOAD_BYTES = 256 * 1024
|
||||
|
||||
|
||||
@bp.get("/")
|
||||
@permission_required("settings_license.view")
|
||||
@permission_required("settings_license.read")
|
||||
def overview():
|
||||
extension = core()
|
||||
conn = db()
|
||||
@@ -68,8 +68,8 @@ def overview():
|
||||
)
|
||||
|
||||
|
||||
@bp.post("/einspielen")
|
||||
@permission_required("settings_license.edit")
|
||||
@bp.post("/install")
|
||||
@permission_required("settings_license.write")
|
||||
def upload():
|
||||
extension = core()
|
||||
manager = extension.license
|
||||
@@ -79,11 +79,11 @@ def upload():
|
||||
|
||||
upload_file = request.files.get("license_file")
|
||||
if upload_file is None or not upload_file.filename:
|
||||
flash("Keine Datei ausgewaehlt.", "danger")
|
||||
flash("Keine Datei ausgewählt.", "danger")
|
||||
return redirect(url_for("own_license.overview"))
|
||||
raw = upload_file.stream.read(MAX_UPLOAD_BYTES + 1)
|
||||
if len(raw) > MAX_UPLOAD_BYTES:
|
||||
flash("Die Datei ist zu gross fuer eine Lizenzdatei.", "danger")
|
||||
flash("Die Datei ist zu groß für eine Lizenzdatei.", "danger")
|
||||
return redirect(url_for("own_license.overview"))
|
||||
|
||||
try:
|
||||
@@ -129,27 +129,27 @@ def _handshake(action: str):
|
||||
return redirect(url_for("own_license.overview"))
|
||||
|
||||
|
||||
@bp.post("/aktivieren")
|
||||
@permission_required("settings_license.edit")
|
||||
@bp.post("/activate")
|
||||
@permission_required("settings_license.write")
|
||||
def activate():
|
||||
return _handshake("activate")
|
||||
|
||||
|
||||
@bp.post("/deaktivieren")
|
||||
@permission_required("settings_license.edit")
|
||||
@bp.post("/deactivate")
|
||||
@permission_required("settings_license.write")
|
||||
@reauth_required
|
||||
def deactivate():
|
||||
return _handshake("deactivate")
|
||||
|
||||
|
||||
@bp.post("/heartbeat")
|
||||
@permission_required("settings_license.edit")
|
||||
@permission_required("settings_license.write")
|
||||
def heartbeat():
|
||||
return _handshake("heartbeat")
|
||||
|
||||
|
||||
@bp.post("/offline-antwort")
|
||||
@permission_required("settings_license.edit")
|
||||
@bp.post("/offline-response")
|
||||
@permission_required("settings_license.write")
|
||||
def offline_response():
|
||||
manager = core().license
|
||||
if manager is None:
|
||||
@@ -166,8 +166,8 @@ def offline_response():
|
||||
return redirect(url_for("own_license.overview"))
|
||||
|
||||
|
||||
@bp.get("/signaturschluessel")
|
||||
@permission_required("settings_license.view")
|
||||
@bp.get("/signing-key")
|
||||
@permission_required("settings_license.read")
|
||||
def signing_key_info():
|
||||
"""Zeigt den oeffentlichen Signaturschluessel -- zum Pinnen beim Kunden.
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ RATE_WINDOW_MINUTES = 15
|
||||
|
||||
GENERIC_ANSWER = (
|
||||
"Falls diese E-Mail-Adresse bei uns hinterlegt ist, wurde soeben eine Nachricht mit "
|
||||
"einem {minutes} Minuten gueltigen Zugangslink verschickt."
|
||||
"einem {minutes} Minuten gültigen Zugangslink verschickt."
|
||||
)
|
||||
|
||||
EDITABLE_FIELDS = (
|
||||
@@ -150,13 +150,13 @@ def request_link():
|
||||
f"Guten Tag{(' ' + str(customer['contact_person'])) if customer['contact_person'] else ''},",
|
||||
"",
|
||||
"mit dem folgenden Link erreichen Sie Ihre Daten im Kundenportal.",
|
||||
f"Der Link ist {minutes} Minuten gueltig und laesst sich nur einmal verwenden:",
|
||||
f"Der Link ist {minutes} Minuten gültig und lässt sich nur einmal verwenden:",
|
||||
"",
|
||||
access_url,
|
||||
"",
|
||||
"Wenn Sie diesen Zugang nicht angefragt haben, ignorieren Sie die Nachricht.",
|
||||
"",
|
||||
"Freundliche Gruesse",
|
||||
"Freundliche Grüße",
|
||||
vendor.get("name") or "Ihr Lizenzgeber",
|
||||
]
|
||||
),
|
||||
@@ -185,7 +185,7 @@ def access(token: str):
|
||||
expires = _parse(row["expires_at"]) if row is not None else None
|
||||
valid = row is not None and row["used_at"] is None and expires is not None and _now() < expires
|
||||
if not valid:
|
||||
flash("Dieser Link ist ungueltig oder abgelaufen.", "danger")
|
||||
flash("Dieser Link ist ungültig oder abgelaufen.", "danger")
|
||||
return redirect(url_for("portal.request_link"))
|
||||
|
||||
minutes = int(extension.settings.get(conn, "portal_session_minutes") or 60)
|
||||
@@ -247,7 +247,7 @@ def me():
|
||||
ip=client_ip(),
|
||||
severity="notice",
|
||||
)
|
||||
flash("Ihre Angaben wurden gespeichert." if changes else "Keine Aenderungen.", "success")
|
||||
flash("Ihre Angaben wurden gespeichert." if changes else "Keine Änderungen.", "success")
|
||||
except issuance.IssuanceError as exc:
|
||||
flash(str(exc), "danger")
|
||||
return redirect(url_for("portal.me"))
|
||||
|
||||
@@ -31,6 +31,8 @@ from .common import (
|
||||
vendor_info,
|
||||
)
|
||||
|
||||
# Die Adresse steht in verschickten Mails und in Tickets -- sie bleibt
|
||||
# deutsch, waehrend der Rest der Anwendung auf englische Pfade wechselt.
|
||||
bp = Blueprint("selfservice", __name__, url_prefix="/lizenz")
|
||||
|
||||
RATE_BUCKET = "selfservice"
|
||||
@@ -60,7 +62,7 @@ def _rate_guard() -> None:
|
||||
with transaction():
|
||||
ratelimit.record(conn, RATE_BUCKET, client_ip() or "unbekannt")
|
||||
if verdict.blocked:
|
||||
abort(429, description="Zu viele Anfragen. Bitte spaeter erneut versuchen.")
|
||||
abort(429, description="Zu viele Anfragen. Bitte später erneut versuchen.")
|
||||
|
||||
|
||||
def _needs_offline(conn, ticket_id: str): # type: ignore[no-untyped-def]
|
||||
@@ -139,8 +141,8 @@ def issue(ticket_id: str):
|
||||
return redirect(url_for("selfservice.overview", ticket_id=ticket_id))
|
||||
if issuance.ticket_has_open_license(conn, ticket_id):
|
||||
flash(
|
||||
"Es existiert bereits eine gueltige Lizenz. Geben Sie diese zuerst frei, wenn Sie "
|
||||
"auf ein anderes System wechseln moechten.",
|
||||
"Es existiert bereits eine gültige Lizenz. Geben Sie diese zuerst frei, wenn Sie "
|
||||
"auf ein anderes System wechseln möchten.",
|
||||
"warning",
|
||||
)
|
||||
return redirect(url_for("selfservice.overview", ticket_id=ticket_id))
|
||||
@@ -236,12 +238,12 @@ def offline(ticket_id: str):
|
||||
_log(
|
||||
"selfservice.offline_rejected",
|
||||
ticket,
|
||||
"Code gehoert nicht zu diesem Vorgang",
|
||||
"Code gehört nicht zu diesem Vorgang",
|
||||
severity="warning",
|
||||
)
|
||||
flash(
|
||||
"Dieser Code gehoert nicht zu Ihrem Vorgang. Bitte pruefen Sie, ob Sie ihn "
|
||||
"vollstaendig kopiert haben.",
|
||||
"Dieser Code gehört nicht zu Ihrem Vorgang. Bitte prüfen Sie, ob Sie ihn "
|
||||
"vollständig kopiert haben.",
|
||||
"danger",
|
||||
)
|
||||
return redirect(url_for("selfservice.offline", ticket_id=ticket_id))
|
||||
@@ -297,7 +299,7 @@ def revoke(ticket_id: str, license_id: str):
|
||||
_log("license.revoked_self_service", ticket, license_id[:12], severity="warning")
|
||||
reporting.report_soon(core())
|
||||
flash(
|
||||
"Die Lizenz wurde freigegeben. Sie koennen jetzt eine neue Lizenz fuer Ihr neues System "
|
||||
"Die Lizenz wurde freigegeben. Sie können jetzt eine neue Lizenz für Ihr neues System "
|
||||
"ausstellen.",
|
||||
"success",
|
||||
)
|
||||
|
||||
@@ -17,7 +17,7 @@ from tesm_core.extension import core, db, transaction
|
||||
from ..services import mail
|
||||
from .common import log_event, master_endpoint, vendor_info
|
||||
|
||||
bp = Blueprint("settings", __name__, url_prefix="/einstellungen")
|
||||
bp = Blueprint("settings", __name__, url_prefix="/administration")
|
||||
|
||||
MAX_LOGO_BYTES = 200 * 1024
|
||||
LOGO_MIME = {
|
||||
@@ -35,7 +35,7 @@ LOGO_MAGIC = {
|
||||
|
||||
|
||||
@bp.get("/system")
|
||||
@permission_required("settings_system.view")
|
||||
@permission_required("settings_system.read")
|
||||
def system():
|
||||
extension = core()
|
||||
conn = db()
|
||||
@@ -54,6 +54,8 @@ def system():
|
||||
"trash_retention_days",
|
||||
"log_rotate_interval",
|
||||
"log_rotate_keep",
|
||||
"session_idle_minutes",
|
||||
"session_absolute_hours",
|
||||
],
|
||||
),
|
||||
specs={spec.key: spec for spec in extension.settings.specs()},
|
||||
@@ -66,8 +68,13 @@ def system():
|
||||
else ""
|
||||
),
|
||||
timezones=_timezone_choices(),
|
||||
nav_items=extension.nav.items,
|
||||
# Nicht ``nav_items``: dieser Name gehoert dem Seitenrahmen. Wer ihn hier
|
||||
# belegt, ueberschreibt die gefilterte Navigation aus dem Kontext --
|
||||
# und die Seitenleiste zeigte dann jeden Punkt, auch den, den dieser
|
||||
# Benutzer nicht darf und den die Lizenz nicht freischaltet.
|
||||
nav_baum=extension.nav.items,
|
||||
nav_order=extension.settings.get(conn, "nav_order") or extension.nav.default_order(),
|
||||
nav_child_order=extension.settings.get(conn, "nav_child_order") or {},
|
||||
sysops_available=bool(sysops and sysops.available),
|
||||
)
|
||||
|
||||
@@ -82,7 +89,7 @@ def _timezone_choices() -> list[str]:
|
||||
|
||||
|
||||
@bp.post("/system")
|
||||
@permission_required("settings_system.edit")
|
||||
@permission_required("settings_system.write")
|
||||
def system_save():
|
||||
extension = core()
|
||||
conn = db()
|
||||
@@ -97,6 +104,8 @@ def system_save():
|
||||
"trash_retention_days",
|
||||
"log_rotate_interval",
|
||||
"log_rotate_keep",
|
||||
"session_idle_minutes",
|
||||
"session_absolute_hours",
|
||||
):
|
||||
spec = extension.settings.spec(key)
|
||||
if spec.kind == "bool":
|
||||
@@ -116,7 +125,7 @@ def system_save():
|
||||
ip=client_ip(),
|
||||
severity="notice",
|
||||
)
|
||||
flash("Einstellungen gespeichert." if changed else "Keine Aenderungen.",
|
||||
flash("Einstellungen gespeichert." if changed else "Keine Änderungen.",
|
||||
"success" if changed else "info")
|
||||
return redirect(url_for("settings.system"))
|
||||
|
||||
@@ -128,10 +137,10 @@ def set_hostname():
|
||||
sysops = extension.sysops
|
||||
hostname = (request.form.get("hostname") or "").strip()
|
||||
if not hostname or len(hostname) > 63 or not hostname.replace("-", "").isalnum():
|
||||
flash("Der Hostname ist ungueltig.", "danger")
|
||||
flash("Der Hostname ist ungültig.", "danger")
|
||||
return redirect(url_for("settings.system"))
|
||||
if sysops is None or not sysops.available:
|
||||
flash("Systemaktionen sind in dieser Umgebung nicht verfuegbar.", "warning")
|
||||
flash("Systemaktionen sind in dieser Umgebung nicht verfügbar.", "warning")
|
||||
return redirect(url_for("settings.system"))
|
||||
result = sysops.set_hostname(hostname)
|
||||
if result.ok:
|
||||
@@ -142,7 +151,7 @@ def set_hostname():
|
||||
return redirect(url_for("settings.system"))
|
||||
|
||||
|
||||
@bp.post("/system/zeitzone")
|
||||
@bp.post("/system/timezone")
|
||||
@permission_required("settings_system.execute")
|
||||
def set_timezone():
|
||||
import time
|
||||
@@ -153,7 +162,7 @@ def set_timezone():
|
||||
flash("Unbekannte Zeitzone.", "danger")
|
||||
return redirect(url_for("settings.system"))
|
||||
if sysops is None or not sysops.available:
|
||||
flash("Systemaktionen sind in dieser Umgebung nicht verfuegbar.", "warning")
|
||||
flash("Systemaktionen sind in dieser Umgebung nicht verfügbar.", "warning")
|
||||
return redirect(url_for("settings.system"))
|
||||
result = sysops.set_timezone(timezone)
|
||||
if result.ok:
|
||||
@@ -173,8 +182,8 @@ def set_timezone():
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
@bp.get("/anbieter")
|
||||
@permission_required("settings_vendor.view")
|
||||
@bp.get("/vendor")
|
||||
@permission_required("settings_vendor.read")
|
||||
def vendor():
|
||||
extension = core()
|
||||
conn = db()
|
||||
@@ -195,8 +204,8 @@ def vendor():
|
||||
)
|
||||
|
||||
|
||||
@bp.post("/anbieter")
|
||||
@permission_required("settings_vendor.edit")
|
||||
@bp.post("/vendor")
|
||||
@permission_required("settings_vendor.write")
|
||||
def vendor_save():
|
||||
extension = core()
|
||||
conn = db()
|
||||
@@ -222,7 +231,7 @@ def vendor_save():
|
||||
if suffix not in LOGO_MIME:
|
||||
logo_problem = "Erlaubt sind PNG, JPG und SVG."
|
||||
elif len(data) > MAX_LOGO_BYTES:
|
||||
logo_problem = f"Das Logo ist zu gross (maximal {MAX_LOGO_BYTES // 1024} KB)."
|
||||
logo_problem = f"Das Logo ist zu groß (maximal {MAX_LOGO_BYTES // 1024} KB)."
|
||||
elif not any(head.startswith(magic) for magic in LOGO_MAGIC):
|
||||
logo_problem = "Die Datei ist kein Bild."
|
||||
else:
|
||||
@@ -240,13 +249,13 @@ def vendor_save():
|
||||
log_event(
|
||||
"settings.vendor_saved", detail=", ".join(changed), severity="notice", scope="anbieter"
|
||||
)
|
||||
flash("Anbieterdaten gespeichert." if changed else "Keine Aenderungen.",
|
||||
flash("Anbieterdaten gespeichert." if changed else "Keine Änderungen.",
|
||||
"success" if changed else "info")
|
||||
return redirect(url_for("settings.vendor"))
|
||||
|
||||
|
||||
@bp.post("/anbieter/logo-entfernen")
|
||||
@permission_required("settings_vendor.edit")
|
||||
@bp.post("/vendor/remove-logo")
|
||||
@permission_required("settings_vendor.write")
|
||||
def vendor_logo_remove():
|
||||
with transaction() as conn:
|
||||
core().settings.set(conn, "vendor_logo_base64", "", actor=current_user.username)
|
||||
@@ -260,7 +269,7 @@ def vendor_logo_remove():
|
||||
|
||||
|
||||
@bp.get("/email")
|
||||
@permission_required("settings_mail.view")
|
||||
@permission_required("settings_mail.read")
|
||||
def mail_settings():
|
||||
extension = core()
|
||||
conn = db()
|
||||
@@ -275,7 +284,7 @@ def mail_settings():
|
||||
|
||||
|
||||
@bp.post("/email")
|
||||
@permission_required("settings_mail.edit")
|
||||
@permission_required("settings_mail.write")
|
||||
def mail_save():
|
||||
extension = core()
|
||||
conn = db()
|
||||
@@ -292,7 +301,7 @@ def mail_save():
|
||||
mail.store_secret(conn, request.form.get("client_secret"))
|
||||
changed.append("client_secret")
|
||||
log_event("settings.mail_saved", detail=", ".join(changed), severity="notice", scope="mail")
|
||||
flash("E-Mail-Einstellungen gespeichert." if changed else "Keine Aenderungen.",
|
||||
flash("E-Mail-Einstellungen gespeichert." if changed else "Keine Änderungen.",
|
||||
"success" if changed else "info")
|
||||
return redirect(url_for("settings.mail_settings"))
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ bp = Blueprint("tickets", __name__, url_prefix="/tickets")
|
||||
|
||||
|
||||
@bp.get("/")
|
||||
@permission_required("tickets.view")
|
||||
@permission_required("tickets.read")
|
||||
def overview():
|
||||
conn = db()
|
||||
tickets = issuance.list_tickets(conn)
|
||||
@@ -45,7 +45,7 @@ def overview():
|
||||
)
|
||||
|
||||
|
||||
@bp.get("/neu")
|
||||
@bp.get("/new")
|
||||
@permission_required("tickets.create")
|
||||
def new():
|
||||
conn = db()
|
||||
@@ -60,11 +60,11 @@ def new():
|
||||
type_labels=type_labels(),
|
||||
default_valid_days=int(extension.settings.get(conn, "default_valid_days") or 365),
|
||||
may_create_license_server=can_issue_license_server_licenses(),
|
||||
preselected_customer=request.args.get("kunde", type=int),
|
||||
preselected_customer=request.args.get("customer", type=int),
|
||||
)
|
||||
|
||||
|
||||
@bp.post("/neu")
|
||||
@bp.post("/new")
|
||||
@permission_required("tickets.create")
|
||||
def create():
|
||||
conn = db()
|
||||
@@ -106,14 +106,14 @@ def _endpoint_missing() -> str:
|
||||
if master_endpoint():
|
||||
return ""
|
||||
return (
|
||||
"Es ist kein oeffentlicher Endpunkt hinterlegt (Einstellungen -> Anbieter). "
|
||||
"Solange er fehlt, koennen keine Lizenzen ausgestellt werden: der Endpunkt wird "
|
||||
"in die Lizenz signiert und laesst sich spaeter nicht nachtragen."
|
||||
"Es ist kein öffentlicher Endpunkt hinterlegt (Einstellungen -> Anbieter). "
|
||||
"Solange er fehlt, können keine Lizenzen ausgestellt werden: der Endpunkt wird "
|
||||
"in die Lizenz signiert und lässt sich später nicht nachtragen."
|
||||
)
|
||||
|
||||
|
||||
@bp.get("/<ticket_id>")
|
||||
@permission_required("tickets.view")
|
||||
@permission_required("tickets.read")
|
||||
def detail(ticket_id: str):
|
||||
conn = db()
|
||||
ticket = issuance.get_ticket(conn, ticket_id)
|
||||
@@ -150,7 +150,7 @@ def detail(ticket_id: str):
|
||||
|
||||
|
||||
@bp.post("/<ticket_id>")
|
||||
@permission_required("tickets.edit")
|
||||
@permission_required("tickets.write")
|
||||
def update(ticket_id: str):
|
||||
conn = db()
|
||||
if issuance.get_ticket(conn, ticket_id) is None:
|
||||
@@ -176,9 +176,9 @@ def update(ticket_id: str):
|
||||
)
|
||||
reporting.report_soon(core())
|
||||
flash(
|
||||
"Gespeichert. Die Aenderung wirkt auf die naechste Ausstellung."
|
||||
"Gespeichert. Die Änderung wirkt auf die nächste Ausstellung."
|
||||
if changes
|
||||
else "Keine Aenderungen.",
|
||||
else "Keine Änderungen.",
|
||||
"success" if changes else "info",
|
||||
)
|
||||
except (issuance.IssuanceError, ValueError) as exc:
|
||||
@@ -186,8 +186,8 @@ def update(ticket_id: str):
|
||||
return redirect(url_for("tickets.detail", ticket_id=ticket_id))
|
||||
|
||||
|
||||
@bp.post("/<ticket_id>/sperre")
|
||||
@permission_required("tickets.edit")
|
||||
@bp.post("/<ticket_id>/lock")
|
||||
@permission_required("tickets.write")
|
||||
def toggle_block(ticket_id: str):
|
||||
conn = db()
|
||||
ticket = issuance.get_ticket(conn, ticket_id)
|
||||
@@ -205,7 +205,7 @@ def toggle_block(ticket_id: str):
|
||||
)
|
||||
reporting.report_soon(core())
|
||||
flash(
|
||||
"Ticket gesperrt -- es lassen sich keine neuen Lizenzen mehr ausstellen."
|
||||
"Ticket gesperrt – es lassen sich keine neuen Lizenzen mehr ausstellen."
|
||||
if new_status == "blocked"
|
||||
else "Ticket entsperrt.",
|
||||
"success",
|
||||
@@ -213,7 +213,7 @@ def toggle_block(ticket_id: str):
|
||||
return redirect(url_for("tickets.detail", ticket_id=ticket_id))
|
||||
|
||||
|
||||
@bp.post("/<ticket_id>/loeschen")
|
||||
@bp.post("/<ticket_id>/delete")
|
||||
@permission_required("tickets.delete")
|
||||
def delete(ticket_id: str):
|
||||
conn = db()
|
||||
@@ -231,7 +231,7 @@ def delete(ticket_id: str):
|
||||
scope="ticket",
|
||||
)
|
||||
reporting.report_soon(core())
|
||||
flash("Ticket und seine Lizenzhistorie geloescht.", "success")
|
||||
flash("Ticket und seine Lizenzhistorie gelöscht.", "success")
|
||||
return redirect(url_for("tickets.overview"))
|
||||
except issuance.IssuanceError as exc:
|
||||
flash(str(exc), "danger")
|
||||
|
||||
@@ -42,22 +42,22 @@ def cmd_init_key(args: argparse.Namespace) -> int:
|
||||
path = master_key_path(extension.config)
|
||||
if path.exists() and not args.force:
|
||||
key = master_key.load(path)
|
||||
print(f"Signaturschluessel existiert bereits: {key.key_id} ({path})")
|
||||
print("Ein Austausch macht ALLE bereits ausgestellten Lizenzen unpruefbar.")
|
||||
print(f"Signaturschlüssel existiert bereits: {key.key_id} ({path})")
|
||||
print("Ein Austausch macht ALLE bereits ausgestellten Lizenzen unprüfbar.")
|
||||
return 0
|
||||
if path.exists() and args.force:
|
||||
print(
|
||||
"ABBRUCH: --force auf einen bestehenden Signaturschluessel wird nicht unterstuetzt.\n"
|
||||
"Ein neuer Schluessel entwertet jede ausgestellte Lizenz. Bitte die Datei bewusst\n"
|
||||
"ABBRUCH: --force auf einen bestehenden Signaturschlüssel wird nicht unterstützt.\n"
|
||||
"Ein neuer Schlüssel entwertet jede ausgestellte Lizenz. Bitte die Datei bewusst\n"
|
||||
"von Hand beiseite legen, wenn das wirklich gewollt ist.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return 2
|
||||
key = master_key.ensure(path)
|
||||
print(f"Signaturschluessel erzeugt: {key.key_id}")
|
||||
print(f"Signaturschlüssel erzeugt: {key.key_id}")
|
||||
print(f"Datei: {path}")
|
||||
print("Bitte SOFORT sichern -- ohne sie ist keine ausgestellte Lizenz mehr pruefbar.")
|
||||
print(f"Oeffentlicher Schluessel (zum Pinnen beim Kunden):\n{key.public_key}")
|
||||
print("Bitte SOFORT sichern – ohne sie ist keine ausgestellte Lizenz mehr prüfbar.")
|
||||
print(f"Öffentlicher Schlüssel (zum Pinnen beim Kunden):\n{key.public_key}")
|
||||
return 0
|
||||
|
||||
|
||||
@@ -65,11 +65,11 @@ def cmd_bootstrap(args: argparse.Namespace) -> int:
|
||||
"""Stellt die eigene Lizenz dieser Wurzelinstanz aus -- nur in der Master-Ausgabe."""
|
||||
if not is_master_edition():
|
||||
for zeile in (
|
||||
"Diese Ausgabe ist fuer Sub-Lizenzserver und kann keine Master-Lizenz erzeugen.",
|
||||
"Diese Ausgabe ist für Sub-Lizenzserver und kann keine Master-Lizenz erzeugen.",
|
||||
"",
|
||||
"Ein Sub-Lizenzserver bekommt seine Lizenz vom Master-Lizenzserver und spielt",
|
||||
"sie unter 'Eigene Lizenz' ein. Danach stellt er selbst Kundenlizenzen aus --",
|
||||
"mit seinem eigenen Signaturschluessel, der beim Installieren entstanden ist.",
|
||||
"mit seinem eigenen Signaturschlüssel, der beim Installieren entstanden ist.",
|
||||
"",
|
||||
"Die Master-Ausgabe liegt im Repository tesm-license-master.",
|
||||
):
|
||||
@@ -83,10 +83,10 @@ def cmd_bootstrap(args: argparse.Namespace) -> int:
|
||||
app, extension, days=int(args.days), name=args.name
|
||||
)
|
||||
print(f"Master-Lizenz ausgestellt: {document['license_id']}")
|
||||
print(f"Gueltig bis: {document['expires_at']}")
|
||||
print(f"Gültig bis: {document['expires_at']}")
|
||||
print(f"Datei: {extension.config.license_path}")
|
||||
if state is not None:
|
||||
print(f"Zustand: gueltig={state.valid}, aktiviert={state.activated}, Rolle={state.role}")
|
||||
print(f"Zustand: gültig={state.valid}, aktiviert={state.activated}, Rolle={state.role}")
|
||||
return 0
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ def cmd_create_admin(args: argparse.Namespace) -> int:
|
||||
return 2
|
||||
password = args.password or getpass.getpass("Passwort: ")
|
||||
if not args.password and password != getpass.getpass("Passwort wiederholen: "):
|
||||
print("Die Passwoerter stimmen nicht ueberein.", file=sys.stderr)
|
||||
print("Die Passwörter stimmen nicht überein.", file=sys.stderr)
|
||||
return 2
|
||||
problems = extension.password_policy.check(password, username=username)
|
||||
if problems and not args.force:
|
||||
@@ -180,7 +180,7 @@ def cmd_status(args: argparse.Namespace) -> int:
|
||||
+ ("unversehrt" if chain["ok"] else f"GEBROCHEN bei {chain['broken_at']}")
|
||||
)
|
||||
print(
|
||||
"Signaturschluessel: "
|
||||
"Signaturschlüssel: "
|
||||
+ (str(key_health.get("key_id")) if key_health.get("present") else "FEHLT")
|
||||
)
|
||||
for problem in key_health.get("problems", []):
|
||||
@@ -253,17 +253,17 @@ def cmd_migrate_legacy(args: argparse.Namespace) -> int:
|
||||
except legacy_import.LegacyImportError as exc:
|
||||
if args.adopt_key:
|
||||
raise
|
||||
print(f"Hinweis: alter Signaturschluessel nicht lesbar ({exc}).")
|
||||
print(f"Hinweis: alter Signaturschlüssel nicht lesbar ({exc}).")
|
||||
|
||||
if key_path.is_file():
|
||||
existing = master_key.load(key_path)
|
||||
report.key_id = existing.key_id
|
||||
if legacy_public and existing.public_key == legacy_public:
|
||||
print(f"Signaturschluessel stimmt bereits ueberein ({existing.key_id}).")
|
||||
print(f"Signaturschlüssel stimmt bereits überein ({existing.key_id}).")
|
||||
elif not legacy_public:
|
||||
issuer_changes = True
|
||||
print(
|
||||
f"Es wird mit dem vorhandenen Signaturschluessel {existing.key_id} "
|
||||
f"Es wird mit dem vorhandenen Signaturschlüssel {existing.key_id} "
|
||||
"gearbeitet."
|
||||
)
|
||||
else:
|
||||
@@ -271,7 +271,7 @@ def cmd_migrate_legacy(args: argparse.Namespace) -> int:
|
||||
# ausgestellte Lizenz waere danach unpruefbar.
|
||||
issuer_changes = True
|
||||
print(
|
||||
f"Diese Installation hat einen eigenen Signaturschluessel "
|
||||
f"Diese Installation hat einen eigenen Signaturschlüssel "
|
||||
f"({existing.key_id}); der alte war {lic.key_id(legacy_public)}. "
|
||||
"Es wird mit dem vorhandenen weitergearbeitet."
|
||||
)
|
||||
@@ -279,12 +279,12 @@ def cmd_migrate_legacy(args: argparse.Namespace) -> int:
|
||||
legacy_private, legacy_public = legacy_import.read_legacy_key(root)
|
||||
report.key_id = legacy_import.adopt_key(legacy_private, legacy_public, key_path)
|
||||
report.key_adopted = True
|
||||
print(f"Signaturschluessel uebernommen: {report.key_id}")
|
||||
print(f"Signaturschlüssel übernommen: {report.key_id}")
|
||||
else:
|
||||
print(
|
||||
"Diese Installation hat noch keinen Signaturschluessel. Mit --adopt-key "
|
||||
"wird der alte uebernommen -- dann bleibt die Anbieteridentitaet erhalten "
|
||||
"und Kunden muessen keinen Ausstellerwechsel bestaetigen.",
|
||||
"Diese Installation hat noch keinen Signaturschlüssel. Mit --adopt-key "
|
||||
"wird der alte übernommen – dann bleibt die Anbieteridentität erhalten "
|
||||
"und Kunden müssen keinen Ausstellerwechsel bestätigen.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return 2
|
||||
@@ -312,7 +312,7 @@ def cmd_migrate_legacy(args: argparse.Namespace) -> int:
|
||||
# Uebernahme.
|
||||
for einstellung, wert in uebernommen.items():
|
||||
gekuerzt = wert if len(wert) <= 60 else wert[:57] + "..."
|
||||
print(f"Uebernommen: {einstellung} = {gekuerzt}")
|
||||
print(f"Übernommen: {einstellung} = {gekuerzt}")
|
||||
|
||||
vendor = {
|
||||
"name": str(extension.settings.get(conn, "vendor_name") or "Eigenbetrieb"),
|
||||
@@ -326,7 +326,7 @@ def cmd_migrate_legacy(args: argparse.Namespace) -> int:
|
||||
print(
|
||||
"Es ist kein Endpunkt hinterlegt, und die alte Installation nennt "
|
||||
"auch keinen. Bitte unter Einstellungen -> Anbieter eintragen: ohne "
|
||||
"ihn koennen uebernommene Lizenzen sich spaeter nicht aktivieren.",
|
||||
"ihn können übernommene Lizenzen sich später nicht aktivieren.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return 2
|
||||
@@ -347,10 +347,10 @@ def cmd_migrate_legacy(args: argparse.Namespace) -> int:
|
||||
result.key_id = report.key_id
|
||||
if issuer_changes:
|
||||
result.warnings.append(
|
||||
"Die Lizenzen sind mit einem anderen Schluessel signiert als "
|
||||
"frueher. Kunden, die den alten Aussteller gepinnt haben, muessen "
|
||||
"beim Einspielen einmal 'Wechsel des Ausstellers ausdruecklich "
|
||||
"zulassen' bestaetigen."
|
||||
"Die Lizenzen sind mit einem anderen Schlüssel signiert als "
|
||||
"früher. Kunden, die den alten Aussteller gepinnt haben, müssen "
|
||||
"beim Einspielen einmal 'Wechsel des Ausstellers ausdrücklich "
|
||||
"zulassen' bestätigen."
|
||||
)
|
||||
if args.dry_run:
|
||||
# Nichts festschreiben -- der Lauf war nur zur Ansicht.
|
||||
@@ -385,7 +385,7 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
)
|
||||
sub = parser.add_subparsers(dest="command", required=True)
|
||||
|
||||
init_key = sub.add_parser("init-key", help="Signaturschluessel erzeugen (einmalig)")
|
||||
init_key = sub.add_parser("init-key", help="Signaturschlüssel erzeugen (einmalig)")
|
||||
init_key.add_argument("--force", action="store_true")
|
||||
init_key.set_defaults(func=cmd_init_key)
|
||||
|
||||
@@ -401,7 +401,7 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
bootstrap.add_argument("--name", default="Lizenzserver (Eigenbetrieb)")
|
||||
bootstrap.set_defaults(func=cmd_bootstrap)
|
||||
|
||||
admin = sub.add_parser("create-admin", help="Administratorkonto anlegen oder zuruecksetzen")
|
||||
admin = sub.add_parser("create-admin", help="Administratorkonto anlegen oder zurücksetzen")
|
||||
admin.add_argument("--username")
|
||||
admin.add_argument("--password")
|
||||
admin.add_argument("--force", action="store_true")
|
||||
@@ -411,16 +411,16 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
status.add_argument("--json", action="store_true")
|
||||
status.set_defaults(func=cmd_status)
|
||||
|
||||
house = sub.add_parser("housekeeping", help="Laufzeitdaten aufraeumen")
|
||||
house = sub.add_parser("housekeeping", help="Laufzeitdaten aufräumen")
|
||||
house.set_defaults(func=cmd_housekeeping)
|
||||
|
||||
migrate = sub.add_parser(
|
||||
"migrate-legacy",
|
||||
help="Lizenzserver der Vorgaengerfassung uebernehmen",
|
||||
help="Lizenzserver der Vorgängerfassung übernehmen",
|
||||
description=(
|
||||
"Uebernimmt Signaturschluessel, Kunden, Tickets und Lizenzen aus einer alten "
|
||||
"Übernimmt Signaturschlüssel, Kunden, Tickets und Lizenzen aus einer alten "
|
||||
"Installation. Die alte Installation wird nur gelesen. Jede Lizenz wird im "
|
||||
"neuen Format neu signiert -- die Kunden brauchen danach eine neue "
|
||||
"neuen Format neu signiert – die Kunden brauchen danach eine neue "
|
||||
"Lizenzdatei, weil die alte Signatur nicht mehr gilt."
|
||||
),
|
||||
)
|
||||
@@ -430,13 +430,13 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
migrate.add_argument(
|
||||
"--adopt-key",
|
||||
action="store_true",
|
||||
help="Den alten Signaturschluessel uebernehmen. Nur moeglich, solange diese "
|
||||
"Installation noch keinen eigenen hat -- ein vorhandener wird nie ueberschrieben.",
|
||||
help="Den alten Signaturschlüssel übernehmen. Nur möglich, solange diese "
|
||||
"Installation noch keinen eigenen hat – ein vorhandener wird nie überschrieben.",
|
||||
)
|
||||
migrate.add_argument(
|
||||
"--dry-run",
|
||||
action="store_true",
|
||||
help="Nur anzeigen, was passieren wuerde -- nichts schreiben",
|
||||
help="Nur anzeigen, was passieren würde – nichts schreiben",
|
||||
)
|
||||
migrate.set_defaults(func=cmd_migrate_legacy)
|
||||
|
||||
|
||||
@@ -28,41 +28,41 @@ def _is_master(_user: Any) -> bool:
|
||||
|
||||
NAVIGATION = NavTree(
|
||||
[
|
||||
NavItem(key="index", label="Uebersicht", icon="grid", endpoint="dashboard.index"),
|
||||
NavItem(key="index", label="Übersicht", icon="grid", endpoint="dashboard.index"),
|
||||
NavItem(
|
||||
key="customers",
|
||||
label="Kunden",
|
||||
icon="building",
|
||||
endpoint="customers.overview",
|
||||
permissions=("customers.view",),
|
||||
permissions=("customers.read",),
|
||||
),
|
||||
NavItem(
|
||||
key="tickets",
|
||||
label="Tickets",
|
||||
icon="ticket",
|
||||
endpoint="tickets.overview",
|
||||
permissions=("tickets.view",),
|
||||
permissions=("tickets.read",),
|
||||
),
|
||||
NavItem(
|
||||
key="licenses",
|
||||
label="Lizenzen",
|
||||
icon="shield",
|
||||
endpoint="licenses.overview",
|
||||
permissions=("licenses.view",),
|
||||
permissions=("licenses.read",),
|
||||
),
|
||||
NavItem(
|
||||
key="offline_code",
|
||||
label="Offline-Aktivierung",
|
||||
icon="transfer",
|
||||
endpoint="licenses.manual_code",
|
||||
permissions=("licenses.execute",),
|
||||
permissions=("license_activation.execute",),
|
||||
),
|
||||
NavItem(
|
||||
key="reports",
|
||||
label="Sub-Lizenzserver",
|
||||
icon="share",
|
||||
endpoint="licenses.reports",
|
||||
permissions=("reports.view",),
|
||||
permissions=("reports.read",),
|
||||
condition=_is_master,
|
||||
),
|
||||
NavItem(
|
||||
@@ -72,24 +72,24 @@ NAVIGATION = NavTree(
|
||||
children=(
|
||||
NavItem(
|
||||
key="logs_live",
|
||||
label="Laufend",
|
||||
label="Live",
|
||||
icon="terminal",
|
||||
endpoint="logs.live",
|
||||
permissions=("logs_live.view",),
|
||||
permissions=("logs_live.read",),
|
||||
),
|
||||
NavItem(
|
||||
key="logs_history",
|
||||
label="Verlauf",
|
||||
icon="clock",
|
||||
endpoint="logs.history",
|
||||
permissions=("logs_history.view", "logs_history.export"),
|
||||
permissions=("logs_history.read", "logs_history.export"),
|
||||
),
|
||||
NavItem(
|
||||
key="logs_audit",
|
||||
label="Audit",
|
||||
icon="history",
|
||||
endpoint="logs.audit_view",
|
||||
permissions=("logs_audit.view", "logs_audit.export"),
|
||||
permissions=("logs_audit.read", "logs_audit.export"),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -103,84 +103,84 @@ NAVIGATION = NavTree(
|
||||
label="Benutzer",
|
||||
icon="users",
|
||||
endpoint="admin.users",
|
||||
permissions=("users.view",),
|
||||
permissions=("users.read",),
|
||||
),
|
||||
NavItem(
|
||||
key="groups",
|
||||
label="Gruppen und Rechte",
|
||||
icon="shield-users",
|
||||
endpoint="admin.groups",
|
||||
permissions=("groups.view",),
|
||||
permissions=("groups.read",),
|
||||
),
|
||||
NavItem(
|
||||
key="settings_vendor",
|
||||
label="Anbieterdaten",
|
||||
icon="building",
|
||||
endpoint="settings.vendor",
|
||||
permissions=("settings_vendor.view",),
|
||||
permissions=("settings_vendor.read",),
|
||||
),
|
||||
NavItem(
|
||||
key="settings_mail",
|
||||
label="E-Mail-Versand",
|
||||
icon="mail",
|
||||
endpoint="settings.mail_settings",
|
||||
permissions=("settings_mail.view",),
|
||||
permissions=("settings_mail.read",),
|
||||
),
|
||||
NavItem(
|
||||
key="settings_system",
|
||||
label="System",
|
||||
icon="sliders",
|
||||
endpoint="settings.system",
|
||||
permissions=("settings_system.view",),
|
||||
permissions=("settings_system.read",),
|
||||
),
|
||||
NavItem(
|
||||
key="settings_network",
|
||||
label="Netzwerk",
|
||||
icon="network",
|
||||
endpoint="hostsettings.network",
|
||||
permissions=("settings_network.view",),
|
||||
permissions=("settings_network.read",),
|
||||
),
|
||||
NavItem(
|
||||
key="settings_web",
|
||||
label="Webserver und TLS",
|
||||
icon="server",
|
||||
endpoint="hostsettings.web",
|
||||
permissions=("settings_web.view",),
|
||||
permissions=("settings_web.read",),
|
||||
),
|
||||
NavItem(
|
||||
key="settings_directory",
|
||||
label="Verzeichnisdienst",
|
||||
icon="users",
|
||||
endpoint="hostsettings.directory_settings",
|
||||
permissions=("settings_directory.view",),
|
||||
permissions=("settings_directory.read",),
|
||||
),
|
||||
NavItem(
|
||||
key="settings_license",
|
||||
label="Eigene Lizenz",
|
||||
icon="key",
|
||||
endpoint="own_license.overview",
|
||||
permissions=("settings_license.view",),
|
||||
permissions=("settings_license.read",),
|
||||
),
|
||||
NavItem(
|
||||
key="backup",
|
||||
label="Sicherung",
|
||||
icon="transfer",
|
||||
endpoint="backup.overview",
|
||||
permissions=("backup.view", "backup.export", "backup.execute"),
|
||||
permissions=("backup_export.read", "backup_import.read"),
|
||||
),
|
||||
NavItem(
|
||||
key="trash",
|
||||
label="Papierkorb",
|
||||
icon="trash",
|
||||
endpoint="trash.overview",
|
||||
permissions=("trash.view",),
|
||||
permissions=("trash.read",),
|
||||
),
|
||||
NavItem(
|
||||
key="diagnostics",
|
||||
label="Diagnose",
|
||||
icon="info",
|
||||
endpoint="diagnostics.overview",
|
||||
permissions=("diagnostics.view",),
|
||||
permissions=("diagnostics.read",),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -28,58 +28,97 @@ A = Action
|
||||
CUSTOMERS = Resource(
|
||||
key="customers",
|
||||
label="Kunden",
|
||||
actions=(A.VIEW, A.CREATE, A.EDIT, A.DELETE),
|
||||
actions=(A.READ, A.CREATE, A.WRITE, A.DELETE),
|
||||
hint="Stammdaten der Kundeninstanzen",
|
||||
action_hints={A.DELETE: "Nur moeglich, solange kein Ticket am Kunden haengt."},
|
||||
action_hints={A.DELETE: "Nur möglich, solange kein Ticket am Kunden hängt."},
|
||||
)
|
||||
|
||||
TICKETS = Resource(
|
||||
key="tickets",
|
||||
label="Tickets",
|
||||
actions=(A.VIEW, A.CREATE, A.EDIT, A.DELETE),
|
||||
hint="Dauerhafte Anspruechte auf eine Lizenz",
|
||||
actions=(A.READ, A.CREATE, A.WRITE, A.DELETE),
|
||||
hint="Dauerhafte Ansprüche auf eine Lizenz",
|
||||
action_hints={
|
||||
A.EDIT: "Parameter aendern und Ticket sperren/entsperren. Wirkt erst auf die "
|
||||
"naechste Ausstellung -- bereits ausgestellte Lizenzen bleiben unveraendert.",
|
||||
A.DELETE: "Nur moeglich, wenn keine offene Lizenz mehr existiert.",
|
||||
A.WRITE: "Parameter ändern und Ticket sperren/entsperren. Wirkt erst auf die "
|
||||
"nächste Ausstellung – bereits ausgestellte Lizenzen bleiben unverändert.",
|
||||
A.DELETE: "Nur möglich, wenn keine offene Lizenz mehr existiert.",
|
||||
},
|
||||
)
|
||||
|
||||
#: Aus einer Zeile wurden fuenf. "Aendern" hiess hier **widerrufen oder neu
|
||||
#: signieren** -- zwei Eingriffe mit entgegengesetzter Wirkung unter einem
|
||||
#: Haken: der eine verlaengert einem Kunden die Lizenz, der andere nimmt sie
|
||||
#: ihm. Wer eine Laufzeit verlaengern durfte, konnte damit jede Lizenz
|
||||
#: abschalten. Genau das soll die Matrix trennen koennen.
|
||||
LICENSES = Resource(
|
||||
key="licenses",
|
||||
label="Lizenzen",
|
||||
actions=(A.VIEW, A.CREATE, A.EDIT, A.DELETE, A.EXECUTE, A.EXPORT),
|
||||
hint="Konkrete, signierte Lizenzdateien",
|
||||
actions=(A.READ, A.DELETE, A.EXPORT),
|
||||
hint="Ausgestellte Lizenzen: Laufzeit, Zustand, Datei",
|
||||
action_hints={
|
||||
A.CREATE: "Aus einem Ticket eine Lizenz ausstellen.",
|
||||
A.EDIT: "Lizenz widerrufen oder eine neue Revision signieren.",
|
||||
A.EXECUTE: "Offline-Aktivierungscodes verarbeiten.",
|
||||
A.DELETE: "Eintrag entfernen (nur ohne offene Aktivierung).",
|
||||
A.EXPORT: "Lizenzdatei herunterladen oder per E-Mail versenden.",
|
||||
},
|
||||
)
|
||||
|
||||
LICENSE_ISSUE = Resource(
|
||||
key="license_issue",
|
||||
parent="licenses",
|
||||
label="Lizenz ausstellen",
|
||||
actions=(A.READ, A.EXECUTE),
|
||||
hint="Aus einem Ticket eine neue Lizenz signieren",
|
||||
action_hints={A.EXECUTE: "Ausstellen und signieren."},
|
||||
)
|
||||
|
||||
LICENSE_RENEW = Resource(
|
||||
key="license_renew",
|
||||
parent="licenses",
|
||||
label="Lizenz erneuern",
|
||||
actions=(A.READ, A.EXECUTE),
|
||||
hint="Neue Revision einer bestehenden Lizenz signieren",
|
||||
action_hints={A.EXECUTE: "Erneuern – die alte Revision verliert ihre Gültigkeit."},
|
||||
)
|
||||
|
||||
LICENSE_REVOKE = Resource(
|
||||
key="license_revoke",
|
||||
parent="licenses",
|
||||
label="Lizenz widerrufen",
|
||||
actions=(A.READ, A.EXECUTE),
|
||||
hint="Eine ausgestellte Lizenz ungültig machen",
|
||||
action_hints={A.EXECUTE: "Widerrufen. Der Kunde verliert den Zugang."},
|
||||
)
|
||||
|
||||
LICENSE_ACTIVATION = Resource(
|
||||
key="license_activation",
|
||||
parent="licenses",
|
||||
label="Aktivierung von Hand",
|
||||
actions=(A.READ, A.EXECUTE),
|
||||
hint="Offline-Codes für Kunden ohne Internetzugang",
|
||||
action_hints={A.EXECUTE: "Code prüfen und Antwortcode erzeugen."},
|
||||
)
|
||||
|
||||
PORTAL = Resource(
|
||||
key="portal",
|
||||
label="Kundenportal",
|
||||
actions=(A.VIEW, A.EXECUTE),
|
||||
hint="Zugangslinks fuer Kunden",
|
||||
actions=(A.READ, A.EXECUTE),
|
||||
hint="Zugangslinks für Kunden",
|
||||
action_hints={A.EXECUTE: "Zugangslink erzeugen und versenden."},
|
||||
)
|
||||
|
||||
REPORTS = Resource(
|
||||
key="reports",
|
||||
label="Berichte der Sub-Lizenzserver",
|
||||
actions=(A.VIEW,),
|
||||
actions=(A.READ,),
|
||||
hint="Von untergeordneten Lizenzservern gemeldete Kunden, Tickets und Lizenzen",
|
||||
)
|
||||
|
||||
MAIL = Resource(
|
||||
key="settings_mail",
|
||||
label="E-Mail-Versand",
|
||||
actions=(A.VIEW, A.EDIT, A.EXECUTE, A.SECRETS),
|
||||
actions=(A.READ, A.WRITE, A.EXECUTE, A.SECRETS),
|
||||
hint="Microsoft Graph (App-only)",
|
||||
action_hints={
|
||||
A.EXECUTE: "Verbindungstest ausfuehren.",
|
||||
A.EXECUTE: "Verbindungstest ausführen.",
|
||||
A.SECRETS: "Client-Secret setzen.",
|
||||
},
|
||||
)
|
||||
@@ -87,8 +126,8 @@ MAIL = Resource(
|
||||
VENDOR = Resource(
|
||||
key="settings_vendor",
|
||||
label="Anbieterdaten",
|
||||
actions=(A.VIEW, A.EDIT),
|
||||
hint="Name, Kontakt, Logo und oeffentlicher Endpunkt -- reisen in jeder Lizenz mit",
|
||||
actions=(A.READ, A.WRITE),
|
||||
hint="Name, Kontakt, Logo und öffentlicher Endpunkt – reisen in jeder Lizenz mit",
|
||||
)
|
||||
|
||||
LICENSING_AREA = Area(
|
||||
@@ -96,7 +135,17 @@ LICENSING_AREA = Area(
|
||||
label="Lizenzierung",
|
||||
icon="key",
|
||||
hint="Kunden, Tickets, Lizenzen. Ohne diesen Zugang bleibt der gesamte Bereich verborgen.",
|
||||
resources=(CUSTOMERS, TICKETS, LICENSES, PORTAL, REPORTS),
|
||||
resources=(
|
||||
CUSTOMERS,
|
||||
TICKETS,
|
||||
LICENSES,
|
||||
LICENSE_ISSUE,
|
||||
LICENSE_RENEW,
|
||||
LICENSE_REVOKE,
|
||||
LICENSE_ACTIVATION,
|
||||
PORTAL,
|
||||
REPORTS,
|
||||
),
|
||||
)
|
||||
|
||||
PERMISSIONS = PermissionTree(
|
||||
@@ -108,76 +157,70 @@ PERMISSIONS = PermissionTree(
|
||||
)
|
||||
|
||||
|
||||
#: Alle Funktionsrechte ausserhalb der Verwaltung, in einer Gruppe.
|
||||
#:
|
||||
#: Seit 2.8.0 heisst das Administratorkennzeichen "Verwaltung" und nicht
|
||||
#: "alles": Geraete, Neustarts, DHCP und Freigaben kommen ueber Gruppen. Diese
|
||||
#: Vorlage ist die Gruppe, die man sich dafuer zuweist -- und die Migration
|
||||
#: gibt sie bestehenden Administratoren, damit nach dem Update nichts fehlt,
|
||||
#: was vorher ging. Entfernen kann man sie mit einem Klick.
|
||||
#:
|
||||
#: Die Liste entsteht aus dem Baum und nicht aus Tippen: eine neue Zeile in der
|
||||
#: Matrix ist sonst genau die, die hier vergessen wird.
|
||||
FUNKTIONEN_VOLLZUGRIFF = RolePreset(
|
||||
key="functions",
|
||||
name="Funktionen (Vollzugriff)",
|
||||
description=(
|
||||
"Alle Rechte ausserhalb der Verwaltung. Gedacht fuer Administratoren, "
|
||||
"die nicht nur einstellen, sondern auch bedienen."
|
||||
),
|
||||
grants=tuple(
|
||||
(resource.key, "*")
|
||||
for area in PERMISSIONS.areas
|
||||
if area.key != PermissionTree.VERWALTUNGSBEREICH
|
||||
for resource in area.resources
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
#: Wie in TESM: drei Gruppen ab Werk, nicht sechs.
|
||||
#:
|
||||
#: Auch "Vertrieb" ist hier entfallen, obwohl es die Rolle ist, die den
|
||||
#: Lizenzserver taeglich benutzt -- gerade deshalb: wer Lizenzen ausstellt,
|
||||
#: schneidet die Gruppe ohnehin auf sein Haus zu (darf Vertrieb widerrufen?
|
||||
#: Tickets loeschen? in die Protokolle sehen?). Eine mitgelieferte Antwort auf
|
||||
#: diese Frage wird entweder uebernommen, ohne sie zu pruefen, oder sie wird
|
||||
#: umgebaut. "Funktionen (Vollzugriff)" ist der ehrlichere Startpunkt.
|
||||
ROLE_PRESETS: tuple[RolePreset, ...] = (
|
||||
RolePreset(
|
||||
key="viewer",
|
||||
name="Benutzer",
|
||||
description="Standardgruppe: nur das laufende Protokoll lesen.",
|
||||
grants=(("logs_live", (A.VIEW,)),),
|
||||
grants=(("logs_live", (A.READ,)),),
|
||||
is_default=True,
|
||||
),
|
||||
RolePreset(
|
||||
key="sales",
|
||||
name="Vertrieb",
|
||||
description="Kunden und Tickets pflegen, Lizenzen ausstellen und versenden.",
|
||||
grants=(
|
||||
("customers", "*"),
|
||||
("tickets", "*"),
|
||||
("licenses", (A.VIEW, A.CREATE, A.EDIT, A.EXPORT)),
|
||||
("portal", "*"),
|
||||
("logs_live", (A.VIEW,)),
|
||||
("logs_audit", (A.VIEW,)),
|
||||
),
|
||||
),
|
||||
RolePreset(
|
||||
key="support",
|
||||
name="Support",
|
||||
description="Lesen und Offline-Aktivierungen verarbeiten.",
|
||||
grants=(
|
||||
("customers", (A.VIEW,)),
|
||||
("tickets", (A.VIEW,)),
|
||||
("licenses", (A.VIEW, A.EXECUTE)),
|
||||
("reports", (A.VIEW,)),
|
||||
("logs_live", (A.VIEW,)),
|
||||
),
|
||||
),
|
||||
RolePreset(
|
||||
key="auditor",
|
||||
name="Revision",
|
||||
description="Nur lesen -- inklusive Aenderungsprotokoll und Diagnose.",
|
||||
grants=(
|
||||
("customers", (A.VIEW,)),
|
||||
("tickets", (A.VIEW,)),
|
||||
("licenses", (A.VIEW,)),
|
||||
("reports", (A.VIEW,)),
|
||||
("users", (A.VIEW,)),
|
||||
("groups", (A.VIEW,)),
|
||||
("logs_live", (A.VIEW,)),
|
||||
("logs_history", (A.VIEW, A.EXPORT)),
|
||||
("logs_audit", (A.VIEW, A.EXPORT)),
|
||||
("diagnostics", (A.VIEW,)),
|
||||
),
|
||||
),
|
||||
RolePreset(
|
||||
key="administration",
|
||||
name="Administration",
|
||||
description="Benutzer, Gruppen und Einstellungen -- ohne Admin-Kennzeichen.",
|
||||
description="Benutzer, Gruppen und Einstellungen – ohne Admin-Kennzeichen.",
|
||||
grants=(
|
||||
("users", "*"),
|
||||
("groups", "*"),
|
||||
("settings_system", "*"),
|
||||
("settings_nav", "*"),
|
||||
("settings_license", "*"),
|
||||
("settings_directory", (A.VIEW, A.EDIT, A.EXECUTE)),
|
||||
("settings_directory", (A.READ, A.WRITE, A.EXECUTE)),
|
||||
("settings_web", "*"),
|
||||
("settings_network", "*"),
|
||||
("settings_mail", (A.VIEW, A.EDIT, A.EXECUTE)),
|
||||
("settings_mail", (A.READ, A.WRITE, A.EXECUTE)),
|
||||
("settings_vendor", "*"),
|
||||
("backup", (A.VIEW, A.EXECUTE, A.EXPORT)),
|
||||
("backup", (A.READ, A.EXECUTE, A.EXPORT)),
|
||||
("trash", "*"),
|
||||
("diagnostics", (A.VIEW,)),
|
||||
("logs_audit", (A.VIEW,)),
|
||||
("diagnostics", (A.READ,)),
|
||||
("logs_audit", (A.READ,)),
|
||||
),
|
||||
),
|
||||
FUNKTIONEN_VOLLZUGRIFF,
|
||||
)
|
||||
|
||||
__all__ = ["PERMISSIONS", "ROLE_PRESETS"]
|
||||
@@ -27,6 +27,8 @@ Aenderungen gegenueber dem Vorgaenger:
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from tesm_core.migrations import Migration
|
||||
|
||||
V1 = """
|
||||
@@ -210,7 +212,92 @@ CREATE INDEX IF NOT EXISTS idx_licenses_revision ON licenses(revision_at);
|
||||
"""
|
||||
|
||||
|
||||
def uebergang_funktionsgruppe(conn) -> None: # type: ignore[no-untyped-def]
|
||||
"""Wie in TESM: das Kennzeichen heisst ab 2.8.0 "Verwaltung".
|
||||
|
||||
Ohne diesen Schritt koennte ein bestehender Administrator nach dem Update
|
||||
keine Lizenz mehr ausstellen -- und wuerde das fuer einen Fehler halten.
|
||||
"""
|
||||
from tesm_core.rbac import service as rbac
|
||||
|
||||
from .permissions import FUNKTIONEN_VOLLZUGRIFF, PERMISSIONS
|
||||
|
||||
rbac.funktionsgruppe_fuer_administratoren(conn, PERMISSIONS, FUNKTIONEN_VOLLZUGRIFF)
|
||||
|
||||
|
||||
#: Die drei Vorlagen, die es bis 2.8.2 gab -- eingefrorene Kopie, siehe TESM.
|
||||
ABGELEGTE_VORLAGEN: tuple[tuple[str, str, tuple[tuple[str, Any], ...]], ...] = (
|
||||
(
|
||||
"sales",
|
||||
"Vertrieb",
|
||||
(
|
||||
("customers", "*"),
|
||||
("tickets", "*"),
|
||||
("licenses", ("read", "export")),
|
||||
("license_issue", "*"),
|
||||
("license_renew", "*"),
|
||||
("license_revoke", "*"),
|
||||
("portal", "*"),
|
||||
("logs_live", ("read",)),
|
||||
("logs_audit", ("read",)),
|
||||
),
|
||||
),
|
||||
(
|
||||
"support",
|
||||
"Support",
|
||||
(
|
||||
("customers", ("read",)),
|
||||
("tickets", ("read",)),
|
||||
("licenses", ("read",)),
|
||||
("license_activation", "*"),
|
||||
("reports", ("read",)),
|
||||
("logs_live", ("read",)),
|
||||
),
|
||||
),
|
||||
(
|
||||
"auditor",
|
||||
"Revision",
|
||||
(
|
||||
("customers", ("read",)),
|
||||
("tickets", ("read",)),
|
||||
("licenses", ("read",)),
|
||||
("reports", ("read",)),
|
||||
("users", ("read",)),
|
||||
("groups", ("read",)),
|
||||
("logs_live", ("read",)),
|
||||
("logs_history", ("read", "export")),
|
||||
("logs_audit", ("read", "export")),
|
||||
("diagnostics", ("read",)),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def uebergang_standardgruppen(conn) -> None: # type: ignore[no-untyped-def]
|
||||
"""Wie in TESM: unberuehrte Vorlagen in den Papierkorb, benutzte bleiben."""
|
||||
from tesm_core.rbac import service as rbac
|
||||
from tesm_core.rbac.model import Action, RolePreset
|
||||
|
||||
from .permissions import PERMISSIONS
|
||||
|
||||
vorlagen = [
|
||||
RolePreset(
|
||||
key=key,
|
||||
name=name,
|
||||
description="",
|
||||
grants=tuple(
|
||||
(ressource, a if a == "*" else tuple(Action(x) for x in a))
|
||||
for ressource, a in grants
|
||||
),
|
||||
)
|
||||
for key, name, grants in ABGELEGTE_VORLAGEN
|
||||
]
|
||||
rbac.unberuehrte_vorlagen_entfernen(conn, PERMISSIONS, vorlagen)
|
||||
|
||||
|
||||
LICENSE_MIGRATIONS: tuple[Migration, ...] = (
|
||||
Migration(version=1, name="baseline", sql=V1, allow_integrity_error=True),
|
||||
Migration(version=2, name="revision-timestamp", sql=V2),
|
||||
Migration(version=3, name="funktionsgruppe-fuer-admins", fn=uebergang_funktionsgruppe),
|
||||
Migration(version=4, name="standardgruppen-aufraeumen", fn=uebergang_standardgruppen),
|
||||
)
|
||||
@@ -132,7 +132,7 @@ def _verify(
|
||||
seen_nonce=seen,
|
||||
)
|
||||
except lic.SignatureInvalid:
|
||||
return None, _error(400, "invalid_signature", "Signatur der Anfrage ist ungueltig.")
|
||||
return None, _error(400, "invalid_signature", "Signatur der Anfrage ist ungültig.")
|
||||
except lic.ReplayDetected as exc:
|
||||
return None, _error(409, "replay", str(exc))
|
||||
except lic.ProtocolViolation as exc:
|
||||
@@ -150,7 +150,7 @@ def process_activate(
|
||||
) -> Outcome:
|
||||
row, error = _verify(conn, request, expected_action="activate")
|
||||
if error is not None or row is None:
|
||||
return error or _error(400, "bad_request", "Ungueltige Anfrage.")
|
||||
return error or _error(400, "bad_request", "Ungültige Anfrage.")
|
||||
|
||||
fingerprint = str(request["fingerprint"])
|
||||
hostname = str(request.get("hostname") or "")
|
||||
@@ -202,7 +202,7 @@ def process_activate(
|
||||
target=str(row["license_id"]),
|
||||
detail=(
|
||||
f"Fingerprint {fingerprint[:16]}..., Host {hostname or 'unbekannt'}"
|
||||
+ (f", verdraengt {len(superseded)} Lizenz(en)" if superseded else "")
|
||||
+ (f", verdrängt {len(superseded)} Lizenz(en)" if superseded else "")
|
||||
),
|
||||
severity="notice",
|
||||
)
|
||||
@@ -211,7 +211,7 @@ def process_activate(
|
||||
request,
|
||||
master_private_key=master_private_key,
|
||||
status="ok",
|
||||
detail="Aktivierung bestaetigt.",
|
||||
detail="Aktivierung bestätigt.",
|
||||
)
|
||||
|
||||
|
||||
@@ -220,7 +220,7 @@ def process_deactivate(
|
||||
) -> Outcome:
|
||||
row, error = _verify(conn, request, expected_action="deactivate")
|
||||
if error is not None or row is None:
|
||||
return error or _error(400, "bad_request", "Ungueltige Anfrage.")
|
||||
return error or _error(400, "bad_request", "Ungültige Anfrage.")
|
||||
|
||||
fingerprint = str(request["fingerprint"])
|
||||
if str(row["status"]) != "active" or str(row["fingerprint"] or "") != fingerprint:
|
||||
@@ -249,7 +249,7 @@ def process_deactivate(
|
||||
request,
|
||||
master_private_key=master_private_key,
|
||||
status="ok",
|
||||
detail="Deaktivierung bestaetigt. Die Lizenz kann auf einer anderen Maschine aktiviert werden.",
|
||||
detail="Deaktivierung bestätigt. Die Lizenz kann auf einer anderen Maschine aktiviert werden.",
|
||||
)
|
||||
|
||||
|
||||
@@ -258,7 +258,7 @@ def process_heartbeat(
|
||||
) -> Outcome:
|
||||
row, error = _verify(conn, request, expected_action="heartbeat")
|
||||
if error is not None or row is None:
|
||||
return error or _error(400, "bad_request", "Ungueltige Anfrage.")
|
||||
return error or _error(400, "bad_request", "Ungültige Anfrage.")
|
||||
|
||||
fingerprint = str(request["fingerprint"])
|
||||
hostname = str(request.get("hostname") or "")
|
||||
@@ -306,7 +306,7 @@ def process_heartbeat(
|
||||
)
|
||||
else:
|
||||
logger.warning(
|
||||
"Bericht von Lizenz %s verworfen -- Rolle ist %s, nicht license_server",
|
||||
"Bericht von Lizenz %s verworfen | Rolle ist %s, nicht license_server",
|
||||
row["license_id"],
|
||||
row["role"],
|
||||
)
|
||||
@@ -322,7 +322,7 @@ def process_heartbeat(
|
||||
request,
|
||||
master_private_key=master_private_key,
|
||||
status="ok",
|
||||
detail="Verbindung bestaetigt.",
|
||||
detail="Verbindung bestätigt.",
|
||||
license_update=update,
|
||||
)
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ def validate_email(value: str, *, required: bool) -> str:
|
||||
# sollen weiter bearbeitbar bleiben, statt ausgesperrt zu werden.
|
||||
return ""
|
||||
if not EMAIL_RE.match(text):
|
||||
raise IssuanceError(f"{text!r} ist keine gueltige E-Mail-Adresse.")
|
||||
raise IssuanceError(f"{text!r} ist keine gültige E-Mail-Adresse.")
|
||||
return text
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ def delete_customer(conn: sqlite3.Connection, customer_id: int) -> None:
|
||||
)
|
||||
if int(tickets or 0):
|
||||
raise IssuanceError(
|
||||
f"An diesem Kunden haengen noch {tickets} Ticket(s). Bitte zuerst entfernen."
|
||||
f"An diesem Kunden hängen noch {tickets} Ticket(s). Bitte zuerst entfernen."
|
||||
)
|
||||
conn.execute("DELETE FROM license_customers WHERE id=?", (customer_id,))
|
||||
|
||||
@@ -224,7 +224,7 @@ def create_ticket(
|
||||
raise IssuanceError("Unbekannter Lizenztyp.")
|
||||
if role not in lic.LICENSE_ROLES or role == "master":
|
||||
# "master" entsteht ausschliesslich lokal per Bootstrap-Skript.
|
||||
raise IssuanceError("Unzulaessige Rolle.")
|
||||
raise IssuanceError("Unzulässige Rolle.")
|
||||
|
||||
# Trial + unbefristet ist ein sinnloser Zustand: eine permanente Lizenz ohne
|
||||
# Module. Diese Regel wird an drei Stellen geprueft (hier, beim Bearbeiten
|
||||
@@ -290,7 +290,7 @@ def update_ticket(
|
||||
if license_type != str(ticket["type"]):
|
||||
changes.append(f"Typ: {ticket['type']} -> {license_type}")
|
||||
if new_modules != str(ticket["modules"]):
|
||||
changes.append("Module geaendert")
|
||||
changes.append("Module geändert")
|
||||
if int(valid_days) != int(ticket["valid_days"]):
|
||||
changes.append(f"Laufzeit: {ticket['valid_days']} -> {valid_days} Tage")
|
||||
if bool(lifetime) != bool(ticket["lifetime"]):
|
||||
@@ -428,7 +428,7 @@ def issue_from_ticket(
|
||||
role = str(ticket["role"])
|
||||
if as_trial and role != "customer":
|
||||
raise IssuanceError(
|
||||
"Eine Testlizenz gibt es nur fuer Kundeninstanzen, nicht fuer Lizenzserver."
|
||||
"Eine Testlizenz gibt es nur für Kundeninstanzen, nicht für Lizenzserver."
|
||||
)
|
||||
|
||||
if as_trial:
|
||||
@@ -452,9 +452,9 @@ def issue_from_ticket(
|
||||
# hier, an der einzigen Stelle, durch die jede Ausstellung laeuft.
|
||||
if not str(master_endpoint or "").strip():
|
||||
raise IssuanceError(
|
||||
"Es ist kein oeffentlicher Endpunkt hinterlegt (Einstellungen -> Anbieter). "
|
||||
"Ohne ihn koennte sich diese Lizenz nie online aktivieren -- der Endpunkt "
|
||||
"wird in die Lizenz signiert und laesst sich spaeter nicht nachtragen."
|
||||
"Es ist kein öffentlicher Endpunkt hinterlegt (Einstellungen -> Anbieter). "
|
||||
"Ohne ihn könnte sich diese Lizenz nie online aktivieren – der Endpunkt "
|
||||
"wird in die Lizenz signiert und lässt sich später nicht nachtragen."
|
||||
)
|
||||
|
||||
customer = get_customer(conn, int(ticket["customer_id"]))
|
||||
@@ -550,7 +550,7 @@ def delivery_bundle(conn: sqlite3.Connection, license_id: str, *, keystore: Any)
|
||||
bundle["client_key"] = keystore.decrypt(encrypted, aad=client_key_aad(license_id))
|
||||
except Exception as exc: # noqa: BLE001
|
||||
raise IssuanceError(
|
||||
"Der Client-Schluessel dieser Lizenz konnte nicht entschluesselt werden. "
|
||||
"Der Client-Schlüssel dieser Lizenz konnte nicht entschlüsselt werden. "
|
||||
"Bitte eine neue Lizenz ausstellen."
|
||||
) from exc
|
||||
return bundle
|
||||
@@ -580,7 +580,7 @@ def delete_license(conn: sqlite3.Connection, license_id: str) -> None:
|
||||
raise IssuanceError("Diese Lizenz existiert nicht.")
|
||||
if str(row["status"]) not in {"revoked", "issued"}:
|
||||
raise IssuanceError(
|
||||
"Eine aktive Lizenz kann nicht geloescht werden. Bitte zuerst widerrufen."
|
||||
"Eine aktive Lizenz kann nicht gelöscht werden. Bitte zuerst widerrufen."
|
||||
)
|
||||
conn.execute("DELETE FROM licenses WHERE license_id=?", (license_id,))
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class Report:
|
||||
|
||||
def as_text(self) -> str:
|
||||
lines = [
|
||||
f"Signaturschluessel uebernommen: {'ja' if self.key_adopted else 'nein'}"
|
||||
f"Signaturschlüssel übernommen: {'ja' if self.key_adopted else 'nein'}"
|
||||
+ (f" ({self.key_id})" if self.key_id else ""),
|
||||
f"Kunden : {self.customers}",
|
||||
f"Tickets : {self.tickets}",
|
||||
@@ -69,7 +69,7 @@ class Report:
|
||||
]
|
||||
if self.reissued:
|
||||
lines.append("")
|
||||
lines.append("Neu signiert -- diese Kunden brauchen eine neue Lizenzdatei:")
|
||||
lines.append("Neu signiert – diese Kunden brauchen eine neue Lizenzdatei:")
|
||||
lines.extend(f" * {entry}" for entry in self.reissued)
|
||||
if self.skipped:
|
||||
lines.append("")
|
||||
@@ -95,7 +95,7 @@ def open_legacy(root: Path) -> sqlite3.Connection:
|
||||
"""Oeffnet die alte Datenbank **nur lesend**."""
|
||||
path = Path(root) / "sqlite.db"
|
||||
if not path.is_file():
|
||||
raise LegacyImportError(f"Unter {path} liegt keine Datenbank der Vorgaengerfassung.")
|
||||
raise LegacyImportError(f"Unter {path} liegt keine Datenbank der Vorgängerfassung.")
|
||||
try:
|
||||
conn = sqlite3.connect(f"file:{path}?mode=ro", uri=True)
|
||||
except sqlite3.Error as exc:
|
||||
@@ -107,7 +107,7 @@ def open_legacy(root: Path) -> sqlite3.Connection:
|
||||
if missing:
|
||||
conn.close()
|
||||
raise LegacyImportError(
|
||||
f"Das sieht nicht nach einem Lizenzserver aus -- es fehlen: {', '.join(sorted(missing))}"
|
||||
f"Das sieht nicht nach einem Lizenzserver aus – es fehlen: {', '.join(sorted(missing))}"
|
||||
)
|
||||
return conn
|
||||
|
||||
@@ -123,7 +123,7 @@ def _standard_b64(wert: str, feld: str) -> str:
|
||||
"""
|
||||
roh = wert.strip()
|
||||
if not roh:
|
||||
raise LegacyImportError(f"Im alten Signaturschluessel fehlt {feld!r}.")
|
||||
raise LegacyImportError(f"Im alten Signaturschlüssel fehlt {feld!r}.")
|
||||
# Fehlende Polsterung ergaenzen -- der Vorgaenger schrieb sie mit, andere
|
||||
# Werkzeuge lassen sie weg.
|
||||
gepolstert = roh + "=" * (-len(roh) % 4)
|
||||
@@ -138,29 +138,29 @@ def _standard_b64(wert: str, feld: str) -> str:
|
||||
continue
|
||||
if len(rohbytes) != 32:
|
||||
raise LegacyImportError(
|
||||
f"{feld} im alten Signaturschluessel ist {len(rohbytes)} Byte lang, "
|
||||
f"{feld} im alten Signaturschlüssel ist {len(rohbytes)} Byte lang, "
|
||||
"erwartet werden 32 (Ed25519)."
|
||||
)
|
||||
return base64.b64encode(rohbytes).decode("ascii")
|
||||
raise LegacyImportError(f"{feld} im alten Signaturschluessel ist kein Base64.")
|
||||
raise LegacyImportError(f"{feld} im alten Signaturschlüssel ist kein Base64.")
|
||||
|
||||
|
||||
def read_legacy_key(root: Path) -> tuple[str, str]:
|
||||
"""Liest den alten Signaturschluessel. Rueckgabe: ``(privat, oeffentlich)``."""
|
||||
path = Path(root) / "master_signing_key.json"
|
||||
if not path.is_file():
|
||||
raise LegacyImportError(f"Der alte Signaturschluessel {path} fehlt.")
|
||||
raise LegacyImportError(f"Der alte Signaturschlüssel {path} fehlt.")
|
||||
try:
|
||||
data = json.loads(path.read_text(encoding="utf-8"))
|
||||
except (OSError, ValueError) as exc:
|
||||
raise LegacyImportError(f"Der alte Signaturschluessel ist unlesbar: {exc}") from exc
|
||||
raise LegacyImportError(f"Der alte Signaturschlüssel ist unlesbar: {exc}") from exc
|
||||
|
||||
# Die Vorgaengerfassung nannte die Felder "private"/"public" und kodierte
|
||||
# sie URL-sicher.
|
||||
private = str(data.get("private") or data.get("private_key") or "")
|
||||
public = str(data.get("public") or data.get("public_key") or "")
|
||||
if not private or not public:
|
||||
raise LegacyImportError("Der alte Signaturschluessel ist unvollstaendig.")
|
||||
raise LegacyImportError("Der alte Signaturschlüssel ist unvollständig.")
|
||||
private = _standard_b64(private, "private")
|
||||
public = _standard_b64(public, "public")
|
||||
# Alles, was aus der Protokollschicht kommt, wird hier zu einer Meldung im
|
||||
@@ -170,11 +170,11 @@ def read_legacy_key(root: Path) -> tuple[str, str]:
|
||||
try:
|
||||
passt = licsrv.public_from_private(private) == public
|
||||
except (ValueError, TypeError) as exc:
|
||||
raise LegacyImportError(f"Der alte Signaturschluessel ist unbrauchbar: {exc}") from exc
|
||||
raise LegacyImportError(f"Der alte Signaturschlüssel ist unbrauchbar: {exc}") from exc
|
||||
if not passt:
|
||||
raise LegacyImportError(
|
||||
"Im alten Signaturschluessel passen privater und oeffentlicher Teil nicht "
|
||||
"zueinander. Die Datei ist beschaedigt."
|
||||
"Im alten Signaturschlüssel passen privater und öffentlicher Teil nicht "
|
||||
"zueinander. Die Datei ist beschädigt."
|
||||
)
|
||||
return private, public
|
||||
|
||||
@@ -190,16 +190,16 @@ def adopt_key(private: str, public: str, target: Path) -> str:
|
||||
|
||||
if Path(target).is_file():
|
||||
raise LegacyImportError(
|
||||
f"Unter {target} liegt bereits ein Signaturschluessel. Er wird nicht "
|
||||
"ueberschrieben -- das wuerde jede damit ausgestellte Lizenz unbrauchbar "
|
||||
"machen. Fuer eine Uebernahme bitte eine frische Installation verwenden."
|
||||
f"Unter {target} liegt bereits ein Signaturschlüssel. Er wird nicht "
|
||||
"überschrieben – das würde jede damit ausgestellte Lizenz unbrauchbar "
|
||||
"machen. Für eine Übernahme bitte eine frische Installation verwenden."
|
||||
)
|
||||
payload = {
|
||||
"private_key": private,
|
||||
"public_key": public,
|
||||
"key_id": lic.key_id(public),
|
||||
"created_at": _now(),
|
||||
"origin": "Uebernommen aus der Vorgaengerfassung.",
|
||||
"origin": "Übernommen aus der Vorgängerfassung.",
|
||||
}
|
||||
write_private_file(Path(target), json.dumps(payload, indent=2, sort_keys=True) + "\n")
|
||||
return lic.key_id(public)
|
||||
@@ -309,7 +309,7 @@ def import_all(
|
||||
)
|
||||
if existing is not None:
|
||||
customer_map[int(row["id"])] = int(existing["id"])
|
||||
report.warnings.append(f"Kunde {name!r} war schon vorhanden -- nicht doppelt angelegt.")
|
||||
report.warnings.append(f"Kunde {name!r} war schon vorhanden – nicht doppelt angelegt.")
|
||||
continue
|
||||
new_id = issuance.create_customer(
|
||||
conn,
|
||||
@@ -331,7 +331,7 @@ def import_all(
|
||||
for row in legacy.execute("SELECT * FROM license_tickets ORDER BY created_at"):
|
||||
customer_id = customer_map.get(int(row["customer_id"] or 0))
|
||||
if customer_id is None:
|
||||
report.skipped.append(f"Ticket {str(row['id'])[:12]} -- Kunde nicht uebernommen")
|
||||
report.skipped.append(f"Ticket {str(row['id'])[:12]} -- Kunde nicht übernommen")
|
||||
continue
|
||||
if Database.one(conn, "SELECT id FROM license_tickets WHERE id=?", (row["id"],)):
|
||||
continue
|
||||
@@ -348,7 +348,7 @@ def import_all(
|
||||
int(row["lifetime"] or 0),
|
||||
str(row["status"] or "open"),
|
||||
str(row["role"] or "customer"),
|
||||
"Aus der Vorgaengerfassung uebernommen.",
|
||||
"Aus der Vorgängerfassung übernommen.",
|
||||
str(row["created_by"] or actor),
|
||||
str(row["created_at"] or _now()),
|
||||
_now(),
|
||||
@@ -361,7 +361,7 @@ def import_all(
|
||||
license_id = str(row["license_id"] or "")
|
||||
customer_id = customer_map.get(int(row["customer_id"] or 0))
|
||||
if not license_id or customer_id is None:
|
||||
report.skipped.append(f"Lizenz {license_id[:12] or '?'} -- Kunde nicht uebernommen")
|
||||
report.skipped.append(f"Lizenz {license_id[:12] or '?'} -- Kunde nicht übernommen")
|
||||
continue
|
||||
if Database.one(conn, "SELECT id FROM licenses WHERE license_id=?", (license_id,)):
|
||||
continue
|
||||
@@ -371,7 +371,7 @@ def import_all(
|
||||
modules = _modules(row["modules"])
|
||||
|
||||
if not reissue:
|
||||
report.skipped.append(f"{customer['name']} / {license_id[:12]} -- nur gezaehlt")
|
||||
report.skipped.append(f"{customer['name']} / {license_id[:12]} -- nur gezählt")
|
||||
report.licenses += 1
|
||||
continue
|
||||
|
||||
@@ -383,7 +383,7 @@ def import_all(
|
||||
if not lifetime and valid_days <= 0:
|
||||
report.skipped.append(
|
||||
f"{customer['name']} / {license_id[:12]} -- abgelaufen am "
|
||||
f"{str(row['expires_at'])[:10]}, nicht uebernommen"
|
||||
f"{str(row['expires_at'])[:10]}, nicht übernommen"
|
||||
)
|
||||
continue
|
||||
|
||||
@@ -444,7 +444,7 @@ def import_all(
|
||||
if report.reissued:
|
||||
report.warnings.append(
|
||||
"Die neu signierten Lizenzen sind noch nicht aktiviert: die Bindung an eine "
|
||||
"Maschine gilt nur fuer die alte Datei. Nach dem Einspielen aktiviert der "
|
||||
"Maschine gilt nur für die alte Datei. Nach dem Einspielen aktiviert der "
|
||||
"Kunde erneut."
|
||||
)
|
||||
return report
|
||||
@@ -92,7 +92,7 @@ def _secret(conn: sqlite3.Connection) -> str:
|
||||
return core().keystore.decrypt(str(value), aad=AAD_GRAPH_SECRET)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
raise MailError(
|
||||
"Das Client-Secret konnte nicht entschluesselt werden -- bitte neu eintragen."
|
||||
"Das Client-Secret konnte nicht entschlüsselt werden – bitte neu eintragen."
|
||||
) from exc
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ def fetch_token(conn: sqlite3.Connection) -> str:
|
||||
def test_connection(conn: sqlite3.Connection) -> dict[str, Any]:
|
||||
"""Holt nur ein Token -- verschickt bewusst keine echte Nachricht."""
|
||||
if not is_enabled(conn):
|
||||
return {"ok": False, "message": "Der E-Mail-Versand ist nicht vollstaendig konfiguriert."}
|
||||
return {"ok": False, "message": "Der E-Mail-Versand ist nicht vollständig konfiguriert."}
|
||||
try:
|
||||
fetch_token(conn)
|
||||
except MailError as exc:
|
||||
|
||||
@@ -48,22 +48,22 @@ class MasterKey:
|
||||
def load(path: Path) -> MasterKey:
|
||||
if not path.is_file():
|
||||
raise MasterKeyError(
|
||||
f"Der Signaturschluessel {path} fehlt. Ohne ihn kann keine Lizenz ausgestellt "
|
||||
f"Der Signaturschlüssel {path} fehlt. Ohne ihn kann keine Lizenz ausgestellt "
|
||||
"werden. Erzeugen Sie ihn mit 'tesm-license-admin init-key'."
|
||||
)
|
||||
try:
|
||||
data = json.loads(path.read_text(encoding="utf-8"))
|
||||
except (OSError, ValueError) as exc:
|
||||
raise MasterKeyError(f"Der Signaturschluessel ist unlesbar: {exc}") from exc
|
||||
raise MasterKeyError(f"Der Signaturschlüssel ist unlesbar: {exc}") from exc
|
||||
|
||||
private = str(data.get("private_key") or "")
|
||||
public = str(data.get("public_key") or "")
|
||||
if not private or not public:
|
||||
raise MasterKeyError("Der Signaturschluessel ist unvollstaendig.")
|
||||
raise MasterKeyError("Der Signaturschlüssel ist unvollständig.")
|
||||
if licsrv.public_from_private(private) != public:
|
||||
raise MasterKeyError(
|
||||
"Der oeffentliche Teil des Signaturschluessels passt nicht zum privaten. "
|
||||
"Die Datei ist beschaedigt oder wurde manipuliert."
|
||||
"Der öffentliche Teil des Signaturschlüssels passt nicht zum privaten. "
|
||||
"Die Datei ist beschädigt oder wurde manipuliert."
|
||||
)
|
||||
return MasterKey(
|
||||
private_key=private, public_key=public, created_at=str(data.get("created_at") or "")
|
||||
@@ -87,7 +87,7 @@ def ensure(path: Path) -> MasterKey:
|
||||
}
|
||||
write_private_file(path, json.dumps(payload, indent=2, sort_keys=True) + "\n")
|
||||
logger.warning(
|
||||
"Neuer Signaturschluessel erzeugt (%s). Diese Datei ist unwiederbringlich -- "
|
||||
"Neuer Signaturschlüssel erzeugt (%s). Diese Datei ist unwiederbringlich – "
|
||||
"bitte sofort gesichert ablegen: %s",
|
||||
lic.key_id(public),
|
||||
path,
|
||||
@@ -98,7 +98,7 @@ def ensure(path: Path) -> MasterKey:
|
||||
def health(path: Path) -> dict[str, object]:
|
||||
"""Zustand fuer die Diagnoseseite."""
|
||||
if not path.is_file():
|
||||
return {"present": False, "problems": ["Signaturschluessel fehlt"]}
|
||||
return {"present": False, "problems": ["Signaturschlüssel fehlt"]}
|
||||
problems = check_private_file(path)
|
||||
try:
|
||||
key = load(path)
|
||||
|
||||
@@ -40,6 +40,16 @@ class LiveLog:
|
||||
def info(self, scope: str, message: str) -> None:
|
||||
self.write("INFO", scope, message)
|
||||
|
||||
def notice(self, scope: str, message: str) -> None:
|
||||
"""Etwas ist passiert, und es ist in Ordnung -- aber es gehoert gesehen.
|
||||
|
||||
Zwischen "laeuft" und "stimmt etwas nicht" fehlte eine Stufe. Ein
|
||||
Geraet, das neu gestartet wird, ist kein Fehler; es einfach als INFO
|
||||
zwischen zweihundert Erreichbarkeitsmeldungen zu stellen heisst aber,
|
||||
dass es niemand findet.
|
||||
"""
|
||||
self.write("HINWEIS", scope, message)
|
||||
|
||||
def warning(self, scope: str, message: str) -> None:
|
||||
self.write("WARNUNG", scope, message)
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import sqlite3
|
||||
from typing import Any, Callable, Iterable
|
||||
|
||||
from tesm_core.db import Database
|
||||
from tesm_core.rbac.legacy_permissions import umgeschrieben
|
||||
from tesm_core.transfer import (
|
||||
MIN_PASSPHRASE_LENGTH,
|
||||
PREVIEW_TTL_MINUTES,
|
||||
@@ -41,11 +42,11 @@ APP_TAG = "tesm-license"
|
||||
|
||||
CATEGORIES: tuple[Category, ...] = (
|
||||
Category("customers", "Kunden", "Stammdaten der Kundeninstanzen"),
|
||||
Category("tickets", "Tickets", "Anspruechte inklusive Self-Service-Schluessel", sensitive=True),
|
||||
Category("tickets", "Tickets", "Ansprüche inklusive Self-Service-Schlüssel", sensitive=True),
|
||||
Category(
|
||||
"licenses",
|
||||
"Lizenzen",
|
||||
"Ausgestellte Lizenzen mit signiertem Dokument und verschluesseltem Client-Schluessel",
|
||||
"Ausgestellte Lizenzen mit signiertem Dokument und verschlüsseltem Client-Schlüssel",
|
||||
sensitive=True,
|
||||
),
|
||||
Category("users", "Benutzer", "Lokale Konten mit Passwort-Hash", admin_only=True),
|
||||
@@ -153,6 +154,10 @@ def apply_import(
|
||||
zusammengefuehrt; Tickets und Lizenzen ueber ihre ID, weil die zugleich
|
||||
kryptographisch relevant ist (Self-Service-Link bzw. signierte Lizenz-ID).
|
||||
"""
|
||||
#: Merkt, ob das Paket alte Rechteschluessel mitbringt -- dann stammt es
|
||||
#: von vor 2.8.0, und ein Administrator konnte dort noch alles.
|
||||
alte_fassung: set[bool] = set()
|
||||
|
||||
wanted = {key for key in categories if key in CATEGORY_BY_KEY}
|
||||
report: dict[str, dict[str, int]] = {}
|
||||
stamp = _stamp()
|
||||
@@ -332,9 +337,16 @@ def apply_import(
|
||||
group_id = int(existing["id"])
|
||||
bump("groups", "updated")
|
||||
conn.execute("DELETE FROM group_permissions WHERE group_id=?", (group_id,))
|
||||
# Wie in TESM: eine Sicherung aus 2.7.x nennt customers.view und
|
||||
# tickets.edit. Unbekannte Schluessel wirft sanitize() still weg --
|
||||
# die wiederhergestellte Gruppe waere leer, ohne Meldung.
|
||||
mitgebracht = [str(recht) for recht in entry.get("permissions", []) or []]
|
||||
neue = umgeschrieben(mitgebracht)
|
||||
if sorted(set(mitgebracht)) != neue:
|
||||
alte_fassung.add(True)
|
||||
conn.executemany(
|
||||
"INSERT OR IGNORE INTO group_permissions (group_id, permission) VALUES (?,?)",
|
||||
[(group_id, str(permission)) for permission in entry.get("permissions", [])],
|
||||
[(group_id, permission) for permission in neue],
|
||||
)
|
||||
|
||||
if "users" in wanted:
|
||||
@@ -393,6 +405,18 @@ def apply_import(
|
||||
set_setting(str(key), value)
|
||||
bump("settings", "updated")
|
||||
|
||||
if alte_fassung and "users" in wanted:
|
||||
# Wie die Migration: aus einer Sicherung von vor 2.8.0 kommen
|
||||
# Administratoren, die alles konnten. Ohne die Gruppe koennten sie
|
||||
# nach dem Einlesen keine Lizenz mehr ausstellen.
|
||||
from tesm_core.rbac import service as rbac
|
||||
|
||||
from ..permissions import FUNKTIONEN_VOLLZUGRIFF, PERMISSIONS
|
||||
|
||||
rbac.funktionsgruppe_fuer_administratoren(
|
||||
conn, PERMISSIONS, FUNKTIONEN_VOLLZUGRIFF
|
||||
)
|
||||
|
||||
return report
|
||||
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ VENDOR_SETTINGS: tuple[SettingSpec, ...] = (
|
||||
"master_endpoint",
|
||||
"",
|
||||
"str",
|
||||
"Oeffentlicher Endpunkt dieses Lizenzservers",
|
||||
hint="Basis-URL, unter der Kundeninstanzen diesen Server erreichen -- z. B. "
|
||||
"Öffentlicher Endpunkt dieses Lizenzservers",
|
||||
hint="Basis-URL, unter der Kundeninstanzen diesen Server erreichen – z. B. "
|
||||
"https://lizenz.firma.de. Wird in jede Lizenz eingebettet und fuer alle "
|
||||
"kundengerichteten Links verwendet.",
|
||||
section="vendor",
|
||||
@@ -38,8 +38,8 @@ PORTAL_SETTINGS: tuple[SettingSpec, ...] = (
|
||||
"portal_link_minutes",
|
||||
30,
|
||||
"int",
|
||||
"Gueltigkeit des Zugangslinks (Minuten)",
|
||||
hint="Der Link ist zusaetzlich nur einmal verwendbar.",
|
||||
"Gültigkeit des Zugangslinks (Minuten)",
|
||||
hint="Der Link ist zusätzlich nur einmal verwendbar.",
|
||||
section="portal",
|
||||
minimum=5,
|
||||
maximum=1440,
|
||||
@@ -48,9 +48,9 @@ PORTAL_SETTINGS: tuple[SettingSpec, ...] = (
|
||||
"portal_session_minutes",
|
||||
60,
|
||||
"int",
|
||||
"Gueltigkeit der Portalsitzung (Minuten)",
|
||||
hint="Zweites, unabhaengiges Zeitfenster: eines fuer das Anklicken des Links, "
|
||||
"eines fuer die daraus entstehende Sitzung.",
|
||||
"Gültigkeit der Portalsitzung (Minuten)",
|
||||
hint="Zweites, unabhängiges Zeitfenster: eines für das Anklicken des Links, "
|
||||
"eines für die daraus entstehende Sitzung.",
|
||||
section="portal",
|
||||
minimum=5,
|
||||
maximum=1440,
|
||||
@@ -64,7 +64,7 @@ PORTAL_SETTINGS: tuple[SettingSpec, ...] = (
|
||||
"bool",
|
||||
"Self-Service-Link je Ticket aktiv",
|
||||
hint="Erlaubt dem Kunden, seine Lizenz selbst herunterzuladen, zu widerrufen und "
|
||||
"neu auszustellen -- ohne Anmeldung, allein ueber den unratbaren Ticket-Link.",
|
||||
"neu auszustellen – ohne Anmeldung, allein über den unratbaren Ticket-Link.",
|
||||
section="portal",
|
||||
),
|
||||
)
|
||||
@@ -83,8 +83,8 @@ DEFAULT_TICKET_SETTINGS: tuple[SettingSpec, ...] = (
|
||||
"allow_customer_revoke",
|
||||
True,
|
||||
"bool",
|
||||
"Kunden duerfen ihre Lizenz selbst widerrufen",
|
||||
hint="Notwendig fuer einen Systemwechsel ohne Support-Anruf.",
|
||||
"Kunden dürfen ihre Lizenz selbst widerrufen",
|
||||
hint="Notwendig für einen Systemwechsel ohne Support-Anruf.",
|
||||
section="licensing",
|
||||
),
|
||||
)
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
{% block topbar_extra %}
|
||||
{% if current_user.has('tickets.create') %}
|
||||
<a class="btn btn--primary btn--sm" href="{{ url_for('tickets.new', kunde=customer.id) }}">
|
||||
<a class="btn btn--primary btn--sm" href="{{ url_for('tickets.new', customer=customer.id) }}">
|
||||
{{ icon('plus', size=15) }} Ticket anlegen
|
||||
</a>
|
||||
{% endif %}
|
||||
@@ -171,22 +171,22 @@
|
||||
<input type="hidden" name="{{ csrf_field_name }}" value="{{ csrf_token() }}">
|
||||
<div class="card__body stack">
|
||||
{{ field('name', 'Firmenname', value=customer.name, required=True,
|
||||
disabled=not current_user.has('customers.edit')) }}
|
||||
disabled=not current_user.has('customers.write')) }}
|
||||
{{ field('contact_email', 'E-Mail', value=customer.contact_email, type='email',
|
||||
disabled=not current_user.has('customers.edit')) }}
|
||||
disabled=not current_user.has('customers.write')) }}
|
||||
{{ field('contact_person', 'Ansprechpartner', value=customer.contact_person,
|
||||
disabled=not current_user.has('customers.edit')) }}
|
||||
disabled=not current_user.has('customers.write')) }}
|
||||
{{ field('contact_phone', 'Telefon', value=customer.contact_phone,
|
||||
disabled=not current_user.has('customers.edit')) }}
|
||||
disabled=not current_user.has('customers.write')) }}
|
||||
<div class="form-grid">
|
||||
{{ field('street', 'Strasse', value=customer.street,
|
||||
disabled=not current_user.has('customers.edit')) }}
|
||||
disabled=not current_user.has('customers.write')) }}
|
||||
{{ field('house_number', 'Nr.', value=customer.house_number,
|
||||
disabled=not current_user.has('customers.edit')) }}
|
||||
disabled=not current_user.has('customers.write')) }}
|
||||
{{ field('postal_code', 'PLZ', value=customer.postal_code,
|
||||
disabled=not current_user.has('customers.edit')) }}
|
||||
disabled=not current_user.has('customers.write')) }}
|
||||
{{ field('city', 'Ort', value=customer.city,
|
||||
disabled=not current_user.has('customers.edit')) }}
|
||||
disabled=not current_user.has('customers.write')) }}
|
||||
</div>
|
||||
{{ textarea_field('notes', 'Notizen', value=customer.notes, rows=3,
|
||||
extra_class='field--full') }}
|
||||
@@ -200,7 +200,7 @@
|
||||
{{ icon('copy', size=13) }}</button></dd>
|
||||
</dl>
|
||||
</div>
|
||||
{% if current_user.has('customers.edit') %}
|
||||
{% if current_user.has('customers.write') %}
|
||||
<div class="card__footer modal__footer--split">
|
||||
{% if current_user.has('customers.delete') %}
|
||||
<button class="btn btn--sm btn--ghost danger-text" type="submit"
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{% if current_user.has('licenses.edit') and license.status != 'revoked' %}
|
||||
{% if current_user.has('license_renew.execute') and license.status != 'revoked' %}
|
||||
<section class="card">
|
||||
<div class="card__header">
|
||||
<div class="flex-1">
|
||||
@@ -170,7 +170,7 @@
|
||||
<summary class="card__header" style="cursor:pointer">
|
||||
<div class="flex-1">
|
||||
<div class="card__title">{{ icon('file-text', size=17) }} Signiertes Dokument</div>
|
||||
<div class="card__sub">Genau so, wie es signiert wurde -- jede Änderung bricht die Signatur</div>
|
||||
<div class="card__sub">Genau so, wie es signiert wurde – jede Änderung bricht die Signatur</div>
|
||||
</div>
|
||||
{{ icon('chevron-down', size=16) }}
|
||||
</summary>
|
||||
@@ -204,17 +204,17 @@
|
||||
</section>
|
||||
{% endif %}
|
||||
|
||||
{% if current_user.has('licenses.edit') or current_user.has('licenses.delete') %}
|
||||
{% if current_user.has('license_revoke.execute') or current_user.has('licenses.delete') %}
|
||||
<section class="card">
|
||||
<div class="card__header">
|
||||
<div class="flex-1"><div class="card__title">{{ icon('alert', size=17) }} Lebenszyklus</div></div>
|
||||
</div>
|
||||
<div class="card__body stack stack--tight">
|
||||
{% if current_user.has('licenses.edit') and license.status != 'revoked' %}
|
||||
{% if current_user.has('license_revoke.execute') and license.status != 'revoked' %}
|
||||
<button class="btn btn--sm btn--danger btn--block" type="button"
|
||||
data-dialog-open="revoke-dialog">Widerrufen</button>
|
||||
<p class="fs-xs faint">
|
||||
Das Ticket bleibt offen -- eine neue Lizenz kann sofort ausgestellt werden. Genau so
|
||||
Das Ticket bleibt offen – eine neue Lizenz kann sofort ausgestellt werden. Genau so
|
||||
läuft ein Systemwechsel.
|
||||
</p>
|
||||
{% endif %}
|
||||
@@ -239,7 +239,7 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block dialogs %}
|
||||
{% if current_user.has('licenses.edit') and license.status != 'revoked' %}
|
||||
{% if current_user.has('license_revoke.execute') and license.status != 'revoked' %}
|
||||
{% call modal('revoke-dialog', 'Lizenz widerrufen', license.customer_name, 'narrow') %}
|
||||
<form method="post" action="{{ url_for('licenses.revoke', license_id=license.license_id) }}">
|
||||
<input type="hidden" name="{{ csrf_field_name }}" value="{{ csrf_token() }}">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
{% block topbar_extra %}
|
||||
{{ search_box('licenses-table', 'Kunde, Lizenz-ID, Host ...') }}
|
||||
{% if current_user.has('licenses.execute') %}
|
||||
{% if current_user.has('license_activation.execute') %}
|
||||
<a class="btn btn--sm" href="{{ url_for('licenses.manual_code') }}">
|
||||
{{ icon('transfer', size=15) }} Offline-Code
|
||||
</a>
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
{% if current_user.has('settings_license.edit') %}
|
||||
{% if current_user.has('settings_license.write') %}
|
||||
<div class="card__footer">
|
||||
{% if not state.activated %}
|
||||
<form method="post" action="{{ url_for('own_license.activate') }}" data-no-guard>
|
||||
@@ -151,7 +151,7 @@
|
||||
</section>
|
||||
{% endif %}
|
||||
|
||||
{% if current_user.has('settings_license.edit') %}
|
||||
{% if current_user.has('settings_license.write') %}
|
||||
<section class="card">
|
||||
<div class="card__header">
|
||||
<div class="flex-1">
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
</form>
|
||||
|
||||
<p class="auth-footnote">
|
||||
Aus Datenschutzgründen bekommen Sie immer dieselbe Rückmeldung -- unabhängig davon, ob die
|
||||
Aus Datenschutzgründen bekommen Sie immer dieselbe Rückmeldung – unabhängig davon, ob die
|
||||
Adresse bei uns bekannt ist.
|
||||
</p>
|
||||
{% endblock %}
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
{% if response_code %}
|
||||
<div class="field">
|
||||
<span class="field__label">Antwortcode -- in TESM eintragen</span>
|
||||
<span class="field__label">Antwortcode – in TESM eintragen</span>
|
||||
<pre class="log-view" id="offline-answer" style="max-height:16dvh">{{ response_code }}</pre>
|
||||
<div class="row row--end mt-2">
|
||||
<button class="btn btn--sm" type="button" data-copy="#offline-answer">
|
||||
@@ -23,7 +23,7 @@
|
||||
</button>
|
||||
</div>
|
||||
<p class="fs-sm muted mt-2">
|
||||
Tragen Sie ihn in TESM unter Verwaltung -- Lizenz bei
|
||||
Tragen Sie ihn in TESM unter Verwaltung → Lizenz bei
|
||||
„Antwortcode des Lizenzservers“ ein.
|
||||
{% if summary.hostname %}
|
||||
Die Anfrage kam von <span class="mono">{{ summary.hostname }}</span>.
|
||||
|
||||
@@ -33,16 +33,16 @@ bewusst keine echte Nachricht.', 'info') }}
|
||||
<input type="hidden" name="{{ csrf_field_name }}" value="{{ csrf_token() }}">
|
||||
<div class="card__body stack">
|
||||
{{ checkbox('graph_enabled', 'E-Mail-Versand aktiv', checked=values.graph_enabled,
|
||||
disabled=not current_user.has('settings_mail.edit')) }}
|
||||
disabled=not current_user.has('settings_mail.write')) }}
|
||||
<div class="form-grid">
|
||||
{{ field('graph_tenant_id', 'Verzeichnis-ID (Tenant)', value=values.graph_tenant_id,
|
||||
disabled=not current_user.has('settings_mail.edit')) }}
|
||||
disabled=not current_user.has('settings_mail.write')) }}
|
||||
{{ field('graph_client_id', 'Anwendungs-ID (Client)', value=values.graph_client_id,
|
||||
disabled=not current_user.has('settings_mail.edit')) }}
|
||||
disabled=not current_user.has('settings_mail.write')) }}
|
||||
{{ field('graph_sender', 'Absender-Postfach', value=values.graph_sender, type='email',
|
||||
disabled=not current_user.has('settings_mail.edit')) }}
|
||||
disabled=not current_user.has('settings_mail.write')) }}
|
||||
{{ field('graph_reply_to', 'Antwortadresse', value=values.graph_reply_to, type='email',
|
||||
disabled=not current_user.has('settings_mail.edit')) }}
|
||||
disabled=not current_user.has('settings_mail.write')) }}
|
||||
</div>
|
||||
<fieldset class="fieldset">
|
||||
<legend>Client-Secret {% if has_secret %}{{ pill('gesetzt', 'online') }}{% else %}{{ pill('fehlt', 'warning') }}{% endif %}</legend>
|
||||
@@ -55,7 +55,7 @@ bewusst keine echte Nachricht.', 'info') }}
|
||||
{% endif %}
|
||||
</fieldset>
|
||||
</div>
|
||||
{% if current_user.has('settings_mail.edit') %}
|
||||
{% if current_user.has('settings_mail.write') %}
|
||||
<div class="card__footer"><button class="btn btn--primary" type="submit">Speichern</button></div>
|
||||
{% endif %}
|
||||
</form>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{% extends "tesm_core/base.html" %}
|
||||
{% from "tesm_core/macros.html" import field, select_field, checkbox, alert %}
|
||||
{% from "tesm_core/macros.html" import field, select_field, checkbox, alert, nav_order_card %}
|
||||
|
||||
{% block page_title %}Systemeinstellungen{% endblock %}
|
||||
{% block page_sub %}Portal, Self-Service, Protokolle, Host{% endblock %}
|
||||
@@ -60,9 +60,6 @@
|
||||
selected=values.log_rotate_interval) }}
|
||||
{{ field('log_rotate_keep', 'Aufbewahrte Rotationen', value=values.log_rotate_keep,
|
||||
type='number') }}
|
||||
{{ field('session_idle_minutes', 'Automatische Abmeldung (Minuten)',
|
||||
value=values.session_idle_minutes, type='number',
|
||||
hint_text=specs['session_idle_minutes'].hint) }}
|
||||
{{ field('trash_retention_days', 'Papierkorb-Aufbewahrung (Tage)',
|
||||
value=values.trash_retention_days, type='number') }}
|
||||
</div>
|
||||
@@ -73,6 +70,34 @@
|
||||
</div>
|
||||
|
||||
<div class="stack">
|
||||
{# Eigene Karte: die Abmeldung stand zwischen Protokollrotation und
|
||||
Papierkorb -- drei Dinge ohne Zusammenhang. Wer die Sitzungsdauer sucht,
|
||||
sucht sie nicht unter "Protokolle". #}
|
||||
<section class="card">
|
||||
<div class="card__header">
|
||||
<div class="flex-1">
|
||||
<div class="card__title">{{ icon('clock', size=17) }} Sitzungen</div>
|
||||
<div class="card__sub">Wie lange eine Anmeldung gilt</div>
|
||||
</div>
|
||||
</div>
|
||||
<form method="post" action="{{ url_for('settings.system_save') }}">
|
||||
<input type="hidden" name="{{ csrf_field_name }}" value="{{ csrf_token() }}">
|
||||
<div class="card__body">
|
||||
<div class="form-grid">
|
||||
{{ field('session_idle_minutes', 'Automatische Abmeldung nach Leerlauf (Minuten)',
|
||||
value=values.session_idle_minutes, type='number',
|
||||
attrs='min="5" max="1440" step="1"',
|
||||
hint_text=specs['session_idle_minutes'].hint) }}
|
||||
{{ field('session_absolute_hours', 'Längstmögliche Sitzungsdauer (Stunden)',
|
||||
value=values.session_absolute_hours, type='number',
|
||||
attrs='min="1" max="168" step="1"',
|
||||
hint_text=specs['session_absolute_hours'].hint) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="card__footer"><button class="btn btn--primary" type="submit">Speichern</button></div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<div class="card__header">
|
||||
<div class="flex-1"><div class="card__title">{{ icon('server', size=17) }} Host</div></div>
|
||||
@@ -104,33 +129,9 @@
|
||||
</section>
|
||||
|
||||
{% if current_user.is_admin %}
|
||||
<section class="card">
|
||||
<div class="card__header">
|
||||
<div class="flex-1">
|
||||
<div class="card__title">{{ icon('sliders', size=17) }} Navigationsreihenfolge</div>
|
||||
<div class="card__sub">Gilt für alle Benutzer</div>
|
||||
</div>
|
||||
</div>
|
||||
<form method="post" action="{{ url_for('admin.nav_order') }}">
|
||||
<input type="hidden" name="{{ csrf_field_name }}" value="{{ csrf_token() }}">
|
||||
<div class="card__body">
|
||||
<ol class="stack stack--tight">
|
||||
{% for key in nav_order %}
|
||||
{% set item = nav_items | selectattr('key', 'equalto', key) | list | first %}
|
||||
{% if item %}
|
||||
<li class="row row--tight">
|
||||
<input type="hidden" name="order" value="{{ item.key }}">
|
||||
<span class="flex-1">{{ icon(item.icon, size=15) }} {{ item.label }}</span>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ol>
|
||||
</div>
|
||||
<div class="card__footer">
|
||||
<button class="btn btn--sm" type="submit">Reihenfolge speichern</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
{{ nav_order_card(nav_baum, nav_order, nav_child_order,
|
||||
url_for('admin.nav_order'), csrf_field_name, csrf_token(),
|
||||
sub='Gilt für alle Benutzer') }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -19,16 +19,16 @@ welche Basis-URL in kundengerichteten Links steht.', 'info') }}
|
||||
<div class="card__body stack">
|
||||
<div class="form-grid">
|
||||
{{ field('vendor_name', 'Anbietername', value=values.vendor_name,
|
||||
disabled=not current_user.has('settings_vendor.edit')) }}
|
||||
disabled=not current_user.has('settings_vendor.write')) }}
|
||||
{{ field('vendor_email', 'E-Mail', value=values.vendor_email, type='email',
|
||||
disabled=not current_user.has('settings_vendor.edit')) }}
|
||||
disabled=not current_user.has('settings_vendor.write')) }}
|
||||
{{ field('vendor_phone', 'Telefon', value=values.vendor_phone,
|
||||
disabled=not current_user.has('settings_vendor.edit')) }}
|
||||
disabled=not current_user.has('settings_vendor.write')) }}
|
||||
</div>
|
||||
{{ textarea_field('vendor_address', 'Adresse', value=values.vendor_address, rows=3) }}
|
||||
{{ field('master_endpoint', 'Öffentlicher Endpunkt', value=values.master_endpoint,
|
||||
placeholder='https://lizenz.firma.de',
|
||||
disabled=not current_user.has('settings_vendor.edit'),
|
||||
disabled=not current_user.has('settings_vendor.write'),
|
||||
hint_text='Basis-URL, unter der Kundeninstanzen diesen Server erreichen. Wird in
|
||||
jede Lizenz eingebettet und für alle kundengerichteten Links verwendet -- statt
|
||||
des Host-Headers der aktüllen Anfrage, der bei internen Aufrufen falsch wäre.',
|
||||
@@ -43,14 +43,14 @@ welche Basis-URL in kundengerichteten Links steht.', 'info') }}
|
||||
<p class="faint fs-sm">Kein Logo hinterlegt.</p>
|
||||
{% endif %}
|
||||
<input class="input" type="file" name="vendor_logo" accept="image/png,image/jpeg,image/svg+xml"
|
||||
{% if not current_user.has('settings_vendor.edit') %}disabled{% endif %}>
|
||||
{% if not current_user.has('settings_vendor.write') %}disabled{% endif %}>
|
||||
<span class="field__hint">
|
||||
Ein zu grosses Logo wird abgelehnt, die übrigen Angaben werden trotzdem gespeichert.
|
||||
Ein zu großes Logo wird abgelehnt, die übrigen Angaben werden trotzdem gespeichert.
|
||||
</span>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{% if current_user.has('settings_vendor.edit') %}
|
||||
{% if current_user.has('settings_vendor.write') %}
|
||||
<div class="card__footer modal__footer--split">
|
||||
{% if values.vendor_logo_base64 %}
|
||||
<button class="btn btn--sm btn--ghost" type="submit"
|
||||
@@ -75,7 +75,7 @@ welche Basis-URL in kundengerichteten Links steht.', 'info') }}
|
||||
<div class="divider"></div>
|
||||
<p class="fs-sm muted">
|
||||
Die Angaben werden zum Zeitpunkt der Ausstellung in die Lizenz kopiert und signiert. Eine
|
||||
Änderung hier wirkt auf neue Lizenzen -- bestehende behalten ihren Stand, bis eine neue
|
||||
Änderung hier wirkt auf neue Lizenzen – bestehende behalten ihren Stand, bis eine neue
|
||||
Revision signiert wird.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<div class="card__title">{{ icon('shield', size=17) }} Lizenz ausstellen</div>
|
||||
<div class="card__sub">
|
||||
{% if has_open_license %}
|
||||
Es existiert bereits eine offene Lizenz -- widerrufen Sie sie zuerst.
|
||||
Es existiert bereits eine offene Lizenz – widerrufen Sie sie zuerst.
|
||||
{% else %}
|
||||
Erzeugt eine signierte Lizenzdatei mit den Werten dieses Tickets.
|
||||
{% endif %}
|
||||
@@ -41,7 +41,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="card__body row row--tight">
|
||||
{% if current_user.has('licenses.create') %}
|
||||
{% if current_user.has('license_issue.execute') %}
|
||||
<form method="post" action="{{ url_for('licenses.issue', ticket_id=ticket.id) }}"
|
||||
data-no-guard>
|
||||
<input type="hidden" name="{{ csrf_field_name }}" value="{{ csrf_token() }}">
|
||||
@@ -128,7 +128,7 @@
|
||||
</div>
|
||||
<p class="fs-xs faint">
|
||||
Damit kann der Kunde seine Lizenz herunterladen, bei einem Systemwechsel freigeben und
|
||||
neu ausstellen. Der Link enthält 192 Bit Zufall und ist nicht ratbar -- behandeln Sie
|
||||
neu ausstellen. Der Link enthält 192 Bit Zufall und ist nicht ratbar – behandeln Sie
|
||||
ihn wie ein Passwort.
|
||||
</p>
|
||||
<div class="divider"></div>
|
||||
@@ -163,7 +163,7 @@
|
||||
<label class="field">
|
||||
<span class="field__label">Lizenztyp</span>
|
||||
<select class="select" name="type" id="ticket-type"
|
||||
{% if not current_user.has('tickets.edit') %}disabled{% endif %}>
|
||||
{% if not current_user.has('tickets.write') %}disabled{% endif %}>
|
||||
{% for value in types %}
|
||||
<option value="{{ value }}" {% if value == ticket.type %}selected{% endif %}>
|
||||
{{ type_labels.get(value, value) }}
|
||||
@@ -178,15 +178,15 @@
|
||||
{% for module in modules %}
|
||||
{{ checkbox('modules', module_labels[module], value=module,
|
||||
checked=module in ticket_modules,
|
||||
disabled=not current_user.has('tickets.edit')) }}
|
||||
disabled=not current_user.has('tickets.write')) }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</fieldset>
|
||||
{% endif %}
|
||||
{{ field('valid_days', 'Laufzeit (Tage)', value=ticket.valid_days, type='number',
|
||||
disabled=not current_user.has('tickets.edit')) }}
|
||||
disabled=not current_user.has('tickets.write')) }}
|
||||
{{ checkbox('lifetime', 'Unbefristet', checked=ticket.lifetime,
|
||||
disabled=not current_user.has('tickets.edit')) }}
|
||||
disabled=not current_user.has('tickets.write')) }}
|
||||
{{ textarea_field('notes', 'Interne Notiz', value=ticket.notes, rows=2) }}
|
||||
<div class="divider"></div>
|
||||
<dl class="kv fs-xs">
|
||||
@@ -195,7 +195,7 @@
|
||||
<dt>Angelegt</dt><dd>{{ ticket.created_at | dt }} von {{ ticket.created_by or '-' }}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
{% if current_user.has('tickets.edit') %}
|
||||
{% if current_user.has('tickets.write') %}
|
||||
<div class="card__footer">
|
||||
<button class="btn btn--primary" type="submit">Speichern</button>
|
||||
</div>
|
||||
@@ -203,13 +203,13 @@
|
||||
</form>
|
||||
</section>
|
||||
|
||||
{% if current_user.has('tickets.edit') or current_user.has('tickets.delete') %}
|
||||
{% if current_user.has('tickets.write') or current_user.has('tickets.delete') %}
|
||||
<section class="card">
|
||||
<div class="card__header">
|
||||
<div class="flex-1"><div class="card__title">{{ icon('lock', size=17) }} Sperre und Löschung</div></div>
|
||||
</div>
|
||||
<div class="card__body stack stack--tight">
|
||||
{% if current_user.has('tickets.edit') %}
|
||||
{% if current_user.has('tickets.write') %}
|
||||
<form method="post" action="{{ url_for('tickets.toggle_block', ticket_id=ticket.id) }}"
|
||||
data-no-guard>
|
||||
<input type="hidden" name="{{ csrf_field_name }}" value="{{ csrf_token() }}">
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
{% endfor %}
|
||||
</select>
|
||||
<span class="field__hint">
|
||||
Der Kunde ist nach dem Anlegen unveränderlich -- der Self-Service-Link ist an ihn
|
||||
Der Kunde ist nach dem Anlegen unveränderlich – der Self-Service-Link ist an ihn
|
||||
gebunden.
|
||||
</span>
|
||||
</label>
|
||||
@@ -77,7 +77,7 @@
|
||||
<div class="flex-1">
|
||||
<div class="card__title">{{ icon('share', size=17) }} Lizenzserver-Lizenz</div>
|
||||
<div class="card__sub">
|
||||
Erzeugt eine neue Vertrauensgrenze -- der Empfänger verwaltet danach eigene Kunden
|
||||
Erzeugt eine neue Vertrauensgrenze – der Empfänger verwaltet danach eigene Kunden
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -103,7 +103,7 @@
|
||||
<div class="card__body">
|
||||
<ol class="stack stack--tight fs-sm muted" style="list-style:decimal;padding-left:1.2em">
|
||||
<li>Ticket anlegen (dieser Schritt).</li>
|
||||
<li>Auf der Ticketseite eine Lizenz ausstellen -- optional als 30-Tage-Testlizenz mit
|
||||
<li>Auf der Ticketseite eine Lizenz ausstellen – optional als 30-Tage-Testlizenz mit
|
||||
allen Modulen.</li>
|
||||
<li>Lizenzdatei herunterladen oder per E-Mail versenden.</li>
|
||||
<li>Der Kunde spielt sie ein und aktiviert sie; die Aktivierung bindet sie an seine
|
||||
@@ -112,7 +112,7 @@
|
||||
<div class="divider"></div>
|
||||
<p class="fs-sm muted">
|
||||
Der Self-Service-Link des Tickets erlaubt dem Kunden, seine Lizenz selbst
|
||||
herunterzuladen und bei einem Systemwechsel freizugeben -- ohne Support-Anruf.
|
||||
herunterzuladen und bei einem Systemwechsel freizugeben – ohne Support-Anruf.
|
||||
</p>
|
||||
</div>
|
||||
<div class="card__footer">
|
||||
|
||||
+89
-3
@@ -39,6 +39,7 @@ HTTPS=0
|
||||
HTTPS_PORT=""
|
||||
DOMAIN=""
|
||||
ACME_EMAIL=""
|
||||
ERZWINGEN=0
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
@@ -49,6 +50,39 @@ warn() { printf '%s !!%s %s\n' "$COLOR_WARN" "$COLOR_OFF" "$*"; }
|
||||
fail() { printf '%s !!%s %s\n' "$COLOR_ERR" "$COLOR_OFF" "$*" >&2; exit 1; }
|
||||
info() { printf ' %s\n' "$*"; }
|
||||
|
||||
# -- Welche Fassung liegt hier, und welche laeuft schon? ---------------------
|
||||
#
|
||||
# Ein Installationslauf auf dieselbe Fassung macht nichts besser: er baut die
|
||||
# Python-Umgebung neu, kopiert dieselben Dateien, laedt nginx neu und startet
|
||||
# den Dienst -- mit der einzigen Wirkung, dass die Anwendung ein paar Sekunden
|
||||
# weg ist. Wer "update.sh" in einen Zeitplan haengt, bekaeme das taeglich.
|
||||
#
|
||||
# Verglichen wird die Anwendung **und** der Kern: die beiden Nummern laufen
|
||||
# absichtlich auseinander (siehe pyproject.toml), und eine Auslieferung kann
|
||||
# denselben Anwendungsstand mit neuem Kern enthalten.
|
||||
|
||||
#: Die Nummer aus einer pyproject.toml. Die erste Zeile "version = ..." gilt --
|
||||
#: weitere Vorkommen stehen in Abhaengigkeiten und gehen uns nichts an.
|
||||
paket_version() {
|
||||
sed -n 's/^version = "\([^"]*\)"/\1/p' "$1" 2>/dev/null | head -1
|
||||
}
|
||||
|
||||
#: Was in dieser Installation laeuft: "<anwendung> <kern>", sonst leer.
|
||||
laufende_version() {
|
||||
local wurzel="$1" modul="$2"
|
||||
[[ -x "$wurzel/venv/bin/python" ]] || return 0
|
||||
"$wurzel/venv/bin/python" -c \
|
||||
"import $modul, tesm_core; print($modul.__version__, tesm_core.__version__)" \
|
||||
2>/dev/null || true
|
||||
}
|
||||
|
||||
#: Ist das, was hier liegt, schon installiert? Eine eigene Funktion, weil genau
|
||||
#: diese Frage sich pruefen lassen muss -- ohne einen Server aufzusetzen.
|
||||
gleiche_version() {
|
||||
local laeuft="$1" liegt="$2"
|
||||
[[ -n "$laeuft" && "$laeuft" == "$liegt" ]]
|
||||
}
|
||||
|
||||
#: Merker fuer die EXIT-Falle. Zurueckgerollt wird nur, was auch gesichert ist.
|
||||
SICHERUNG_STEHT=0
|
||||
INSTALL_FERTIG=0
|
||||
@@ -129,6 +163,7 @@ Verwendung: install.sh --app <tesm|tesm-license> [Optionen]
|
||||
--acme-email <a> Kontaktadresse fuer Let's Encrypt.
|
||||
--skip-packages Keine Systempakete installieren
|
||||
--yes Rueckfragen ueberspringen
|
||||
--force Auch dann einrichten, wenn dieselbe Fassung schon laeuft
|
||||
USAGE
|
||||
}
|
||||
|
||||
@@ -144,6 +179,7 @@ while [[ $# -gt 0 ]]; do
|
||||
--acme-email) ACME_EMAIL="${2:?}"; shift 2 ;;
|
||||
--skip-packages) SKIP_PACKAGES=1; shift ;;
|
||||
--yes|-y) ASSUME_YES=1; shift ;;
|
||||
--force) ERZWINGEN=1; shift ;;
|
||||
-h|--help) usage; exit 0 ;;
|
||||
*) fail "unbekannte Option: $1" ;;
|
||||
esac
|
||||
@@ -168,6 +204,8 @@ LOG_DIR="/var/log/$NAME"
|
||||
SERVICE_USER="$APP"
|
||||
UNIT="$NAME.service"
|
||||
MONITOR_UNIT="$NAME-monitor.service"
|
||||
CLEANUP_UNIT="$NAME-cleanup.service"
|
||||
CLEANUP_TIMER="$NAME-cleanup.timer"
|
||||
NGINX_SITE="/etc/nginx/sites-available/$NAME"
|
||||
ENV_PREFIX="TESM_"
|
||||
[[ "$APP" == "tesm-license" ]] && ENV_PREFIX="TESM_LICENSE_"
|
||||
@@ -259,6 +297,23 @@ FAILED_DIR="/srv/$NAME-failed-$TIMESTAMP"
|
||||
IS_UPDATE=0
|
||||
[[ -f "$ROOT/data/app.db" ]] && IS_UPDATE=1
|
||||
|
||||
# Laeuft hier schon genau das, was hier liegt? Dann ist Schluss, bevor
|
||||
# irgendetwas angefasst wird -- und zwar mit Ausstiegscode 0: es ist nichts
|
||||
# schiefgegangen, es war nur nichts zu tun.
|
||||
MODUL="tesm"
|
||||
[[ "$APP" == "tesm-license" ]] && MODUL="tesm_license"
|
||||
LIEGT="$(paket_version "$REPO_DIR/apps/$APP/pyproject.toml") $(
|
||||
paket_version "$REPO_DIR/packages/tesm-core/pyproject.toml")"
|
||||
LAEUFT="$(laufende_version "$ROOT" "$MODUL")"
|
||||
if [[ $IS_UPDATE -eq 1 && $ERZWINGEN -eq 0 ]] && gleiche_version "$LAEUFT" "$LIEGT"; then
|
||||
step "Nichts zu tun"
|
||||
info "$APP ${LIEGT%% *} (tesm-core ${LIEGT##* }) laeuft hier bereits."
|
||||
info "Ein zweiter Durchlauf wuerde nur die Umgebung neu bauen und den"
|
||||
info "Dienst neu starten -- ohne dass sich etwas aendert."
|
||||
info "Trotzdem neu einrichten: --force"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
step "TESM-Installation"
|
||||
info "Anwendung : $APP${INSTANCE:+ (Instanz $INSTANCE)}"
|
||||
info "Ziel : $ROOT"
|
||||
@@ -276,6 +331,7 @@ else
|
||||
info "nginx : Port $HTTP_PORT (nur HTTP)"
|
||||
fi
|
||||
info "Modus : $([[ $IS_UPDATE -eq 1 ]] && echo Aktualisierung || echo Neuinstallation)"
|
||||
info "Fassung : ${LIEGT%% *} (tesm-core ${LIEGT##* })${LAEUFT:+, bisher ${LAEUFT%% *}}"
|
||||
|
||||
if [[ $ASSUME_YES -eq 0 ]]; then
|
||||
read -r -p "Fortfahren? [j/N] " answer
|
||||
@@ -362,9 +418,32 @@ info "Dateien abgeglichen (Instanzdaten unter data/ bleiben unangetastet)"
|
||||
|
||||
# -- venv --------------------------------------------------------------------
|
||||
step "Python-Umgebung"
|
||||
if [[ ! -x "$ROOT/venv/bin/python3" ]]; then
|
||||
# Ein venv haengt an der **Minor-Fassung**, mit der er gebaut wurde: die Pakete
|
||||
# liegen unter lib/python3.X. Wechselt die Systemfassung -- ein Release-Upgrade
|
||||
# von Ubuntu bringt genau das, 24.04 hat 3.12 und 26.04 hat 3.14 --, dann ist
|
||||
# venv/bin/python3 weiter ausfuehrbar: der Verweis zeigt auf /usr/bin/python3,
|
||||
# also auf den **neuen** Interpreter. Der venv sieht heil aus und ist es nicht.
|
||||
# Er findet danach kein einziges Paket mehr, nicht einmal pip.
|
||||
#
|
||||
# Gemessen auf dem Testserver, mit verschobenem lib-Verzeichnis:
|
||||
# [[ -x venv/bin/python3 ]] -> wahr
|
||||
# venv/bin/python3 -m pip --version -> "No module named pip"
|
||||
#
|
||||
# Die alte Pruefung fragte nur nach der Ausfuehrbarkeit. Sie haette den toten
|
||||
# venv behalten und waere eine Zeile spaeter an "python3 -m pip" gescheitert --
|
||||
# mitten in einer Aktualisierung, auf einem Server, dessen Dienste ohnehin
|
||||
# schon stehen. Gefragt wird deshalb, was gebraucht wird: laesst sich in
|
||||
# diesem venv pip benutzen?
|
||||
venv_traegt() {
|
||||
[[ -x "$ROOT/venv/bin/python3" ]] || return 1
|
||||
"$ROOT/venv/bin/python3" -c "import pip" >/dev/null 2>&1
|
||||
}
|
||||
if ! venv_traegt; then
|
||||
# Ohne --clear: ein erneutes "venv" ergaenzt das fehlende lib-Verzeichnis und
|
||||
# holt pip zurueck; die Abhaengigkeiten kommen gleich darunter ohnehin neu.
|
||||
# Auch das ist gemessen und nicht angenommen.
|
||||
python3 -m venv "$ROOT/venv"
|
||||
info "venv erzeugt"
|
||||
info "Python-Umgebung aufgebaut ($(python3 -V 2>&1))"
|
||||
fi
|
||||
# Immer ueber "python3 -m pip" -- der pip-Shim im venv baeckt einen absoluten
|
||||
# Pfad in seinen Shebang, der nach einer Umbenennung des Verzeichnisses bricht.
|
||||
@@ -539,6 +618,11 @@ render_unit "$ROOT/deploy/systemd/$APP.service" "/etc/systemd/system/$UNIT"
|
||||
if [[ "$APP" == "tesm" ]]; then
|
||||
render_unit "$ROOT/deploy/systemd/tesm-monitor.service" "/etc/systemd/system/$MONITOR_UNIT"
|
||||
fi
|
||||
# Aufraeumen lief bisher nur von Hand -- also praktisch nie. Auf einer
|
||||
# laufenden Installation lagen deshalb hunderte abgelaufene Sitzungszeilen in
|
||||
# der Datenbank, und das Aenderungsprotokoll waere nie archiviert worden.
|
||||
render_unit "$ROOT/deploy/systemd/$APP-cleanup.service" "/etc/systemd/system/$CLEANUP_UNIT"
|
||||
render_unit "$ROOT/deploy/systemd/$APP-cleanup.timer" "/etc/systemd/system/$CLEANUP_TIMER"
|
||||
[[ $UNITS_CHANGED -eq 1 ]] && systemctl daemon-reload && info "Units neu geladen" \
|
||||
|| info "Units unveraendert"
|
||||
|
||||
@@ -611,6 +695,8 @@ systemctl enable --now "$UNIT" >/dev/null
|
||||
if [[ "$APP" == "tesm" ]]; then
|
||||
systemctl enable --now "$MONITOR_UNIT" >/dev/null
|
||||
fi
|
||||
# Der Timer, nicht der Dienst: der Dienst laeuft einmal und ist fertig.
|
||||
systemctl enable --now "$CLEANUP_TIMER" >/dev/null 2>&1 && info "Aufraeumen: taeglich 03:30" || info "Aufraeum-Timer nicht aktiviert -- 'systemctl status $CLEANUP_TIMER' zeigt warum"
|
||||
|
||||
# -- Health-Check und Rollback ----------------------------------------------
|
||||
step "Gesundheitspruefung"
|
||||
@@ -620,7 +706,7 @@ for attempt in $(seq 1 20); do
|
||||
# pruefen ging schon einmal schief -- auf einem gemeinsamen Port antwortete
|
||||
# eine andere Instanz, und ein toter Dienst galt als gesund.
|
||||
if systemctl is-active --quiet "$UNIT" &&
|
||||
curl -fsS --max-time 3 "http://127.0.0.1:$PORT/gesundheit" >/dev/null 2>&1; then
|
||||
curl -fsS --max-time 3 "http://127.0.0.1:$PORT/health" >/dev/null 2>&1; then
|
||||
HEALTHY=1
|
||||
info "Antwort nach ${attempt}x"
|
||||
break
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
[Unit]
|
||||
Description=TESM -- Aufraeumen: Sitzungen, Ratenereignisse, Protokollarchiv
|
||||
After=tesm.service
|
||||
# Ohne die laufende Anwendung ist nichts kaputt -- der Befehl arbeitet direkt
|
||||
# auf der Datenbank. "After" sorgt nur fuer eine sinnvolle Reihenfolge beim
|
||||
# Hochfahren.
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
User=tesm
|
||||
Group=tesm
|
||||
WorkingDirectory=/srv/tesm
|
||||
Environment=TESM_BASE_DIR=/srv/tesm
|
||||
Environment=TESM_DATA_DIR=/srv/tesm/data
|
||||
Environment=TESM_LOG_DIR=/var/log/tesm
|
||||
Environment=PYTHONUNBUFFERED=1
|
||||
ExecStart=/srv/tesm/venv/bin/tesm-admin housekeeping
|
||||
|
||||
# Hier darf voll gehaertet werden: dieser Aufruf fasst nur die Datenbank und
|
||||
# das Protokollverzeichnis an, keine Systemdateien und keinen Helfer per sudo.
|
||||
NoNewPrivileges=yes
|
||||
PrivateTmp=yes
|
||||
ProtectSystem=strict
|
||||
ProtectHome=yes
|
||||
ProtectKernelTunables=yes
|
||||
ProtectKernelModules=yes
|
||||
ProtectControlGroups=yes
|
||||
RestrictSUIDSGID=yes
|
||||
RestrictNamespaces=yes
|
||||
RestrictAddressFamilies=AF_UNIX
|
||||
LockPersonality=yes
|
||||
SystemCallArchitectures=native
|
||||
UMask=0027
|
||||
ReadWritePaths=/srv/tesm/data /var/log/tesm
|
||||
@@ -0,0 +1,18 @@
|
||||
[Unit]
|
||||
Description=TESM -- taegliches Aufraeumen
|
||||
|
||||
[Timer]
|
||||
# Nachts, wenn niemand arbeitet: abgelaufene Sitzungen, alte Ratenereignisse
|
||||
# und die Archivierung des Aenderungsprotokolls.
|
||||
#
|
||||
# Vorher lief das nur, wenn jemand "tesm-admin housekeeping" aufrief oder in
|
||||
# der Diagnose darauf klickte -- also praktisch nie. Gemessen auf einer
|
||||
# Installation nach vier Wochen: 747 Sitzungszeilen, 682 davon abgelaufen.
|
||||
OnCalendar=*-*-* 03:30:00
|
||||
# Streuung, damit nicht jede Installation im Netz zur selben Sekunde loslegt.
|
||||
RandomizedDelaySec=15m
|
||||
# Nachgeholt, wenn die Maschine nachts aus war.
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
@@ -0,0 +1,34 @@
|
||||
[Unit]
|
||||
Description=TESM-Lizenzserver -- Aufraeumen: Sitzungen, Ratenereignisse, Protokollarchiv
|
||||
After=tesm-license.service
|
||||
# Ohne die laufende Anwendung ist nichts kaputt -- der Befehl arbeitet direkt
|
||||
# auf der Datenbank. "After" sorgt nur fuer eine sinnvolle Reihenfolge beim
|
||||
# Hochfahren.
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
User=tesm-license
|
||||
Group=tesm-license
|
||||
WorkingDirectory=/srv/tesm-license
|
||||
Environment=TESM_LICENSE_BASE_DIR=/srv/tesm-license
|
||||
Environment=TESM_LICENSE_DATA_DIR=/srv/tesm-license/data
|
||||
Environment=TESM_LICENSE_LOG_DIR=/var/log/tesm-license
|
||||
Environment=PYTHONUNBUFFERED=1
|
||||
ExecStart=/srv/tesm-license/venv/bin/tesm-license-admin housekeeping
|
||||
|
||||
# Hier darf voll gehaertet werden: dieser Aufruf fasst nur die Datenbank und
|
||||
# das Protokollverzeichnis an, keine Systemdateien und keinen Helfer per sudo.
|
||||
NoNewPrivileges=yes
|
||||
PrivateTmp=yes
|
||||
ProtectSystem=strict
|
||||
ProtectHome=yes
|
||||
ProtectKernelTunables=yes
|
||||
ProtectKernelModules=yes
|
||||
ProtectControlGroups=yes
|
||||
RestrictSUIDSGID=yes
|
||||
RestrictNamespaces=yes
|
||||
RestrictAddressFamilies=AF_UNIX
|
||||
LockPersonality=yes
|
||||
SystemCallArchitectures=native
|
||||
UMask=0027
|
||||
ReadWritePaths=/srv/tesm-license/data /var/log/tesm-license
|
||||
@@ -0,0 +1,18 @@
|
||||
[Unit]
|
||||
Description=TESM-Lizenzserver -- taegliches Aufraeumen
|
||||
|
||||
[Timer]
|
||||
# Nachts, wenn niemand arbeitet: abgelaufene Sitzungen, alte Ratenereignisse
|
||||
# und die Archivierung des Aenderungsprotokolls.
|
||||
#
|
||||
# Vorher lief das nur, wenn jemand "tesm-license-admin housekeeping" aufrief oder in
|
||||
# der Diagnose darauf klickte -- also praktisch nie. Gemessen auf einer
|
||||
# Installation nach vier Wochen: 747 Sitzungszeilen, 682 davon abgelaufen.
|
||||
OnCalendar=*-*-* 03:30:00
|
||||
# Streuung, damit nicht jede Installation im Netz zur selben Sekunde loslegt.
|
||||
RandomizedDelaySec=15m
|
||||
# Nachgeholt, wenn die Maschine nachts aus war.
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
@@ -150,6 +150,22 @@ def main(argv: list[str] | None = None) -> int:
|
||||
globals().update(AMBER="", DIM="", BOLD="", RESET="")
|
||||
|
||||
root = Path(args.root)
|
||||
|
||||
# Gibt es diese Installation ueberhaupt noch? Wenn nicht, ist hier nichts
|
||||
# zu melden -- auch kein Fehler.
|
||||
#
|
||||
# Der Hook unter /etc/update-motd.d bleibt liegen, wenn jemand eine
|
||||
# Installation von Hand entfernt; einen Rueckbau bringt TESM nicht mit.
|
||||
# Vorher druckte jeder dieser Hooks trotzdem seinen vollen Banner und
|
||||
# darunter "Datenbank nicht lesbar". Auf dem Testserver standen so
|
||||
# vierzehn Bloecke fuer vierzehn laengst geloeschte Probeinstallationen
|
||||
# vor jeder Anmeldung -- und der echte Banner ging darin unter.
|
||||
#
|
||||
# Eine entfernte Installation ist keine kaputte. Eine Datenbank, die da
|
||||
# ist und sich nicht lesen laesst, dagegen schon: die meldet sich weiter.
|
||||
if not (root / "data" / "app.db").is_file():
|
||||
return 0
|
||||
|
||||
# Kein isatty()-Test: dieses Skript schreibt beim Login nicht auf ein
|
||||
# Terminal, sondern ueber run-parts in eine Datei. Der Betrachter ist
|
||||
# trotzdem ein echtes Terminal -- deshalb immer Farbe.
|
||||
|
||||
@@ -0,0 +1,303 @@
|
||||
#!/usr/bin/env bash
|
||||
# =============================================================================
|
||||
# Rueckbau einer Installation von TESM oder TESM-Lizenzserver.
|
||||
#
|
||||
# Aufruf:
|
||||
# sudo bash deploy/uninstall.sh --app tesm
|
||||
# sudo bash deploy/uninstall.sh --app tesm-license --instance test
|
||||
# sudo bash deploy/uninstall.sh --app tesm --dry-run
|
||||
#
|
||||
# Das genaue Gegenstueck zu install.sh -- und es fehlte. Wer eine Installation
|
||||
# von Hand loeschte ("rm -rf /srv/tesm-probe"), liess zurueck: die systemd-Unit
|
||||
# (die systemd danach in einer Dauerschleife neu zu starten versuchte), den
|
||||
# Begruessungshaken (der bei jeder Anmeldung seinen Banner druckte), den
|
||||
# Shim unter /usr/local/bin, die Umgebungsdatei, die nginx-Site und den
|
||||
# Dienstbenutzer. Auf dem Testserver standen so neun tote Dienste und vierzehn
|
||||
# Banner. Genau das raeumt dieses Skript ab.
|
||||
#
|
||||
# Zwei Regeln, die den Unterschied machen:
|
||||
#
|
||||
# * **Daten bleiben.** Datenbank, Schluessel und Lizenz werden vorher in ein
|
||||
# Archiv gelegt, nicht geloescht. Wer sie wirklich los sein will, sagt es
|
||||
# mit --purge. Ein Rueckbau, der beilaeufig die Datenbank mitnimmt, ist
|
||||
# keiner, sondern ein Unfall.
|
||||
# * **Geteiltes bleibt, solange es jemand braucht.** sudoers-Datei und
|
||||
# Dienstbenutzer gehoeren der *Anwendung* (nicht der Instanz), der Helfer
|
||||
# unter /usr/local/lib/tesm allen Installationen beider Anwendungen. Sie
|
||||
# verschwinden erst, wenn die letzte geht -- sonst legt der Rueckbau einer
|
||||
# Testinstanz die Produktion daneben lahm.
|
||||
# =============================================================================
|
||||
set -euo pipefail
|
||||
|
||||
APP=""
|
||||
INSTANCE=""
|
||||
PURGE=0
|
||||
ASSUME_YES=0
|
||||
DRY_RUN=0
|
||||
|
||||
#: Ueberschreibbar, damit sich die Entscheidungen dieses Skripts in einem Test
|
||||
#: wirklich ausfuehren lassen -- und nicht nur als Textmuster geprueft werden.
|
||||
ETC_TESM="${TESM_ETC_DIR:-/etc/tesm}"
|
||||
SRV_DIR="${TESM_SRV_DIR:-/srv}"
|
||||
UNIT_DIR="${TESM_SYSTEMD_DIR:-/etc/systemd/system}"
|
||||
MOTD_DIR="${TESM_MOTD_DIR:-/etc/update-motd.d}"
|
||||
BIN_DIR="${TESM_BIN_DIR:-/usr/local/bin}"
|
||||
LIB_DIR="${TESM_LIB_DIR:-/usr/local/lib/tesm}"
|
||||
SUDOERS_DIR="${TESM_SUDOERS_DIR:-/etc/sudoers.d}"
|
||||
LOGROTATE_DIR="${TESM_LOGROTATE_DIR:-/etc/logrotate.d}"
|
||||
NGINX_DIR="${TESM_NGINX_DIR:-/etc/nginx}"
|
||||
LOG_BASE="${TESM_LOG_BASE:-/var/log}"
|
||||
|
||||
COLOR_OK=$'\033[32m'; COLOR_WARN=$'\033[33m'; COLOR_ERR=$'\033[31m'; COLOR_OFF=$'\033[0m'
|
||||
step() { printf '\n%s==>%s %s\n' "$COLOR_OK" "$COLOR_OFF" "$*"; }
|
||||
warn() { printf '%s !!%s %s\n' "$COLOR_WARN" "$COLOR_OFF" "$*" ; }
|
||||
fail() { printf '%s !!%s %s\n' "$COLOR_ERR" "$COLOR_OFF" "$*" >&2; exit 1; }
|
||||
info() { printf ' %s\n' "$*"; }
|
||||
|
||||
usage() {
|
||||
cat <<'TEXT'
|
||||
Rueckbau einer Installation.
|
||||
|
||||
--app <tesm|tesm-license> welche Anwendung (Pflicht)
|
||||
--instance <name> benannte Instanz (sonst die Hauptinstallation)
|
||||
--purge Daten nicht sichern, sondern loeschen
|
||||
--dry-run nur zeigen, was geschehen wuerde
|
||||
--yes, -y nicht nachfragen
|
||||
TEXT
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--app) APP="${2:?}"; shift 2 ;;
|
||||
--instance) INSTANCE="${2:?}"; shift 2 ;;
|
||||
--purge) PURGE=1; shift ;;
|
||||
--dry-run) DRY_RUN=1; shift ;;
|
||||
--yes|-y) ASSUME_YES=1; shift ;;
|
||||
-h|--help) usage; exit 0 ;;
|
||||
*) fail "unbekannte Option: $1" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
[[ -n "$APP" ]] || { usage; fail "--app fehlt"; }
|
||||
[[ "$APP" == "tesm" || "$APP" == "tesm-license" ]] || fail "--app muss tesm oder tesm-license sein"
|
||||
[[ -z "$INSTANCE" || "$INSTANCE" =~ ^[a-z0-9-]{1,16}$ ]] || fail "ungueltiger Instanzname"
|
||||
# Root braucht es wegen /srv, /etc und systemd. Wer die Pfade umbiegt (Test),
|
||||
# fasst nichts davon an -- dann ist die Huerde keine Sicherheit, sondern nur im
|
||||
# Weg, und ein Rueckbau, der sich nicht pruefen laesst, ist ein Risiko fuer sich.
|
||||
if [[ $DRY_RUN -eq 0 && "$SRV_DIR" == "/srv" && "$(id -u)" -ne 0 ]]; then
|
||||
fail "bitte mit sudo ausfuehren"
|
||||
fi
|
||||
|
||||
NAME="$APP"
|
||||
[[ -n "$INSTANCE" ]] && NAME="$APP-$INSTANCE"
|
||||
ROOT="$SRV_DIR/$NAME"
|
||||
|
||||
# Das Datenverzeichnis kann verschoben sein -- dann steht es in der
|
||||
# Umgebungsdatei, und nur dort. Ein Rueckbau, der stattdessen "$ROOT/data"
|
||||
# annimmt, sichert ein leeres Verzeichnis und laesst die echte Datenbank liegen.
|
||||
ENV_FILE="$ETC_TESM/$NAME.env"
|
||||
DATEN_DIR="$(sed -n 's/^TESM_DATA_DIR=//p' "$ENV_FILE" 2>/dev/null | tail -1 || true)"
|
||||
DATEN_DIR="${DATEN_DIR:-$ROOT/data}"
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Wer teilt sich was?
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
#: Gibt es neben dieser noch eine weitere Installation **derselben** Anwendung?
|
||||
#: Daran haengen sudoers-Datei und Dienstbenutzer -- beide tragen den Namen der
|
||||
#: Anwendung, nicht den der Instanz.
|
||||
weitere_dieser_anwendung() {
|
||||
local eintrag name
|
||||
for eintrag in "$ETC_TESM/$APP.env" "$ETC_TESM/$APP-"*.env; do
|
||||
[[ -f "$eintrag" ]] || continue
|
||||
name="$(basename "$eintrag" .env)"
|
||||
[[ "$name" == "$NAME" ]] && continue
|
||||
return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
#: Gibt es ueberhaupt noch irgendeine Installation? Daran haengen der Helfer
|
||||
#: und das Banner-Programm unter /usr/local/lib/tesm -- die gehoeren allen.
|
||||
weitere_ueberhaupt() {
|
||||
local eintrag name
|
||||
for eintrag in "$ETC_TESM"/*.env; do
|
||||
[[ -f "$eintrag" ]] || continue
|
||||
name="$(basename "$eintrag" .env)"
|
||||
[[ "$name" == "$NAME" ]] && continue
|
||||
return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Der Plan -- erst zeigen, dann tun
|
||||
# --------------------------------------------------------------------------- #
|
||||
UNITS=("$NAME.service" "$NAME-monitor.service" "$NAME-cleanup.service" "$NAME-cleanup.timer")
|
||||
DATEIEN=(
|
||||
"$NGINX_DIR/sites-enabled/$NAME"
|
||||
"$NGINX_DIR/sites-available/$NAME"
|
||||
"$MOTD_DIR/50-$NAME"
|
||||
"$BIN_DIR/$NAME-admin"
|
||||
"$LOGROTATE_DIR/$NAME"
|
||||
"$ENV_FILE"
|
||||
)
|
||||
VERZEICHNISSE=("$ETC_TESM/certs/$NAME" "$LOG_BASE/$NAME")
|
||||
|
||||
gefunden=0
|
||||
step "Rueckbau von $NAME"
|
||||
info "Anwendung : $APP${INSTANCE:+ (Instanz $INSTANCE)}"
|
||||
info "Verzeichnis : $ROOT"
|
||||
|
||||
echo
|
||||
echo " Dienste:"
|
||||
for unit in "${UNITS[@]}"; do
|
||||
if [[ -f "$UNIT_DIR/$unit" ]]; then info "- $unit"; gefunden=1; fi
|
||||
done
|
||||
[[ $gefunden -eq 1 ]] || info "(keine)"
|
||||
|
||||
echo
|
||||
echo " Dateien und Verzeichnisse:"
|
||||
for pfad in "${DATEIEN[@]}" "${VERZEICHNISSE[@]}"; do
|
||||
if [[ -e "$pfad" ]]; then info "- $pfad"; gefunden=1; fi
|
||||
done
|
||||
if [[ -d "$ROOT" ]]; then info "- $ROOT"; gefunden=1; fi
|
||||
|
||||
if [[ $gefunden -eq 0 ]]; then
|
||||
echo
|
||||
info "Von '$NAME' ist nichts mehr da -- nichts zu tun."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo
|
||||
echo " Daten (Datenbank, Schluessel, Lizenz):"
|
||||
if [[ -d "$DATEN_DIR" ]]; then
|
||||
if [[ $PURGE -eq 1 ]]; then
|
||||
warn "$DATEN_DIR wird GELOESCHT (--purge)"
|
||||
else
|
||||
info "$DATEN_DIR wird vorher gesichert"
|
||||
fi
|
||||
else
|
||||
info "(kein Datenverzeichnis gefunden)"
|
||||
fi
|
||||
|
||||
echo
|
||||
echo " Bleibt stehen:"
|
||||
if weitere_dieser_anwendung; then
|
||||
info "sudoers und Dienstbenutzer '$APP' -- eine weitere Installation braucht sie"
|
||||
else
|
||||
info "- (sudoers und Dienstbenutzer '$APP' werden entfernt)"
|
||||
fi
|
||||
if weitere_ueberhaupt; then
|
||||
info "Helfer unter $LIB_DIR -- andere Installationen brauchen ihn"
|
||||
else
|
||||
info "- (Helfer unter $LIB_DIR wird entfernt)"
|
||||
fi
|
||||
|
||||
if [[ $DRY_RUN -eq 1 ]]; then
|
||||
echo
|
||||
info "Probelauf -- es wurde nichts geaendert."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ $ASSUME_YES -eq 0 ]]; then
|
||||
echo
|
||||
read -r -p "Fortfahren? [j/N] " antwort
|
||||
[[ "$antwort" =~ ^[jJyY]$ ]] || fail "abgebrochen"
|
||||
fi
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Ausfuehren
|
||||
# --------------------------------------------------------------------------- #
|
||||
step "Daten"
|
||||
if [[ -d "$DATEN_DIR" && $PURGE -eq 0 ]]; then
|
||||
ARCHIV="$SRV_DIR/$NAME-daten-$(date +%Y%m%d-%H%M%S).tar.gz"
|
||||
tar -czf "$ARCHIV" -C "$(dirname "$DATEN_DIR")" "$(basename "$DATEN_DIR")"
|
||||
chmod 600 "$ARCHIV"
|
||||
info "gesichert: $ARCHIV"
|
||||
elif [[ -d "$DATEN_DIR" ]]; then
|
||||
info "wird mit dem Verzeichnis geloescht (--purge)"
|
||||
else
|
||||
info "nichts zu sichern"
|
||||
fi
|
||||
|
||||
step "Dienste"
|
||||
for unit in "${UNITS[@]}"; do
|
||||
[[ -f "$UNIT_DIR/$unit" ]] || continue
|
||||
systemctl disable --now "$unit" >/dev/null 2>&1 || true
|
||||
rm -f "$UNIT_DIR/$unit"
|
||||
# Ohne das bleibt eine entfernte Unit als "not-found" im Fehlerzustand
|
||||
# stehen und faerbt "systemctl --failed" rot.
|
||||
systemctl reset-failed "$unit" >/dev/null 2>&1 || true
|
||||
info "entfernt: $unit"
|
||||
done
|
||||
systemctl daemon-reload >/dev/null 2>&1 || true
|
||||
|
||||
step "Webserver"
|
||||
if [[ -e "$NGINX_DIR/sites-enabled/$NAME" || -e "$NGINX_DIR/sites-available/$NAME" ]]; then
|
||||
rm -f "$NGINX_DIR/sites-enabled/$NAME" "$NGINX_DIR/sites-available/$NAME"
|
||||
# Drei Faelle, und sie bedeuten Verschiedenes: kein nginx da (dann gibt es
|
||||
# nichts neu zu laden), nginx da und zufrieden, nginx da und unzufrieden.
|
||||
# Sie in einen Zweig zu werfen hiesse, auf einer Maschine ohne nginx eine
|
||||
# Warnung ueber eine kaputte Konfiguration auszugeben, die es nicht gibt.
|
||||
if ! command -v nginx >/dev/null 2>&1; then
|
||||
info "Site entfernt (nginx ist hier nicht installiert)"
|
||||
elif nginx -t >/dev/null 2>&1; then
|
||||
systemctl reload nginx >/dev/null 2>&1 || true
|
||||
info "Site entfernt, nginx neu geladen"
|
||||
else
|
||||
warn "Site entfernt -- nginx beanstandet die Konfiguration, bitte 'nginx -t' ansehen"
|
||||
fi
|
||||
else
|
||||
info "keine Site vorhanden"
|
||||
fi
|
||||
|
||||
step "Dateien"
|
||||
for pfad in "${DATEIEN[@]}"; do
|
||||
[[ -e "$pfad" ]] && { rm -f "$pfad"; info "entfernt: $pfad"; }
|
||||
done
|
||||
for pfad in "${VERZEICHNISSE[@]}"; do
|
||||
[[ -d "$pfad" ]] && { rm -rf "$pfad"; info "entfernt: $pfad"; }
|
||||
done
|
||||
if [[ -d "$ROOT" ]]; then
|
||||
rm -rf "$ROOT"
|
||||
info "entfernt: $ROOT"
|
||||
fi
|
||||
if [[ $PURGE -eq 1 ]]; then
|
||||
# Die Rueckwege aelterer Aktualisierungen. Sie enthalten dieselben Daten wie
|
||||
# die Installation -- deshalb nur hier, nie im Normalfall.
|
||||
for rest in "$SRV_DIR/$NAME-backup-"* "$SRV_DIR/$NAME-failed-"*; do
|
||||
[[ -d "$rest" ]] && { rm -rf "$rest"; info "entfernt: $rest"; }
|
||||
done
|
||||
fi
|
||||
|
||||
step "Geteiltes"
|
||||
if weitere_dieser_anwendung; then
|
||||
info "sudoers und Dienstbenutzer '$APP' bleiben -- eine weitere Installation braucht sie"
|
||||
else
|
||||
rm -f "$SUDOERS_DIR/$APP"
|
||||
info "entfernt: $SUDOERS_DIR/$APP"
|
||||
if getent passwd "$APP" >/dev/null 2>&1; then
|
||||
# Ein laufender Prozess haelt den Benutzer fest. Das ist kein Grund,
|
||||
# den Rueckbau scheitern zu lassen -- der Dienst ist oben schon gestoppt,
|
||||
# und was sonst noch unter diesem Namen laeuft, gehoert angesehen.
|
||||
if userdel "$APP" >/dev/null 2>&1; then
|
||||
info "entfernt: Dienstbenutzer $APP"
|
||||
else
|
||||
warn "Dienstbenutzer $APP liess sich nicht entfernen -- laeuft noch etwas unter ihm?"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
if weitere_ueberhaupt; then
|
||||
info "Helfer unter $LIB_DIR bleibt -- andere Installationen brauchen ihn"
|
||||
else
|
||||
rm -rf "$LIB_DIR"
|
||||
rmdir "$ETC_TESM/certs" "$ETC_TESM" >/dev/null 2>&1 || true
|
||||
info "entfernt: $LIB_DIR"
|
||||
fi
|
||||
|
||||
step "Fertig"
|
||||
info "'$NAME' ist zurueckgebaut."
|
||||
if [[ $PURGE -eq 0 && -n "${ARCHIV:-}" ]]; then
|
||||
info "Die Daten liegen unter $ARCHIV -- dort und sonst nirgends."
|
||||
fi
|
||||
@@ -33,6 +33,8 @@ EXTRA=("$@")
|
||||
echo "Verwendung: update.sh <tesm|tesm-license> [tag] [install.sh-Argumente ...]" >&2
|
||||
echo "Beispiel : update.sh tesm latest --instance test" >&2
|
||||
echo "Ohne Rueckfrage: --yes anhaengen (ohne Terminal zwingend)." >&2
|
||||
echo "Laeuft die Fassung schon, endet der Aufruf ohne Arbeit; --force setzt" >&2
|
||||
echo "sie trotzdem neu auf." >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
@@ -173,6 +175,32 @@ release_holen() {
|
||||
|
||||
release_holen
|
||||
|
||||
# Schon installiert? Dann gar nicht erst fragen.
|
||||
#
|
||||
# Dieselbe Pruefung steht in install.sh und gilt dort endgueltig (sie
|
||||
# vergleicht auch den Kern). Hier steht sie noch einmal, weil ein Update, das
|
||||
# ohne Wirkung bleibt, gar nicht erst nach einer Bestaetigung fragen soll --
|
||||
# und weil "es lief durch" sonst wie eine Aktualisierung aussieht.
|
||||
ERZWINGEN=0
|
||||
for ((i = 0; i < ${#EXTRA[@]}; i++)); do
|
||||
[[ "${EXTRA[i]}" == "--force" ]] && ERZWINGEN=1
|
||||
done
|
||||
INSTALLATION="$APP"
|
||||
for ((i = 0; i < ${#EXTRA[@]}; i++)); do
|
||||
[[ "${EXTRA[i]}" == "--instance" ]] && INSTALLATION="$APP-${EXTRA[i + 1]:-}"
|
||||
done
|
||||
MODUL="tesm"
|
||||
[[ "$APP" == "tesm-license" ]] && MODUL="tesm_license"
|
||||
if [[ $ERZWINGEN -eq 0 && -x "/srv/$INSTALLATION/venv/bin/python" ]]; then
|
||||
LAEUFT="$("/srv/$INSTALLATION/venv/bin/python" -c \
|
||||
"import $MODUL; print($MODUL.__version__)" 2>/dev/null || true)"
|
||||
if [[ -n "$LAEUFT" && "v$LAEUFT" == "$TAG" ]]; then
|
||||
echo "==> $APP $LAEUFT laeuft hier bereits -- nichts zu tun."
|
||||
echo " Trotzdem neu einrichten: --force"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# --yes darf auch hier stehen, nicht nur bei install.sh und upgrade.sh. Es
|
||||
# bleibt in EXTRA: install.sh bekommt es ohnehin, doppelt schadet nicht.
|
||||
OHNE_RUECKFRAGE=0
|
||||
|
||||
+47
-1
@@ -120,6 +120,14 @@ sudo bash /srv/tesm/deploy/update.sh tesm
|
||||
sudo bash /srv/tesm-license/deploy/update.sh tesm-license
|
||||
```
|
||||
|
||||
**Läuft die Fassung schon, passiert nichts.** `update.sh` vergleicht den
|
||||
aufgelösten Tag mit dem, was installiert ist, und endet mit `0`, bevor es eine
|
||||
Rückfrage stellt; `install.sh` prüft es noch einmal genauer (Anwendung **und**
|
||||
Kern) und bricht vor dem ersten Eingriff ab. Ein zweiter Lauf auf dieselbe
|
||||
Fassung baut sonst die Python-Umgebung neu, kopiert dieselben Dateien und
|
||||
startet den Dienst neu -- ein paar Sekunden Ausfall ohne jede Wirkung. Wer das
|
||||
trotzdem will (eine beschädigte Installation etwa), hängt `--force` an.
|
||||
|
||||
Alles nach dem Tag geht unverändert an `install.sh` weiter -- das ist der Weg,
|
||||
eine **benannte Instanz** zu aktualisieren:
|
||||
|
||||
@@ -375,6 +383,44 @@ sudo bash /srv/tesm/deploy/update.sh tesm
|
||||
|
||||
---
|
||||
|
||||
## 4c. Installation entfernen
|
||||
|
||||
Das Gegenstück zu `install.sh`:
|
||||
|
||||
```bash
|
||||
sudo bash /srv/tesm/deploy/uninstall.sh --app tesm --dry-run
|
||||
sudo bash /srv/tesm/deploy/uninstall.sh --app tesm
|
||||
sudo bash /srv/tesm/deploy/uninstall.sh --app tesm-license --instance test --yes
|
||||
```
|
||||
|
||||
Entfernt werden Dienste (`.service`, `-monitor`, `-cleanup` samt Timer), die
|
||||
nginx-Site, der Begrüßungshaken, der Shim unter `/usr/local/bin`, die
|
||||
Umgebungsdatei, das Zertifikatsverzeichnis, das Protokollverzeichnis und die
|
||||
Installation selbst.
|
||||
|
||||
**Die Daten bleiben.** Datenbank, Schlüssel und Lizenz gehen vorher in ein
|
||||
Archiv (`/srv/<name>-daten-<zeit>.tar.gz`, nur root). Sie sind das einzige an
|
||||
einer Installation, was sich nicht wiederherstellen lässt. Wer sie wirklich
|
||||
los sein will, nimmt `--purge` — das löscht zusätzlich die Rückwege älterer
|
||||
Aktualisierungen (`/srv/<name>-backup-*`).
|
||||
|
||||
**Geteiltes bleibt, solange es jemand braucht.** Die sudoers-Datei und der
|
||||
Dienstbenutzer tragen den Namen der *Anwendung*, nicht den der Instanz; der
|
||||
Helfer unter `/usr/local/lib/tesm` gehört allen Installationen beider
|
||||
Anwendungen. Sie verschwinden erst mit der letzten. Sonst legte der Rückbau
|
||||
einer Testinstanz die Produktion daneben lahm.
|
||||
|
||||
`--dry-run` zeigt den Plan, ohne etwas zu ändern. Ein zweiter Lauf auf eine
|
||||
bereits entfernte Installation sagt das und endet mit 0.
|
||||
|
||||
Warum es das gibt: wer eine Installation von Hand löscht (`rm -rf /srv/…`),
|
||||
lässt Unit, Begrüßungshaken, Shim, sudoers-Datei und nginx-Site zurück.
|
||||
systemd versucht die Unit danach in einer Dauerschleife zu starten, und der
|
||||
Haken druckt bei jeder Anmeldung seinen Banner. Auf dem Testserver standen so
|
||||
neun tote Dienste und vierzehn Banner.
|
||||
|
||||
---
|
||||
|
||||
## 5. Dienste
|
||||
|
||||
```bash
|
||||
@@ -446,7 +492,7 @@ Unverzichtbar:
|
||||
**Die Anwendung antwortet nicht.**
|
||||
```bash
|
||||
journalctl -u tesm -n 200 --no-pager
|
||||
curl -s http://127.0.0.1:5000/gesundheit
|
||||
curl -s http://127.0.0.1:5000/health
|
||||
```
|
||||
Antwortet gunicorn, aber der Browser nicht, liegt es an nginx.
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ Was geschützt wird, womit, und wo bewusst Grenzen gezogen sind.
|
||||
| Speicherung | Argon2id (argon2-cffi) |
|
||||
| Altbestand | bcrypt wird noch geprüft und bei der nächsten erfolgreichen Anmeldung stillschweigend auf Argon2id umgestellt |
|
||||
| Zweiter Faktor | TOTP, optional erzwingbar für Administratoren |
|
||||
| Rechte | Eine Zeile je Funktion; das Administratorkennzeichen gibt den Verwaltungsbereich, nicht alles |
|
||||
| Sperre je Konto | nach `LOGIN_MAX_ATTEMPTS` Versuchen |
|
||||
| Sperre je Adresse | zusätzlich `LOGIN_MAX_ATTEMPTS_PER_IP` -- sonst lässt sich die Kontosperre umgehen, indem man viele Konten je einmal probiert |
|
||||
| Verzeichnisdienst | LDAP nur über TLS, Zertifikat wird geprüft. Ohne gültiges Zertifikat keine Anmeldung -- kein Schalter, der das abschaltet |
|
||||
@@ -171,6 +172,10 @@ braucht der Dienst kein `--workers 1` mehr.
|
||||
* **Kein CSRF-Freibrief für cookie-autorisierte Routen.**
|
||||
* **Kein `unsafe-inline` für Skripte**, auch nicht "vorübergehend".
|
||||
* **Keine Rechteausweitung**, auch nicht für Administratoren untereinander.
|
||||
Ein echter Administrator darf sich Funktionsrechte über eine Gruppe geben --
|
||||
das ist gewollt und hinterlässt eine Zeile im Änderungsprotokoll. Was es
|
||||
nicht gibt, ist der stille Weg: ein Kennzeichen, das ohne Eintrag alles
|
||||
aufschließt.
|
||||
* **Kein Hostname im Lizenz-Fingerabdruck** -- Umbenennen darf die Bindung
|
||||
nicht brechen.
|
||||
* **Keine von Hand gepflegte nginx-Site.** Sie wird immer neu erzeugt.
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "tesm-core"
|
||||
version = "2.2.0"
|
||||
version = "2.8.18"
|
||||
description = "Gemeinsames Anwendungsgeruest (Auth, RBAC, Navigation, Design-System, Migrationen) fuer TESM und TESM-Lizenzserver"
|
||||
requires-python = ">=3.11"
|
||||
dependencies = [
|
||||
|
||||
@@ -13,10 +13,12 @@ import secrets
|
||||
from datetime import datetime, timezone
|
||||
from typing import Any, Sequence
|
||||
|
||||
from flask import Blueprint, Flask, g, render_template, request
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from flask import Blueprint, Flask, g, redirect, render_template, request
|
||||
from werkzeug.exceptions import HTTPException
|
||||
|
||||
from . import audit, logging_setup, ui
|
||||
from . import audit, legacy_urls, logging_setup, ui
|
||||
from .config import CoreConfig
|
||||
from .core_schema import CORE_MIGRATIONS
|
||||
from .db import Database
|
||||
@@ -57,18 +59,29 @@ CORE_SETTINGS: tuple[SettingSpec, ...] = (
|
||||
30,
|
||||
"int",
|
||||
"Aufbewahrung im Papierkorb (Tage)",
|
||||
hint="Nach dieser Frist werden Eintraege beim naechsten Aufruf endgueltig entfernt.",
|
||||
hint="Nach dieser Frist werden Einträge beim nächsten Aufruf endgültig entfernt.",
|
||||
section="system",
|
||||
minimum=1,
|
||||
maximum=3650,
|
||||
),
|
||||
SettingSpec(
|
||||
"session_absolute_hours",
|
||||
12,
|
||||
"int",
|
||||
"Längstmögliche Sitzungsdauer (Stunden)",
|
||||
hint="Danach ist Schluss, auch bei ständiger Arbeit – eine Sitzung soll nicht "
|
||||
"ewig leben. Die eingebundenen Dateifreigaben enden mit ihr.",
|
||||
section="system",
|
||||
minimum=1,
|
||||
maximum=168,
|
||||
),
|
||||
SettingSpec(
|
||||
"session_idle_minutes",
|
||||
30,
|
||||
"int",
|
||||
"Automatische Abmeldung nach Leerlauf (Minuten)",
|
||||
hint="Jede Anfrage setzt den Zaehler zurueck -- gezaehlt wird nur Untaetigkeit. "
|
||||
"Gilt auch fuer die eingebundenen Dateifreigaben: mit der Sitzung endet die "
|
||||
hint="Jede Anfrage setzt den Zähler zurück – gezählt wird nur Untätigkeit. "
|
||||
"Gilt auch für die eingebundenen Dateifreigaben: mit der Sitzung endet die "
|
||||
"Einbindung.",
|
||||
section="system",
|
||||
minimum=5,
|
||||
@@ -89,6 +102,14 @@ CORE_SETTINGS: tuple[SettingSpec, ...] = (
|
||||
),
|
||||
# -- Webserver/TLS (Host-Ebene, in beiden Anwendungen gleich) ----------- #
|
||||
# Lizenzserver: eigenes Zertifikat statt abgeschalteter Pruefung.
|
||||
SettingSpec(
|
||||
"modules_disabled",
|
||||
[],
|
||||
"json",
|
||||
"Vor Ort abgeschaltete Module",
|
||||
hint="Die Lizenz sagt, was erlaubt ist; das hier sagt, was benutzt wird.",
|
||||
section="system",
|
||||
),
|
||||
SettingSpec(
|
||||
"license_server_ca",
|
||||
"",
|
||||
@@ -101,8 +122,8 @@ CORE_SETTINGS: tuple[SettingSpec, ...] = (
|
||||
SettingSpec("web_hsts_enabled", False, "bool", "HSTS senden", section="web"),
|
||||
SettingSpec("web_redirect_http", True, "bool", "HTTP auf HTTPS umleiten", section="web"),
|
||||
SettingSpec("web_cert_path", "", "str", "Zertifikat (Pfad)", section="web"),
|
||||
SettingSpec("web_key_path", "", "str", "Privater Schluessel (Pfad)", section="web"),
|
||||
SettingSpec("web_acme_email", "", "str", "E-Mail fuer Let's Encrypt", section="web"),
|
||||
SettingSpec("web_key_path", "", "str", "Privater Schlüssel (Pfad)", section="web"),
|
||||
SettingSpec("web_acme_email", "", "str", "E-Mail für Let's Encrypt", section="web"),
|
||||
SettingSpec("web_acme_webroot", "", "str", "ACME-Webroot", section="web"),
|
||||
# Abweichende Ports braucht nur eine Testinstanz neben der Produktion --
|
||||
# im Regelbetrieb bleibt es bei 80 und 443.
|
||||
@@ -113,7 +134,7 @@ CORE_SETTINGS: tuple[SettingSpec, ...] = (
|
||||
"web_https_port", 443, "int", "HTTPS-Port", section="web", minimum=1, maximum=65535
|
||||
),
|
||||
SettingSpec(
|
||||
"web_max_body_mb", 128, "int", "Maximale Anfragegroesse (MB)", section="web",
|
||||
"web_max_body_mb", 128, "int", "Maximale Anfragegröße (MB)", section="web",
|
||||
minimum=1, maximum=8192,
|
||||
),
|
||||
*directory.SETTINGS,
|
||||
@@ -135,7 +156,11 @@ def create_base_app(
|
||||
#: Wortmarke, ohne Zeile darunter; die Marke selbst zeigen beide
|
||||
#: Anwendungen.
|
||||
auth_tagline: str = "",
|
||||
app_version: str = "2.2.0",
|
||||
#: Beide Anwendungen geben ihre eigene Paketversion mit -- und die laeuft
|
||||
#: absichtlich auseinander: was sich nicht geaendert hat, bekommt keine
|
||||
#: neue Nummer. Eine feste Zahl an dieser Stelle wuerde irgendwann eine
|
||||
#: falsche Version in die Fussnote schreiben.
|
||||
app_version: str = "unbekannt",
|
||||
built_in_trusted_keys: tuple[str, ...] = (),
|
||||
enable_license: bool = True,
|
||||
template_folder: str | None = None,
|
||||
@@ -147,6 +172,10 @@ def create_base_app(
|
||||
static_folder=static_folder or "static",
|
||||
static_url_path="/assets",
|
||||
)
|
||||
# Umlaute bleiben Umlaute -- auch in JSON. Flask wuerde sonst nach ASCII
|
||||
# ausweichen ("ü"), und genau darin stehen die Flash-Meldungen in der
|
||||
# Seite: eine Meldung mit "ue" war lesbar, eine mit "ü" wurde zu Zahlen.
|
||||
app.json.ensure_ascii = False
|
||||
|
||||
# Templates und Design-System des Kerns liegen im Paket ``tesm_core`` und
|
||||
# werden ueber einen eigenen Blueprint bereitgestellt. Dadurch kann jede
|
||||
@@ -230,12 +259,21 @@ def create_base_app(
|
||||
wert = 0
|
||||
return wert if wert > 0 else config.security.session_idle_minutes
|
||||
|
||||
def _gesamtdauer(conn: Any) -> int:
|
||||
"""Gesamtdauer aus den Einstellungen -- ueber dieselbe offene Verbindung."""
|
||||
try:
|
||||
wert = int(settings.get(conn, "session_absolute_hours") or 0)
|
||||
except (TypeError, ValueError):
|
||||
wert = 0
|
||||
return wert if wert > 0 else config.security.session_absolute_hours
|
||||
|
||||
app.session_interface = SqliteSessionInterface(
|
||||
database,
|
||||
cookie_name=app.config["SESSION_COOKIE_NAME"],
|
||||
idle_minutes=config.security.session_idle_minutes,
|
||||
absolute_hours=config.security.session_absolute_hours,
|
||||
idle_lookup=_leerlauf,
|
||||
absolute_lookup=_gesamtdauer,
|
||||
)
|
||||
|
||||
# -- Schema und Startzustand ------------------------------------------ #
|
||||
@@ -336,14 +374,24 @@ def create_base_app(
|
||||
# -- Fehlerseiten ------------------------------------------------------ #
|
||||
@app.errorhandler(HTTPException)
|
||||
def _http_error(error: HTTPException): # type: ignore[no-untyped-def]
|
||||
if error.code == 404:
|
||||
# Vor der Fehlerseite: war das eine Adresse aus der Zeit vor 2.5.0?
|
||||
# Erst hier gefragt, damit die Tabelle nie eine bestehende Route
|
||||
# verdeckt -- auf dem Lizenzserver ist /lizenz/<ticket> echt.
|
||||
ziel = legacy_urls.neue_adresse(request.path)
|
||||
if ziel is not None:
|
||||
parameter = legacy_urls.neue_parameter(request.args.to_dict(flat=True))
|
||||
if parameter:
|
||||
ziel = ziel + "?" + urlencode(parameter)
|
||||
return redirect(ziel)
|
||||
if error.code == 413:
|
||||
# "Request Entity Too Large" allein hilft niemandem weiter: die
|
||||
# Zahl steht in einer Einstellung, und wer hochlaedt, soll sie
|
||||
# sehen. Vorher stand hier nur der nackte Status.
|
||||
grenze = uploads.limit_mb()
|
||||
error.description = (
|
||||
f"Diese Datei ist groesser als erlaubt. Zurzeit sind {grenze} MB je Upload "
|
||||
"eingestellt; aendern kann das ein Administrator unter "
|
||||
f"Diese Datei ist größer als erlaubt. Zurzeit sind {grenze} MB je Upload "
|
||||
"eingestellt; ändern kann das ein Administrator unter "
|
||||
'"Einstellungen -> Webserver und TLS".'
|
||||
)
|
||||
if _wants_json():
|
||||
@@ -399,7 +447,7 @@ def create_base_app(
|
||||
with app.app_context():
|
||||
trash_views.register_core_providers()
|
||||
|
||||
app.add_url_rule("/gesundheit", "health", _health, methods=["GET"])
|
||||
app.add_url_rule("/health", "health", _health, methods=["GET"])
|
||||
|
||||
return app
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import sqlite3
|
||||
from collections import defaultdict
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from typing import Any, Iterable
|
||||
from typing import Any, Collection, Iterable, Mapping, Sequence
|
||||
|
||||
from .db import Database
|
||||
|
||||
@@ -116,6 +116,49 @@ def log(
|
||||
return int(cursor.lastrowid or 0)
|
||||
|
||||
|
||||
def diff(
|
||||
vorher: Mapping[str, Any] | None,
|
||||
nachher: Mapping[str, Any] | None,
|
||||
*,
|
||||
felder: Sequence[tuple[str, str]] | None = None,
|
||||
geheim: Collection[str] = (),
|
||||
) -> str:
|
||||
"""Was sich geaendert hat: ``Feld: alt -> neu``, mit Komma getrennt.
|
||||
|
||||
Damit steht im Protokoll nicht nur *dass* etwas geaendert wurde, sondern
|
||||
auch *von was auf was* -- der Weg zurueck steht damit in der Zeile selbst.
|
||||
|
||||
``felder`` gibt Auswahl und Beschriftung vor (``[("ssh_port", "SSH-Port")]``);
|
||||
ohne Angabe werden alle gemeinsamen Felder verglichen. Namen in ``geheim``
|
||||
werden nie im Klartext geschrieben -- dort steht nur, dass sie sich
|
||||
geaendert haben.
|
||||
"""
|
||||
if vorher is None or nachher is None:
|
||||
return ""
|
||||
paare = felder or [(name, name) for name in sorted(set(vorher) & set(nachher))]
|
||||
teile: list[str] = []
|
||||
for name, beschriftung in paare:
|
||||
if name not in vorher or name not in nachher:
|
||||
continue
|
||||
alt, neu = vorher[name], nachher[name]
|
||||
if alt == neu:
|
||||
continue
|
||||
if name in geheim:
|
||||
teile.append(f"{beschriftung}: geaendert")
|
||||
continue
|
||||
teile.append(f"{beschriftung}: {_wert(alt)} -> {_wert(neu)}")
|
||||
return ", ".join(teile)
|
||||
|
||||
|
||||
def _wert(wert: Any) -> str:
|
||||
if wert is None or wert == "":
|
||||
return "(leer)"
|
||||
if isinstance(wert, bool):
|
||||
return "ein" if wert else "aus"
|
||||
text = " ".join(str(wert).split())
|
||||
return text if len(text) <= 80 else text[:79] + "…"
|
||||
|
||||
|
||||
def verify_chain(conn: sqlite3.Connection, *, limit: int | None = None) -> dict[str, Any]:
|
||||
"""Prueft die Hash-Kette. Rueckgabe: ``{"ok", "checked", "broken_at", "reason"}``."""
|
||||
sql = "SELECT * FROM audit_log ORDER BY id"
|
||||
@@ -133,14 +176,14 @@ def verify_chain(conn: sqlite3.Connection, *, limit: int | None = None) -> dict[
|
||||
"ok": False,
|
||||
"checked": checked,
|
||||
"broken_at": data["id"],
|
||||
"reason": "Vorgaenger-Hash passt nicht -- eine Zeile wurde entfernt oder eingefuegt.",
|
||||
"reason": "Vorgänger-Hash passt nicht – eine Zeile wurde entfernt oder eingefügt.",
|
||||
}
|
||||
if compute_hash(str(data["prev_hash"]), data) != data["hash"]:
|
||||
return {
|
||||
"ok": False,
|
||||
"checked": checked,
|
||||
"broken_at": data["id"],
|
||||
"reason": "Zeileninhalt passt nicht zum gespeicherten Hash -- Eintrag geaendert.",
|
||||
"reason": "Zeileninhalt passt nicht zum gespeicherten Hash | Eintrag geändert.",
|
||||
}
|
||||
expected_prev = str(data["hash"])
|
||||
checked += 1
|
||||
|
||||
@@ -26,6 +26,7 @@ import re
|
||||
import socket
|
||||
import sqlite3
|
||||
import ssl
|
||||
import time
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime, timezone
|
||||
from typing import Any, Literal
|
||||
@@ -59,20 +60,20 @@ SETTINGS: tuple[SettingSpec, ...] = (
|
||||
section="ldap",
|
||||
choices=(("ldaps", "LDAPS (Port 636)"), ("starttls", "StartTLS (Port 389)"), ("none", "Unverschluesselt")),
|
||||
),
|
||||
SettingSpec("ldap_verify_cert", True, "bool", "Serverzertifikat pruefen", section="ldap"),
|
||||
SettingSpec("ldap_verify_cert", True, "bool", "Serverzertifikat prüfen", section="ldap"),
|
||||
SettingSpec("ldap_ca_file", "", "str", "CA-Zertifikat (Pfad)", section="ldap"),
|
||||
SettingSpec(
|
||||
"ldap_allow_insecure",
|
||||
False,
|
||||
"bool",
|
||||
"Unverschluesselte Verbindung ausdruecklich erlauben",
|
||||
hint="Nur fuer Testumgebungen. Das Passwort geht dabei im Klartext ueber das Netz.",
|
||||
"Unverschlüsselte Verbindung ausdrücklich erlauben",
|
||||
hint="Nur für Testumgebungen. Das Passwort geht dabei im Klartext über das Netz.",
|
||||
section="ldap",
|
||||
),
|
||||
SettingSpec("ldap_base_dn", "", "str", "Basis-DN (leer = automatisch)", section="ldap"),
|
||||
SettingSpec("ldap_user_attribute", "sAMAccountName", "str", "Anmeldeattribut", section="ldap"),
|
||||
SettingSpec("ldap_email_attribute", "userPrincipalName", "str", "E-Mail-Attribut", section="ldap"),
|
||||
SettingSpec("ldap_group_sync", True, "bool", "Gruppen aus dem Verzeichnis uebernehmen", section="ldap"),
|
||||
SettingSpec("ldap_group_sync", True, "bool", "Gruppen aus dem Verzeichnis übernehmen", section="ldap"),
|
||||
SettingSpec("ldap_timeout", 8, "int", "Zeitlimit (Sekunden)", section="ldap", minimum=1, maximum=60),
|
||||
)
|
||||
|
||||
@@ -123,7 +124,7 @@ def bind_credentials(conn: sqlite3.Connection) -> tuple[str, str]:
|
||||
try:
|
||||
secret = core().keystore.decrypt(encrypted, aad=AAD_LDAP_BIND)
|
||||
except Exception: # noqa: BLE001 - Schluessel gewechselt/Datei kaputt
|
||||
logger.error("Bind-Passwort des Verzeichnisdienstes konnte nicht entschluesselt werden")
|
||||
logger.error("Bind-Passwort des Verzeichnisdienstes konnte nicht entschlüsselt werden")
|
||||
return str(row.get("username") or ""), ""
|
||||
return str(row.get("username") or ""), secret
|
||||
|
||||
@@ -162,19 +163,82 @@ def _tls_object(config: dict[str, Any]):
|
||||
|
||||
|
||||
def _server(config: dict[str, Any]):
|
||||
"""Das Server-Objekt -- so sparsam wie moeglich.
|
||||
|
||||
``get_info`` entscheidet, was ldap3 beim Verbinden **zusaetzlich** holt.
|
||||
Mit ``ALL`` ist das die Beschreibung des Verzeichnisses *und sein ganzes
|
||||
Schema*: bei einem Active Directory sind das Tausende Attribut- und
|
||||
Klassendefinitionen, mehrere Megabyte, bei jeder Verbindung neu. Fuer eine
|
||||
Anmeldung braucht davon nichts -- gelesen wird hoechstens der
|
||||
``defaultNamingContext``, wenn kein Basis-DN eingetragen ist, und dafuer
|
||||
genuegt ``DSA`` (nur die Serverinformation, ein Datensatz).
|
||||
|
||||
Liegt der Domain-Controller in einem anderen Netz, ist genau das der
|
||||
Unterschied zwischen "geht sofort" und "dauert manchmal".
|
||||
"""
|
||||
from ldap3 import Server
|
||||
|
||||
security = str(config["ldap_security"])
|
||||
braucht_basis = not str(config.get("ldap_base_dn") or "").strip()
|
||||
return Server(
|
||||
str(config["ldap_host"]),
|
||||
port=int(config["ldap_port"]),
|
||||
use_ssl=security == "ldaps",
|
||||
tls=_tls_object(config) if security in {"ldaps", "starttls"} else None,
|
||||
get_info="ALL",
|
||||
get_info="DSA" if braucht_basis else "NO_INFO",
|
||||
connect_timeout=int(config["ldap_timeout"]),
|
||||
)
|
||||
|
||||
|
||||
#: Fehler, die nur "gerade jetzt nicht" bedeuten -- nicht "falsches Passwort".
|
||||
#:
|
||||
#: Die Liste stammt aus der Fassung 1.2.8, wo dieses Problem schon einmal
|
||||
#: geloest war. Der Kommentar dort beschreibt es genauer, als ich es koennte:
|
||||
#: ein Domain-Controller in einem anderen, langsameren Netzsegment -- die
|
||||
#: allererste Verbindung dorthin ist oft spuerbar langsamer als jede folgende,
|
||||
#: und der erste Login schlug mit "Benutzer/Passwort ungueltig" fehl, waehrend
|
||||
#: ein sofortiger zweiter Versuch klappte.
|
||||
TRANSIENTE_FEHLER: tuple[type[Exception], ...] = ()
|
||||
|
||||
|
||||
def _transiente_fehler() -> tuple[type[Exception], ...]:
|
||||
"""Die Ausnahmeklassen von ldap3, die einen Wiederholversuch verdienen."""
|
||||
global TRANSIENTE_FEHLER
|
||||
if TRANSIENTE_FEHLER:
|
||||
return TRANSIENTE_FEHLER
|
||||
from ldap3.core.exceptions import (
|
||||
LDAPResponseTimeoutError,
|
||||
LDAPSocketOpenError,
|
||||
LDAPSocketReceiveError,
|
||||
LDAPSocketSendError,
|
||||
)
|
||||
|
||||
TRANSIENTE_FEHLER = (
|
||||
LDAPSocketOpenError,
|
||||
LDAPSocketReceiveError,
|
||||
LDAPSocketSendError,
|
||||
LDAPResponseTimeoutError,
|
||||
)
|
||||
return TRANSIENTE_FEHLER
|
||||
|
||||
|
||||
def mit_wiederholung(aufbau: Any) -> Any:
|
||||
"""Genau ein zweiter Versuch -- und nur bei einem Netzfehler.
|
||||
|
||||
Nicht bei einer abgelehnten Anmeldung: ein Tippfehler im Passwort wuerde
|
||||
sonst den Sperrzaehler des Kontos zweimal statt einmal hochzaehlen. Das
|
||||
ist die Regel aus 1.2.8, und sie ist richtig.
|
||||
"""
|
||||
try:
|
||||
return aufbau()
|
||||
except _transiente_fehler() as fehler:
|
||||
logger.info(
|
||||
"Verzeichnisdienst antwortete nicht (%s) -- ein zweiter Versuch",
|
||||
type(fehler).__name__,
|
||||
)
|
||||
return aufbau()
|
||||
|
||||
|
||||
def _connect(config: dict[str, Any], user: str, password: str):
|
||||
"""Baut eine Verbindung auf und bindet. Wirft bei Netz-/TLS-Problemen."""
|
||||
from ldap3 import Connection
|
||||
@@ -182,7 +246,7 @@ def _connect(config: dict[str, Any], user: str, password: str):
|
||||
security = str(config["ldap_security"])
|
||||
if security == "none" and not config["ldap_allow_insecure"]:
|
||||
raise PermissionError(
|
||||
"Unverschluesselte Verzeichnisverbindungen sind deaktiviert. "
|
||||
"Unverschlüsselte Verzeichnisverbindungen sind deaktiviert. "
|
||||
"Nutzen Sie LDAPS oder StartTLS."
|
||||
)
|
||||
connection = Connection(
|
||||
@@ -192,6 +256,12 @@ def _connect(config: dict[str, Any], user: str, password: str):
|
||||
auto_bind=False,
|
||||
raise_exceptions=False,
|
||||
receive_timeout=int(config["ldap_timeout"]),
|
||||
# Ein Active Directory antwortet auf eine Suche ab der Domaenenwurzel
|
||||
# mit Verweisen auf andere Controller. ldap3 folgt ihnen von sich aus
|
||||
# -- und baut dafuer neue Verbindungen auf, womoeglich in ein anderes
|
||||
# Netz. Fuer eine Anmeldung ist das nicht nur unnoetig, sondern die
|
||||
# Quelle genau der Wartezeiten, die niemand erklaeren kann.
|
||||
auto_referrals=False,
|
||||
)
|
||||
if security == "starttls":
|
||||
if not connection.open():
|
||||
@@ -249,12 +319,23 @@ def authenticate(conn: sqlite3.Connection, username: str, password: str) -> Dire
|
||||
bind_user, bind_password = bind_credentials(conn)
|
||||
warnings: list[str] = []
|
||||
if str(config["ldap_security"]) == "none":
|
||||
warnings.append("Unverschluesselte Verzeichnisverbindung in Benutzung")
|
||||
warnings.append("Unverschlüsselte Verzeichnisverbindung in Benutzung")
|
||||
if not config["ldap_verify_cert"]:
|
||||
warnings.append("Serverzertifikat des Verzeichnisdienstes wird nicht geprueft")
|
||||
warnings.append("Serverzertifikat des Verzeichnisdienstes wird nicht geprüft")
|
||||
|
||||
begonnen = time.monotonic()
|
||||
zeiten: list[str] = []
|
||||
|
||||
def gemessen(name: str, seit: float) -> float:
|
||||
"""Haelt eine Stufe mit ihrer Dauer fest und gibt die neue Marke."""
|
||||
jetzt = time.monotonic()
|
||||
zeiten.append(f"{name} {int((jetzt - seit) * 1000)}ms")
|
||||
return jetzt
|
||||
|
||||
try:
|
||||
service_conn, bound = _connect(config, bind_user, bind_password)
|
||||
service_conn, bound = mit_wiederholung(
|
||||
lambda: _connect(config, bind_user, bind_password)
|
||||
)
|
||||
except (PermissionError, ConnectionError) as exc:
|
||||
logger.error("Verzeichnisdienst: %s", exc)
|
||||
return DirectoryResult("unavailable", message=str(exc), warnings=tuple(warnings))
|
||||
@@ -271,8 +352,10 @@ def authenticate(conn: sqlite3.Connection, username: str, password: str) -> Dire
|
||||
warnings=tuple(warnings),
|
||||
)
|
||||
|
||||
marke = gemessen("Dienstbindung", begonnen)
|
||||
try:
|
||||
base = _base_dn(service_conn, config)
|
||||
marke = gemessen("Basis-DN", marke)
|
||||
if not base:
|
||||
return DirectoryResult(
|
||||
"unavailable", message="Basis-DN konnte nicht ermittelt werden.", warnings=tuple(warnings)
|
||||
@@ -288,8 +371,10 @@ def authenticate(conn: sqlite3.Connection, username: str, password: str) -> Dire
|
||||
attributes=list(dict.fromkeys(wanted)),
|
||||
size_limit=2,
|
||||
)
|
||||
marke = gemessen("Benutzersuche", marke)
|
||||
entries = list(service_conn.entries)
|
||||
if len(entries) != 1:
|
||||
logger.info("Verzeichnisanmeldung %s: %s", username, ", ".join(zeiten))
|
||||
return DirectoryResult("invalid", warnings=tuple(warnings))
|
||||
|
||||
entry = entries[0]
|
||||
@@ -300,9 +385,18 @@ def authenticate(conn: sqlite3.Connection, username: str, password: str) -> Dire
|
||||
|
||||
# Zweite, unabhaengige Verbindung mit den Benutzerdaten -- die eigentliche
|
||||
# Passwortpruefung. Niemals ueber die Dienstkonto-Verbindung rebinden.
|
||||
user_conn, user_bound = _connect(config, dn, password)
|
||||
#
|
||||
# Mit Wiederholversuch, und genau hier zeigte sich das Symptom: bei
|
||||
# einem Domain-Controller in einem anderen Netz schlug der erste
|
||||
# Versuch mit "Benutzer/Passwort ungueltig" fehl, der zweite gleich
|
||||
# darauf klappte. Wiederholt wird nur bei einem Netzfehler -- eine
|
||||
# abgelehnte Anmeldung bleibt abgelehnt, sonst zaehlt ein Tippfehler
|
||||
# den Sperrzaehler des Kontos zweimal hoch.
|
||||
user_conn, user_bound = mit_wiederholung(lambda: _connect(config, dn, password))
|
||||
marke = gemessen("Passwortpruefung", marke)
|
||||
try:
|
||||
if not user_bound:
|
||||
logger.info("Verzeichnisanmeldung %s: %s", username, ", ".join(zeiten))
|
||||
return DirectoryResult("invalid", warnings=tuple(warnings))
|
||||
finally:
|
||||
try:
|
||||
@@ -313,6 +407,7 @@ def authenticate(conn: sqlite3.Connection, username: str, password: str) -> Dire
|
||||
group_dns: tuple[str, ...] = ()
|
||||
if config["ldap_group_sync"]:
|
||||
group_dns = _resolve_groups(service_conn, base, dn)
|
||||
marke = gemessen("Gruppen", marke)
|
||||
|
||||
profile = DirectoryProfile(
|
||||
username=_attr(entry, attribute) or username,
|
||||
@@ -322,6 +417,15 @@ def authenticate(conn: sqlite3.Connection, username: str, password: str) -> Dire
|
||||
email=_attr(entry, email_attribute),
|
||||
group_dns=group_dns,
|
||||
)
|
||||
# Eine Zeile je Anmeldung mit den Dauern der Stufen. Aus "dauert
|
||||
# manchmal laenger" wird damit eine Zahl -- und man sieht, ob es die
|
||||
# Verbindung ist, die Suche oder die Gruppen.
|
||||
logger.info(
|
||||
"Verzeichnisanmeldung %s: %s, gesamt %dms",
|
||||
username,
|
||||
", ".join(zeiten),
|
||||
int((time.monotonic() - begonnen) * 1000),
|
||||
)
|
||||
return DirectoryResult("ok", profile=profile, warnings=tuple(warnings))
|
||||
finally:
|
||||
try:
|
||||
@@ -359,7 +463,7 @@ def _resolve_groups(connection: Any, base: str, user_dn: str) -> tuple[str, ...]
|
||||
)
|
||||
return tuple(str(entry.entry_dn) for entry in connection.entries)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
logger.warning("Gruppenaufloesung fehlgeschlagen: %s", exc)
|
||||
logger.warning("Gruppenauflösung fehlgeschlagen: %s", exc)
|
||||
return ()
|
||||
|
||||
|
||||
@@ -423,18 +527,24 @@ def _apply_group_mappings(
|
||||
zugewiesene Gruppen bleiben erhalten, wenn sie kein Verzeichnis-Mapping
|
||||
haben -- sonst waere jede lokale Zuweisung nach dem naechsten Login weg.
|
||||
"""
|
||||
if not group_dns:
|
||||
return
|
||||
mappings = Database.all(
|
||||
conn, "SELECT ad_group_dn, app_group_id FROM ldap_group_mappings"
|
||||
conn, "SELECT ad_group_dn, app_group_id, grants_admin FROM ldap_group_mappings"
|
||||
)
|
||||
if not mappings:
|
||||
return
|
||||
mapped_group_ids = {int(row["app_group_id"]) for row in mappings}
|
||||
lowered = {dn.lower() for dn in group_dns}
|
||||
# Das Kennzeichen zuerst -- es haengt an keiner Gruppe und muss auch dann
|
||||
# ausgewertet werden, wenn das Konto in keiner zugeordneten Gruppe steht.
|
||||
_kennzeichen_setzen(conn, user_id, mappings, lowered)
|
||||
if not group_dns:
|
||||
return
|
||||
gruppenzuordnungen = [row for row in mappings if row["app_group_id"] is not None]
|
||||
if not gruppenzuordnungen:
|
||||
return
|
||||
mapped_group_ids = {int(row["app_group_id"]) for row in gruppenzuordnungen}
|
||||
wanted = {
|
||||
int(row["app_group_id"])
|
||||
for row in mappings
|
||||
for row in gruppenzuordnungen
|
||||
if str(row["ad_group_dn"]).lower() in lowered
|
||||
}
|
||||
|
||||
@@ -452,6 +562,71 @@ def _apply_group_mappings(
|
||||
)
|
||||
|
||||
|
||||
def _kennzeichen_setzen(
|
||||
conn: sqlite3.Connection,
|
||||
user_id: int,
|
||||
mappings: list[dict[str, Any]],
|
||||
gruppen: set[str],
|
||||
) -> None:
|
||||
"""Setzt oder entzieht das Administratorkennzeichen nach dem Verzeichnis.
|
||||
|
||||
Wirkung wie bei Gruppen: **ersetzend**. Wer aus der zugeordneten
|
||||
AD-Gruppe herausfaellt, verliert das Kennzeichen bei der naechsten
|
||||
Anmeldung -- sonst waere ein Austritt im Verzeichnis eine Aenderung, die
|
||||
hier nie ankommt.
|
||||
|
||||
Zwei Grenzen, beide absichtlich:
|
||||
|
||||
* Nur **Verzeichniskonten**. Ein lokales Konto (etwa das, das
|
||||
``tesm-admin create-admin`` anlegt) bleibt unberuehrt -- es ist der
|
||||
Notausgang, wenn das Verzeichnis nicht erreichbar ist.
|
||||
* Nie den letzten entsperrten Administrator herunterstufen. Ein
|
||||
Tippfehler im DN wuerde sonst beim naechsten Login die Anlage
|
||||
verschliessen, und niemand koennte ihn korrigieren.
|
||||
"""
|
||||
zuordnungen = [row for row in mappings if int(row["grants_admin"] or 0) == 1]
|
||||
if not zuordnungen:
|
||||
return
|
||||
soll = any(str(row["ad_group_dn"]).lower() in gruppen for row in zuordnungen)
|
||||
zeile = Database.one(
|
||||
conn, "SELECT is_admin, auth_source FROM users WHERE id=?", (user_id,)
|
||||
)
|
||||
if zeile is None or str(zeile["auth_source"]) != "ldap":
|
||||
return
|
||||
ist = bool(zeile["is_admin"])
|
||||
if ist == soll:
|
||||
return
|
||||
if not soll:
|
||||
uebrig = Database.value(
|
||||
conn,
|
||||
"SELECT COUNT(*) FROM users WHERE is_admin=1 AND is_locked=0 "
|
||||
"AND deleted_at IS NULL AND id<>?",
|
||||
(user_id,),
|
||||
default=0,
|
||||
)
|
||||
if not uebrig:
|
||||
logger.warning(
|
||||
"Administratorkennzeichen bleibt bei Benutzer %s: es waere das letzte.",
|
||||
user_id,
|
||||
)
|
||||
return
|
||||
conn.execute(
|
||||
"UPDATE users SET is_admin=?, updated_at=? WHERE id=?", (int(soll), _now(), user_id)
|
||||
)
|
||||
audit.log(
|
||||
conn,
|
||||
actor="system",
|
||||
action="auth.admin_flag_changed",
|
||||
target=str(user_id),
|
||||
detail=(
|
||||
"Administrator: "
|
||||
+ ("nein -> ja" if soll else "ja -> nein")
|
||||
+ " (aus der Verzeichniszuordnung)"
|
||||
),
|
||||
severity="warning",
|
||||
)
|
||||
|
||||
|
||||
def _user_group_ids(conn: sqlite3.Connection, user_id: int) -> list[dict[str, Any]]:
|
||||
return Database.all(conn, "SELECT group_id AS id FROM user_groups WHERE user_id=?", (user_id,))
|
||||
|
||||
|
||||
@@ -77,25 +77,40 @@ class User:
|
||||
|
||||
@property
|
||||
def effective_permissions(self) -> frozenset[str]:
|
||||
"""Rechte nach Anwendung der Bereichs-Kill-Switches."""
|
||||
"""Rechte nach Anwendung der Bereichs-Kill-Switches.
|
||||
|
||||
Ein echter Administrator hat den Verwaltungsbereich immer dabei -- auch
|
||||
ohne Gruppe und ohne dass jemand ihn angehakt haette. Sonst koennte
|
||||
sich das letzte Administratorkonto aus der eigenen Anlage aussperren,
|
||||
indem es seine Gruppe verliert.
|
||||
"""
|
||||
if self._effective is None:
|
||||
tree = self._tree
|
||||
self._effective = (
|
||||
frozenset(tree.effective(self.granted)) if tree is not None else frozenset()
|
||||
)
|
||||
if tree is None:
|
||||
self._effective = frozenset()
|
||||
else:
|
||||
eigene = set(tree.effective(self.granted))
|
||||
if self.is_admin:
|
||||
eigene |= set(tree.verwaltungsrechte())
|
||||
self._effective = frozenset(eigene)
|
||||
return self._effective
|
||||
|
||||
def has(self, *permissions: str) -> bool:
|
||||
"""True, wenn **alle** angegebenen Rechte greifen. Admins duerfen immer alles."""
|
||||
if self.is_admin:
|
||||
return True
|
||||
"""True, wenn **alle** angegebenen Rechte greifen.
|
||||
|
||||
Das Administratorkennzeichen gibt seit 2.8.0 **den Verwaltungsbereich**
|
||||
frei und nicht mehr jede Pruefung: Benutzer, Gruppen, Einstellungen,
|
||||
Sicherung, Papierkorb, Diagnose. Funktionsrechte -- Geraete, Neustarts,
|
||||
DHCP, Freigaben -- kommen ueber Gruppen, und die darf sich ein
|
||||
Administrator selbst zuweisen. Der Unterschied ist nicht, *ob* er sie
|
||||
bekommen kann, sondern dass es dann eine Zeile im
|
||||
Aenderungsprotokoll gibt und in der Matrix zu sehen ist.
|
||||
"""
|
||||
if not permissions:
|
||||
return True
|
||||
return all(permission in self.effective_permissions for permission in permissions)
|
||||
|
||||
def has_any(self, permissions: Iterable[str]) -> bool:
|
||||
if self.is_admin:
|
||||
return True
|
||||
effective = self.effective_permissions
|
||||
return any(permission in effective for permission in permissions)
|
||||
|
||||
@@ -220,6 +235,66 @@ def login_required(view: Callable[..., Any]) -> Callable[..., Any]:
|
||||
return wrapper
|
||||
|
||||
|
||||
def _verlangt_wiederanmeldung(permission: str) -> bool:
|
||||
"""Fragt das Rechtemodell -- ausserhalb einer Anwendung nie."""
|
||||
try:
|
||||
from ..extension import core
|
||||
|
||||
return bool(core().permissions.verlangt_wiederanmeldung(permission))
|
||||
except Exception: # noqa: BLE001 - ohne Modell keine zusaetzliche Huerde
|
||||
return False
|
||||
|
||||
|
||||
def _wiederanmeldung_frisch() -> bool:
|
||||
from .service import reauth_is_fresh # zyklischen Import vermeiden
|
||||
|
||||
return reauth_is_fresh()
|
||||
|
||||
|
||||
def _bitte_bestaetigen(permission: str) -> Any:
|
||||
"""Zur Passwortbestaetigung schicken -- oder es einem Skript sagen.
|
||||
|
||||
Ein Aufruf per fetch bekaeme sonst die Anmeldeseite als Antwort und wuesste
|
||||
nichts damit anzufangen.
|
||||
"""
|
||||
if is_automatic(request) or (
|
||||
request.accept_mimetypes.accept_json and not request.accept_mimetypes.accept_html
|
||||
):
|
||||
abort(403, description="Bitte bestätigen Sie zur Sicherheit Ihr Passwort.")
|
||||
session["_after_reauth"] = request.full_path if request.query_string else request.path
|
||||
flash("Bitte bestätigen Sie zur Sicherheit Ihr Passwort.", "info")
|
||||
return redirect(url_for("auth.reauth"))
|
||||
|
||||
|
||||
def _heikel(permissions: tuple[str, ...], mode: str) -> str:
|
||||
"""Welches Recht verlangt hier eine frische Bestaetigung? Sonst leer.
|
||||
|
||||
Bei ``mode="all"`` ist die Antwort einfach: jedes genannte Recht wird
|
||||
gebraucht, also zaehlt jedes heikle darunter.
|
||||
|
||||
Bei ``mode="any"`` nicht. Diese Seiten nennen mehrere **unabhaengige**
|
||||
Wege hinein, und welcher genommen wird, entscheidet das Konto. Der
|
||||
Protokollverlauf etwa nennt "logs_history.read" und "logs_history.export":
|
||||
lesen ist harmlos, mitnehmen nicht. Gezaehlt wurde aber ueber alle
|
||||
genannten Rechte -- und so verlangte das blosse **Ansehen** des Verlaufs
|
||||
nach fuenfzehn Minuten eine Passworteingabe, mit dem Hinweis, man greife
|
||||
auf einen Datenexport zu. Das stimmte nicht, und wer es dreimal liest,
|
||||
glaubt die Meldung beim vierten Mal auch dann nicht, wenn sie zutrifft.
|
||||
|
||||
Gefragt wird deshalb: haette dieses Konto die Seite auch ohne das heikle
|
||||
Recht geoeffnet? Dann gibt es nichts zu bestaetigen. Die Ausfuhr selbst
|
||||
haengt an ihrer eigenen Route, und die nennt nur ein Recht.
|
||||
"""
|
||||
heikle = [p for p in permissions if _verlangt_wiederanmeldung(p)]
|
||||
if not heikle:
|
||||
return ""
|
||||
if mode == "any":
|
||||
harmlos = [p for p in permissions if p not in heikle]
|
||||
if any(current_user.has(p) for p in harmlos):
|
||||
return ""
|
||||
return heikle[0]
|
||||
|
||||
|
||||
def permission_required(*permissions: str, mode: str = "all") -> Callable[..., Any]:
|
||||
"""Erzwingt Rechte serverseitig.
|
||||
|
||||
@@ -237,7 +312,15 @@ def permission_required(*permissions: str, mode: str = "all") -> Callable[..., A
|
||||
else current_user.has(*permissions)
|
||||
)
|
||||
if not ok:
|
||||
return _deny("Fuer diese Seite fehlt Ihnen die Berechtigung.")
|
||||
return _deny("Für diese Seite fehlt Ihnen die Berechtigung.")
|
||||
# Geheimnisse und Exporte verlangen eine frische Bestaetigung --
|
||||
# das steht im Rechtemodell und wird deshalb hier abgefragt, nicht
|
||||
# in jeder Route einzeln. Vorher hing es daran, dass jemand an den
|
||||
# Dekorator dachte: dieselbe Lizenz herunterzuladen fragte nach,
|
||||
# sie per Mail zu verschicken nicht.
|
||||
heikel = _heikel(permissions, mode)
|
||||
if heikel and not _wiederanmeldung_frisch():
|
||||
return _bitte_bestaetigen(heikel)
|
||||
return view(*args, **kwargs)
|
||||
|
||||
wrapper._required_permissions = permissions # type: ignore[attr-defined]
|
||||
@@ -279,7 +362,7 @@ def reauth_required(view: Callable[..., Any]) -> Callable[..., Any]:
|
||||
return _deny("Anmeldung erforderlich.")
|
||||
if not reauth_is_fresh():
|
||||
session["_after_reauth"] = request.full_path if request.query_string else request.path
|
||||
flash("Bitte bestaetigen Sie zur Sicherheit Ihr Passwort.", "info")
|
||||
flash("Bitte bestätigen Sie zur Sicherheit Ihr Passwort.", "info")
|
||||
return redirect(url_for("auth.reauth"))
|
||||
return view(*args, **kwargs)
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ def login():
|
||||
)
|
||||
|
||||
|
||||
@bp.route("/login/zweiter-faktor", methods=["GET", "POST"])
|
||||
@bp.route("/login/second-factor", methods=["GET", "POST"])
|
||||
def second_factor():
|
||||
conn = db()
|
||||
user_row = service.pending_totp_user(conn)
|
||||
@@ -116,7 +116,7 @@ def logout_get():
|
||||
return redirect(url_for("auth.login"))
|
||||
|
||||
|
||||
@bp.route("/bestaetigen", methods=["GET", "POST"])
|
||||
@bp.route("/confirm", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def reauth():
|
||||
target = _safe_next(session.get("_after_reauth"))
|
||||
|
||||
@@ -151,7 +151,7 @@ def authenticate(
|
||||
if ip_verdict.blocked:
|
||||
return AuthOutcome(
|
||||
"rate_limited",
|
||||
"Zu viele Anmeldeversuche von dieser Adresse. Bitte spaeter erneut versuchen.",
|
||||
"Zu viele Anmeldeversuche von dieser Adresse. Bitte später erneut versuchen.",
|
||||
retry_after=ip_verdict.retry_after_seconds,
|
||||
)
|
||||
|
||||
@@ -165,7 +165,7 @@ def authenticate(
|
||||
if user_verdict.blocked:
|
||||
return AuthOutcome(
|
||||
"rate_limited",
|
||||
"Dieses Konto ist nach mehreren Fehlversuchen voruebergehend gesperrt.",
|
||||
"Dieses Konto ist nach mehreren Fehlversuchen vorübergehend gesperrt.",
|
||||
retry_after=user_verdict.retry_after_seconds,
|
||||
)
|
||||
|
||||
@@ -248,7 +248,7 @@ def _verify_credentials(
|
||||
return AuthOutcome(
|
||||
"directory_unavailable",
|
||||
"Der Verzeichnisdienst ist derzeit nicht erreichbar. "
|
||||
"Bitte versuchen Sie es spaeter erneut.",
|
||||
"Bitte versuchen Sie es später erneut.",
|
||||
)
|
||||
if result.status != "ok" or result.profile is None:
|
||||
return AuthOutcome("invalid", GENERIC_FAILURE)
|
||||
@@ -257,6 +257,24 @@ def _verify_credentials(
|
||||
return AuthOutcome("ok", user_row=user_row, group_dns=result.profile.group_dns)
|
||||
|
||||
|
||||
|
||||
def _ist_erstanmeldung(user_row: dict[str, Any]) -> bool:
|
||||
"""Meldet sich dieses Konto zum ersten Mal ueberhaupt an?
|
||||
|
||||
Das Aenderungsprotokoll soll Aenderungen zeigen. Eine taegliche Anmeldung
|
||||
ist keine -- sie erzeugte aber jedes Mal eine Zeile und schob damit echte
|
||||
Eintraege aus dem Blickfeld. Interessant ist genau die erste: mit ihr
|
||||
entsteht das Konto aus dem Verzeichnisdienst und betritt jemand die
|
||||
Anwendung, der vorher nicht darin war.
|
||||
|
||||
Nicht betroffen: fehlgeschlagene Anmeldungen und Sperren. Die stehen
|
||||
weiterhin **jedes Mal** im Protokoll -- dort liegt der sicherheitsrelevante
|
||||
Teil, und Haeufung ist dort das Signal. Wer wann zuletzt angemeldet war,
|
||||
steht ausserdem unveraendert am Konto und in der Sitzungsuebersicht.
|
||||
"""
|
||||
return not str(user_row.get("last_login_at") or "").strip()
|
||||
|
||||
|
||||
def complete_login(
|
||||
conn: sqlite3.Connection,
|
||||
user_row: dict[str, Any],
|
||||
@@ -275,21 +293,26 @@ def complete_login(
|
||||
"""
|
||||
from ..security import csrf
|
||||
|
||||
# Vor dem UPDATE lesen -- danach steht ueberall ein Zeitstempel.
|
||||
erstanmeldung = _ist_erstanmeldung(user_row)
|
||||
|
||||
with core().database.transaction(conn):
|
||||
session_store.rotate(conn, session, reason="login") # type: ignore[arg-type]
|
||||
conn.execute(
|
||||
"UPDATE users SET last_login_at=? WHERE id=?", (_iso(_now()), user_row["id"])
|
||||
)
|
||||
audit.log(
|
||||
conn,
|
||||
actor=str(user_row["username"]),
|
||||
actor_id=int(user_row["id"]),
|
||||
action="auth.login",
|
||||
target=str(user_row["username"]),
|
||||
detail=f"Quelle: {user_row.get('auth_source') or 'local'}",
|
||||
ip=ip,
|
||||
request_id=getattr(g, "request_id", ""),
|
||||
)
|
||||
if erstanmeldung:
|
||||
audit.log(
|
||||
conn,
|
||||
actor=str(user_row["username"]),
|
||||
actor_id=int(user_row["id"]),
|
||||
action="auth.first_login",
|
||||
target=str(user_row["username"]),
|
||||
detail=f"Erste Anmeldung | Quelle: {user_row.get('auth_source') or 'local'}",
|
||||
ip=ip,
|
||||
request_id=getattr(g, "request_id", ""),
|
||||
severity="notice",
|
||||
)
|
||||
|
||||
session.clear()
|
||||
session[SESSION_USER_KEY] = int(user_row["id"])
|
||||
@@ -336,15 +359,11 @@ def logout(conn: sqlite3.Connection) -> None:
|
||||
current_app.logger.exception(
|
||||
"Abmeldehaken %r fehlgeschlagen", getattr(hook, "__name__", hook)
|
||||
)
|
||||
with core().database.transaction(conn):
|
||||
audit.log(
|
||||
conn,
|
||||
actor=user.username,
|
||||
actor_id=user.id,
|
||||
action="auth.logout",
|
||||
target=user.username,
|
||||
ip=client_ip(),
|
||||
)
|
||||
# Kein Protokolleintrag fuer das Abmelden: eine Abmeldung aendert
|
||||
# nichts. Sie stand als "Info" in jeder zweiten Zeile und verdraengte
|
||||
# die Eintraege, um die es geht. Wer wissen will, wer wann da war,
|
||||
# liest die Sitzungsuebersicht; fehlgeschlagene Anmeldungen und
|
||||
# Sperren stehen weiterhin jedes Mal im Protokoll.
|
||||
session.destroy() if hasattr(session, "destroy") else session.clear() # type: ignore[attr-defined]
|
||||
g.user = ANONYMOUS
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ def _config_from_settings(extension: Any, conn: Any) -> webserver.WebConfig:
|
||||
],
|
||||
)
|
||||
return webserver.WebConfig(
|
||||
# Die neue Schreibweise, sobald der Webserver sie kennt.
|
||||
http2_directive=webserver.nginx_kann_http2(),
|
||||
app_key=extension.config.site_key,
|
||||
upstream=str(extension.registry.get("upstream", "127.0.0.1:5000")),
|
||||
static_root=str(
|
||||
@@ -83,7 +85,7 @@ def run_web_setup(app: Any, extension: Any, args: argparse.Namespace) -> int:
|
||||
port = getattr(args, flag, None)
|
||||
if port:
|
||||
if not 1 <= int(port) <= 65535:
|
||||
print(f"Ungueltiger Port: {port}", file=sys.stderr)
|
||||
print(f"Ungültiger Port: {port}", file=sys.stderr)
|
||||
return 2
|
||||
values[key] = int(port)
|
||||
|
||||
@@ -93,11 +95,11 @@ def run_web_setup(app: Any, extension: Any, args: argparse.Namespace) -> int:
|
||||
|
||||
# -- Zertifikat --------------------------------------------------- #
|
||||
config = _config_from_settings(extension, conn)
|
||||
cert: dict[str, Any] = {"ok": True, "message": "Zertifikat unveraendert."}
|
||||
cert: dict[str, Any] = {"ok": True, "message": "Zertifikat unverändert."}
|
||||
|
||||
if args.acme:
|
||||
if sysops is None or not sysops.available:
|
||||
print("Der Systemhelfer ist nicht verfuegbar.", file=sys.stderr)
|
||||
print("Der Systemhelfer ist nicht verfügbar.", file=sys.stderr)
|
||||
return 2
|
||||
cert = webserver.request_certificate(
|
||||
sysops,
|
||||
@@ -118,7 +120,7 @@ def run_web_setup(app: Any, extension: Any, args: argparse.Namespace) -> int:
|
||||
|
||||
if args.self_signed and not args.acme:
|
||||
if sysops is None or not sysops.available:
|
||||
print("Der Systemhelfer ist nicht verfuegbar.", file=sys.stderr)
|
||||
print("Der Systemhelfer ist nicht verfügbar.", file=sys.stderr)
|
||||
return 2
|
||||
suggested = webserver.local_names()
|
||||
cert = webserver.create_self_signed(
|
||||
@@ -144,7 +146,7 @@ def run_web_setup(app: Any, extension: Any, args: argparse.Namespace) -> int:
|
||||
if args.https:
|
||||
if not (config.cert_path and config.key_path):
|
||||
print(
|
||||
"HTTPS verlangt Zertifikat und Schluessel -- bitte --self-signed "
|
||||
"HTTPS verlangt Zertifikat und Schlüssel – bitte --self-signed "
|
||||
"oder --acme angeben.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
@@ -172,7 +174,7 @@ def run_web_setup(app: Any, extension: Any, args: argparse.Namespace) -> int:
|
||||
return 0
|
||||
|
||||
if sysops is None or not sysops.available:
|
||||
print("Der Systemhelfer ist nicht verfuegbar.", file=sys.stderr)
|
||||
print("Der Systemhelfer ist nicht verfügbar.", file=sys.stderr)
|
||||
return 2
|
||||
result = webserver.apply_config(sysops, rendered)
|
||||
print(result["message"])
|
||||
@@ -194,7 +196,7 @@ def add_web_setup(sub: Any, runner: Any) -> None:
|
||||
help="nginx und TLS einrichten (Port 80/443)",
|
||||
description=(
|
||||
"Setzt die Webserver-Einstellungen und erzeugt daraus die nginx-Site. "
|
||||
"Die Datei wird immer vollstaendig neu geschrieben -- eine von Hand "
|
||||
"Die Datei wird immer vollständig neu geschrieben – eine von Hand "
|
||||
"bearbeitete Site-Datei gibt es in diesem Projekt bewusst nicht."
|
||||
),
|
||||
)
|
||||
@@ -207,20 +209,20 @@ def add_web_setup(sub: Any, runner: Any) -> None:
|
||||
parser.add_argument(
|
||||
"--acme",
|
||||
action="store_true",
|
||||
help="Zertifikat per Let's Encrypt anfordern (Domain muss oeffentlich zeigen)",
|
||||
help="Zertifikat per Let's Encrypt anfordern (Domain muss öffentlich zeigen)",
|
||||
)
|
||||
parser.add_argument("--domain", help="Oeffentlicher Name dieser Installation")
|
||||
parser.add_argument("--acme-email", help="Kontaktadresse fuer Let's Encrypt")
|
||||
parser.add_argument("--domain", help="Öffentlicher Name dieser Installation")
|
||||
parser.add_argument("--acme-email", help="Kontaktadresse für Let's Encrypt")
|
||||
parser.add_argument("--hsts", action="store_true", help="HSTS-Header setzen")
|
||||
parser.add_argument(
|
||||
"--no-redirect",
|
||||
action="store_true",
|
||||
help="Port 80 nicht auf HTTPS umleiten (Sonderfall)",
|
||||
)
|
||||
parser.add_argument("--max-body-mb", type=int, help="Obergrenze fuer Uploads")
|
||||
parser.add_argument("--max-body-mb", type=int, help="Obergrenze für Uploads")
|
||||
parser.add_argument("--http-port", type=int, help="Abweichender HTTP-Port (Standard 80)")
|
||||
parser.add_argument("--https-port", type=int, help="Abweichender HTTPS-Port (Standard 443)")
|
||||
parser.add_argument("--apply", action="store_true", help="nginx schreiben, pruefen, neu laden")
|
||||
parser.add_argument("--apply", action="store_true", help="nginx schreiben, prüfen, neu laden")
|
||||
parser.add_argument(
|
||||
"--print-config", action="store_true", help="Nur die erzeugte Datei ausgeben"
|
||||
)
|
||||
|
||||
@@ -175,11 +175,11 @@ def load_core_config(
|
||||
|
||||
bind = (_env(env_prefix, "BIND") or default_bind).strip()
|
||||
if not re.fullmatch(r"[0-9A-Za-z_.\[\]:-]{1,80}:\d{1,5}", bind):
|
||||
raise ValueError(f"Ungueltige Bind-Adresse: {bind!r}")
|
||||
raise ValueError(f"Ungültige Bind-Adresse: {bind!r}")
|
||||
|
||||
site_key = (_env(env_prefix, "SITE_KEY") or app_key).strip().lower()
|
||||
if not re.fullmatch(r"[a-z0-9][a-z0-9-]{0,39}", site_key):
|
||||
raise ValueError(f"Ungueltiger SITE_KEY: {site_key!r}")
|
||||
raise ValueError(f"Ungültiger SITE_KEY: {site_key!r}")
|
||||
|
||||
return CoreConfig(
|
||||
app_key=app_key,
|
||||
|
||||
@@ -141,11 +141,16 @@ CREATE TABLE IF NOT EXISTS service_accounts (
|
||||
updated_at TEXT NOT NULL
|
||||
);
|
||||
|
||||
-- Eine Verzeichnisgruppe zeigt entweder auf eine lokale Gruppe **oder** auf
|
||||
-- das Administratorkennzeichen (grants_admin). Darum ist app_group_id
|
||||
-- nullbar: "Domänen-Admins" soll echte Administratoren erzeugen koennen und
|
||||
-- nicht nur Mitglieder der Gruppe "Administration".
|
||||
CREATE TABLE IF NOT EXISTS ldap_group_mappings (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
ad_group_dn TEXT NOT NULL UNIQUE,
|
||||
ad_group_name TEXT NOT NULL,
|
||||
app_group_id INTEGER NOT NULL REFERENCES groups(id) ON DELETE CASCADE,
|
||||
app_group_id INTEGER REFERENCES groups(id) ON DELETE CASCADE,
|
||||
grants_admin INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TEXT NOT NULL
|
||||
);
|
||||
"""
|
||||
@@ -186,8 +191,145 @@ CREATE INDEX IF NOT EXISTS idx_jobs_kind_state ON jobs(kind, state);
|
||||
CREATE INDEX IF NOT EXISTS idx_jobs_created ON jobs(created_at);
|
||||
"""
|
||||
|
||||
def benenne_rechte_um(conn) -> None: # type: ignore[no-untyped-def]
|
||||
"""Schreibt bestehende Gruppenrechte auf das neue Vokabular um.
|
||||
|
||||
``devices.view`` wird ``devices.read``, ``devices.edit`` wird
|
||||
``devices.write``. Ohne diesen Schritt stehen in den Gruppen nur noch
|
||||
Schluessel, die der Rechtebaum nicht kennt -- und
|
||||
:meth:`PermissionTree.sanitize` wirft Unbekanntes **still** weg. Nach dem
|
||||
Update waeren alle Gruppen leer und niemand kaeme mehr an seine Seiten:
|
||||
kein Fehler, den man sieht, sondern einer, den man erst merkt, wenn jemand
|
||||
anruft.
|
||||
|
||||
Im Kern und nicht in den Anwendungen, weil die Tabelle beiden gehoert.
|
||||
Idempotent: was schon neu heisst, wird nicht angefasst.
|
||||
"""
|
||||
from .rbac.legacy_permissions import UMBENANNTE_AKTIONEN
|
||||
|
||||
for alt, neu in UMBENANNTE_AKTIONEN.items():
|
||||
# Erst die Dubletten weg, die beim Umschreiben entstehen wuerden: haette
|
||||
# eine Gruppe (aus welchem Grund auch immer) beide Schluessel, brach der
|
||||
# eindeutige Index. Lieber vorher aufraeumen als in der Migration
|
||||
# scheitern.
|
||||
conn.execute(
|
||||
"DELETE FROM group_permissions WHERE permission LIKE ? AND EXISTS ("
|
||||
" SELECT 1 FROM group_permissions AS andere"
|
||||
" WHERE andere.group_id = group_permissions.group_id"
|
||||
" AND andere.permission = substr(group_permissions.permission, 1,"
|
||||
" length(group_permissions.permission) - ?) || ?)",
|
||||
(f"%.{alt}", len(alt), neu),
|
||||
)
|
||||
conn.execute(
|
||||
"UPDATE group_permissions"
|
||||
" SET permission = substr(permission, 1, length(permission) - ?) || ?"
|
||||
" WHERE permission LIKE ?",
|
||||
(len(alt), neu, f"%.{alt}"),
|
||||
)
|
||||
|
||||
|
||||
def zuordnung_auf_kennzeichen(conn) -> None: # type: ignore[no-untyped-def]
|
||||
"""Erlaubt einer Verzeichnisgruppe, das Administratorkennzeichen zu setzen.
|
||||
|
||||
Bisher konnte eine Zuordnung nur auf eine lokale Gruppe zeigen. "Domänen-
|
||||
Admins" landete deshalb in der Gruppe *Administration* -- und wurde damit
|
||||
gerade **kein** echter Administrator: die Gruppe pflegt Benutzer und
|
||||
Rechte, hat aber kein Kennzeichen und kann sich keines geben.
|
||||
|
||||
Zwei Aenderungen an der Tabelle, und SQLite kann Spalten nicht
|
||||
umdefinieren: also neu anlegen und umkopieren. ``app_group_id`` wird
|
||||
nullbar (eine Zuordnung auf das Kennzeichen zeigt auf keine Gruppe), und
|
||||
``grants_admin`` sagt, dass genau das gemeint ist.
|
||||
"""
|
||||
spalten = {
|
||||
str(zeile[1]) for zeile in conn.execute("PRAGMA table_info(ldap_group_mappings)")
|
||||
}
|
||||
if "grants_admin" in spalten:
|
||||
return
|
||||
conn.execute(
|
||||
"""
|
||||
CREATE TABLE ldap_group_mappings_neu (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
ad_group_dn TEXT NOT NULL UNIQUE,
|
||||
ad_group_name TEXT NOT NULL,
|
||||
app_group_id INTEGER REFERENCES groups(id) ON DELETE CASCADE,
|
||||
grants_admin INTEGER NOT NULL DEFAULT 0,
|
||||
created_at TEXT NOT NULL
|
||||
)
|
||||
"""
|
||||
)
|
||||
conn.execute(
|
||||
"INSERT INTO ldap_group_mappings_neu "
|
||||
"(id, ad_group_dn, ad_group_name, app_group_id, grants_admin, created_at) "
|
||||
"SELECT id, ad_group_dn, ad_group_name, app_group_id, 0, created_at "
|
||||
" FROM ldap_group_mappings"
|
||||
)
|
||||
conn.execute("DROP TABLE ldap_group_mappings")
|
||||
conn.execute("ALTER TABLE ldap_group_mappings_neu RENAME TO ldap_group_mappings")
|
||||
|
||||
|
||||
def teile_rechte_auf(conn) -> None: # type: ignore[no-untyped-def]
|
||||
"""Verteilt ein altes Sammelrecht auf die Zeilen, die daraus wurden.
|
||||
|
||||
Additiv: wer ``dhcp.edit`` hatte, bekommt alle fuenf DHCP-Zeilen, und das
|
||||
alte Recht verschwindet. Ohne diesen Schritt stuende in der Gruppe ein
|
||||
Schluessel, den der Baum nicht kennt -- und weg waere er still, denn genau
|
||||
das tut :meth:`PermissionTree.sanitize` mit Unbekanntem.
|
||||
|
||||
Laeuft nach ``benenne_rechte_um``: die Tabelle nennt beide Schreibweisen,
|
||||
wo es darauf ankommt, und ein zweiter Lauf findet nichts mehr zu tun.
|
||||
"""
|
||||
from .rbac.legacy_permissions import (
|
||||
ERWEITERTE_RECHTE,
|
||||
GETEILTE_RECHTE,
|
||||
neue_schluessel,
|
||||
)
|
||||
|
||||
def gruppen_mit(recht: str) -> list[int]:
|
||||
return [
|
||||
int(zeile[0])
|
||||
for zeile in conn.execute(
|
||||
"SELECT DISTINCT group_id FROM group_permissions WHERE permission=?",
|
||||
(recht,),
|
||||
).fetchall()
|
||||
]
|
||||
|
||||
# Geteilt: das alte Recht gibt es nicht mehr, also ersetzen.
|
||||
for altes, neue in GETEILTE_RECHTE.items():
|
||||
gruppen = gruppen_mit(altes)
|
||||
if not gruppen:
|
||||
continue
|
||||
conn.executemany(
|
||||
"INSERT OR IGNORE INTO group_permissions (group_id, permission) VALUES (?,?)",
|
||||
[(gid, recht) for gid in gruppen for recht in neue],
|
||||
)
|
||||
conn.execute("DELETE FROM group_permissions WHERE permission=?", (altes,))
|
||||
|
||||
# Erweitert: das Recht bleibt und bekommt dazu, was bisher an ihm hing.
|
||||
# Loeschen waere hier falsch -- es ist keines von gestern.
|
||||
for recht, dazu in ERWEITERTE_RECHTE.items():
|
||||
gruppen = gruppen_mit(recht)
|
||||
if not gruppen:
|
||||
continue
|
||||
conn.executemany(
|
||||
"INSERT OR IGNORE INTO group_permissions (group_id, permission) VALUES (?,?)",
|
||||
[(gid, weiteres) for gid in gruppen for weiteres in dazu],
|
||||
)
|
||||
assert neue_schluessel # in derselben Tabelle nachgeschlagen wie beim Import
|
||||
|
||||
|
||||
CORE_MIGRATIONS: tuple[Migration, ...] = (
|
||||
Migration(version=1, name="baseline", sql=V1_BASELINE),
|
||||
Migration(
|
||||
version=1,
|
||||
name="baseline",
|
||||
sql=V1_BASELINE,
|
||||
geaendert_weil=(
|
||||
"Das Grundschema legt ldap_group_mappings jetzt mit grants_admin und nullbarer app_group_id an -- eine neue Installation soll nicht erst core/6 brauchen, um die Tabelle wieder umzubauen."
|
||||
),
|
||||
),
|
||||
Migration(version=2, name="trusted-issuer-keys", sql=V2_TRUSTED_KEYS),
|
||||
Migration(version=3, name="jobs", sql=V3_JOBS),
|
||||
Migration(version=4, name="rechte-read-write", fn=benenne_rechte_um),
|
||||
Migration(version=5, name="rechte-je-funktion", fn=teile_rechte_auf),
|
||||
Migration(version=6, name="ldap-kennzeichen", fn=zuordnung_auf_kennzeichen),
|
||||
)
|
||||
@@ -80,8 +80,8 @@ class Database:
|
||||
"""Oeffnet eine neue Verbindung. Nicht aufrufen, solange eine Transaktion laeuft."""
|
||||
if self._depth() > 0:
|
||||
raise NestedConnectionError(
|
||||
"Es laeuft bereits eine Schreibtransaktion auf dieser Datenbank. "
|
||||
"Reiche die bestehende Verbindung durch, statt eine neue zu oeffnen "
|
||||
"Es läuft bereits eine Schreibtransaktion auf dieser Datenbank. "
|
||||
"Reiche die bestehende Verbindung durch, statt eine neue zu öffnen "
|
||||
"(sonst blockiert SQLite sich selbst)."
|
||||
)
|
||||
return self._raw_connect()
|
||||
@@ -119,6 +119,29 @@ class Database:
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
@contextmanager
|
||||
def dauerhaft(self, conn: sqlite3.Connection) -> Iterator[sqlite3.Connection]:
|
||||
"""Fuer Schreibvorgaenge, die einen Stromausfall ueberstehen muessen.
|
||||
|
||||
Im Alltag laeuft die Datenbank mit ``synchronous=NORMAL``: schnell, und
|
||||
bei einem Stromausfall gehen hoechstens die letzten Sekunden verloren --
|
||||
die Datei bleibt heil. Fuer einen Messwert ist das genau richtig.
|
||||
|
||||
Fuer eine Unterschrift nicht. Dort liegt die Datei anschliessend auf der
|
||||
Freigabe, und fehlte der Eintrag dazu, waere sie "unbekannt" statt
|
||||
nachweisbar. Ein fsync kostet ein paar Millisekunden -- bei ein paar
|
||||
Unterschriften am Tag ist das keine Diskussion wert.
|
||||
|
||||
Umschliesst die Transaktion, nicht umgekehrt: ``PRAGMA synchronous``
|
||||
wirkt auf den naechsten Commit, und gesetzt werden kann es nur
|
||||
ausserhalb einer laufenden Transaktion.
|
||||
"""
|
||||
conn.execute("PRAGMA synchronous=FULL")
|
||||
try:
|
||||
yield conn
|
||||
finally:
|
||||
conn.execute("PRAGMA synchronous=NORMAL")
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Transaktionen
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
@@ -79,7 +79,7 @@ def core(app: Flask | None = None) -> TesmCore:
|
||||
try:
|
||||
return target.extensions["tesm"] # type: ignore[return-value]
|
||||
except KeyError as exc: # pragma: no cover - Programmierfehler
|
||||
raise RuntimeError("tesm_core ist fuer diese Anwendung nicht initialisiert") from exc
|
||||
raise RuntimeError("tesm_core ist für diese Anwendung nicht initialisiert") from exc
|
||||
|
||||
|
||||
def db() -> sqlite3.Connection:
|
||||
|
||||
@@ -78,7 +78,7 @@ def check_private_file(path: Path) -> list[str]:
|
||||
except OSError:
|
||||
return problems
|
||||
if mode & (stat.S_IRGRP | stat.S_IROTH | stat.S_IWGRP | stat.S_IWOTH):
|
||||
problems.append(f"{path} ist fuer Gruppe/Andere lesbar oder schreibbar (erwartet 0600)")
|
||||
problems.append(f"{path} ist für Gruppe/Andere lesbar oder schreibbar (erwartet 0600)")
|
||||
return problems
|
||||
|
||||
|
||||
@@ -110,11 +110,11 @@ class Keystore:
|
||||
created_at=str(entry.get("created_at", "")),
|
||||
)
|
||||
if len(key.material) != _KEY_BYTES:
|
||||
raise ValueError(f"Schluessel {key.key_id} hat die falsche Laenge")
|
||||
raise ValueError(f"Schlüssel {key.key_id} hat die falsche Länge")
|
||||
self._keys[key.key_id] = key
|
||||
self._active = str(raw.get("active") or "")
|
||||
if self._active not in self._keys:
|
||||
raise ValueError("Aktiver Schluessel fehlt im Schluesselbund")
|
||||
raise ValueError("Aktiver Schlüssel fehlt im Schlüsselbund")
|
||||
return
|
||||
self._active = "1"
|
||||
self._keys = {
|
||||
@@ -160,7 +160,7 @@ class Keystore:
|
||||
def drop_key(self, key_id: str) -> None:
|
||||
"""Entfernt einen alten Schluessel -- erst nach vollstaendiger Neuverschluesselung."""
|
||||
if key_id == self._active:
|
||||
raise ValueError("Der aktive Schluessel kann nicht entfernt werden")
|
||||
raise ValueError("Der aktive Schlüssel kann nicht entfernt werden")
|
||||
self._keys.pop(key_id, None)
|
||||
self._persist()
|
||||
|
||||
@@ -183,14 +183,14 @@ class Keystore:
|
||||
raise DecryptionError(f"Unbekannte Chiffrat-Version: {prefix!r}")
|
||||
key = self._keys.get(key_id)
|
||||
if key is None:
|
||||
raise DecryptionError(f"Schluessel {key_id} ist nicht im Schluesselbund")
|
||||
raise DecryptionError(f"Schlüssel {key_id} ist nicht im Schlüsselbund")
|
||||
try:
|
||||
plain = AESGCM(key.material).decrypt(
|
||||
_b64d(nonce_b64), _b64d(ct_b64), aad.encode("utf-8")
|
||||
)
|
||||
except (InvalidTag, ValueError) as exc:
|
||||
raise DecryptionError(
|
||||
"Chiffrat konnte nicht entschluesselt werden (falscher Schluessel, "
|
||||
"Chiffrat konnte nicht entschlüsselt werden (falscher Schlüssel, "
|
||||
"manipulierte Daten oder falscher Verwendungszweck)"
|
||||
) from exc
|
||||
return plain.decode("utf-8")
|
||||
|
||||
@@ -0,0 +1,242 @@
|
||||
"""Alte, deutsche Adressen auf die neuen englischen umlenken.
|
||||
|
||||
Mit 2.5.0 folgen die Adressen der Navigation und sind englisch:
|
||||
``/monitoring/host-keys`` statt ``/hostschluessel``. Das ist eine gute
|
||||
Aenderung und eine unangenehme zugleich -- Lesezeichen, offene Browsertabs und
|
||||
ein Link in einer Mail zeigen weiter auf die alte Adresse. Ein offener Tab ist
|
||||
dabei der unangenehmste Fall: die Statusuebersicht fragt alle 20 Sekunden ihre
|
||||
Kacheln ab und bekam nach dem Update jedes Mal einen 404.
|
||||
|
||||
Deshalb diese Tabelle. Sie greift **nur, wenn sonst ein 404 herauskaeme** --
|
||||
also nie vor einer bestehenden Route. Das ist keine Feinheit: auf dem
|
||||
Lizenzserver ist ``/lizenz/<ticket>`` eine echte, weiterhin gueltige Adresse
|
||||
(sie steht in verschickten Mails), waehrend dieselbe Wurzel in TESM zur
|
||||
Lizenzseite fuehrte. Wer zuerst das Routing fragt, muss sich nicht zwischen
|
||||
beidem entscheiden.
|
||||
|
||||
Die Tabelle ist bewusst vollstaendig und nicht nur auf Wurzeln gekuerzt: eine
|
||||
Umleitung von ``/dateifreigaben/x/vorschau`` auf eine Uebersichtsseite waere
|
||||
zwar kein 404 mehr, aber auch nicht das, was jemand angeklickt hat.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Mapping
|
||||
|
||||
#: Alte Wurzel -> (neue Wurzel, Uebersetzung der Segmente darunter).
|
||||
WURZELN: dict[str, tuple[str, Mapping[str, str]]] = {
|
||||
"/dateifreigaben": (
|
||||
"/fileshares",
|
||||
{
|
||||
"herunterladen": "download",
|
||||
"vorschau": "preview",
|
||||
"hochladen": "upload",
|
||||
"formular": "form",
|
||||
"ordner": "folder",
|
||||
"umbenennen": "rename",
|
||||
"loeschen": "delete",
|
||||
"freigeben": "release",
|
||||
"zuordnungen": "mappings",
|
||||
},
|
||||
),
|
||||
"/hostschluessel": (
|
||||
"/monitoring/host-keys",
|
||||
{"pruefen": "probe", "freigeben": "trust", "verwerfen": "forget", "verwaist": "orphaned"},
|
||||
),
|
||||
"/zugangsdaten": (
|
||||
"/monitoring/credentials",
|
||||
{"neu": "new", "loeschen": "delete", "anzeigen": "reveal"},
|
||||
),
|
||||
"/switche": (
|
||||
"/monitoring/switches",
|
||||
{
|
||||
"neu": "new",
|
||||
"loeschen": "delete",
|
||||
"hostkey": "host-key",
|
||||
"pruefen": "probe",
|
||||
"freigeben": "trust",
|
||||
"verwerfen": "forget",
|
||||
"kommando": "command",
|
||||
"konsole": "console",
|
||||
},
|
||||
),
|
||||
"/clients": (
|
||||
"/monitoring/clients",
|
||||
{
|
||||
"neu": "new",
|
||||
"aktiv": "active",
|
||||
"loeschen": "delete",
|
||||
"neustart": "restart",
|
||||
"hostkey": "host-key",
|
||||
"pruefen": "probe",
|
||||
"freigeben": "trust",
|
||||
"verwerfen": "forget",
|
||||
"konsole": "console",
|
||||
},
|
||||
),
|
||||
"/wartung": (
|
||||
"/maintenance",
|
||||
{
|
||||
"paket-nachinstallieren": "install-package",
|
||||
"auftrag": "job",
|
||||
"ausgabe": "output",
|
||||
"aktualisieren": "update",
|
||||
"neustarten": "restart",
|
||||
},
|
||||
),
|
||||
"/protokolle": (
|
||||
"/logs",
|
||||
{
|
||||
"kea": "dhcp",
|
||||
"neustarts": "restarts",
|
||||
"laufend": "live",
|
||||
"inhalt": "content",
|
||||
"verlauf": "history",
|
||||
"datei": "file",
|
||||
"archiv": "archive",
|
||||
"archiv-export": "archive-export",
|
||||
"archiv-loeschen": "archive-delete",
|
||||
"aenderungen": "audit",
|
||||
},
|
||||
),
|
||||
"/verwaltung": (
|
||||
"/administration",
|
||||
{
|
||||
"benutzer": "users",
|
||||
"neu": "new",
|
||||
"loeschen": "delete",
|
||||
"sitzungen-beenden": "end-sessions",
|
||||
"verzeichnis-suche": "directory-search",
|
||||
"verzeichnis-uebernehmen": "directory-import",
|
||||
"gruppen": "groups",
|
||||
"vorlage-anwenden": "apply-preset",
|
||||
"sitzungen": "sessions",
|
||||
"beenden": "end",
|
||||
},
|
||||
),
|
||||
"/einstellungen": (
|
||||
"/administration",
|
||||
{
|
||||
"zeitzone": "timezone",
|
||||
"pruefung-jetzt": "check-now",
|
||||
"netzwerk": "network",
|
||||
"bestaetigen": "confirm",
|
||||
"webserver": "web",
|
||||
"uebernehmen": "apply",
|
||||
"zertifikat": "certificate",
|
||||
"selbstsigniert": "self-signed",
|
||||
"verzeichnisdienst": "directory",
|
||||
"gruppensuche": "group-search",
|
||||
"zuordnung": "mapping",
|
||||
"loeschen": "delete",
|
||||
"anbieter": "vendor",
|
||||
"logo-entfernen": "remove-logo",
|
||||
},
|
||||
),
|
||||
"/sicherung": (
|
||||
"/administration/backup",
|
||||
{"vorschau": "preview", "uebernehmen": "apply", "verwerfen": "discard"},
|
||||
),
|
||||
"/papierkorb": (
|
||||
"/administration/trash",
|
||||
{"wiederherstellen": "restore", "endgueltig-loeschen": "purge", "leeren": "empty"},
|
||||
),
|
||||
"/diagnose": (
|
||||
"/administration/diagnostics",
|
||||
{"aufraeumen": "cleanup", "schluessel-rotieren": "rotate-keys"},
|
||||
),
|
||||
"/eigene-lizenz": (
|
||||
"/own-license",
|
||||
{
|
||||
"einspielen": "install",
|
||||
"aktivieren": "activate",
|
||||
"deaktivieren": "deactivate",
|
||||
"offline-antwort": "offline-response",
|
||||
"signaturschluessel": "signing-key",
|
||||
},
|
||||
),
|
||||
"/lizenzen": (
|
||||
"/licenses",
|
||||
{
|
||||
"aus-ticket": "from-ticket",
|
||||
"datei": "file",
|
||||
"neu-signieren": "resign",
|
||||
"widerrufen": "revoke",
|
||||
"loeschen": "delete",
|
||||
"versenden": "send",
|
||||
"sub-lizenzserver": "sub-servers",
|
||||
},
|
||||
),
|
||||
"/lizenz": (
|
||||
"/administration/license",
|
||||
{
|
||||
"einspielen": "install",
|
||||
"aktivieren": "activate",
|
||||
"deaktivieren": "deactivate",
|
||||
"offline-antwort": "offline-response",
|
||||
"serverzertifikat": "server-certificate",
|
||||
"aussteller": "issuer",
|
||||
"entfernen": "remove",
|
||||
},
|
||||
),
|
||||
"/kunden": ("/customers", {"neu": "new", "loeschen": "delete"}),
|
||||
"/konto": (
|
||||
"/account",
|
||||
{
|
||||
"stammdaten": "profile",
|
||||
"profilbild": "avatar",
|
||||
"sicherheit": "security",
|
||||
"passwort": "password",
|
||||
"zwei-faktor": "two-factor",
|
||||
"starten": "start",
|
||||
"bestaetigen": "confirm",
|
||||
"deaktivieren": "disable",
|
||||
"codes-erneuern": "recovery-codes",
|
||||
"sitzungen": "sessions",
|
||||
"beenden": "end",
|
||||
"alle-beenden": "end-all",
|
||||
},
|
||||
),
|
||||
"/uebersicht": ("/overview", {"kacheln": "tiles"}),
|
||||
"/gesundheit": ("/health", {}),
|
||||
"/bestaetigen": ("/confirm", {}),
|
||||
}
|
||||
|
||||
#: Abfrageparameter, die mit umbenannt wurden.
|
||||
PARAMETER = {
|
||||
"freigabe": "share",
|
||||
"pfad": "path",
|
||||
"aktion": "action",
|
||||
"benutzer": "actor",
|
||||
"stufe": "severity",
|
||||
"seite": "page",
|
||||
"methode": "method",
|
||||
"kunde": "customer",
|
||||
"freischalten": "unlocked",
|
||||
}
|
||||
|
||||
|
||||
#: Wurzeln, unter denen eine unbekannte Unterseite **nicht** umgelenkt wird.
|
||||
#: ``/lizenz/<ticket>`` ist auf dem Lizenzserver eine echte Adresse; ein
|
||||
#: abgelaufenes oder falsches Ticket gehoert dort auf die Fehlerseite und nicht
|
||||
#: in die Verwaltung.
|
||||
STRENG = {"/lizenz"}
|
||||
|
||||
|
||||
def neue_adresse(pfad: str) -> str | None:
|
||||
"""Uebersetzt eine alte Adresse -- oder ``None``, wenn es keine ist."""
|
||||
for alt, (neu, segmente) in WURZELN.items():
|
||||
if pfad != alt and not pfad.startswith(alt + "/"):
|
||||
continue
|
||||
rest = pfad[len(alt) :]
|
||||
teile = rest.split("/")
|
||||
if alt in STRENG:
|
||||
erstes = next((teil for teil in teile if teil), "")
|
||||
if erstes and erstes not in segmente:
|
||||
return None
|
||||
return neu + "/".join(segmente.get(teil, teil) for teil in teile)
|
||||
return None
|
||||
|
||||
|
||||
def neue_parameter(args: Mapping[str, str]) -> dict[str, str]:
|
||||
return {PARAMETER.get(name, name): wert for name, wert in args.items()}
|
||||
@@ -34,7 +34,7 @@ import urllib.request
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from typing import Any, Callable
|
||||
from typing import Any, Callable, Iterable
|
||||
|
||||
import tesm_licensing as lic
|
||||
|
||||
@@ -54,6 +54,21 @@ SETTING_HEARTBEAT_ERROR = "license_heartbeat_error"
|
||||
EXPIRY_HINT_DAYS = 90
|
||||
SETTING_EXPORT_GRACE = "license_export_grace"
|
||||
|
||||
#: Module, die der Betreiber vor Ort abgeschaltet hat (Liste von Namen).
|
||||
#:
|
||||
#: Die Lizenz sagt, *was erlaubt ist*; sie sagt nicht, was ein Haus auch
|
||||
#: benutzen will. Wer kein DHCP ueber TESM fahren will, weil ein anderer Server
|
||||
#: das tut, soll den Punkt nicht wegdruecken muessen -- und vor allem soll
|
||||
#: niemand versehentlich eine fremde Kea-Konfiguration ueberschreiben koennen.
|
||||
#: Abschalten ist deshalb mehr als Aufraeumen der Navigation: die Sperre sitzt
|
||||
#: an derselben Stelle wie die Lizenzpruefung, also vor jeder Route.
|
||||
#: Bewusst **ohne** das Praefix ``license_``: Sicherungen lassen alles mit
|
||||
#: diesem Praefix draussen, weil Lizenz- und Aktivierungszustand zur Maschine
|
||||
#: gehoeren und nicht in ein Backup. Der Schalter ist aber keine Lizenzangabe,
|
||||
#: sondern eine Entscheidung des Hauses -- die soll eine Wiederherstellung
|
||||
#: mitbringen.
|
||||
SETTING_MODULES_OFF = "modules_disabled"
|
||||
|
||||
STATUS_INACTIVE = "inactive"
|
||||
STATUS_PENDING = "pending"
|
||||
STATUS_ACTIVE = "active"
|
||||
@@ -68,10 +83,10 @@ API_PATHS = {
|
||||
#: die einzige Wahrheit -- Templates lesen sie, Routen erzwingen sie.
|
||||
LICENSED_FEATURES: dict[str, str] = {
|
||||
"directory": "Verzeichnisanmeldung (LDAP/AD) konfigurieren",
|
||||
"nginx": "Webserver-Einstellungen aendern",
|
||||
"nginx": "Webserver-Einstellungen ändern",
|
||||
"export": "Daten exportieren",
|
||||
"trash_restore": "Papierkorb wiederherstellen und endgueltig loeschen",
|
||||
"monitor_interval": "Pruefintervall der Ueberwachung aendern",
|
||||
"trash_restore": "Papierkorb wiederherstellen und endgültig löschen",
|
||||
"monitor_interval": "Prüfintervall der Überwachung ändern",
|
||||
"auto_poe_restart": "Automatischer PoE-Neustart bei Ausfall",
|
||||
}
|
||||
|
||||
@@ -85,7 +100,7 @@ def describe_transport_error(exc: BaseException, endpoint: str) -> str:
|
||||
"""
|
||||
text = str(exc)
|
||||
if "CERTIFICATE_VERIFY_FAILED" in text or "certificate verify failed" in text:
|
||||
detail = "Das Zertifikat konnte nicht geprueft werden"
|
||||
detail = "Das Zertifikat konnte nicht geprüft werden"
|
||||
if "self-signed" in text or "self signed" in text:
|
||||
detail = "Der Lizenzserver benutzt ein selbstsigniertes Zertifikat"
|
||||
return (
|
||||
@@ -94,7 +109,7 @@ def describe_transport_error(exc: BaseException, endpoint: str) -> str:
|
||||
"einer anerkannten Stelle."
|
||||
)
|
||||
if "Name or service not known" in text or "nodename nor servname" in text:
|
||||
return f"Der Name im Endpunkt ({endpoint}) laesst sich nicht aufloesen."
|
||||
return f"Der Name im Endpunkt ({endpoint}) lässt sich nicht auflösen."
|
||||
if "Connection refused" in text:
|
||||
return f"{endpoint} nimmt keine Verbindung an."
|
||||
if "timed out" in text or "timeout" in text.lower():
|
||||
@@ -121,6 +136,8 @@ class LicenseState:
|
||||
last_heartbeat_at: str = ""
|
||||
heartbeat_error: str = ""
|
||||
pending_action: str = ""
|
||||
#: Vor Ort abgeschaltet -- unabhaengig davon, was die Lizenz erlaubt.
|
||||
modules_off: frozenset[str] = frozenset()
|
||||
|
||||
@property
|
||||
def role(self) -> str:
|
||||
@@ -128,8 +145,14 @@ class LicenseState:
|
||||
|
||||
@property
|
||||
def modules(self) -> frozenset[str]:
|
||||
"""Was die Lizenz freischaltet -- ohne Ruecksicht auf den Schalter."""
|
||||
return self.status.modules if self.status else frozenset()
|
||||
|
||||
@property
|
||||
def modules_in_use(self) -> frozenset[str]:
|
||||
"""Was tatsaechlich laeuft: lizenziert **und** nicht abgeschaltet."""
|
||||
return self.modules - self.modules_off
|
||||
|
||||
@property
|
||||
def customer_name(self) -> str:
|
||||
return str((self.status.customer if self.status else {}).get("name") or "")
|
||||
@@ -179,6 +202,7 @@ class LicenseManager:
|
||||
"""Liest Lizenzdatei und Status neu ein."""
|
||||
with self._lock:
|
||||
state = LicenseState()
|
||||
state.modules_off = self.abgeschaltete_module(conn)
|
||||
state.last_heartbeat_at = str(self.settings.get(conn, SETTING_LAST_HEARTBEAT) or "")
|
||||
state.heartbeat_error = str(self.settings.get(conn, SETTING_HEARTBEAT_ERROR) or "")
|
||||
pending = self._pending(conn)
|
||||
@@ -239,9 +263,51 @@ class LicenseManager:
|
||||
)
|
||||
|
||||
def module_active(self, name: str) -> bool:
|
||||
"""Ist ein Vollmodul (dhcp/fileshare/maintenance) freigeschaltet?"""
|
||||
"""Ist ein Vollmodul (dhcp/fileshare/maintenance) in Betrieb?
|
||||
|
||||
Zwei Bedingungen, und beide muessen gelten: die Lizenz muss es
|
||||
freischalten, und der Betreiber darf es nicht abgeschaltet haben. Diese
|
||||
eine Funktion fragen die Navigation, jede Route und die Hintergrund-
|
||||
aufgaben -- darum sitzt der Schalter hier und nicht in einer Vorlage.
|
||||
"""
|
||||
return (
|
||||
self.active()
|
||||
and name in self._state.modules
|
||||
and name not in self._state.modules_off
|
||||
)
|
||||
|
||||
def module_licensed(self, name: str) -> bool:
|
||||
"""Schaltet die Lizenz das Modul frei? (Ohne den Schalter vor Ort.)"""
|
||||
return self.active() and name in self._state.modules
|
||||
|
||||
def abgeschaltete_module(self, conn: sqlite3.Connection) -> frozenset[str]:
|
||||
"""Liest die Liste aus den Einstellungen."""
|
||||
gespeichert = self.settings.get(conn, SETTING_MODULES_OFF) or []
|
||||
if isinstance(gespeichert, str): # Altbestand: ein einzelner Name
|
||||
gespeichert = [gespeichert]
|
||||
return frozenset(str(name) for name in gespeichert)
|
||||
|
||||
def module_abschalten(
|
||||
self, conn: sqlite3.Connection, namen: Iterable[str], *, actor: str = ""
|
||||
) -> tuple[frozenset[str], frozenset[str]]:
|
||||
"""Setzt die Liste der abgeschalteten Module neu.
|
||||
|
||||
Gibt ``(eingeschaltet, abgeschaltet)`` zurueck -- also nur das, was sich
|
||||
wirklich geaendert hat; der Aufrufer schreibt daraus seinen
|
||||
Protokolleintrag.
|
||||
|
||||
Der Zustand wird hier nicht neu eingelesen, sondern nur an dieser einen
|
||||
Stelle nachgezogen: ein voller Neuaufbau wuerde die Lizenzdatei erneut
|
||||
pruefen, obwohl sich an ihr nichts geaendert hat -- und der Schalter ist
|
||||
das Einzige, was jetzt anders ist.
|
||||
"""
|
||||
vorher = self.abgeschaltete_module(conn)
|
||||
nachher = frozenset(str(name) for name in namen)
|
||||
self.settings.set(conn, SETTING_MODULES_OFF, sorted(nachher), actor=actor)
|
||||
with self._lock:
|
||||
self._state.modules_off = nachher
|
||||
return vorher - nachher, nachher - vorher
|
||||
|
||||
def feature_allowed(self, feature: str) -> bool:
|
||||
"""Lizenzpflichtige Einzelfunktion.
|
||||
|
||||
@@ -257,8 +323,8 @@ class LicenseManager:
|
||||
def require(self, feature: str) -> None:
|
||||
if not self.feature_allowed(feature):
|
||||
raise LicenseError(
|
||||
f"{LICENSED_FEATURES.get(feature, feature)} ist ohne gueltige, "
|
||||
"aktivierte Lizenz nicht moeglich."
|
||||
f"{LICENSED_FEATURES.get(feature, feature)} ist ohne gültige, "
|
||||
"aktivierte Lizenz nicht möglich."
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
@@ -284,7 +350,7 @@ class LicenseManager:
|
||||
try:
|
||||
payload = json.loads(text)
|
||||
except ValueError as exc:
|
||||
raise LicenseError("Die Datei ist kein gueltiges JSON.") from exc
|
||||
raise LicenseError("Die Datei ist kein gültiges JSON.") from exc
|
||||
|
||||
try:
|
||||
document, client_key = lic.split_bundle(payload)
|
||||
@@ -294,20 +360,20 @@ class LicenseManager:
|
||||
try:
|
||||
lic.verify_license(document) # innere Konsistenz
|
||||
except lic.LicensingError as exc:
|
||||
raise LicenseError(f"Die Lizenzdatei ist ungueltig: {exc}") from exc
|
||||
raise LicenseError(f"Die Lizenzdatei ist ungültig: {exc}") from exc
|
||||
|
||||
master_pubkey = str(document.get("master_pubkey") or "")
|
||||
known = self.trusted_keys(conn)
|
||||
if known and master_pubkey not in set(known) and not allow_new_issuer:
|
||||
raise LicenseError(
|
||||
"Diese Lizenz wurde von einem anderen Lizenzserver ausgestellt "
|
||||
f"(Schluessel {lic.key_id(master_pubkey)}). Ein Administrator muss den "
|
||||
"Wechsel des Ausstellers ausdruecklich bestaetigen."
|
||||
f"(Schlüssel {lic.key_id(master_pubkey)}). Ein Administrator muss den "
|
||||
"Wechsel des Ausstellers ausdrücklich bestätigen."
|
||||
)
|
||||
|
||||
if not client_key and not self.key_path.is_file():
|
||||
raise LicenseError(
|
||||
"Der Datei fehlt der Client-Schluessel. Bitte das vollstaendige "
|
||||
"Der Datei fehlt der Client-Schlüssel. Bitte das vollständige "
|
||||
"Lizenz-Bundle des Lizenzservers verwenden."
|
||||
)
|
||||
|
||||
@@ -332,7 +398,7 @@ class LicenseManager:
|
||||
actor=actor,
|
||||
action="license.issuer_pinned",
|
||||
target=lic.key_id(master_pubkey),
|
||||
detail="Trust on first use" if not known else "Aussteller-Wechsel bestaetigt",
|
||||
detail="Trust on first use" if not known else "Aussteller-Wechsel bestätigt",
|
||||
severity="notice",
|
||||
)
|
||||
|
||||
@@ -397,11 +463,11 @@ class LicenseManager:
|
||||
self, action: str, *, hostname: str = "", report: dict[str, Any] | None = None
|
||||
) -> dict[str, Any]:
|
||||
if not self._state.valid:
|
||||
raise LicenseError("Es ist keine gueltige Lizenz installiert.")
|
||||
raise LicenseError("Es ist keine gültige Lizenz installiert.")
|
||||
key = self.client_key()
|
||||
if not key:
|
||||
raise LicenseError(
|
||||
"Der Client-Schluessel dieser Lizenz fehlt. Bitte die Lizenzdatei erneut importieren."
|
||||
"Der Client-Schlüssel dieser Lizenz fehlt. Bitte die Lizenzdatei erneut importieren."
|
||||
)
|
||||
return lic.build_client_request(
|
||||
action, self._state.document, key, hostname=hostname, report=report
|
||||
@@ -442,8 +508,8 @@ class LicenseManager:
|
||||
)
|
||||
else:
|
||||
reason = (
|
||||
"In dieser Lizenz ist kein Lizenzserver hinterlegt -- sie kann sich nur "
|
||||
"ueber den Offline-Weg aktivieren."
|
||||
"In dieser Lizenz ist kein Lizenzserver hinterlegt – sie kann sich nur "
|
||||
"über den Offline-Weg aktivieren."
|
||||
)
|
||||
|
||||
# Offline-Weg: Anfrage merken -- **mit** dem Code. Zwischen Anfrage und
|
||||
@@ -475,7 +541,7 @@ class LicenseManager:
|
||||
"code": code,
|
||||
"message": (
|
||||
(reason + " " if reason else "")
|
||||
+ "Der Offline-Weg steht offen: uebermitteln Sie den angezeigten Code an "
|
||||
+ "Der Offline-Weg steht offen: übermitteln Sie den angezeigten Code an "
|
||||
"Ihren Ansprechpartner und tragen Sie die Antwort hier ein."
|
||||
),
|
||||
}
|
||||
@@ -527,7 +593,7 @@ class LicenseManager:
|
||||
current_seq=current_seq,
|
||||
)
|
||||
except lic.LicensingError as exc:
|
||||
raise LicenseError(f"Die Antwort des Lizenzservers ist nicht gueltig: {exc}") from exc
|
||||
raise LicenseError(f"Die Antwort des Lizenzservers ist nicht gültig: {exc}") from exc
|
||||
|
||||
status = str(response.get("status") or "")
|
||||
detail = str(response.get("detail") or "")
|
||||
@@ -597,7 +663,7 @@ class LicenseManager:
|
||||
actor=actor,
|
||||
)
|
||||
self.settings.set(conn, SETTING_HEARTBEAT_ERROR, "", actor=actor)
|
||||
message = "Verbindung zum Lizenzserver bestaetigt."
|
||||
message = "Verbindung zum Lizenzserver bestätigt."
|
||||
|
||||
self.settings.set(conn, SETTING_PENDING, "", actor=actor)
|
||||
# Ein erfolgreicher Heartbeat laeuft alle paar Minuten und ist kein
|
||||
@@ -648,7 +714,7 @@ class LicenseManager:
|
||||
url: str, payload: dict[str, Any], *, timeout: int, ca_pem: str = ""
|
||||
) -> dict[str, Any]:
|
||||
if not url.startswith(("https://", "http://")):
|
||||
raise ValueError("Ungueltiger Endpunkt")
|
||||
raise ValueError("Ungültiger Endpunkt")
|
||||
data = json.dumps(payload).encode("utf-8")
|
||||
request = urllib.request.Request( # noqa: S310 - Schema oben geprueft
|
||||
url,
|
||||
@@ -748,7 +814,7 @@ class LicenseManager:
|
||||
}
|
||||
if not state.valid:
|
||||
return {
|
||||
"label": "Lizenz ungueltig",
|
||||
"label": "Lizenz ungültig",
|
||||
"css_class": "status-pill--danger",
|
||||
"dot": "1",
|
||||
"dot_class": "status-pill__dot--pulse",
|
||||
@@ -773,29 +839,29 @@ class LicenseManager:
|
||||
"dot": "1",
|
||||
"dot_class": "status-pill__dot--pulse",
|
||||
"title": (
|
||||
"Die Kulanzfrist laeuft noch, Funktionen bleiben vorerst verfuegbar."
|
||||
"Die Kulanzfrist läuft noch, Funktionen bleiben vorerst verfügbar."
|
||||
if status.grace_active
|
||||
else "Lizenzpflichtige Funktionen sind abgeschaltet."
|
||||
),
|
||||
}
|
||||
if status.expiring_soon:
|
||||
return {
|
||||
"label": f"Lizenz laeuft in {status.days_left} Tagen ab",
|
||||
"label": f"Lizenz läuft in {status.days_left} Tagen ab",
|
||||
"css_class": "status-pill--warning",
|
||||
"dot": "1",
|
||||
"dot_class": "status-pill__dot--pulse",
|
||||
"title": "Bitte rechtzeitig verlaengern.",
|
||||
"title": "Bitte rechtzeitig verlängern.",
|
||||
}
|
||||
# Zwischen der Warnschwelle und 90 Tagen: gruen, rein als Hinweis. Wer
|
||||
# eine Verlaengerung im Voraus plant, will das Datum sehen, ohne dass es
|
||||
# nach einem Problem aussieht.
|
||||
if status.days_left is not None and 0 < status.days_left <= EXPIRY_HINT_DAYS:
|
||||
return {
|
||||
"label": f"Lizenz laeuft in {status.days_left} Tagen ab",
|
||||
"label": f"Lizenz läuft in {status.days_left} Tagen ab",
|
||||
"css_class": "",
|
||||
"dot": "1",
|
||||
"dot_class": "",
|
||||
"title": "Nur ein Hinweis -- es ist nichts eingeschraenkt.",
|
||||
"title": "Nur ein Hinweis – es ist nichts eingeschränkt.",
|
||||
}
|
||||
if state.last_heartbeat_at:
|
||||
try:
|
||||
@@ -809,6 +875,6 @@ class LicenseManager:
|
||||
"css_class": "status-pill--warning",
|
||||
"dot": "1",
|
||||
"dot_class": "",
|
||||
"title": "Rein informativ -- es wird nichts abgeschaltet.",
|
||||
"title": "Rein informativ – es wird nichts abgeschaltet.",
|
||||
}
|
||||
return None
|
||||
@@ -94,7 +94,7 @@ def init_app(app: Flask, *, log_dir: Path, debug: bool, json_logs: bool = False)
|
||||
except OSError:
|
||||
pass
|
||||
except OSError as exc: # pragma: no cover - z. B. fehlende Rechte
|
||||
root.warning("Konnte app.log nicht oeffnen: %s", exc)
|
||||
root.warning("Konnte app.log nicht öffnen: %s", exc)
|
||||
|
||||
# Zugriffsprotokoll separat: eine Zeile pro Anfrage, ohne Stacktraces.
|
||||
access = logging.getLogger(ACCESS_LOGGER)
|
||||
|
||||
@@ -50,6 +50,12 @@ class Migration:
|
||||
sql: str = ""
|
||||
fn: MigrationFn | None = None
|
||||
allow_integrity_error: bool = False
|
||||
#: Begruendung, falls der Text einer bereits angewendeten Migration
|
||||
#: absichtlich geaendert wurde -- etwa weil eine frische Installation
|
||||
#: mit der neuen Schreibweise starten muss. Ohne Begruendung warnt der
|
||||
#: Lauf, und das soll er auch: ein stiller Umbau einer angewendeten
|
||||
#: Migration ist fast immer ein Versehen.
|
||||
geaendert_weil: str = ""
|
||||
tags: tuple[str, ...] = field(default=())
|
||||
|
||||
@property
|
||||
@@ -175,17 +181,33 @@ class MigrationRunner:
|
||||
record = known.get(migration.version)
|
||||
if record is not None:
|
||||
if record["checksum"] != migration.checksum:
|
||||
logger.warning(
|
||||
"Migration %s/%s (%s) wurde nachtraeglich geaendert "
|
||||
"(Pruefsumme %s != %s). Bereits angewendete Migrationen werden "
|
||||
"nicht erneut ausgefuehrt -- neue Aenderungen brauchen eine neue "
|
||||
"Versionsnummer.",
|
||||
component,
|
||||
migration.version,
|
||||
migration.name,
|
||||
record["checksum"],
|
||||
migration.checksum,
|
||||
)
|
||||
if migration.geaendert_weil:
|
||||
# Mit Begruendung ist es eine Notiz, keine Warnung:
|
||||
# manchmal muss der Text einer laengst angewendeten
|
||||
# Migration mit, damit eine **frische** Installation
|
||||
# denselben Stand erreicht. Wer das Protokoll liest,
|
||||
# soll den Unterschied zu einem Versehen sehen.
|
||||
logger.info(
|
||||
"Migration %s/%s (%s) wurde absichtlich geändert: %s "
|
||||
"Auf dieser Installation ist sie längst angewendet und "
|
||||
"wird nicht erneut ausgeführt.",
|
||||
component,
|
||||
migration.version,
|
||||
migration.name,
|
||||
migration.geaendert_weil,
|
||||
)
|
||||
else:
|
||||
logger.warning(
|
||||
"Migration %s/%s (%s) wurde nachträglich geändert "
|
||||
"(Prüfsumme %s != %s). Bereits angewendete Migrationen werden "
|
||||
"nicht erneut ausgeführt – neue Änderungen brauchen eine neue "
|
||||
"Versionsnummer.",
|
||||
component,
|
||||
migration.version,
|
||||
migration.name,
|
||||
record["checksum"],
|
||||
migration.checksum,
|
||||
)
|
||||
continue
|
||||
|
||||
try:
|
||||
@@ -210,7 +232,7 @@ class MigrationRunner:
|
||||
raise
|
||||
logger.error(
|
||||
"Migration %s/%s (%s) konnte wegen bestehender Altdaten nicht "
|
||||
"angewendet werden. Der Start laeuft weiter; die Daten muessen "
|
||||
"angewendet werden. Der Start läuft weiter; die Daten müssen "
|
||||
"manuell bereinigt werden.",
|
||||
component,
|
||||
migration.version,
|
||||
|
||||
@@ -16,10 +16,10 @@ A = Action
|
||||
USERS = Resource(
|
||||
key="users",
|
||||
label="Benutzer",
|
||||
actions=(A.VIEW, A.CREATE, A.EDIT, A.DELETE),
|
||||
actions=(A.READ, A.CREATE, A.WRITE, A.DELETE),
|
||||
hint="Konten anlegen, sperren, Gruppen zuordnen",
|
||||
action_hints={
|
||||
A.EDIT: "Stammdaten, Sperre und Gruppenzuordnung aendern.",
|
||||
A.WRITE: "Stammdaten, Sperre und Gruppenzuordnung ändern.",
|
||||
A.DELETE: "Konto in den Papierkorb legen (Verzeichniskonten sofort entfernen).",
|
||||
},
|
||||
)
|
||||
@@ -27,35 +27,46 @@ USERS = Resource(
|
||||
GROUPS = Resource(
|
||||
key="groups",
|
||||
label="Gruppen und Rechte",
|
||||
actions=(A.VIEW, A.CREATE, A.EDIT, A.DELETE),
|
||||
actions=(A.READ, A.CREATE, A.WRITE, A.DELETE),
|
||||
hint="Rechtematrix pflegen",
|
||||
action_hints={
|
||||
A.EDIT: "Rechte vergeben -- nur Rechte, die man selbst besitzt.",
|
||||
A.WRITE: "Rechte vergeben – nur Rechte, die man selbst besitzt.",
|
||||
},
|
||||
)
|
||||
|
||||
SETTINGS_SYSTEM = Resource(
|
||||
key="settings_system",
|
||||
label="Systemeinstellungen",
|
||||
actions=(A.VIEW, A.EDIT, A.EXECUTE),
|
||||
hint="Hostname, Zeitzone, Protokollrotation, Navigation",
|
||||
action_hints={A.EXECUTE: "Systemaktionen ausloesen (Dienste, Netzwerk uebernehmen)."},
|
||||
actions=(A.READ, A.WRITE, A.EXECUTE),
|
||||
hint="Hostname, Zeitzone, Protokollrotation, Sitzungsdauer",
|
||||
action_hints={A.EXECUTE: "Systemaktionen auslösen (Dienste, Netzwerk übernehmen)."},
|
||||
)
|
||||
|
||||
#: Die Reihenfolge des Menues lief unter "Systemaktionen auslösen" mit -- also
|
||||
#: unter demselben Recht wie das Aendern des Hostnamens. Es ist aber das
|
||||
#: harmloseste, was man in der Verwaltung tun kann, und das haeufigste.
|
||||
SETTINGS_NAV = Resource(
|
||||
key="settings_nav",
|
||||
parent="settings_system",
|
||||
label="Navigation",
|
||||
actions=(A.READ, A.WRITE),
|
||||
hint="Reihenfolge der Menüpunkte und ihrer Unterpunkte",
|
||||
)
|
||||
|
||||
SETTINGS_LICENSE = Resource(
|
||||
key="settings_license",
|
||||
label="Lizenz",
|
||||
actions=(A.VIEW, A.EDIT),
|
||||
actions=(A.READ, A.WRITE),
|
||||
hint="Lizenzdatei einspielen, aktivieren, deaktivieren",
|
||||
)
|
||||
|
||||
SETTINGS_DIRECTORY = Resource(
|
||||
key="settings_directory",
|
||||
label="Verzeichnisdienst (LDAP/AD)",
|
||||
actions=(A.VIEW, A.EDIT, A.EXECUTE, A.SECRETS),
|
||||
actions=(A.READ, A.WRITE, A.EXECUTE, A.SECRETS),
|
||||
hint="Anbindung und Gruppen-Zuordnung",
|
||||
action_hints={
|
||||
A.EXECUTE: "Verbindungstest ausfuehren.",
|
||||
A.EXECUTE: "Verbindungstest ausführen.",
|
||||
A.SECRETS: "Bind-Passwort des Dienstkontos setzen.",
|
||||
},
|
||||
)
|
||||
@@ -63,67 +74,78 @@ SETTINGS_DIRECTORY = Resource(
|
||||
SETTINGS_WEB = Resource(
|
||||
key="settings_web",
|
||||
label="Webserver und TLS",
|
||||
actions=(A.VIEW, A.EDIT, A.EXECUTE),
|
||||
actions=(A.READ, A.WRITE, A.EXECUTE),
|
||||
hint="Domain, Zertifikat, HSTS",
|
||||
action_hints={A.EXECUTE: "Konfiguration uebernehmen, Zertifikat anfordern."},
|
||||
action_hints={A.EXECUTE: "Konfiguration übernehmen, Zertifikat anfordern."},
|
||||
)
|
||||
|
||||
SETTINGS_NETWORK = Resource(
|
||||
key="settings_network",
|
||||
label="Netzwerkeinstellungen",
|
||||
actions=(A.VIEW, A.EDIT),
|
||||
actions=(A.READ, A.WRITE),
|
||||
hint="IP-Adresse, Gateway, DNS des Hosts",
|
||||
)
|
||||
|
||||
BACKUP = Resource(
|
||||
key="backup",
|
||||
label="Sicherung und Uebertragung",
|
||||
actions=(A.VIEW, A.EXECUTE, A.EXPORT, A.SECRETS),
|
||||
hint="Verschluesselter Export und Import",
|
||||
#: Sichern und Einspielen sind zwei Zeilen, weil es zwei Vorgaenge mit sehr
|
||||
#: verschiedenen Folgen sind: eine Sicherung zu erzeugen aendert nichts, eine
|
||||
#: einzuspielen aendert alles. Sie liefen unter einem Recht, und wer eine
|
||||
#: Sicherung ziehen durfte, durfte damit auch eine fremde einspielen.
|
||||
BACKUP_EXPORT = Resource(
|
||||
key="backup_export",
|
||||
label="Sicherung erstellen",
|
||||
actions=(A.READ, A.EXPORT, A.SECRETS),
|
||||
hint="Verschlüsselter Export des Datenstands",
|
||||
action_hints={
|
||||
A.EXECUTE: "Eine Sicherung einspielen.",
|
||||
A.EXPORT: "Sicherung erzeugen und herunterladen.",
|
||||
A.SECRETS: "Zugangsdaten in die Sicherung einschliessen.",
|
||||
A.SECRETS: "Zugangsdaten in die Sicherung einschließen.",
|
||||
},
|
||||
)
|
||||
|
||||
BACKUP_IMPORT = Resource(
|
||||
key="backup_import",
|
||||
label="Sicherung einspielen",
|
||||
actions=(A.READ, A.EXECUTE),
|
||||
hint="Prüfen, übernehmen, verwerfen",
|
||||
action_hints={A.EXECUTE: "Eine geprüfte Sicherung anwenden."},
|
||||
)
|
||||
|
||||
TRASH = Resource(
|
||||
key="trash",
|
||||
label="Papierkorb",
|
||||
actions=(A.VIEW, A.EDIT, A.DELETE),
|
||||
hint="Geloeschtes wiederherstellen oder endgueltig entfernen",
|
||||
actions=(A.READ, A.WRITE, A.DELETE),
|
||||
hint="Gelöschtes wiederherstellen oder endgültig entfernen",
|
||||
action_hints={
|
||||
A.EDIT: "Eintraege wiederherstellen.",
|
||||
A.DELETE: "Eintraege endgueltig entfernen.",
|
||||
A.WRITE: "Einträge wiederherstellen.",
|
||||
A.DELETE: "Einträge endgültig entfernen.",
|
||||
},
|
||||
)
|
||||
|
||||
DIAGNOSTICS = Resource(
|
||||
key="diagnostics",
|
||||
label="Diagnose",
|
||||
actions=(A.VIEW,),
|
||||
hint="Schemastand, Protokollintegritaet, Schluesselrechte",
|
||||
actions=(A.READ,),
|
||||
hint="Schemastand, Protokollintegrität, Schlüsselrechte",
|
||||
)
|
||||
|
||||
LOGS_LIVE = Resource(
|
||||
key="logs_live",
|
||||
label="Laufendes Protokoll",
|
||||
actions=(A.VIEW,),
|
||||
label="Live-Protokoll",
|
||||
actions=(A.READ,),
|
||||
)
|
||||
|
||||
LOGS_HISTORY = Resource(
|
||||
key="logs_history",
|
||||
label="Protokollverlauf",
|
||||
actions=(A.VIEW, A.DELETE, A.EXPORT),
|
||||
actions=(A.READ, A.DELETE, A.EXPORT),
|
||||
hint="Rotierte und archivierte Protokolle",
|
||||
action_hints={A.DELETE: "Archivierte Tage vom Server entfernen."},
|
||||
)
|
||||
|
||||
LOGS_AUDIT = Resource(
|
||||
key="logs_audit",
|
||||
label="Aenderungsprotokoll",
|
||||
actions=(A.VIEW, A.EXPORT),
|
||||
hint="Wer hat wann was geaendert",
|
||||
label="Änderungsprotokoll",
|
||||
actions=(A.READ, A.EXPORT),
|
||||
hint="Wer hat wann was geändert",
|
||||
)
|
||||
|
||||
|
||||
@@ -139,11 +161,13 @@ def administration_area(*extra: Resource) -> Area:
|
||||
USERS,
|
||||
GROUPS,
|
||||
SETTINGS_SYSTEM,
|
||||
SETTINGS_NAV,
|
||||
SETTINGS_LICENSE,
|
||||
SETTINGS_DIRECTORY,
|
||||
SETTINGS_WEB,
|
||||
SETTINGS_NETWORK,
|
||||
BACKUP,
|
||||
BACKUP_EXPORT,
|
||||
BACKUP_IMPORT,
|
||||
TRASH,
|
||||
DIAGNOSTICS,
|
||||
*extra,
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
"""Alte Rechteschluessel auf neue -- an einer Stelle, nicht an dreien.
|
||||
|
||||
Mit 2.8.0 heisst das Aktionsvokabular durchgehend wie das, was es tut:
|
||||
``view`` wurde ``read``, ``edit`` wurde ``write``. Danach steht in der Matrix
|
||||
"Write" und im Aenderungsprotokoll ``write``, nicht zweierlei.
|
||||
|
||||
Drei Stellen brauchen die Zuordnung, und darum steht sie hier und nicht dort:
|
||||
|
||||
* die **Migration**, die bestehende Gruppenzeilen umschreibt,
|
||||
* der **Import**, dem eine Sicherung aus 2.7.x untergeschoben wird -- ohne die
|
||||
Zuordnung landen dort lauter unbekannte Schluessel, und
|
||||
:meth:`PermissionTree.sanitize` wirft Unbekanntes absichtlich **still** weg.
|
||||
Aus einer Sicherung wuerden Gruppen ohne Rechte.
|
||||
* der **Test**, der prueft, dass kein alter Schluessel mehr im Code steht.
|
||||
|
||||
Warum nicht dreimal dieselbe Ersetzung tippen: weil die dritte Kopie beim
|
||||
naechsten Umbau vergessen wird. Genau so entstand das Muster bei den Adressen
|
||||
(:mod:`tesm_core.legacy_urls`).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
#: Aktion alt -> neu. Die Ressource bleibt, wie sie heisst.
|
||||
UMBENANNTE_AKTIONEN: dict[str, str] = {
|
||||
"view": "read",
|
||||
"edit": "write",
|
||||
}
|
||||
|
||||
#: Ein altes Recht, das in mehrere neue zerfaellt -- ein Recht je Funktion.
|
||||
#:
|
||||
#: Die Aufteilung ist **additiv**: wer das alte Recht hatte, bekommt alle
|
||||
#: neuen. Niemand verliert etwas; ab jetzt laesst sich jedes Stueck einzeln
|
||||
#: vergeben. Der umgekehrte Weg waere auch denkbar gewesen -- nur das
|
||||
#: Harmloseste uebernehmen --, waere aber ein Update, das Leuten Rechte
|
||||
#: wegnimmt, ohne dass jemand es entschieden hat.
|
||||
#:
|
||||
#: Die Schluessel stehen fuer beide Anwendungen in einer Tabelle. Auf einer
|
||||
#: TESM-Datenbank tut die Zeile fuer ``licenses.write`` nichts, weil sie dort
|
||||
#: in keiner Gruppe steht -- und umgekehrt. Zwei getrennte Tabellen waeren
|
||||
#: zwei Stellen, die man pflegen muss.
|
||||
GETEILTE_RECHTE: dict[str, tuple[str, ...]] = {
|
||||
# Drei Neustartwege mit drei verschiedenen Folgen.
|
||||
"devices.execute": (
|
||||
"device_restart_poe.read",
|
||||
"device_restart_poe.execute",
|
||||
"device_restart_ssh.read",
|
||||
"device_restart_ssh.execute",
|
||||
"device_restart_rpc.read",
|
||||
"device_restart_rpc.execute",
|
||||
),
|
||||
# Die Switch-Konsole war "Switch ausfuehren".
|
||||
"switches.execute": ("switch_console.read", "switch_console.execute"),
|
||||
# Vier Funktionen: aktualisieren, neu starten, Werkzeug installieren --
|
||||
# und die Client-Konsole, die jetzt bei den Clients steht.
|
||||
"maintenance.read": (
|
||||
"servicing_update.read",
|
||||
"servicing_reboot.read",
|
||||
"servicing_tool.read",
|
||||
"device_console.read",
|
||||
),
|
||||
"maintenance.execute": (
|
||||
"servicing_update.read",
|
||||
"servicing_update.execute",
|
||||
"servicing_reboot.read",
|
||||
"servicing_reboot.execute",
|
||||
"servicing_tool.read",
|
||||
"servicing_tool.execute",
|
||||
"device_console.read",
|
||||
"device_console.execute",
|
||||
),
|
||||
# Elf Funktionen an einem Recht.
|
||||
"dhcp.read": (
|
||||
"dhcp_subnets.read",
|
||||
"dhcp_options.read",
|
||||
"dhcp_reservations.read",
|
||||
"dhcp_config.read",
|
||||
"dhcp_service.read",
|
||||
),
|
||||
"dhcp.write": (
|
||||
"dhcp_subnets.read",
|
||||
"dhcp_subnets.create",
|
||||
"dhcp_subnets.write",
|
||||
"dhcp_subnets.delete",
|
||||
"dhcp_options.read",
|
||||
"dhcp_options.write",
|
||||
"dhcp_reservations.read",
|
||||
"dhcp_reservations.create",
|
||||
"dhcp_reservations.write",
|
||||
"dhcp_reservations.delete",
|
||||
"dhcp_config.read",
|
||||
"dhcp_config.execute",
|
||||
),
|
||||
"dhcp.execute": ("dhcp_service.read", "dhcp_service.execute"),
|
||||
# Sichern und Einspielen.
|
||||
"backup.read": ("backup_export.read", "backup_import.read"),
|
||||
"backup.export": ("backup_export.read", "backup_export.export"),
|
||||
"backup.secrets": ("backup_export.read", "backup_export.secrets"),
|
||||
"backup.execute": ("backup_import.read", "backup_import.execute"),
|
||||
# Lizenzserver: "aendern" hiess widerrufen **oder** erneuern -- zwei
|
||||
# Eingriffe mit entgegengesetzter Wirkung unter einem Haken.
|
||||
"licenses.create": ("license_issue.read", "license_issue.execute"),
|
||||
"licenses.write": (
|
||||
"license_renew.read",
|
||||
"license_renew.execute",
|
||||
"license_revoke.read",
|
||||
"license_revoke.execute",
|
||||
),
|
||||
"licenses.execute": ("license_activation.read", "license_activation.execute"),
|
||||
}
|
||||
|
||||
|
||||
#: Ein Recht, das **bleibt** und bisher noch etwas anderes mitgab.
|
||||
#:
|
||||
#: Der Unterschied zu :data:`GETEILTE_RECHTE` ist keine Formsache: dort ist der
|
||||
#: alte Schluessel verschwunden und muss ersetzt werden, hier gilt er weiter
|
||||
#: und bekommt nur Gesellschaft. Beides in eine Tabelle zu werfen hiesse, in
|
||||
#: der Migration ein Recht zu loeschen, das es noch gibt -- und im Test nicht
|
||||
#: mehr pruefen zu koennen, welcher Fall gemeint war.
|
||||
ERWEITERTE_RECHTE: dict[str, tuple[str, ...]] = {
|
||||
# Die Navigationsreihenfolge lief unter "Systemaktionen ausloesen" mit.
|
||||
"settings_system.execute": ("settings_nav.read", "settings_nav.write"),
|
||||
# Einen Host-Schluessel freizugeben hing an den Stammdaten.
|
||||
"devices.write": ("hostkeys.read", "hostkeys.execute"),
|
||||
"switches.write": ("hostkeys.read", "hostkeys.execute"),
|
||||
# Umbenennen war auch "Freigaben zuordnen".
|
||||
"fileshare.write": (
|
||||
"fileshare_mappings.read",
|
||||
"fileshare_mappings.create",
|
||||
"fileshare_mappings.write",
|
||||
"fileshare_mappings.delete",
|
||||
),
|
||||
# Ausgefuellt ablegen war auch "unterschreiben".
|
||||
"fileshare_pdf.create": ("fileshare_signature.read", "fileshare_signature.execute"),
|
||||
}
|
||||
|
||||
|
||||
def neue_schluessel(alt: str) -> tuple[str, ...]:
|
||||
"""Was aus einem alten Rechteschluessel wird -- eins oder mehrere.
|
||||
|
||||
Unbekanntes kommt unveraendert zurueck: ob ein Schluessel gilt, entscheidet
|
||||
der Rechtebaum, nicht diese Tabelle. Sie benennt nur um.
|
||||
"""
|
||||
if alt in GETEILTE_RECHTE:
|
||||
return GETEILTE_RECHTE[alt]
|
||||
ressource, punkt, aktion = alt.rpartition(".")
|
||||
if not punkt:
|
||||
return (alt,)
|
||||
neu = UMBENANNTE_AKTIONEN.get(aktion)
|
||||
selbst = f"{ressource}.{neu}" if neu else alt
|
||||
# Ein Recht, das bleibt, nimmt mit, was es bisher mitgab -- sonst verliert
|
||||
# jemand beim Update genau die Funktion, die vorher an diesem Haken hing.
|
||||
return (selbst, *ERWEITERTE_RECHTE.get(selbst, ()))
|
||||
|
||||
|
||||
def umgeschrieben(rechte: object) -> list[str]:
|
||||
"""Eine ganze Liste umschreiben, ohne Dubletten und in fester Reihenfolge."""
|
||||
if not isinstance(rechte, (list, tuple, set, frozenset)):
|
||||
return []
|
||||
ergebnis: set[str] = set()
|
||||
for recht in rechte:
|
||||
ergebnis.update(neue_schluessel(str(recht)))
|
||||
return sorted(ergebnis)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"UMBENANNTE_AKTIONEN",
|
||||
"GETEILTE_RECHTE",
|
||||
"ERWEITERTE_RECHTE",
|
||||
"neue_schluessel",
|
||||
"umgeschrieben",
|
||||
]
|
||||
@@ -1,6 +1,14 @@
|
||||
"""Rechtemodell: Bereiche, Ressourcen, Aktionen.
|
||||
|
||||
Das Vorgaengermodell kannte fuenf Spalten (R/W/E/D/X), wobei ``E`` ("Aendern")
|
||||
Das Vokabular heisst seit 2.8.0 durchgehend wie das, was es tut: **Read,
|
||||
Create, Write, Delete, Execute, Export, Secrets**. Bis dahin hiessen zwei
|
||||
Aktionen anders (``view``, ``edit``), waehrend die Matrix "Bearbeiten" zeigte
|
||||
und die Kurzfassung "U" -- dieselbe Aktion in drei Schreibweisen. Der
|
||||
Kill-Switch eines Bereichs heisst entsprechend ``<bereich>.read``.
|
||||
:mod:`tesm_core.rbac.legacy_permissions` schreibt alte Schluessel um; die
|
||||
Migration ``core/4`` tut das fuer bestehende Gruppen.
|
||||
|
||||
Das Modell vor 2.0 kannte fuenf Spalten (R/W/E/D/X), wobei ``E`` ("Aendern")
|
||||
das Loeschen **mit abdeckte** und ``D``/``X`` je nach Zeile etwas voellig anderes
|
||||
bedeuteten (Dashboard-Neustart bzw. Export). Das war kompakt, aber:
|
||||
|
||||
@@ -15,7 +23,7 @@ Aktionen eine Ressource ueberhaupt kennt, entscheidet die Ressource; die Matrix
|
||||
rendert nur die Spalten, die im jeweiligen Bereich wirklich vorkommen.
|
||||
|
||||
Beibehalten wird der bewaehrte **Kill-Switch**: jeder Bereich hat ein
|
||||
``<bereich>.view``-Recht. Ohne dieses greift kein einziges Recht innerhalb des
|
||||
``<bereich>.read``-Recht. Ohne dieses greift kein einziges Recht innerhalb des
|
||||
Bereichs -- unabhaengig davon, was einzeln angehakt ist. Das erlaubt es, einer
|
||||
Gruppe einen ganzen Bereich mit einem Klick zu entziehen, ohne die fein
|
||||
eingestellten Einzelrechte zu verlieren.
|
||||
@@ -29,38 +37,68 @@ from typing import Iterable, Mapping, Sequence
|
||||
|
||||
|
||||
class Action(str, Enum):
|
||||
"""Aktionsvokabular. Bedeutung ist ueberall dieselbe -- keine Ausnahmen."""
|
||||
"""Aktionsvokabular. Bedeutung ist ueberall dieselbe -- keine Ausnahmen.
|
||||
|
||||
VIEW = "view"
|
||||
Die Namen sind die englischen, weil sie in jedem Rechtesystem dieselben
|
||||
sind und keiner Uebersetzung bedarf: wer ``write`` liest, weiss es. Zwei
|
||||
hiessen bis 2.7.x anders (``view``, ``edit``) -- in der Matrix stand
|
||||
"Bearbeiten" und im Protokoll ``edit``, also zweierlei fuer dasselbe.
|
||||
:mod:`tesm_core.rbac.legacy_permissions` schreibt die alten Schluessel um.
|
||||
"""
|
||||
|
||||
READ = "read"
|
||||
CREATE = "create"
|
||||
EDIT = "edit"
|
||||
WRITE = "write"
|
||||
DELETE = "delete"
|
||||
EXECUTE = "execute"
|
||||
EXPORT = "export"
|
||||
SECRETS = "secrets"
|
||||
|
||||
|
||||
#: Kuerzel und Erklaerung je Aktion -- Kopfzeile der Rechtematrix.
|
||||
ACTION_META: dict[Action, tuple[str, str, str]] = {
|
||||
Action.VIEW: ("R", "Ansehen", "Datensaetze und Seiten dieses Bereichs lesen."),
|
||||
Action.CREATE: ("C", "Anlegen", "Neue Datensaetze erstellen."),
|
||||
Action.EDIT: ("U", "Bearbeiten", "Bestehende Datensaetze aendern -- ohne Loeschen."),
|
||||
Action.DELETE: ("D", "Loeschen", "Datensaetze loeschen bzw. endgueltig entfernen."),
|
||||
Action.EXECUTE: ("X", "Ausfuehren", "Aktionen ausloesen (Neustart, Dienste, Jobs, Import)."),
|
||||
Action.EXPORT: ("E", "Exportieren", "Daten aus dem System heraustragen (Datei-Download)."),
|
||||
#: Kuerzel, englischer Name, deutsche Beschriftung, Erklaerung.
|
||||
#:
|
||||
#: Beides hat seinen Ort: die Matrix fuehrt die Spalte unter ihrem englischen
|
||||
#: Namen (das ist das Vokabular, und es steht so auch im Schluessel), die
|
||||
#: Kleinschrift darunter und jeder Satz in der Oberflaeche bleiben deutsch.
|
||||
ACTION_META: dict[Action, tuple[str, str, str, str]] = {
|
||||
Action.READ: ("R", "Read", "ansehen", "Datensätze und Seiten dieses Bereichs ansehen."),
|
||||
Action.CREATE: ("C", "Create", "anlegen", "Neue Datensätze anlegen."),
|
||||
Action.WRITE: (
|
||||
"W",
|
||||
"Write",
|
||||
"ändern",
|
||||
"Bestehende Datensätze ändern – ohne Anlegen, ohne Löschen.",
|
||||
),
|
||||
Action.DELETE: ("D", "Delete", "löschen", "Datensätze löschen bzw. endgültig entfernen."),
|
||||
Action.EXECUTE: (
|
||||
"X",
|
||||
"Execute",
|
||||
"auslösen",
|
||||
"Aktionen auslösen (Neustart, Dienste, Aufträge, Import).",
|
||||
),
|
||||
Action.EXPORT: (
|
||||
"E",
|
||||
"Export",
|
||||
"mitnehmen",
|
||||
"Daten aus dem System heraustragen (Datei-Download).",
|
||||
),
|
||||
Action.SECRETS: (
|
||||
"S",
|
||||
"Geheimnisse",
|
||||
"Passwoerter und Schluessel im Klartext sehen oder mitnehmen.",
|
||||
"Secrets",
|
||||
"Klartext",
|
||||
"Passwörter und Schlüssel im Klartext sehen oder mitnehmen.",
|
||||
),
|
||||
}
|
||||
|
||||
#: Aktionen, die zusaetzlich eine frische Passworteingabe verlangen (sudo-Modus).
|
||||
SENSITIVE_ACTIONS: frozenset[Action] = frozenset({Action.SECRETS, Action.EXPORT})
|
||||
|
||||
#: ``view`` ist Voraussetzung fuer alles andere in derselben Zeile.
|
||||
#: ``read`` ist Voraussetzung fuer alles andere in derselben Zeile. Umgekehrt
|
||||
#: gilt nichts: wer anlegen darf, darf damit nicht aendern, und wer aendern
|
||||
#: darf, nicht anlegen. Das ist die Trennung, die man in einer
|
||||
#: Verwaltungsanwendung am haeufigsten braucht.
|
||||
IMPLIED_BY: dict[Action, tuple[Action, ...]] = {
|
||||
action: (Action.VIEW,) for action in Action if action is not Action.VIEW
|
||||
action: (Action.READ,) for action in Action if action is not Action.READ
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +112,32 @@ class Resource:
|
||||
hint: str = ""
|
||||
#: Abweichende Erklaerung einzelner Aktionen (z. B. was "Ausfuehren" hier meint).
|
||||
action_hints: Mapping[Action, str] = field(default_factory=dict)
|
||||
#: Zu welcher Zeile diese gehoert -- rein fuer die Darstellung.
|
||||
#:
|
||||
#: Aus einer Zeile "Clients" sind sechs geworden (Stammdaten, drei
|
||||
#: Neustartwege, Konsole, Host-Schluessel). Untereinander und alle gleich
|
||||
#: eingerueckt liest man sie als sechs unabhaengige Dinge; eingerueckt
|
||||
#: unter ihrer Hauptzeile sieht man, dass sie zusammengehoeren. Auf die
|
||||
#: Rechte hat das keine Wirkung: jede Zeile bleibt einzeln vergebbar, und
|
||||
#: die Hauptzeile ist **nicht** Voraussetzung fuer ihre Unterzeilen.
|
||||
parent: str = ""
|
||||
#: Aktionen, die hier **keine** frische Passwortbestaetigung verlangen,
|
||||
#: obwohl sie in SENSITIVE_ACTIONS stehen. Bewusst hier und nicht als
|
||||
#: stilles Weglassen in der Route: eine Ausnahme von einer
|
||||
#: Sicherheitsregel gehoert dorthin, wo man sie sieht und begruenden muss.
|
||||
ohne_wiederanmeldung: tuple[Action, ...] = ()
|
||||
|
||||
@property
|
||||
def short_label(self) -> str:
|
||||
"""Beschriftung ohne den Namen der Hauptzeile.
|
||||
|
||||
Unter "Clients" steht "Neustart über PoE" und nicht "Clients: Neustart
|
||||
über PoE" -- das Wort stand sonst siebenmal untereinander. Ausserhalb
|
||||
der Matrix (Protokoll, Meldungen) bleibt der vollstaendige Name.
|
||||
"""
|
||||
if self.parent and ": " in self.label:
|
||||
return self.label.split(": ", 1)[1]
|
||||
return self.label
|
||||
|
||||
def permission(self, action: Action) -> str:
|
||||
return f"{self.key}.{action.value}"
|
||||
@@ -96,8 +160,9 @@ class Area:
|
||||
hint: str = ""
|
||||
|
||||
@property
|
||||
def view_key(self) -> str:
|
||||
return f"{self.key}.view"
|
||||
def read_key(self) -> str:
|
||||
"""Der Kill-Switch des Bereichs. Ohne ihn greift keine Zeile darunter."""
|
||||
return f"{self.key}.read"
|
||||
|
||||
def columns(self) -> tuple[Action, ...]:
|
||||
"""Nur die Aktionen, die in diesem Bereich tatsaechlich vorkommen."""
|
||||
@@ -123,45 +188,92 @@ class PermissionTree:
|
||||
self._parent: dict[str, str] = {}
|
||||
self._all: list[str] = []
|
||||
self._resources: dict[str, tuple[Area, Resource]] = {}
|
||||
self._verwaltung: frozenset[str] | None = None
|
||||
|
||||
seen_keys: set[str] = set()
|
||||
for area in self.areas:
|
||||
if area.key in seen_keys:
|
||||
raise ValueError(f"Doppelter Bereichsschluessel: {area.key}")
|
||||
raise ValueError(f"Doppelter Bereichsschlüssel: {area.key}")
|
||||
seen_keys.add(area.key)
|
||||
self._by_key[area.key] = area
|
||||
self._all.append(area.view_key)
|
||||
self._all.append(area.read_key)
|
||||
for resource in area.resources:
|
||||
if resource.key in seen_keys:
|
||||
raise ValueError(f"Doppelter Ressourcenschluessel: {resource.key}")
|
||||
raise ValueError(f"Doppelter Ressourcenschlüssel: {resource.key}")
|
||||
seen_keys.add(resource.key)
|
||||
if Action.VIEW not in resource.actions:
|
||||
if Action.READ not in resource.actions:
|
||||
raise ValueError(
|
||||
f"Ressource {resource.key} muss die Aktion 'view' anbieten -- "
|
||||
"sie ist Voraussetzung fuer jede andere Aktion."
|
||||
f"Ressource {resource.key} muss die Aktion 'read' anbieten – "
|
||||
"sie ist Voraussetzung für jede andere Aktion."
|
||||
)
|
||||
self._resources[resource.key] = (area, resource)
|
||||
for permission in resource.permissions():
|
||||
self._all.append(permission)
|
||||
self._parent[permission] = area.view_key
|
||||
self._parent[permission] = area.read_key
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
def all_keys(self) -> tuple[str, ...]:
|
||||
return tuple(self._all)
|
||||
|
||||
#: Der Bereich, den ein echter Administrator immer ganz hat.
|
||||
#:
|
||||
#: Nicht "alles": das Kennzeichen ``is_admin`` gab bisher jede Pruefung
|
||||
#: frei, auch Geraete, DHCP und Dateifreigaben. Ein Administrator ist aber
|
||||
#: jemand, der die **Anlage** verwaltet -- Benutzer, Rechte,
|
||||
#: Einstellungen --, und nicht automatisch jemand, der Maschinen neu
|
||||
#: startet oder in Freigaben liest. Diese Rechte holt er sich ueber eine
|
||||
#: Gruppe, und dann steht es im Aenderungsprotokoll.
|
||||
VERWALTUNGSBEREICH = "administration"
|
||||
|
||||
def verwaltungsrechte(self) -> frozenset[str]:
|
||||
"""Alle Rechte des Verwaltungsbereichs, samt seinem Kill-Switch.
|
||||
|
||||
Einmal gerechnet und gemerkt: die Antwort haengt nur am Baum, und der
|
||||
entsteht beim Import.
|
||||
"""
|
||||
if self._verwaltung is None:
|
||||
bereich = self._by_key.get(self.VERWALTUNGSBEREICH)
|
||||
if bereich is None:
|
||||
self._verwaltung = frozenset()
|
||||
else:
|
||||
rechte = {bereich.read_key}
|
||||
for resource in bereich.resources:
|
||||
rechte.update(resource.permissions())
|
||||
self._verwaltung = frozenset(rechte)
|
||||
return self._verwaltung
|
||||
|
||||
def area(self, key: str) -> Area | None:
|
||||
return self._by_key.get(key)
|
||||
|
||||
def parent_view_key(self, permission: str) -> str | None:
|
||||
def parent_read_key(self, permission: str) -> str | None:
|
||||
return self._parent.get(permission)
|
||||
|
||||
def resource(self, key: str) -> tuple[Area, Resource] | None:
|
||||
return self._resources.get(key)
|
||||
|
||||
def verlangt_wiederanmeldung(self, permission: str) -> bool:
|
||||
"""Braucht dieses Recht eine frische Passwortbestaetigung?
|
||||
|
||||
Die Antwort steht im Modell (``SENSITIVE_ACTIONS``) und nicht in der
|
||||
Route -- sonst vergisst sie die naechste, die dazukommt.
|
||||
"""
|
||||
resource_key, _, action_value = permission.rpartition(".")
|
||||
entry = self._resources.get(resource_key)
|
||||
if entry is None:
|
||||
return False
|
||||
_, resource = entry
|
||||
try:
|
||||
action = Action(action_value)
|
||||
except ValueError:
|
||||
return False
|
||||
if action in resource.ohne_wiederanmeldung:
|
||||
return False
|
||||
return action in SENSITIVE_ACTIONS
|
||||
|
||||
def label_for(self, permission: str) -> str:
|
||||
"""Menschenlesbare Beschreibung eines Rechteschluessels -- fuer Audit-Logs."""
|
||||
if permission.endswith(".view") and permission[:-5] in self._by_key:
|
||||
if permission.endswith(".read") and permission[:-5] in self._by_key:
|
||||
return f"Bereich {self._by_key[permission[:-5]].label}: Zugang"
|
||||
resource_key, _, action_value = permission.rpartition(".")
|
||||
entry = self._resources.get(resource_key)
|
||||
@@ -172,7 +284,10 @@ class PermissionTree:
|
||||
action = Action(action_value)
|
||||
except ValueError:
|
||||
return permission
|
||||
return f"{resource.label}: {ACTION_META[action][1]}"
|
||||
# Die deutsche Beschriftung, nicht der englische Name: dieser Text
|
||||
# landet in Saetzen ("Sie koennen kein Recht vergeben ...") und im
|
||||
# Aenderungsprotokoll, und die sind deutsch.
|
||||
return f"{resource.label}: {ACTION_META[action][2]}"
|
||||
|
||||
def sanitize(self, permissions: Iterable[str]) -> list[str]:
|
||||
"""Wirft unbekannte Rechte weg und ergaenzt implizierte.
|
||||
@@ -180,7 +295,7 @@ class PermissionTree:
|
||||
Regeln:
|
||||
* Ein Recht, das nicht im Baum steht, wird verworfen (kein stilles
|
||||
Weiterschleppen von Altrechten nach einem Refactoring).
|
||||
* Jede Aktion impliziert ``view`` derselben Zeile.
|
||||
* Jede Aktion impliziert ``read`` derselben Zeile -- aber nur diese.
|
||||
* Existiert irgendein Recht eines Bereichs, wird der Kill-Switch des
|
||||
Bereichs mitgesetzt -- sonst waere die Auswahl wirkungslos und der
|
||||
Bearbeiter wuerde sich wundern.
|
||||
@@ -200,13 +315,13 @@ class PermissionTree:
|
||||
result.add(candidate)
|
||||
for area in self.areas:
|
||||
if any(p in result for resource in area.resources for p in resource.permissions()):
|
||||
result.add(area.view_key)
|
||||
result.add(area.read_key)
|
||||
return sorted(result)
|
||||
|
||||
def effective(self, permissions: Iterable[str]) -> set[str]:
|
||||
"""Rechte, die nach Anwendung der Kill-Switches tatsaechlich greifen."""
|
||||
granted = set(permissions)
|
||||
active = {key for key in granted if key.endswith(".view") and key[:-5] in self._by_key}
|
||||
active = {key for key in granted if key.endswith(".read") and key[:-5] in self._by_key}
|
||||
return {
|
||||
key
|
||||
for key in granted
|
||||
|
||||
@@ -29,7 +29,7 @@ from typing import Any, Iterable, Sequence
|
||||
|
||||
from ..db import Database
|
||||
from ..security import passwords
|
||||
from .model import Action, PermissionTree, RolePreset
|
||||
from .model import ACTION_META, Action, PermissionTree, RolePreset
|
||||
|
||||
|
||||
class PermissionDenied(Exception):
|
||||
@@ -124,7 +124,20 @@ def group_permissions(conn: sqlite3.Connection, group_id: int) -> list[str]:
|
||||
def guard_no_amplification(
|
||||
actor: Any, tree: PermissionTree, added: Iterable[str], *, what: str = "Recht"
|
||||
) -> None:
|
||||
"""Verhindert, dass jemand Rechte vergibt, die er selbst nicht besitzt."""
|
||||
"""Verhindert, dass jemand Rechte vergibt, die er selbst nicht besitzt.
|
||||
|
||||
Ein echter Administrator darf es -- und das ist seit 2.8.0 die bewusst
|
||||
offene Tuer: sein Kennzeichen gibt ihm den Verwaltungsbereich, die
|
||||
Funktionen holt er sich ueber eine Gruppe, auch fuer sich selbst. Der
|
||||
Unterschied zu vorher ist nicht, *ob* er an die Funktionen kommt, sondern
|
||||
dass es dann eine Zeile im Aenderungsprotokoll gibt und in der Matrix zu
|
||||
sehen ist, statt unsichtbar im Kennzeichen zu stecken.
|
||||
|
||||
Fuer alle anderen bleibt die Regel dicht -- auch fuer die Gruppe
|
||||
"Administration", die Benutzer und Gruppen pflegt: sie kann keiner Gruppe
|
||||
ein Recht geben, das sie nicht selbst hat, und sich damit nicht ueber eine
|
||||
neue Gruppe hochstufen.
|
||||
"""
|
||||
if getattr(actor, "is_admin", False):
|
||||
return
|
||||
missing = sorted(p for p in added if not actor.has(p))
|
||||
@@ -132,7 +145,7 @@ def guard_no_amplification(
|
||||
labels = ", ".join(tree.label_for(p) for p in missing[:6])
|
||||
more = "" if len(missing) <= 6 else f" (und {len(missing) - 6} weitere)"
|
||||
raise PermissionDenied(
|
||||
f"Sie koennen kein {what} vergeben, das Sie selbst nicht besitzen: {labels}{more}."
|
||||
f"Sie können kein {what} vergeben, das Sie selbst nicht besitzen: {labels}{more}."
|
||||
)
|
||||
|
||||
|
||||
@@ -160,7 +173,7 @@ def create_group(
|
||||
if existing["deleted_at"]:
|
||||
raise ValidationError(
|
||||
f"Eine Gruppe namens {clean_name!r} liegt im Papierkorb. "
|
||||
"Stellen Sie sie wieder her oder loeschen Sie sie endgueltig."
|
||||
"Stellen Sie sie wieder her oder löschen Sie sie endgültig."
|
||||
)
|
||||
raise ValidationError(f"Eine Gruppe namens {clean_name!r} existiert bereits.")
|
||||
|
||||
@@ -205,7 +218,7 @@ def update_group(
|
||||
|
||||
if name is not None and name.strip() != group.name:
|
||||
if group.is_system:
|
||||
raise PermissionDenied("Systemgruppen koennen nicht umbenannt werden.")
|
||||
raise PermissionDenied("Systemgruppen können nicht umbenannt werden.")
|
||||
clean = name.strip()
|
||||
if not clean:
|
||||
raise ValidationError("Der Gruppenname darf nicht leer sein.")
|
||||
@@ -224,13 +237,13 @@ def update_group(
|
||||
"UPDATE groups SET description=?, updated_at=? WHERE id=?",
|
||||
(description.strip(), _now(), group_id),
|
||||
)
|
||||
changes.append("Beschreibung geaendert")
|
||||
changes.append("Beschreibung geändert")
|
||||
|
||||
if permissions is not None:
|
||||
if group.is_system and not unlock_system:
|
||||
raise PermissionDenied(
|
||||
"Die Rechte dieser Systemgruppe sind gesperrt. "
|
||||
"Sie muessen sie zuerst ausdruecklich freischalten."
|
||||
"Sie müssen sie zuerst ausdrücklich freischalten."
|
||||
)
|
||||
wanted = tree.sanitize(permissions)
|
||||
added = sorted(set(wanted) - set(group.permissions))
|
||||
@@ -240,7 +253,7 @@ def update_group(
|
||||
_write_permissions(conn, group_id, wanted)
|
||||
conn.execute("UPDATE groups SET updated_at=? WHERE id=?", (_now(), group_id))
|
||||
if added:
|
||||
changes.append("Rechte hinzugefuegt: " + ", ".join(tree.label_for(p) for p in added))
|
||||
changes.append("Rechte hinzugefügt: " + ", ".join(tree.label_for(p) for p in added))
|
||||
if removed:
|
||||
changes.append("Rechte entfernt: " + ", ".join(tree.label_for(p) for p in removed))
|
||||
|
||||
@@ -252,7 +265,7 @@ def soft_delete_group(conn: sqlite3.Connection, group_id: int) -> None:
|
||||
if group is None:
|
||||
raise ValidationError("Diese Gruppe existiert nicht.")
|
||||
if group.is_system:
|
||||
raise PermissionDenied("Systemgruppen koennen nicht geloescht werden.")
|
||||
raise PermissionDenied("Systemgruppen können nicht gelöscht werden.")
|
||||
conn.execute("UPDATE groups SET deleted_at=? WHERE id=?", (_now(), group_id))
|
||||
|
||||
|
||||
@@ -315,6 +328,113 @@ def ensure_presets(
|
||||
return created
|
||||
|
||||
|
||||
def unberuehrte_vorlagen_entfernen(
|
||||
conn: sqlite3.Connection, tree: PermissionTree, presets: Sequence[RolePreset]
|
||||
) -> list[str]:
|
||||
"""Legt Vorlagengruppen in den Papierkorb -- aber nur unberuehrte.
|
||||
|
||||
Wird gebraucht, wenn eine Vorlage aus der Auslieferung verschwindet. Auf
|
||||
einer frischen Installation entsteht sie dann gar nicht erst; auf einer
|
||||
bestehenden steht sie in der Datenbank, und eine Migration, die sie einfach
|
||||
loescht, nimmt einem Kunden womoeglich eine Gruppe weg, mit der er
|
||||
arbeitet.
|
||||
|
||||
Darum diese fuenf Bedingungen, und alle fuenf muessen zutreffen:
|
||||
|
||||
* Die Gruppe stammt **aus der Auslieferung**: ihr ``preset_key`` ist der der
|
||||
Vorlage. Diese Kennung setzt nur :func:`ensure_presets`; eine selbst
|
||||
angelegte Gruppe hat sie nicht, auch wenn sie zufaellig denselben Namen
|
||||
traegt. Ueber den Namen wird bewusst *nicht* gesucht -- sonst raeumte
|
||||
dieser Schritt jemandem seine eigene Gruppe "Betrieb" weg.
|
||||
* Sie heisst noch so, wie sie ausgeliefert wurde. Ein anderer Name heisst:
|
||||
jemand hat sie uebernommen.
|
||||
* Die Gruppe hat **keine Mitglieder**. Wer Mitglieder hat, wird benutzt.
|
||||
* Ihre Rechte sind **unveraendert** die der Vorlage. Jede Abweichung heisst:
|
||||
jemand hat sie angepasst, also ist sie seine, nicht unsere.
|
||||
* Sie ist keine Systemgruppe.
|
||||
|
||||
Geloescht wird weich: die Gruppe liegt im Papierkorb und kommt mit einem
|
||||
Klick zurueck. Gibt die Namen der einsortierten Gruppen zurueck.
|
||||
"""
|
||||
entfernt: list[str] = []
|
||||
gruppen = list_groups(conn)
|
||||
for preset in presets:
|
||||
gruppe = next(
|
||||
(
|
||||
g
|
||||
for g in gruppen
|
||||
if g.preset_key
|
||||
and g.preset_key == preset.key
|
||||
and g.name.lower() == preset.name.lower()
|
||||
),
|
||||
None,
|
||||
)
|
||||
if gruppe is None or gruppe.is_system or gruppe.member_count:
|
||||
continue
|
||||
if set(gruppe.permissions) != set(tree.expand_preset(preset)):
|
||||
continue
|
||||
conn.execute("UPDATE groups SET deleted_at=? WHERE id=?", (_now(), gruppe.id))
|
||||
entfernt.append(gruppe.name)
|
||||
return entfernt
|
||||
|
||||
|
||||
def funktionsgruppe_anlegen(
|
||||
conn: sqlite3.Connection, tree: PermissionTree, preset: RolePreset
|
||||
) -> int:
|
||||
"""Legt die Vollzugriffsgruppe an, falls sie fehlt, und gibt ihre Nummer.
|
||||
|
||||
Getrennt von :func:`funktionsgruppe_fuer_administratoren`, weil das zwei
|
||||
verschiedene Dinge sind: hier entsteht nur die Gruppe, dort bekommt sie
|
||||
**jeder** Administrator. Wer ein einzelnes Konto aufnehmen will -- etwa
|
||||
das, das an der Kommandozeile entsteht --, braucht das erste ohne das
|
||||
zweite; sonst faengt sich ein Administrator, der die Gruppe bewusst
|
||||
abgelegt hat, sie beim naechsten Aufruf wieder ein.
|
||||
"""
|
||||
zeile = Database.one(
|
||||
conn, "SELECT id FROM groups WHERE name=? COLLATE NOCASE", (preset.name,)
|
||||
)
|
||||
if zeile is not None:
|
||||
return int(zeile["id"])
|
||||
cursor = conn.execute(
|
||||
"INSERT INTO groups (name, description, is_system, is_default, preset_key, "
|
||||
"created_at, updated_at) VALUES (?,?,0,0,?,?,?)",
|
||||
(preset.name, preset.description, preset.key, _now(), _now()),
|
||||
)
|
||||
gruppe = int(cursor.lastrowid or 0)
|
||||
_write_permissions(conn, gruppe, tree.expand_preset(preset))
|
||||
return gruppe
|
||||
|
||||
|
||||
def funktionsgruppe_fuer_administratoren(
|
||||
conn: sqlite3.Connection, tree: PermissionTree, preset: RolePreset
|
||||
) -> int:
|
||||
"""Legt die Vollzugriffsgruppe an und gibt sie allen Administratoren.
|
||||
|
||||
Der Uebergang zu 2.8.0: bis dahin gab das Kennzeichen ``is_admin`` jede
|
||||
Pruefung frei. Danach gibt es den Verwaltungsbereich, und alles andere
|
||||
kommt ueber Gruppen. Ohne diesen Schritt fehlt einem bestehenden
|
||||
Administrator nach dem Update die halbe Anwendung -- und er haelt das fuer
|
||||
einen Fehler, nicht fuer eine Absicht.
|
||||
|
||||
Auf einer frischen Installation gibt es beim Migrieren noch kein Konto;
|
||||
dann entsteht nur die Gruppe, und wer sie will, weist sie sich zu. Genau so
|
||||
ist die neue Trennung gedacht.
|
||||
|
||||
Gibt die Nummer der Gruppe zurueck.
|
||||
"""
|
||||
gruppe = funktionsgruppe_anlegen(conn, tree, preset)
|
||||
conn.executemany(
|
||||
"INSERT OR IGNORE INTO user_groups (user_id, group_id) VALUES (?,?)",
|
||||
[
|
||||
(int(row["id"]), gruppe)
|
||||
for row in Database.all(
|
||||
conn, "SELECT id FROM users WHERE is_admin=1 AND deleted_at IS NULL"
|
||||
)
|
||||
],
|
||||
)
|
||||
return gruppe
|
||||
|
||||
|
||||
def default_group_id(conn: sqlite3.Connection) -> int | None:
|
||||
value = Database.value(
|
||||
conn, "SELECT id FROM groups WHERE is_default=1 AND deleted_at IS NULL ORDER BY id LIMIT 1"
|
||||
@@ -410,7 +530,7 @@ def guard_target_account(actor: Any, target: dict[str, Any]) -> None:
|
||||
"""Ein Administratorkonto darf nur ein echter Administrator anfassen."""
|
||||
if bool(target.get("is_admin")) and not getattr(actor, "is_admin", False):
|
||||
raise PermissionDenied(
|
||||
"Administratorkonten koennen nur von Administratoren bearbeitet werden."
|
||||
"Administratorkonten können nur von Administratoren bearbeitet werden."
|
||||
)
|
||||
|
||||
|
||||
@@ -420,8 +540,8 @@ def guard_last_admin(conn: sqlite3.Connection, user_id: int, *, action: str) ->
|
||||
return
|
||||
if count_active_admins(conn, exclude_id=user_id) == 0:
|
||||
raise PermissionDenied(
|
||||
f"{action} nicht moeglich: es muss mindestens ein entsperrtes "
|
||||
"Administratorkonto uebrig bleiben."
|
||||
f"{action} nicht möglich: es muss mindestens ein entsperrtes "
|
||||
"Administratorkonto übrig bleiben."
|
||||
)
|
||||
|
||||
|
||||
@@ -482,12 +602,12 @@ def create_user(
|
||||
if existing["deleted_at"]:
|
||||
raise ValidationError(
|
||||
f"Der Benutzername {clean!r} liegt im Papierkorb. Stellen Sie das Konto "
|
||||
"wieder her oder loeschen Sie es endgueltig."
|
||||
"wieder her oder löschen Sie es endgültig."
|
||||
)
|
||||
raise ValidationError(f"Der Benutzername {clean!r} ist bereits vergeben.")
|
||||
|
||||
if is_admin and not getattr(actor, "is_admin", False):
|
||||
raise PermissionDenied("Nur Administratoren koennen weitere Administratoren anlegen.")
|
||||
raise PermissionDenied("Nur Administratoren können weitere Administratoren anlegen.")
|
||||
|
||||
if auth_source == "local":
|
||||
problems = policy.check(password, username=clean)
|
||||
@@ -552,24 +672,30 @@ def update_user(
|
||||
# ueberschrieben -- die Bearbeitung waere eine Illusion.
|
||||
raise ValidationError(
|
||||
"Name und E-Mail eines Verzeichniskontos werden bei jeder Anmeldung "
|
||||
"aus dem Verzeichnis uebernommen und koennen hier nicht geaendert werden."
|
||||
"aus dem Verzeichnis übernommen und können hier nicht geändert werden."
|
||||
)
|
||||
|
||||
fields: dict[str, Any] = {}
|
||||
# Mit Werten, nicht nur "geaendert": aus dem Protokoll soll man den
|
||||
# vorherigen Stand ablesen koennen, ohne eine Sicherung auszupacken.
|
||||
beschriftungen = {"first_name": "Vorname", "last_name": "Nachname", "email": "E-Mail"}
|
||||
for column, value in (
|
||||
("first_name", first_name),
|
||||
("last_name", last_name),
|
||||
("email", email),
|
||||
):
|
||||
if value is not None and value.strip() != str(target.get(column) or ""):
|
||||
alt = str(target.get(column) or "")
|
||||
if value is not None and value.strip() != alt:
|
||||
fields[column] = value.strip()
|
||||
changes.append(f"{column} geaendert")
|
||||
changes.append(
|
||||
f"{beschriftungen[column]}: {alt or '(leer)'} -> {value.strip() or '(leer)'}"
|
||||
)
|
||||
|
||||
if is_admin is not None and bool(is_admin) != bool(target["is_admin"]):
|
||||
if not getattr(actor, "is_admin", False):
|
||||
raise PermissionDenied("Das Admin-Kennzeichen kann nur ein Administrator aendern.")
|
||||
raise PermissionDenied("Das Admin-Kennzeichen kann nur ein Administrator ändern.")
|
||||
if int(target["id"]) == int(getattr(actor, "id", 0)):
|
||||
raise PermissionDenied("Sie koennen Ihr eigenes Admin-Kennzeichen nicht aendern.")
|
||||
raise PermissionDenied("Sie können Ihr eigenes Admin-Kennzeichen nicht ändern.")
|
||||
if not is_admin:
|
||||
guard_last_admin(conn, user_id, action="Herabstufen")
|
||||
fields["is_admin"] = int(bool(is_admin))
|
||||
@@ -577,7 +703,7 @@ def update_user(
|
||||
|
||||
if is_locked is not None and bool(is_locked) != bool(target["is_locked"]):
|
||||
if int(target["id"]) == int(getattr(actor, "id", 0)):
|
||||
raise PermissionDenied("Sie koennen Ihr eigenes Konto nicht sperren.")
|
||||
raise PermissionDenied("Sie können Ihr eigenes Konto nicht sperren.")
|
||||
if is_locked:
|
||||
guard_last_admin(conn, user_id, action="Sperren")
|
||||
fields["is_locked"] = int(bool(is_locked))
|
||||
@@ -595,7 +721,7 @@ def update_user(
|
||||
after = {int(gid) for gid in group_ids}
|
||||
if before != after:
|
||||
set_user_groups(conn, user_id, sorted(after), actor=actor, tree=tree)
|
||||
changes.append("Gruppenzuordnung geaendert")
|
||||
changes.append("Gruppenzuordnung geändert")
|
||||
|
||||
return changes
|
||||
|
||||
@@ -613,7 +739,7 @@ def set_password(
|
||||
raise ValidationError("Dieses Konto existiert nicht.")
|
||||
if str(row.get("auth_source")) == "ldap":
|
||||
raise ValidationError(
|
||||
"Verzeichniskonten haben hier kein Passwort -- es wird im Verzeichnisdienst gepflegt."
|
||||
"Verzeichniskonten haben hier kein Passwort – es wird im Verzeichnisdienst gepflegt."
|
||||
)
|
||||
problems = policy.check(new_password, username=str(row["username"]))
|
||||
if problems:
|
||||
@@ -631,7 +757,7 @@ def soft_delete_user(conn: sqlite3.Connection, user_id: int, *, actor: Any) -> s
|
||||
raise ValidationError("Dieses Konto existiert nicht (mehr).")
|
||||
guard_target_account(actor, target)
|
||||
if int(target["id"]) == int(getattr(actor, "id", 0)):
|
||||
raise PermissionDenied("Sie koennen Ihr eigenes Konto nicht loeschen.")
|
||||
raise PermissionDenied("Sie können Ihr eigenes Konto nicht löschen.")
|
||||
guard_last_admin(conn, user_id, action="Loeschen")
|
||||
|
||||
if str(target.get("auth_source")) == "ldap":
|
||||
@@ -677,7 +803,7 @@ def matrix_state(
|
||||
granted = set(permissions)
|
||||
state: dict[str, dict[str, bool]] = {}
|
||||
for area in tree.areas:
|
||||
state[area.key] = {"view": area.view_key in granted}
|
||||
state[area.key] = {"read": area.read_key in granted}
|
||||
for resource in area.resources:
|
||||
state[resource.key] = {
|
||||
action.value: resource.permission(action) in granted for action in resource.actions
|
||||
@@ -690,7 +816,7 @@ def summarize_permissions(tree: PermissionTree, permissions: Iterable[str]) -> l
|
||||
granted = set(permissions)
|
||||
lines: list[str] = []
|
||||
for area in tree.areas:
|
||||
if area.view_key not in granted:
|
||||
if area.read_key not in granted:
|
||||
continue
|
||||
parts: list[str] = []
|
||||
for resource in area.resources:
|
||||
@@ -706,12 +832,9 @@ def summarize_permissions(tree: PermissionTree, permissions: Iterable[str]) -> l
|
||||
return lines
|
||||
|
||||
|
||||
#: Abgeleitet und nicht abgeschrieben: die Buchstaben stehen in ACTION_META.
|
||||
#: Die zweite Liste hier hatte "U" fuer Bearbeiten, waehrend die Matrix "W"
|
||||
#: zeigte -- dieselbe Aktion, zwei Kuerzel, je nachdem wo man hinsah.
|
||||
ACTION_LETTERS: dict[Action, str] = {
|
||||
Action.VIEW: "R",
|
||||
Action.CREATE: "C",
|
||||
Action.EDIT: "U",
|
||||
Action.DELETE: "D",
|
||||
Action.EXECUTE: "X",
|
||||
Action.EXPORT: "E",
|
||||
Action.SECRETS: "S",
|
||||
action: meta[0] for action, meta in ACTION_META.items()
|
||||
}
|
||||
@@ -112,7 +112,7 @@ def protect() -> None:
|
||||
if not expected or not provided:
|
||||
abort(403, description="Das Sicherheitstoken des Formulars fehlt. Bitte Seite neu laden.")
|
||||
if not hmac.compare_digest(str(expected), str(provided)):
|
||||
abort(403, description="Das Sicherheitstoken des Formulars ist ungueltig. Bitte Seite neu laden.")
|
||||
abort(403, description="Das Sicherheitstoken des Formulars ist ungültig. Bitte Seite neu laden.")
|
||||
|
||||
|
||||
def exempt(view):
|
||||
|
||||
@@ -65,10 +65,10 @@ class PasswordPolicy:
|
||||
if classes < self.require_classes:
|
||||
problems.append(
|
||||
f"Mindestens {self.require_classes} verschiedene Zeichenarten "
|
||||
"(Klein-/Grossbuchstaben, Ziffern, Sonderzeichen)."
|
||||
"(Klein-/Großbuchstaben, Ziffern, Sonderzeichen)."
|
||||
)
|
||||
if normalized.lower() in _FORBIDDEN:
|
||||
problems.append("Dieses Passwort ist zu haeufig und damit unsicher.")
|
||||
problems.append("Dieses Passwort ist zu häufig und damit unsicher.")
|
||||
if username and len(username) >= 3 and username.lower() in normalized.lower():
|
||||
problems.append("Das Passwort darf den Benutzernamen nicht enthalten.")
|
||||
if len(set(normalized)) <= 3 and normalized:
|
||||
|
||||
@@ -163,6 +163,7 @@ class SqliteSessionInterface(SessionInterface):
|
||||
idle_minutes: int,
|
||||
absolute_hours: int,
|
||||
idle_lookup: Any = None,
|
||||
absolute_lookup: Any = None,
|
||||
) -> None:
|
||||
self.database = database
|
||||
self.cookie_name = cookie_name
|
||||
@@ -172,6 +173,16 @@ class SqliteSessionInterface(SessionInterface):
|
||||
#: Zeit zur Laufzeit einstellbar, ohne den Dienst neu zu starten -- und
|
||||
#: ohne eine zweite Datenbankverbindung, denn sie bekommt die offene.
|
||||
self._idle_lookup = idle_lookup
|
||||
self._absolute_lookup = absolute_lookup
|
||||
|
||||
def _absolute(self, conn: Any) -> int:
|
||||
"""Gesamtdauer in Stunden -- einstellbar wie die Leerlaufgrenze."""
|
||||
if self._absolute_lookup is None:
|
||||
return self.absolute_hours
|
||||
try:
|
||||
return int(self._absolute_lookup(conn)) or self.absolute_hours
|
||||
except Exception: # pragma: no cover - Einstellung unlesbar
|
||||
return self.absolute_hours
|
||||
|
||||
def _idle(self, conn: Any) -> int:
|
||||
if self._idle_lookup is None:
|
||||
@@ -280,7 +291,10 @@ class SqliteSessionInterface(SessionInterface):
|
||||
payload = json.dumps(dict(session), separators=(",", ":"), sort_keys=True)
|
||||
with self.database.session() as conn, self.database.transaction(conn):
|
||||
if session.new or not session.sid:
|
||||
session.sid = secrets.token_urlsafe(SESSION_ID_BYTES)
|
||||
# Eine vorhandene ID nicht wegwerfen: nach einem Wechsel beim
|
||||
# Anmelden steht sie schon, und andere haben sie sich gemerkt.
|
||||
if not session.sid:
|
||||
session.sid = secrets.token_urlsafe(SESSION_ID_BYTES)
|
||||
conn.execute(
|
||||
"INSERT INTO user_sessions "
|
||||
"(id, user_id, created_at, last_seen_at, idle_expires_at, "
|
||||
@@ -292,7 +306,7 @@ class SqliteSessionInterface(SessionInterface):
|
||||
_iso(now),
|
||||
_iso(now),
|
||||
_iso(now + timedelta(minutes=self._idle(conn))),
|
||||
_iso(now + timedelta(hours=self.absolute_hours)),
|
||||
_iso(now + timedelta(hours=self._absolute(conn))),
|
||||
session.get("_ip", ""),
|
||||
session.get("_ua", ""),
|
||||
payload,
|
||||
@@ -371,7 +385,12 @@ def rotate(conn: sqlite3.Connection, session: ServerSession, *, reason: str = "p
|
||||
"UPDATE user_sessions SET revoked_at=?, revoked_reason=? WHERE id=?",
|
||||
(_iso(_now()), reason, old_sid),
|
||||
)
|
||||
session.sid = ""
|
||||
# Die neue ID entsteht **jetzt** und nicht erst beim Speichern der Antwort.
|
||||
# Zwischen beidem laufen die Anmeldehaken, und einer davon bindet die
|
||||
# Dateifreigaben ein und schreibt sich die Sitzung dazu. Mit einer leeren
|
||||
# Sitzung hielt der Aufraeumer diese Einbindungen fuer verwaist und loeste
|
||||
# sie binnen Minuten wieder.
|
||||
session.sid = secrets.token_urlsafe(SESSION_ID_BYTES)
|
||||
session.new = True
|
||||
session.modified = True
|
||||
return old_sid
|
||||
|
||||
@@ -58,6 +58,30 @@ class SettingSpec:
|
||||
return str(raw)
|
||||
|
||||
def serialize(self, value: Any) -> str:
|
||||
"""Ein Wert als Text fuer die Datenbank.
|
||||
|
||||
Der Wert kann als Python-Wert kommen (aus einem Formular, aus dem
|
||||
Code) -- oder als die Zeichenkette, die schon in der Datenbank stand.
|
||||
Genau so liest eine **Sicherung** ihn wieder ein, und genau dort lag
|
||||
ein stiller Fehler: ``serialize("0")`` ergab ``"1"``, weil jede nicht
|
||||
leere Zeichenkette wahr ist. Aus jedem abgeschalteten Schalter wurde
|
||||
beim Einspielen ein eingeschalteter -- auch aus
|
||||
``ldap_allow_insecure``. Ein JSON-Feld wurde ein zweites Mal kodiert,
|
||||
und aus der Navigationsreihenfolge damit eine Zeichenkette.
|
||||
|
||||
Deshalb: eine Zeichenkette erst lesen. Was hier herauskommt, muss
|
||||
durch ``serialize`` unveraendert hindurchgehen -- sonst ueberlebt kein
|
||||
Wert eine Sicherung.
|
||||
"""
|
||||
if isinstance(value, str):
|
||||
if self.kind == "bool":
|
||||
value = self.parse(value)
|
||||
elif self.kind == "json":
|
||||
try:
|
||||
value = json.loads(value)
|
||||
except ValueError:
|
||||
# Kein JSON-Text, also ein Wert: dann wird er kodiert.
|
||||
pass
|
||||
if self.kind == "bool":
|
||||
return "1" if value else "0"
|
||||
if self.kind == "json":
|
||||
@@ -67,6 +91,45 @@ class SettingSpec:
|
||||
return "" if value is None else str(value)
|
||||
|
||||
|
||||
#: So lang darf ein Wert im Protokoll werden -- danach wird gekuerzt. Ein
|
||||
#: JSON-Feld mit der halben Navigationsreihenfolge macht die Zeile unlesbar.
|
||||
WERT_GRENZE = 80
|
||||
|
||||
|
||||
class Aenderung(str):
|
||||
"""Eine geaenderte Einstellung, lesbar als ``schluessel: alt -> neu``.
|
||||
|
||||
Eine Zeichenkette und kein eigener Typ, weil die Aufrufer die Liste
|
||||
weiterhin mit ``", ".join(...)`` in einen Protokolleintrag schreiben --
|
||||
so gibt es keine Stelle, die man beim Umbau vergessen kann.
|
||||
"""
|
||||
|
||||
key: str
|
||||
alt: str
|
||||
neu: str
|
||||
|
||||
def __new__(cls, key: str, alt: Any, neu: Any, *, geheim: bool = False) -> "Aenderung":
|
||||
alt_text = "(gesetzt)" if geheim and alt else _kurz(alt)
|
||||
neu_text = "(geaendert)" if geheim else _kurz(neu)
|
||||
selbst = super().__new__(cls, f"{key}: {alt_text} -> {neu_text}")
|
||||
selbst.key = key
|
||||
selbst.alt = alt_text
|
||||
selbst.neu = neu_text
|
||||
return selbst
|
||||
|
||||
|
||||
def _kurz(wert: Any) -> str:
|
||||
"""Ein Wert als kurzer Text -- leer wird sichtbar, lang wird gekuerzt."""
|
||||
if wert is None or wert == "":
|
||||
return "(leer)"
|
||||
if isinstance(wert, bool):
|
||||
return "ein" if wert else "aus"
|
||||
text = " ".join(str(wert).split())
|
||||
if len(text) > WERT_GRENZE:
|
||||
return text[: WERT_GRENZE - 1] + "…"
|
||||
return text
|
||||
|
||||
|
||||
class SettingsStore:
|
||||
"""Zugriff auf ``settings``. Alle Methoden nehmen die bestehende Verbindung."""
|
||||
|
||||
@@ -140,16 +203,24 @@ class SettingsStore:
|
||||
|
||||
def set_many(
|
||||
self, conn: sqlite3.Connection, values: dict[str, Any], *, actor: str = ""
|
||||
) -> list[str]:
|
||||
"""Setzt mehrere Werte, gibt die tatsaechlich geaenderten Schluessel zurueck."""
|
||||
changed: list[str] = []
|
||||
) -> list["Aenderung"]:
|
||||
"""Setzt mehrere Werte und gibt die Aenderungen zurueck.
|
||||
|
||||
Jede Aenderung ist eine Zeichenkette der Form ``schluessel: alt -> neu``
|
||||
-- und traegt die Einzelteile als Attribute. Damit steht im
|
||||
Aenderungsprotokoll, was sich geaendert hat, ohne dass jede
|
||||
Einstellungsseite es einzeln zusammenbauen muss. Vorher stand dort nur
|
||||
der Schluessel, und die Frage "was war vorher eingestellt?" liess sich
|
||||
aus dem Protokoll nicht beantworten.
|
||||
"""
|
||||
changed: list[Aenderung] = []
|
||||
current = self.get_many(conn, list(values))
|
||||
for key, value in values.items():
|
||||
spec = self.spec(key)
|
||||
if spec.serialize(current.get(key)) == spec.serialize(value):
|
||||
continue
|
||||
self.set(conn, key, value, actor=actor)
|
||||
changed.append(key)
|
||||
changed.append(Aenderung(key, current.get(key), value, geheim=spec.kind == "secret"))
|
||||
return changed
|
||||
|
||||
def delete(self, conn: sqlite3.Connection, key: str) -> None:
|
||||
|
||||
@@ -720,6 +720,16 @@
|
||||
min-height: 220px;
|
||||
background: var(--surface-1);
|
||||
}
|
||||
/* Hochkant -- Tablet oder Monitor im Hochformat -- gibt es unter dem Dialog
|
||||
viel Platz, den die Obergrenze verschenkt. Beim Ausfuellen eines
|
||||
Formulars zaehlt jede sichtbare Zeile, also nehmen wir dort die Hoehe,
|
||||
die da ist. Der Rest (Kopf, Dateiname, Fusszeile) braucht rund 200 Pixel;
|
||||
die 240 lassen etwas Luft. */
|
||||
@media (orientation: portrait) {
|
||||
.viewer {
|
||||
height: calc(100dvh - 240px);
|
||||
}
|
||||
}
|
||||
.viewer > .file-preview {
|
||||
flex: 1;
|
||||
height: auto;
|
||||
@@ -754,11 +764,32 @@
|
||||
user-select: none;
|
||||
-webkit-user-drag: none;
|
||||
}
|
||||
/* pdf.js verlangt einen absolut positionierten, scrollenden Behaelter. */
|
||||
/* pdf.js verlangt einen absolut positionierten, scrollenden Behaelter --
|
||||
der liegt deshalb *innen*. Aussen ein gewoehnlicher Flex-Kasten, damit
|
||||
Zoomleiste und Speicherzeile ihren Platz behalten. Vorher rechnete der
|
||||
Bereich mit "bottom: var(--sp-10)", also mit genau einer Leiste; die
|
||||
zweite Zeile lag dann unter dem Dialogrand. */
|
||||
.viewer__pdf {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
/* Ein PDF ist weisses Papier. pdf.js malt Formularfelder mit Systemfarben
|
||||
und ueberlaesst Ankreuzfelder dem Browser -- im dunklen Design heisst
|
||||
CanvasText weiss, und die Haken waren auf dem Papier unsichtbar. Fuer
|
||||
diesen Ausschnitt gilt deshalb immer das helle Schema. */
|
||||
color-scheme: light;
|
||||
}
|
||||
/* pdf.js rechnet fuer die Seite mit dem Standard "content-box": ihr
|
||||
9-Pixel-Rahmen liegt *ausserhalb* der angegebenen Breite. Unser globales
|
||||
"border-box" rechnete ihn hinein -- die Leinwand wurde 18 Pixel schmaler
|
||||
als die Anmerkungsebene, und die Formularfelder wanderten nach rechts
|
||||
unten, immer weiter je weiter unten sie lagen. */
|
||||
.viewer__pdf .pdfViewer .page {
|
||||
box-sizing: content-box;
|
||||
}
|
||||
.viewer__pdfscroll {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
bottom: var(--sp-10);
|
||||
overflow: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
@@ -773,6 +804,75 @@
|
||||
.viewer__hint {
|
||||
margin-inline-start: auto;
|
||||
}
|
||||
/* Bildfeld eines Formulars: der Kasten zeigt das gewaehlte Foto, die
|
||||
Schaltflaeche liegt darin. Acrobats eigener Knopf tut im Browser nichts --
|
||||
das hier ist der Ersatz. */
|
||||
.viewer__bildfeld [data-viewer-bildvorschau] {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: contain;
|
||||
background: #fff;
|
||||
}
|
||||
.viewer__bildwahl {
|
||||
position: absolute;
|
||||
inset: auto 0 4px 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
}
|
||||
.viewer__bildwahl > span {
|
||||
padding: 4px 10px;
|
||||
border-radius: var(--r-sm, 6px);
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
font-size: var(--fs-xs);
|
||||
font-weight: 600;
|
||||
box-shadow: var(--shadow-sm, 0 1px 3px rgb(0 0 0 / 0.3));
|
||||
}
|
||||
.viewer__bildfeld--belegt .viewer__bildwahl > span {
|
||||
opacity: 0.85;
|
||||
}
|
||||
.viewer__save {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
gap: var(--sp-3);
|
||||
padding: var(--sp-3) var(--sp-4);
|
||||
border-top: 1px solid var(--border);
|
||||
background: var(--surface-2, var(--surface-1));
|
||||
}
|
||||
.viewer__save .viewer__feld {
|
||||
flex: 1 1 12rem;
|
||||
margin: 0;
|
||||
}
|
||||
/* Die Entscheidung steht rechts und der Haken darueber: er gehoert zum
|
||||
Speichern, nicht zu den Feldern davor. */
|
||||
.viewer__saveaktionen {
|
||||
margin-left: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
gap: var(--sp-2);
|
||||
}
|
||||
.viewer__saveknoepfe {
|
||||
display: flex;
|
||||
gap: var(--sp-2);
|
||||
}
|
||||
/* Nach "gibt es schon": der Haken ist die Antwort -- also faellt er auf. */
|
||||
.viewer__saveaktionen .check.is-gefragt {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 3px;
|
||||
border-radius: var(--r-xs);
|
||||
}
|
||||
/* Eigener Name: ".field--inline" gibt es schon und steht dort fuer
|
||||
"waagerecht" -- diese Regel haette sie app-weit umgestellt. */
|
||||
.viewer__feld {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
/* Der Dateiname ist ein Knopf (er oeffnet die Vorschau), soll aber wie ein
|
||||
Link aussehen -- ein Knopf mit Rahmen mitten in einer Tabellenzeile waere
|
||||
unruhig. */
|
||||
@@ -910,7 +1010,25 @@
|
||||
text-align: center;
|
||||
}
|
||||
.matrix thead th:first-child { text-align: left; }
|
||||
.matrix td:not(:first-child), .matrix th:not(:first-child) { width: 62px; text-align: center; }
|
||||
/* Kuerzel, englischer Name, deutsche Beschriftung -- untereinander. Nur das
|
||||
Kuerzel allein war eine Spalte, die man nachschlagen musste; die Legende
|
||||
steht unter einer Tabelle, die man dafuer erst zu Ende scrollt. */
|
||||
.matrix__spalte { display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
|
||||
.matrix__spalte b {
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--fs-sm);
|
||||
color: var(--text);
|
||||
font-weight: 650;
|
||||
}
|
||||
.matrix__spalte span { font-size: var(--fs-xs); color: var(--text-muted); text-transform: none; }
|
||||
.matrix__spalte small {
|
||||
font-size: 10px;
|
||||
color: var(--text-faint);
|
||||
text-transform: none;
|
||||
letter-spacing: 0;
|
||||
font-weight: 400;
|
||||
}
|
||||
.matrix td:not(:first-child), .matrix th:not(:first-child) { width: 72px; text-align: center; }
|
||||
.matrix tr.matrix__area > td {
|
||||
background: var(--surface-2);
|
||||
font-weight: 640;
|
||||
@@ -936,6 +1054,46 @@
|
||||
}
|
||||
.matrix__resource-label { display: flex; flex-direction: column; gap: 1px; }
|
||||
.matrix__resource-label small { color: var(--text-faint); font-size: var(--fs-xs); }
|
||||
.matrix__zeile { display: flex; align-items: baseline; gap: var(--sp-2); }
|
||||
.matrix__zeile b { font-weight: 600; }
|
||||
|
||||
/* Unterzeile: gehoert zur Zeile darueber. Ohne Einrueckung liest man sechs
|
||||
unabhaengige Dinge, wo sechs Teile eines Ganzen stehen. */
|
||||
.matrix tr.matrix__unterzeile > td:first-child { padding-left: var(--sp-6); }
|
||||
.matrix tr.matrix__unterzeile > td:first-child .matrix__zeile b { font-weight: 500; }
|
||||
|
||||
/* Was eine Aktion in dieser Zeile bedeutet -- in der Zeile, nicht im
|
||||
Titelattribut: mit dem Finger gibt es kein "hover". */
|
||||
.matrix__bedeutung { color: var(--text-faint); font-size: var(--fs-xs); }
|
||||
.matrix__bedeutung b {
|
||||
font-family: var(--font-mono);
|
||||
color: var(--text-muted);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.matrix__alle {
|
||||
border: 1px solid var(--border);
|
||||
background: transparent;
|
||||
color: var(--text-muted);
|
||||
border-radius: var(--r-sm);
|
||||
font-size: 10px;
|
||||
line-height: 1;
|
||||
padding: 2px 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.matrix__alle:hover { color: var(--accent); border-color: var(--accent); }
|
||||
|
||||
.matrix__filter {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: var(--sp-3);
|
||||
margin-bottom: var(--sp-3);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.matrix__filter-hint { color: var(--text-faint); font-size: var(--fs-xs); }
|
||||
/* Eine ausgefilterte Zeile ist versteckt, nicht entfernt: ihre Kaestchen
|
||||
bleiben im Formular, sonst loescht ein Filter beim Speichern Rechte. */
|
||||
.matrix tr[hidden] { display: none; }
|
||||
.matrix__legend {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
@@ -975,6 +1133,16 @@
|
||||
}
|
||||
.log-view mark { background: var(--warning-soft); color: var(--warning); border-radius: 3px; }
|
||||
|
||||
/* Stufen im laufenden Protokoll. Die Zuordnung der Farbrollen ist Absicht:
|
||||
--warning ist bernsteinfarben und traegt den HINWEIS, --danger ist rot und
|
||||
traegt die WARNUNG. Wer das nach den Namen "aufraeumt", dreht die Bedeutung
|
||||
um: ein Geraet, das nicht antwortet, waere dann orange und eines, das neu
|
||||
startet, rot. */
|
||||
.log-view__zeile--info { color: var(--success); }
|
||||
.log-view__zeile--hinweis { color: var(--warning); }
|
||||
.log-view__zeile--warnung { color: var(--danger); }
|
||||
.log-view__zeile--fehler { color: var(--danger); font-weight: 600; }
|
||||
|
||||
.kv { display: grid; grid-template-columns: auto 1fr; gap: var(--sp-2) var(--sp-4); font-size: var(--fs-base); }
|
||||
.kv dt { color: var(--text-faint); white-space: nowrap; }
|
||||
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
|
||||
@@ -1050,6 +1218,12 @@
|
||||
--tile-accent: var(--text-faint);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
/* Spalte, damit die Fusszeile unten haengen kann (siehe .tile__actions).
|
||||
Die Kacheln eines Rasters sind gleich hoch, ihr Inhalt aber nicht: mal
|
||||
fehlt der Switch, mal der Standort. Ohne diesen Halt stuenden die Knoepfe
|
||||
in jeder Kachel auf einer anderen Hoehe -- und das Auge sucht sie. */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: var(--sp-4);
|
||||
padding-left: calc(var(--sp-4) + 3px);
|
||||
border: 1px solid var(--border-subtle);
|
||||
@@ -1111,6 +1285,73 @@
|
||||
color: var(--text-faint);
|
||||
}
|
||||
|
||||
/* Mitlesen auf der Wartungsseite: die Ausgabe eines laufenden Auftrags,
|
||||
direkt unter seinem Geraet. Dunkler Grund wie in jeder Konsole -- was
|
||||
dort steht, kommt von einer fremden Maschine und nicht aus dieser
|
||||
Oberflaeche. */
|
||||
.job-output {
|
||||
margin: 0;
|
||||
max-height: 220px;
|
||||
overflow: auto;
|
||||
padding: var(--sp-3) var(--sp-4);
|
||||
background: #101216;
|
||||
color: #d7dbe0;
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--fs-xs);
|
||||
line-height: 1.5;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- #
|
||||
Bildschirmsitzung (VNC)
|
||||
|
||||
Die Leinwand bekommt einen dunklen Grund -- unabhaengig vom Thema der
|
||||
Oberflaeche: was darauf erscheint, ist der Bildschirm eines fremden
|
||||
Geraets, und ein heller Rahmen darum laesst ihn wie einen Teil dieser
|
||||
Seite aussehen. Er ist keiner.
|
||||
---------------------------------------------------------------------- */
|
||||
.screen {
|
||||
border: 1px solid var(--border-subtle);
|
||||
border-radius: var(--r-md);
|
||||
background: #101216;
|
||||
overflow: hidden;
|
||||
}
|
||||
.screen__canvas {
|
||||
width: 100%;
|
||||
/* Genug Hoehe, dass ein Bildschirm erkennbar ist, ohne die Seite zu
|
||||
sprengen; noVNC skaliert das Bild hinein. */
|
||||
height: min(72vh, 760px);
|
||||
}
|
||||
/* Im Fenster ist weniger Platz -- und das Fenster soll nicht ueber den
|
||||
Bildschirmrand hinauswachsen, nur weil das Geraet hochaufloesend ist. */
|
||||
dialog.modal .screen__canvas { height: min(62vh, 620px); }
|
||||
.screen__status {
|
||||
font-size: var(--fs-sm);
|
||||
color: var(--text-faint);
|
||||
}
|
||||
.screen__status--ok { color: var(--success); }
|
||||
.screen__status--warnung { color: var(--warning); }
|
||||
.screen__status--fehler { color: var(--danger); }
|
||||
|
||||
/* Fusszeile der Kachel: links der Bildschirm, rechts der Neustart.
|
||||
``margin-top: auto`` schiebt sie an den unteren Rand -- unabhaengig
|
||||
davon, wie viel darueber steht. Die beiden Eingriffe stehen damit in
|
||||
jeder Kachel an derselben Stelle, und der eine liegt nicht dort, wo eben
|
||||
noch der andere war. */
|
||||
.tile__actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--sp-2);
|
||||
margin-top: auto;
|
||||
padding-top: var(--sp-3);
|
||||
}
|
||||
.tile__actions > :last-child { margin-left: auto; }
|
||||
/* Steht nur ein Knopf da, bleibt er links -- sonst spraenge der Neustart bei
|
||||
einem Geraet ohne Bildschirmzugang an die Stelle, an der nebenan VNC
|
||||
steht. Das Fuellstueck haelt den Platz. */
|
||||
.tile__spacer { flex: 1 1 auto; }
|
||||
|
||||
/* Marke und Karte stehen uebereinander im normalen Fluss. Vorher lag die
|
||||
Marke absolut positioniert hinter der Karte -- auf einem flachen Fenster
|
||||
schnitt die Karte mitten durch den Schriftzug und die Funktionszeile. Ein
|
||||
@@ -1234,3 +1475,340 @@
|
||||
.hide-sm { display: none !important; }
|
||||
}
|
||||
}
|
||||
|
||||
/* -- Sortierbare Liste (Navigationsreihenfolge) --------------------------- */
|
||||
/* Symbol und Beschriftung stehen in einer Zeile -- so wie im Menue selbst.
|
||||
Vorher brach die Beschriftung unter das Symbol, und die Liste sah aus wie
|
||||
etwas anderes als das, was sie sortiert. */
|
||||
|
||||
.reorder {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.reorder__row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 6px 10px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--r-sm);
|
||||
background: var(--surface-2);
|
||||
cursor: grab;
|
||||
}
|
||||
|
||||
.reorder__row > .flex-1 {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.reorder__row.is-dragging {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.reorder__grip {
|
||||
color: var(--text-muted);
|
||||
display: inline-flex;
|
||||
}
|
||||
|
||||
.reorder__pos {
|
||||
min-width: 1.6em;
|
||||
text-align: right;
|
||||
font-variant-numeric: tabular-nums;
|
||||
color: var(--text-muted);
|
||||
font-size: var(--fs-xs);
|
||||
}
|
||||
|
||||
.reorder__moves {
|
||||
display: inline-flex;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.reorder__group {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.reorder--child {
|
||||
margin: 4px 0 4px 28px;
|
||||
}
|
||||
|
||||
.reorder--child .reorder__row {
|
||||
background: transparent;
|
||||
border-style: dashed;
|
||||
}
|
||||
|
||||
/* -- Unterschrift --------------------------------------------------------- */
|
||||
/* Die Zeichenflaeche braucht "touch-action: none": sonst scrollt ein iPad die
|
||||
Seite, statt einen Strich zu zeichnen -- und es sieht aus, als reagierte das
|
||||
Feld nicht. */
|
||||
|
||||
.viewer__sign {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
padding: 10px 12px;
|
||||
border-top: 1px solid var(--border);
|
||||
background: var(--surface-2);
|
||||
}
|
||||
|
||||
.viewer__signfelder {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.viewer__signpad {
|
||||
width: 100%;
|
||||
height: 160px;
|
||||
border: 1px dashed var(--border-strong, var(--border));
|
||||
border-radius: var(--r-sm);
|
||||
background: #fff;
|
||||
touch-action: none;
|
||||
cursor: crosshair;
|
||||
}
|
||||
|
||||
.viewer__signaktionen {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
justify-content: flex-end;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.viewer__pdfscroll--setzen {
|
||||
cursor: crosshair;
|
||||
}
|
||||
|
||||
.viewer__pdfscroll--setzen .page {
|
||||
outline: 2px dashed var(--accent, #c8791f);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
|
||||
/* Die gesetzte Unterschrift liegt auf der Seite -- in Prozent, damit sie beim
|
||||
Zoomen an ihrer Stelle bleibt. Sie nimmt Zeiger an: verschieben mit dem
|
||||
Block, Groesse mit dem Griff unten rechts, entfernen mit dem Kreuz.
|
||||
"touch-action: none" ist auf dem iPad die Bedingung dafuer, dass ein Finger
|
||||
zieht statt die Seite zu scrollen. */
|
||||
/* Die Marke ist genau die Zeichnung: ihre Unterkante liegt auf dem
|
||||
Ankerpunkt -- dieselbe Kante, an der pdf-lib das Bild setzt. Der Text
|
||||
haengt darunter und darf die Hoehe nicht mitbestimmen. */
|
||||
.viewer__unterschrift {
|
||||
position: absolute;
|
||||
z-index: 3;
|
||||
cursor: grab;
|
||||
touch-action: none;
|
||||
/* "outline" statt "border": ein Rahmen haette die Marke um zwei Pixel
|
||||
groesser gemacht und die Bildkante vom Ankerpunkt weggeschoben. */
|
||||
outline: 1px dashed transparent;
|
||||
outline-offset: 1px;
|
||||
}
|
||||
|
||||
.viewer__unterschrift:hover,
|
||||
.viewer__unterschrift.is-fassend {
|
||||
outline-color: var(--accent);
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
.viewer__unterschrift img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Dieselbe Rechnung wie im PDF (Breite durch 18): auf dem Schirm steht, was
|
||||
spaeter in der Datei steht. */
|
||||
/* "width: max-content": der Strich ist so lang wie der Text darunter -- so
|
||||
wie im PDF. Waere er so breit wie der Block, zeigte die Vorschau etwas
|
||||
anderes als die Datei. */
|
||||
.viewer__unterschrifttext {
|
||||
/* Unter der Zeichnung, nicht in ihr: "top: 100%" setzt die Oberkante des
|
||||
Strichs auf die Bildkante -- genau dort zieht ihn auch pdf-lib. Abstand,
|
||||
Strichstaerke und Innenabstand rechnet das Skript in Punkten. */
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
/* Helvetica: dieselbe Schrift, die das PDF benutzt (StandardFonts.Helvetica).
|
||||
Mit der Hausschrift sah die Vorschau anders aus als das Ergebnis. Die
|
||||
Groesse setzt das Skript je Unterschrift -- hier steht nur ein Rueckfall. */
|
||||
font-family: Helvetica, Arial, sans-serif;
|
||||
/* Die tatsaechliche Groesse setzt das Skript in Pixeln (Punkte mal
|
||||
Pixel-je-Punkt der Seite). Dieser Wert gilt nur, solange sie noch nicht
|
||||
gerechnet wurde -- geerbt wuerde sonst die Schriftgroesse der Seite. */
|
||||
font-size: 8px;
|
||||
line-height: 1.15;
|
||||
color: #111;
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.85);
|
||||
pointer-events: none;
|
||||
white-space: nowrap;
|
||||
width: max-content;
|
||||
}
|
||||
|
||||
.viewer__unterschriftgriff,
|
||||
.viewer__unterschriftweg {
|
||||
position: absolute;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
padding: 0;
|
||||
border: 1px solid var(--accent);
|
||||
border-radius: 3px;
|
||||
background: var(--surface-1);
|
||||
color: var(--accent);
|
||||
font-size: 11px;
|
||||
line-height: 1;
|
||||
opacity: 0;
|
||||
cursor: nwse-resize;
|
||||
}
|
||||
|
||||
.viewer__unterschriftweg {
|
||||
cursor: pointer;
|
||||
top: -8px;
|
||||
right: -8px;
|
||||
}
|
||||
|
||||
.viewer__unterschriftgriff {
|
||||
right: -8px;
|
||||
bottom: -8px;
|
||||
}
|
||||
|
||||
.viewer__unterschrift:hover .viewer__unterschriftgriff,
|
||||
.viewer__unterschrift:hover .viewer__unterschriftweg,
|
||||
.viewer__unterschrift.is-fassend .viewer__unterschriftgriff {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* Auf einem Tastbildschirm gibt es kein "hover" -- dort stehen die Knoepfe
|
||||
immer, sonst kaeme man nie an sie heran. */
|
||||
@media (hover: none) {
|
||||
.viewer__unterschriftgriff,
|
||||
.viewer__unterschriftweg {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* -- Ergebnis der Signaturpruefung ---------------------------------------- */
|
||||
/* Der Schleier liegt ueber der Seite und nimmt keine Klicks an: ein
|
||||
unterschriebenes Dokument ist flach, aber bei einem Irrtum soll die
|
||||
Kennzeichnung nicht auch noch die Bedienung blockieren. */
|
||||
|
||||
.viewer__pdf--unveraendert {
|
||||
box-shadow: inset 0 0 0 3px var(--success);
|
||||
}
|
||||
|
||||
.viewer__pdf--unveraendert::after,
|
||||
.viewer__pdf--veraendert::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
pointer-events: none;
|
||||
z-index: 4;
|
||||
}
|
||||
|
||||
.viewer__pdf--unveraendert::after {
|
||||
background: rgba(47, 158, 68, 0.1);
|
||||
}
|
||||
|
||||
.viewer__pdf--veraendert {
|
||||
box-shadow: inset 0 0 0 3px var(--danger);
|
||||
}
|
||||
|
||||
.viewer__pdf--veraendert::after {
|
||||
background: rgba(201, 42, 42, 0.08);
|
||||
}
|
||||
|
||||
.viewer__pruefung {
|
||||
margin: 0;
|
||||
padding: 6px 12px;
|
||||
font-size: var(--fs-xs);
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.viewer__pruefung--gut {
|
||||
color: var(--success);
|
||||
background: rgba(47, 158, 68, 0.12);
|
||||
}
|
||||
|
||||
.viewer__pruefung--schlecht {
|
||||
color: var(--danger);
|
||||
background: rgba(201, 42, 42, 0.12);
|
||||
}
|
||||
|
||||
/* -- Tabelle, die schmal zu Bloecken wird -------------------------------- */
|
||||
/* Eine Protokollzeile besteht aus sieben Angaben, von denen eine lang ist:
|
||||
das Detail. Auf einem breiten Schirm passt das nebeneinander. Wird es eng,
|
||||
ist eine Spalte von zwei Zentimetern fuer eine Pruefsumme keine Loesung --
|
||||
dann steht jede Angabe auf ihrer eigenen Zeile, beschriftet. */
|
||||
|
||||
.table--stapelbar .td--detail {
|
||||
/* Zeilenumbrueche aus dem Eintrag bleiben stehen: die Pruefsumme steht
|
||||
unter dem lesbaren Teil, nicht mitten darin. Und ein Hash ohne Trennstelle
|
||||
darf notfalls hart umbrechen. */
|
||||
white-space: pre-line;
|
||||
overflow-wrap: anywhere;
|
||||
max-width: 52ch;
|
||||
}
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
.table--stapelbar thead {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.table--stapelbar,
|
||||
.table--stapelbar tbody,
|
||||
.table--stapelbar tr,
|
||||
.table--stapelbar td {
|
||||
display: block;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.table--stapelbar tr {
|
||||
padding: var(--sp-3) 0;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.table--stapelbar td {
|
||||
display: grid;
|
||||
grid-template-columns: 8.5rem 1fr;
|
||||
gap: var(--sp-2);
|
||||
align-items: baseline;
|
||||
border: 0;
|
||||
padding: 2px var(--sp-3);
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.table--stapelbar td::before {
|
||||
content: attr(data-spalte);
|
||||
color: var(--text-muted);
|
||||
font-size: var(--fs-xs);
|
||||
}
|
||||
|
||||
.table--stapelbar .td--detail {
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
/* Leere Zellen brauchen keine Zeile. */
|
||||
.table--stapelbar td:empty {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* -- Dateiliste: Symbol und Name in einer Zeile -------------------------- */
|
||||
/* Das Symbol ist ein Block-SVG; ohne diese Regel stand der Name darunter und
|
||||
eine Ordnerzeile sah doppelt so hoch aus wie eine Dateizeile. */
|
||||
|
||||
.file-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.file-cell > svg {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ export function showToast(message, type = "info", { timeout = 6000 } = {}) {
|
||||
const close = document.createElement("button");
|
||||
close.type = "button";
|
||||
close.className = "toast__close";
|
||||
close.setAttribute("aria-label", "Meldung schliessen");
|
||||
close.setAttribute("aria-label", "Meldung schließen");
|
||||
close.textContent = "×";
|
||||
toast.append(body, close);
|
||||
toastStack.appendChild(toast);
|
||||
@@ -293,7 +293,7 @@ function initConfirmations() {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
pending = trigger;
|
||||
titleNode.textContent = trigger.dataset.confirmTitle || "Bitte bestaetigen";
|
||||
titleNode.textContent = trigger.dataset.confirmTitle || "Bitte bestätigen";
|
||||
textNode.textContent = trigger.dataset.confirm;
|
||||
okButton.textContent = trigger.dataset.confirmOk || "Fortfahren";
|
||||
okButton.className = `btn btn--${trigger.dataset.confirmStyle || "danger"}`;
|
||||
@@ -440,6 +440,56 @@ function initPermissionMatrix() {
|
||||
});
|
||||
};
|
||||
|
||||
/* -- Ganze Zeile, ganze Spalte, Filter -----------------------------
|
||||
Bei 37 Zeilen und bis zu sieben Spalten je Bereich sind das ueber
|
||||
zweihundert Kaestchen. Ohne diese drei Hilfen setzt man oben den
|
||||
Bereichsschalter und laesst es dabei -- und die feine Aufteilung
|
||||
haette nichts gebracht. */
|
||||
// Nur was man sieht: eine vom Filter ausgeblendete Zeile darf ein
|
||||
// Sammelknopf nicht mitnehmen. Sonst setzt man "alle Write" waehrend nach
|
||||
// "Neustart" gefiltert ist und aendert dabei Zeilen, die gar nicht auf dem
|
||||
// Schirm stehen -- und merkt es erst nach dem Speichern.
|
||||
const sichtbar = (box) => !box.disabled && !box.closest("tr").hidden;
|
||||
const felder = (bereich) =>
|
||||
$$('input[type="checkbox"][name][data-action]', bereich).filter(sichtbar);
|
||||
|
||||
table.addEventListener("click", (event) => {
|
||||
const ziel = event.target;
|
||||
if (!(ziel instanceof HTMLElement)) return;
|
||||
|
||||
const zeilenknopf = ziel.closest("[data-matrix-row]");
|
||||
if (zeilenknopf) {
|
||||
event.preventDefault();
|
||||
const row = zeilenknopf.closest("tr");
|
||||
if (!row) return;
|
||||
const kaestchen = felder(row);
|
||||
// Erst wenn alles gesetzt ist, nimmt der Knopf weg -- sonst waere
|
||||
// ein zweiter Klick auf eine halb gesetzte Zeile ein Ruecksprung.
|
||||
const alleGesetzt = kaestchen.length > 0 && kaestchen.every((box) => box.checked);
|
||||
kaestchen.forEach((box) => {
|
||||
box.checked = !alleGesetzt;
|
||||
box.dispatchEvent(new Event("change", { bubbles: true }));
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const spaltenknopf = ziel.closest("[data-matrix-column]");
|
||||
if (spaltenknopf) {
|
||||
event.preventDefault();
|
||||
const aktion = spaltenknopf.dataset.matrixColumn;
|
||||
const bereich = spaltenknopf.dataset.area;
|
||||
const kaestchen = $$(
|
||||
`tr[data-area="${bereich}"] input[data-action="${aktion}"][name]`,
|
||||
table
|
||||
).filter(sichtbar);
|
||||
const alleGesetzt = kaestchen.length > 0 && kaestchen.every((box) => box.checked);
|
||||
kaestchen.forEach((box) => {
|
||||
box.checked = !alleGesetzt;
|
||||
box.dispatchEvent(new Event("change", { bubbles: true }));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$$("[data-area-switch]", table).forEach((master) => {
|
||||
const areaKey = master.dataset.areaSwitch;
|
||||
syncArea(areaKey);
|
||||
@@ -451,8 +501,12 @@ function initPermissionMatrix() {
|
||||
if (!(box instanceof HTMLInputElement) || !box.dataset.action) return;
|
||||
const row = box.closest("tr");
|
||||
if (!row) return;
|
||||
const viewBox = $('input[data-action="view"]', row);
|
||||
if (box.dataset.action === "view") {
|
||||
// "read", nicht "view": die Aktion heisst seit 2.8.0 wie das, was sie
|
||||
// tut. Mit dem alten Namen fand diese Zeile das Kaestchen nicht mehr --
|
||||
// die Matrix haette sich weiter bedienen lassen und dabei die Regel
|
||||
// "jede Aktion setzt Ansehen voraus" stillschweigend fallen gelassen.
|
||||
const viewBox = $('input[data-action="read"]', row);
|
||||
if (box.dataset.action === "read") {
|
||||
// "Ansehen" abwaehlen entfernt alles andere dieser Zeile.
|
||||
if (!box.checked) {
|
||||
$$('input[type="checkbox"][name]', row).forEach((other) => {
|
||||
@@ -469,6 +523,30 @@ function initPermissionMatrix() {
|
||||
master.dispatchEvent(new Event("change"));
|
||||
}
|
||||
});
|
||||
|
||||
const suche = $("[data-matrix-filter]");
|
||||
const zaehler = $("[data-matrix-count]");
|
||||
if (suche) {
|
||||
const zeilen = $$("tr[data-suchtext]", table);
|
||||
const filtern = () => {
|
||||
const begriff = suche.value.trim().toLowerCase();
|
||||
let sichtbar = 0;
|
||||
zeilen.forEach((row) => {
|
||||
const passt = !begriff || (row.dataset.suchtext || "").includes(begriff);
|
||||
// "hidden" und nicht aus dem Formular nehmen: ein Filter, der
|
||||
// Kaestchen entfernt, loescht beim Speichern Rechte.
|
||||
row.hidden = !passt;
|
||||
if (passt) sichtbar += 1;
|
||||
});
|
||||
if (zaehler) {
|
||||
zaehler.textContent = begriff
|
||||
? `${sichtbar} von ${zeilen.length} Zeilen`
|
||||
: `${zeilen.length} Zeilen`;
|
||||
}
|
||||
};
|
||||
suche.addEventListener("input", filtern);
|
||||
filtern();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -497,14 +575,14 @@ function initAutoRefresh() {
|
||||
nameField.value = entry.name || "";
|
||||
dnField.value = entry.dn || "";
|
||||
results.hidden = true;
|
||||
show(`Uebernommen: ${entry.name || entry.dn}`);
|
||||
show(`Übernommen: ${entry.name || entry.dn}`);
|
||||
};
|
||||
|
||||
const search = async () => {
|
||||
const term = query.value.trim();
|
||||
if (term.length < 2) { show("Bitte mindestens zwei Zeichen eingeben."); return; }
|
||||
button.disabled = true;
|
||||
show("Suche laeuft ...");
|
||||
show("Suche läuft ...");
|
||||
results.innerHTML = "";
|
||||
try {
|
||||
const url = `${picker.dataset.searchUrl}?q=${encodeURIComponent(term)}`;
|
||||
@@ -532,10 +610,10 @@ function initAutoRefresh() {
|
||||
results.appendChild(row);
|
||||
});
|
||||
results.hidden = false;
|
||||
show(`${entries.length} Treffer -- zum Uebernehmen anklicken.`);
|
||||
show(`${entries.length} Treffer – zum Übernehmen anklicken.`);
|
||||
} catch (error) {
|
||||
results.hidden = true;
|
||||
show("Die Suche ist fehlgeschlagen. Laeuft die Verbindung zum Verzeichnis?");
|
||||
show("Die Suche ist fehlgeschlagen. Läuft die Verbindung zum Verzeichnis?");
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
}
|
||||
@@ -720,7 +798,7 @@ function initClipboard() {
|
||||
timeout: 2500,
|
||||
});
|
||||
} catch {
|
||||
showToast("Kopieren nicht moeglich -- bitte manuell markieren.", "warning");
|
||||
showToast("Kopieren nicht möglich – bitte manuell markieren.", "warning");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -856,6 +934,81 @@ function initTileFilters() {
|
||||
});
|
||||
}
|
||||
|
||||
/* -- Reihenfolge aendern -------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Eine Liste, deren Reihenfolge man aendern kann -- ohne Bibliothek.
|
||||
*
|
||||
* Die Reihenfolge steckt in der Reihenfolge der versteckten Felder: das
|
||||
* Formular schickt sie als wiederholtes Feld, und der Server liest sie als
|
||||
* Liste. Verschiebt man einen Eintrag, verschiebt sich das Feld mit ihm.
|
||||
*
|
||||
* Zwei Wege, weil es zwei Arten von Geraeten gibt: Ziehen mit der Maus und
|
||||
* zwei Knoepfe je Zeile. Die Knoepfe sind nicht die Notloesung -- auf einem
|
||||
* Tablet sind sie der einzige Weg, der zuverlaessig funktioniert, und mit der
|
||||
* Tastatur ebenso.
|
||||
*/
|
||||
function initReorder() {
|
||||
$$('[data-behavior="reorder"]').forEach((liste) => {
|
||||
// Nur die eigenen Zeilen: Gruppen enthalten wiederum eine sortierbare
|
||||
// Liste, und deren Zeilen gehoeren der inneren Liste, nicht dieser.
|
||||
const zeilen = () => Array.from(liste.querySelectorAll(":scope > [data-reorder-item]"));
|
||||
|
||||
const nummerieren = () => {
|
||||
zeilen().forEach((zeile, index) => {
|
||||
const nummer = zeile.querySelector("[data-reorder-position-text]");
|
||||
if (nummer) nummer.textContent = String(index + 1);
|
||||
const hoch = zeile.querySelector('[data-reorder-move="up"]');
|
||||
const runter = zeile.querySelector('[data-reorder-move="down"]');
|
||||
if (hoch) hoch.disabled = index === 0;
|
||||
if (runter) runter.disabled = index === zeilen().length - 1;
|
||||
});
|
||||
};
|
||||
|
||||
liste.addEventListener("click", (event) => {
|
||||
const knopf = event.target.closest("[data-reorder-move]");
|
||||
if (!knopf) return;
|
||||
const zeile = knopf.closest("[data-reorder-item]");
|
||||
if (!zeile || zeile.parentElement !== liste) return;
|
||||
event.preventDefault();
|
||||
if (knopf.dataset.reorderMove === "up") {
|
||||
const davor = zeile.previousElementSibling;
|
||||
if (davor) liste.insertBefore(zeile, davor);
|
||||
} else {
|
||||
const danach = zeile.nextElementSibling;
|
||||
if (danach) liste.insertBefore(danach, zeile);
|
||||
}
|
||||
nummerieren();
|
||||
zeile.querySelector(`[data-reorder-move="${knopf.dataset.reorderMove}"]`)?.focus();
|
||||
});
|
||||
|
||||
let gezogen = null;
|
||||
liste.addEventListener("dragstart", (event) => {
|
||||
const zeile = event.target.closest("[data-reorder-item]");
|
||||
if (!zeile || zeile.parentElement !== liste) return;
|
||||
gezogen = zeile;
|
||||
gezogen.classList.add("is-dragging");
|
||||
if (event.dataTransfer) event.dataTransfer.effectAllowed = "move";
|
||||
});
|
||||
liste.addEventListener("dragend", () => {
|
||||
if (gezogen) gezogen.classList.remove("is-dragging");
|
||||
gezogen = null;
|
||||
nummerieren();
|
||||
});
|
||||
liste.addEventListener("dragover", (event) => {
|
||||
if (!gezogen) return;
|
||||
event.preventDefault();
|
||||
const ziel = event.target.closest("[data-reorder-item]");
|
||||
if (!ziel || ziel === gezogen || ziel.parentElement !== liste) return;
|
||||
const kasten = ziel.getBoundingClientRect();
|
||||
const obereHaelfte = event.clientY < kasten.top + kasten.height / 2;
|
||||
liste.insertBefore(gezogen, obereHaelfte ? ziel : ziel.nextElementSibling);
|
||||
});
|
||||
|
||||
nummerieren();
|
||||
});
|
||||
}
|
||||
|
||||
/* -- Start ---------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
@@ -893,6 +1046,7 @@ function boot() {
|
||||
initPalette();
|
||||
initSubmitGuards();
|
||||
initTileFilters();
|
||||
initReorder();
|
||||
initLogTails();
|
||||
unsavedGuard.init();
|
||||
initViewer();
|
||||
@@ -902,7 +1056,11 @@ function boot() {
|
||||
einem PDF noch pdf.js nach. Beides erst dann, wenn es gebraucht wird. */
|
||||
function initViewer() {
|
||||
if (!document.querySelector("[data-viewer]")) return;
|
||||
import("./viewer.js")
|
||||
// Dieselbe Version wie diese Datei: app.js wird als ".../app.js?v=<Zeit>"
|
||||
// eingebunden, und nginx liefert /core-assets/ mit "expires 7d". Ohne das
|
||||
// Anhaengsel bliebe der alte Betrachter nach einem Update im Cache liegen.
|
||||
const version = new URL(import.meta.url).search;
|
||||
import(`./viewer.js${version}`)
|
||||
.then((modul) => modul.initFilePreview())
|
||||
.catch((fehler) => console.error("Dateibetrachter", fehler));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,468 @@
|
||||
// Bildschirmsitzung im Browser: noVNC an die WebSocket-Strecke von TESM.
|
||||
//
|
||||
// Der Client handelt das RFB-Protokoll unmittelbar mit dem Geraet aus; TESM
|
||||
// reicht nur Bytes durch. Alles, was diese Datei tut, ist: verbinden, den
|
||||
// Zustand in Worte fassen und nach Zugangsdaten fragen, wenn keine hinterlegt
|
||||
// sind.
|
||||
//
|
||||
// Die Meldungen sind der eigentliche Wert. Eine Sitzung, die schwarz bleibt,
|
||||
// laesst offen, ob es an der Berechtigung, am Netz, am Server oder am
|
||||
// Passwort liegt -- und wer das nicht sieht, sucht den Fehler in TESM.
|
||||
//
|
||||
// **Ein Bauteil, zwei Orte.** Dieselbe Sitzung laeuft auf der Bildschirmseite
|
||||
// und im Fenster der Statusuebersicht. Sie holt alles, was sie braucht, aus
|
||||
// einer JSON-Auskunft des Servers -- damit gibt es keine zweite Fassung, die
|
||||
// man beim naechsten Fund vergisst nachzuziehen.
|
||||
|
||||
import RFB from "../vendor/novnc/core/rfb.js";
|
||||
|
||||
// Drei Eingriffe in private Methoden der mitgelieferten Bibliothek. Bewusst
|
||||
// hier und nicht in der Bibliothek selbst: eine neue Fassung von noVNC laesst
|
||||
// sich dann austauschen, ohne eine Aenderung nachzupflegen -- faellt eine
|
||||
// Methode weg, entfaellt nur die Auskunft, nicht die Sitzung.
|
||||
//
|
||||
// Zwei davon holen nur Auskunft (_fail, _socketClose). Der dritte greift in
|
||||
// die Wahl des Sicherheitsverfahrens ein -- aber erst, **nachdem** eines
|
||||
// nachweislich nicht getragen hat, oder weil eines schon einmal getragen hat.
|
||||
//
|
||||
// Die Vorgeschichte gehoert dazu, damit niemand den Schritt zurueckgeht: hier
|
||||
// stand einmal eine Vorauswahl, die ohne hinterlegte Zugangsdaten ein
|
||||
// Verfahren ohne Anmeldung erzwang, weil RealVNC RA2ne zuerst nennt. Das war
|
||||
// geraten und falsch. Was jetzt hier steht, ist das Gegenteil einer Vermutung:
|
||||
// ein Befund aus einer vorherigen Sitzung.
|
||||
const istUnterstuetzt = RFB.prototype._isSupportedSecurityType;
|
||||
|
||||
//: Den *Grund* eines Fehlschlags kennt nur ``_fail`` -- das Ereignis
|
||||
//: "disconnect" traegt ihn nicht, und der Weg ueber die Protokollausgabe
|
||||
//: funktioniert nicht: die Bibliothek bindet ``console.error`` beim Laden,
|
||||
//: also bevor eine Seite etwas daran aendern koennte.
|
||||
let letzterGrund = "";
|
||||
const originalFail = RFB.prototype._fail;
|
||||
RFB.prototype._fail = function (details) {
|
||||
letzterGrund = String(details);
|
||||
return originalFail.call(this, details);
|
||||
};
|
||||
|
||||
//: Und der Abschluss der Leitung selbst: der Schliesscode sagt, ob TESM
|
||||
//: abgewiesen hat (1008), ob es ein Serverfehler war (1011) -- oder ob die
|
||||
//: Verbindung nie zustande kam (1006).
|
||||
let letzterCode = 0;
|
||||
const originalSocketClose = RFB.prototype._socketClose;
|
||||
RFB.prototype._socketClose = function (ereignis) {
|
||||
letzterCode = (ereignis && ereignis.code) || 0;
|
||||
if (ereignis && ereignis.reason) {
|
||||
letzterGrund = letzterGrund || String(ereignis.reason);
|
||||
}
|
||||
return originalSocketClose.call(this, ereignis);
|
||||
};
|
||||
|
||||
//: Hoechstens ein zweiter Anlauf. Jeder Versuch ist eine Verbindung, und ein
|
||||
//: RealVNC Server zaehlt abgebrochene Versuche mit -- wer dreimal anklopft,
|
||||
//: sperrt sich aus.
|
||||
const HOECHSTENS = 2;
|
||||
|
||||
//: So lange darf "wird aufgebaut" stehen, bevor die Seite selbst nachsieht.
|
||||
//: Kommt die WebSocket-Verbindung gar nicht erst zustande, wartet noVNC ohne
|
||||
//: jedes Ereignis, und die Seite stuende stumm bis zum Seitenwechsel.
|
||||
const AUFBAU_GRENZE = 12000;
|
||||
|
||||
//: Verfahren, die im Browser keinen Schluesseltausch kosten.
|
||||
//:
|
||||
//: Der Grund steht in der Bibliothek, `core/ra2.js`: fuer RA2ne erzeugt der
|
||||
//: **Browser** bei jeder Sitzung ein eigenes 2048-Bit-RSA-Schluesselpaar, in
|
||||
//: JavaScript. Die Primzahlsuche dafuer dauert ein bis drei Minuten -- genau
|
||||
//: die Zeit, die zwischen Klick und Bild lag. "Ohne Authentifizierung" (1)
|
||||
//: kostet davon nichts.
|
||||
//:
|
||||
//: Deshalb kommt es zuerst, **wenn der Server es anbietet** und wir nicht
|
||||
//: ohnehin schon wissen, was hier traegt. Das ist nicht dieselbe Vorauswahl
|
||||
//: wie in 2.8.14: die war geraten, diese steht auf einer Messung. Traegt sie
|
||||
//: nicht, nimmt der zweite Anlauf die Reihenfolge des Servers -- dann dauert
|
||||
//: es eben.
|
||||
const OHNE_SCHLUESSELTAUSCH = new Set([1]);
|
||||
|
||||
//: RA2ne. Wird es ausgehandelt, ist die Wartezeit erklaerbar und kein Fehler.
|
||||
const RA2NE = 6;
|
||||
|
||||
//: Tastenkombinationen, die der Arbeitsplatz selbst abfaengt und die deshalb
|
||||
//: einen Knopf brauchen. X11-Keysyms.
|
||||
const ALT_LINKS = 0xffe9;
|
||||
const F4 = 0xffc1;
|
||||
const F5 = 0xffc2;
|
||||
|
||||
const schema = window.location.protocol === "https:" ? "wss:" : "ws:";
|
||||
|
||||
/**
|
||||
* Baut eine Sitzung in diesem Behaelter auf.
|
||||
*
|
||||
* ``quelle`` ist die Adresse der JSON-Auskunft; alles Weitere steht dort.
|
||||
* Rueckgabe: eine Funktion, die die Sitzung wieder abbaut.
|
||||
*/
|
||||
export function starteSitzung(wurzel, quelle, { beiEnde = null } = {}) {
|
||||
const teil = (rolle) => wurzel.querySelector(`[data-rolle="${rolle}"]`);
|
||||
const leinwand = teil("leinwand");
|
||||
const zeile = teil("status");
|
||||
const abfrage = teil("zugangsdaten");
|
||||
const feldBenutzer = teil("benutzer");
|
||||
const feldPasswort = teil("passwort");
|
||||
const knopfSenden = teil("anmelden");
|
||||
const knopfTrennen = teil("trennen");
|
||||
const knoepfeSitzung = [...wurzel.querySelectorAll("[data-rolle^='taste-']"), knopfTrennen];
|
||||
|
||||
const gescheitert = new Set();
|
||||
let rfb = null;
|
||||
let aufbauUhr = 0;
|
||||
let versuche = 0;
|
||||
let stand = false;
|
||||
let daten = null;
|
||||
let letzterZugang = {};
|
||||
let beendet = false;
|
||||
|
||||
function melden(text, art = "") {
|
||||
if (!zeile) return;
|
||||
zeile.textContent = text;
|
||||
zeile.className = `screen__status${art ? " screen__status--" + art : ""}`;
|
||||
}
|
||||
|
||||
function sitzungsknoepfe(sichtbar) {
|
||||
knoepfeSitzung.forEach((knopf) => {
|
||||
if (knopf) knopf.hidden = !sichtbar;
|
||||
});
|
||||
}
|
||||
|
||||
function grund() {
|
||||
const teile = [];
|
||||
if (letzterGrund) {
|
||||
teile.push(letzterGrund.replace(/^Failed (when|while) \w+: /, ""));
|
||||
}
|
||||
if (rfb && rfb._rfbAuthScheme > 0) {
|
||||
teile.push(`gewähltes Verfahren: ${rfb._rfbAuthScheme}`);
|
||||
}
|
||||
if (gescheitert.size) {
|
||||
teile.push(`erfolglos: ${[...gescheitert].join(", ")}`);
|
||||
}
|
||||
return teile.join(" · ");
|
||||
}
|
||||
|
||||
// Steht die WebSocket-Strecke zu TESM überhaupt? Zwei sehr verschiedene
|
||||
// Ursachen sehen von aussen gleich aus: der VNC-Server mag nicht, oder die
|
||||
// Verbindung kommt nie zustande, weil ein Proxy zwischen Browser und TESM
|
||||
// "Upgrade" nicht durchreicht. Diese Probe trennt sie.
|
||||
function streckeTesten() {
|
||||
return new Promise((fertig) => {
|
||||
let beantwortet = false;
|
||||
const pruefling = new WebSocket(`${schema}//${window.location.host}/ws/probe`);
|
||||
const schliessen = (ergebnis) => {
|
||||
if (beantwortet) return;
|
||||
beantwortet = true;
|
||||
try {
|
||||
pruefling.close();
|
||||
} catch (fehler) {
|
||||
/* schon zu */
|
||||
}
|
||||
fertig(ergebnis);
|
||||
};
|
||||
pruefling.onmessage = () => schliessen(true);
|
||||
pruefling.onerror = () => schliessen(false);
|
||||
pruefling.onclose = () => schliessen(false);
|
||||
window.setTimeout(() => schliessen(false), 4000);
|
||||
});
|
||||
}
|
||||
|
||||
// Hat das gewählte Verfahren die Verbindung abreissen lassen? Dann ist das
|
||||
// ein Befund und keine Vermutung -- der naechste Anlauf laesst es aus. Nur
|
||||
// solange nie ein Bild stand: bricht eine **laufende** Sitzung ab, liegt es
|
||||
// nicht am Anmeldeverfahren.
|
||||
function naechsterVersuch() {
|
||||
const verfahren = rfb && rfb._rfbAuthScheme > 0 ? rfb._rfbAuthScheme : 0;
|
||||
if (!verfahren || versuche >= HOECHSTENS || gescheitert.has(verfahren)) {
|
||||
return false;
|
||||
}
|
||||
gescheitert.add(verfahren);
|
||||
melden(
|
||||
`Verfahren ${verfahren} hat die Verbindung nicht getragen – nächster Anlauf ` +
|
||||
"mit dem nächsten, das der Server anbietet …",
|
||||
"warnung",
|
||||
);
|
||||
const zugang = letzterZugang;
|
||||
rfb = null;
|
||||
window.setTimeout(() => verbinden(zugang), 400);
|
||||
return true;
|
||||
}
|
||||
|
||||
function verfahrenMelden(gewaehlt) {
|
||||
if (!gewaehlt || gewaehlt === daten.bewaehrt || !daten.meldeweg) return;
|
||||
fetch(daten.meldeweg, {
|
||||
method: "POST",
|
||||
credentials: "same-origin",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-Requested-With": "fetch",
|
||||
"X-CSRF-Token": document.body?.dataset.csrf || "",
|
||||
},
|
||||
body: JSON.stringify({ verfahren: gewaehlt }),
|
||||
}).catch(() => {
|
||||
/* Eine Merkhilfe, kein Teil der Sitzung. */
|
||||
});
|
||||
}
|
||||
|
||||
function verbinden(zugang) {
|
||||
if (beendet) return;
|
||||
melden(versuche ? "Nächster Versuch …" : "Verbindung wird aufgebaut …");
|
||||
letzterGrund = "";
|
||||
letzterCode = 0;
|
||||
letzterZugang = zugang;
|
||||
versuche += 1;
|
||||
window.clearTimeout(aufbauUhr);
|
||||
aufbauUhr = window.setTimeout(() => {
|
||||
// Ein ausgehandeltes RA2ne ist kein Fehler, sondern Rechenzeit: der
|
||||
// Browser erzeugt dafuer gerade einen 2048-Bit-Schluessel. Das zu
|
||||
// melden ist das Gegenteil einer Warnung -- es nimmt die Sorge.
|
||||
if (rfb && rfb._rfbAuthScheme === RA2NE) {
|
||||
melden(
|
||||
"Der Server verlangt RA2ne (RSA-AES). Dafür erzeugt der Browser ein " +
|
||||
"2048-Bit-Schlüsselpaar – das dauert ein bis drei Minuten. Bitte warten.",
|
||||
"warnung",
|
||||
);
|
||||
return;
|
||||
}
|
||||
melden("Es kommt keine Antwort. Wird geprüft, woran es liegt …", "warnung");
|
||||
streckeTesten().then((steht) => {
|
||||
melden(
|
||||
steht
|
||||
? "Die WebSocket-Strecke zu TESM steht, aber die Sitzung kommt nicht " +
|
||||
"zustande. Antwortet der VNC-Server auf dem Gerät noch? Ein Neustart " +
|
||||
"des VNC-Dienstes räumt eine Sperre ab."
|
||||
: "Die WebSocket-Verbindung zu TESM kommt nicht zustande – auch eine " +
|
||||
"einfache Probe scheitert. Ein Proxy zwischen Browser und TESM muss " +
|
||||
"die Kopfzeilen Upgrade und Connection durchreichen (nginx: " +
|
||||
"location /ws/ mit proxy_set_header Upgrade $http_upgrade).",
|
||||
"fehler",
|
||||
);
|
||||
});
|
||||
}, AUFBAU_GRENZE);
|
||||
|
||||
// Drei Regeln, alle aus Messung und keine aus Vermutung:
|
||||
//
|
||||
// 1. Was schon einmal getragen hat, kommt zuerst.
|
||||
// 2. Sonst das Verfahren ohne Schluesseltausch -- aber nur, wenn der
|
||||
// Server es nachweislich anbietet (sonst faende noVNC gar keines und
|
||||
// scheiterte sofort). RA2ne kostet sonst ein bis drei Minuten
|
||||
// Rechenzeit im Browser, jedes Mal.
|
||||
// 3. Was abgerissen ist, wird nicht noch einmal gewaehlt.
|
||||
//
|
||||
// Beides gilt nur fuer den **ersten** Anlauf; danach zaehlt die
|
||||
// Reihenfolge des Servers, abzueglich dessen, was schon abgerissen ist.
|
||||
const bewaehrt = daten.bewaehrt || 0;
|
||||
const angeboten = daten.verfahren || [];
|
||||
const schnell = angeboten.filter((typ) => OHNE_SCHLUESSELTAUSCH.has(typ));
|
||||
let bevorzugt = 0;
|
||||
if (versuche === 1) {
|
||||
if (bewaehrt > 0 && !gescheitert.has(bewaehrt)) bevorzugt = bewaehrt;
|
||||
else if (schnell.length && !gescheitert.has(schnell[0])) bevorzugt = schnell[0];
|
||||
}
|
||||
RFB.prototype._isSupportedSecurityType = function (typ) {
|
||||
if (gescheitert.has(typ)) return false;
|
||||
if (bevorzugt) return typ === bevorzugt;
|
||||
return istUnterstuetzt.call(this, typ);
|
||||
};
|
||||
|
||||
rfb = new RFB(leinwand, `${schema}//${window.location.host}${daten.socket}`, {
|
||||
credentials: zugang,
|
||||
// Eine Bildschirmsitzung soll nicht nebenbei die Zwischenablage des
|
||||
// Arbeitsplatzes mit dem Geraet teilen -- das ist eine eigene
|
||||
// Entscheidung, und niemand hat sie hier getroffen.
|
||||
clipboardTarget: null,
|
||||
});
|
||||
rfb.scaleViewport = true;
|
||||
rfb.resizeSession = false;
|
||||
rfb.focusOnClick = true;
|
||||
|
||||
rfb.addEventListener("connect", () => {
|
||||
window.clearTimeout(aufbauUhr);
|
||||
stand = true;
|
||||
verfahrenMelden(rfb && rfb._rfbAuthScheme > 0 ? rfb._rfbAuthScheme : 0);
|
||||
melden(`Verbunden mit ${daten.ziel}`, "ok");
|
||||
if (abfrage) abfrage.hidden = true;
|
||||
leinwand.hidden = false;
|
||||
sitzungsknoepfe(true);
|
||||
});
|
||||
|
||||
rfb.addEventListener("disconnect", (ereignis) => {
|
||||
window.clearTimeout(aufbauUhr);
|
||||
leinwand.hidden = true;
|
||||
sitzungsknoepfe(false);
|
||||
if (ereignis.detail && ereignis.detail.clean) {
|
||||
// Beim sauberen Schluss steht der Grund im Schliessrahmen -- etwa,
|
||||
// dass TESM wegen Untätigkeit getrennt hat.
|
||||
melden(letzterGrund ? `Sitzung beendet – ${letzterGrund}` : "Sitzung beendet.");
|
||||
// Im Fenster gibt es nach dem Trennen nichts mehr zu sehen: ein leerer
|
||||
// Rahmen, den man wegklicken muss. Bei einem **Abbruch** bleibt es
|
||||
// stehen -- dort steht der Grund, und der ist der ganze Zweck.
|
||||
beiEnde?.();
|
||||
} else if (!stand && naechsterVersuch()) {
|
||||
return;
|
||||
} else {
|
||||
const erklaerung = grund();
|
||||
melden(
|
||||
erklaerung
|
||||
? `Verbindung abgebrochen – ${erklaerung}`
|
||||
: "Verbindung abgebrochen. Wird geprüft, woran es liegt …",
|
||||
"fehler",
|
||||
);
|
||||
if (letzterCode === 1006 || !erklaerung) {
|
||||
streckeTesten().then((steht) => {
|
||||
melden(
|
||||
steht
|
||||
? `${erklaerung || "Verbindung abgebrochen"} – die WebSocket-Strecke zu ` +
|
||||
"TESM selbst steht (Probe erfolgreich), der Abbruch kommt also von " +
|
||||
"der VNC-Seite."
|
||||
: "Die WebSocket-Verbindung zu TESM kommt nicht zustande – auch eine " +
|
||||
"einfache Probe scheitert. Ein Proxy zwischen Browser und TESM muss " +
|
||||
"die Kopfzeilen Upgrade und Connection durchreichen (nginx: " +
|
||||
"location /ws/ mit proxy_set_header Upgrade $http_upgrade). Dasselbe " +
|
||||
"gilt für die Browser-Konsole.",
|
||||
"fehler",
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
rfb = null;
|
||||
});
|
||||
|
||||
rfb.addEventListener("credentialsrequired", (ereignis) => {
|
||||
window.clearTimeout(aufbauUhr);
|
||||
const gefragt = ereignis.detail.types || ["password"];
|
||||
if (abfrage) abfrage.hidden = false;
|
||||
if (feldBenutzer) feldBenutzer.closest("label").hidden = !gefragt.includes("username");
|
||||
melden("Der VNC-Server verlangt Zugangsdaten.", "warnung");
|
||||
(gefragt.includes("username") ? feldBenutzer : feldPasswort)?.focus();
|
||||
});
|
||||
|
||||
rfb.addEventListener("securityfailure", (ereignis) => {
|
||||
window.clearTimeout(aufbauUhr);
|
||||
melden(
|
||||
`Anmeldung abgelehnt: ${ereignis.detail.reason || "kein Grund genannt"}`,
|
||||
"fehler",
|
||||
);
|
||||
if (abfrage) abfrage.hidden = false;
|
||||
});
|
||||
}
|
||||
|
||||
knopfSenden?.addEventListener("click", () => {
|
||||
const zugang = {};
|
||||
if (feldBenutzer?.value) zugang.username = feldBenutzer.value;
|
||||
if (feldPasswort?.value) zugang.password = feldPasswort.value;
|
||||
if (rfb) rfb.sendCredentials(zugang);
|
||||
else verbinden(zugang);
|
||||
});
|
||||
|
||||
[feldBenutzer, feldPasswort].forEach((feld) =>
|
||||
feld?.addEventListener("keydown", (ereignis) => {
|
||||
if (ereignis.key === "Enter") {
|
||||
ereignis.preventDefault();
|
||||
knopfSenden?.click();
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
knopfTrennen?.addEventListener("click", () => rfb && rfb.disconnect());
|
||||
teil("taste-cad")?.addEventListener("click", () => rfb && rfb.sendCtrlAltDel());
|
||||
// Alt+F4 kennt noVNC nicht als fertigen Griff: der Arbeitsplatz faengt die
|
||||
// Kombination selbst ab, bevor sie in der Leinwand ankommt. Also einzeln --
|
||||
// Alt halten, F4 tippen, Alt loslassen -- wie es auf der Tastatur auch
|
||||
// geschieht.
|
||||
teil("taste-altf4")?.addEventListener("click", () => {
|
||||
if (!rfb) return;
|
||||
rfb.sendKey(ALT_LINKS, "AltLeft", true);
|
||||
rfb.sendKey(F4, "F4", true);
|
||||
rfb.sendKey(F4, "F4", false);
|
||||
rfb.sendKey(ALT_LINKS, "AltLeft", false);
|
||||
});
|
||||
// F5 faengt der Browser des Arbeitsplatzes ab -- er wuerde diese Seite neu
|
||||
// laden statt das Bild auf dem Geraet.
|
||||
teil("taste-f5")?.addEventListener("click", () => {
|
||||
if (!rfb) return;
|
||||
rfb.sendKey(F5, "F5", true);
|
||||
rfb.sendKey(F5, "F5", false);
|
||||
});
|
||||
|
||||
sitzungsknoepfe(false);
|
||||
melden("Wird vorbereitet …");
|
||||
|
||||
fetch(quelle, { credentials: "same-origin", headers: { "X-Requested-With": "fetch" } })
|
||||
.then((antwort) => antwort.json().then((inhalt) => ({ status: antwort.status, inhalt })))
|
||||
.then(({ status, inhalt }) => {
|
||||
if (beendet) return;
|
||||
if (status === 409 && inhalt.reauth) {
|
||||
melden(
|
||||
"Für den Bildschirm ist eine frische Passwortbestätigung nötig – bitte über " +
|
||||
"die Geräteseite öffnen.",
|
||||
"warnung",
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (status !== 200) {
|
||||
melden(inhalt.fehler || "Diese Sitzung lässt sich nicht öffnen.", "fehler");
|
||||
return;
|
||||
}
|
||||
daten = inhalt;
|
||||
if (daten.hinderungsgrund) {
|
||||
melden(daten.hinderungsgrund, "fehler");
|
||||
return;
|
||||
}
|
||||
const zugang = {};
|
||||
if (daten.vorgaben?.username) zugang.username = daten.vorgaben.username;
|
||||
if (daten.vorgaben?.password) zugang.password = daten.vorgaben.password;
|
||||
verbinden(zugang);
|
||||
})
|
||||
.catch(() => melden("Die Sitzungsdaten sind nicht abrufbar.", "fehler"));
|
||||
|
||||
return function beenden() {
|
||||
beendet = true;
|
||||
window.clearTimeout(aufbauUhr);
|
||||
try {
|
||||
rfb?.disconnect();
|
||||
} catch (fehler) {
|
||||
/* schon zu */
|
||||
}
|
||||
rfb = null;
|
||||
};
|
||||
}
|
||||
|
||||
// -- Die beiden Orte -------------------------------------------------------- #
|
||||
|
||||
// 1. Die Bildschirmseite: ein Behaelter, der seine Quelle selbst mitbringt.
|
||||
const seite = document.getElementById("screen");
|
||||
if (seite?.dataset.sitzung) {
|
||||
starteSitzung(seite, seite.dataset.sitzung);
|
||||
}
|
||||
|
||||
// 2. Die Statusuebersicht: ein Fenster, das jede Kachel oeffnen kann. Ein
|
||||
// Dialog fuer alle -- er bekommt beim Oeffnen, welches Geraet gemeint ist.
|
||||
const fenster = document.getElementById("vnc-fenster");
|
||||
if (fenster) {
|
||||
let beenden = null;
|
||||
const behaelter = fenster.querySelector("[data-rolle='behaelter']");
|
||||
const titel = fenster.querySelector("[data-rolle='titel']");
|
||||
|
||||
document.addEventListener("click", (ereignis) => {
|
||||
const knopf = ereignis.target.closest("[data-vnc-oeffnen]");
|
||||
if (!knopf) return;
|
||||
ereignis.preventDefault();
|
||||
beenden?.();
|
||||
titel.textContent = knopf.dataset.vncName || "Bildschirm";
|
||||
if (typeof fenster.showModal === "function") fenster.showModal();
|
||||
else fenster.setAttribute("open", "");
|
||||
beenden = starteSitzung(behaelter, knopf.dataset.vncOeffnen, {
|
||||
beiEnde: () => fenster.close(),
|
||||
});
|
||||
});
|
||||
|
||||
// Zu heisst zu: eine Sitzung, die im Hintergrund weiterlaeuft, haelt die
|
||||
// Verbindung zum Geraet und bei RealVNC den einen Sitzungsplatz.
|
||||
fenster.addEventListener("close", () => {
|
||||
beenden?.();
|
||||
beenden = null;
|
||||
});
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,13 @@
|
||||
maintainers:
|
||||
- Samuel Mannehed for Cendio AB (@samhed)
|
||||
- Pierre Ossman for Cendio AB (@CendioOssman)
|
||||
maintainersEmeritus:
|
||||
- Joel Martin (@kanaka)
|
||||
- Solly Ross (@directxman12)
|
||||
- @astrand
|
||||
contributors:
|
||||
# There are a bunch of people that should be here.
|
||||
# If you want to be on this list, feel free send a PR
|
||||
# to add yourself.
|
||||
- jalf <git@jalf.dk>
|
||||
- NTT corp.
|
||||
@@ -0,0 +1,52 @@
|
||||
# noVNC 1.6.0 -- mitgeliefert, nicht nachgeladen
|
||||
|
||||
Quelle: <https://github.com/novnc/noVNC>, Fassung **1.6.0**, uebernommen am
|
||||
13.09.2026. Enthalten sind `core/` (die Bibliothek) und `vendor/pako` (die
|
||||
Entpackroutine, die `core/inflator.js` braucht) -- ohne `app/`, `tests/` und
|
||||
die mitgelieferte Oberflaeche: die Bedienung stellt TESM selbst
|
||||
(`apps/tesm/src/tesm/templates/tesm/screen.html`).
|
||||
|
||||
**Lizenz:** MPL-2.0 fuer die Kernbibliothek, siehe `LICENSE.txt` und `AUTHORS`
|
||||
(beide unveraendert uebernommen). pako steht unter MIT, siehe
|
||||
`vendor/pako/LICENSE`.
|
||||
|
||||
**Warum mitgeliefert und nicht von einem CDN:** dieselbe Regel wie bei pdf.js
|
||||
und pdf-lib nebenan. Die Anwendung laeuft in Netzen ohne Internetzugang, die
|
||||
Inhaltsrichtlinie (CSP) erlaubt ausschliesslich `'self'`, und eine
|
||||
Bibliothek, die sich zur Laufzeit aendern kann, gehoert nicht in einen Pfad,
|
||||
der einen Bildschirm fernsteuert.
|
||||
|
||||
**Unveraendert.** Wird eine Anpassung noetig, gehoert sie hierher in diese
|
||||
Datei -- mit Grund und Fundstelle, damit ein Wechsel auf eine neuere Fassung
|
||||
nicht stillschweigend darueberlaeuft.
|
||||
|
||||
**Was TESM von aussen umbiegt** (also *nicht* in diesen Dateien steht, sondern
|
||||
in `js/screen.js`):
|
||||
|
||||
* `RFB.prototype._fail` und `_socketClose` -- nur, um den Grund eines
|
||||
Abbruchs zu erfahren. noVNC meldet ihn sonst ausschliesslich in die
|
||||
Entwicklerkonsole, und `console.error` mitzulesen traegt nicht: die
|
||||
Bibliothek bindet es beim Laden.
|
||||
* `RFB.prototype._isSupportedSecurityType` -- **erst nachdem** ein Verfahren
|
||||
die Verbindung nachweislich hat abreissen lassen. Dann wird es fuer den
|
||||
zweiten Anlauf ausgelassen, damit noVNC nicht wieder dasselbe zuerst findet.
|
||||
Hoechstens zwei Anlaeufe, denn jeder ist eine Verbindung, und ein RealVNC
|
||||
Server zaehlt abgebrochene mit.
|
||||
|
||||
Hier stand einmal das Gegenteil: eine **Vorauswahl**, die ohne hinterlegte
|
||||
Zugangsdaten ein Verfahren ohne Anmeldung erzwang. Das war geraten und hat
|
||||
eine laufende Sitzung gebrochen. Der Unterschied ist nicht der Code, sondern
|
||||
der Anlass: eine Vermutung vorher gegen einen Befund hinterher.
|
||||
|
||||
Faellt eine dieser Methoden in einer neueren Fassung weg, entfaellt nur die
|
||||
Auskunft bzw. der zweite Anlauf -- die Sitzung laeuft wie ohne sie.
|
||||
|
||||
**Was noVNC an Sicherheitsverfahren spricht** (`core/rfb.js`,
|
||||
`_isSupportedSecurityType`): `1` None, `2` VNC-Passwort, `6` RA2ne (RSA-AES
|
||||
ohne Streckenverschluesselung), `16` Tight, `19` VeNCrypt, `22` xvp, `30` ARD,
|
||||
`113` MS-Logon II. **Nicht** dabei: `5` (RA2 mit Streckenverschluesselung) und
|
||||
alles aus dem RealVNC-eigenen Bereich `7`-`15`. Ein RealVNC Server, der nur
|
||||
`13` und `5` anbietet, kommt mit dieser Bibliothek also nicht zusammen -- er
|
||||
muss `Encryption=AlwaysOff` (dann `6`) oder `Authentication=VncAuth` (dann
|
||||
`2`) angeboten bekommen. TESM misst das und schreibt es auf die Seite, statt
|
||||
den Benutzer vor eine schwarze Flaeche zu setzen.
|
||||
@@ -0,0 +1,62 @@
|
||||
noVNC is Copyright (C) 2022 The noVNC authors
|
||||
(./AUTHORS)
|
||||
|
||||
The noVNC core library files are licensed under the MPL 2.0 (Mozilla
|
||||
Public License 2.0). The noVNC core library is composed of the
|
||||
Javascript code necessary for full noVNC operation. This includes (but
|
||||
is not limited to):
|
||||
|
||||
core/**/*.js
|
||||
app/*.js
|
||||
test/playback.js
|
||||
|
||||
The HTML, CSS, font and images files that included with the noVNC
|
||||
source distibution (or repository) are not considered part of the
|
||||
noVNC core library and are licensed under more permissive licenses.
|
||||
The intent is to allow easy integration of noVNC into existing web
|
||||
sites and web applications.
|
||||
|
||||
The HTML, CSS, font and image files are licensed as follows:
|
||||
|
||||
*.html : 2-Clause BSD license
|
||||
|
||||
app/styles/*.css : 2-Clause BSD license
|
||||
|
||||
app/styles/Orbitron* : SIL Open Font License 1.1
|
||||
(Copyright 2009 Matt McInerney)
|
||||
|
||||
app/images/ : Creative Commons Attribution-ShareAlike
|
||||
http://creativecommons.org/licenses/by-sa/3.0/
|
||||
|
||||
Some portions of noVNC are copyright to their individual authors.
|
||||
Please refer to the individual source files and/or to the noVNC commit
|
||||
history: https://github.com/novnc/noVNC/commits/master
|
||||
|
||||
The are several files and projects that have been incorporated into
|
||||
the noVNC core library. Here is a list of those files and the original
|
||||
licenses (all MPL 2.0 compatible):
|
||||
|
||||
core/base64.js : MPL 2.0
|
||||
|
||||
core/des.js : Various BSD style licenses
|
||||
|
||||
vendor/pako/ : MIT
|
||||
|
||||
Any other files not mentioned above are typically marked with
|
||||
a copyright/license header at the top of the file. The default noVNC
|
||||
license is MPL-2.0.
|
||||
|
||||
The following license texts are included:
|
||||
|
||||
docs/LICENSE.MPL-2.0
|
||||
docs/LICENSE.OFL-1.1
|
||||
docs/LICENSE.BSD-3-Clause (New BSD)
|
||||
docs/LICENSE.BSD-2-Clause (Simplified BSD / FreeBSD)
|
||||
vendor/pako/LICENSE (MIT)
|
||||
|
||||
Or alternatively the license texts may be found here:
|
||||
|
||||
http://www.mozilla.org/MPL/2.0/
|
||||
http://scripts.sil.org/OFL
|
||||
http://en.wikipedia.org/wiki/BSD_licenses
|
||||
https://opensource.org/licenses/MIT
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// From: http://hg.mozilla.org/mozilla-central/raw-file/ec10630b1a54/js/src/devtools/jint/sunspider/string-base64.js
|
||||
|
||||
import * as Log from './util/logging.js';
|
||||
|
||||
export default {
|
||||
/* Convert data (an array of integers) to a Base64 string. */
|
||||
toBase64Table: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split(''),
|
||||
base64Pad: '=',
|
||||
|
||||
encode(data) {
|
||||
"use strict";
|
||||
let result = '';
|
||||
const length = data.length;
|
||||
const lengthpad = (length % 3);
|
||||
// Convert every three bytes to 4 ascii characters.
|
||||
|
||||
for (let i = 0; i < (length - 2); i += 3) {
|
||||
result += this.toBase64Table[data[i] >> 2];
|
||||
result += this.toBase64Table[((data[i] & 0x03) << 4) + (data[i + 1] >> 4)];
|
||||
result += this.toBase64Table[((data[i + 1] & 0x0f) << 2) + (data[i + 2] >> 6)];
|
||||
result += this.toBase64Table[data[i + 2] & 0x3f];
|
||||
}
|
||||
|
||||
// Convert the remaining 1 or 2 bytes, pad out to 4 characters.
|
||||
const j = length - lengthpad;
|
||||
if (lengthpad === 2) {
|
||||
result += this.toBase64Table[data[j] >> 2];
|
||||
result += this.toBase64Table[((data[j] & 0x03) << 4) + (data[j + 1] >> 4)];
|
||||
result += this.toBase64Table[(data[j + 1] & 0x0f) << 2];
|
||||
result += this.toBase64Table[64];
|
||||
} else if (lengthpad === 1) {
|
||||
result += this.toBase64Table[data[j] >> 2];
|
||||
result += this.toBase64Table[(data[j] & 0x03) << 4];
|
||||
result += this.toBase64Table[64];
|
||||
result += this.toBase64Table[64];
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
/* Convert Base64 data to a string */
|
||||
/* eslint-disable comma-spacing */
|
||||
toBinaryTable: [
|
||||
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
|
||||
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
|
||||
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63,
|
||||
52,53,54,55, 56,57,58,59, 60,61,-1,-1, -1, 0,-1,-1,
|
||||
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
|
||||
15,16,17,18, 19,20,21,22, 23,24,25,-1, -1,-1,-1,-1,
|
||||
-1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
|
||||
41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1
|
||||
],
|
||||
/* eslint-enable comma-spacing */
|
||||
|
||||
decode(data, offset = 0) {
|
||||
let dataLength = data.indexOf('=') - offset;
|
||||
if (dataLength < 0) { dataLength = data.length - offset; }
|
||||
|
||||
/* Every four characters is 3 resulting numbers */
|
||||
const resultLength = (dataLength >> 2) * 3 + Math.floor((dataLength % 4) / 1.5);
|
||||
const result = new Array(resultLength);
|
||||
|
||||
// Convert one by one.
|
||||
|
||||
let leftbits = 0; // number of bits decoded, but yet to be appended
|
||||
let leftdata = 0; // bits decoded, but yet to be appended
|
||||
for (let idx = 0, i = offset; i < data.length; i++) {
|
||||
const c = this.toBinaryTable[data.charCodeAt(i) & 0x7f];
|
||||
const padding = (data.charAt(i) === this.base64Pad);
|
||||
// Skip illegal characters and whitespace
|
||||
if (c === -1) {
|
||||
Log.Error("Illegal character code " + data.charCodeAt(i) + " at position " + i);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Collect data into leftdata, update bitcount
|
||||
leftdata = (leftdata << 6) | c;
|
||||
leftbits += 6;
|
||||
|
||||
// If we have 8 or more bits, append 8 bits to the result
|
||||
if (leftbits >= 8) {
|
||||
leftbits -= 8;
|
||||
// Append if not padding.
|
||||
if (!padding) {
|
||||
result[idx++] = (leftdata >> leftbits) & 0xff;
|
||||
}
|
||||
leftdata &= (1 << leftbits) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// If there are any bits left, the base64 string was corrupted
|
||||
if (leftbits) {
|
||||
const err = new Error('Corrupted base64 string');
|
||||
err.name = 'Base64-Error';
|
||||
throw err;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}; /* End of Base64 namespace */
|
||||
+178
@@ -0,0 +1,178 @@
|
||||
export class AESECBCipher {
|
||||
constructor() {
|
||||
this._key = null;
|
||||
}
|
||||
|
||||
get algorithm() {
|
||||
return { name: "AES-ECB" };
|
||||
}
|
||||
|
||||
static async importKey(key, _algorithm, extractable, keyUsages) {
|
||||
const cipher = new AESECBCipher;
|
||||
await cipher._importKey(key, extractable, keyUsages);
|
||||
return cipher;
|
||||
}
|
||||
|
||||
async _importKey(key, extractable, keyUsages) {
|
||||
this._key = await window.crypto.subtle.importKey(
|
||||
"raw", key, {name: "AES-CBC"}, extractable, keyUsages);
|
||||
}
|
||||
|
||||
async encrypt(_algorithm, plaintext) {
|
||||
const x = new Uint8Array(plaintext);
|
||||
if (x.length % 16 !== 0 || this._key === null) {
|
||||
return null;
|
||||
}
|
||||
const n = x.length / 16;
|
||||
for (let i = 0; i < n; i++) {
|
||||
const y = new Uint8Array(await window.crypto.subtle.encrypt({
|
||||
name: "AES-CBC",
|
||||
iv: new Uint8Array(16),
|
||||
}, this._key, x.slice(i * 16, i * 16 + 16))).slice(0, 16);
|
||||
x.set(y, i * 16);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
export class AESEAXCipher {
|
||||
constructor() {
|
||||
this._rawKey = null;
|
||||
this._ctrKey = null;
|
||||
this._cbcKey = null;
|
||||
this._zeroBlock = new Uint8Array(16);
|
||||
this._prefixBlock0 = this._zeroBlock;
|
||||
this._prefixBlock1 = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);
|
||||
this._prefixBlock2 = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2]);
|
||||
}
|
||||
|
||||
get algorithm() {
|
||||
return { name: "AES-EAX" };
|
||||
}
|
||||
|
||||
async _encryptBlock(block) {
|
||||
const encrypted = await window.crypto.subtle.encrypt({
|
||||
name: "AES-CBC",
|
||||
iv: this._zeroBlock,
|
||||
}, this._cbcKey, block);
|
||||
return new Uint8Array(encrypted).slice(0, 16);
|
||||
}
|
||||
|
||||
async _initCMAC() {
|
||||
const k1 = await this._encryptBlock(this._zeroBlock);
|
||||
const k2 = new Uint8Array(16);
|
||||
const v = k1[0] >>> 6;
|
||||
for (let i = 0; i < 15; i++) {
|
||||
k2[i] = (k1[i + 1] >> 6) | (k1[i] << 2);
|
||||
k1[i] = (k1[i + 1] >> 7) | (k1[i] << 1);
|
||||
}
|
||||
const lut = [0x0, 0x87, 0x0e, 0x89];
|
||||
k2[14] ^= v >>> 1;
|
||||
k2[15] = (k1[15] << 2) ^ lut[v];
|
||||
k1[15] = (k1[15] << 1) ^ lut[v >> 1];
|
||||
this._k1 = k1;
|
||||
this._k2 = k2;
|
||||
}
|
||||
|
||||
async _encryptCTR(data, counter) {
|
||||
const encrypted = await window.crypto.subtle.encrypt({
|
||||
name: "AES-CTR",
|
||||
counter: counter,
|
||||
length: 128
|
||||
}, this._ctrKey, data);
|
||||
return new Uint8Array(encrypted);
|
||||
}
|
||||
|
||||
async _decryptCTR(data, counter) {
|
||||
const decrypted = await window.crypto.subtle.decrypt({
|
||||
name: "AES-CTR",
|
||||
counter: counter,
|
||||
length: 128
|
||||
}, this._ctrKey, data);
|
||||
return new Uint8Array(decrypted);
|
||||
}
|
||||
|
||||
async _computeCMAC(data, prefixBlock) {
|
||||
if (prefixBlock.length !== 16) {
|
||||
return null;
|
||||
}
|
||||
const n = Math.floor(data.length / 16);
|
||||
const m = Math.ceil(data.length / 16);
|
||||
const r = data.length - n * 16;
|
||||
const cbcData = new Uint8Array((m + 1) * 16);
|
||||
cbcData.set(prefixBlock);
|
||||
cbcData.set(data, 16);
|
||||
if (r === 0) {
|
||||
for (let i = 0; i < 16; i++) {
|
||||
cbcData[n * 16 + i] ^= this._k1[i];
|
||||
}
|
||||
} else {
|
||||
cbcData[(n + 1) * 16 + r] = 0x80;
|
||||
for (let i = 0; i < 16; i++) {
|
||||
cbcData[(n + 1) * 16 + i] ^= this._k2[i];
|
||||
}
|
||||
}
|
||||
let cbcEncrypted = await window.crypto.subtle.encrypt({
|
||||
name: "AES-CBC",
|
||||
iv: this._zeroBlock,
|
||||
}, this._cbcKey, cbcData);
|
||||
|
||||
cbcEncrypted = new Uint8Array(cbcEncrypted);
|
||||
const mac = cbcEncrypted.slice(cbcEncrypted.length - 32, cbcEncrypted.length - 16);
|
||||
return mac;
|
||||
}
|
||||
|
||||
static async importKey(key, _algorithm, _extractable, _keyUsages) {
|
||||
const cipher = new AESEAXCipher;
|
||||
await cipher._importKey(key);
|
||||
return cipher;
|
||||
}
|
||||
|
||||
async _importKey(key) {
|
||||
this._rawKey = key;
|
||||
this._ctrKey = await window.crypto.subtle.importKey(
|
||||
"raw", key, {name: "AES-CTR"}, false, ["encrypt", "decrypt"]);
|
||||
this._cbcKey = await window.crypto.subtle.importKey(
|
||||
"raw", key, {name: "AES-CBC"}, false, ["encrypt"]);
|
||||
await this._initCMAC();
|
||||
}
|
||||
|
||||
async encrypt(algorithm, message) {
|
||||
const ad = algorithm.additionalData;
|
||||
const nonce = algorithm.iv;
|
||||
const nCMAC = await this._computeCMAC(nonce, this._prefixBlock0);
|
||||
const encrypted = await this._encryptCTR(message, nCMAC);
|
||||
const adCMAC = await this._computeCMAC(ad, this._prefixBlock1);
|
||||
const mac = await this._computeCMAC(encrypted, this._prefixBlock2);
|
||||
for (let i = 0; i < 16; i++) {
|
||||
mac[i] ^= nCMAC[i] ^ adCMAC[i];
|
||||
}
|
||||
const res = new Uint8Array(16 + encrypted.length);
|
||||
res.set(encrypted);
|
||||
res.set(mac, encrypted.length);
|
||||
return res;
|
||||
}
|
||||
|
||||
async decrypt(algorithm, data) {
|
||||
const encrypted = data.slice(0, data.length - 16);
|
||||
const ad = algorithm.additionalData;
|
||||
const nonce = algorithm.iv;
|
||||
const mac = data.slice(data.length - 16);
|
||||
const nCMAC = await this._computeCMAC(nonce, this._prefixBlock0);
|
||||
const adCMAC = await this._computeCMAC(ad, this._prefixBlock1);
|
||||
const computedMac = await this._computeCMAC(encrypted, this._prefixBlock2);
|
||||
for (let i = 0; i < 16; i++) {
|
||||
computedMac[i] ^= nCMAC[i] ^ adCMAC[i];
|
||||
}
|
||||
if (computedMac.length !== mac.length) {
|
||||
return null;
|
||||
}
|
||||
for (let i = 0; i < mac.length; i++) {
|
||||
if (computedMac[i] !== mac[i]) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
const res = await this._decryptCTR(encrypted, nCMAC);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
export function modPow(b, e, m) {
|
||||
let r = 1n;
|
||||
b = b % m;
|
||||
while (e > 0n) {
|
||||
if ((e & 1n) === 1n) {
|
||||
r = (r * b) % m;
|
||||
}
|
||||
e = e >> 1n;
|
||||
b = (b * b) % m;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
export function bigIntToU8Array(bigint, padLength=0) {
|
||||
let hex = bigint.toString(16);
|
||||
if (padLength === 0) {
|
||||
padLength = Math.ceil(hex.length / 2);
|
||||
}
|
||||
hex = hex.padStart(padLength * 2, '0');
|
||||
const length = hex.length / 2;
|
||||
const arr = new Uint8Array(length);
|
||||
for (let i = 0; i < length; i++) {
|
||||
arr[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
export function u8ArrayToBigInt(arr) {
|
||||
let hex = '0x';
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
hex += arr[i].toString(16).padStart(2, '0');
|
||||
}
|
||||
return BigInt(hex);
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
import { AESECBCipher, AESEAXCipher } from "./aes.js";
|
||||
import { DESCBCCipher, DESECBCipher } from "./des.js";
|
||||
import { RSACipher } from "./rsa.js";
|
||||
import { DHCipher } from "./dh.js";
|
||||
import { MD5 } from "./md5.js";
|
||||
|
||||
// A single interface for the cryptographic algorithms not supported by SubtleCrypto.
|
||||
// Both synchronous and asynchronous implmentations are allowed.
|
||||
class LegacyCrypto {
|
||||
constructor() {
|
||||
this._algorithms = {
|
||||
"AES-ECB": AESECBCipher,
|
||||
"AES-EAX": AESEAXCipher,
|
||||
"DES-ECB": DESECBCipher,
|
||||
"DES-CBC": DESCBCCipher,
|
||||
"RSA-PKCS1-v1_5": RSACipher,
|
||||
"DH": DHCipher,
|
||||
"MD5": MD5,
|
||||
};
|
||||
}
|
||||
|
||||
encrypt(algorithm, key, data) {
|
||||
if (key.algorithm.name !== algorithm.name) {
|
||||
throw new Error("algorithm does not match");
|
||||
}
|
||||
if (typeof key.encrypt !== "function") {
|
||||
throw new Error("key does not support encryption");
|
||||
}
|
||||
return key.encrypt(algorithm, data);
|
||||
}
|
||||
|
||||
decrypt(algorithm, key, data) {
|
||||
if (key.algorithm.name !== algorithm.name) {
|
||||
throw new Error("algorithm does not match");
|
||||
}
|
||||
if (typeof key.decrypt !== "function") {
|
||||
throw new Error("key does not support encryption");
|
||||
}
|
||||
return key.decrypt(algorithm, data);
|
||||
}
|
||||
|
||||
importKey(format, keyData, algorithm, extractable, keyUsages) {
|
||||
if (format !== "raw") {
|
||||
throw new Error("key format is not supported");
|
||||
}
|
||||
const alg = this._algorithms[algorithm.name];
|
||||
if (typeof alg === "undefined" || typeof alg.importKey !== "function") {
|
||||
throw new Error("algorithm is not supported");
|
||||
}
|
||||
return alg.importKey(keyData, algorithm, extractable, keyUsages);
|
||||
}
|
||||
|
||||
generateKey(algorithm, extractable, keyUsages) {
|
||||
const alg = this._algorithms[algorithm.name];
|
||||
if (typeof alg === "undefined" || typeof alg.generateKey !== "function") {
|
||||
throw new Error("algorithm is not supported");
|
||||
}
|
||||
return alg.generateKey(algorithm, extractable, keyUsages);
|
||||
}
|
||||
|
||||
exportKey(format, key) {
|
||||
if (format !== "raw") {
|
||||
throw new Error("key format is not supported");
|
||||
}
|
||||
if (typeof key.exportKey !== "function") {
|
||||
throw new Error("key does not support exportKey");
|
||||
}
|
||||
return key.exportKey();
|
||||
}
|
||||
|
||||
digest(algorithm, data) {
|
||||
const alg = this._algorithms[algorithm];
|
||||
if (typeof alg !== "function") {
|
||||
throw new Error("algorithm is not supported");
|
||||
}
|
||||
return alg(data);
|
||||
}
|
||||
|
||||
deriveBits(algorithm, key, length) {
|
||||
if (key.algorithm.name !== algorithm.name) {
|
||||
throw new Error("algorithm does not match");
|
||||
}
|
||||
if (typeof key.deriveBits !== "function") {
|
||||
throw new Error("key does not support deriveBits");
|
||||
}
|
||||
return key.deriveBits(algorithm, length);
|
||||
}
|
||||
}
|
||||
|
||||
export default new LegacyCrypto;
|
||||
+330
@@ -0,0 +1,330 @@
|
||||
/*
|
||||
* Ported from Flashlight VNC ActionScript implementation:
|
||||
* http://www.wizhelp.com/flashlight-vnc/
|
||||
*
|
||||
* Full attribution follows:
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* This DES class has been extracted from package Acme.Crypto for use in VNC.
|
||||
* The unnecessary odd parity code has been removed.
|
||||
*
|
||||
* These changes are:
|
||||
* Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
|
||||
* DesCipher - the DES encryption method
|
||||
*
|
||||
* The meat of this code is by Dave Zimmerman <dzimm@widget.com>, and is:
|
||||
*
|
||||
* Copyright (c) 1996 Widget Workshop, Inc. All Rights Reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software
|
||||
* and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
|
||||
* without fee is hereby granted, provided that this copyright notice is kept
|
||||
* intact.
|
||||
*
|
||||
* WIDGET WORKSHOP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
|
||||
* OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WIDGET WORKSHOP SHALL NOT BE LIABLE
|
||||
* FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
|
||||
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
* THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
|
||||
* CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
|
||||
* PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
|
||||
* NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
|
||||
* SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
|
||||
* SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
|
||||
* PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES"). WIDGET WORKSHOP
|
||||
* SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
|
||||
* HIGH RISK ACTIVITIES.
|
||||
*
|
||||
*
|
||||
* The rest is:
|
||||
*
|
||||
* Copyright (C) 1996 by Jef Poskanzer <jef@acme.com>. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* Visit the ACME Labs Java page for up-to-date versions of this and other
|
||||
* fine Java utilities: http://www.acme.com/java/
|
||||
*/
|
||||
|
||||
/* eslint-disable comma-spacing */
|
||||
|
||||
// Tables, permutations, S-boxes, etc.
|
||||
const PC2 = [13,16,10,23, 0, 4, 2,27,14, 5,20, 9,22,18,11, 3,
|
||||
25, 7,15, 6,26,19,12, 1,40,51,30,36,46,54,29,39,
|
||||
50,44,32,47,43,48,38,55,33,52,45,41,49,35,28,31 ],
|
||||
totrot = [ 1, 2, 4, 6, 8,10,12,14,15,17,19,21,23,25,27,28];
|
||||
|
||||
const z = 0x0;
|
||||
let a,b,c,d,e,f;
|
||||
a=1<<16; b=1<<24; c=a|b; d=1<<2; e=1<<10; f=d|e;
|
||||
const SP1 = [c|e,z|z,a|z,c|f,c|d,a|f,z|d,a|z,z|e,c|e,c|f,z|e,b|f,c|d,b|z,z|d,
|
||||
z|f,b|e,b|e,a|e,a|e,c|z,c|z,b|f,a|d,b|d,b|d,a|d,z|z,z|f,a|f,b|z,
|
||||
a|z,c|f,z|d,c|z,c|e,b|z,b|z,z|e,c|d,a|z,a|e,b|d,z|e,z|d,b|f,a|f,
|
||||
c|f,a|d,c|z,b|f,b|d,z|f,a|f,c|e,z|f,b|e,b|e,z|z,a|d,a|e,z|z,c|d];
|
||||
a=1<<20; b=1<<31; c=a|b; d=1<<5; e=1<<15; f=d|e;
|
||||
const SP2 = [c|f,b|e,z|e,a|f,a|z,z|d,c|d,b|f,b|d,c|f,c|e,b|z,b|e,a|z,z|d,c|d,
|
||||
a|e,a|d,b|f,z|z,b|z,z|e,a|f,c|z,a|d,b|d,z|z,a|e,z|f,c|e,c|z,z|f,
|
||||
z|z,a|f,c|d,a|z,b|f,c|z,c|e,z|e,c|z,b|e,z|d,c|f,a|f,z|d,z|e,b|z,
|
||||
z|f,c|e,a|z,b|d,a|d,b|f,b|d,a|d,a|e,z|z,b|e,z|f,b|z,c|d,c|f,a|e];
|
||||
a=1<<17; b=1<<27; c=a|b; d=1<<3; e=1<<9; f=d|e;
|
||||
const SP3 = [z|f,c|e,z|z,c|d,b|e,z|z,a|f,b|e,a|d,b|d,b|d,a|z,c|f,a|d,c|z,z|f,
|
||||
b|z,z|d,c|e,z|e,a|e,c|z,c|d,a|f,b|f,a|e,a|z,b|f,z|d,c|f,z|e,b|z,
|
||||
c|e,b|z,a|d,z|f,a|z,c|e,b|e,z|z,z|e,a|d,c|f,b|e,b|d,z|e,z|z,c|d,
|
||||
b|f,a|z,b|z,c|f,z|d,a|f,a|e,b|d,c|z,b|f,z|f,c|z,a|f,z|d,c|d,a|e];
|
||||
a=1<<13; b=1<<23; c=a|b; d=1<<0; e=1<<7; f=d|e;
|
||||
const SP4 = [c|d,a|f,a|f,z|e,c|e,b|f,b|d,a|d,z|z,c|z,c|z,c|f,z|f,z|z,b|e,b|d,
|
||||
z|d,a|z,b|z,c|d,z|e,b|z,a|d,a|e,b|f,z|d,a|e,b|e,a|z,c|e,c|f,z|f,
|
||||
b|e,b|d,c|z,c|f,z|f,z|z,z|z,c|z,a|e,b|e,b|f,z|d,c|d,a|f,a|f,z|e,
|
||||
c|f,z|f,z|d,a|z,b|d,a|d,c|e,b|f,a|d,a|e,b|z,c|d,z|e,b|z,a|z,c|e];
|
||||
a=1<<25; b=1<<30; c=a|b; d=1<<8; e=1<<19; f=d|e;
|
||||
const SP5 = [z|d,a|f,a|e,c|d,z|e,z|d,b|z,a|e,b|f,z|e,a|d,b|f,c|d,c|e,z|f,b|z,
|
||||
a|z,b|e,b|e,z|z,b|d,c|f,c|f,a|d,c|e,b|d,z|z,c|z,a|f,a|z,c|z,z|f,
|
||||
z|e,c|d,z|d,a|z,b|z,a|e,c|d,b|f,a|d,b|z,c|e,a|f,b|f,z|d,a|z,c|e,
|
||||
c|f,z|f,c|z,c|f,a|e,z|z,b|e,c|z,z|f,a|d,b|d,z|e,z|z,b|e,a|f,b|d];
|
||||
a=1<<22; b=1<<29; c=a|b; d=1<<4; e=1<<14; f=d|e;
|
||||
const SP6 = [b|d,c|z,z|e,c|f,c|z,z|d,c|f,a|z,b|e,a|f,a|z,b|d,a|d,b|e,b|z,z|f,
|
||||
z|z,a|d,b|f,z|e,a|e,b|f,z|d,c|d,c|d,z|z,a|f,c|e,z|f,a|e,c|e,b|z,
|
||||
b|e,z|d,c|d,a|e,c|f,a|z,z|f,b|d,a|z,b|e,b|z,z|f,b|d,c|f,a|e,c|z,
|
||||
a|f,c|e,z|z,c|d,z|d,z|e,c|z,a|f,z|e,a|d,b|f,z|z,c|e,b|z,a|d,b|f];
|
||||
a=1<<21; b=1<<26; c=a|b; d=1<<1; e=1<<11; f=d|e;
|
||||
const SP7 = [a|z,c|d,b|f,z|z,z|e,b|f,a|f,c|e,c|f,a|z,z|z,b|d,z|d,b|z,c|d,z|f,
|
||||
b|e,a|f,a|d,b|e,b|d,c|z,c|e,a|d,c|z,z|e,z|f,c|f,a|e,z|d,b|z,a|e,
|
||||
b|z,a|e,a|z,b|f,b|f,c|d,c|d,z|d,a|d,b|z,b|e,a|z,c|e,z|f,a|f,c|e,
|
||||
z|f,b|d,c|f,c|z,a|e,z|z,z|d,c|f,z|z,a|f,c|z,z|e,b|d,b|e,z|e,a|d];
|
||||
a=1<<18; b=1<<28; c=a|b; d=1<<6; e=1<<12; f=d|e;
|
||||
const SP8 = [b|f,z|e,a|z,c|f,b|z,b|f,z|d,b|z,a|d,c|z,c|f,a|e,c|e,a|f,z|e,z|d,
|
||||
c|z,b|d,b|e,z|f,a|e,a|d,c|d,c|e,z|f,z|z,z|z,c|d,b|d,b|e,a|f,a|z,
|
||||
a|f,a|z,c|e,z|e,z|d,c|d,z|e,a|f,b|e,z|d,b|d,c|z,c|d,b|z,a|z,b|f,
|
||||
z|z,c|f,a|d,b|d,c|z,b|e,b|f,z|z,c|f,a|e,a|e,z|f,z|f,a|d,b|z,c|e];
|
||||
|
||||
/* eslint-enable comma-spacing */
|
||||
|
||||
class DES {
|
||||
constructor(password) {
|
||||
this.keys = [];
|
||||
|
||||
// Set the key.
|
||||
const pc1m = [], pcr = [], kn = [];
|
||||
|
||||
for (let j = 0, l = 56; j < 56; ++j, l -= 8) {
|
||||
l += l < -5 ? 65 : l < -3 ? 31 : l < -1 ? 63 : l === 27 ? 35 : 0; // PC1
|
||||
const m = l & 0x7;
|
||||
pc1m[j] = ((password[l >>> 3] & (1<<m)) !== 0) ? 1: 0;
|
||||
}
|
||||
|
||||
for (let i = 0; i < 16; ++i) {
|
||||
const m = i << 1;
|
||||
const n = m + 1;
|
||||
kn[m] = kn[n] = 0;
|
||||
for (let o = 28; o < 59; o += 28) {
|
||||
for (let j = o - 28; j < o; ++j) {
|
||||
const l = j + totrot[i];
|
||||
pcr[j] = l < o ? pc1m[l] : pc1m[l - 28];
|
||||
}
|
||||
}
|
||||
for (let j = 0; j < 24; ++j) {
|
||||
if (pcr[PC2[j]] !== 0) {
|
||||
kn[m] |= 1 << (23 - j);
|
||||
}
|
||||
if (pcr[PC2[j + 24]] !== 0) {
|
||||
kn[n] |= 1 << (23 - j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// cookey
|
||||
for (let i = 0, rawi = 0, KnLi = 0; i < 16; ++i) {
|
||||
const raw0 = kn[rawi++];
|
||||
const raw1 = kn[rawi++];
|
||||
this.keys[KnLi] = (raw0 & 0x00fc0000) << 6;
|
||||
this.keys[KnLi] |= (raw0 & 0x00000fc0) << 10;
|
||||
this.keys[KnLi] |= (raw1 & 0x00fc0000) >>> 10;
|
||||
this.keys[KnLi] |= (raw1 & 0x00000fc0) >>> 6;
|
||||
++KnLi;
|
||||
this.keys[KnLi] = (raw0 & 0x0003f000) << 12;
|
||||
this.keys[KnLi] |= (raw0 & 0x0000003f) << 16;
|
||||
this.keys[KnLi] |= (raw1 & 0x0003f000) >>> 4;
|
||||
this.keys[KnLi] |= (raw1 & 0x0000003f);
|
||||
++KnLi;
|
||||
}
|
||||
}
|
||||
|
||||
// Encrypt 8 bytes of text
|
||||
enc8(text) {
|
||||
const b = text.slice();
|
||||
let i = 0, l, r, x; // left, right, accumulator
|
||||
|
||||
// Squash 8 bytes to 2 ints
|
||||
l = b[i++]<<24 | b[i++]<<16 | b[i++]<<8 | b[i++];
|
||||
r = b[i++]<<24 | b[i++]<<16 | b[i++]<<8 | b[i++];
|
||||
|
||||
x = ((l >>> 4) ^ r) & 0x0f0f0f0f;
|
||||
r ^= x;
|
||||
l ^= (x << 4);
|
||||
x = ((l >>> 16) ^ r) & 0x0000ffff;
|
||||
r ^= x;
|
||||
l ^= (x << 16);
|
||||
x = ((r >>> 2) ^ l) & 0x33333333;
|
||||
l ^= x;
|
||||
r ^= (x << 2);
|
||||
x = ((r >>> 8) ^ l) & 0x00ff00ff;
|
||||
l ^= x;
|
||||
r ^= (x << 8);
|
||||
r = (r << 1) | ((r >>> 31) & 1);
|
||||
x = (l ^ r) & 0xaaaaaaaa;
|
||||
l ^= x;
|
||||
r ^= x;
|
||||
l = (l << 1) | ((l >>> 31) & 1);
|
||||
|
||||
for (let i = 0, keysi = 0; i < 8; ++i) {
|
||||
x = (r << 28) | (r >>> 4);
|
||||
x ^= this.keys[keysi++];
|
||||
let fval = SP7[x & 0x3f];
|
||||
fval |= SP5[(x >>> 8) & 0x3f];
|
||||
fval |= SP3[(x >>> 16) & 0x3f];
|
||||
fval |= SP1[(x >>> 24) & 0x3f];
|
||||
x = r ^ this.keys[keysi++];
|
||||
fval |= SP8[x & 0x3f];
|
||||
fval |= SP6[(x >>> 8) & 0x3f];
|
||||
fval |= SP4[(x >>> 16) & 0x3f];
|
||||
fval |= SP2[(x >>> 24) & 0x3f];
|
||||
l ^= fval;
|
||||
x = (l << 28) | (l >>> 4);
|
||||
x ^= this.keys[keysi++];
|
||||
fval = SP7[x & 0x3f];
|
||||
fval |= SP5[(x >>> 8) & 0x3f];
|
||||
fval |= SP3[(x >>> 16) & 0x3f];
|
||||
fval |= SP1[(x >>> 24) & 0x3f];
|
||||
x = l ^ this.keys[keysi++];
|
||||
fval |= SP8[x & 0x0000003f];
|
||||
fval |= SP6[(x >>> 8) & 0x3f];
|
||||
fval |= SP4[(x >>> 16) & 0x3f];
|
||||
fval |= SP2[(x >>> 24) & 0x3f];
|
||||
r ^= fval;
|
||||
}
|
||||
|
||||
r = (r << 31) | (r >>> 1);
|
||||
x = (l ^ r) & 0xaaaaaaaa;
|
||||
l ^= x;
|
||||
r ^= x;
|
||||
l = (l << 31) | (l >>> 1);
|
||||
x = ((l >>> 8) ^ r) & 0x00ff00ff;
|
||||
r ^= x;
|
||||
l ^= (x << 8);
|
||||
x = ((l >>> 2) ^ r) & 0x33333333;
|
||||
r ^= x;
|
||||
l ^= (x << 2);
|
||||
x = ((r >>> 16) ^ l) & 0x0000ffff;
|
||||
l ^= x;
|
||||
r ^= (x << 16);
|
||||
x = ((r >>> 4) ^ l) & 0x0f0f0f0f;
|
||||
l ^= x;
|
||||
r ^= (x << 4);
|
||||
|
||||
// Spread ints to bytes
|
||||
x = [r, l];
|
||||
for (i = 0; i < 8; i++) {
|
||||
b[i] = (x[i>>>2] >>> (8 * (3 - (i % 4)))) % 256;
|
||||
if (b[i] < 0) { b[i] += 256; } // unsigned
|
||||
}
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
export class DESECBCipher {
|
||||
constructor() {
|
||||
this._cipher = null;
|
||||
}
|
||||
|
||||
get algorithm() {
|
||||
return { name: "DES-ECB" };
|
||||
}
|
||||
|
||||
static importKey(key, _algorithm, _extractable, _keyUsages) {
|
||||
const cipher = new DESECBCipher;
|
||||
cipher._importKey(key);
|
||||
return cipher;
|
||||
}
|
||||
|
||||
_importKey(key, _extractable, _keyUsages) {
|
||||
this._cipher = new DES(key);
|
||||
}
|
||||
|
||||
encrypt(_algorithm, plaintext) {
|
||||
const x = new Uint8Array(plaintext);
|
||||
if (x.length % 8 !== 0 || this._cipher === null) {
|
||||
return null;
|
||||
}
|
||||
const n = x.length / 8;
|
||||
for (let i = 0; i < n; i++) {
|
||||
x.set(this._cipher.enc8(x.slice(i * 8, i * 8 + 8)), i * 8);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
export class DESCBCCipher {
|
||||
constructor() {
|
||||
this._cipher = null;
|
||||
}
|
||||
|
||||
get algorithm() {
|
||||
return { name: "DES-CBC" };
|
||||
}
|
||||
|
||||
static importKey(key, _algorithm, _extractable, _keyUsages) {
|
||||
const cipher = new DESCBCCipher;
|
||||
cipher._importKey(key);
|
||||
return cipher;
|
||||
}
|
||||
|
||||
_importKey(key) {
|
||||
this._cipher = new DES(key);
|
||||
}
|
||||
|
||||
encrypt(algorithm, plaintext) {
|
||||
const x = new Uint8Array(plaintext);
|
||||
let y = new Uint8Array(algorithm.iv);
|
||||
if (x.length % 8 !== 0 || this._cipher === null) {
|
||||
return null;
|
||||
}
|
||||
const n = x.length / 8;
|
||||
for (let i = 0; i < n; i++) {
|
||||
for (let j = 0; j < 8; j++) {
|
||||
y[j] ^= plaintext[i * 8 + j];
|
||||
}
|
||||
y = this._cipher.enc8(y);
|
||||
x.set(y, i * 8);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
import { modPow, bigIntToU8Array, u8ArrayToBigInt } from "./bigint.js";
|
||||
|
||||
class DHPublicKey {
|
||||
constructor(key) {
|
||||
this._key = key;
|
||||
}
|
||||
|
||||
get algorithm() {
|
||||
return { name: "DH" };
|
||||
}
|
||||
|
||||
exportKey() {
|
||||
return this._key;
|
||||
}
|
||||
}
|
||||
|
||||
export class DHCipher {
|
||||
constructor() {
|
||||
this._g = null;
|
||||
this._p = null;
|
||||
this._gBigInt = null;
|
||||
this._pBigInt = null;
|
||||
this._privateKey = null;
|
||||
}
|
||||
|
||||
get algorithm() {
|
||||
return { name: "DH" };
|
||||
}
|
||||
|
||||
static generateKey(algorithm, _extractable) {
|
||||
const cipher = new DHCipher;
|
||||
cipher._generateKey(algorithm);
|
||||
return { privateKey: cipher, publicKey: new DHPublicKey(cipher._publicKey) };
|
||||
}
|
||||
|
||||
_generateKey(algorithm) {
|
||||
const g = algorithm.g;
|
||||
const p = algorithm.p;
|
||||
this._keyBytes = p.length;
|
||||
this._gBigInt = u8ArrayToBigInt(g);
|
||||
this._pBigInt = u8ArrayToBigInt(p);
|
||||
this._privateKey = window.crypto.getRandomValues(new Uint8Array(this._keyBytes));
|
||||
this._privateKeyBigInt = u8ArrayToBigInt(this._privateKey);
|
||||
this._publicKey = bigIntToU8Array(modPow(
|
||||
this._gBigInt, this._privateKeyBigInt, this._pBigInt), this._keyBytes);
|
||||
}
|
||||
|
||||
deriveBits(algorithm, length) {
|
||||
const bytes = Math.ceil(length / 8);
|
||||
const pkey = new Uint8Array(algorithm.public);
|
||||
const len = bytes > this._keyBytes ? bytes : this._keyBytes;
|
||||
const secret = modPow(u8ArrayToBigInt(pkey), this._privateKeyBigInt, this._pBigInt);
|
||||
return bigIntToU8Array(secret, len).slice(0, len);
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2021 The noVNC authors
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Performs MD5 hashing on an array of bytes, returns an array of bytes
|
||||
*/
|
||||
|
||||
export async function MD5(d) {
|
||||
let s = "";
|
||||
for (let i = 0; i < d.length; i++) {
|
||||
s += String.fromCharCode(d[i]);
|
||||
}
|
||||
return M(V(Y(X(s), 8 * s.length)));
|
||||
}
|
||||
|
||||
function M(d) {
|
||||
let f = new Uint8Array(d.length);
|
||||
for (let i=0;i<d.length;i++) {
|
||||
f[i] = d.charCodeAt(i);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
function X(d) {
|
||||
let r = Array(d.length >> 2);
|
||||
for (let m = 0; m < r.length; m++) r[m] = 0;
|
||||
for (let m = 0; m < 8 * d.length; m += 8) r[m >> 5] |= (255 & d.charCodeAt(m / 8)) << m % 32;
|
||||
return r;
|
||||
}
|
||||
|
||||
function V(d) {
|
||||
let r = "";
|
||||
for (let m = 0; m < 32 * d.length; m += 8) r += String.fromCharCode(d[m >> 5] >>> m % 32 & 255);
|
||||
return r;
|
||||
}
|
||||
|
||||
function Y(d, g) {
|
||||
d[g >> 5] |= 128 << g % 32, d[14 + (g + 64 >>> 9 << 4)] = g;
|
||||
let m = 1732584193, f = -271733879, r = -1732584194, i = 271733878;
|
||||
for (let n = 0; n < d.length; n += 16) {
|
||||
let h = m,
|
||||
t = f,
|
||||
g = r,
|
||||
e = i;
|
||||
f = ii(f = ii(f = ii(f = ii(f = hh(f = hh(f = hh(f = hh(f = gg(f = gg(f = gg(f = gg(f = ff(f = ff(f = ff(f = ff(f, r = ff(r, i = ff(i, m = ff(m, f, r, i, d[n + 0], 7, -680876936), f, r, d[n + 1], 12, -389564586), m, f, d[n + 2], 17, 606105819), i, m, d[n + 3], 22, -1044525330), r = ff(r, i = ff(i, m = ff(m, f, r, i, d[n + 4], 7, -176418897), f, r, d[n + 5], 12, 1200080426), m, f, d[n + 6], 17, -1473231341), i, m, d[n + 7], 22, -45705983), r = ff(r, i = ff(i, m = ff(m, f, r, i, d[n + 8], 7, 1770035416), f, r, d[n + 9], 12, -1958414417), m, f, d[n + 10], 17, -42063), i, m, d[n + 11], 22, -1990404162), r = ff(r, i = ff(i, m = ff(m, f, r, i, d[n + 12], 7, 1804603682), f, r, d[n + 13], 12, -40341101), m, f, d[n + 14], 17, -1502002290), i, m, d[n + 15], 22, 1236535329), r = gg(r, i = gg(i, m = gg(m, f, r, i, d[n + 1], 5, -165796510), f, r, d[n + 6], 9, -1069501632), m, f, d[n + 11], 14, 643717713), i, m, d[n + 0], 20, -373897302), r = gg(r, i = gg(i, m = gg(m, f, r, i, d[n + 5], 5, -701558691), f, r, d[n + 10], 9, 38016083), m, f, d[n + 15], 14, -660478335), i, m, d[n + 4], 20, -405537848), r = gg(r, i = gg(i, m = gg(m, f, r, i, d[n + 9], 5, 568446438), f, r, d[n + 14], 9, -1019803690), m, f, d[n + 3], 14, -187363961), i, m, d[n + 8], 20, 1163531501), r = gg(r, i = gg(i, m = gg(m, f, r, i, d[n + 13], 5, -1444681467), f, r, d[n + 2], 9, -51403784), m, f, d[n + 7], 14, 1735328473), i, m, d[n + 12], 20, -1926607734), r = hh(r, i = hh(i, m = hh(m, f, r, i, d[n + 5], 4, -378558), f, r, d[n + 8], 11, -2022574463), m, f, d[n + 11], 16, 1839030562), i, m, d[n + 14], 23, -35309556), r = hh(r, i = hh(i, m = hh(m, f, r, i, d[n + 1], 4, -1530992060), f, r, d[n + 4], 11, 1272893353), m, f, d[n + 7], 16, -155497632), i, m, d[n + 10], 23, -1094730640), r = hh(r, i = hh(i, m = hh(m, f, r, i, d[n + 13], 4, 681279174), f, r, d[n + 0], 11, -358537222), m, f, d[n + 3], 16, -722521979), i, m, d[n + 6], 23, 76029189), r = hh(r, i = hh(i, m = hh(m, f, r, i, d[n + 9], 4, -640364487), f, r, d[n + 12], 11, -421815835), m, f, d[n + 15], 16, 530742520), i, m, d[n + 2], 23, -995338651), r = ii(r, i = ii(i, m = ii(m, f, r, i, d[n + 0], 6, -198630844), f, r, d[n + 7], 10, 1126891415), m, f, d[n + 14], 15, -1416354905), i, m, d[n + 5], 21, -57434055), r = ii(r, i = ii(i, m = ii(m, f, r, i, d[n + 12], 6, 1700485571), f, r, d[n + 3], 10, -1894986606), m, f, d[n + 10], 15, -1051523), i, m, d[n + 1], 21, -2054922799), r = ii(r, i = ii(i, m = ii(m, f, r, i, d[n + 8], 6, 1873313359), f, r, d[n + 15], 10, -30611744), m, f, d[n + 6], 15, -1560198380), i, m, d[n + 13], 21, 1309151649), r = ii(r, i = ii(i, m = ii(m, f, r, i, d[n + 4], 6, -145523070), f, r, d[n + 11], 10, -1120210379), m, f, d[n + 2], 15, 718787259), i, m, d[n + 9], 21, -343485551), m = add(m, h), f = add(f, t), r = add(r, g), i = add(i, e);
|
||||
}
|
||||
return Array(m, f, r, i);
|
||||
}
|
||||
|
||||
function cmn(d, g, m, f, r, i) {
|
||||
return add(rol(add(add(g, d), add(f, i)), r), m);
|
||||
}
|
||||
|
||||
function ff(d, g, m, f, r, i, n) {
|
||||
return cmn(g & m | ~g & f, d, g, r, i, n);
|
||||
}
|
||||
|
||||
function gg(d, g, m, f, r, i, n) {
|
||||
return cmn(g & f | m & ~f, d, g, r, i, n);
|
||||
}
|
||||
|
||||
function hh(d, g, m, f, r, i, n) {
|
||||
return cmn(g ^ m ^ f, d, g, r, i, n);
|
||||
}
|
||||
|
||||
function ii(d, g, m, f, r, i, n) {
|
||||
return cmn(m ^ (g | ~f), d, g, r, i, n);
|
||||
}
|
||||
|
||||
function add(d, g) {
|
||||
let m = (65535 & d) + (65535 & g);
|
||||
return (d >> 16) + (g >> 16) + (m >> 16) << 16 | 65535 & m;
|
||||
}
|
||||
|
||||
function rol(d, g) {
|
||||
return d << g | d >>> 32 - g;
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
import Base64 from "../base64.js";
|
||||
import { modPow, bigIntToU8Array, u8ArrayToBigInt } from "./bigint.js";
|
||||
|
||||
export class RSACipher {
|
||||
constructor() {
|
||||
this._keyLength = 0;
|
||||
this._keyBytes = 0;
|
||||
this._n = null;
|
||||
this._e = null;
|
||||
this._d = null;
|
||||
this._nBigInt = null;
|
||||
this._eBigInt = null;
|
||||
this._dBigInt = null;
|
||||
this._extractable = false;
|
||||
}
|
||||
|
||||
get algorithm() {
|
||||
return { name: "RSA-PKCS1-v1_5" };
|
||||
}
|
||||
|
||||
_base64urlDecode(data) {
|
||||
data = data.replace(/-/g, "+").replace(/_/g, "/");
|
||||
data = data.padEnd(Math.ceil(data.length / 4) * 4, "=");
|
||||
return Base64.decode(data);
|
||||
}
|
||||
|
||||
_padArray(arr, length) {
|
||||
const res = new Uint8Array(length);
|
||||
res.set(arr, length - arr.length);
|
||||
return res;
|
||||
}
|
||||
|
||||
static async generateKey(algorithm, extractable, _keyUsages) {
|
||||
const cipher = new RSACipher;
|
||||
await cipher._generateKey(algorithm, extractable);
|
||||
return { privateKey: cipher };
|
||||
}
|
||||
|
||||
async _generateKey(algorithm, extractable) {
|
||||
this._keyLength = algorithm.modulusLength;
|
||||
this._keyBytes = Math.ceil(this._keyLength / 8);
|
||||
const key = await window.crypto.subtle.generateKey(
|
||||
{
|
||||
name: "RSA-OAEP",
|
||||
modulusLength: algorithm.modulusLength,
|
||||
publicExponent: algorithm.publicExponent,
|
||||
hash: {name: "SHA-256"},
|
||||
},
|
||||
true, ["encrypt", "decrypt"]);
|
||||
const privateKey = await window.crypto.subtle.exportKey("jwk", key.privateKey);
|
||||
this._n = this._padArray(this._base64urlDecode(privateKey.n), this._keyBytes);
|
||||
this._nBigInt = u8ArrayToBigInt(this._n);
|
||||
this._e = this._padArray(this._base64urlDecode(privateKey.e), this._keyBytes);
|
||||
this._eBigInt = u8ArrayToBigInt(this._e);
|
||||
this._d = this._padArray(this._base64urlDecode(privateKey.d), this._keyBytes);
|
||||
this._dBigInt = u8ArrayToBigInt(this._d);
|
||||
this._extractable = extractable;
|
||||
}
|
||||
|
||||
static async importKey(key, _algorithm, extractable, keyUsages) {
|
||||
if (keyUsages.length !== 1 || keyUsages[0] !== "encrypt") {
|
||||
throw new Error("only support importing RSA public key");
|
||||
}
|
||||
const cipher = new RSACipher;
|
||||
await cipher._importKey(key, extractable);
|
||||
return cipher;
|
||||
}
|
||||
|
||||
async _importKey(key, extractable) {
|
||||
const n = key.n;
|
||||
const e = key.e;
|
||||
if (n.length !== e.length) {
|
||||
throw new Error("the sizes of modulus and public exponent do not match");
|
||||
}
|
||||
this._keyBytes = n.length;
|
||||
this._keyLength = this._keyBytes * 8;
|
||||
this._n = new Uint8Array(this._keyBytes);
|
||||
this._e = new Uint8Array(this._keyBytes);
|
||||
this._n.set(n);
|
||||
this._e.set(e);
|
||||
this._nBigInt = u8ArrayToBigInt(this._n);
|
||||
this._eBigInt = u8ArrayToBigInt(this._e);
|
||||
this._extractable = extractable;
|
||||
}
|
||||
|
||||
async encrypt(_algorithm, message) {
|
||||
if (message.length > this._keyBytes - 11) {
|
||||
return null;
|
||||
}
|
||||
const ps = new Uint8Array(this._keyBytes - message.length - 3);
|
||||
window.crypto.getRandomValues(ps);
|
||||
for (let i = 0; i < ps.length; i++) {
|
||||
ps[i] = Math.floor(ps[i] * 254 / 255 + 1);
|
||||
}
|
||||
const em = new Uint8Array(this._keyBytes);
|
||||
em[1] = 0x02;
|
||||
em.set(ps, 2);
|
||||
em.set(message, ps.length + 3);
|
||||
const emBigInt = u8ArrayToBigInt(em);
|
||||
const c = modPow(emBigInt, this._eBigInt, this._nBigInt);
|
||||
return bigIntToU8Array(c, this._keyBytes);
|
||||
}
|
||||
|
||||
async decrypt(_algorithm, message) {
|
||||
if (message.length !== this._keyBytes) {
|
||||
return null;
|
||||
}
|
||||
const msgBigInt = u8ArrayToBigInt(message);
|
||||
const emBigInt = modPow(msgBigInt, this._dBigInt, this._nBigInt);
|
||||
const em = bigIntToU8Array(emBigInt, this._keyBytes);
|
||||
if (em[0] !== 0x00 || em[1] !== 0x02) {
|
||||
return null;
|
||||
}
|
||||
let i = 2;
|
||||
for (; i < em.length; i++) {
|
||||
if (em[i] === 0x00) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i === em.length) {
|
||||
return null;
|
||||
}
|
||||
return em.slice(i + 1, em.length);
|
||||
}
|
||||
|
||||
async exportKey() {
|
||||
if (!this._extractable) {
|
||||
throw new Error("key is not extractable");
|
||||
}
|
||||
return { n: this._n, e: this._e, d: this._d };
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2019 The noVNC authors
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*
|
||||
*/
|
||||
|
||||
export default class CopyRectDecoder {
|
||||
decodeRect(x, y, width, height, sock, display, depth) {
|
||||
if (sock.rQwait("COPYRECT", 4)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let deltaX = sock.rQshift16();
|
||||
let deltaY = sock.rQshift16();
|
||||
|
||||
if ((width === 0) || (height === 0)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
display.copyImage(deltaX, deltaY, x, y, width, height);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+321
@@ -0,0 +1,321 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2024 The noVNC authors
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*
|
||||
*/
|
||||
|
||||
import * as Log from '../util/logging.js';
|
||||
|
||||
export class H264Parser {
|
||||
constructor(data) {
|
||||
this._data = data;
|
||||
this._index = 0;
|
||||
this.profileIdc = null;
|
||||
this.constraintSet = null;
|
||||
this.levelIdc = null;
|
||||
}
|
||||
|
||||
_getStartSequenceLen(index) {
|
||||
let data = this._data;
|
||||
if (data[index + 0] == 0 && data[index + 1] == 0 && data[index + 2] == 0 && data[index + 3] == 1) {
|
||||
return 4;
|
||||
}
|
||||
if (data[index + 0] == 0 && data[index + 1] == 0 && data[index + 2] == 1) {
|
||||
return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
_indexOfNextNalUnit(index) {
|
||||
let data = this._data;
|
||||
for (let i = index; i < data.length; ++i) {
|
||||
if (this._getStartSequenceLen(i) != 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
_parseSps(index) {
|
||||
this.profileIdc = this._data[index];
|
||||
this.constraintSet = this._data[index + 1];
|
||||
this.levelIdc = this._data[index + 2];
|
||||
}
|
||||
|
||||
_parseNalUnit(index) {
|
||||
const firstByte = this._data[index];
|
||||
if (firstByte & 0x80) {
|
||||
throw new Error('H264 parsing sanity check failed, forbidden zero bit is set');
|
||||
}
|
||||
const unitType = firstByte & 0x1f;
|
||||
|
||||
switch (unitType) {
|
||||
case 1: // coded slice, non-idr
|
||||
return { slice: true };
|
||||
case 5: // coded slice, idr
|
||||
return { slice: true, key: true };
|
||||
case 6: // sei
|
||||
return {};
|
||||
case 7: // sps
|
||||
this._parseSps(index + 1);
|
||||
return {};
|
||||
case 8: // pps
|
||||
return {};
|
||||
default:
|
||||
Log.Warn("Unhandled unit type: ", unitType);
|
||||
break;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
parse() {
|
||||
const startIndex = this._index;
|
||||
let isKey = false;
|
||||
|
||||
while (this._index < this._data.length) {
|
||||
const startSequenceLen = this._getStartSequenceLen(this._index);
|
||||
if (startSequenceLen == 0) {
|
||||
throw new Error('Invalid start sequence in bit stream');
|
||||
}
|
||||
|
||||
const { slice, key } = this._parseNalUnit(this._index + startSequenceLen);
|
||||
|
||||
let nextIndex = this._indexOfNextNalUnit(this._index + startSequenceLen);
|
||||
if (nextIndex == -1) {
|
||||
this._index = this._data.length;
|
||||
} else {
|
||||
this._index = nextIndex;
|
||||
}
|
||||
|
||||
if (key) {
|
||||
isKey = true;
|
||||
}
|
||||
if (slice) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (startIndex === this._index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
frame: this._data.subarray(startIndex, this._index),
|
||||
key: isKey,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class H264Context {
|
||||
constructor(width, height) {
|
||||
this.lastUsed = 0;
|
||||
this._width = width;
|
||||
this._height = height;
|
||||
this._profileIdc = null;
|
||||
this._constraintSet = null;
|
||||
this._levelIdc = null;
|
||||
this._decoder = null;
|
||||
this._pendingFrames = [];
|
||||
}
|
||||
|
||||
_handleFrame(frame) {
|
||||
let pending = this._pendingFrames.shift();
|
||||
if (pending === undefined) {
|
||||
throw new Error("Pending frame queue empty when receiving frame from decoder");
|
||||
}
|
||||
|
||||
if (pending.timestamp != frame.timestamp) {
|
||||
throw new Error("Video frame timestamp mismatch. Expected " +
|
||||
frame.timestamp + " but but got " + pending.timestamp);
|
||||
}
|
||||
|
||||
pending.frame = frame;
|
||||
pending.ready = true;
|
||||
pending.resolve();
|
||||
|
||||
if (!pending.keep) {
|
||||
frame.close();
|
||||
}
|
||||
}
|
||||
|
||||
_handleError(e) {
|
||||
throw new Error("Failed to decode frame: " + e.message);
|
||||
}
|
||||
|
||||
_configureDecoder(profileIdc, constraintSet, levelIdc) {
|
||||
if (this._decoder === null || this._decoder.state === 'closed') {
|
||||
this._decoder = new VideoDecoder({
|
||||
output: frame => this._handleFrame(frame),
|
||||
error: e => this._handleError(e),
|
||||
});
|
||||
}
|
||||
const codec = 'avc1.' +
|
||||
profileIdc.toString(16).padStart(2, '0') +
|
||||
constraintSet.toString(16).padStart(2, '0') +
|
||||
levelIdc.toString(16).padStart(2, '0');
|
||||
this._decoder.configure({
|
||||
codec: codec,
|
||||
codedWidth: this._width,
|
||||
codedHeight: this._height,
|
||||
optimizeForLatency: true,
|
||||
});
|
||||
}
|
||||
|
||||
_preparePendingFrame(timestamp) {
|
||||
let pending = {
|
||||
timestamp: timestamp,
|
||||
promise: null,
|
||||
resolve: null,
|
||||
frame: null,
|
||||
ready: false,
|
||||
keep: false,
|
||||
};
|
||||
pending.promise = new Promise((resolve) => {
|
||||
pending.resolve = resolve;
|
||||
});
|
||||
this._pendingFrames.push(pending);
|
||||
|
||||
return pending;
|
||||
}
|
||||
|
||||
decode(payload) {
|
||||
let parser = new H264Parser(payload);
|
||||
let result = null;
|
||||
|
||||
// Ideally, this timestamp should come from the server, but we'll just
|
||||
// approximate it instead.
|
||||
let timestamp = Math.round(window.performance.now() * 1e3);
|
||||
|
||||
while (true) {
|
||||
let encodedFrame = parser.parse();
|
||||
if (encodedFrame === null) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (parser.profileIdc !== null) {
|
||||
self._profileIdc = parser.profileIdc;
|
||||
self._constraintSet = parser.constraintSet;
|
||||
self._levelIdc = parser.levelIdc;
|
||||
}
|
||||
|
||||
if (this._decoder === null || this._decoder.state !== 'configured') {
|
||||
if (!encodedFrame.key) {
|
||||
Log.Warn("Missing key frame. Can't decode until one arrives");
|
||||
continue;
|
||||
}
|
||||
if (self._profileIdc === null) {
|
||||
Log.Warn('Cannot config decoder. Have not received SPS and PPS yet.');
|
||||
continue;
|
||||
}
|
||||
this._configureDecoder(self._profileIdc, self._constraintSet,
|
||||
self._levelIdc);
|
||||
}
|
||||
|
||||
result = this._preparePendingFrame(timestamp);
|
||||
|
||||
const chunk = new EncodedVideoChunk({
|
||||
timestamp: timestamp,
|
||||
type: encodedFrame.key ? 'key' : 'delta',
|
||||
data: encodedFrame.frame,
|
||||
});
|
||||
|
||||
try {
|
||||
this._decoder.decode(chunk);
|
||||
} catch (e) {
|
||||
Log.Warn("Failed to decode:", e);
|
||||
}
|
||||
}
|
||||
|
||||
// We only keep last frame of each payload
|
||||
if (result !== null) {
|
||||
result.keep = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export default class H264Decoder {
|
||||
constructor() {
|
||||
this._tick = 0;
|
||||
this._contexts = {};
|
||||
}
|
||||
|
||||
_contextId(x, y, width, height) {
|
||||
return [x, y, width, height].join(',');
|
||||
}
|
||||
|
||||
_findOldestContextId() {
|
||||
let oldestTick = Number.MAX_VALUE;
|
||||
let oldestKey = undefined;
|
||||
for (const [key, value] of Object.entries(this._contexts)) {
|
||||
if (value.lastUsed < oldestTick) {
|
||||
oldestTick = value.lastUsed;
|
||||
oldestKey = key;
|
||||
}
|
||||
}
|
||||
return oldestKey;
|
||||
}
|
||||
|
||||
_createContext(x, y, width, height) {
|
||||
const maxContexts = 64;
|
||||
if (Object.keys(this._contexts).length >= maxContexts) {
|
||||
let oldestContextId = this._findOldestContextId();
|
||||
delete this._contexts[oldestContextId];
|
||||
}
|
||||
let context = new H264Context(width, height);
|
||||
this._contexts[this._contextId(x, y, width, height)] = context;
|
||||
return context;
|
||||
}
|
||||
|
||||
_getContext(x, y, width, height) {
|
||||
let context = this._contexts[this._contextId(x, y, width, height)];
|
||||
return context !== undefined ? context : this._createContext(x, y, width, height);
|
||||
}
|
||||
|
||||
_resetContext(x, y, width, height) {
|
||||
delete this._contexts[this._contextId(x, y, width, height)];
|
||||
}
|
||||
|
||||
_resetAllContexts() {
|
||||
this._contexts = {};
|
||||
}
|
||||
|
||||
decodeRect(x, y, width, height, sock, display, depth) {
|
||||
const resetContextFlag = 1;
|
||||
const resetAllContextsFlag = 2;
|
||||
|
||||
if (sock.rQwait("h264 header", 8)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const length = sock.rQshift32();
|
||||
const flags = sock.rQshift32();
|
||||
|
||||
if (sock.rQwait("h264 payload", length, 8)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (flags & resetAllContextsFlag) {
|
||||
this._resetAllContexts();
|
||||
} else if (flags & resetContextFlag) {
|
||||
this._resetContext(x, y, width, height);
|
||||
}
|
||||
|
||||
let context = this._getContext(x, y, width, height);
|
||||
context.lastUsed = this._tick++;
|
||||
|
||||
if (length !== 0) {
|
||||
let payload = sock.rQshiftBytes(length, false);
|
||||
let frame = context.decode(payload);
|
||||
if (frame !== null) {
|
||||
display.videoFrame(x, y, width, height, frame);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2019 The noVNC authors
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*
|
||||
*/
|
||||
|
||||
import * as Log from '../util/logging.js';
|
||||
|
||||
export default class HextileDecoder {
|
||||
constructor() {
|
||||
this._tiles = 0;
|
||||
this._lastsubencoding = 0;
|
||||
this._tileBuffer = new Uint8Array(16 * 16 * 4);
|
||||
}
|
||||
|
||||
decodeRect(x, y, width, height, sock, display, depth) {
|
||||
if (this._tiles === 0) {
|
||||
this._tilesX = Math.ceil(width / 16);
|
||||
this._tilesY = Math.ceil(height / 16);
|
||||
this._totalTiles = this._tilesX * this._tilesY;
|
||||
this._tiles = this._totalTiles;
|
||||
}
|
||||
|
||||
while (this._tiles > 0) {
|
||||
let bytes = 1;
|
||||
|
||||
if (sock.rQwait("HEXTILE", bytes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let subencoding = sock.rQpeek8();
|
||||
if (subencoding > 30) { // Raw
|
||||
throw new Error("Illegal hextile subencoding (subencoding: " +
|
||||
subencoding + ")");
|
||||
}
|
||||
|
||||
const currTile = this._totalTiles - this._tiles;
|
||||
const tileX = currTile % this._tilesX;
|
||||
const tileY = Math.floor(currTile / this._tilesX);
|
||||
const tx = x + tileX * 16;
|
||||
const ty = y + tileY * 16;
|
||||
const tw = Math.min(16, (x + width) - tx);
|
||||
const th = Math.min(16, (y + height) - ty);
|
||||
|
||||
// Figure out how much we are expecting
|
||||
if (subencoding & 0x01) { // Raw
|
||||
bytes += tw * th * 4;
|
||||
} else {
|
||||
if (subencoding & 0x02) { // Background
|
||||
bytes += 4;
|
||||
}
|
||||
if (subencoding & 0x04) { // Foreground
|
||||
bytes += 4;
|
||||
}
|
||||
if (subencoding & 0x08) { // AnySubrects
|
||||
bytes++; // Since we aren't shifting it off
|
||||
|
||||
if (sock.rQwait("HEXTILE", bytes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let subrects = sock.rQpeekBytes(bytes).at(-1);
|
||||
if (subencoding & 0x10) { // SubrectsColoured
|
||||
bytes += subrects * (4 + 2);
|
||||
} else {
|
||||
bytes += subrects * 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sock.rQwait("HEXTILE", bytes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We know the encoding and have a whole tile
|
||||
sock.rQshift8();
|
||||
if (subencoding === 0) {
|
||||
if (this._lastsubencoding & 0x01) {
|
||||
// Weird: ignore blanks are RAW
|
||||
Log.Debug(" Ignoring blank after RAW");
|
||||
} else {
|
||||
display.fillRect(tx, ty, tw, th, this._background);
|
||||
}
|
||||
} else if (subencoding & 0x01) { // Raw
|
||||
let pixels = tw * th;
|
||||
let data = sock.rQshiftBytes(pixels * 4, false);
|
||||
// Max sure the image is fully opaque
|
||||
for (let i = 0;i < pixels;i++) {
|
||||
data[i * 4 + 3] = 255;
|
||||
}
|
||||
display.blitImage(tx, ty, tw, th, data, 0);
|
||||
} else {
|
||||
if (subencoding & 0x02) { // Background
|
||||
this._background = new Uint8Array(sock.rQshiftBytes(4));
|
||||
}
|
||||
if (subencoding & 0x04) { // Foreground
|
||||
this._foreground = new Uint8Array(sock.rQshiftBytes(4));
|
||||
}
|
||||
|
||||
this._startTile(tx, ty, tw, th, this._background);
|
||||
if (subencoding & 0x08) { // AnySubrects
|
||||
let subrects = sock.rQshift8();
|
||||
|
||||
for (let s = 0; s < subrects; s++) {
|
||||
let color;
|
||||
if (subencoding & 0x10) { // SubrectsColoured
|
||||
color = sock.rQshiftBytes(4);
|
||||
} else {
|
||||
color = this._foreground;
|
||||
}
|
||||
const xy = sock.rQshift8();
|
||||
const sx = (xy >> 4);
|
||||
const sy = (xy & 0x0f);
|
||||
|
||||
const wh = sock.rQshift8();
|
||||
const sw = (wh >> 4) + 1;
|
||||
const sh = (wh & 0x0f) + 1;
|
||||
|
||||
this._subTile(sx, sy, sw, sh, color);
|
||||
}
|
||||
}
|
||||
this._finishTile(display);
|
||||
}
|
||||
this._lastsubencoding = subencoding;
|
||||
this._tiles--;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// start updating a tile
|
||||
_startTile(x, y, width, height, color) {
|
||||
this._tileX = x;
|
||||
this._tileY = y;
|
||||
this._tileW = width;
|
||||
this._tileH = height;
|
||||
|
||||
const red = color[0];
|
||||
const green = color[1];
|
||||
const blue = color[2];
|
||||
|
||||
const data = this._tileBuffer;
|
||||
for (let i = 0; i < width * height * 4; i += 4) {
|
||||
data[i] = red;
|
||||
data[i + 1] = green;
|
||||
data[i + 2] = blue;
|
||||
data[i + 3] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
// update sub-rectangle of the current tile
|
||||
_subTile(x, y, w, h, color) {
|
||||
const red = color[0];
|
||||
const green = color[1];
|
||||
const blue = color[2];
|
||||
const xend = x + w;
|
||||
const yend = y + h;
|
||||
|
||||
const data = this._tileBuffer;
|
||||
const width = this._tileW;
|
||||
for (let j = y; j < yend; j++) {
|
||||
for (let i = x; i < xend; i++) {
|
||||
const p = (i + (j * width)) * 4;
|
||||
data[p] = red;
|
||||
data[p + 1] = green;
|
||||
data[p + 2] = blue;
|
||||
data[p + 3] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// draw the current tile to the screen
|
||||
_finishTile(display) {
|
||||
display.blitImage(this._tileX, this._tileY,
|
||||
this._tileW, this._tileH,
|
||||
this._tileBuffer, 0);
|
||||
}
|
||||
}
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2019 The noVNC authors
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*
|
||||
*/
|
||||
|
||||
export default class JPEGDecoder {
|
||||
constructor() {
|
||||
// RealVNC will reuse the quantization tables
|
||||
// and Huffman tables, so we need to cache them.
|
||||
this._cachedQuantTables = [];
|
||||
this._cachedHuffmanTables = [];
|
||||
|
||||
this._segments = [];
|
||||
}
|
||||
|
||||
decodeRect(x, y, width, height, sock, display, depth) {
|
||||
// A rect of JPEG encodings is simply a JPEG file
|
||||
while (true) {
|
||||
let segment = this._readSegment(sock);
|
||||
if (segment === null) {
|
||||
return false;
|
||||
}
|
||||
this._segments.push(segment);
|
||||
// End of image?
|
||||
if (segment[1] === 0xD9) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let huffmanTables = [];
|
||||
let quantTables = [];
|
||||
for (let segment of this._segments) {
|
||||
let type = segment[1];
|
||||
if (type === 0xC4) {
|
||||
// Huffman tables
|
||||
huffmanTables.push(segment);
|
||||
} else if (type === 0xDB) {
|
||||
// Quantization tables
|
||||
quantTables.push(segment);
|
||||
}
|
||||
}
|
||||
|
||||
const sofIndex = this._segments.findIndex(
|
||||
x => x[1] == 0xC0 || x[1] == 0xC2
|
||||
);
|
||||
if (sofIndex == -1) {
|
||||
throw new Error("Illegal JPEG image without SOF");
|
||||
}
|
||||
|
||||
if (quantTables.length === 0) {
|
||||
this._segments.splice(sofIndex+1, 0,
|
||||
...this._cachedQuantTables);
|
||||
}
|
||||
if (huffmanTables.length === 0) {
|
||||
this._segments.splice(sofIndex+1, 0,
|
||||
...this._cachedHuffmanTables);
|
||||
}
|
||||
|
||||
let length = 0;
|
||||
for (let segment of this._segments) {
|
||||
length += segment.length;
|
||||
}
|
||||
|
||||
let data = new Uint8Array(length);
|
||||
length = 0;
|
||||
for (let segment of this._segments) {
|
||||
data.set(segment, length);
|
||||
length += segment.length;
|
||||
}
|
||||
|
||||
display.imageRect(x, y, width, height, "image/jpeg", data);
|
||||
|
||||
if (huffmanTables.length !== 0) {
|
||||
this._cachedHuffmanTables = huffmanTables;
|
||||
}
|
||||
if (quantTables.length !== 0) {
|
||||
this._cachedQuantTables = quantTables;
|
||||
}
|
||||
|
||||
this._segments = [];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
_readSegment(sock) {
|
||||
if (sock.rQwait("JPEG", 2)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let marker = sock.rQshift8();
|
||||
if (marker != 0xFF) {
|
||||
throw new Error("Illegal JPEG marker received (byte: " +
|
||||
marker + ")");
|
||||
}
|
||||
let type = sock.rQshift8();
|
||||
if (type >= 0xD0 && type <= 0xD9 || type == 0x01) {
|
||||
// No length after marker
|
||||
return new Uint8Array([marker, type]);
|
||||
}
|
||||
|
||||
if (sock.rQwait("JPEG", 2, 2)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let length = sock.rQshift16();
|
||||
if (length < 2) {
|
||||
throw new Error("Illegal JPEG length received (length: " +
|
||||
length + ")");
|
||||
}
|
||||
|
||||
if (sock.rQwait("JPEG", length-2, 4)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let extra = 0;
|
||||
if (type === 0xDA) {
|
||||
// start of scan
|
||||
extra += 2;
|
||||
while (true) {
|
||||
if (sock.rQwait("JPEG", length-2+extra, 4)) {
|
||||
return null;
|
||||
}
|
||||
let data = sock.rQpeekBytes(length-2+extra, false);
|
||||
if (data.at(-2) === 0xFF && data.at(-1) !== 0x00 &&
|
||||
!(data.at(-1) >= 0xD0 && data.at(-1) <= 0xD7)) {
|
||||
extra -= 2;
|
||||
break;
|
||||
}
|
||||
extra++;
|
||||
}
|
||||
}
|
||||
|
||||
let segment = new Uint8Array(2 + length + extra);
|
||||
segment[0] = marker;
|
||||
segment[1] = type;
|
||||
segment[2] = length >> 8;
|
||||
segment[3] = length;
|
||||
segment.set(sock.rQshiftBytes(length-2+extra, false), 4);
|
||||
|
||||
return segment;
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2019 The noVNC authors
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*
|
||||
*/
|
||||
|
||||
export default class RawDecoder {
|
||||
constructor() {
|
||||
this._lines = 0;
|
||||
}
|
||||
|
||||
decodeRect(x, y, width, height, sock, display, depth) {
|
||||
if ((width === 0) || (height === 0)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this._lines === 0) {
|
||||
this._lines = height;
|
||||
}
|
||||
|
||||
const pixelSize = depth == 8 ? 1 : 4;
|
||||
const bytesPerLine = width * pixelSize;
|
||||
|
||||
while (this._lines > 0) {
|
||||
if (sock.rQwait("RAW", bytesPerLine)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const curY = y + (height - this._lines);
|
||||
|
||||
let data = sock.rQshiftBytes(bytesPerLine, false);
|
||||
|
||||
// Convert data if needed
|
||||
if (depth == 8) {
|
||||
const newdata = new Uint8Array(width * 4);
|
||||
for (let i = 0; i < width; i++) {
|
||||
newdata[i * 4 + 0] = ((data[i] >> 0) & 0x3) * 255 / 3;
|
||||
newdata[i * 4 + 1] = ((data[i] >> 2) & 0x3) * 255 / 3;
|
||||
newdata[i * 4 + 2] = ((data[i] >> 4) & 0x3) * 255 / 3;
|
||||
newdata[i * 4 + 3] = 255;
|
||||
}
|
||||
data = newdata;
|
||||
}
|
||||
|
||||
// Max sure the image is fully opaque
|
||||
for (let i = 0; i < width; i++) {
|
||||
data[i * 4 + 3] = 255;
|
||||
}
|
||||
|
||||
display.blitImage(x, curY, width, 1, data, 0);
|
||||
this._lines--;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2019 The noVNC authors
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*
|
||||
*/
|
||||
|
||||
export default class RREDecoder {
|
||||
constructor() {
|
||||
this._subrects = 0;
|
||||
}
|
||||
|
||||
decodeRect(x, y, width, height, sock, display, depth) {
|
||||
if (this._subrects === 0) {
|
||||
if (sock.rQwait("RRE", 4 + 4)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._subrects = sock.rQshift32();
|
||||
|
||||
let color = sock.rQshiftBytes(4); // Background
|
||||
display.fillRect(x, y, width, height, color);
|
||||
}
|
||||
|
||||
while (this._subrects > 0) {
|
||||
if (sock.rQwait("RRE", 4 + 8)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let color = sock.rQshiftBytes(4);
|
||||
let sx = sock.rQshift16();
|
||||
let sy = sock.rQshift16();
|
||||
let swidth = sock.rQshift16();
|
||||
let sheight = sock.rQshift16();
|
||||
display.fillRect(x + sx, y + sy, swidth, sheight, color);
|
||||
|
||||
this._subrects--;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+393
@@ -0,0 +1,393 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2019 The noVNC authors
|
||||
* (c) 2012 Michael Tinglof, Joe Balaz, Les Piech (Mercuri.ca)
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*
|
||||
*/
|
||||
|
||||
import * as Log from '../util/logging.js';
|
||||
import Inflator from "../inflator.js";
|
||||
|
||||
export default class TightDecoder {
|
||||
constructor() {
|
||||
this._ctl = null;
|
||||
this._filter = null;
|
||||
this._numColors = 0;
|
||||
this._palette = new Uint8Array(1024); // 256 * 4 (max palette size * max bytes-per-pixel)
|
||||
this._len = 0;
|
||||
|
||||
this._zlibs = [];
|
||||
for (let i = 0; i < 4; i++) {
|
||||
this._zlibs[i] = new Inflator();
|
||||
}
|
||||
}
|
||||
|
||||
decodeRect(x, y, width, height, sock, display, depth) {
|
||||
if (this._ctl === null) {
|
||||
if (sock.rQwait("TIGHT compression-control", 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._ctl = sock.rQshift8();
|
||||
|
||||
// Reset streams if the server requests it
|
||||
for (let i = 0; i < 4; i++) {
|
||||
if ((this._ctl >> i) & 1) {
|
||||
this._zlibs[i].reset();
|
||||
Log.Info("Reset zlib stream " + i);
|
||||
}
|
||||
}
|
||||
|
||||
// Figure out filter
|
||||
this._ctl = this._ctl >> 4;
|
||||
}
|
||||
|
||||
let ret;
|
||||
|
||||
if (this._ctl === 0x08) {
|
||||
ret = this._fillRect(x, y, width, height,
|
||||
sock, display, depth);
|
||||
} else if (this._ctl === 0x09) {
|
||||
ret = this._jpegRect(x, y, width, height,
|
||||
sock, display, depth);
|
||||
} else if (this._ctl === 0x0A) {
|
||||
ret = this._pngRect(x, y, width, height,
|
||||
sock, display, depth);
|
||||
} else if ((this._ctl & 0x08) == 0) {
|
||||
ret = this._basicRect(this._ctl, x, y, width, height,
|
||||
sock, display, depth);
|
||||
} else {
|
||||
throw new Error("Illegal tight compression received (ctl: " +
|
||||
this._ctl + ")");
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
this._ctl = null;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
_fillRect(x, y, width, height, sock, display, depth) {
|
||||
if (sock.rQwait("TIGHT", 3)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let pixel = sock.rQshiftBytes(3);
|
||||
display.fillRect(x, y, width, height, pixel, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
_jpegRect(x, y, width, height, sock, display, depth) {
|
||||
let data = this._readData(sock);
|
||||
if (data === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
display.imageRect(x, y, width, height, "image/jpeg", data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
_pngRect(x, y, width, height, sock, display, depth) {
|
||||
throw new Error("PNG received in standard Tight rect");
|
||||
}
|
||||
|
||||
_basicRect(ctl, x, y, width, height, sock, display, depth) {
|
||||
if (this._filter === null) {
|
||||
if (ctl & 0x4) {
|
||||
if (sock.rQwait("TIGHT", 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._filter = sock.rQshift8();
|
||||
} else {
|
||||
// Implicit CopyFilter
|
||||
this._filter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
let streamId = ctl & 0x3;
|
||||
|
||||
let ret;
|
||||
|
||||
switch (this._filter) {
|
||||
case 0: // CopyFilter
|
||||
ret = this._copyFilter(streamId, x, y, width, height,
|
||||
sock, display, depth);
|
||||
break;
|
||||
case 1: // PaletteFilter
|
||||
ret = this._paletteFilter(streamId, x, y, width, height,
|
||||
sock, display, depth);
|
||||
break;
|
||||
case 2: // GradientFilter
|
||||
ret = this._gradientFilter(streamId, x, y, width, height,
|
||||
sock, display, depth);
|
||||
break;
|
||||
default:
|
||||
throw new Error("Illegal tight filter received (ctl: " +
|
||||
this._filter + ")");
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
this._filter = null;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
_copyFilter(streamId, x, y, width, height, sock, display, depth) {
|
||||
const uncompressedSize = width * height * 3;
|
||||
let data;
|
||||
|
||||
if (uncompressedSize === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (uncompressedSize < 12) {
|
||||
if (sock.rQwait("TIGHT", uncompressedSize)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
data = sock.rQshiftBytes(uncompressedSize);
|
||||
} else {
|
||||
data = this._readData(sock);
|
||||
if (data === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._zlibs[streamId].setInput(data);
|
||||
data = this._zlibs[streamId].inflate(uncompressedSize);
|
||||
this._zlibs[streamId].setInput(null);
|
||||
}
|
||||
|
||||
let rgbx = new Uint8Array(width * height * 4);
|
||||
for (let i = 0, j = 0; i < width * height * 4; i += 4, j += 3) {
|
||||
rgbx[i] = data[j];
|
||||
rgbx[i + 1] = data[j + 1];
|
||||
rgbx[i + 2] = data[j + 2];
|
||||
rgbx[i + 3] = 255; // Alpha
|
||||
}
|
||||
|
||||
display.blitImage(x, y, width, height, rgbx, 0, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
_paletteFilter(streamId, x, y, width, height, sock, display, depth) {
|
||||
if (this._numColors === 0) {
|
||||
if (sock.rQwait("TIGHT palette", 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const numColors = sock.rQpeek8() + 1;
|
||||
const paletteSize = numColors * 3;
|
||||
|
||||
if (sock.rQwait("TIGHT palette", 1 + paletteSize)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._numColors = numColors;
|
||||
sock.rQskipBytes(1);
|
||||
|
||||
sock.rQshiftTo(this._palette, paletteSize);
|
||||
}
|
||||
|
||||
const bpp = (this._numColors <= 2) ? 1 : 8;
|
||||
const rowSize = Math.floor((width * bpp + 7) / 8);
|
||||
const uncompressedSize = rowSize * height;
|
||||
|
||||
let data;
|
||||
|
||||
if (uncompressedSize === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (uncompressedSize < 12) {
|
||||
if (sock.rQwait("TIGHT", uncompressedSize)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
data = sock.rQshiftBytes(uncompressedSize);
|
||||
} else {
|
||||
data = this._readData(sock);
|
||||
if (data === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._zlibs[streamId].setInput(data);
|
||||
data = this._zlibs[streamId].inflate(uncompressedSize);
|
||||
this._zlibs[streamId].setInput(null);
|
||||
}
|
||||
|
||||
// Convert indexed (palette based) image data to RGB
|
||||
if (this._numColors == 2) {
|
||||
this._monoRect(x, y, width, height, data, this._palette, display);
|
||||
} else {
|
||||
this._paletteRect(x, y, width, height, data, this._palette, display);
|
||||
}
|
||||
|
||||
this._numColors = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
_monoRect(x, y, width, height, data, palette, display) {
|
||||
// Convert indexed (palette based) image data to RGB
|
||||
// TODO: reduce number of calculations inside loop
|
||||
const dest = this._getScratchBuffer(width * height * 4);
|
||||
const w = Math.floor((width + 7) / 8);
|
||||
const w1 = Math.floor(width / 8);
|
||||
|
||||
for (let y = 0; y < height; y++) {
|
||||
let dp, sp, x;
|
||||
for (x = 0; x < w1; x++) {
|
||||
for (let b = 7; b >= 0; b--) {
|
||||
dp = (y * width + x * 8 + 7 - b) * 4;
|
||||
sp = (data[y * w + x] >> b & 1) * 3;
|
||||
dest[dp] = palette[sp];
|
||||
dest[dp + 1] = palette[sp + 1];
|
||||
dest[dp + 2] = palette[sp + 2];
|
||||
dest[dp + 3] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
for (let b = 7; b >= 8 - width % 8; b--) {
|
||||
dp = (y * width + x * 8 + 7 - b) * 4;
|
||||
sp = (data[y * w + x] >> b & 1) * 3;
|
||||
dest[dp] = palette[sp];
|
||||
dest[dp + 1] = palette[sp + 1];
|
||||
dest[dp + 2] = palette[sp + 2];
|
||||
dest[dp + 3] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
display.blitImage(x, y, width, height, dest, 0, false);
|
||||
}
|
||||
|
||||
_paletteRect(x, y, width, height, data, palette, display) {
|
||||
// Convert indexed (palette based) image data to RGB
|
||||
const dest = this._getScratchBuffer(width * height * 4);
|
||||
const total = width * height * 4;
|
||||
for (let i = 0, j = 0; i < total; i += 4, j++) {
|
||||
const sp = data[j] * 3;
|
||||
dest[i] = palette[sp];
|
||||
dest[i + 1] = palette[sp + 1];
|
||||
dest[i + 2] = palette[sp + 2];
|
||||
dest[i + 3] = 255;
|
||||
}
|
||||
|
||||
display.blitImage(x, y, width, height, dest, 0, false);
|
||||
}
|
||||
|
||||
_gradientFilter(streamId, x, y, width, height, sock, display, depth) {
|
||||
// assume the TPIXEL is 3 bytes long
|
||||
const uncompressedSize = width * height * 3;
|
||||
let data;
|
||||
|
||||
if (uncompressedSize === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (uncompressedSize < 12) {
|
||||
if (sock.rQwait("TIGHT", uncompressedSize)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
data = sock.rQshiftBytes(uncompressedSize);
|
||||
} else {
|
||||
data = this._readData(sock);
|
||||
if (data === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._zlibs[streamId].setInput(data);
|
||||
data = this._zlibs[streamId].inflate(uncompressedSize);
|
||||
this._zlibs[streamId].setInput(null);
|
||||
}
|
||||
|
||||
let rgbx = new Uint8Array(4 * width * height);
|
||||
|
||||
let rgbxIndex = 0, dataIndex = 0;
|
||||
let left = new Uint8Array(3);
|
||||
for (let x = 0; x < width; x++) {
|
||||
for (let c = 0; c < 3; c++) {
|
||||
const prediction = left[c];
|
||||
const value = data[dataIndex++] + prediction;
|
||||
rgbx[rgbxIndex++] = value;
|
||||
left[c] = value;
|
||||
}
|
||||
rgbx[rgbxIndex++] = 255;
|
||||
}
|
||||
|
||||
let upperIndex = 0;
|
||||
let upper = new Uint8Array(3),
|
||||
upperleft = new Uint8Array(3);
|
||||
for (let y = 1; y < height; y++) {
|
||||
left.fill(0);
|
||||
upperleft.fill(0);
|
||||
for (let x = 0; x < width; x++) {
|
||||
for (let c = 0; c < 3; c++) {
|
||||
upper[c] = rgbx[upperIndex++];
|
||||
let prediction = left[c] + upper[c] - upperleft[c];
|
||||
if (prediction < 0) {
|
||||
prediction = 0;
|
||||
} else if (prediction > 255) {
|
||||
prediction = 255;
|
||||
}
|
||||
const value = data[dataIndex++] + prediction;
|
||||
rgbx[rgbxIndex++] = value;
|
||||
upperleft[c] = upper[c];
|
||||
left[c] = value;
|
||||
}
|
||||
rgbx[rgbxIndex++] = 255;
|
||||
upperIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
display.blitImage(x, y, width, height, rgbx, 0, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
_readData(sock) {
|
||||
if (this._len === 0) {
|
||||
if (sock.rQwait("TIGHT", 3)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let byte;
|
||||
|
||||
byte = sock.rQshift8();
|
||||
this._len = byte & 0x7f;
|
||||
if (byte & 0x80) {
|
||||
byte = sock.rQshift8();
|
||||
this._len |= (byte & 0x7f) << 7;
|
||||
if (byte & 0x80) {
|
||||
byte = sock.rQshift8();
|
||||
this._len |= byte << 14;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sock.rQwait("TIGHT", this._len)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let data = sock.rQshiftBytes(this._len, false);
|
||||
this._len = 0;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
_getScratchBuffer(size) {
|
||||
if (!this._scratchBuffer || (this._scratchBuffer.length < size)) {
|
||||
this._scratchBuffer = new Uint8Array(size);
|
||||
}
|
||||
return this._scratchBuffer;
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2019 The noVNC authors
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*
|
||||
*/
|
||||
|
||||
import TightDecoder from './tight.js';
|
||||
|
||||
export default class TightPNGDecoder extends TightDecoder {
|
||||
_pngRect(x, y, width, height, sock, display, depth) {
|
||||
let data = this._readData(sock);
|
||||
if (data === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
display.imageRect(x, y, width, height, "image/png", data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
_basicRect(ctl, x, y, width, height, sock, display, depth) {
|
||||
throw new Error("BasicCompression received in TightPNG rect");
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2024 The noVNC authors
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*
|
||||
*/
|
||||
|
||||
import Inflator from "../inflator.js";
|
||||
|
||||
export default class ZlibDecoder {
|
||||
constructor() {
|
||||
this._zlib = new Inflator();
|
||||
this._length = 0;
|
||||
}
|
||||
|
||||
decodeRect(x, y, width, height, sock, display, depth) {
|
||||
if ((width === 0) || (height === 0)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this._length === 0) {
|
||||
if (sock.rQwait("ZLIB", 4)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._length = sock.rQshift32();
|
||||
}
|
||||
|
||||
if (sock.rQwait("ZLIB", this._length)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let data = new Uint8Array(sock.rQshiftBytes(this._length, false));
|
||||
this._length = 0;
|
||||
|
||||
this._zlib.setInput(data);
|
||||
data = this._zlib.inflate(width * height * 4);
|
||||
this._zlib.setInput(null);
|
||||
|
||||
// Max sure the image is fully opaque
|
||||
for (let i = 0; i < width * height; i++) {
|
||||
data[i * 4 + 3] = 255;
|
||||
}
|
||||
|
||||
display.blitImage(x, y, width, height, data, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+185
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2021 The noVNC authors
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*
|
||||
*/
|
||||
|
||||
import Inflate from "../inflator.js";
|
||||
|
||||
const ZRLE_TILE_WIDTH = 64;
|
||||
const ZRLE_TILE_HEIGHT = 64;
|
||||
|
||||
export default class ZRLEDecoder {
|
||||
constructor() {
|
||||
this._length = 0;
|
||||
this._inflator = new Inflate();
|
||||
|
||||
this._pixelBuffer = new Uint8Array(ZRLE_TILE_WIDTH * ZRLE_TILE_HEIGHT * 4);
|
||||
this._tileBuffer = new Uint8Array(ZRLE_TILE_WIDTH * ZRLE_TILE_HEIGHT * 4);
|
||||
}
|
||||
|
||||
decodeRect(x, y, width, height, sock, display, depth) {
|
||||
if (this._length === 0) {
|
||||
if (sock.rQwait("ZLib data length", 4)) {
|
||||
return false;
|
||||
}
|
||||
this._length = sock.rQshift32();
|
||||
}
|
||||
if (sock.rQwait("Zlib data", this._length)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const data = sock.rQshiftBytes(this._length, false);
|
||||
|
||||
this._inflator.setInput(data);
|
||||
|
||||
for (let ty = y; ty < y + height; ty += ZRLE_TILE_HEIGHT) {
|
||||
let th = Math.min(ZRLE_TILE_HEIGHT, y + height - ty);
|
||||
|
||||
for (let tx = x; tx < x + width; tx += ZRLE_TILE_WIDTH) {
|
||||
let tw = Math.min(ZRLE_TILE_WIDTH, x + width - tx);
|
||||
|
||||
const tileSize = tw * th;
|
||||
const subencoding = this._inflator.inflate(1)[0];
|
||||
if (subencoding === 0) {
|
||||
// raw data
|
||||
const data = this._readPixels(tileSize);
|
||||
display.blitImage(tx, ty, tw, th, data, 0, false);
|
||||
} else if (subencoding === 1) {
|
||||
// solid
|
||||
const background = this._readPixels(1);
|
||||
display.fillRect(tx, ty, tw, th, [background[0], background[1], background[2]]);
|
||||
} else if (subencoding >= 2 && subencoding <= 16) {
|
||||
const data = this._decodePaletteTile(subencoding, tileSize, tw, th);
|
||||
display.blitImage(tx, ty, tw, th, data, 0, false);
|
||||
} else if (subencoding === 128) {
|
||||
const data = this._decodeRLETile(tileSize);
|
||||
display.blitImage(tx, ty, tw, th, data, 0, false);
|
||||
} else if (subencoding >= 130 && subencoding <= 255) {
|
||||
const data = this._decodeRLEPaletteTile(subencoding - 128, tileSize);
|
||||
display.blitImage(tx, ty, tw, th, data, 0, false);
|
||||
} else {
|
||||
throw new Error('Unknown subencoding: ' + subencoding);
|
||||
}
|
||||
}
|
||||
}
|
||||
this._length = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
_getBitsPerPixelInPalette(paletteSize) {
|
||||
if (paletteSize <= 2) {
|
||||
return 1;
|
||||
} else if (paletteSize <= 4) {
|
||||
return 2;
|
||||
} else if (paletteSize <= 16) {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
||||
_readPixels(pixels) {
|
||||
let data = this._pixelBuffer;
|
||||
const buffer = this._inflator.inflate(3*pixels);
|
||||
for (let i = 0, j = 0; i < pixels*4; i += 4, j += 3) {
|
||||
data[i] = buffer[j];
|
||||
data[i + 1] = buffer[j + 1];
|
||||
data[i + 2] = buffer[j + 2];
|
||||
data[i + 3] = 255; // Add the Alpha
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
_decodePaletteTile(paletteSize, tileSize, tilew, tileh) {
|
||||
const data = this._tileBuffer;
|
||||
const palette = this._readPixels(paletteSize);
|
||||
const bitsPerPixel = this._getBitsPerPixelInPalette(paletteSize);
|
||||
const mask = (1 << bitsPerPixel) - 1;
|
||||
|
||||
let offset = 0;
|
||||
let encoded = this._inflator.inflate(1)[0];
|
||||
|
||||
for (let y=0; y<tileh; y++) {
|
||||
let shift = 8-bitsPerPixel;
|
||||
for (let x=0; x<tilew; x++) {
|
||||
if (shift<0) {
|
||||
shift=8-bitsPerPixel;
|
||||
encoded = this._inflator.inflate(1)[0];
|
||||
}
|
||||
let indexInPalette = (encoded>>shift) & mask;
|
||||
|
||||
data[offset] = palette[indexInPalette * 4];
|
||||
data[offset + 1] = palette[indexInPalette * 4 + 1];
|
||||
data[offset + 2] = palette[indexInPalette * 4 + 2];
|
||||
data[offset + 3] = palette[indexInPalette * 4 + 3];
|
||||
offset += 4;
|
||||
shift-=bitsPerPixel;
|
||||
}
|
||||
if (shift<8-bitsPerPixel && y<tileh-1) {
|
||||
encoded = this._inflator.inflate(1)[0];
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
_decodeRLETile(tileSize) {
|
||||
const data = this._tileBuffer;
|
||||
let i = 0;
|
||||
while (i < tileSize) {
|
||||
const pixel = this._readPixels(1);
|
||||
const length = this._readRLELength();
|
||||
for (let j = 0; j < length; j++) {
|
||||
data[i * 4] = pixel[0];
|
||||
data[i * 4 + 1] = pixel[1];
|
||||
data[i * 4 + 2] = pixel[2];
|
||||
data[i * 4 + 3] = pixel[3];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
_decodeRLEPaletteTile(paletteSize, tileSize) {
|
||||
const data = this._tileBuffer;
|
||||
|
||||
// palette
|
||||
const palette = this._readPixels(paletteSize);
|
||||
|
||||
let offset = 0;
|
||||
while (offset < tileSize) {
|
||||
let indexInPalette = this._inflator.inflate(1)[0];
|
||||
let length = 1;
|
||||
if (indexInPalette >= 128) {
|
||||
indexInPalette -= 128;
|
||||
length = this._readRLELength();
|
||||
}
|
||||
if (indexInPalette > paletteSize) {
|
||||
throw new Error('Too big index in palette: ' + indexInPalette + ', palette size: ' + paletteSize);
|
||||
}
|
||||
if (offset + length > tileSize) {
|
||||
throw new Error('Too big rle length in palette mode: ' + length + ', allowed length is: ' + (tileSize - offset));
|
||||
}
|
||||
|
||||
for (let j = 0; j < length; j++) {
|
||||
data[offset * 4] = palette[indexInPalette * 4];
|
||||
data[offset * 4 + 1] = palette[indexInPalette * 4 + 1];
|
||||
data[offset * 4 + 2] = palette[indexInPalette * 4 + 2];
|
||||
data[offset * 4 + 3] = palette[indexInPalette * 4 + 3];
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
_readRLELength() {
|
||||
let length = 0;
|
||||
let current = 0;
|
||||
do {
|
||||
current = this._inflator.inflate(1)[0];
|
||||
length += current;
|
||||
} while (current === 255);
|
||||
return length + 1;
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2020 The noVNC authors
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*/
|
||||
|
||||
import { deflateInit, deflate } from "../vendor/pako/lib/zlib/deflate.js";
|
||||
import { Z_FULL_FLUSH, Z_DEFAULT_COMPRESSION } from "../vendor/pako/lib/zlib/deflate.js";
|
||||
import ZStream from "../vendor/pako/lib/zlib/zstream.js";
|
||||
|
||||
export default class Deflator {
|
||||
constructor() {
|
||||
this.strm = new ZStream();
|
||||
this.chunkSize = 1024 * 10 * 10;
|
||||
this.outputBuffer = new Uint8Array(this.chunkSize);
|
||||
|
||||
deflateInit(this.strm, Z_DEFAULT_COMPRESSION);
|
||||
}
|
||||
|
||||
deflate(inData) {
|
||||
/* eslint-disable camelcase */
|
||||
this.strm.input = inData;
|
||||
this.strm.avail_in = this.strm.input.length;
|
||||
this.strm.next_in = 0;
|
||||
this.strm.output = this.outputBuffer;
|
||||
this.strm.avail_out = this.chunkSize;
|
||||
this.strm.next_out = 0;
|
||||
/* eslint-enable camelcase */
|
||||
|
||||
let lastRet = deflate(this.strm, Z_FULL_FLUSH);
|
||||
let outData = new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out);
|
||||
|
||||
if (lastRet < 0) {
|
||||
throw new Error("zlib deflate failed");
|
||||
}
|
||||
|
||||
if (this.strm.avail_in > 0) {
|
||||
// Read chunks until done
|
||||
|
||||
let chunks = [outData];
|
||||
let totalLen = outData.length;
|
||||
do {
|
||||
/* eslint-disable camelcase */
|
||||
this.strm.output = new Uint8Array(this.chunkSize);
|
||||
this.strm.next_out = 0;
|
||||
this.strm.avail_out = this.chunkSize;
|
||||
/* eslint-enable camelcase */
|
||||
|
||||
lastRet = deflate(this.strm, Z_FULL_FLUSH);
|
||||
|
||||
if (lastRet < 0) {
|
||||
throw new Error("zlib deflate failed");
|
||||
}
|
||||
|
||||
let chunk = new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out);
|
||||
totalLen += chunk.length;
|
||||
chunks.push(chunk);
|
||||
} while (this.strm.avail_in > 0);
|
||||
|
||||
// Combine chunks into a single data
|
||||
|
||||
let newData = new Uint8Array(totalLen);
|
||||
let offset = 0;
|
||||
|
||||
for (let i = 0; i < chunks.length; i++) {
|
||||
newData.set(chunks[i], offset);
|
||||
offset += chunks[i].length;
|
||||
}
|
||||
|
||||
outData = newData;
|
||||
}
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
this.strm.input = null;
|
||||
this.strm.avail_in = 0;
|
||||
this.strm.next_in = 0;
|
||||
/* eslint-enable camelcase */
|
||||
|
||||
return outData;
|
||||
}
|
||||
|
||||
}
|
||||
+575
@@ -0,0 +1,575 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2019 The noVNC authors
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*/
|
||||
|
||||
import * as Log from './util/logging.js';
|
||||
import Base64 from "./base64.js";
|
||||
import { toSigned32bit } from './util/int.js';
|
||||
|
||||
export default class Display {
|
||||
constructor(target) {
|
||||
this._drawCtx = null;
|
||||
|
||||
this._renderQ = []; // queue drawing actions for in-oder rendering
|
||||
this._flushPromise = null;
|
||||
|
||||
// the full frame buffer (logical canvas) size
|
||||
this._fbWidth = 0;
|
||||
this._fbHeight = 0;
|
||||
|
||||
this._prevDrawStyle = "";
|
||||
|
||||
Log.Debug(">> Display.constructor");
|
||||
|
||||
// The visible canvas
|
||||
this._target = target;
|
||||
|
||||
if (!this._target) {
|
||||
throw new Error("Target must be set");
|
||||
}
|
||||
|
||||
if (typeof this._target === 'string') {
|
||||
throw new Error('target must be a DOM element');
|
||||
}
|
||||
|
||||
if (!this._target.getContext) {
|
||||
throw new Error("no getContext method");
|
||||
}
|
||||
|
||||
this._targetCtx = this._target.getContext('2d');
|
||||
|
||||
// the visible canvas viewport (i.e. what actually gets seen)
|
||||
this._viewportLoc = { 'x': 0, 'y': 0, 'w': this._target.width, 'h': this._target.height };
|
||||
|
||||
// The hidden canvas, where we do the actual rendering
|
||||
this._backbuffer = document.createElement('canvas');
|
||||
this._drawCtx = this._backbuffer.getContext('2d');
|
||||
|
||||
this._damageBounds = { left: 0, top: 0,
|
||||
right: this._backbuffer.width,
|
||||
bottom: this._backbuffer.height };
|
||||
|
||||
Log.Debug("User Agent: " + navigator.userAgent);
|
||||
|
||||
Log.Debug("<< Display.constructor");
|
||||
|
||||
// ===== PROPERTIES =====
|
||||
|
||||
this._scale = 1.0;
|
||||
this._clipViewport = false;
|
||||
}
|
||||
|
||||
// ===== PROPERTIES =====
|
||||
|
||||
get scale() { return this._scale; }
|
||||
set scale(scale) {
|
||||
this._rescale(scale);
|
||||
}
|
||||
|
||||
get clipViewport() { return this._clipViewport; }
|
||||
set clipViewport(viewport) {
|
||||
this._clipViewport = viewport;
|
||||
// May need to readjust the viewport dimensions
|
||||
const vp = this._viewportLoc;
|
||||
this.viewportChangeSize(vp.w, vp.h);
|
||||
this.viewportChangePos(0, 0);
|
||||
}
|
||||
|
||||
get width() {
|
||||
return this._fbWidth;
|
||||
}
|
||||
|
||||
get height() {
|
||||
return this._fbHeight;
|
||||
}
|
||||
|
||||
// ===== PUBLIC METHODS =====
|
||||
|
||||
viewportChangePos(deltaX, deltaY) {
|
||||
const vp = this._viewportLoc;
|
||||
deltaX = Math.floor(deltaX);
|
||||
deltaY = Math.floor(deltaY);
|
||||
|
||||
if (!this._clipViewport) {
|
||||
deltaX = -vp.w; // clamped later of out of bounds
|
||||
deltaY = -vp.h;
|
||||
}
|
||||
|
||||
const vx2 = vp.x + vp.w - 1;
|
||||
const vy2 = vp.y + vp.h - 1;
|
||||
|
||||
// Position change
|
||||
|
||||
if (deltaX < 0 && vp.x + deltaX < 0) {
|
||||
deltaX = -vp.x;
|
||||
}
|
||||
if (vx2 + deltaX >= this._fbWidth) {
|
||||
deltaX -= vx2 + deltaX - this._fbWidth + 1;
|
||||
}
|
||||
|
||||
if (vp.y + deltaY < 0) {
|
||||
deltaY = -vp.y;
|
||||
}
|
||||
if (vy2 + deltaY >= this._fbHeight) {
|
||||
deltaY -= (vy2 + deltaY - this._fbHeight + 1);
|
||||
}
|
||||
|
||||
if (deltaX === 0 && deltaY === 0) {
|
||||
return;
|
||||
}
|
||||
Log.Debug("viewportChange deltaX: " + deltaX + ", deltaY: " + deltaY);
|
||||
|
||||
vp.x += deltaX;
|
||||
vp.y += deltaY;
|
||||
|
||||
this._damage(vp.x, vp.y, vp.w, vp.h);
|
||||
|
||||
this.flip();
|
||||
}
|
||||
|
||||
viewportChangeSize(width, height) {
|
||||
|
||||
if (!this._clipViewport ||
|
||||
typeof(width) === "undefined" ||
|
||||
typeof(height) === "undefined") {
|
||||
|
||||
Log.Debug("Setting viewport to full display region");
|
||||
width = this._fbWidth;
|
||||
height = this._fbHeight;
|
||||
}
|
||||
|
||||
width = Math.floor(width);
|
||||
height = Math.floor(height);
|
||||
|
||||
if (width > this._fbWidth) {
|
||||
width = this._fbWidth;
|
||||
}
|
||||
if (height > this._fbHeight) {
|
||||
height = this._fbHeight;
|
||||
}
|
||||
|
||||
const vp = this._viewportLoc;
|
||||
if (vp.w !== width || vp.h !== height) {
|
||||
vp.w = width;
|
||||
vp.h = height;
|
||||
|
||||
const canvas = this._target;
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
|
||||
// The position might need to be updated if we've grown
|
||||
this.viewportChangePos(0, 0);
|
||||
|
||||
this._damage(vp.x, vp.y, vp.w, vp.h);
|
||||
this.flip();
|
||||
|
||||
// Update the visible size of the target canvas
|
||||
this._rescale(this._scale);
|
||||
}
|
||||
}
|
||||
|
||||
absX(x) {
|
||||
if (this._scale === 0) {
|
||||
return 0;
|
||||
}
|
||||
return toSigned32bit(x / this._scale + this._viewportLoc.x);
|
||||
}
|
||||
|
||||
absY(y) {
|
||||
if (this._scale === 0) {
|
||||
return 0;
|
||||
}
|
||||
return toSigned32bit(y / this._scale + this._viewportLoc.y);
|
||||
}
|
||||
|
||||
resize(width, height) {
|
||||
this._prevDrawStyle = "";
|
||||
|
||||
this._fbWidth = width;
|
||||
this._fbHeight = height;
|
||||
|
||||
const canvas = this._backbuffer;
|
||||
if (canvas.width !== width || canvas.height !== height) {
|
||||
|
||||
// We have to save the canvas data since changing the size will clear it
|
||||
let saveImg = null;
|
||||
if (canvas.width > 0 && canvas.height > 0) {
|
||||
saveImg = this._drawCtx.getImageData(0, 0, canvas.width, canvas.height);
|
||||
}
|
||||
|
||||
if (canvas.width !== width) {
|
||||
canvas.width = width;
|
||||
}
|
||||
if (canvas.height !== height) {
|
||||
canvas.height = height;
|
||||
}
|
||||
|
||||
if (saveImg) {
|
||||
this._drawCtx.putImageData(saveImg, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Readjust the viewport as it may be incorrectly sized
|
||||
// and positioned
|
||||
const vp = this._viewportLoc;
|
||||
this.viewportChangeSize(vp.w, vp.h);
|
||||
this.viewportChangePos(0, 0);
|
||||
}
|
||||
|
||||
getImageData() {
|
||||
return this._drawCtx.getImageData(0, 0, this.width, this.height);
|
||||
}
|
||||
|
||||
toDataURL(type, encoderOptions) {
|
||||
return this._backbuffer.toDataURL(type, encoderOptions);
|
||||
}
|
||||
|
||||
toBlob(callback, type, quality) {
|
||||
return this._backbuffer.toBlob(callback, type, quality);
|
||||
}
|
||||
|
||||
// Track what parts of the visible canvas that need updating
|
||||
_damage(x, y, w, h) {
|
||||
if (x < this._damageBounds.left) {
|
||||
this._damageBounds.left = x;
|
||||
}
|
||||
if (y < this._damageBounds.top) {
|
||||
this._damageBounds.top = y;
|
||||
}
|
||||
if ((x + w) > this._damageBounds.right) {
|
||||
this._damageBounds.right = x + w;
|
||||
}
|
||||
if ((y + h) > this._damageBounds.bottom) {
|
||||
this._damageBounds.bottom = y + h;
|
||||
}
|
||||
}
|
||||
|
||||
// Update the visible canvas with the contents of the
|
||||
// rendering canvas
|
||||
flip(fromQueue) {
|
||||
if (this._renderQ.length !== 0 && !fromQueue) {
|
||||
this._renderQPush({
|
||||
'type': 'flip'
|
||||
});
|
||||
} else {
|
||||
let x = this._damageBounds.left;
|
||||
let y = this._damageBounds.top;
|
||||
let w = this._damageBounds.right - x;
|
||||
let h = this._damageBounds.bottom - y;
|
||||
|
||||
let vx = x - this._viewportLoc.x;
|
||||
let vy = y - this._viewportLoc.y;
|
||||
|
||||
if (vx < 0) {
|
||||
w += vx;
|
||||
x -= vx;
|
||||
vx = 0;
|
||||
}
|
||||
if (vy < 0) {
|
||||
h += vy;
|
||||
y -= vy;
|
||||
vy = 0;
|
||||
}
|
||||
|
||||
if ((vx + w) > this._viewportLoc.w) {
|
||||
w = this._viewportLoc.w - vx;
|
||||
}
|
||||
if ((vy + h) > this._viewportLoc.h) {
|
||||
h = this._viewportLoc.h - vy;
|
||||
}
|
||||
|
||||
if ((w > 0) && (h > 0)) {
|
||||
// FIXME: We may need to disable image smoothing here
|
||||
// as well (see copyImage()), but we haven't
|
||||
// noticed any problem yet.
|
||||
this._targetCtx.drawImage(this._backbuffer,
|
||||
x, y, w, h,
|
||||
vx, vy, w, h);
|
||||
}
|
||||
|
||||
this._damageBounds.left = this._damageBounds.top = 65535;
|
||||
this._damageBounds.right = this._damageBounds.bottom = 0;
|
||||
}
|
||||
}
|
||||
|
||||
pending() {
|
||||
return this._renderQ.length > 0;
|
||||
}
|
||||
|
||||
flush() {
|
||||
if (this._renderQ.length === 0) {
|
||||
return Promise.resolve();
|
||||
} else {
|
||||
if (this._flushPromise === null) {
|
||||
this._flushPromise = new Promise((resolve) => {
|
||||
this._flushResolve = resolve;
|
||||
});
|
||||
}
|
||||
return this._flushPromise;
|
||||
}
|
||||
}
|
||||
|
||||
fillRect(x, y, width, height, color, fromQueue) {
|
||||
if (this._renderQ.length !== 0 && !fromQueue) {
|
||||
this._renderQPush({
|
||||
'type': 'fill',
|
||||
'x': x,
|
||||
'y': y,
|
||||
'width': width,
|
||||
'height': height,
|
||||
'color': color
|
||||
});
|
||||
} else {
|
||||
this._setFillColor(color);
|
||||
this._drawCtx.fillRect(x, y, width, height);
|
||||
this._damage(x, y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
copyImage(oldX, oldY, newX, newY, w, h, fromQueue) {
|
||||
if (this._renderQ.length !== 0 && !fromQueue) {
|
||||
this._renderQPush({
|
||||
'type': 'copy',
|
||||
'oldX': oldX,
|
||||
'oldY': oldY,
|
||||
'x': newX,
|
||||
'y': newY,
|
||||
'width': w,
|
||||
'height': h,
|
||||
});
|
||||
} else {
|
||||
// Due to this bug among others [1] we need to disable the image-smoothing to
|
||||
// avoid getting a blur effect when copying data.
|
||||
//
|
||||
// 1. https://bugzilla.mozilla.org/show_bug.cgi?id=1194719
|
||||
//
|
||||
// We need to set these every time since all properties are reset
|
||||
// when the the size is changed
|
||||
this._drawCtx.mozImageSmoothingEnabled = false;
|
||||
this._drawCtx.webkitImageSmoothingEnabled = false;
|
||||
this._drawCtx.msImageSmoothingEnabled = false;
|
||||
this._drawCtx.imageSmoothingEnabled = false;
|
||||
|
||||
this._drawCtx.drawImage(this._backbuffer,
|
||||
oldX, oldY, w, h,
|
||||
newX, newY, w, h);
|
||||
this._damage(newX, newY, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
imageRect(x, y, width, height, mime, arr) {
|
||||
/* The internal logic cannot handle empty images, so bail early */
|
||||
if ((width === 0) || (height === 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const img = new Image();
|
||||
img.src = "data: " + mime + ";base64," + Base64.encode(arr);
|
||||
|
||||
this._renderQPush({
|
||||
'type': 'img',
|
||||
'img': img,
|
||||
'x': x,
|
||||
'y': y,
|
||||
'width': width,
|
||||
'height': height
|
||||
});
|
||||
}
|
||||
|
||||
videoFrame(x, y, width, height, frame) {
|
||||
this._renderQPush({
|
||||
'type': 'frame',
|
||||
'frame': frame,
|
||||
'x': x,
|
||||
'y': y,
|
||||
'width': width,
|
||||
'height': height
|
||||
});
|
||||
}
|
||||
|
||||
blitImage(x, y, width, height, arr, offset, fromQueue) {
|
||||
if (this._renderQ.length !== 0 && !fromQueue) {
|
||||
// NB(directxman12): it's technically more performant here to use preallocated arrays,
|
||||
// but it's a lot of extra work for not a lot of payoff -- if we're using the render queue,
|
||||
// this probably isn't getting called *nearly* as much
|
||||
const newArr = new Uint8Array(width * height * 4);
|
||||
newArr.set(new Uint8Array(arr.buffer, 0, newArr.length));
|
||||
this._renderQPush({
|
||||
'type': 'blit',
|
||||
'data': newArr,
|
||||
'x': x,
|
||||
'y': y,
|
||||
'width': width,
|
||||
'height': height,
|
||||
});
|
||||
} else {
|
||||
// NB(directxman12): arr must be an Type Array view
|
||||
let data = new Uint8ClampedArray(arr.buffer,
|
||||
arr.byteOffset + offset,
|
||||
width * height * 4);
|
||||
let img = new ImageData(data, width, height);
|
||||
this._drawCtx.putImageData(img, x, y);
|
||||
this._damage(x, y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
drawImage(img, ...args) {
|
||||
this._drawCtx.drawImage(img, ...args);
|
||||
|
||||
if (args.length <= 4) {
|
||||
const [x, y] = args;
|
||||
this._damage(x, y, img.width, img.height);
|
||||
} else {
|
||||
const [,, sw, sh, dx, dy] = args;
|
||||
this._damage(dx, dy, sw, sh);
|
||||
}
|
||||
}
|
||||
|
||||
autoscale(containerWidth, containerHeight) {
|
||||
let scaleRatio;
|
||||
|
||||
if (containerWidth === 0 || containerHeight === 0) {
|
||||
scaleRatio = 0;
|
||||
|
||||
} else {
|
||||
|
||||
const vp = this._viewportLoc;
|
||||
const targetAspectRatio = containerWidth / containerHeight;
|
||||
const fbAspectRatio = vp.w / vp.h;
|
||||
|
||||
if (fbAspectRatio >= targetAspectRatio) {
|
||||
scaleRatio = containerWidth / vp.w;
|
||||
} else {
|
||||
scaleRatio = containerHeight / vp.h;
|
||||
}
|
||||
}
|
||||
|
||||
this._rescale(scaleRatio);
|
||||
}
|
||||
|
||||
// ===== PRIVATE METHODS =====
|
||||
|
||||
_rescale(factor) {
|
||||
this._scale = factor;
|
||||
const vp = this._viewportLoc;
|
||||
|
||||
// NB(directxman12): If you set the width directly, or set the
|
||||
// style width to a number, the canvas is cleared.
|
||||
// However, if you set the style width to a string
|
||||
// ('NNNpx'), the canvas is scaled without clearing.
|
||||
const width = factor * vp.w + 'px';
|
||||
const height = factor * vp.h + 'px';
|
||||
|
||||
if ((this._target.style.width !== width) ||
|
||||
(this._target.style.height !== height)) {
|
||||
this._target.style.width = width;
|
||||
this._target.style.height = height;
|
||||
}
|
||||
}
|
||||
|
||||
_setFillColor(color) {
|
||||
const newStyle = 'rgb(' + color[0] + ',' + color[1] + ',' + color[2] + ')';
|
||||
if (newStyle !== this._prevDrawStyle) {
|
||||
this._drawCtx.fillStyle = newStyle;
|
||||
this._prevDrawStyle = newStyle;
|
||||
}
|
||||
}
|
||||
|
||||
_renderQPush(action) {
|
||||
this._renderQ.push(action);
|
||||
if (this._renderQ.length === 1) {
|
||||
// If this can be rendered immediately it will be, otherwise
|
||||
// the scanner will wait for the relevant event
|
||||
this._scanRenderQ();
|
||||
}
|
||||
}
|
||||
|
||||
_resumeRenderQ() {
|
||||
// "this" is the object that is ready, not the
|
||||
// display object
|
||||
this.removeEventListener('load', this._noVNCDisplay._resumeRenderQ);
|
||||
this._noVNCDisplay._scanRenderQ();
|
||||
}
|
||||
|
||||
_scanRenderQ() {
|
||||
let ready = true;
|
||||
while (ready && this._renderQ.length > 0) {
|
||||
const a = this._renderQ[0];
|
||||
switch (a.type) {
|
||||
case 'flip':
|
||||
this.flip(true);
|
||||
break;
|
||||
case 'copy':
|
||||
this.copyImage(a.oldX, a.oldY, a.x, a.y, a.width, a.height, true);
|
||||
break;
|
||||
case 'fill':
|
||||
this.fillRect(a.x, a.y, a.width, a.height, a.color, true);
|
||||
break;
|
||||
case 'blit':
|
||||
this.blitImage(a.x, a.y, a.width, a.height, a.data, 0, true);
|
||||
break;
|
||||
case 'img':
|
||||
if (a.img.complete) {
|
||||
if (a.img.width !== a.width || a.img.height !== a.height) {
|
||||
Log.Error("Decoded image has incorrect dimensions. Got " +
|
||||
a.img.width + "x" + a.img.height + ". Expected " +
|
||||
a.width + "x" + a.height + ".");
|
||||
return;
|
||||
}
|
||||
this.drawImage(a.img, a.x, a.y);
|
||||
} else {
|
||||
a.img._noVNCDisplay = this;
|
||||
a.img.addEventListener('load', this._resumeRenderQ);
|
||||
// We need to wait for this image to 'load'
|
||||
// to keep things in-order
|
||||
ready = false;
|
||||
}
|
||||
break;
|
||||
case 'frame':
|
||||
if (a.frame.ready) {
|
||||
// The encoded frame may be larger than the rect due to
|
||||
// limitations of the encoder, so we need to crop the
|
||||
// frame.
|
||||
let frame = a.frame.frame;
|
||||
if (frame.codedWidth < a.width || frame.codedHeight < a.height) {
|
||||
Log.Warn("Decoded video frame does not cover its full rectangle area. Expecting at least " +
|
||||
a.width + "x" + a.height + " but got " +
|
||||
frame.codedWidth + "x" + frame.codedHeight);
|
||||
}
|
||||
const sx = 0;
|
||||
const sy = 0;
|
||||
const sw = a.width;
|
||||
const sh = a.height;
|
||||
const dx = a.x;
|
||||
const dy = a.y;
|
||||
const dw = sw;
|
||||
const dh = sh;
|
||||
this.drawImage(frame, sx, sy, sw, sh, dx, dy, dw, dh);
|
||||
frame.close();
|
||||
} else {
|
||||
let display = this;
|
||||
a.frame.promise.then(() => {
|
||||
display._scanRenderQ();
|
||||
});
|
||||
ready = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (ready) {
|
||||
this._renderQ.shift();
|
||||
}
|
||||
}
|
||||
|
||||
if (this._renderQ.length === 0 &&
|
||||
this._flushPromise !== null) {
|
||||
this._flushResolve();
|
||||
this._flushPromise = null;
|
||||
this._flushResolve = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2019 The noVNC authors
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*/
|
||||
|
||||
export const encodings = {
|
||||
encodingRaw: 0,
|
||||
encodingCopyRect: 1,
|
||||
encodingRRE: 2,
|
||||
encodingHextile: 5,
|
||||
encodingZlib: 6,
|
||||
encodingTight: 7,
|
||||
encodingZRLE: 16,
|
||||
encodingTightPNG: -260,
|
||||
encodingJPEG: 21,
|
||||
encodingH264: 50,
|
||||
|
||||
pseudoEncodingQualityLevel9: -23,
|
||||
pseudoEncodingQualityLevel0: -32,
|
||||
pseudoEncodingDesktopSize: -223,
|
||||
pseudoEncodingLastRect: -224,
|
||||
pseudoEncodingCursor: -239,
|
||||
pseudoEncodingQEMUExtendedKeyEvent: -258,
|
||||
pseudoEncodingQEMULedEvent: -261,
|
||||
pseudoEncodingDesktopName: -307,
|
||||
pseudoEncodingExtendedDesktopSize: -308,
|
||||
pseudoEncodingXvp: -309,
|
||||
pseudoEncodingFence: -312,
|
||||
pseudoEncodingContinuousUpdates: -313,
|
||||
pseudoEncodingExtendedMouseButtons: -316,
|
||||
pseudoEncodingCompressLevel9: -247,
|
||||
pseudoEncodingCompressLevel0: -256,
|
||||
pseudoEncodingVMwareCursor: 0x574d5664,
|
||||
pseudoEncodingExtendedClipboard: 0xc0a1e5ce
|
||||
};
|
||||
|
||||
export function encodingName(num) {
|
||||
switch (num) {
|
||||
case encodings.encodingRaw: return "Raw";
|
||||
case encodings.encodingCopyRect: return "CopyRect";
|
||||
case encodings.encodingRRE: return "RRE";
|
||||
case encodings.encodingHextile: return "Hextile";
|
||||
case encodings.encodingZlib: return "Zlib";
|
||||
case encodings.encodingTight: return "Tight";
|
||||
case encodings.encodingZRLE: return "ZRLE";
|
||||
case encodings.encodingTightPNG: return "TightPNG";
|
||||
case encodings.encodingJPEG: return "JPEG";
|
||||
case encodings.encodingH264: return "H.264";
|
||||
default: return "[unknown encoding " + num + "]";
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2020 The noVNC authors
|
||||
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||
*
|
||||
* See README.md for usage and integration instructions.
|
||||
*/
|
||||
|
||||
import { inflateInit, inflate, inflateReset } from "../vendor/pako/lib/zlib/inflate.js";
|
||||
import ZStream from "../vendor/pako/lib/zlib/zstream.js";
|
||||
|
||||
export default class Inflate {
|
||||
constructor() {
|
||||
this.strm = new ZStream();
|
||||
this.chunkSize = 1024 * 10 * 10;
|
||||
this.strm.output = new Uint8Array(this.chunkSize);
|
||||
|
||||
inflateInit(this.strm);
|
||||
}
|
||||
|
||||
setInput(data) {
|
||||
if (!data) {
|
||||
//FIXME: flush remaining data.
|
||||
/* eslint-disable camelcase */
|
||||
this.strm.input = null;
|
||||
this.strm.avail_in = 0;
|
||||
this.strm.next_in = 0;
|
||||
} else {
|
||||
this.strm.input = data;
|
||||
this.strm.avail_in = this.strm.input.length;
|
||||
this.strm.next_in = 0;
|
||||
/* eslint-enable camelcase */
|
||||
}
|
||||
}
|
||||
|
||||
inflate(expected) {
|
||||
// resize our output buffer if it's too small
|
||||
// (we could just use multiple chunks, but that would cause an extra
|
||||
// allocation each time to flatten the chunks)
|
||||
if (expected > this.chunkSize) {
|
||||
this.chunkSize = expected;
|
||||
this.strm.output = new Uint8Array(this.chunkSize);
|
||||
}
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
this.strm.next_out = 0;
|
||||
this.strm.avail_out = expected;
|
||||
/* eslint-enable camelcase */
|
||||
|
||||
let ret = inflate(this.strm, 0); // Flush argument not used.
|
||||
if (ret < 0) {
|
||||
throw new Error("zlib inflate failed");
|
||||
}
|
||||
|
||||
if (this.strm.next_out != expected) {
|
||||
throw new Error("Incomplete zlib block");
|
||||
}
|
||||
|
||||
return new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out);
|
||||
}
|
||||
|
||||
reset() {
|
||||
inflateReset(this.strm);
|
||||
}
|
||||
}
|
||||
+311
@@ -0,0 +1,311 @@
|
||||
/*
|
||||
* noVNC: HTML5 VNC client
|
||||
* Copyright (C) 2018 The noVNC authors
|
||||
* Licensed under MPL 2.0 or any later version (see LICENSE.txt)
|
||||
*/
|
||||
|
||||
import KeyTable from "./keysym.js";
|
||||
|
||||
/*
|
||||
* Mapping between HTML key values and VNC/X11 keysyms for "special"
|
||||
* keys that cannot be handled via their Unicode codepoint.
|
||||
*
|
||||
* See https://www.w3.org/TR/uievents-key/ for possible values.
|
||||
*/
|
||||
|
||||
const DOMKeyTable = {};
|
||||
|
||||
function addStandard(key, standard) {
|
||||
if (standard === undefined) throw new Error("Undefined keysym for key \"" + key + "\"");
|
||||
if (key in DOMKeyTable) throw new Error("Duplicate entry for key \"" + key + "\"");
|
||||
DOMKeyTable[key] = [standard, standard, standard, standard];
|
||||
}
|
||||
|
||||
function addLeftRight(key, left, right) {
|
||||
if (left === undefined) throw new Error("Undefined keysym for key \"" + key + "\"");
|
||||
if (right === undefined) throw new Error("Undefined keysym for key \"" + key + "\"");
|
||||
if (key in DOMKeyTable) throw new Error("Duplicate entry for key \"" + key + "\"");
|
||||
DOMKeyTable[key] = [left, left, right, left];
|
||||
}
|
||||
|
||||
function addNumpad(key, standard, numpad) {
|
||||
if (standard === undefined) throw new Error("Undefined keysym for key \"" + key + "\"");
|
||||
if (numpad === undefined) throw new Error("Undefined keysym for key \"" + key + "\"");
|
||||
if (key in DOMKeyTable) throw new Error("Duplicate entry for key \"" + key + "\"");
|
||||
DOMKeyTable[key] = [standard, standard, standard, numpad];
|
||||
}
|
||||
|
||||
// 3.2. Modifier Keys
|
||||
|
||||
addLeftRight("Alt", KeyTable.XK_Alt_L, KeyTable.XK_Alt_R);
|
||||
addStandard("AltGraph", KeyTable.XK_ISO_Level3_Shift);
|
||||
addStandard("CapsLock", KeyTable.XK_Caps_Lock);
|
||||
addLeftRight("Control", KeyTable.XK_Control_L, KeyTable.XK_Control_R);
|
||||
// - Fn
|
||||
// - FnLock
|
||||
addLeftRight("Meta", KeyTable.XK_Super_L, KeyTable.XK_Super_R);
|
||||
addStandard("NumLock", KeyTable.XK_Num_Lock);
|
||||
addStandard("ScrollLock", KeyTable.XK_Scroll_Lock);
|
||||
addLeftRight("Shift", KeyTable.XK_Shift_L, KeyTable.XK_Shift_R);
|
||||
// - Symbol
|
||||
// - SymbolLock
|
||||
// - Hyper
|
||||
// - Super
|
||||
|
||||
// 3.3. Whitespace Keys
|
||||
|
||||
addNumpad("Enter", KeyTable.XK_Return, KeyTable.XK_KP_Enter);
|
||||
addStandard("Tab", KeyTable.XK_Tab);
|
||||
addNumpad(" ", KeyTable.XK_space, KeyTable.XK_KP_Space);
|
||||
|
||||
// 3.4. Navigation Keys
|
||||
|
||||
addNumpad("ArrowDown", KeyTable.XK_Down, KeyTable.XK_KP_Down);
|
||||
addNumpad("ArrowLeft", KeyTable.XK_Left, KeyTable.XK_KP_Left);
|
||||
addNumpad("ArrowRight", KeyTable.XK_Right, KeyTable.XK_KP_Right);
|
||||
addNumpad("ArrowUp", KeyTable.XK_Up, KeyTable.XK_KP_Up);
|
||||
addNumpad("End", KeyTable.XK_End, KeyTable.XK_KP_End);
|
||||
addNumpad("Home", KeyTable.XK_Home, KeyTable.XK_KP_Home);
|
||||
addNumpad("PageDown", KeyTable.XK_Next, KeyTable.XK_KP_Next);
|
||||
addNumpad("PageUp", KeyTable.XK_Prior, KeyTable.XK_KP_Prior);
|
||||
|
||||
// 3.5. Editing Keys
|
||||
|
||||
addStandard("Backspace", KeyTable.XK_BackSpace);
|
||||
// Browsers send "Clear" for the numpad 5 without NumLock because
|
||||
// Windows uses VK_Clear for that key. But Unix expects KP_Begin for
|
||||
// that scenario.
|
||||
addNumpad("Clear", KeyTable.XK_Clear, KeyTable.XK_KP_Begin);
|
||||
addStandard("Copy", KeyTable.XF86XK_Copy);
|
||||
// - CrSel
|
||||
addStandard("Cut", KeyTable.XF86XK_Cut);
|
||||
addNumpad("Delete", KeyTable.XK_Delete, KeyTable.XK_KP_Delete);
|
||||
// - EraseEof
|
||||
// - ExSel
|
||||
addNumpad("Insert", KeyTable.XK_Insert, KeyTable.XK_KP_Insert);
|
||||
addStandard("Paste", KeyTable.XF86XK_Paste);
|
||||
addStandard("Redo", KeyTable.XK_Redo);
|
||||
addStandard("Undo", KeyTable.XK_Undo);
|
||||
|
||||
// 3.6. UI Keys
|
||||
|
||||
// - Accept
|
||||
// - Again (could just be XK_Redo)
|
||||
// - Attn
|
||||
addStandard("Cancel", KeyTable.XK_Cancel);
|
||||
addStandard("ContextMenu", KeyTable.XK_Menu);
|
||||
addStandard("Escape", KeyTable.XK_Escape);
|
||||
addStandard("Execute", KeyTable.XK_Execute);
|
||||
addStandard("Find", KeyTable.XK_Find);
|
||||
addStandard("Help", KeyTable.XK_Help);
|
||||
addStandard("Pause", KeyTable.XK_Pause);
|
||||
// - Play
|
||||
// - Props
|
||||
addStandard("Select", KeyTable.XK_Select);
|
||||
addStandard("ZoomIn", KeyTable.XF86XK_ZoomIn);
|
||||
addStandard("ZoomOut", KeyTable.XF86XK_ZoomOut);
|
||||
|
||||
// 3.7. Device Keys
|
||||
|
||||
addStandard("BrightnessDown", KeyTable.XF86XK_MonBrightnessDown);
|
||||
addStandard("BrightnessUp", KeyTable.XF86XK_MonBrightnessUp);
|
||||
addStandard("Eject", KeyTable.XF86XK_Eject);
|
||||
addStandard("LogOff", KeyTable.XF86XK_LogOff);
|
||||
addStandard("Power", KeyTable.XF86XK_PowerOff);
|
||||
addStandard("PowerOff", KeyTable.XF86XK_PowerDown);
|
||||
addStandard("PrintScreen", KeyTable.XK_Print);
|
||||
addStandard("Hibernate", KeyTable.XF86XK_Hibernate);
|
||||
addStandard("Standby", KeyTable.XF86XK_Standby);
|
||||
addStandard("WakeUp", KeyTable.XF86XK_WakeUp);
|
||||
|
||||
// 3.8. IME and Composition Keys
|
||||
|
||||
addStandard("AllCandidates", KeyTable.XK_MultipleCandidate);
|
||||
addStandard("Alphanumeric", KeyTable.XK_Eisu_toggle);
|
||||
addStandard("CodeInput", KeyTable.XK_Codeinput);
|
||||
addStandard("Compose", KeyTable.XK_Multi_key);
|
||||
addStandard("Convert", KeyTable.XK_Henkan);
|
||||
// - Dead
|
||||
// - FinalMode
|
||||
addStandard("GroupFirst", KeyTable.XK_ISO_First_Group);
|
||||
addStandard("GroupLast", KeyTable.XK_ISO_Last_Group);
|
||||
addStandard("GroupNext", KeyTable.XK_ISO_Next_Group);
|
||||
addStandard("GroupPrevious", KeyTable.XK_ISO_Prev_Group);
|
||||
// - ModeChange (XK_Mode_switch is often used for AltGr)
|
||||
// - NextCandidate
|
||||
addStandard("NonConvert", KeyTable.XK_Muhenkan);
|
||||
addStandard("PreviousCandidate", KeyTable.XK_PreviousCandidate);
|
||||
// - Process
|
||||
addStandard("SingleCandidate", KeyTable.XK_SingleCandidate);
|
||||
addStandard("HangulMode", KeyTable.XK_Hangul);
|
||||
addStandard("HanjaMode", KeyTable.XK_Hangul_Hanja);
|
||||
addStandard("JunjaMode", KeyTable.XK_Hangul_Jeonja);
|
||||
addStandard("Eisu", KeyTable.XK_Eisu_toggle);
|
||||
addStandard("Hankaku", KeyTable.XK_Hankaku);
|
||||
addStandard("Hiragana", KeyTable.XK_Hiragana);
|
||||
addStandard("HiraganaKatakana", KeyTable.XK_Hiragana_Katakana);
|
||||
addStandard("KanaMode", KeyTable.XK_Kana_Shift); // could also be _Kana_Lock
|
||||
addStandard("KanjiMode", KeyTable.XK_Kanji);
|
||||
addStandard("Katakana", KeyTable.XK_Katakana);
|
||||
addStandard("Romaji", KeyTable.XK_Romaji);
|
||||
addStandard("Zenkaku", KeyTable.XK_Zenkaku);
|
||||
addStandard("ZenkakuHankaku", KeyTable.XK_Zenkaku_Hankaku);
|
||||
|
||||
// 3.9. General-Purpose Function Keys
|
||||
|
||||
addStandard("F1", KeyTable.XK_F1);
|
||||
addStandard("F2", KeyTable.XK_F2);
|
||||
addStandard("F3", KeyTable.XK_F3);
|
||||
addStandard("F4", KeyTable.XK_F4);
|
||||
addStandard("F5", KeyTable.XK_F5);
|
||||
addStandard("F6", KeyTable.XK_F6);
|
||||
addStandard("F7", KeyTable.XK_F7);
|
||||
addStandard("F8", KeyTable.XK_F8);
|
||||
addStandard("F9", KeyTable.XK_F9);
|
||||
addStandard("F10", KeyTable.XK_F10);
|
||||
addStandard("F11", KeyTable.XK_F11);
|
||||
addStandard("F12", KeyTable.XK_F12);
|
||||
addStandard("F13", KeyTable.XK_F13);
|
||||
addStandard("F14", KeyTable.XK_F14);
|
||||
addStandard("F15", KeyTable.XK_F15);
|
||||
addStandard("F16", KeyTable.XK_F16);
|
||||
addStandard("F17", KeyTable.XK_F17);
|
||||
addStandard("F18", KeyTable.XK_F18);
|
||||
addStandard("F19", KeyTable.XK_F19);
|
||||
addStandard("F20", KeyTable.XK_F20);
|
||||
addStandard("F21", KeyTable.XK_F21);
|
||||
addStandard("F22", KeyTable.XK_F22);
|
||||
addStandard("F23", KeyTable.XK_F23);
|
||||
addStandard("F24", KeyTable.XK_F24);
|
||||
addStandard("F25", KeyTable.XK_F25);
|
||||
addStandard("F26", KeyTable.XK_F26);
|
||||
addStandard("F27", KeyTable.XK_F27);
|
||||
addStandard("F28", KeyTable.XK_F28);
|
||||
addStandard("F29", KeyTable.XK_F29);
|
||||
addStandard("F30", KeyTable.XK_F30);
|
||||
addStandard("F31", KeyTable.XK_F31);
|
||||
addStandard("F32", KeyTable.XK_F32);
|
||||
addStandard("F33", KeyTable.XK_F33);
|
||||
addStandard("F34", KeyTable.XK_F34);
|
||||
addStandard("F35", KeyTable.XK_F35);
|
||||
// - Soft1...
|
||||
|
||||
// 3.10. Multimedia Keys
|
||||
|
||||
// - ChannelDown
|
||||
// - ChannelUp
|
||||
addStandard("Close", KeyTable.XF86XK_Close);
|
||||
addStandard("MailForward", KeyTable.XF86XK_MailForward);
|
||||
addStandard("MailReply", KeyTable.XF86XK_Reply);
|
||||
addStandard("MailSend", KeyTable.XF86XK_Send);
|
||||
// - MediaClose
|
||||
addStandard("MediaFastForward", KeyTable.XF86XK_AudioForward);
|
||||
addStandard("MediaPause", KeyTable.XF86XK_AudioPause);
|
||||
addStandard("MediaPlay", KeyTable.XF86XK_AudioPlay);
|
||||
// - MediaPlayPause
|
||||
addStandard("MediaRecord", KeyTable.XF86XK_AudioRecord);
|
||||
addStandard("MediaRewind", KeyTable.XF86XK_AudioRewind);
|
||||
addStandard("MediaStop", KeyTable.XF86XK_AudioStop);
|
||||
addStandard("MediaTrackNext", KeyTable.XF86XK_AudioNext);
|
||||
addStandard("MediaTrackPrevious", KeyTable.XF86XK_AudioPrev);
|
||||
addStandard("New", KeyTable.XF86XK_New);
|
||||
addStandard("Open", KeyTable.XF86XK_Open);
|
||||
addStandard("Print", KeyTable.XK_Print);
|
||||
addStandard("Save", KeyTable.XF86XK_Save);
|
||||
addStandard("SpellCheck", KeyTable.XF86XK_Spell);
|
||||
|
||||
// 3.11. Multimedia Numpad Keys
|
||||
|
||||
// - Key11
|
||||
// - Key12
|
||||
|
||||
// 3.12. Audio Keys
|
||||
|
||||
// - AudioBalanceLeft
|
||||
// - AudioBalanceRight
|
||||
// - AudioBassBoostDown
|
||||
// - AudioBassBoostToggle
|
||||
// - AudioBassBoostUp
|
||||
// - AudioFaderFront
|
||||
// - AudioFaderRear
|
||||
// - AudioSurroundModeNext
|
||||
// - AudioTrebleDown
|
||||
// - AudioTrebleUp
|
||||
addStandard("AudioVolumeDown", KeyTable.XF86XK_AudioLowerVolume);
|
||||
addStandard("AudioVolumeUp", KeyTable.XF86XK_AudioRaiseVolume);
|
||||
addStandard("AudioVolumeMute", KeyTable.XF86XK_AudioMute);
|
||||
// - MicrophoneToggle
|
||||
// - MicrophoneVolumeDown
|
||||
// - MicrophoneVolumeUp
|
||||
addStandard("MicrophoneVolumeMute", KeyTable.XF86XK_AudioMicMute);
|
||||
|
||||
// 3.13. Speech Keys
|
||||
|
||||
// - SpeechCorrectionList
|
||||
// - SpeechInputToggle
|
||||
|
||||
// 3.14. Application Keys
|
||||
|
||||
addStandard("LaunchApplication1", KeyTable.XF86XK_MyComputer);
|
||||
addStandard("LaunchApplication2", KeyTable.XF86XK_Calculator);
|
||||
addStandard("LaunchCalendar", KeyTable.XF86XK_Calendar);
|
||||
// - LaunchContacts
|
||||
addStandard("LaunchMail", KeyTable.XF86XK_Mail);
|
||||
addStandard("LaunchMediaPlayer", KeyTable.XF86XK_AudioMedia);
|
||||
addStandard("LaunchMusicPlayer", KeyTable.XF86XK_Music);
|
||||
addStandard("LaunchPhone", KeyTable.XF86XK_Phone);
|
||||
addStandard("LaunchScreenSaver", KeyTable.XF86XK_ScreenSaver);
|
||||
addStandard("LaunchSpreadsheet", KeyTable.XF86XK_Excel);
|
||||
addStandard("LaunchWebBrowser", KeyTable.XF86XK_WWW);
|
||||
addStandard("LaunchWebCam", KeyTable.XF86XK_WebCam);
|
||||
addStandard("LaunchWordProcessor", KeyTable.XF86XK_Word);
|
||||
|
||||
// 3.15. Browser Keys
|
||||
|
||||
addStandard("BrowserBack", KeyTable.XF86XK_Back);
|
||||
addStandard("BrowserFavorites", KeyTable.XF86XK_Favorites);
|
||||
addStandard("BrowserForward", KeyTable.XF86XK_Forward);
|
||||
addStandard("BrowserHome", KeyTable.XF86XK_HomePage);
|
||||
addStandard("BrowserRefresh", KeyTable.XF86XK_Refresh);
|
||||
addStandard("BrowserSearch", KeyTable.XF86XK_Search);
|
||||
addStandard("BrowserStop", KeyTable.XF86XK_Stop);
|
||||
|
||||
// 3.16. Mobile Phone Keys
|
||||
|
||||
// - A whole bunch...
|
||||
|
||||
// 3.17. TV Keys
|
||||
|
||||
// - A whole bunch...
|
||||
|
||||
// 3.18. Media Controller Keys
|
||||
|
||||
// - A whole bunch...
|
||||
addStandard("Dimmer", KeyTable.XF86XK_BrightnessAdjust);
|
||||
addStandard("MediaAudioTrack", KeyTable.XF86XK_AudioCycleTrack);
|
||||
addStandard("RandomToggle", KeyTable.XF86XK_AudioRandomPlay);
|
||||
addStandard("SplitScreenToggle", KeyTable.XF86XK_SplitScreen);
|
||||
addStandard("Subtitle", KeyTable.XF86XK_Subtitle);
|
||||
addStandard("VideoModeNext", KeyTable.XF86XK_Next_VMode);
|
||||
|
||||
// Extra: Numpad
|
||||
|
||||
addNumpad("=", KeyTable.XK_equal, KeyTable.XK_KP_Equal);
|
||||
addNumpad("+", KeyTable.XK_plus, KeyTable.XK_KP_Add);
|
||||
addNumpad("-", KeyTable.XK_minus, KeyTable.XK_KP_Subtract);
|
||||
addNumpad("*", KeyTable.XK_asterisk, KeyTable.XK_KP_Multiply);
|
||||
addNumpad("/", KeyTable.XK_slash, KeyTable.XK_KP_Divide);
|
||||
addNumpad(".", KeyTable.XK_period, KeyTable.XK_KP_Decimal);
|
||||
addNumpad(",", KeyTable.XK_comma, KeyTable.XK_KP_Separator);
|
||||
addNumpad("0", KeyTable.XK_0, KeyTable.XK_KP_0);
|
||||
addNumpad("1", KeyTable.XK_1, KeyTable.XK_KP_1);
|
||||
addNumpad("2", KeyTable.XK_2, KeyTable.XK_KP_2);
|
||||
addNumpad("3", KeyTable.XK_3, KeyTable.XK_KP_3);
|
||||
addNumpad("4", KeyTable.XK_4, KeyTable.XK_KP_4);
|
||||
addNumpad("5", KeyTable.XK_5, KeyTable.XK_KP_5);
|
||||
addNumpad("6", KeyTable.XK_6, KeyTable.XK_KP_6);
|
||||
addNumpad("7", KeyTable.XK_7, KeyTable.XK_KP_7);
|
||||
addNumpad("8", KeyTable.XK_8, KeyTable.XK_KP_8);
|
||||
addNumpad("9", KeyTable.XK_9, KeyTable.XK_KP_9);
|
||||
|
||||
export default DOMKeyTable;
|
||||
Loaded 100 of 170 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user