blob: bd43f88a6b2a7e296b483ea64b8b78c8cf84f4c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
use crate::{new_rpc_client, Command, Result};
pub struct Lan;
#[mullvad_management_interface::async_trait]
impl Command for Lan {
fn name(&self) -> &'static str {
"lan"
}
fn clap_subcommand(&self) -> clap::App<'static> {
clap::App::new(self.name())
.about("Control the allow local network sharing setting")
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
.subcommand(
clap::App::new("set").about("Change allow LAN setting").arg(
clap::Arg::new("policy")
.required(true)
.possible_values(&["allow", "block"]),
),
)
.subcommand(
clap::App::new("get").about("Display the current local network sharing setting"),
)
}
async fn run(&self, matches: &clap::ArgMatches) -> Result<()> {
if let Some(set_matches) = matches.subcommand_matches("set") {
let allow_lan = set_matches.value_of("policy").expect("missing policy");
self.set(allow_lan == "allow").await
} else if let Some(_matches) = matches.subcommand_matches("get") {
self.get().await
} else {
unreachable!("No lan command given");
}
}
}
impl Lan {
async fn set(&self, allow_lan: bool) -> Result<()> {
let mut rpc = new_rpc_client().await?;
rpc.set_allow_lan(allow_lan).await?;
println!("Changed local network sharing setting");
Ok(())
}
async fn get(&self) -> Result<()> {
let mut rpc = new_rpc_client().await?;
let allow_lan = rpc.get_settings(()).await?.into_inner().allow_lan;
println!(
"Local network sharing setting: {}",
if allow_lan { "allow" } else { "block" }
);
Ok(())
}
}
|