diff --git a/src/lib.rs b/src/lib.rs index b5c2630..4c6d415 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,18 +18,25 @@ pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> Result bool { // Check if the token provided by the endpoint is valid. - match kv.get("authorized_tokens").cache_ttl(300).text().await.unwrap() { - Some(t) => t.split(",") - .any(|authorized_token| authorized_token == token), - None => false, -} + match kv + .get("authorized_tokens") + .cache_ttl(300) + .text() + .await + .unwrap() + { + Some(t) => t + .split(",") + .any(|authorized_token| authorized_token == token), + None => false, + } } router .get_async("/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); + return Response::error("Unauthorized", 401); } } @@ -49,7 +56,7 @@ pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> Result Result return Response::error("Could not find remote IP", 500), }; - conf = conf.replace("##EXTERNAL_IP##", &remote_ip) + "\nxx"; + conf = conf.replace("##EXTERNAL_IP##", &remote_ip) + "\n"; match kv.get("users").cache_ttl(300).text().await? { Some(users) => { @@ -110,6 +117,25 @@ pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> Result Response::ok(&base), + None => Response::error( + format!("Could not find modules.conf for {}", hostname), + 404, + ), + }; + } + Response::error("Bad Request", 400) + }) .run(req, env) .await }