;loud_sound: report all incoming connections over WebHook, for now

main
(on company time) 2022-12-16 16:46:30 -06:00
parent 33fe10ee27
commit 93be903b86
2 changed files with 29 additions and 0 deletions

View File

@ -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! { tokio::select! {
_val = task_quic_server => { _val = task_quic_server => {
eprintln! ("QUIC relay server exited, exiting"); eprintln! ("QUIC relay server exited, exiting");
@ -186,17 +200,20 @@ struct RelayState {
p4_server_proxies: Mutex <HashMap <PeerId, P4State>>, p4_server_proxies: Mutex <HashMap <PeerId, P4State>>,
direc_cookies: Mutex <HashMap <Vec <u8>, DirecState>>, direc_cookies: Mutex <HashMap <Vec <u8>, DirecState>>,
stats: Stats, stats: Stats,
http_client: reqwest::Client,
} }
#[derive (Default)] #[derive (Default)]
struct Config { struct Config {
ip_nicknames: BTreeMap <[u8; 4], String>, ip_nicknames: BTreeMap <[u8; 4], String>,
webhook_url: Option <String>,
} }
impl From <ConfigFile> for Config { impl From <ConfigFile> for Config {
fn from (x: ConfigFile) -> Self { fn from (x: ConfigFile) -> Self {
Self { Self {
ip_nicknames: x.ip_nicknames.into_iter ().collect (), ip_nicknames: x.ip_nicknames.into_iter ().collect (),
webhook_url: x.webhook_url,
} }
} }
} }
@ -204,6 +221,7 @@ impl From <ConfigFile> for Config {
#[derive (Deserialize)] #[derive (Deserialize)]
struct ConfigFile { struct ConfigFile {
ip_nicknames: Vec <([u8; 4], String)>, ip_nicknames: Vec <([u8; 4], String)>,
webhook_url: Option <String>,
} }
struct DirecState { struct DirecState {
@ -351,6 +369,16 @@ async fn handle_quic_connection (
debug! ("EHG7NVUD Incoming QUIC connection {} from {:?} ({})", id, remote_addr, ip_nickname); 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?; let conn = conn.await?;
// Everyone who connects must identify themselves with the first // Everyone who connects must identify themselves with the first

View File

@ -47,6 +47,7 @@ pub use rand::{
}; };
pub use rusty_ulid::Ulid; pub use rusty_ulid::Ulid;
pub use serde::Deserialize; pub use serde::Deserialize;
pub use serde_json::json;
pub use tracing::{ pub use tracing::{
debug, debug,
error, error,