From 55a91b1459aab1eb5988766fbca53e808fbbbe0f Mon Sep 17 00:00:00 2001 From: Sam Sartor Date: Sat, 25 Oct 2025 19:56:58 -0600 Subject: [PATCH] actually read the config maybe --- config.toml.example | 1 - docker/proxy-config.toml | 2 -- proxy/src/main.rs | 46 ++++++++++++++++++---------------------- 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/config.toml.example b/config.toml.example index 11eca30..7f1df48 100644 --- a/config.toml.example +++ b/config.toml.example @@ -1,7 +1,6 @@ https_listen_address = "127.0.0.1:4433" http_listen_address = "127.0.0.1:8080" mumble_server_url = "[SERVER_URL_HERE]" -gui_path = "target/dx/mumble-web2-gui/release/web/public" [gui] force_proxy = true diff --git a/docker/proxy-config.toml b/docker/proxy-config.toml index db51597..3528a3e 100644 --- a/docker/proxy-config.toml +++ b/docker/proxy-config.toml @@ -4,8 +4,6 @@ http_listen_address = "127.0.0.1:4400" #key_path = "./key.pem" #mumble_server_url = "voip.ohea.xyz:64738" mumble_server_url = "127.0.0.1:64738" -#gui_path = "./target/dx/mumble-web2-gui/release/web/public" -gui_path = "./target/dx/mumble-web2-gui/debug/web/public" [gui] force_proxy = true diff --git a/proxy/src/main.rs b/proxy/src/main.rs index 91b75df..ba92ab1 100644 --- a/proxy/src/main.rs +++ b/proxy/src/main.rs @@ -31,7 +31,7 @@ fn default_cert_alt_names() -> Vec { vec!["localhost".into()] } -#[derive(Deserialize)] +#[derive(Debug, Deserialize, Serialize)] struct Config { https_listen_address: SocketAddr, http_listen_address: Option, @@ -41,7 +41,7 @@ struct Config { cert_alt_names: Vec, mumble_server_url: String, mumble_server_address: Option, - gui_path: PathBuf, + gui_path: Option, gui: Mutex, } @@ -52,8 +52,15 @@ static CONFIG: OnceCell = OnceCell::new(); async fn serve_gui_index_html(req: &Request, res: &mut Response) { let config = CONFIG.get().unwrap(); + let path = match &config.gui_path { + Some(p) => p.join("index.html"), + None => { + res.status_code(StatusCode::NOT_FOUND); + return; + } + }; + // Load the HTML file - let path = config.gui_path.join("index.html"); let html = match fs::read_to_string(&path).await { Ok(content) => content, Err(err) => { @@ -74,10 +81,9 @@ async fn serve_gui_index_html(req: &Request, res: &mut Response) { res.render(Text::Html(modified_html)); } -async fn init_config() -> Result<()> { +fn init_config() -> Result<()> { let mut config: Config = toml::from_str( - &fs::read_to_string("./config.toml") - .await + &std::fs::read_to_string("./config.toml") .context("reading config.toml (try making a copy of config.toml.example)")?, )?; let mumble_server_addr = config @@ -102,10 +108,9 @@ async fn init_config() -> Result<()> { #[tokio::main] async fn main() -> Result<()> { init_logging(); - init_config().await?; + init_config()?; let config = CONFIG.get().unwrap(); - info!("config\n{}", toml::to_string_pretty(&config.gui)?); - info!("gui config\n{}", serde_json::to_string_pretty(&config.gui)?); + info!("config\n{}", toml::to_string_pretty(&config)?); rustls::crypto::aws_lc_rs::default_provider() .install_default() @@ -150,20 +155,18 @@ async fn main() -> Result<()> { let rustls_config = RustlsConfig::new(Keycert::new().cert(cert.as_slice()).key(key.as_slice())); let config_craft = ConfigCraft { - client_config: MumbleClientConfig { - force_proxy: true, - proxy_url: "https://localhost:4433".to_string(), - cert_hash: config.gui.lock().unwrap().cert_hash.clone().unwrap(), - }, + client_config: config.gui.lock().unwrap().clone(), }; // Server routing - let router = Router::new() + let mut router = Router::new() .get(serve_gui_index_html) .push(Router::with_path("/proxy").goal(connect_proxy)) .push(Router::with_path("/config").get(config_craft.get_config())) - .push(Router::with_path("/<*+rest>").get(StaticDir::new(config.gui_path.clone()))) .hoop(Logger::new()); + if let Some(gui_path) = config.gui_path.clone() { + router = router.push(Router::with_path("/<*+rest>").get(StaticDir::new(gui_path))); + } let cors = Cors::new().allow_origin(AllowOrigin::any()).into_handler(); @@ -190,22 +193,15 @@ async fn main() -> Result<()> { Ok(()) } -#[derive(Serialize, Clone)] -struct MumbleClientConfig { - force_proxy: bool, - proxy_url: String, - cert_hash: Vec, -} - #[derive(Clone)] pub struct ConfigCraft { - client_config: MumbleClientConfig, + client_config: GuiConfig, } #[craft] impl ConfigCraft { #[craft(handler)] - async fn get_config(&self) -> Json { + async fn get_config(&self) -> Json { Json(self.client_config.clone()) } }