parent
3af7b892b2
commit
f10c7df262
10 changed files with 276 additions and 326 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue