actually read the config maybe

This commit is contained in:
2025-10-25 19:56:58 -06:00
parent d9695be153
commit 55a91b1459
3 changed files with 21 additions and 28 deletions
-1
View File
@@ -1,7 +1,6 @@
https_listen_address = "127.0.0.1:4433" https_listen_address = "127.0.0.1:4433"
http_listen_address = "127.0.0.1:8080" http_listen_address = "127.0.0.1:8080"
mumble_server_url = "[SERVER_URL_HERE]" mumble_server_url = "[SERVER_URL_HERE]"
gui_path = "target/dx/mumble-web2-gui/release/web/public"
[gui] [gui]
force_proxy = true force_proxy = true
-2
View File
@@ -4,8 +4,6 @@ http_listen_address = "127.0.0.1:4400"
#key_path = "./key.pem" #key_path = "./key.pem"
#mumble_server_url = "voip.ohea.xyz:64738" #mumble_server_url = "voip.ohea.xyz:64738"
mumble_server_url = "127.0.0.1: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] [gui]
force_proxy = true force_proxy = true
+21 -25
View File
@@ -31,7 +31,7 @@ fn default_cert_alt_names() -> Vec<String> {
vec!["localhost".into()] vec!["localhost".into()]
} }
#[derive(Deserialize)] #[derive(Debug, Deserialize, Serialize)]
struct Config { struct Config {
https_listen_address: SocketAddr, https_listen_address: SocketAddr,
http_listen_address: Option<SocketAddr>, http_listen_address: Option<SocketAddr>,
@@ -41,7 +41,7 @@ struct Config {
cert_alt_names: Vec<String>, cert_alt_names: Vec<String>,
mumble_server_url: String, mumble_server_url: String,
mumble_server_address: Option<SocketAddr>, mumble_server_address: Option<SocketAddr>,
gui_path: PathBuf, gui_path: Option<PathBuf>,
gui: Mutex<GuiConfig>, gui: Mutex<GuiConfig>,
} }
@@ -52,8 +52,15 @@ static CONFIG: OnceCell<Config> = OnceCell::new();
async fn serve_gui_index_html(req: &Request, res: &mut Response) { async fn serve_gui_index_html(req: &Request, res: &mut Response) {
let config = CONFIG.get().unwrap(); 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 // Load the HTML file
let path = config.gui_path.join("index.html");
let html = match fs::read_to_string(&path).await { let html = match fs::read_to_string(&path).await {
Ok(content) => content, Ok(content) => content,
Err(err) => { Err(err) => {
@@ -74,10 +81,9 @@ async fn serve_gui_index_html(req: &Request, res: &mut Response) {
res.render(Text::Html(modified_html)); res.render(Text::Html(modified_html));
} }
async fn init_config() -> Result<()> { fn init_config() -> Result<()> {
let mut config: Config = toml::from_str( let mut config: Config = toml::from_str(
&fs::read_to_string("./config.toml") &std::fs::read_to_string("./config.toml")
.await
.context("reading config.toml (try making a copy of config.toml.example)")?, .context("reading config.toml (try making a copy of config.toml.example)")?,
)?; )?;
let mumble_server_addr = config let mumble_server_addr = config
@@ -102,10 +108,9 @@ async fn init_config() -> Result<()> {
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
init_logging(); init_logging();
init_config().await?; init_config()?;
let config = CONFIG.get().unwrap(); let config = CONFIG.get().unwrap();
info!("config\n{}", toml::to_string_pretty(&config.gui)?); info!("config\n{}", toml::to_string_pretty(&config)?);
info!("gui config\n{}", serde_json::to_string_pretty(&config.gui)?);
rustls::crypto::aws_lc_rs::default_provider() rustls::crypto::aws_lc_rs::default_provider()
.install_default() .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 rustls_config = RustlsConfig::new(Keycert::new().cert(cert.as_slice()).key(key.as_slice()));
let config_craft = ConfigCraft { let config_craft = ConfigCraft {
client_config: MumbleClientConfig { client_config: config.gui.lock().unwrap().clone(),
force_proxy: true,
proxy_url: "https://localhost:4433".to_string(),
cert_hash: config.gui.lock().unwrap().cert_hash.clone().unwrap(),
},
}; };
// Server routing // Server routing
let router = Router::new() let mut router = Router::new()
.get(serve_gui_index_html) .get(serve_gui_index_html)
.push(Router::with_path("/proxy").goal(connect_proxy)) .push(Router::with_path("/proxy").goal(connect_proxy))
.push(Router::with_path("/config").get(config_craft.get_config())) .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()); .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(); let cors = Cors::new().allow_origin(AllowOrigin::any()).into_handler();
@@ -190,22 +193,15 @@ async fn main() -> Result<()> {
Ok(()) Ok(())
} }
#[derive(Serialize, Clone)]
struct MumbleClientConfig {
force_proxy: bool,
proxy_url: String,
cert_hash: Vec<u8>,
}
#[derive(Clone)] #[derive(Clone)]
pub struct ConfigCraft { pub struct ConfigCraft {
client_config: MumbleClientConfig, client_config: GuiConfig,
} }
#[craft] #[craft]
impl ConfigCraft { impl ConfigCraft {
#[craft(handler)] #[craft(handler)]
async fn get_config(&self) -> Json<MumbleClientConfig> { async fn get_config(&self) -> Json<GuiConfig> {
Json(self.client_config.clone()) Json(self.client_config.clone())
} }
} }