diff --git a/README.md b/README.md index 9af8d5e..1915c85 100644 --- a/README.md +++ b/README.md @@ -7,29 +7,34 @@ Features -------- This can't do much right now besides hosting some static files. In fact, the -feature set happens to be limited to what I need to host my own gemini page. +feature set happens to be limited to what I need to host my own Gemini page. Coincidence? More is to come however. Specifically I'd want to add CGI support. And maybe reverse proxy support as well, depending on how much stuff I'll be hosting over Gemini. +Platform Support +---------------- + +This currently only works on UNIX platforms as `setuid` and `setgid` system +calls are used to drop the privilege level after initialization. Currently +there is no way to disable this. Of course, Gemini's default port (1965) can be +opened in user-mode, but not changing the user after startup would retain read +permissions to the private key. + Starting -------- -Right now every relevant option needs to be given through command line -parameters. Though handling of a configuration file is a feature I'll add -later on. +Sheldon Director look for a config file in `/etc/sheldond.conf`. If you want to +change this, pass an alternative path on startup like so: An example start can look like this: ```sh -sudo ./sheldond -l "[::]:1965" -l "0.0.0.0:1965" -d "klockenschooster.de" -g /var/gemini/ --user gem-data --group gem-data +sudo ./sheldond -c ./sheldond.conf ``` -This serves the content of the folder `/var/gemini/` over both IPv4 and IPv6 -on port 1965 on the domain `klockenschooster.de`. After opening the socket and -reading the certificates the server sets its user and group id to the -respective values for `gem-data`. +An example config file can be found in this repository in `doc/sheldond.conf`. Why "Sheldon Director"? ----------------------- diff --git a/src/main.rs b/src/main.rs index 5639158..7e5787a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,10 @@ fn parse_args() -> Option { loop { match args.next() { Some(arg) => { + if arg == "-h" || arg == "--help" { + help(); + return None; + } if arg == "-c" || arg == "--config" { let config_fname = args.next().unwrap(); return Some(config_fname); @@ -29,7 +33,7 @@ fn parse_args() -> Option { } } - None + Some("/etc/sheldond.conf".to_string()) } fn parse_config(fname: String) -> server::ServerConfig { @@ -38,8 +42,8 @@ fn parse_config(fname: String) -> server::ServerConfig { let file = match File::open(path) { Ok(file) => BufReader::new(file), - Err(e) => { - panic!(e); + Err(_) => { + panic!("could not open config file: {}", fname); } }; @@ -77,13 +81,13 @@ fn parse_config(fname: String) -> server::ServerConfig { } fn main() { - let config = match parse_args() { - Some(config_fname) => parse_config(config_fname), + let config_fname = match parse_args() { + Some(config_fname) => config_fname, None => { - help(); return; } }; + let config = parse_config(config_fname); let server = server::Server::new(&config); server.serve(); diff --git a/src/mime/mod.rs b/src/mime/mod.rs index 6fc0f9f..156dd0d 100644 --- a/src/mime/mod.rs +++ b/src/mime/mod.rs @@ -14,6 +14,7 @@ pub fn get_mime_type(extension: &OsStr) -> &'static str { match ext_str { "gmi" => "text/gemini", + "gemini" => "text/gemini", "txt" => "text/plain", _ => default_mime_type(), } diff --git a/src/server/handler.rs b/src/server/handler.rs index 84d9d17..5f77f93 100644 --- a/src/server/handler.rs +++ b/src/server/handler.rs @@ -5,7 +5,7 @@ use openssl::ssl::SslStream; use std::fs::File; use std::io::{copy, BufReader, BufWriter}; use std::net::TcpStream; -use std::path::Path; +use std::path::{Path, PathBuf}; use url::Url; fn send_header(stream: &mut SslStream, header: &response::Header) { @@ -50,6 +50,13 @@ pub fn handle_request(config: &ServerConfig, mut stream: SslStream) { handle_response(config, location, &mut stream); } +fn gen_path_index(path: &Path) -> PathBuf { + match path.is_dir() { + true => path.join("index.gmi"), + false => PathBuf::from(path), + } +} + fn handle_response(config: &ServerConfig, url: Url, mut stream: &mut SslStream) { if url.scheme() != "gemini" { send_header(&mut stream, &response::permanent_failure()); @@ -68,7 +75,8 @@ fn handle_response(config: &ServerConfig, url: Url, mut stream: &mut SslStream file,