added presets

This commit is contained in:
2026-06-25 15:28:46 +03:00
parent db5f174ef3
commit 84a007f9d0
106 changed files with 6250 additions and 36 deletions
+17
View File
@@ -6,12 +6,14 @@ configuration is delegated to the privileged helper script `bt-netconfig`
(invoked through sudo) so the web service can keep running unprivileged.
"""
import ipaddress
import json
import re
import subprocess
from flask import Blueprint, abort, jsonify, request
from auth import login_required
from config_store import config_path
from paths import scripts_dir
network_bp = Blueprint("network", __name__)
@@ -19,6 +21,20 @@ network_bp = Blueprint("network", __name__)
_IFACE_RE = re.compile(r"^[A-Za-z0-9_.:-]{1,32}$")
def network_config_path():
return config_path().parent / "network.json"
def save_network_config(payload):
path = network_config_path()
path.parent.mkdir(parents=True, exist_ok=True)
tmp = path.with_suffix(".json.tmp")
with tmp.open("w", encoding="utf-8") as f:
json.dump(payload, f, ensure_ascii=False, indent=2)
f.write("\n")
tmp.replace(path)
def _run(args, timeout=10):
try:
out = subprocess.run(args, capture_output=True, text=True, timeout=timeout)
@@ -152,4 +168,5 @@ def api_set_network():
if rc != 0:
return jsonify({"ok": False, "error": err_out.strip() or out.strip()
or f"exit {rc}"}), 500
save_network_config(payload)
return jsonify({"ok": True, "output": out.strip()})