working wake up

This commit is contained in:
WanderingPenwing 2024-09-02 17:57:58 +02:00
parent 49b32d8d53
commit b928f679f2
3 changed files with 16 additions and 0 deletions

7
Cargo.lock generated
View file

@ -1336,6 +1336,12 @@ version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "wake-on-lan"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ccf60b60ad7e5b1b37372c5134cbcab4db0706c231d212e0c643a077462bc8f"
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.11.0+wasi-snapshot-preview1" version = "0.11.0+wasi-snapshot-preview1"
@ -1569,6 +1575,7 @@ dependencies = [
"ping-rs", "ping-rs",
"pulldown-cmark", "pulldown-cmark",
"serde", "serde",
"wake-on-lan",
] ]
[[package]] [[package]]

View file

@ -11,3 +11,4 @@ actix-files = "0.6"
pulldown-cmark = "0.9" # Markdown parser pulldown-cmark = "0.9" # Markdown parser
ping-rs = "0.1.2" ping-rs = "0.1.2"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
wake-on-lan = "0.2.0"

View file

@ -3,6 +3,7 @@ use actix_web::{web, App, HttpServer, HttpResponse, Responder};
use std::fs; use std::fs;
use std::time::Duration; use std::time::Duration;
use serde::Deserialize; use serde::Deserialize;
use wake_on_lan;
#[derive(Deserialize)] #[derive(Deserialize)]
struct WakeQuery { struct WakeQuery {
@ -116,7 +117,14 @@ async fn wake(query: web::Query<WakeQuery>) -> impl Responder {
let password = &query.password; let password = &query.password;
if password == "magic" { if password == "magic" {
let mac_address: [u8; 6] = [0xC0, 0x7C, 0xD1, 0xFB, 0xC9, 0x86];
let magic_packet = wake_on_lan::MagicPacket::new(&mac_address);
let _ = magic_packet.send();
serve_markdown("pages/summary.md", Some(true)).await serve_markdown("pages/summary.md", Some(true)).await
} else { } else {
serve_markdown("pages/summary.md", Some(false)).await serve_markdown("pages/summary.md", Some(false)).await
} }