diff --git a/README b/README index ffe5f6b..43e566a 100644 --- a/README +++ b/README @@ -37,17 +37,18 @@ Thanks to tiwesdaeg for figuring it out. There's example SCGI scripts for python and perl in the cgi-scripts directory. -### 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" -If "cgi" is false or not set the server with respond "Not Found" to any +If "cgi" is false or not set the server will respond "Not Found" to any executable file. Scripts have 5 seconds to complete or they will be terminated. +### CGI Environments + + These variables are preset for you. If you need more you can define them in the config file under "cgienv" diff --git a/config.toml b/config.toml index 0cf8ff6..4eb5014 100644 --- a/config.toml +++ b/config.toml @@ -17,7 +17,7 @@ index = "index.gmi" cgi = true # cgipath is optional and only checked if cgi is true. It restricts cgi to only # this directory. -cgi = "/path/to/cgi-bin/" +cgipath = "/path/to/cgi-bin/" # scgi is optional scgi = { "/scgi" = "localhost:4000" } # cgienv is optional diff --git a/src/cgi.rs b/src/cgi.rs index b705328..0f631c4 100644 --- a/src/cgi.rs +++ b/src/cgi.rs @@ -132,7 +132,12 @@ pub async fn scgi(addr: String, u: url::Url, mut con: conn::Connection, srv: &co stream.flush().await?; let mut buf = vec![]; - stream.read_to_end(&mut buf).await?; + if let Err(_) = tokio::time::timeout( + tokio::time::Duration::from_secs(5), stream.read_to_end(&mut buf)).await { + logger::logger(con.peer_addr, Status::CGIError, u.as_str()); + con.send_status(Status::CGIError, None).await?; + return Ok(()); + } let req = String::from_utf8_lossy(&buf[..]); if !check(req.as_bytes()[0], con.peer_addr, u) { con.send_status(Status::CGIError, None).await?;