make proxy part of the project structure

This commit is contained in:
2024-11-11 14:35:04 -07:00
parent efe842f671
commit 80aedc7269
8 changed files with 747 additions and 46 deletions
Generated
+705 -23
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,6 +1,6 @@
[workspace] [workspace]
resolver = "2" resolver = "2"
members = [ "common","gui"] members = [ "common","gui", "proxy"]
[workspace.dependencies] [workspace.dependencies]
serde = { version = "1.0.214", features = ["derive"] } serde = { version = "1.0.214", features = ["derive"] }
+23
View File
@@ -0,0 +1,23 @@
# GUI Development
## Running Desktop
1. `dx build -p mumble-web2-gui --platform desktop`
## Running Web
1. `cargo install dioxus-cli --version 0.6.0-alpha.4`
2. `cargo install cargo install wtransport --example gencert`
3. in the proxy directory:
1. `cp config.toml.example config.toml`
2. run `gencert` and copy the certificate hash into config.toml
3. `cargo run -p mumble-web2-proxy` in the background
## with `dx serve`
4. in the gui directory
1. `export 'MUMBLE_WEB2_GUI_CONFIG={"cert_hash": <CERTIFICATE HASH HERE>, "proxy_url": "https://localhost:4433"}'`
2. `dx serve -p mumble-web2-gui --platform web`
5. connect to `localhost:8080` (most common)
## with `mumble-web2-proxy` only
4. in the gui directory:
1. `dx build -p mumble-web2-gui --platform web`
5. connect to `localhost:4434` (most common)
+1 -1
View File
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Default)] #[derive(Clone, Deserialize, Serialize, Default)]
pub struct GuiConfig { pub struct GuiConfig {
#[serde(default)] #[serde(default)]
pub force_proxy: bool, pub force_proxy: bool,
-1
View File
@@ -1,4 +1,3 @@
/target
cert.pem cert.pem
key.pem key.pem
bundle bundle
+3 -4
View File
@@ -1,12 +1,10 @@
[package] [package]
name = "mumble-webtransport-proxy" name = "mumble-web2-proxy"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
anyhow = "1.0.86" color-eyre = "0.6.3"
axum = "0.7.7" axum = "0.7.7"
axum-server = { version = "0.7.1", features = ["tls-rustls"] } axum-server = { version = "0.7.1", features = ["tls-rustls"] }
lazy_static = "1.4.0" lazy_static = "1.4.0"
@@ -21,3 +19,4 @@ tower-http = { version = "0.6.1", features = ["fs"] }
tracing = { version = "0.1.40", features = ["async-await"] } tracing = { version = "0.1.40", features = ["async-await"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
wtransport = "0.1.13" wtransport = "0.1.13"
mumble-web2-common = { workspace = true }
+4 -3
View File
@@ -3,9 +3,10 @@ http_listen_address = "127.0.0.1:4434"
cert_path = "./cert.pem" cert_path = "./cert.pem"
key_path = "./key.pem" key_path = "./key.pem"
mumble_server_url = "voip.ohea.xyz:64738" mumble_server_url = "voip.ohea.xyz:64738"
gui_path = "../mumble-web2/dist" gui_path = "../gui/dist"
serve_https = true serve_https = false
[gui] [gui]
proxy_url = "https://voip2.ohea.xyz" force_proxy = true
proxy_url = "https://localhost:4433"
# cert_hash = [...] # cert_hash = [...]
+10 -13
View File
@@ -1,8 +1,9 @@
use anyhow::{anyhow, Context, Result};
use axum::extract::State; use axum::extract::State;
use axum::http::{Response, StatusCode}; use axum::http::{Response, StatusCode};
use axum::response::IntoResponse; use axum::response::IntoResponse;
use serde::{Deserialize, Serialize}; use color_eyre::eyre::{anyhow, Context, Error, Result};
use mumble_web2_common::GuiConfig;
use serde::Deserialize;
use std::future::IntoFuture; use std::future::IntoFuture;
use std::net::{SocketAddr, ToSocketAddrs}; use std::net::{SocketAddr, ToSocketAddrs};
use std::path::PathBuf; use std::path::PathBuf;
@@ -88,18 +89,12 @@ impl ServerCertVerifier for NoCertificateVerification {
} }
} }
#[derive(Clone, Deserialize, Serialize)]
struct GuiConfig {
proxy_url: Option<String>,
cert_hash: Option<Vec<u8>>,
}
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize)]
struct Config { struct Config {
proxy_listen_address: SocketAddr, proxy_listen_address: SocketAddr,
http_listen_address: SocketAddr, http_listen_address: SocketAddr,
cert_path: String, cert_path: PathBuf,
key_path: String, key_path: PathBuf,
#[serde(default)] #[serde(default)]
serve_https: bool, serve_https: bool,
mumble_server_url: String, mumble_server_url: String,
@@ -133,7 +128,7 @@ async fn serve_index_html_with_config(State(config): State<Config>) -> impl Into
.into_response() .into_response()
} }
fn configure_tls(config: &Config) -> Result<rustls::ServerConfig, anyhow::Error> { fn configure_tls(config: &Config) -> Result<rustls::ServerConfig, Error> {
// Thanks perplexity! // Thanks perplexity!
use rustls_pemfile::{certs, pkcs8_private_keys}; use rustls_pemfile::{certs, pkcs8_private_keys};
use std::fs::File; use std::fs::File;
@@ -143,12 +138,14 @@ fn configure_tls(config: &Config) -> Result<rustls::ServerConfig, anyhow::Error>
//(rustls::server::NoClientAuth::new()); //(rustls::server::NoClientAuth::new());
// Read the certificate file // Read the certificate file
let cert_file = File::open(&config.cert_path)?; let cert_file = File::open(&config.cert_path)
.context(format!("opening cert {}", config.cert_path.display()))?;
let mut cert_reader = BufReader::new(cert_file); let mut cert_reader = BufReader::new(cert_file);
let cert_chain = certs(&mut cert_reader).collect::<Result<_, _>>()?; let cert_chain = certs(&mut cert_reader).collect::<Result<_, _>>()?;
// Read the private key file // Read the private key file
let key_file = File::open(&config.key_path)?; let key_file = File::open(&config.key_path)
.context(format!("opening key {}", config.key_path.display()))?;
let mut key_reader = BufReader::new(key_file); let mut key_reader = BufReader::new(key_file);
let key = pkcs8_private_keys(&mut key_reader) let key = pkcs8_private_keys(&mut key_reader)
.next() .next()