支持wg
This commit is contained in:
@@ -75,6 +75,7 @@ pub fn parse_args_config() -> anyhow::Result<Option<(Config, Vec<String>, bool)>
|
||||
opts.optopt("f", "", "配置文件", "<conf>");
|
||||
opts.optopt("", "compressor", "压缩算法", "<lz4>");
|
||||
opts.optflag("", "disable-stats", "关闭流量统计");
|
||||
opts.optflag("", "allow-wg", "允许接入WireGuard");
|
||||
//"后台运行时,查看其他设备列表"
|
||||
opts.optflag("", "add", "后台运行时,添加地址");
|
||||
opts.optflag("", "list", "后台运行时,查看其他设备列表");
|
||||
@@ -281,6 +282,7 @@ pub fn parse_args_config() -> anyhow::Result<Option<(Config, Vec<String>, bool)>
|
||||
let port_mapping_list = matches.opt_strs("mapping");
|
||||
let vnt_mapping_list = matches.opt_strs("vnt-mapping");
|
||||
let disable_stats = matches.opt_present("disable-stats");
|
||||
let allow_wire_guard = matches.opt_present("allow-wg");
|
||||
let compressor = if let Some(compressor) = matches.opt_str("compressor").as_ref() {
|
||||
Compressor::from_str(compressor)
|
||||
.map_err(|e| anyhow!("{}", e))
|
||||
@@ -321,6 +323,7 @@ pub fn parse_args_config() -> anyhow::Result<Option<(Config, Vec<String>, bool)>
|
||||
port_mapping_list,
|
||||
compressor,
|
||||
!disable_stats,
|
||||
allow_wire_guard,
|
||||
) {
|
||||
Ok(config) => config,
|
||||
Err(e) => {
|
||||
@@ -435,6 +438,7 @@ fn print_usage(program: &str, _opts: Options) {
|
||||
)
|
||||
);
|
||||
println!(" --disable-stats 关闭流量统计");
|
||||
println!(" --allow-wg 允许接入WireGuard客户端");
|
||||
println!();
|
||||
#[cfg(feature = "command")]
|
||||
{
|
||||
|
||||
@@ -45,6 +45,7 @@ pub struct DeviceItem {
|
||||
pub client_secret_hash: Vec<u8>,
|
||||
pub current_client_secret: bool,
|
||||
pub current_client_secret_hash: Vec<u8>,
|
||||
pub wire_guard: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Default)]
|
||||
|
||||
@@ -219,6 +219,7 @@ pub fn command_list(vnt: &Vnt) -> Vec<DeviceItem> {
|
||||
client_secret_hash: peer.client_secret_hash,
|
||||
current_client_secret,
|
||||
current_client_secret_hash: client_encrypt_hash.to_vec(),
|
||||
wire_guard: peer.wireguard,
|
||||
};
|
||||
list.push(item);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,8 @@ pub struct FileConfig {
|
||||
pub compressor: Option<String>,
|
||||
pub vnt_mapping: Vec<String>,
|
||||
pub disable_stats: bool,
|
||||
// 允许传递wg流量
|
||||
pub allow_wire_guard: bool,
|
||||
}
|
||||
|
||||
impl Default for FileConfig {
|
||||
@@ -90,6 +92,7 @@ impl Default for FileConfig {
|
||||
compressor: None,
|
||||
vnt_mapping: vec![],
|
||||
disable_stats: false,
|
||||
allow_wire_guard: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -177,6 +180,7 @@ pub fn read_config(file_path: &str) -> anyhow::Result<(Config, Vec<String>, bool
|
||||
file_conf.mapping,
|
||||
compressor,
|
||||
!file_conf.disable_stats,
|
||||
file_conf.allow_wire_guard,
|
||||
)?;
|
||||
|
||||
Ok((config, file_conf.vnt_mapping, file_conf.cmd))
|
||||
|
||||
@@ -132,15 +132,21 @@ pub fn console_device_list(mut list: Vec<DeviceItem>) {
|
||||
("Rt".to_string(), Style::new()),
|
||||
]);
|
||||
for item in list {
|
||||
let name = if item.wire_guard {
|
||||
format!("{}(wg)", item.name)
|
||||
} else {
|
||||
item.name
|
||||
};
|
||||
if &item.status == "Online" {
|
||||
if item.client_secret != item.current_client_secret
|
||||
|| (!item.current_client_secret_hash.is_empty()
|
||||
&& !item.client_secret_hash.is_empty()
|
||||
&& item.current_client_secret_hash != item.client_secret_hash)
|
||||
if !item.wire_guard
|
||||
&& (item.client_secret != item.current_client_secret
|
||||
|| (!item.current_client_secret_hash.is_empty()
|
||||
&& !item.client_secret_hash.is_empty()
|
||||
&& item.current_client_secret_hash != item.client_secret_hash))
|
||||
{
|
||||
//加密状态不一致,无法通信的
|
||||
out_list.push(vec![
|
||||
(item.name, Style::new().red()),
|
||||
(name, Style::new().red()),
|
||||
(item.virtual_ip, Style::new().red()),
|
||||
(item.status, Style::new().red()),
|
||||
("Mismatch".to_string(), Style::new().red()),
|
||||
@@ -149,7 +155,7 @@ pub fn console_device_list(mut list: Vec<DeviceItem>) {
|
||||
} else {
|
||||
if item.nat_traversal_type.contains("p2p") {
|
||||
out_list.push(vec![
|
||||
(item.name, Style::new().green()),
|
||||
(name, Style::new().green()),
|
||||
(item.virtual_ip, Style::new().green()),
|
||||
(item.status, Style::new().green()),
|
||||
(item.nat_traversal_type, Style::new().green()),
|
||||
@@ -157,7 +163,7 @@ pub fn console_device_list(mut list: Vec<DeviceItem>) {
|
||||
]);
|
||||
} else {
|
||||
out_list.push(vec![
|
||||
(item.name, Style::new().yellow()),
|
||||
(name, Style::new().yellow()),
|
||||
(item.virtual_ip, Style::new().yellow()),
|
||||
(item.status, Style::new().yellow()),
|
||||
(item.nat_traversal_type, Style::new().yellow()),
|
||||
@@ -167,7 +173,7 @@ pub fn console_device_list(mut list: Vec<DeviceItem>) {
|
||||
}
|
||||
} else {
|
||||
out_list.push(vec![
|
||||
(item.name, Style::new().color256(102)),
|
||||
(name, Style::new().color256(102)),
|
||||
(item.virtual_ip, Style::new().color256(102)),
|
||||
(item.status, Style::new().color256(102)),
|
||||
("".to_string(), Style::new().color256(102)),
|
||||
|
||||
Reference in New Issue
Block a user