actually read the config maybe
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+21
-25
@@ -31,7 +31,7 @@ fn default_cert_alt_names() -> Vec<String> {
|
||||
vec!["localhost".into()]
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
struct Config {
|
||||
https_listen_address: SocketAddr,
|
||||
http_listen_address: Option<SocketAddr>,
|
||||
@@ -41,7 +41,7 @@ struct Config {
|
||||
cert_alt_names: Vec<String>,
|
||||
mumble_server_url: String,
|
||||
mumble_server_address: Option<SocketAddr>,
|
||||
gui_path: PathBuf,
|
||||
gui_path: Option<PathBuf>,
|
||||
gui: Mutex<GuiConfig>,
|
||||
}
|
||||
|
||||
@@ -52,8 +52,15 @@ static CONFIG: OnceCell<Config> = 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<u8>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ConfigCraft {
|
||||
client_config: MumbleClientConfig,
|
||||
client_config: GuiConfig,
|
||||
}
|
||||
|
||||
#[craft]
|
||||
impl ConfigCraft {
|
||||
#[craft(handler)]
|
||||
async fn get_config(&self) -> Json<MumbleClientConfig> {
|
||||
async fn get_config(&self) -> Json<GuiConfig> {
|
||||
Json(self.client_config.clone())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user