diff --git a/README b/README index 80789fa..ea59467 100644 --- a/README +++ b/README @@ -35,6 +35,10 @@ Thanks to tiwesdaeg for figuring it out. ## CGI Environments +In the configuration file there's "cgi" which is an optional bool to turn cgi +on. If it's true it'll run scripts from any directory. To limit it to only one +directory set "cgipath" + Scripts have 5 seconds to complete or they will be terminated. These variables are preset for you. If you need more you can define them in the diff --git a/config.toml b/config.toml index 87f69e9..d8f873e 100644 --- a/config.toml +++ b/config.toml @@ -13,7 +13,10 @@ cert = "/path/to/cert" # index is optional but defaults to index.gemini. The server will serve files # ending in gemini or gmi. index = "index.gmi" -# cgi dir is optional +# cgi is optional bool +cgi = true +# cgipath is optional and only checked if cgi is true. It restricts cgi to only +# this directory. cgi = "/path/to/cgi-bin/" # cgienv is optional cgienv = { "GIT_PROJECT_ROOT" = "/srv/git" } diff --git a/src/config.rs b/src/config.rs index 4b140b4..74c2546 100644 --- a/src/config.rs +++ b/src/config.rs @@ -18,7 +18,8 @@ pub struct Server { pub key: String, pub cert: String, pub index: Option, - pub cgi: Option, + pub cgi: Option, + pub cgipath: Option, pub cgienv: Option>, pub usrdir: Option, pub proxy: Option>, diff --git a/src/main.rs b/src/main.rs index 9e1367e..601553a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -232,9 +232,9 @@ async fn handle_connection( } } } - - match &srv.server.cgi { - Some(c) => { + if srv.server.cgi.unwrap_or(false) { + match &srv.server.cgipath { + Some(c) => { if c.trim_end_matches("/") == path.parent().unwrap().to_str().unwrap() { if perm.mode() & 0o0111 == 0o0111 { cgi::cgi(con, srv, path, url).await?; @@ -244,9 +244,23 @@ async fn handle_connection( con.send_status(Status::CGIError, None).await?; return Ok(()); } + } else { + logger::logger(con.peer_addr, Status::CGIError, &request); + con.send_status(Status::CGIError, None).await?; + return Ok(()); } + }, + None => { + if perm.mode() & 0o0111 == 0o0111 { + cgi::cgi(con, srv, path, url).await?; + return Ok(()); + } else { + logger::logger(con.peer_addr, Status::CGIError, &request); + con.send_status(Status::CGIError, None).await?; + return Ok(()); + } + }, } - None => {} } if perm.mode() & 0o0444 != 0o0444 {