diff --git a/server/src/initialize.rs b/server/src/initialize.rs index 9b895cc..4894052 100644 --- a/server/src/initialize.rs +++ b/server/src/initialize.rs @@ -4,9 +4,7 @@ use dialoguer::{theme::ColorfulTheme, Input}; use indoc::printdoc; use publicip::Preference; use rusqlite::{params, Connection}; -use shared::{ - prompts, CidrContents, Endpoint, Hostname, PeerContents, PERSISTENT_KEEPALIVE_INTERVAL_SECS, -}; +use shared::{prompts, CidrContents, Endpoint, PeerContents, PERSISTENT_KEEPALIVE_INTERVAL_SECS}; use wgctrl::KeyPair; fn create_database>( @@ -26,7 +24,7 @@ fn create_database>( pub struct InitializeOpts { /// The network name (ex: evilcorp) #[structopt(long)] - pub network_name: Option, + pub network_name: Option, /// The network CIDR (ex: 10.42.0.0/16) #[structopt(long)] @@ -121,7 +119,7 @@ pub fn init_wizard(conf: &ServerConfig, opts: InitializeOpts) -> Result<(), Erro \n" ); - let name: Hostname = if let Some(name) = opts.network_name { + let name: InterfaceName = if let Some(name) = opts.network_name { name } else { Input::with_theme(&theme) @@ -138,9 +136,6 @@ pub fn init_wizard(conf: &ServerConfig, opts: InitializeOpts) -> Result<(), Erro .interact()? }; - // This probably won't error because of the `hostname_validator` regex. - let name = name.parse()?; - let endpoint: Endpoint = if let Some(endpoint) = opts.external_endpoint { endpoint } else if opts.auto_external_endpoint { diff --git a/shared/src/prompts.rs b/shared/src/prompts.rs index bb9bf9c..0523922 100644 --- a/shared/src/prompts.rs +++ b/shared/src/prompts.rs @@ -357,13 +357,18 @@ pub fn set_listen_port( pub fn ask_endpoint() -> Result { println!("getting external IP address."); - let external_ip = publicip::get_any(Preference::Ipv4); + let external_ip = if Confirm::with_theme(&*THEME) + .with_prompt("Auto-fill public IP address (using a DNS query to 1.1.1.1)?") + .interact()? + { + publicip::get_any(Preference::Ipv4) + } else { + None + }; let mut endpoint_builder = Input::with_theme(&*THEME); if let Some(ip) = external_ip { - endpoint_builder.default(SocketAddr::new(ip, 51820).into()); - } else { - println!("failed to get external IP."); + endpoint_builder.with_initial_text(SocketAddr::new(ip, 51820).to_string()); } endpoint_builder .with_prompt("External endpoint")