Add system reboot and shutdown controls

This commit is contained in:
2026-11-22 18:15:02 +03:00
parent ba0ffbe89b
commit 85929c9054
3 changed files with 76 additions and 0 deletions
+33
View File
@@ -373,6 +373,39 @@ async def update_admin_password(
return RedirectResponse("/admin/login?result=password-changed", status_code=303)
@app.post("/admin/system/reboot")
async def admin_reboot(request: Request, csrf_token: str = Form(...)):
if not admin_session_valid(request):
return RedirectResponse("/admin/login", status_code=303)
session_token = request.session.get("password_csrf", "")
if not session_token or not hmac.compare_digest(csrf_token, session_token):
return RedirectResponse("/admin?error=system-csrf", status_code=303)
ok, _ = run_helper("system-power", "reboot")
if not ok:
return RedirectResponse("/admin?error=system-power", status_code=303)
return RedirectResponse("/admin", status_code=303)
@app.post("/admin/system/poweroff")
async def admin_poweroff(request: Request, csrf_token: str = Form(...)):
if not admin_session_valid(request):
return RedirectResponse("/admin/login", status_code=303)
session_token = request.session.get("password_csrf", "")
if not session_token or not hmac.compare_digest(csrf_token, session_token):
return RedirectResponse("/admin?error=system-csrf", status_code=303)
ok, _ = run_helper("system-power", "poweroff")
if not ok:
return RedirectResponse("/admin?error=system-power", status_code=303)
return RedirectResponse("/admin", status_code=303)
@app.post("/admin/settings/network")
async def update_network(
request: Request,