shell
Some checks failed
ci/woodpecker/push/build Pipeline failed

This commit is contained in:
JMARyA 2025-05-05 14:56:02 +02:00
parent 3af7b892b2
commit f10c7df262
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
10 changed files with 276 additions and 326 deletions

View file

@ -1,10 +1,10 @@
use std::{os, process::Stdio};
use std::process::Stdio;
use owl::Serialize;
use rumqttc::AsyncClient;
use sage::PersonaIdentity;
use crate::api::{ClientAction, ServerResponse, ServerResponses};
use crate::api::{ClientAction, ServerResponse, ServerResponses, ShellResponse};
// Client MQTT
pub async fn handle_mqtt(topic: String, data: Vec<u8>) {
@ -31,6 +31,28 @@ pub async fn handle_mqtt(topic: String, data: Vec<u8>) {
)
.await;
}
crate::api::ClientActions::Shell(cmd, cwd) => {
log::info!("Received shell command: {cmd} in {cwd}");
let res = std::process::Command::new("sh")
.arg("-c")
.arg(cmd)
.current_dir(cwd)
.output()
.unwrap();
send_back(
crate::MQTT.get().unwrap(),
"respond",
ServerResponse::of(
&action,
ServerResponses::Shell(ShellResponse {
stdout: String::from_utf8_lossy(&res.stdout).to_string(),
stderr: String::from_utf8_lossy(&res.stderr).to_string(),
status: res.status.code().unwrap(),
}),
),
)
.await;
}
}
}