Add check command
This commit is contained in:
parent
f48b500f64
commit
1a2a96911e
1 changed files with 18 additions and 0 deletions
18
src/main.rs
18
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<Location>,
|
||||
}
|
||||
|
||||
#[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<WireguardKeyPair, anyhow::Error> {
|
||||
let privkey = process::Command::new("wg").arg("genkey").output()?.stdout;
|
||||
let mut pubkey_cmd = process::Command::new("wg")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue