working lol

This commit is contained in:
2024-02-18 12:53:25 +01:00
commit c6832f17d0
4 changed files with 1359 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

1314
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

12
Cargo.toml Normal file
View File

@@ -0,0 +1,12 @@
[package]
name = "go_to_sleep"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
actix-web = "4.5.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
futures = "0.3"

32
src/main.rs Normal file
View File

@@ -0,0 +1,32 @@
use actix_web::{get, web, Responder, Result};
use serde::Serialize;
use std::process::Command;
#[derive(Serialize)]
struct MyObj {
name: String,
}
#[get("/a/{name}")]
async fn index(name: web::Path<String>) -> Result<impl Responder> {
let obj = MyObj {
name: name.to_string(),
};
let mut sleep_command = Command::new("ssh root@192.168.0.22 shutdown now");
let name = name.to_string();
if name == "penis" {
sleep_command.status().expect("failed to shutdown serwer");
}
Ok(web::Json(obj))
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
use actix_web::{App, HttpServer};
HttpServer::new(|| App::new().service(index))
.bind(("127.0.0.1", 8080))?
.run()
.await
}