From 93be903b866eae84ac1d4670b90f3719f37a5a7c Mon Sep 17 00:00:00 2001 From: "(on company time)" <_@_> Date: Fri, 16 Dec 2022 16:46:30 -0600 Subject: [PATCH] ;loud_sound: report all incoming connections over WebHook, for now --- .../ptth_quic/src/executable_relay_server.rs | 28 +++++++++++++++++++ crates/ptth_quic/src/prelude.rs | 1 + 2 files changed, 29 insertions(+) diff --git a/crates/ptth_quic/src/executable_relay_server.rs b/crates/ptth_quic/src/executable_relay_server.rs index bedc3a6..c7321b8 100644 --- a/crates/ptth_quic/src/executable_relay_server.rs +++ b/crates/ptth_quic/src/executable_relay_server.rs @@ -147,6 +147,20 @@ pub async fn main (opt: Opt) -> anyhow::Result <()> }); } + { + let config = relay_state.config.load (); + dbg! (&config.webhook_url); + if let Some (webhook_url) = config.webhook_url.clone () { + let j = json! ({ + "text": "Booting up", + }).to_string (); + let http_client = relay_state.http_client.clone (); + tokio::spawn (async move { + http_client.post (webhook_url).body (j).send ().await + }); + } + } + tokio::select! { _val = task_quic_server => { eprintln! ("QUIC relay server exited, exiting"); @@ -186,17 +200,20 @@ struct RelayState { p4_server_proxies: Mutex >, direc_cookies: Mutex , DirecState>>, stats: Stats, + http_client: reqwest::Client, } #[derive (Default)] struct Config { ip_nicknames: BTreeMap <[u8; 4], String>, + webhook_url: Option , } impl From for Config { fn from (x: ConfigFile) -> Self { Self { ip_nicknames: x.ip_nicknames.into_iter ().collect (), + webhook_url: x.webhook_url, } } } @@ -204,6 +221,7 @@ impl From for Config { #[derive (Deserialize)] struct ConfigFile { ip_nicknames: Vec <([u8; 4], String)>, + webhook_url: Option , } struct DirecState { @@ -351,6 +369,16 @@ async fn handle_quic_connection ( debug! ("EHG7NVUD Incoming QUIC connection {} from {:?} ({})", id, remote_addr, ip_nickname); + if let Some (webhook_url) = config.webhook_url.clone () { + let j = json! ({ + "text": format! ("Incoming QUIC connection from {:?} ({})", remote_addr, ip_nickname), + }).to_string (); + let http_client = relay_state.http_client.clone (); + tokio::spawn (async move { + http_client.post (webhook_url).body (j).send ().await + }); + } + let conn = conn.await?; // Everyone who connects must identify themselves with the first diff --git a/crates/ptth_quic/src/prelude.rs b/crates/ptth_quic/src/prelude.rs index 4be9557..9508d89 100644 --- a/crates/ptth_quic/src/prelude.rs +++ b/crates/ptth_quic/src/prelude.rs @@ -47,6 +47,7 @@ pub use rand::{ }; pub use rusty_ulid::Ulid; pub use serde::Deserialize; +pub use serde_json::json; pub use tracing::{ debug, error,