diff --git a/backend/src/bin/embassy-init.rs b/backend/src/bin/embassy-init.rs index 507908881..ac841d446 100644 --- a/backend/src/bin/embassy-init.rs +++ b/backend/src/bin/embassy-init.rs @@ -7,7 +7,6 @@ use embassy::context::{DiagnosticContext, InstallContext, SetupContext}; use embassy::disk::fsck::RepairStrategy; use embassy::disk::main::DEFAULT_PASSWORD; use embassy::disk::REPAIR_DISK_PATH; -use embassy::hostname::get_current_ip; use embassy::init::STANDBY_MODE_PATH; use embassy::net::embassy_service_http_server::EmbassyServiceHTTPServer; #[cfg(feature = "avahi")] @@ -32,8 +31,7 @@ async fn setup_or_init(cfg_path: Option) -> Result<(), Error> { let ctx = InstallContext::init(cfg_path).await?; - let embassy_ip = get_current_ip(ctx.ethernet_interface.to_owned()).await?; - let embassy_ip_fqdn: ResourceFqdn = embassy_ip.parse()?; + let embassy_ip_fqdn: ResourceFqdn = ResourceFqdn::IpAddr; let embassy_fqdn: ResourceFqdn = "pureos.local".parse()?; let localhost_fqdn = ResourceFqdn::LocalHost; @@ -74,8 +72,7 @@ async fn setup_or_init(cfg_path: Option) -> Result<(), Error> { let ctx = SetupContext::init(cfg_path).await?; - let embassy_ip = get_current_ip(ctx.ethernet_interface.to_owned()).await?; - let embassy_ip_fqdn: ResourceFqdn = embassy_ip.parse()?; + let embassy_ip_fqdn: ResourceFqdn = ResourceFqdn::IpAddr; let embassy_fqdn: ResourceFqdn = "embassy.local".parse()?; let localhost_fqdn = ResourceFqdn::LocalHost; @@ -203,8 +200,7 @@ async fn inner_main(cfg_path: Option) -> Result, Error ) .await?; - let embassy_ip = get_current_ip(ctx.ethernet_interface.to_owned()).await?; - let embassy_ip_fqdn: ResourceFqdn = embassy_ip.parse()?; + let embassy_ip_fqdn: ResourceFqdn = ResourceFqdn::IpAddr; let embassy_fqdn: ResourceFqdn = "embassy.local".parse()?; let localhost_fqdn = ResourceFqdn::LocalHost; diff --git a/backend/src/bin/embassyd.rs b/backend/src/bin/embassyd.rs index 2d32ede0f..5487c62d3 100644 --- a/backend/src/bin/embassyd.rs +++ b/backend/src/bin/embassyd.rs @@ -187,8 +187,7 @@ fn main() { ) .await?; - let embassy_ip = get_current_ip(ctx.ethernet_interface.to_owned()).await?; - let embassy_ip_fqdn: ResourceFqdn = embassy_ip.parse()?; + let embassy_ip_fqdn: ResourceFqdn = ResourceFqdn::IpAddr; let embassy_fqdn: ResourceFqdn = "embassy.local".parse()?; let diag_ui_handler = diag_ui_file_router(ctx.clone()).await?; diff --git a/backend/src/context/cli.rs b/backend/src/context/cli.rs index 6bb2b47b3..15e29fd22 100644 --- a/backend/src/context/cli.rs +++ b/backend/src/context/cli.rs @@ -21,7 +21,6 @@ use crate::ResultExt; #[derive(Debug, Default, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct CliContextConfig { - pub bind_rpc: Option, pub host: Option, #[serde(deserialize_with = "crate::util::serde::deserialize_from_str_opt")] #[serde(default)] @@ -81,11 +80,7 @@ impl CliContext { } else if let Some(host) = base.host { host } else { - format!( - "http://{}", - base.bind_rpc.unwrap_or(([127, 0, 0, 1], 80).into()) - ) - .parse()? + format!("http://localhost").parse()? }; let proxy = if let Some(proxy) = matches.value_of("proxy") { Some(proxy.parse()?) diff --git a/backend/src/context/diagnostic.rs b/backend/src/context/diagnostic.rs index 0024f8565..9c853a4eb 100644 --- a/backend/src/context/diagnostic.rs +++ b/backend/src/context/diagnostic.rs @@ -15,7 +15,6 @@ use crate::Error; #[derive(Debug, Default, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct DiagnosticContextConfig { - pub ethernet_interface: String, pub datadir: Option, } impl DiagnosticContextConfig { @@ -44,7 +43,6 @@ impl DiagnosticContextConfig { } pub struct DiagnosticContextSeed { - pub ethernet_interface: String, pub datadir: PathBuf, pub shutdown: Sender>, pub error: Arc, @@ -68,7 +66,6 @@ impl DiagnosticContext { let (shutdown, _) = tokio::sync::broadcast::channel(1); Ok(Self(Arc::new(DiagnosticContextSeed { - ethernet_interface: cfg.ethernet_interface.clone(), datadir: cfg.datadir().to_owned(), shutdown, disk_guid, diff --git a/backend/src/context/setup.rs b/backend/src/context/setup.rs index cf64bd51c..f72eafcd6 100644 --- a/backend/src/context/setup.rs +++ b/backend/src/context/setup.rs @@ -34,7 +34,6 @@ pub struct SetupResult { #[serde(rename_all = "kebab-case")] pub struct SetupContextConfig { pub os_partitions: OsPartitionInfo, - pub ethernet_interface: String, pub migration_batch_rows: Option, pub migration_prefetch_rows: Option, pub datadir: Option, @@ -65,7 +64,6 @@ impl SetupContextConfig { pub struct SetupContextSeed { pub os_partitions: OsPartitionInfo, - pub ethernet_interface: String, pub config_path: Option, pub migration_batch_rows: usize, pub migration_prefetch_rows: usize, @@ -96,7 +94,6 @@ impl SetupContext { let datadir = cfg.datadir().to_owned(); Ok(Self(Arc::new(SetupContextSeed { os_partitions: cfg.os_partitions, - ethernet_interface: cfg.ethernet_interface, config_path: path.as_ref().map(|p| p.as_ref().to_owned()), migration_batch_rows: cfg.migration_batch_rows.unwrap_or(25000), migration_prefetch_rows: cfg.migration_prefetch_rows.unwrap_or(100_000), diff --git a/backend/src/net/net_controller.rs b/backend/src/net/net_controller.rs index 26126c545..7e4b8cb4a 100644 --- a/backend/src/net/net_controller.rs +++ b/backend/src/net/net_controller.rs @@ -115,12 +115,11 @@ impl NetController { async fn setup_embassy_http_ui_handle(rpc_ctx: RpcContext) -> Result<(), Error> { let host_name = rpc_ctx.net_controller.proxy.get_hostname().await; - let ip = get_current_ip(rpc_ctx.ethernet_interface.to_owned()).await?; - + let embassy_tor_addr = get_embassyd_tor_addr(rpc_ctx.clone()).await?; let embassy_tor_fqdn: ResourceFqdn = embassy_tor_addr.parse()?; let host_name_fqdn: ResourceFqdn = host_name.parse()?; - let ip_fqdn: ResourceFqdn = ip.parse()?; + let ip_fqdn: ResourceFqdn = ResourceFqdn::IpAddr; let localhost_fqdn = ResourceFqdn::LocalHost; diff --git a/backend/src/net/net_utils.rs b/backend/src/net/net_utils.rs index 73d97675b..97ca85999 100644 --- a/backend/src/net/net_utils.rs +++ b/backend/src/net/net_utils.rs @@ -29,7 +29,7 @@ pub fn host_addr_fqdn(req: &Request) -> Result { #[derive(Eq, PartialEq, PartialOrd, Ord, Debug, Clone)] pub enum ResourceFqdn { - IpAddr(IpAddr), + IpAddr, Uri { full_uri: String, root: String, @@ -41,9 +41,6 @@ pub enum ResourceFqdn { impl fmt::Display for ResourceFqdn { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - ResourceFqdn::IpAddr(ip) => { - write!(f, "{}", ip) - } ResourceFqdn::Uri { full_uri, root: _, @@ -52,6 +49,7 @@ impl fmt::Display for ResourceFqdn { write!(f, "{}", full_uri) } ResourceFqdn::LocalHost => write!(f, "localhost"), + ResourceFqdn::IpAddr => write!(f, "ip-address"), } } } @@ -77,12 +75,12 @@ impl FromStr for ResourceFqdn { type Err = Error; fn from_str(input: &str) -> Result { - if input == "localhost" { - return Ok(ResourceFqdn::LocalHost); + if input.parse::().is_ok() { + return Ok(ResourceFqdn::IpAddr); } - if let Ok(ip) = input.parse::() { - return Ok(ResourceFqdn::IpAddr(ip)); + if input == "localhost" { + return Ok(ResourceFqdn::LocalHost); } let hostname_split: Vec<&str> = input.split('.').collect(); diff --git a/backend/src/net/proxy_controller.rs b/backend/src/net/proxy_controller.rs index 5313e4343..1da295dcc 100644 --- a/backend/src/net/proxy_controller.rs +++ b/backend/src/net/proxy_controller.rs @@ -103,52 +103,21 @@ impl ProxyController { // Note: only after client received an empty body with STATUS_OK can the // connection be upgraded, so we can't return a response inside // `on_upgrade` future. - match host_addr_fqdn(&req) { - Ok(host) => { - tokio::task::spawn(async move { - match hyper::upgrade::on(req).await { - Ok(upgraded) => match host { - ResourceFqdn::IpAddr(ip) => { - if let Err(e) = Self::tunnel(upgraded, ip.to_string()).await { - error!("server io error: {}", e); - }; - } - ResourceFqdn::Uri { - full_uri, - root: _, - tld: _, - } => { - if let Err(e) = - Self::tunnel(upgraded, full_uri.to_string()).await - { - error!("server io error: {}", e); - }; - } - ResourceFqdn::LocalHost => { - if let Err(e) = - Self::tunnel(upgraded, "localhost".to_string()).await - { - error!("server io error: {}", e); - }; - } - }, - Err(e) => error!("upgrade error: {}", e), + + tokio::task::spawn(async move { + let addr = req.uri().clone(); + + match hyper::upgrade::on(req).await { + Ok(upgraded) => { + if let Err(e) = Self::tunnel(upgraded, addr.to_string()).await { + error!("server io error: {}", e); } - }); - - Ok(Response::new(Body::empty())) + } + Err(e) => error!("upgrade error: {}", e), } - Err(e) => { - let err_txt = format!("CONNECT host is not socket addr: {:?}", &req.uri()); - let mut resp = Response::new(Body::from(format!( - "CONNECT must be to a socket address: {}: {}", - err_txt, e - ))); - *resp.status_mut() = http::StatusCode::BAD_REQUEST; + }); - Ok(resp) - } - } + Ok(Response::new(Body::empty())) } else { client.request(req).await } @@ -221,10 +190,11 @@ impl ProxyControllerInner { pkg_id: PackageId, ) -> Result<(), Error> { let package_cert = match resource_fqdn.clone() { - ResourceFqdn::IpAddr(ip) => { - self.ssl_manager - .certificate_for(&ip.to_string(), &pkg_id) - .await? + ResourceFqdn::IpAddr => { + return Err(Error::new( + eyre!("ssl not supported for ip addresses"), + crate::ErrorKind::Network, + )) } ResourceFqdn::Uri { full_uri: _, diff --git a/backend/src/nginx/install-wizard.conf b/backend/src/nginx/install-wizard.conf deleted file mode 100644 index 9dc6634c7..000000000 --- a/backend/src/nginx/install-wizard.conf +++ /dev/null @@ -1,29 +0,0 @@ -server { - listen 80 default_server; - listen [::]:80 default_server; - - root /var/www/html/install; - - index index.html index.htm index.nginx-debian.html; - - server_name _; - - proxy_buffering off; - proxy_request_buffering off; - proxy_socket_keepalive on; - proxy_http_version 1.1; - proxy_read_timeout 1800; - - gzip on; - gzip_vary on; - gzip_min_length 1024; - gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml; - - location /rpc/ { - proxy_pass http://127.0.0.1:5959/; - } - - location / { - try_files $uri $uri/ =404; - } -} \ No newline at end of file