diff options
| author | Markus Pettersson <markus.pettersson@mullvad.net> | 2023-09-26 15:34:20 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2023-10-09 14:40:14 +0200 |
| commit | 532bd6d38c9cbb95b6d628dd4470f89f06025d94 (patch) | |
| tree | 2d41ef1eeed1be7aa2fe8f457813a0804d5b57f4 /mullvad-cli/src | |
| parent | 28c09203858b4d36b46a7d2c1d7af1f1fedaeb9c (diff) | |
| download | mullvadvpn-532bd6d38c9cbb95b6d628dd4470f89f06025d94.tar.xz mullvadvpn-532bd6d38c9cbb95b6d628dd4470f89f06025d94.zip | |
Split up `mullvad api-access add` command for SOCKS5-proxy
Split up `mullvad api-access add` command for SOCKS5-proxy into "local"
and "remote".
Diffstat (limited to 'mullvad-cli/src')
| -rw-r--r-- | mullvad-cli/src/cmds/api_access.rs | 112 |
1 files changed, 62 insertions, 50 deletions
diff --git a/mullvad-cli/src/cmds/api_access.rs b/mullvad-cli/src/cmds/api_access.rs index 260f0c4496..655f10a5de 100644 --- a/mullvad-cli/src/cmds/api_access.rs +++ b/mullvad-cli/src/cmds/api_access.rs @@ -193,18 +193,30 @@ impl ApiAccess { #[derive(Subcommand, Debug, Clone)] pub enum AddCustomCommands { /// Configure a local SOCKS5 proxy - Socks5Local { + #[clap(subcommand)] + Socks5(AddSocks5Commands), + /// Configure Shadowsocks proxy + Shadowsocks { /// An easy to remember name for this custom proxy name: String, - /// The port that the server on localhost is listening on - local_port: u16, - /// The IP of the remote peer + /// The IP of the remote Shadowsocks server remote_ip: IpAddr, - /// The port of the remote peer + /// The port of the remote Shadowsocks server + #[arg(default_value = "443")] remote_port: u16, + /// Password for authentication + #[arg(default_value = "mullvad")] + password: String, + /// Cipher to use + #[arg(value_parser = SHADOWSOCKS_CIPHERS, default_value = "aes-256-gcm")] + cipher: String, }, +} + +#[derive(Subcommand, Debug, Clone)] +pub enum AddSocks5Commands { /// Configure a remote SOCKS5 proxy - Socks5Remote { + Remote { /// An easy to remember name for this custom proxy name: String, /// The IP of the remote proxy server @@ -212,30 +224,27 @@ pub enum AddCustomCommands { /// The port of the remote proxy server remote_port: u16, }, - /// Configure Shadowsocks proxy - Shadowsocks { + /// Configure a local SOCKS5 proxy + Local { /// An easy to remember name for this custom proxy name: String, - /// The IP of the remote Shadowsocks server + /// The port that the server on localhost is listening on + local_port: u16, + /// The IP of the remote peer remote_ip: IpAddr, - /// The port of the remote Shadowsocks server - #[arg(default_value = "443")] + /// The port of the remote peer remote_port: u16, - /// Password for authentication - #[arg(default_value = "mullvad")] - password: String, - /// Cipher to use - #[arg(value_parser = SHADOWSOCKS_CIPHERS, default_value = "aes-256-gcm")] - cipher: String, }, } impl AddCustomCommands { fn name(&self) -> String { match self { - AddCustomCommands::Socks5Local { name, .. } => name, - AddCustomCommands::Socks5Remote { name, .. } => name, AddCustomCommands::Shadowsocks { name, .. } => name, + AddCustomCommands::Socks5(socks) => match socks { + AddSocks5Commands::Remote { name, .. } => name, + AddSocks5Commands::Local { name, .. } => name, + }, } .clone() } @@ -308,42 +317,47 @@ mod conversions { use anyhow::{anyhow, Error}; use mullvad_types::access_method as daemon_types; - use super::AddCustomCommands; + use super::{AddCustomCommands, AddSocks5Commands}; impl TryFrom<AddCustomCommands> for daemon_types::AccessMethod { type Error = Error; fn try_from(value: AddCustomCommands) -> Result<Self, Self::Error> { Ok(match value { - AddCustomCommands::Socks5Local { - local_port, - remote_ip, - remote_port, - name: _, - } => { - println!("Adding Local SOCKS5-proxy: localhost:{local_port} => {remote_ip}:{remote_port}"); - let socks_proxy = daemon_types::Socks5::Local( - daemon_types::Socks5Local::from_args( - remote_ip.to_string(), - remote_port, - local_port, - ) - .ok_or(anyhow!("Could not create a local Socks5 api proxy"))?, - ); - daemon_types::AccessMethod::from(socks_proxy) - } - AddCustomCommands::Socks5Remote { - remote_ip, - remote_port, - name: _, - } => { - println!("Adding SOCKS5-proxy: {remote_ip}:{remote_port}"); - let socks_proxy = daemon_types::Socks5::Remote( - daemon_types::Socks5Remote::from_args(remote_ip.to_string(), remote_port) + AddCustomCommands::Socks5(socks) => match socks { + AddSocks5Commands::Local { + local_port, + remote_ip, + remote_port, + name: _, + } => { + println!("Adding Local SOCKS5-proxy: localhost:{local_port} => {remote_ip}:{remote_port}"); + let socks_proxy = daemon_types::Socks5::Local( + daemon_types::Socks5Local::from_args( + remote_ip.to_string(), + remote_port, + local_port, + ) + .ok_or(anyhow!("Could not create a local Socks5 api proxy"))?, + ); + daemon_types::AccessMethod::from(socks_proxy) + } + AddSocks5Commands::Remote { + remote_ip, + remote_port, + name: _, + } => { + println!("Adding SOCKS5-proxy: {remote_ip}:{remote_port}"); + let socks_proxy = daemon_types::Socks5::Remote( + daemon_types::Socks5Remote::from_args( + remote_ip.to_string(), + remote_port, + ) .ok_or(anyhow!("Could not create a remote Socks5 api proxy"))?, - ); - daemon_types::AccessMethod::from(socks_proxy) - } + ); + daemon_types::AccessMethod::from(socks_proxy) + } + }, AddCustomCommands::Shadowsocks { remote_ip, remote_port, @@ -396,8 +410,6 @@ mod pp { } }; - writeln!(f, "{:?}", self.api_access_method)?; - match &self.api_access_method.access_method { AccessMethod::BuiltIn(method) => { write!(f, "{}", method.canonical_name())?; |
