Permissions, shutdown route

This commit is contained in:
Jack Mechem 2026-03-30 19:53:55 -07:00
parent 15d0d174a9
commit ac01c03094
4 changed files with 31 additions and 1 deletions

View file

@ -4,6 +4,33 @@ use zbus::Connection;
use crate::auth;
use crate::models;
// POST /system/shutdown
pub async fn system_shutdown(headers: HeaderMap) -> impl IntoResponse {
let conn = match Connection::system().await {
Ok(c) => c,
Err(e) => {
return models::ActionResponse::err(StatusCode::INTERNAL_SERVER_ERROR, &e.to_string())
.into_response();
}
};
let result = conn
.call_method(
Some("org.freedesktop.login1"),
"/org/freedesktop/login1",
Some("org.freedesktop.login1.Manager"),
"PowerOff",
&(false,),
)
.await;
match result {
Ok(_) => models::ActionResponse::ok("Shutting down...".to_string()).into_response(),
Err(e) => models::ActionResponse::err(StatusCode::INTERNAL_SERVER_ERROR, &e.to_string())
.into_response(),
}
}
// POST /system/reboot
pub async fn system_reboot(headers: HeaderMap) -> impl IntoResponse {
let conn = match Connection::system().await {