shared(prompts): add consent prompt for public IP query

Closes #73
This commit is contained in:
Jake McGinty 2021-05-10 04:39:46 +09:00
parent 8a021a3674
commit 3cb766f795
2 changed files with 12 additions and 12 deletions

View file

@ -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<P: AsRef<Path>>(
@ -26,7 +24,7 @@ fn create_database<P: AsRef<Path>>(
pub struct InitializeOpts {
/// The network name (ex: evilcorp)
#[structopt(long)]
pub network_name: Option<Hostname>,
pub network_name: Option<InterfaceName>,
/// 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 {

View file

@ -357,13 +357,18 @@ pub fn set_listen_port(
pub fn ask_endpoint() -> Result<Endpoint, Error> {
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")