diff --git a/src/lib.rs b/src/lib.rs index 4c6d415..e669c7d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -136,6 +136,62 @@ pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> Result Response::ok(&base), + None => { + Response::error(format!("Could not find logger.conf for {}", hostname), 404) + } + }; + } + Response::error("Bad Request", 400) + }) + .get_async("/f2b/asterisk/:hostname/:token", |_req, ctx| async move { + if let Some(token) = ctx.param("token") { + if !check_endpoint_auth(token, ctx.kv("GONK_NODES")?).await { + return Response::error("Unauthorized", 401); + } + } + if let Some(hostname) = ctx.param("hostname") { + let kv = ctx.kv("GONK_NODES")?; + + return match kv.get("base_f2b_asterisk").cache_ttl(300).text().await? { + Some(base) => Response::ok(&base), + None => Response::error( + format!("Could not find fail2ban asterisk.conf for {}", hostname), + 404, + ), + }; + } + Response::error("Bad Request", 400) + }) + .get_async("/f2b/voipbl/:hostname/:token", |_req, ctx| async move { + if let Some(token) = ctx.param("token") { + if !check_endpoint_auth(token, ctx.kv("GONK_NODES")?).await { + return Response::error("Unauthorized", 401); + } + } + if let Some(hostname) = ctx.param("hostname") { + let kv = ctx.kv("GONK_NODES")?; + + return match kv.get("base_f2b_voipbl").cache_ttl(300).text().await? { + Some(base) => Response::ok(&base), + None => Response::error( + format!("Could not find fail2ban voipbl.conf for {}", hostname), + 404, + ), + }; + } + Response::error("Bad Request", 400) + }) .run(req, env) .await }