diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-12-19 14:47:56 +0100 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-12-20 15:19:24 +0100 |
| commit | a9077776f7ac2f585b74d3ee033e56ec9cabac25 (patch) | |
| tree | 919eded0ac7ee43678592e3cbec449596d00a626 /mullvad-cli/src/cmds | |
| parent | 1dfe880b2b730e70ada710307e3d3a4c9c6a13d0 (diff) | |
| download | mullvadvpn-a9077776f7ac2f585b74d3ee033e56ec9cabac25.tar.xz mullvadvpn-a9077776f7ac2f585b74d3ee033e56ec9cabac25.zip | |
Add allow_lan support to the CLI
Diffstat (limited to 'mullvad-cli/src/cmds')
| -rw-r--r-- | mullvad-cli/src/cmds/lan.rs | 55 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/mod.rs | 4 |
2 files changed, 59 insertions, 0 deletions
diff --git a/mullvad-cli/src/cmds/lan.rs b/mullvad-cli/src/cmds/lan.rs new file mode 100644 index 0000000000..29ab264de2 --- /dev/null +++ b/mullvad-cli/src/cmds/lan.rs @@ -0,0 +1,55 @@ +use {Command, Result}; +use clap; +use rpc; + +pub struct Lan; + +impl Command for Lan { + fn name(&self) -> &'static str { + "lan" + } + + fn clap_subcommand(&self) -> clap::App<'static, 'static> { + clap::SubCommand::with_name(self.name()) + .about("Control the allow local network sharing setting") + .setting(clap::AppSettings::SubcommandRequired) + .subcommand( + clap::SubCommand::with_name("set") + .about("Change allow LAN setting") + .arg( + clap::Arg::with_name("policy") + .required(true) + .possible_values(&["allow", "block"]), + ), + ) + .subcommand( + clap::SubCommand::with_name("get") + .about("Display the current local network sharing setting"), + ) + } + + fn run(&self, matches: &clap::ArgMatches) -> Result<()> { + if let Some(set_matches) = matches.subcommand_matches("set") { + let allow_lan = value_t_or_exit!(set_matches.value_of("policy"), String); + self.set(allow_lan == "allow") + } else if let Some(_matches) = matches.subcommand_matches("get") { + self.get() + } else { + unreachable!("No lan command given"); + } + } +} + +impl Lan { + fn set(&self, allow_lan: bool) -> Result<()> { + rpc::call("set_allow_lan", &[allow_lan]).map(|_: Option<()>| { + println!("Changed local network sharing setting"); + }) + } + + fn get(&self) -> Result<()> { + let allow_lan: bool = rpc::call("get_allow_lan", &[] as &[u8; 0])?; + println!("Local network sharing setting: {}", if allow_lan { "allow" } else { "block" }); + Ok(()) + } +} diff --git a/mullvad-cli/src/cmds/mod.rs b/mullvad-cli/src/cmds/mod.rs index 1c10fa81c2..0caa5179e7 100644 --- a/mullvad-cli/src/cmds/mod.rs +++ b/mullvad-cli/src/cmds/mod.rs @@ -19,6 +19,9 @@ pub use self::relay::Relay; mod shutdown; pub use self::shutdown::Shutdown; +mod lan; +pub use self::lan::Lan; + /// Returns a map of all available subcommands with their name as key. pub fn get_commands() -> HashMap<&'static str, Box<Command>> { let commands: Vec<Box<Command>> = vec![ @@ -28,6 +31,7 @@ pub fn get_commands() -> HashMap<&'static str, Box<Command>> { Box::new(Disconnect), Box::new(Shutdown), Box::new(Relay), + Box::new(Lan), ]; let mut map = HashMap::new(); for cmd in commands { |
