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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
use anyhow::Result;
use clap::Subcommand;
use mullvad_management_interface::MullvadProxyClient;
use mullvad_types::{
constraints::Constraint,
relay_constraints::{
ObfuscationSettings, SelectedObfuscation, ShadowsocksSettings, Udp2TcpObfuscationSettings,
},
};
#[derive(Subcommand, Debug)]
pub enum Obfuscation {
/// Get current obfuscation settings
Get,
/// Set obfuscation settings
#[clap(subcommand)]
Set(SetCommands),
}
#[derive(Subcommand, Debug, Clone)]
pub enum SetCommands {
/// Specify which obfuscation protocol to use, if any.
Mode { mode: SelectedObfuscation },
/// Configure udp2tcp obfuscation.
Udp2tcp {
/// Port to use, or 'any'
#[arg(long, short = 'p')]
port: Constraint<u16>,
},
/// Configure Shadowsocks obfuscation.
Shadowsocks {
/// Port to use, or 'any'
#[arg(long, short = 'p')]
port: Constraint<u16>,
},
}
impl Obfuscation {
pub async fn handle(self) -> Result<()> {
match self {
Obfuscation::Get => {
let mut rpc = MullvadProxyClient::new().await?;
let obfuscation_settings = rpc.get_settings().await?.obfuscation_settings;
println!(
"Obfuscation mode: {}",
obfuscation_settings.selected_obfuscation
);
println!("udp2tcp settings: {}", obfuscation_settings.udp2tcp);
println!("Shadowsocks settings: {}", obfuscation_settings.shadowsocks);
Ok(())
}
Obfuscation::Set(subcmd) => Self::set(subcmd).await,
}
}
async fn set(subcmd: SetCommands) -> Result<()> {
let mut rpc = MullvadProxyClient::new().await?;
let current_settings = rpc.get_settings().await?.obfuscation_settings;
match subcmd {
SetCommands::Mode { mode } => {
rpc.set_obfuscation_settings(ObfuscationSettings {
selected_obfuscation: mode,
..current_settings
})
.await?;
}
SetCommands::Udp2tcp { port } => {
rpc.set_obfuscation_settings(ObfuscationSettings {
udp2tcp: Udp2TcpObfuscationSettings { port },
..current_settings
})
.await?;
}
SetCommands::Shadowsocks { port } => {
rpc.set_obfuscation_settings(ObfuscationSettings {
shadowsocks: ShadowsocksSettings { port },
..current_settings
})
.await?;
}
}
println!("Updated obfuscation settings");
Ok(())
}
}
|