From 0498b55d39edbdc697f18f29454f2650b050c619 Mon Sep 17 00:00:00 2001 From: m1m1sha <18262227804@163.com> Date: Wed, 8 May 2024 14:47:22 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20custom=20hostname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 3 ++- easytier-gui/locales/cn.yml | 1 + easytier-gui/locales/en.yml | 1 + easytier-gui/src-tauri/src/main.rs | 2 ++ easytier-gui/src/components/Config.vue | 20 ++++++++++++++++++ easytier-gui/src/types/network.ts | 1 + easytier/Cargo.toml | 2 ++ easytier/src/common/config.rs | 17 +++++++++++++++ easytier/src/common/global_ctx.rs | 29 +++++++++++++++++++------- easytier/src/easytier-core.rs | 23 ++++++++++++++++++++ 10 files changed, 91 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3dc6e30..5bb95a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -387,7 +387,7 @@ dependencies = [ [[package]] name = "boringtun" version = "0.6.0" -source = "git+https://github.com/KKRainbow/boringtun.git#449204c3eca736dc23b075d81426527a357e2f2a" +source = "git+https://github.com/EasyTier/boringtun.git#449204c3eca736dc23b075d81426527a357e2f2a" dependencies = [ "aead", "atomic-shim", @@ -1309,6 +1309,7 @@ dependencies = [ "quinn", "rand 0.8.5", "rcgen", + "regex", "reqwest", "ring 0.17.8", "rstest", diff --git a/easytier-gui/locales/cn.yml b/easytier-gui/locales/cn.yml index 4e6be22..aa2ce02 100644 --- a/easytier-gui/locales/cn.yml +++ b/easytier-gui/locales/cn.yml @@ -32,6 +32,7 @@ settings: 设置 exchange_language: Switch to English exit: 退出 chips_placeholder: 例如: {0}, 按回车添加 +hostname_placeholder: 留空默认为设备名称 off_text: 点击关闭 on_text: 点击开启 show_config: 显示配置 diff --git a/easytier-gui/locales/en.yml b/easytier-gui/locales/en.yml index 6c80c27..7221c0e 100644 --- a/easytier-gui/locales/en.yml +++ b/easytier-gui/locales/en.yml @@ -33,6 +33,7 @@ exchange_language: 切换中文 exit: Exit chips_placeholder: 'e.g: {0}, press Enter to add' +hostname_placeholder: Leave blank and default to device name off_text: Press to disable on_text: Press to enable show_config: Show Config diff --git a/easytier-gui/src-tauri/src/main.rs b/easytier-gui/src-tauri/src/main.rs index ad4a472..6124ee5 100644 --- a/easytier-gui/src-tauri/src/main.rs +++ b/easytier-gui/src-tauri/src/main.rs @@ -42,6 +42,7 @@ struct NetworkConfig { instance_id: String, virtual_ipv4: String, + hostname: Option, network_name: String, network_secret: String, networking_method: NetworkingMethod, @@ -70,6 +71,7 @@ impl NetworkConfig { .parse() .with_context(|| format!("failed to parse instance id: {}", self.instance_id))?, ); + cfg.set_hostname(self.hostname.clone()); cfg.set_inst_name(self.network_name.clone()); cfg.set_network_identity(NetworkIdentity::new( self.network_name.clone(), diff --git a/easytier-gui/src/components/Config.vue b/easytier-gui/src/components/Config.vue index 947a1a8..0a65ca3 100644 --- a/easytier-gui/src/components/Config.vue +++ b/easytier-gui/src/components/Config.vue @@ -32,6 +32,18 @@ const curNetwork = computed(() => { const presetPublicServers = [ 'tcp://easytier.public.kkrainbow.top:11010', ] + +function validateHostname() { + if (curNetwork.value.hostname) { + // eslint no-useless-escape + let name = curNetwork.value.hostname!.replaceAll(/[^\u4E00-\u9FA5a-zA-Z0-9\-]*/g, '') + if (name.length > 32) + name = name.substring(0, 32) + + if (curNetwork.value.hostname !== name) + curNetwork.value.hostname = name + } +}