- Added all seven issued service trees without omissions. - Preserved the supplied runtime configuration, binaries, and assets.
37 lines
1.5 KiB
Python
Executable File
37 lines
1.5 KiB
Python
Executable File
from pathlib import Path
|
|
from flask import Blueprint, abort, make_response, send_from_directory
|
|
from werkzeug.security import safe_join
|
|
from backend.app.api.context import ledger
|
|
|
|
|
|
bp = Blueprint("console", __name__)
|
|
|
|
|
|
@bp.get("/", defaults={"path": ""})
|
|
@bp.get("/<path:path>")
|
|
def console(path):
|
|
static_root = ledger().static_root
|
|
public_root = static_root / "public"
|
|
if path.startswith("src/"):
|
|
source_path = path.removeprefix("src/")
|
|
source_root = static_root / "src"
|
|
target = safe_join(str(source_root), source_path)
|
|
if target and Path(target).is_file():
|
|
return send_from_directory(source_root, source_path)
|
|
abort(404)
|
|
target = safe_join(str(public_root), path)
|
|
if path and path != "index.html" and target and Path(target).is_file():
|
|
return send_from_directory(public_root, path)
|
|
pages = {"", "login", "home", "home/register_implant", "home/check_certificate", "home/reissue", "home/implants", "home/registry"}
|
|
if path not in pages and not (
|
|
(path.startswith("home/implants/") and len(path.split("/")) == 3)
|
|
or (path.startswith("home/check_certificate/") and len(path.split("/")) == 4 and path.endswith("/check"))
|
|
):
|
|
abort(404)
|
|
index = public_root / "index.html"
|
|
if not index.is_file():
|
|
abort(503, "Console not found")
|
|
response = make_response(index.read_text(encoding="utf-8"))
|
|
response.headers["Cache-Control"] = "no-store"
|
|
return response
|