diff --git a/Cargo.lock b/Cargo.lock index e98415e..f9cafe8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -141,6 +141,7 @@ dependencies = [ "sha2", "tokio", "tonic", + "tower-http", "urlencoding", "x509-parser", ] @@ -1078,6 +1079,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-range-header" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9171a2ea8a68358193d15dd5d70c1c10a2afc3e7e4c5bc92bc9f025cebd7359c" + [[package]] name = "httparse" version = "1.9.5" @@ -1617,6 +1624,16 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -3167,14 +3184,24 @@ checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2" dependencies = [ "bitflags 2.8.0", "bytes", + "futures-core", "futures-util", "http", "http-body", + "http-body-util", + "http-range-header", + "httpdate", "iri-string", + "mime", + "mime_guess", + "percent-encoding", "pin-project-lite", + "tokio", + "tokio-util", "tower", "tower-layer", "tower-service", + "tracing", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 61da961..17f2905 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,4 +47,6 @@ lazy_static = "1.5.0" #openssl = "0.10.73" x509-parser = "0.17.0" rustls-pemfile = "2.2.0" +tower-http = { version = "0.6.6", features = ["fs"] } + diff --git a/README.md b/README.md index 1ea19bc..4e47ee7 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,8 @@ Built on Rust, on top of **Cloudflare’s Pingora engine**, **Aralez** delivers | **hc_method** | HEAD | Healthcheck method (HEAD, GET, POST are supported) UPPERCASE | | **hc_interval** | 2 | Interval for health checks in seconds | | **master_key** | 5aeff7f9-7b94-447c-af60-e8c488544a3e | Master key for working with API server and JWT Secret generation | +| **file_server_folder** | /some/local/folder | Optional, local folder to serve | +| **file_server_address** | 127.0.0.1:3002 | Optional, Local address for file server. Can set as upstream for public access | ### 🌐 `upstreams.yaml` diff --git a/etc/main.yaml b/etc/main.yaml index 526c059..a25ed2e 100644 --- a/etc/main.yaml +++ b/etc/main.yaml @@ -1,7 +1,7 @@ # Main configuration file , applied on startup threads: 12 # Nubber of daemon threads default setting -#user: pastor # Username for running aralez after dropping root privileges, requires program to start as root -#group: pastor # Group for running aralez after dropping root privileges, requires program to start as root +#user: aralez # Username for running aralez after dropping root privileges, requires program to start as root +#group: aralez # Group for running aralez after dropping root privileges, requires program to start as root daemon: false # Run in background upstream_keepalive_pool_size: 500 # Pool size for upstream keepalive connections pid_file: /tmp/aralez.pid # Path to PID file @@ -13,8 +13,10 @@ config_tls_certificate: etc/server.crt # Mandatory if config_tls_address is set config_tls_key_file: etc/key.pem # Mandatory if config_tls_address is set proxy_address_http: 0.0.0.0:6193 # Proxy HTTP bind address proxy_address_tls: 0.0.0.0:6194 # Optional, Proxy TLS bind address -proxy_certificates: etc/yoyo # Mandatory if proxy_address_tls set, should contain certificate and key files strictly in a format {NAME}.crt, {NAME}.key. +proxy_certificates: etc/certificates # Mandatory if proxy_address_tls set, should contain certificate and key files strictly in a format {NAME}.crt, {NAME}.key. upstreams_conf: etc/upstreams.yaml # the location of upstreams file +#file_server_folder: /some/path # Optional, local folder to serve +#file_server_address: 127.0.0.1:3002 # Optional, Local address for file server. Can set as upstream for public access. log_level: info # info, warn, error, debug, trace, off hc_method: HEAD # Healthcheck method (HEAD, GET, POST are supported) UPPERCASE hc_interval: 2 #Interval for health checks in seconds diff --git a/src/utils/discovery.rs b/src/utils/discovery.rs index 2a8e001..58467ce 100644 --- a/src/utils/discovery.rs +++ b/src/utils/discovery.rs @@ -14,6 +14,8 @@ pub struct APIUpstreamProvider { pub tls_address: Option, pub tls_certificate: Option, pub tls_key_file: Option, + pub file_server_address: Option, + pub file_server_folder: Option, } pub struct ConsulProvider { diff --git a/src/utils/parceyaml.rs b/src/utils/parceyaml.rs index a97c6c7..4a4754c 100644 --- a/src/utils/parceyaml.rs +++ b/src/utils/parceyaml.rs @@ -150,15 +150,5 @@ pub fn parce_main_config(path: &str) -> AppConfig { } } }; - // match cfo.config_tls_address.clone() { - // Some(tls_cert) => { - // if let Some((ip, port_str)) = tls_cert.split_once(':') { - // if let Ok(port) = port_str.parse::() { - // cfo.local_tls_server = Option::from((ip.to_string(), port)); - // } - // } - // } - // None => {} - // }; cfo } diff --git a/src/utils/structs.rs b/src/utils/structs.rs index b31b380..c1dd26d 100644 --- a/src/utils/structs.rs +++ b/src/utils/structs.rs @@ -75,4 +75,6 @@ pub struct AppConfig { pub proxy_port_tls: Option, pub local_server: Option<(String, u16)>, pub proxy_certificates: Option, + pub file_server_address: Option, + pub file_server_folder: Option, } diff --git a/src/web/bgservice.rs b/src/web/bgservice.rs index eb4871e..e213ba7 100644 --- a/src/web/bgservice.rs +++ b/src/web/bgservice.rs @@ -39,6 +39,8 @@ impl BackgroundService for LB { tls_address: self.config.config_tls_address.clone(), tls_certificate: self.config.config_tls_certificate.clone(), tls_key_file: self.config.config_tls_key_file.clone(), + file_server_address: self.config.file_server_address.clone(), + file_server_folder: self.config.file_server_folder.clone(), }; let tx_api = tx.clone(); let _ = tokio::spawn(async move { api_load.start(tx_api).await }); diff --git a/src/web/proxyhttp.rs b/src/web/proxyhttp.rs index 6f80724..a31880d 100644 --- a/src/web/proxyhttp.rs +++ b/src/web/proxyhttp.rs @@ -79,26 +79,6 @@ impl ProxyHttp for LB { match ddr { Some((address, port, ssl, is_h2, to_https)) => { let mut peer = Box::new(HttpPeer::new((address.clone(), port.clone()), ssl, String::new())); - /* - let key = PeerKey { - addr: address.clone(), - port: port, - ssl: ssl, - }; - - let gk = key.get_hash(); - let pooled_conn = self.connection_pool.connections.get(&gk); - match pooled_conn { - Some(conn) => { - peer = Box::from(conn); - } - None => { - let id = self.connection_pool.next_id(); - self.connection_pool.connections.put(&ConnectionMeta { key: gk, id: id }, *peer.clone()); - debug!("Added peer to pool: {}", id); - } - } - */ // if session.is_http2() { if is_h2 { peer.options.alpn = ALPN::H2; @@ -125,11 +105,6 @@ impl ProxyHttp for LB { } ctx.backend_id = format!("{}:{}:{}", address.clone(), port.clone(), ssl); - /* - ctx.peer = Some(peer.clone()); - ctx.peer_key = Some(key.clone()); - ctx.group_key = Some(gk.clone()); - */ Ok(peer) } None => { diff --git a/src/web/webserver.rs b/src/web/webserver.rs index dd015f2..cfd2da9 100644 --- a/src/web/webserver.rs +++ b/src/web/webserver.rs @@ -17,6 +17,7 @@ use std::collections::HashMap; use std::net::SocketAddr; use std::time::{Duration, SystemTime, UNIX_EPOCH}; use tokio::net::TcpListener; +use tower_http::services::ServeDir; #[derive(Deserialize)] struct InputKey { @@ -42,12 +43,14 @@ pub async fn run_server(config: &APIUpstreamProvider, mut to_return: Sender