summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli/src
diff options
context:
space:
mode:
Diffstat (limited to 'mullvad-cli/src')
-rw-r--r--mullvad-cli/src/cmds/mod.rs4
-rw-r--r--mullvad-cli/src/cmds/reset.rs44
2 files changed, 48 insertions, 0 deletions
diff --git a/mullvad-cli/src/cmds/mod.rs b/mullvad-cli/src/cmds/mod.rs
index 83bfd47883..8caf26eac5 100644
--- a/mullvad-cli/src/cmds/mod.rs
+++ b/mullvad-cli/src/cmds/mod.rs
@@ -28,6 +28,9 @@ pub use self::relay::Relay;
mod lan;
pub use self::lan::Lan;
+mod reset;
+pub use self::reset::Reset;
+
mod tunnel;
pub use self::tunnel::Tunnel;
@@ -45,6 +48,7 @@ pub fn get_commands() -> HashMap<&'static str, Box<dyn Command>> {
Box::new(Disconnect),
Box::new(Lan),
Box::new(Relay),
+ Box::new(Reset),
Box::new(Status),
Box::new(Tunnel),
Box::new(Version),
diff --git a/mullvad-cli/src/cmds/reset.rs b/mullvad-cli/src/cmds/reset.rs
new file mode 100644
index 0000000000..d859d1e436
--- /dev/null
+++ b/mullvad-cli/src/cmds/reset.rs
@@ -0,0 +1,44 @@
+use crate::{new_rpc_client, Command, Result};
+use std::io::stdin;
+
+pub struct Reset;
+impl Command for Reset {
+ fn name(&self) -> &'static str {
+ "factory-reset"
+ }
+
+ fn clap_subcommand(&self) -> clap::App<'static, 'static> {
+ clap::SubCommand::with_name(self.name()).about("Reset settings, caches and logs")
+ }
+
+ fn run(&self, _matches: &clap::ArgMatches<'_>) -> Result<()> {
+ let mut rpc = new_rpc_client()?;
+ if Self::receive_confirmation() {
+ if rpc.factory_reset().is_err() {
+ eprintln!("FAILED TO PERFORM FACTORY RESET");
+ } else {
+ #[cfg(target_os = "linux")]
+ println!("If you're running systemd, to remove all logs, you must use journalctl");
+ }
+ }
+ Ok(())
+ }
+}
+
+impl Reset {
+ fn receive_confirmation() -> bool {
+ println!("Are you sure you want to disconnect, log out, delete all settings, logs and cache files for the Mullvad VPN system service? [Yes/No (default)]");
+ loop {
+ let mut buf = String::new();
+ if let Err(e) = stdin().read_line(&mut buf) {
+ eprintln!("Couldn't read from STDIN - {}", e);
+ return false;
+ }
+ match buf.trim() {
+ "Yes" => return true,
+ "No" | "no" | "" => return false,
+ _ => println!("Unexpected response. Please enter \"Yes\" or \"No\""),
+ }
+ }
+ }
+}