diff --git a/src/main.rs b/src/main.rs index 8d75003..d1c18a0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,6 +32,7 @@ struct ConfigOpts { enum Command { Endpoints(EndpointsOpts), Config(ConfigOpts), + Check, } #[derive(Serialize, Deserialize, Debug)] @@ -53,6 +54,13 @@ struct Locations { locations: Vec, } +#[derive(Serialize, Deserialize, Debug)] +struct CheckResult { + connected: bool, + ip: String, // XXX + location: String, +} + #[derive(Serialize, Deserialize, Debug)] struct WireguardConfig { status: String, @@ -79,6 +87,7 @@ fn main() -> Result<(), anyhow::Error> { match &opts.command { Command::Endpoints(list_opts) => list(&list_opts)?, Command::Config(get_config_opts) => get_config(&get_config_opts)?, + Command::Check => check()?, } Ok(()) } @@ -145,6 +154,15 @@ AllowedIPs = 0.0.0.0/0 #, ::/0", Ok(()) } +fn check() -> Result<(), anyhow::Error> { + let url = format!("{}/check", BASE_URL); + let result: CheckResult = ureq::get(&url).call()?.into_json()?; + println!("Connected: {:?}", result.connected); + println!("IP: {}", result.ip); + println!("Location: {}", result.location); + Ok(()) +} + fn generage_keys() -> Result { let privkey = process::Command::new("wg").arg("genkey").output()?.stdout; let mut pubkey_cmd = process::Command::new("wg")