The index file is now configurable
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "gemserv"
|
name = "gemserv"
|
||||||
version = "0.1.1"
|
version = "0.2.0"
|
||||||
authors = ["int 80h <int@80h.dev>"]
|
authors = ["int 80h <int@80h.dev>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ hostname = "example.com"
|
|||||||
dir = "/path/to/serv"
|
dir = "/path/to/serv"
|
||||||
key = "/path/to/key"
|
key = "/path/to/key"
|
||||||
cert = "/path/to/cert"
|
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 dir is optional
|
||||||
cgi = "/path/to/cgi-bin/"
|
cgi = "/path/to/cgi-bin/"
|
||||||
# cgienv is optional
|
# cgienv is optional
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ pub struct Server {
|
|||||||
pub dir: String,
|
pub dir: String,
|
||||||
pub key: String,
|
pub key: String,
|
||||||
pub cert: String,
|
pub cert: String,
|
||||||
|
pub index: Option<String>,
|
||||||
pub cgi: Option<String>,
|
pub cgi: Option<String>,
|
||||||
pub cgienv: Option<HashMap<String, String>>,
|
pub cgienv: Option<HashMap<String, String>>,
|
||||||
pub usrdir: Option<bool>,
|
pub usrdir: Option<bool>,
|
||||||
@@ -30,6 +31,7 @@ pub struct ServerCfg {
|
|||||||
pub dir: String,
|
pub dir: String,
|
||||||
pub key: String,
|
pub key: String,
|
||||||
pub cert: String,
|
pub cert: String,
|
||||||
|
pub index: String,
|
||||||
pub cgi: String,
|
pub cgi: String,
|
||||||
pub cgienv: HashMap<String, String>,
|
pub cgienv: HashMap<String, String>,
|
||||||
pub usrdir: bool,
|
pub usrdir: bool,
|
||||||
@@ -72,6 +74,10 @@ impl Config {
|
|||||||
Some(c) => cmap = c.clone(),
|
Some(c) => cmap = c.clone(),
|
||||||
None => {}
|
None => {}
|
||||||
};
|
};
|
||||||
|
let index = match srv.index.to_owned() {
|
||||||
|
Some(i) => i,
|
||||||
|
None => "index.gemini".to_string()
|
||||||
|
};
|
||||||
|
|
||||||
map.insert(
|
map.insert(
|
||||||
srv.hostname.clone(),
|
srv.hostname.clone(),
|
||||||
@@ -80,6 +86,7 @@ impl Config {
|
|||||||
dir: srv.dir.clone(),
|
dir: srv.dir.clone(),
|
||||||
key: srv.key.clone(),
|
key: srv.key.clone(),
|
||||||
cert: srv.cert.clone(),
|
cert: srv.cert.clone(),
|
||||||
|
index: index.to_string(),
|
||||||
cgi: cgi,
|
cgi: cgi,
|
||||||
cgienv: cmap.clone(),
|
cgienv: cmap.clone(),
|
||||||
usrdir: usrdir,
|
usrdir: usrdir,
|
||||||
|
|||||||
22
src/main.rs
22
src/main.rs
@@ -34,11 +34,17 @@ fn get_mime(path: &PathBuf) -> String {
|
|||||||
Some(p) => p.to_str().unwrap(),
|
Some(p) => p.to_str().unwrap(),
|
||||||
None => return mime.to_string(),
|
None => return mime.to_string(),
|
||||||
};
|
};
|
||||||
if ext != "gemini" {
|
|
||||||
m = mime_guess::from_ext(ext).first().unwrap();
|
mime = match ext {
|
||||||
mime = m.essence_str();
|
"gemini" => mime,
|
||||||
}
|
"gmi" => mime,
|
||||||
mime.to_string()
|
_ => {
|
||||||
|
m = mime_guess::from_ext(ext).first().unwrap();
|
||||||
|
m.essence_str()
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return mime.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_binary(mut con: conn::Connection, path: PathBuf, meta: String) -> io::Result<()> {
|
async fn get_binary(mut con: conn::Connection, path: PathBuf, meta: String) -> io::Result<()> {
|
||||||
@@ -202,8 +208,8 @@ async fn handle_connection(
|
|||||||
.await?;
|
.await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
if path.join("index.gemini").exists() {
|
if path.join(&srv.index).exists() {
|
||||||
path.push("index.gemini");
|
path.push(&srv.index);
|
||||||
meta = fs::metadata(&path).expect("Unable to read metadata");
|
meta = fs::metadata(&path).expect("Unable to read metadata");
|
||||||
perm = meta.permissions();
|
perm = meta.permissions();
|
||||||
if perm.mode() & 0o0444 != 0o444 {
|
if perm.mode() & 0o0444 != 0o444 {
|
||||||
@@ -241,7 +247,7 @@ async fn handle_connection(
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let content = get_content(path, url)?;
|
let content = get_content(path, url)?;
|
||||||
con.send_body(status::Status::Success, Some(mime.as_str()), Some(content))
|
con.send_body(status::Status::Success, Some(&mime), Some(content))
|
||||||
.await?;
|
.await?;
|
||||||
logger::logger(con.peer_addr, Status::Success, &request);
|
logger::logger(con.peer_addr, Status::Success, &request);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user