From 761fc49461b3b4bf24c0c41e041ae384e5c11d34 Mon Sep 17 00:00:00 2001 From: acidburns Date: Fri, 13 Feb 2026 02:35:50 +0100 Subject: [PATCH] Add web UI reboot/shutdown controls and system action API --- src/webapp.py | 23 +++++++++++++++++++++++ static/style.css | 14 ++++++++++++++ templates/index.html | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/webapp.py b/src/webapp.py index 068d32e..15488b1 100644 --- a/src/webapp.py +++ b/src/webapp.py @@ -1,5 +1,7 @@ import json import queue +import subprocess +import threading from typing import Any, Dict from flask import Flask, Response, jsonify, render_template, request, stream_with_context @@ -70,6 +72,27 @@ class WebPortal: self.network_manager.refresh_state() return jsonify({"ok": True, "message": message}) + @self.app.route("/api/system/", methods=["POST"]) + def system_action(action: str) -> Response: + commands = { + "reboot": ["systemctl", "reboot"], + "shutdown": ["systemctl", "poweroff"], + } + cmd = commands.get(action) + if cmd is None: + return jsonify({"ok": False, "message": "Unknown action"}), 400 + + self.state.update_status(f"System action requested: {action}", "") + + def _exec() -> None: + try: + subprocess.run(cmd, capture_output=True, text=True, timeout=20, check=False) + except Exception: + pass + + threading.Thread(target=_exec, daemon=True, name=f"system-{action}").start() + return jsonify({"ok": True, "message": f"{action} triggered"}) + @self.app.route("/events/serial") def serial_events() -> Response: @stream_with_context diff --git a/static/style.css b/static/style.css index e727810..cb00c9e 100644 --- a/static/style.css +++ b/static/style.css @@ -59,6 +59,20 @@ button:hover { filter: brightness(0.95); } +.button-row { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 10px; +} + +.btn-secondary { + background: #3b4958; +} + +.btn-danger { + background: #b42318; +} + .error { color: var(--error); font-size: 14px; diff --git a/templates/index.html b/templates/index.html index 169da22..f665bbd 100644 --- a/templates/index.html +++ b/templates/index.html @@ -36,6 +36,15 @@

Serial Monitor

Zur Live-Serial-Seite + +
+

System

+
+ + +
+
+