Add web UI reboot/shutdown controls and system action API

This commit is contained in:
2026-02-13 02:35:50 +01:00
parent 0d4e769292
commit 761fc49461
3 changed files with 71 additions and 1 deletions

View File

@@ -36,6 +36,15 @@
<h2>Serial Monitor</h2>
<a href="/serial">Zur Live-Serial-Seite</a>
</section>
<section class="card">
<h2>System</h2>
<div class="button-row">
<button id="rebootBtn" class="btn-secondary">Reboot</button>
<button id="shutdownBtn" class="btn-danger">Shutdown</button>
</div>
<div id="systemMsg"></div>
</section>
</main>
<script>
@@ -86,7 +95,7 @@
const msg = document.getElementById('connectMsg');
if (!ssid) {
msg.textContent = 'Bitte SSID wählen.';
msg.textContent = 'Bitte SSID waehlen.';
return;
}
@@ -109,8 +118,32 @@
setTimeout(refreshStatus, 1000);
}
async function triggerSystemAction(action) {
const msg = document.getElementById('systemMsg');
const label = action === 'reboot' ? 'Reboot' : 'Shutdown';
const ok = window.confirm(`System wirklich ${label.toLowerCase()} ausfuehren?`);
if (!ok) {
return;
}
msg.textContent = `${label} wird gestartet...`;
try {
const resp = await fetch(`/api/system/${action}`, {method: 'POST'});
const data = await resp.json();
if (resp.ok && data.ok) {
msg.textContent = `${label} ausgeloest.`;
} else {
msg.textContent = `Fehler: ${data.message || 'Aktion fehlgeschlagen'}`;
}
} catch (e) {
msg.textContent = `${label} fehlgeschlagen.`;
}
}
document.getElementById('scanBtn').addEventListener('click', scan);
document.getElementById('connectBtn').addEventListener('click', connectWifi);
document.getElementById('rebootBtn').addEventListener('click', () => triggerSystemAction('reboot'));
document.getElementById('shutdownBtn').addEventListener('click', () => triggerSystemAction('shutdown'));
refreshStatus();
setInterval(refreshStatus, 5000);