fix CGI support

This commit is contained in:
Cadey Ratio 2020-08-08 12:08:03 -04:00
parent 1da65dcfeb
commit a533ebbeaf
2 changed files with 13 additions and 4 deletions

View File

@ -42,11 +42,18 @@ impl Handler {
} }
}; };
if let Err(why) = std::fs::metadata(&path) {
log::error!("can't find {:?}: {}", path, why);
return Ok(Response::not_found());
}
let filtered_env: HashMap<String, String> = std::env::vars() let filtered_env: HashMap<String, String> = std::env::vars()
.filter(|&(ref k, _)| k == "TERM" || k == "TZ" || k == "LANG" || k == "PATH") .filter(|&(ref k, _)| k == "TERM" || k == "TZ" || k == "LANG" || k == "PATH")
.collect(); .collect();
let output = Command::new(path.clone()) let remote_host = format!("{}", r.addr);
let output = Command::new(&path)
.env_clear() .env_clear()
.envs(filtered_env) .envs(filtered_env)
.env("GATEWAY_INTERFACE", "CGI/1.1") .env("GATEWAY_INTERFACE", "CGI/1.1")
@ -59,8 +66,8 @@ impl Handler {
.env("SERVER_NAME", r.url.host_str().unwrap()) .env("SERVER_NAME", r.url.host_str().unwrap())
.env("SERVER_HOSTNAME", r.url.host_str().unwrap()) .env("SERVER_HOSTNAME", r.url.host_str().unwrap())
.env("SERVER_PORT", format!("{}", r.url.port().unwrap_or(1965))) .env("SERVER_PORT", format!("{}", r.url.port().unwrap_or(1965)))
.env("REMOTE_HOST", "127.0.0.1") .env("REMOTE_HOST", &remote_host)
.env("REMOTE_ADDR", "127.0.0.1") .env("REMOTE_ADDR", remote_host)
.env("TLS_CIPHER", "Secure") .env("TLS_CIPHER", "Secure")
.env("TLS_VERSION", "TLSv1.3") .env("TLS_VERSION", "TLSv1.3")
.output()?; .output()?;

View File

@ -15,6 +15,7 @@ use url::Url;
#[allow(dead_code)] #[allow(dead_code)]
pub struct Request { pub struct Request {
pub url: Url, pub url: Url,
pub addr: SocketAddr,
pub certs: Option<Vec<Certificate>>, pub certs: Option<Vec<Certificate>>,
} }
@ -103,6 +104,7 @@ async fn handle_request(
let req = Request { let req = Request {
url: url, url: url,
addr: addr,
certs: None, certs: None,
}; };
handle(h, req, &mut stream, addr).await; handle(h, req, &mut stream, addr).await;
@ -155,7 +157,7 @@ async fn parse_request<R: Read + Unpin>(mut stream: R) -> Result<Url> {
Url::parse(request)? Url::parse(request)?
}; };
// Validate the URL. TODO: Check the hostname and port. // Validate the URL.
Ok(url) Ok(url)
} }