summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli/src
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2018-11-13 10:54:11 +0100
committerLinus Färnstrand <linus@mullvad.net>2018-11-13 13:34:09 +0100
commit968dd55f5ada6962643923bb85db581235faec65 (patch)
tree7d10a0990a9f3e6ac5566fe7cc343804d897e89a /mullvad-cli/src
parentf048c66ab3672b32098158f97a56ac6a0717c976 (diff)
downloadmullvadvpn-968dd55f5ada6962643923bb85db581235faec65.tar.xz
mullvadvpn-968dd55f5ada6962643923bb85db581235faec65.zip
Add block-when-disconnected to CLI
Diffstat (limited to 'mullvad-cli/src')
-rw-r--r--mullvad-cli/src/cmds/block_when_disconnected.rs63
-rw-r--r--mullvad-cli/src/cmds/mod.rs8
2 files changed, 69 insertions, 2 deletions
diff --git a/mullvad-cli/src/cmds/block_when_disconnected.rs b/mullvad-cli/src/cmds/block_when_disconnected.rs
new file mode 100644
index 0000000000..23ba31ebb1
--- /dev/null
+++ b/mullvad-cli/src/cmds/block_when_disconnected.rs
@@ -0,0 +1,63 @@
+use clap::{self, value_t_or_exit};
+use crate::{new_rpc_client, Command, Result};
+
+pub struct BlockWhenDisconnected;
+
+impl Command for BlockWhenDisconnected {
+ fn name(&self) -> &'static str {
+ "block-when-disconnected"
+ }
+
+ fn clap_subcommand(&self) -> clap::App<'static, 'static> {
+ clap::SubCommand::with_name(self.name())
+ .about("Control if the system service should block network access when disconnected from VPN")
+ .setting(clap::AppSettings::SubcommandRequired)
+ .subcommand(
+ clap::SubCommand::with_name("set")
+ .about("Change the block when disconnected setting")
+ .arg(
+ clap::Arg::with_name("policy")
+ .required(true)
+ .possible_values(&["on", "off"]),
+ ),
+ )
+ .subcommand(
+ clap::SubCommand::with_name("get")
+ .about("Display the current block when disconnected setting"),
+ )
+ }
+
+ fn run(&self, matches: &clap::ArgMatches) -> Result<()> {
+ if let Some(set_matches) = matches.subcommand_matches("set") {
+ let block_when_disconnected = value_t_or_exit!(set_matches.value_of("policy"), String);
+ self.set(block_when_disconnected == "on")
+ } else if let Some(_matches) = matches.subcommand_matches("get") {
+ self.get()
+ } else {
+ unreachable!("No block-when-disconnected command given");
+ }
+ }
+}
+
+impl BlockWhenDisconnected {
+ fn set(&self, block_when_disconnected: bool) -> Result<()> {
+ let mut rpc = new_rpc_client()?;
+ rpc.set_block_when_disconnected(block_when_disconnected)?;
+ println!("Changed block when disconnected setting");
+ Ok(())
+ }
+
+ fn get(&self) -> Result<()> {
+ let mut rpc = new_rpc_client()?;
+ let block_when_disconnected = rpc.get_settings()?.get_block_when_disconnected();
+ println!(
+ "Network traffic will be {} when the VPN is disconnected",
+ if block_when_disconnected {
+ "blocked"
+ } else {
+ "allowed"
+ }
+ );
+ Ok(())
+ }
+}
diff --git a/mullvad-cli/src/cmds/mod.rs b/mullvad-cli/src/cmds/mod.rs
index e80ef875a5..0a16b952f4 100644
--- a/mullvad-cli/src/cmds/mod.rs
+++ b/mullvad-cli/src/cmds/mod.rs
@@ -16,6 +16,9 @@ pub use self::connect::Connect;
mod disconnect;
pub use self::disconnect::Disconnect;
+mod block_when_disconnected;
+pub use self::block_when_disconnected::BlockWhenDisconnected;
+
mod relay;
pub use self::relay::Relay;
@@ -33,11 +36,12 @@ pub fn get_commands() -> HashMap<&'static str, Box<Command>> {
let commands: Vec<Box<Command>> = vec![
Box::new(Account),
Box::new(AutoConnect),
- Box::new(Status),
+ Box::new(BlockWhenDisconnected),
Box::new(Connect),
Box::new(Disconnect),
- Box::new(Relay),
Box::new(Lan),
+ Box::new(Relay),
+ Box::new(Status),
Box::new(Tunnel),
Box::new(Version),
];