Added UPDATING FILE. also fixed a few bugs

This commit is contained in:
int 80h
2020-05-28 16:34:48 -04:00
parent 2f89d8cb9a
commit 014b7c938b
6 changed files with 41 additions and 10 deletions

View File

@@ -66,6 +66,13 @@ pub async fn cgi(
let mut envs = envs(con.peer_addr, srv, &url);
envs.insert("SCRIPT_NAME".to_string(), path.file_name().unwrap().to_str().unwrap().to_string());
match path.parent() {
Some(p) => {
std::env::set_current_dir(p)?;
},
None => {},
}
let cmd = Command::new(path.to_str().unwrap())
.env_clear()
.envs(&envs)

View File

@@ -36,7 +36,10 @@ pub struct ServerCfg {
impl Config {
pub fn new(file: &Path) -> Result<Config, Error> {
let fd = std::fs::read_to_string(file).unwrap();
let config: Config = toml::from_str(&fd).unwrap();
let config: Config = match toml::from_str(&fd) {
Ok(c) => c,
Err(e) => return Err(e),
};
return Ok(config);
}
pub fn to_map(&self) -> HashMap<String, ServerCfg> {

View File

@@ -29,7 +29,7 @@ fn get_mime(path: &PathBuf) -> String {
let mut mime = "text/gemini".to_string();
let ext = match path.extension() {
Some(p) => p.to_str().unwrap(),
None => return mime.to_string(),
None => return mime,
};
mime = match ext {
@@ -38,12 +38,12 @@ fn get_mime(path: &PathBuf) -> String {
_ => {
match mime_guess::from_ext(ext).first() {
Some(m) => m.essence_str().to_string(),
None => mime,
None => "text/plain".to_string(),
}
},
};
return mime.to_string();
return mime;
}
async fn get_binary(mut con: conn::Connection, path: PathBuf, meta: String) -> io::Result<()> {
@@ -263,20 +263,19 @@ async fn handle_connection(
}
},
None => {
if perm.mode() & 0o0111 == 0o0111 {
if meta.is_file() && perm.mode() & 0o0111 == 0o0111 {
cgi::cgi(con, srv, path, url).await?;
return Ok(());
}
},
}
}
if perm.mode() & 0o0111 == 0o0111 {
if meta.is_file() && perm.mode() & 0o0111 == 0o0111 {
logger::logger(con.peer_addr, Status::NotFound, &request);
con.send_status(Status::NotFound, None).await?;
return Ok(());
}
if perm.mode() & 0o0444 != 0o0444 {
logger::logger(con.peer_addr, Status::NotFound, &request);
con.send_status(Status::NotFound, None).await?;
@@ -310,7 +309,13 @@ fn main() -> io::Result<()> {
return Ok(());
}
let cfg = config::Config::new(&p)?;
let cfg = match config::Config::new(&p) {
Ok(c) => c,
Err(e) => {
eprintln!("Config error: {}", e);
return Ok(());
},
};
let cmap = cfg.to_map();
let default = &cfg.server[0].hostname;
println!("Serving {} vhosts", cfg.server.len());