feat: add unified Tauri desktop client and secure web access
No files matched your search
@@ -6,4 +6,8 @@ vnt_current_config.txt
|
||||
logs/*
|
||||
/.tools/
|
||||
node_modules
|
||||
vnt-web/ui/dist
|
||||
vnt-web/ui/dist
|
||||
vnt-desktop/dist
|
||||
vnt-desktop/src-tauri/gen
|
||||
vnt-desktop/src-tauri/icons/android
|
||||
vnt-desktop/src-tauri/icons/ios
|
||||
@@ -0,0 +1,5 @@
|
||||
/node_modules/
|
||||
/vnt-desktop/node_modules/
|
||||
/vnt-web/ui/node_modules/
|
||||
/vnt-desktop/dist/
|
||||
/vnt-web/static/
|
||||
@@ -6,7 +6,7 @@ edition = "2024"
|
||||
[dependencies]
|
||||
vnt-ipc = { path = "vnt-ipc", optional = true }
|
||||
vnt-web = { path = "vnt-web", optional = true }
|
||||
clap = { version = "4.5", features = ["derive"] }
|
||||
clap = { version = "4.5", features = ["derive", "env"] }
|
||||
|
||||
tokio = { workspace = true, features = ["full"] }
|
||||
|
||||
@@ -43,7 +43,7 @@ path = "src/main_web.rs"
|
||||
required-features = ["vnt-web"]
|
||||
|
||||
[workspace]
|
||||
members = ["vnt-web", "vnt-ipc", "vnt-core", "vnt-jni"]
|
||||
members = ["vnt-web", "vnt-ipc", "vnt-core", "vnt-jni", "vnt-desktop/src-tauri"]
|
||||
|
||||
[workspace.dependencies]
|
||||
vnt-core = { path = "vnt-core" }
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
1. vnt2_cli 是一个纯命令行组网工具,可以从命令行参数或配置文件快速启动组网
|
||||
2. vnt2_ctrl 和vnt2_cli搭配使用,vnt2_cli后台运行时,可以用vnt2_ctrl来获取组网状态
|
||||
3. vnt2_web 是一个集成web服务的组网工具,带web页面,可以在页面上操作组网
|
||||
4. `vnt-desktop` 是基于 Tauri 2 的 PC 客户端,内置组网服务、桌面工作台和系统托盘
|
||||
|
||||
## 使用vnt2_cli组网
|
||||
|
||||
@@ -30,20 +31,32 @@
|
||||
# 启动程序
|
||||
./vnt2_web
|
||||
```
|
||||
2. 浏览器打开 http://127.0.0.1:19099
|
||||
2. 从启动日志复制带 `?token=...` 的 Web 访问地址;也可以通过 `--token` 或 `VNT_WEB_TOKEN` 指定固定令牌
|
||||
3. 在页面上添加组网配置,再启动组网
|
||||
|
||||
## 前端构建
|
||||
|
||||
web 前端源码位于 `vnt-web/ui/`(Vite + Vue 3 + Pinia + Tailwind CSS v4),构建产物输出到 `vnt-web/static/`,由 RustEmbed 嵌入二进制。
|
||||
|
||||
项目使用根级 pnpm workspace 统一管理 Web 与桌面前端依赖:
|
||||
|
||||
```
|
||||
cd vnt-web/ui
|
||||
pnpm install
|
||||
pnpm build
|
||||
pnpm build:web
|
||||
```
|
||||
|
||||
开发调试使用 `pnpm dev`,Vite dev server 会将 `/api` 代理到 `127.0.0.1:19099`(需先启动 vnt2_web)。
|
||||
开发调试使用 `pnpm dev:web`,Vite dev server 会将 `/api` 代理到 `127.0.0.1:19099`。启动 `vnt2_web` 时应指定令牌,并在浏览器登录页输入相同令牌。
|
||||
|
||||
## PC 客户端
|
||||
|
||||
桌面客户端源码位于 `vnt-desktop/`(Tauri 2 + Vue 3)。桌面工作台通过 Tauri IPC 直接调用进程内 `vnt-core`;需要浏览器访问时,可在“Web 访问”中按需启用同进程 HTTP 服务,无需单独运行 `vnt2_web`。Tauri 与 Web 端统一使用 `vnt-web/ui/src/` 下的同一套响应式前端代码。
|
||||
|
||||
```
|
||||
pnpm install
|
||||
pnpm dev:desktop
|
||||
```
|
||||
|
||||
构建安装包使用 `pnpm build:desktop`。更多说明见 `vnt-desktop/README.md`。
|
||||
|
||||
# VNT2.0新特性
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "vnt-workspace",
|
||||
"private": true,
|
||||
"packageManager": "pnpm@10.34.5",
|
||||
"scripts": {
|
||||
"dev:web": "pnpm --filter vnt-web-ui dev",
|
||||
"build:web": "pnpm --filter vnt-web-ui build",
|
||||
"dev:desktop-ui": "pnpm --filter vnt-desktop dev",
|
||||
"dev:desktop": "pnpm --filter vnt-desktop tauri dev",
|
||||
"build:desktop-ui": "pnpm --filter vnt-desktop build",
|
||||
"build:desktop": "pnpm --filter vnt-desktop tauri build"
|
||||
}
|
||||
}
|
||||
@@ -4,31 +4,88 @@ settings:
|
||||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
catalogs:
|
||||
default:
|
||||
'@tailwindcss/vite':
|
||||
specifier: ^4.1.12
|
||||
version: 4.3.3
|
||||
'@vitejs/plugin-vue':
|
||||
specifier: ^6.0.1
|
||||
version: 6.0.8
|
||||
pinia:
|
||||
specifier: ^3.0.3
|
||||
version: 3.0.4
|
||||
tailwindcss:
|
||||
specifier: ^4.1.12
|
||||
version: 4.3.3
|
||||
vite:
|
||||
specifier: ^7.1.3
|
||||
version: 7.3.6
|
||||
vue:
|
||||
specifier: ^3.5.18
|
||||
version: 3.5.41
|
||||
vue-router:
|
||||
specifier: ^4.5.1
|
||||
version: 4.6.4
|
||||
|
||||
importers:
|
||||
|
||||
.:
|
||||
.: {}
|
||||
|
||||
vnt-desktop:
|
||||
dependencies:
|
||||
'@tauri-apps/api':
|
||||
specifier: ^2.8.0
|
||||
version: 2.11.1
|
||||
pinia:
|
||||
specifier: ^3.0.3
|
||||
specifier: 'catalog:'
|
||||
version: 3.0.4(vue@3.5.41)
|
||||
vue:
|
||||
specifier: ^3.5.18
|
||||
specifier: 'catalog:'
|
||||
version: 3.5.41
|
||||
vue-router:
|
||||
specifier: ^4.5.1
|
||||
specifier: 'catalog:'
|
||||
version: 4.6.4(vue@3.5.41)
|
||||
devDependencies:
|
||||
'@tailwindcss/vite':
|
||||
specifier: ^4.1.12
|
||||
specifier: 'catalog:'
|
||||
version: 4.3.3(vite@7.3.6(jiti@2.7.0)(lightningcss@1.32.0))
|
||||
'@tauri-apps/cli':
|
||||
specifier: ^2.8.4
|
||||
version: 2.11.4
|
||||
'@vitejs/plugin-vue':
|
||||
specifier: ^6.0.1
|
||||
specifier: 'catalog:'
|
||||
version: 6.0.8(vite@7.3.6(jiti@2.7.0)(lightningcss@1.32.0))(vue@3.5.41)
|
||||
tailwindcss:
|
||||
specifier: ^4.1.12
|
||||
specifier: 'catalog:'
|
||||
version: 4.3.3
|
||||
vite:
|
||||
specifier: ^7.1.3
|
||||
specifier: 'catalog:'
|
||||
version: 7.3.6(jiti@2.7.0)(lightningcss@1.32.0)
|
||||
|
||||
vnt-web/ui:
|
||||
dependencies:
|
||||
pinia:
|
||||
specifier: 'catalog:'
|
||||
version: 3.0.4(vue@3.5.41)
|
||||
vue:
|
||||
specifier: 'catalog:'
|
||||
version: 3.5.41
|
||||
vue-router:
|
||||
specifier: 'catalog:'
|
||||
version: 4.6.4(vue@3.5.41)
|
||||
devDependencies:
|
||||
'@tailwindcss/vite':
|
||||
specifier: 'catalog:'
|
||||
version: 4.3.3(vite@7.3.6(jiti@2.7.0)(lightningcss@1.32.0))
|
||||
'@vitejs/plugin-vue':
|
||||
specifier: 'catalog:'
|
||||
version: 6.0.8(vite@7.3.6(jiti@2.7.0)(lightningcss@1.32.0))(vue@3.5.41)
|
||||
tailwindcss:
|
||||
specifier: 'catalog:'
|
||||
version: 4.3.3
|
||||
vite:
|
||||
specifier: 'catalog:'
|
||||
version: 7.3.6(jiti@2.7.0)(lightningcss@1.32.0)
|
||||
|
||||
packages:
|
||||
@@ -464,6 +521,85 @@ packages:
|
||||
peerDependencies:
|
||||
vite: ^5.2.0 || ^6 || ^7 || ^8
|
||||
|
||||
'@tauri-apps/api@2.11.1':
|
||||
resolution: {integrity: sha512-M2FPuYND2m+wh5hfW9ZpSdxMPdEJovPBWwoHJmwUpysTYNHaOkVFN419m/K0LIgjb/7KU2vBgsUepJWugQCvAA==}
|
||||
|
||||
'@tauri-apps/cli-darwin-arm64@2.11.4':
|
||||
resolution: {integrity: sha512-1ryOF3ZhpZ/nemHV5zVwBQBz9jDGKmKPvWPADOhc83ig0P4bMc2iER4NbC6r9sjeIZ6RVQ4g3RZIYvezhcl4TQ==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [arm64]
|
||||
os: [darwin]
|
||||
|
||||
'@tauri-apps/cli-darwin-x64@2.11.4':
|
||||
resolution: {integrity: sha512-uFsGQAAfuyz1k/yGLmkWfkBlgKAqZfxqlHmLWx81QU27RJWfmbNHCIq8T8w1e+VClleIuZUjpHWfoE4E3DLo3A==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [x64]
|
||||
os: [darwin]
|
||||
|
||||
'@tauri-apps/cli-linux-arm-gnueabihf@2.11.4':
|
||||
resolution: {integrity: sha512-IaHZn5CdBL21oUmjiVOS1ctw6Ip1O0pjp70FwOWmYz1myWe0SY96ZIj2FYf7pT0m8bI2h/hrs5ZbEXXh44/MkQ==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [arm]
|
||||
os: [linux]
|
||||
|
||||
'@tauri-apps/cli-linux-arm64-gnu@2.11.4':
|
||||
resolution: {integrity: sha512-N41/ukTRVe6XSuUTESuFdGeOW2i7k62tK+6gHK5Kd5/q5RPvvi19GaWAVPPb9u95HSGmTChSolBfzynUsssFaA==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@tauri-apps/cli-linux-arm64-musl@2.11.4':
|
||||
resolution: {integrity: sha512-v277UnT/fB64xAfSroL5N3Km3tLmvATWqJJw/wRI+g6o+HkeD0slyE7gOhNs1MbjE41R7bQOTxMVoL3aomUJmw==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
libc: [musl]
|
||||
|
||||
'@tauri-apps/cli-linux-riscv64-gnu@2.11.4':
|
||||
resolution: {integrity: sha512-qqgNkQ2u1yZHxjhxsZaxUtRDW8dIqIYm33rx/mzwQv0SfY9x1B+iraj8vWeFiXjjSVVhEMepXSOts1TqPzvXNQ==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [riscv64]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@tauri-apps/cli-linux-x64-gnu@2.11.4':
|
||||
resolution: {integrity: sha512-2VRNWl84FOH0m2giiDkO2h0QXlcMJeX+zJDpI5kDIQAx6s+geF3v48F4DXfJez4GS/FdoDGnPnw1C2iYGbQ7bQ==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@tauri-apps/cli-linux-x64-musl@2.11.4':
|
||||
resolution: {integrity: sha512-o9GyhYor/nc7xarmwDE3ka2szuW3uuZzXjHWh64Q8YX5AtSgxdQkFWzrY4O8KiGtVNvFBI14H3Q49Qj5TOIP/A==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
libc: [musl]
|
||||
|
||||
'@tauri-apps/cli-win32-arm64-msvc@2.11.4':
|
||||
resolution: {integrity: sha512-ld5Ehb598m0VkYyylRPNeCFsBe/km0jxis6KgMpl3IGY6I/i1RwQXO05I1AsXUXO2WC6AvB/Lw4qTf/asiuEiQ==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [arm64]
|
||||
os: [win32]
|
||||
|
||||
'@tauri-apps/cli-win32-ia32-msvc@2.11.4':
|
||||
resolution: {integrity: sha512-12Hxi0XX/H5VFxO/bGgHkFWhml9VMgEOu9CidjeCeTNQ1l6fpUlbiGgSP7CLI3PFtW9/FfbeHieZ+kyWK5H7CA==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [ia32]
|
||||
os: [win32]
|
||||
|
||||
'@tauri-apps/cli-win32-x64-msvc@2.11.4':
|
||||
resolution: {integrity: sha512-+vDiqBIU5dMISg/wNvX3sF+ZHfgJGJ5T0AcO+EHNXV9GGAG+P5fzodlDXD3QdKCRgZxMoCm5PPvj3BqLNjBthw==}
|
||||
engines: {node: '>= 10'}
|
||||
cpu: [x64]
|
||||
os: [win32]
|
||||
|
||||
'@tauri-apps/cli@2.11.4':
|
||||
resolution: {integrity: sha512-R8xGtMpwyetawSqm9kYOuMmEqkhUbvcUy8n0aNXIxollKBLESUu5f4Fx+64hgASYm1H+jSWq6jCW6zqTnH6hqQ==}
|
||||
engines: {node: '>= 10'}
|
||||
hasBin: true
|
||||
|
||||
'@types/estree@1.0.9':
|
||||
resolution: {integrity: sha512-GhdPgy1el4/ImP05X05Uw4cw2/M93BCUmnEvWZNStlCzEKME4Fkk+YpoA5OiHNQmoS7Cafb8Xa3Pya8m1Qrzeg==}
|
||||
|
||||
@@ -1019,6 +1155,55 @@ snapshots:
|
||||
tailwindcss: 4.3.3
|
||||
vite: 7.3.6(jiti@2.7.0)(lightningcss@1.32.0)
|
||||
|
||||
'@tauri-apps/api@2.11.1': {}
|
||||
|
||||
'@tauri-apps/cli-darwin-arm64@2.11.4':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli-darwin-x64@2.11.4':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli-linux-arm-gnueabihf@2.11.4':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli-linux-arm64-gnu@2.11.4':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli-linux-arm64-musl@2.11.4':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli-linux-riscv64-gnu@2.11.4':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli-linux-x64-gnu@2.11.4':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli-linux-x64-musl@2.11.4':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli-win32-arm64-msvc@2.11.4':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli-win32-ia32-msvc@2.11.4':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli-win32-x64-msvc@2.11.4':
|
||||
optional: true
|
||||
|
||||
'@tauri-apps/cli@2.11.4':
|
||||
optionalDependencies:
|
||||
'@tauri-apps/cli-darwin-arm64': 2.11.4
|
||||
'@tauri-apps/cli-darwin-x64': 2.11.4
|
||||
'@tauri-apps/cli-linux-arm-gnueabihf': 2.11.4
|
||||
'@tauri-apps/cli-linux-arm64-gnu': 2.11.4
|
||||
'@tauri-apps/cli-linux-arm64-musl': 2.11.4
|
||||
'@tauri-apps/cli-linux-riscv64-gnu': 2.11.4
|
||||
'@tauri-apps/cli-linux-x64-gnu': 2.11.4
|
||||
'@tauri-apps/cli-linux-x64-musl': 2.11.4
|
||||
'@tauri-apps/cli-win32-arm64-msvc': 2.11.4
|
||||
'@tauri-apps/cli-win32-ia32-msvc': 2.11.4
|
||||
'@tauri-apps/cli-win32-x64-msvc': 2.11.4
|
||||
|
||||
'@types/estree@1.0.9': {}
|
||||
|
||||
'@vitejs/plugin-vue@6.0.8(vite@7.3.6(jiti@2.7.0)(lightningcss@1.32.0))(vue@3.5.41)':
|
||||
@@ -0,0 +1,12 @@
|
||||
packages:
|
||||
- "vnt-web/ui"
|
||||
- "vnt-desktop"
|
||||
|
||||
catalog:
|
||||
"@tailwindcss/vite": ^4.1.12
|
||||
"@vitejs/plugin-vue": ^6.0.1
|
||||
pinia: ^3.0.3
|
||||
tailwindcss: ^4.1.12
|
||||
vite: ^7.1.3
|
||||
vue: ^3.5.18
|
||||
vue-router: ^4.5.1
|
||||
@@ -15,6 +15,9 @@ struct Args {
|
||||
/// 加载vnt配置路径,配置内容参考web端的配置格式
|
||||
#[clap(long)]
|
||||
conf: Option<PathBuf>,
|
||||
/// Web API 访问令牌;未指定时会生成随机令牌并输出到日志
|
||||
#[clap(long, env = "VNT_WEB_TOKEN")]
|
||||
token: Option<String>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
@@ -31,6 +34,19 @@ async fn main0() -> anyhow::Result<()> {
|
||||
#[cfg(windows)]
|
||||
extract_wintun_dll::extract_wintun();
|
||||
let addr = args.addr.unwrap_or("127.0.0.1:19099".parse()?);
|
||||
vnt_web::run_http_server(addr, args.conf).await?;
|
||||
let token = args.token.unwrap_or_else(vnt_web::generate_access_token);
|
||||
let browser_host = if addr.ip().is_unspecified() {
|
||||
"127.0.0.1".to_string()
|
||||
} else {
|
||||
addr.ip().to_string()
|
||||
};
|
||||
log::info!("Web access token: {}", token);
|
||||
log::info!(
|
||||
"Web access URL: http://{}:{}/?token={}",
|
||||
browser_host,
|
||||
addr.port(),
|
||||
token
|
||||
);
|
||||
vnt_web::run_http_server(addr, args.conf, token).await?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
# VNT Desktop
|
||||
|
||||
基于 Tauri 2 + Vue 3 的 VNT PC 客户端。桌面端直接内置 `vnt-web` 的服务能力,不需要另行启动 `vnt2_web`。
|
||||
|
||||
桌面端与 Web 端共用 `vnt-web/ui/src/` 下的同一套 Vue 应用、路由、状态、组件和样式。`vnt-desktop/src/main.js` 只负责注册 Tauri IPC 桥接,不维护第二套界面代码。
|
||||
|
||||
## 功能
|
||||
|
||||
- 桌面工作台:总览、实例、在线设备、路由和配置管理
|
||||
- 多实例启动、停止、重启及启动日志
|
||||
- 表单 / TOML 双模式配置编辑
|
||||
- 原生窗口、系统托盘、单实例运行
|
||||
- 关闭主窗口时隐藏到托盘,托盘菜单可彻底退出
|
||||
- 深浅主题与 `Ctrl/Cmd + 1~5` 页面快捷键
|
||||
- 响应式布局:桌面侧栏、移动端顶部栏和抽屉导航
|
||||
- 桌面工作台通过 Tauri IPC 直接调用进程内 `vnt-core`,不监听本地 API 端口
|
||||
- 可选 Web 访问:启停、端口、本机/局域网监听范围、访问令牌、打开浏览器
|
||||
- Web API 强制使用 Bearer 令牌鉴权,令牌可在桌面端重新生成
|
||||
|
||||
桌面数据存放在系统应用数据目录的 `com.vnt.desktop` 下,包括 `vnt_config`、自启动记录、`web_access.toml`、日志及 Windows 下的 `wintun.dll`。
|
||||
|
||||
## 开发
|
||||
|
||||
要求:Rust、Node.js、pnpm,以及 Tauri 2 对应的系统依赖。
|
||||
|
||||
依赖由仓库根目录的 pnpm workspace 统一管理:
|
||||
|
||||
```powershell
|
||||
pnpm install
|
||||
pnpm dev:desktop
|
||||
```
|
||||
|
||||
只验证前端:
|
||||
|
||||
```powershell
|
||||
pnpm build:desktop-ui
|
||||
```
|
||||
|
||||
验证 Rust 桌面模块:
|
||||
|
||||
```powershell
|
||||
cargo check -p vnt-desktop
|
||||
```
|
||||
|
||||
## 打包
|
||||
|
||||
```powershell
|
||||
pnpm build:desktop
|
||||
```
|
||||
|
||||
Windows 使用虚拟网卡模式时,可能需要以管理员身份运行。
|
||||
|
||||
## 应用图标
|
||||
|
||||
图标母版保存在 `vnt-desktop/assets/vnt-icon-master.png`。需要重新生成各平台图标时,在仓库根目录执行:
|
||||
|
||||
```powershell
|
||||
pnpm --filter vnt-desktop tauri icon assets/vnt-icon-master.png --ios-color '#4F46E5'
|
||||
```
|
||||
|
After Width: | Height: | Size: 988 KiB |
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="theme-color" content="#07111f" />
|
||||
<title>VNT Desktop</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "vnt-desktop",
|
||||
"private": true,
|
||||
"version": "2.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"tauri": "tauri"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.8.0",
|
||||
"pinia": "catalog:",
|
||||
"vue": "catalog:",
|
||||
"vue-router": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/vite": "catalog:",
|
||||
"@tauri-apps/cli": "^2.8.4",
|
||||
"@vitejs/plugin-vue": "catalog:",
|
||||
"tailwindcss": "catalog:",
|
||||
"vite": "catalog:"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
[package]
|
||||
name = "vnt-desktop"
|
||||
version = "2.0.0"
|
||||
description = "VNT virtual network desktop client"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
name = "vnt_desktop_lib"
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2.6.3", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2.11.5", features = ["tray-icon"] }
|
||||
tauri-plugin-single-instance = "2.4.3"
|
||||
tauri-plugin-opener = "2"
|
||||
vnt-web = { path = "../../vnt-web" }
|
||||
vnt2 = { path = "../.." }
|
||||
log.workspace = true
|
||||
tokio = { workspace = true, features = ["full"] }
|
||||
tokio-util.workspace = true
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
toml.workspace = true
|
||||
anyhow.workspace = true
|
||||
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "desktop-capability",
|
||||
"description": "VNT Desktop main window permissions",
|
||||
"windows": ["main"],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"core:window:allow-close",
|
||||
"core:window:allow-minimize",
|
||||
"core:window:allow-maximize",
|
||||
"core:window:allow-unmaximize",
|
||||
"core:window:allow-is-maximized",
|
||||
"core:window:allow-start-dragging",
|
||||
"opener:allow-open-url"
|
||||
]
|
||||
}
|
||||
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 53 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 63 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 75 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 6.5 KiB |
|
After Width: | Height: | Size: 9.3 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 67 KiB |
|
After Width: | Height: | Size: 192 KiB |
@@ -0,0 +1,322 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use tauri::menu::{Menu, MenuItem};
|
||||
use tauri::tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent};
|
||||
use tauri::{AppHandle, Manager, WindowEvent};
|
||||
use tauri_plugin_opener::OpenerExt;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use vnt_web::VntService;
|
||||
|
||||
#[cfg(windows)]
|
||||
mod wintun;
|
||||
|
||||
static EXITING: AtomicBool = AtomicBool::new(false);
|
||||
const WEB_ACCESS_CONFIG: &str = "web_access.toml";
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
#[serde(default)]
|
||||
struct WebAccessConfig {
|
||||
enabled: bool,
|
||||
port: u16,
|
||||
global: bool,
|
||||
token: String,
|
||||
}
|
||||
|
||||
impl Default for WebAccessConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enabled: false,
|
||||
port: 19099,
|
||||
global: false,
|
||||
token: vnt_web::generate_access_token(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct WebAccessStatus {
|
||||
enabled: bool,
|
||||
running: bool,
|
||||
port: u16,
|
||||
global: bool,
|
||||
token: String,
|
||||
url: String,
|
||||
listen_address: String,
|
||||
}
|
||||
|
||||
struct WebRuntime {
|
||||
config: WebAccessConfig,
|
||||
cancellation: Option<CancellationToken>,
|
||||
handle: Option<tokio::task::JoinHandle<anyhow::Result<()>>>,
|
||||
}
|
||||
|
||||
struct DesktopState {
|
||||
service: VntService,
|
||||
web: tokio::sync::Mutex<WebRuntime>,
|
||||
config_path: PathBuf,
|
||||
}
|
||||
|
||||
fn load_web_config(path: &Path) -> WebAccessConfig {
|
||||
let mut config: WebAccessConfig = std::fs::read_to_string(path)
|
||||
.ok()
|
||||
.and_then(|text| toml::from_str(&text).ok())
|
||||
.unwrap_or_default();
|
||||
if config.port == 0 {
|
||||
config.port = 19099;
|
||||
}
|
||||
if config.token.len() < 16 {
|
||||
config.token = vnt_web::generate_access_token();
|
||||
}
|
||||
config
|
||||
}
|
||||
|
||||
fn save_web_config(path: &Path, config: &WebAccessConfig) -> anyhow::Result<()> {
|
||||
std::fs::write(path, toml::to_string_pretty(config)?)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn listen_addr(config: &WebAccessConfig) -> SocketAddr {
|
||||
let ip = if config.global {
|
||||
IpAddr::V4(Ipv4Addr::UNSPECIFIED)
|
||||
} else {
|
||||
IpAddr::V4(Ipv4Addr::LOCALHOST)
|
||||
};
|
||||
SocketAddr::new(ip, config.port)
|
||||
}
|
||||
|
||||
fn lan_ip() -> Option<IpAddr> {
|
||||
let socket = UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0)).ok()?;
|
||||
socket.connect((Ipv4Addr::new(8, 8, 8, 8), 80)).ok()?;
|
||||
Some(socket.local_addr().ok()?.ip())
|
||||
}
|
||||
|
||||
fn access_url(config: &WebAccessConfig) -> String {
|
||||
let host = if config.global {
|
||||
lan_ip().unwrap_or(IpAddr::V4(Ipv4Addr::LOCALHOST))
|
||||
} else {
|
||||
IpAddr::V4(Ipv4Addr::LOCALHOST)
|
||||
};
|
||||
format!("http://{}:{}/?token={}", host, config.port, config.token)
|
||||
}
|
||||
|
||||
async fn stop_web(runtime: &mut WebRuntime) {
|
||||
if let Some(cancellation) = runtime.cancellation.take() {
|
||||
cancellation.cancel();
|
||||
}
|
||||
if let Some(handle) = runtime.handle.take() {
|
||||
match handle.await {
|
||||
Ok(Ok(())) => {}
|
||||
Ok(Err(error)) => log::warn!("Web service stopped with error: {error:#}"),
|
||||
Err(error) if !error.is_cancelled() => log::warn!("Web service task failed: {error}"),
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn start_web(service: &VntService, runtime: &mut WebRuntime) -> anyhow::Result<()> {
|
||||
if !runtime.config.enabled {
|
||||
return Ok(());
|
||||
}
|
||||
let cancellation = CancellationToken::new();
|
||||
let handle = service
|
||||
.start_http(
|
||||
listen_addr(&runtime.config),
|
||||
runtime.config.token.clone(),
|
||||
cancellation.clone(),
|
||||
)
|
||||
.await?;
|
||||
runtime.cancellation = Some(cancellation);
|
||||
runtime.handle = Some(handle);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn api_request(
|
||||
state: tauri::State<'_, DesktopState>,
|
||||
method: String,
|
||||
path: String,
|
||||
body: Option<String>,
|
||||
) -> Result<serde_json::Value, String> {
|
||||
if !path.starts_with("/api/") {
|
||||
return Err("只允许调用 VNT API".to_string());
|
||||
}
|
||||
state
|
||||
.service
|
||||
.request(&method, &path, body)
|
||||
.await
|
||||
.map_err(|error| format!("{error:#}"))
|
||||
}
|
||||
|
||||
fn web_status(runtime: &WebRuntime) -> WebAccessStatus {
|
||||
WebAccessStatus {
|
||||
enabled: runtime.config.enabled,
|
||||
running: runtime
|
||||
.handle
|
||||
.as_ref()
|
||||
.is_some_and(|handle| !handle.is_finished()),
|
||||
port: runtime.config.port,
|
||||
global: runtime.config.global,
|
||||
token: runtime.config.token.clone(),
|
||||
url: access_url(&runtime.config),
|
||||
listen_address: listen_addr(&runtime.config).to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn web_access_status(
|
||||
state: tauri::State<'_, DesktopState>,
|
||||
) -> Result<WebAccessStatus, String> {
|
||||
let runtime = state.web.lock().await;
|
||||
Ok(web_status(&runtime))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn update_web_access(
|
||||
state: tauri::State<'_, DesktopState>,
|
||||
config: WebAccessConfig,
|
||||
) -> Result<WebAccessStatus, String> {
|
||||
if config.port == 0 {
|
||||
return Err("监听端口必须在 1-65535 之间".to_string());
|
||||
}
|
||||
if config.token.len() < 16 {
|
||||
return Err("访问令牌至少需要 16 个字符".to_string());
|
||||
}
|
||||
|
||||
let mut runtime = state.web.lock().await;
|
||||
stop_web(&mut runtime).await;
|
||||
let previous = runtime.config.clone();
|
||||
runtime.config = config;
|
||||
if let Err(error) = start_web(&state.service, &mut runtime).await {
|
||||
runtime.config = previous;
|
||||
if let Err(restore_error) = start_web(&state.service, &mut runtime).await {
|
||||
log::error!("Failed to restore Web service: {restore_error:#}");
|
||||
}
|
||||
return Err(format!("无法启动 Web 服务:{error:#}"));
|
||||
}
|
||||
save_web_config(&state.config_path, &runtime.config)
|
||||
.map_err(|error| format!("保存 Web 访问设置失败:{error:#}"))?;
|
||||
Ok(web_status(&runtime))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn generate_web_token() -> String {
|
||||
vnt_web::generate_access_token()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn open_web_url(app: AppHandle, url: String) -> Result<(), String> {
|
||||
if !url.starts_with("http://") && !url.starts_with("https://") {
|
||||
return Err("只允许打开 HTTP(S) 地址".to_string());
|
||||
}
|
||||
app.opener()
|
||||
.open_url(url, None::<&str>)
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
fn show_main_window(app: &AppHandle) {
|
||||
if let Some(window) = app.get_webview_window("main") {
|
||||
let _ = window.show();
|
||||
let _ = window.unminimize();
|
||||
let _ = window.set_focus();
|
||||
}
|
||||
}
|
||||
|
||||
fn toggle_main_window(app: &AppHandle) {
|
||||
if let Some(window) = app.get_webview_window("main") {
|
||||
match window.is_visible() {
|
||||
Ok(true) => {
|
||||
let _ = window.hide();
|
||||
}
|
||||
_ => show_main_window(app),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
api_request,
|
||||
web_access_status,
|
||||
update_web_access,
|
||||
generate_web_token,
|
||||
open_web_url
|
||||
])
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
|
||||
show_main_window(app);
|
||||
}))
|
||||
.setup(|app| {
|
||||
let data_dir = app.path().app_data_dir()?;
|
||||
std::fs::create_dir_all(&data_dir)?;
|
||||
std::env::set_current_dir(&data_dir)?;
|
||||
vnt2::log::log_init("vnt-desktop");
|
||||
|
||||
#[cfg(windows)]
|
||||
wintun::ensure_wintun(&data_dir)?;
|
||||
|
||||
let config_path = data_dir.join(WEB_ACCESS_CONFIG);
|
||||
let config = load_web_config(&config_path);
|
||||
save_web_config(&config_path, &config)?;
|
||||
let service = tauri::async_runtime::block_on(VntService::new(None))?;
|
||||
let mut web = WebRuntime {
|
||||
config,
|
||||
cancellation: None,
|
||||
handle: None,
|
||||
};
|
||||
if let Err(error) = tauri::async_runtime::block_on(start_web(&service, &mut web)) {
|
||||
log::error!("Failed to restore Web access service: {error:#}");
|
||||
web.config.enabled = false;
|
||||
save_web_config(&config_path, &web.config)?;
|
||||
}
|
||||
app.manage(DesktopState {
|
||||
service,
|
||||
web: tokio::sync::Mutex::new(web),
|
||||
config_path,
|
||||
});
|
||||
|
||||
let show = MenuItem::with_id(app, "show", "显示主窗口", true, None::<&str>)?;
|
||||
let quit = MenuItem::with_id(app, "quit", "退出 VNT", true, None::<&str>)?;
|
||||
let menu = Menu::with_items(app, &[&show, &quit])?;
|
||||
|
||||
let mut tray = TrayIconBuilder::with_id("vnt-tray")
|
||||
.tooltip("VNT Desktop")
|
||||
.menu(&menu)
|
||||
.show_menu_on_left_click(false)
|
||||
.on_menu_event(|app, event| match event.id.as_ref() {
|
||||
"show" => show_main_window(app),
|
||||
"quit" => {
|
||||
EXITING.store(true, Ordering::SeqCst);
|
||||
app.exit(0);
|
||||
}
|
||||
_ => {}
|
||||
})
|
||||
.on_tray_icon_event(|tray, event| {
|
||||
if let TrayIconEvent::Click {
|
||||
button: MouseButton::Left,
|
||||
button_state: MouseButtonState::Up,
|
||||
..
|
||||
} = event
|
||||
{
|
||||
toggle_main_window(tray.app_handle());
|
||||
}
|
||||
});
|
||||
if let Some(icon) = app.default_window_icon() {
|
||||
tray = tray.icon(icon.clone());
|
||||
}
|
||||
tray.build(app)?;
|
||||
Ok(())
|
||||
})
|
||||
.on_window_event(|window, event| {
|
||||
if let WindowEvent::CloseRequested { api, .. } = event
|
||||
&& !EXITING.load(Ordering::SeqCst)
|
||||
{
|
||||
api.prevent_close();
|
||||
let _ = window.hide();
|
||||
}
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running VNT Desktop");
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
vnt_desktop_lib::run();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
const WINTUN_DLL: &[u8] = include_bytes!("../../../dll/amd64/wintun.dll");
|
||||
#[cfg(target_arch = "x86")]
|
||||
const WINTUN_DLL: &[u8] = include_bytes!("../../../dll/x86/wintun.dll");
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
const WINTUN_DLL: &[u8] = include_bytes!("../../../dll/arm64/wintun.dll");
|
||||
#[cfg(target_arch = "arm")]
|
||||
const WINTUN_DLL: &[u8] = include_bytes!("../../../dll/arm/wintun.dll");
|
||||
|
||||
pub fn ensure_wintun(data_dir: &Path) -> io::Result<()> {
|
||||
let target = data_dir.join("wintun.dll");
|
||||
let current = std::fs::read(&target).unwrap_or_default();
|
||||
if current != WINTUN_DLL {
|
||||
std::fs::write(target, WINTUN_DLL)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "VNT Desktop",
|
||||
"version": "2.0.0",
|
||||
"identifier": "com.vnt.desktop",
|
||||
"build": {
|
||||
"beforeDevCommand": "pnpm dev",
|
||||
"devUrl": "http://127.0.0.1:1420",
|
||||
"beforeBuildCommand": "pnpm build",
|
||||
"frontendDist": "../dist"
|
||||
},
|
||||
"app": {
|
||||
"windows": [
|
||||
{
|
||||
"label": "main",
|
||||
"title": "VNT Desktop",
|
||||
"width": 1180,
|
||||
"height": 760,
|
||||
"minWidth": 820,
|
||||
"minHeight": 600,
|
||||
"center": true,
|
||||
"decorations": true,
|
||||
"resizable": true,
|
||||
"shadow": true
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' asset: data:; connect-src 'self' ipc: http://ipc.localhost http://127.0.0.1:*"
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
],
|
||||
"category": "Utility",
|
||||
"shortDescription": "轻量、高效的虚拟局域网桌面客户端",
|
||||
"longDescription": "VNT Desktop 用于创建和管理安全、快速的虚拟局域网连接。",
|
||||
"windows": {
|
||||
"wix": { "language": "zh-CN" },
|
||||
"nsis": { "displayLanguageSelector": false }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
globalThis.__VNT_DESKTOP__ = true;
|
||||
globalThis.__VNT_IPC_REQUEST__ = ({ method, path, body }) =>
|
||||
invoke("api_request", { method, path, body });
|
||||
globalThis.__VNT_WEB_ACCESS__ = {
|
||||
status: () => invoke("web_access_status"),
|
||||
update: (config) => invoke("update_web_access", { config }),
|
||||
generateToken: () => invoke("generate_web_token"),
|
||||
openUrl: (url) => invoke("open_web_url", { url }),
|
||||
};
|
||||
|
||||
// Tauri 与 Web 端共用同一个 Vue 应用,这里只负责平台初始化。
|
||||
await import("@shared/main.js");
|
||||
@@ -0,0 +1,24 @@
|
||||
import { fileURLToPath, URL } from "node:url";
|
||||
import { defineConfig } from "vite";
|
||||
import vue from "@vitejs/plugin-vue";
|
||||
import tailwindcss from "@tailwindcss/vite";
|
||||
|
||||
const sharedUi = fileURLToPath(new URL("../vnt-web/ui/src", import.meta.url));
|
||||
const desktopRoot = fileURLToPath(new URL(".", import.meta.url));
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue(), tailwindcss()],
|
||||
resolve: {
|
||||
alias: {
|
||||
"@shared": sharedUi,
|
||||
},
|
||||
},
|
||||
server: {
|
||||
port: 1420,
|
||||
strictPort: true,
|
||||
host: "127.0.0.1",
|
||||
fs: { allow: [desktopRoot, sharedUi] },
|
||||
watch: { ignored: ["**/src-tauri/**"] },
|
||||
},
|
||||
clearScreen: false,
|
||||
});
|
||||
@@ -8,6 +8,7 @@ vnt-core.workspace = true
|
||||
tokio = { workspace = true, features = ["full"] }
|
||||
axum = "0.8.8"
|
||||
tower-http = { version = "0.7", features = ["fs", "cors", "trace"] }
|
||||
tower = { version = "0.5", features = ["util"] }
|
||||
|
||||
serde.workspace = true
|
||||
serde_json.workspace = true
|
||||
@@ -21,3 +22,5 @@ rust-embed = "8.0"
|
||||
mime_guess = "2.0"
|
||||
parking_lot.workspace = true
|
||||
time = { workspace = true, features = ["local-offset", "formatting", "macros"] }
|
||||
tokio-util.workspace = true
|
||||
rand = "0.9"
|
||||
@@ -1,6 +1,6 @@
|
||||
mod service_http;
|
||||
|
||||
pub use service_http::run_http_server;
|
||||
pub use service_http::{VntService, generate_access_token, run_http_server};
|
||||
|
||||
struct ScopeGuard<F: FnOnce()>(Option<F>);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::defer;
|
||||
use anyhow::{Context, anyhow, bail};
|
||||
use axum::body::Body;
|
||||
use axum::http::{HeaderMap, HeaderValue, StatusCode, Uri, header};
|
||||
use axum::body::{Body, to_bytes};
|
||||
use axum::http::{HeaderMap, HeaderValue, Method, StatusCode, Uri, header};
|
||||
use axum::response::IntoResponse;
|
||||
use axum::{
|
||||
Json, Router,
|
||||
@@ -13,6 +13,7 @@ use axum::{
|
||||
use ipnet::Ipv4Net;
|
||||
use mime_guess::from_path;
|
||||
use parking_lot::Mutex;
|
||||
use rand::Rng;
|
||||
use rust_embed::RustEmbed;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
@@ -23,6 +24,8 @@ use std::time::{Instant, SystemTime, UNIX_EPOCH};
|
||||
use time::{OffsetDateTime, format_description};
|
||||
use tokio::fs;
|
||||
use tokio::net::TcpListener;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use tower::ServiceExt;
|
||||
use tower_http::cors::{Any, CorsLayer};
|
||||
use vnt_core::api::VntApi;
|
||||
use vnt_core::context::config::Config as CoreConfig;
|
||||
@@ -465,37 +468,86 @@ async fn logging_middleware(req: Request, next: axum::middleware::Next) -> Respo
|
||||
#[folder = "static/"]
|
||||
struct Asset;
|
||||
|
||||
pub async fn run_http_server(
|
||||
addr: SocketAddr,
|
||||
start_config_file_name: Option<PathBuf>,
|
||||
) -> anyhow::Result<()> {
|
||||
fs::create_dir_all(CONFIG_DIR)
|
||||
.await
|
||||
.context("Failed to create config directory")?;
|
||||
/// 进程内 VNT 业务服务。HTTP 和 Tauri IPC 共用同一组 handler 与状态。
|
||||
#[derive(Clone)]
|
||||
pub struct VntService {
|
||||
router: Router,
|
||||
}
|
||||
|
||||
let state = HttpAppState {
|
||||
inner: Arc::new(Default::default()),
|
||||
};
|
||||
impl VntService {
|
||||
pub async fn new(start_config_file_name: Option<PathBuf>) -> anyhow::Result<Self> {
|
||||
fs::create_dir_all(CONFIG_DIR)
|
||||
.await
|
||||
.context("Failed to create config directory")?;
|
||||
|
||||
// 自动启动逻辑
|
||||
let auto_start_files = determine_auto_start_files(start_config_file_name).await;
|
||||
let state = HttpAppState {
|
||||
inner: Arc::new(Default::default()),
|
||||
};
|
||||
|
||||
for (file_name, path) in auto_start_files {
|
||||
log::info!("Auto starting VNT with config: {:?}", path);
|
||||
let state_clone = state.clone();
|
||||
tokio::spawn(async move {
|
||||
if let Err(e) = start_vnt_internal(&state_clone, file_name, path).await {
|
||||
log::error!("Auto start failed: {:?}", e);
|
||||
}
|
||||
});
|
||||
for (file_name, path) in determine_auto_start_files(start_config_file_name).await {
|
||||
log::info!("Auto starting VNT with config: {:?}", path);
|
||||
let state_clone = state.clone();
|
||||
tokio::spawn(async move {
|
||||
if let Err(e) = start_vnt_internal(&state_clone, file_name, path).await {
|
||||
log::error!("Auto start failed: {:?}", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
router: api_router(state),
|
||||
})
|
||||
}
|
||||
|
||||
let cors = CorsLayer::new()
|
||||
.allow_origin(Any)
|
||||
.allow_methods(Any)
|
||||
.allow_headers(Any);
|
||||
/// 由 Tauri command 调用,不经过 TCP/HTTP 监听端口。
|
||||
pub async fn request(
|
||||
&self,
|
||||
method: &str,
|
||||
path: &str,
|
||||
body: Option<String>,
|
||||
) -> anyhow::Result<serde_json::Value> {
|
||||
let method = Method::from_bytes(method.as_bytes()).context("Invalid request method")?;
|
||||
let request = axum::http::Request::builder()
|
||||
.method(method)
|
||||
.uri(path)
|
||||
.header(header::CONTENT_TYPE, "application/json")
|
||||
.body(Body::from(body.unwrap_or_default()))?;
|
||||
let response = self.router.clone().oneshot(request).await?;
|
||||
let status = response.status();
|
||||
let bytes = to_bytes(response.into_body(), 8 * 1024 * 1024).await?;
|
||||
let value: serde_json::Value = serde_json::from_slice(&bytes)
|
||||
.with_context(|| format!("Invalid service response ({status})"))?;
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
let app = Router::new()
|
||||
/// 在当前进程中按需开放带令牌鉴权的 Web 服务。
|
||||
pub async fn start_http(
|
||||
&self,
|
||||
addr: SocketAddr,
|
||||
token: String,
|
||||
cancellation: CancellationToken,
|
||||
) -> anyhow::Result<tokio::task::JoinHandle<anyhow::Result<()>>> {
|
||||
let listener = TcpListener::bind(addr).await?;
|
||||
let actual_addr = listener.local_addr()?;
|
||||
let app = http_router(self.router.clone(), token);
|
||||
log::info!("HTTP API Listening on http://{}", actual_addr);
|
||||
Ok(tokio::spawn(async move {
|
||||
axum::serve(listener, app)
|
||||
.with_graceful_shutdown(cancellation.cancelled_owned())
|
||||
.await?;
|
||||
Ok(())
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_access_token() -> String {
|
||||
let mut bytes = [0_u8; 24];
|
||||
rand::rng().fill(&mut bytes);
|
||||
bytes.iter().map(|byte| format!("{byte:02x}")).collect()
|
||||
}
|
||||
|
||||
fn api_router(state: HttpAppState) -> Router {
|
||||
Router::new()
|
||||
.route("/api/version", get(get_version))
|
||||
.route("/api/info", get(get_info))
|
||||
.route("/api/peers", get(get_peers))
|
||||
@@ -511,17 +563,56 @@ pub async fn run_http_server(
|
||||
"/api/config",
|
||||
get(get_config).post(save_config).delete(delete_config),
|
||||
)
|
||||
.with_state(state)
|
||||
}
|
||||
|
||||
async fn token_auth_middleware(
|
||||
State(token): State<String>,
|
||||
req: Request,
|
||||
next: axum::middleware::Next,
|
||||
) -> Response {
|
||||
let authorized = req
|
||||
.headers()
|
||||
.get(header::AUTHORIZATION)
|
||||
.and_then(|value| value.to_str().ok())
|
||||
.and_then(|value| value.strip_prefix("Bearer "))
|
||||
.is_some_and(|provided| provided == token);
|
||||
if !authorized {
|
||||
return (
|
||||
StatusCode::UNAUTHORIZED,
|
||||
Json(ApiResponse::<()>::error("访问令牌无效或已过期")),
|
||||
)
|
||||
.into_response();
|
||||
}
|
||||
next.run(req).await
|
||||
}
|
||||
|
||||
fn http_router(api: Router, token: String) -> Router {
|
||||
let cors = CorsLayer::new()
|
||||
.allow_origin(Any)
|
||||
.allow_methods(Any)
|
||||
.allow_headers(Any);
|
||||
Router::new()
|
||||
.merge(api.layer(middleware::from_fn_with_state(
|
||||
token,
|
||||
token_auth_middleware,
|
||||
)))
|
||||
.fallback(static_handler)
|
||||
.layer(cors)
|
||||
.layer(middleware::from_fn(logging_middleware))
|
||||
.with_state(state)
|
||||
.fallback(static_handler);
|
||||
|
||||
log::info!("HTTP API Listening on http://{}", addr);
|
||||
let listener = TcpListener::bind(addr).await?;
|
||||
axum::serve(listener, app)
|
||||
.with_graceful_shutdown(shutdown_signal())
|
||||
.await?;
|
||||
}
|
||||
|
||||
pub async fn run_http_server(
|
||||
addr: SocketAddr,
|
||||
start_config_file_name: Option<PathBuf>,
|
||||
token: String,
|
||||
) -> anyhow::Result<()> {
|
||||
let service = VntService::new(start_config_file_name).await?;
|
||||
let cancellation = CancellationToken::new();
|
||||
let handle = service.start_http(addr, token, cancellation.clone()).await?;
|
||||
shutdown_signal().await;
|
||||
cancellation.cancel();
|
||||
handle.await??;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1498,6 +1589,45 @@ async fn get_routes(
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_ipc_request_uses_in_process_router() {
|
||||
let service = VntService {
|
||||
router: api_router(new_test_state()),
|
||||
};
|
||||
let response = service.request("GET", "/api/version", None).await.unwrap();
|
||||
assert_eq!(response["code"], 0);
|
||||
assert!(response["data"].as_str().is_some_and(|value| !value.is_empty()));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_http_api_requires_bearer_token() {
|
||||
let token = "test-token-with-enough-entropy".to_string();
|
||||
let app = http_router(api_router(new_test_state()), token.clone());
|
||||
let unauthorized = app
|
||||
.clone()
|
||||
.oneshot(
|
||||
axum::http::Request::builder()
|
||||
.uri("/api/version")
|
||||
.body(Body::empty())
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(unauthorized.status(), StatusCode::UNAUTHORIZED);
|
||||
|
||||
let authorized = app
|
||||
.oneshot(
|
||||
axum::http::Request::builder()
|
||||
.uri("/api/version")
|
||||
.header(header::AUTHORIZATION, format!("Bearer {token}"))
|
||||
.body(Body::empty())
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(authorized.status(), StatusCode::OK);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_normalize_config_file_name() {
|
||||
// 无扩展名补 .toml
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
.config-card-actions[data-v-b7dce6ea]{opacity:1}@media(min-width:640px)and (hover:hover)and (pointer:fine){.config-card-actions[data-v-b7dce6ea]{opacity:0}.group:hover .config-card-actions[data-v-b7dce6ea],.group:focus-within .config-card-actions[data-v-b7dce6ea]{opacity:1}}.web-switch[data-v-2bc5d3bf]{position:relative;display:inline-flex;flex:0 0 44px;align-items:center;width:44px;min-width:44px;height:24px;min-height:24px;padding:2px;border:0;border-radius:9999px;cursor:pointer}.web-switch-knob[data-v-2bc5d3bf]{display:block;width:20px;min-width:20px;height:20px;border-radius:9999px;transform:translate(0);transition:transform .16s ease}.web-switch-knob-on[data-v-2bc5d3bf]{transform:translate(20px)}@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-translate-x:0;--tw-translate-y:0;--tw-translate-z:0;--tw-rotate-x:initial;--tw-rotate-y:initial;--tw-rotate-z:initial;--tw-skew-x:initial;--tw-skew-y:initial;--tw-space-y-reverse:0;--tw-border-style:solid;--tw-leading:initial;--tw-font-weight:initial;--tw-tracking:initial;--tw-ordinal:initial;--tw-slashed-zero:initial;--tw-numeric-figure:initial;--tw-numeric-spacing:initial;--tw-numeric-fraction:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-backdrop-blur:initial;--tw-backdrop-brightness:initial;--tw-backdrop-contrast:initial;--tw-backdrop-grayscale:initial;--tw-backdrop-hue-rotate:initial;--tw-backdrop-invert:initial;--tw-backdrop-opacity:initial;--tw-backdrop-saturate:initial;--tw-backdrop-sepia:initial;--tw-duration:initial;--tw-scale-x:1;--tw-scale-y:1;--tw-scale-z:1;--tw-divide-y-reverse:0}}}@layer theme{:root,:host{--font-sans:-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;--color-red-50:oklch(97.1% .013 17.38);--color-red-100:oklch(93.6% .032 17.717);--color-red-200:oklch(88.5% .062 18.334);--color-red-300:oklch(80.8% .114 19.571);--color-red-400:oklch(70.4% .191 22.216);--color-red-500:oklch(63.7% .237 25.331);--color-red-600:oklch(57.7% .245 27.325);--color-red-700:oklch(50.5% .213 27.518);--color-red-900:oklch(39.6% .141 25.723);--color-amber-400:oklch(82.8% .189 84.429);--color-yellow-100:oklch(97.3% .071 103.193);--color-yellow-300:oklch(90.5% .182 98.111);--color-yellow-400:oklch(85.2% .199 91.936);--color-yellow-500:oklch(79.5% .184 86.047);--color-yellow-600:oklch(68.1% .162 75.834);--color-yellow-700:oklch(55.4% .135 66.442);--color-yellow-900:oklch(42.1% .095 57.708);--color-green-100:oklch(96.2% .044 156.743);--color-green-200:oklch(92.5% .084 155.995);--color-green-300:oklch(87.1% .15 154.449);--color-green-400:oklch(79.2% .209 151.711);--color-green-500:oklch(72.3% .219 149.579);--color-green-600:oklch(62.7% .194 149.214);--color-green-700:oklch(52.7% .154 150.069);--color-green-800:oklch(44.8% .119 151.328);--color-green-900:oklch(39.3% .095 152.535);--color-blue-100:oklch(93.2% .032 255.585);--color-blue-300:oklch(80.9% .105 251.813);--color-blue-400:oklch(70.7% .165 254.624);--color-blue-500:oklch(62.3% .214 259.815);--color-blue-600:oklch(54.6% .245 262.881);--color-blue-700:oklch(48.8% .243 264.376);--color-blue-900:oklch(37.9% .146 265.522);--color-indigo-50:oklch(96.2% .018 272.314);--color-indigo-300:oklch(78.5% .115 274.713);--color-indigo-400:oklch(67.3% .182 276.935);--color-indigo-500:oklch(58.5% .233 277.117);--color-indigo-600:oklch(51.1% .262 276.966);--color-indigo-700:oklch(45.7% .24 277.023);--color-purple-100:oklch(94.6% .033 307.174);--color-purple-300:oklch(82.7% .119 306.383);--color-purple-400:oklch(71.4% .203 305.504);--color-purple-600:oklch(55.8% .288 302.321);--color-purple-700:oklch(49.6% .265 301.924);--color-purple-900:oklch(38.1% .176 304.987);--color-slate-50:oklch(98.4% .003 247.858);--color-slate-100:oklch(96.8% .007 247.896);--color-slate-200:oklch(92.9% .013 255.508);--color-slate-300:oklch(86.9% .022 252.894);--color-slate-400:oklch(70.4% .04 256.788);--color-slate-500:oklch(55.4% .046 257.417);--color-slate-600:oklch(44.6% .043 257.281);--color-slate-700:oklch(37.2% .044 257.287);--color-slate-800:oklch(27.9% .041 260.031);--color-slate-900:oklch(20.8% .042 265.755);--color-slate-950:oklch(12.9% .042 264.695);--color-white:#fff;--spacing:.25rem;--container-sm:24rem;--container-md:28rem;--container-2xl:42rem;--container-4xl:56rem;--container-6xl:72rem;--container-7xl:80rem;--text-xs:.75rLine truncated
|
||||
@@ -0,0 +1,168 @@
|
||||
(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))n(o);new MutationObserver(o=>{for(const l of o)if(l.type==="childList")for(const r of l.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&n(r)}).observe(document,{childList:!0,subtree:!0});function s(o){const l={};return o.integrity&&(l.integrity=o.integrity),o.referrerPolicy&&(l.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?l.credentials="include":o.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function n(o){if(o.ep)return;o.ep=!0;const l=s(o);fetch(o.href,l)}})();function Uo(e){const t=Object.create(null);for(const s of e.split(","))t[s]=1;return s=>s in t}const ke={},vs=[],_t=()=>{},Tr=()=>!1,An=e=>e.charCodeAt(0)===111&&e.charCodeAt(1)===110&&(e.charCodeAt(2)>122||e.charCodeAt(2)<97),$n=e=>e.startsWith("onUpdate:"),Re=Object.assign,Ho=(e,t)=>{const s=e.indexOf(t);s>-1&&e.splice(s,1)},wa=Object.prototype.hasOwnProperty,ve=(e,t)=>wa.call(e,t),J=Array.isArray,bs=e=>nn(e)==="[object Map]",Es=e=>nn(e)==="[object Set]",xl=e=>nn(e)==="[object Date]",le=e=>typeof e=="function",Ce=e=>typeof e=="string",Xe=e=>typeof e=="symbol",be=e=>e!==null&&typeof e=="object",Ar=e=>(be(e)||le(e))&&le(e.then)&&le(e.catch),$r=Object.prototype.toString,nn=e=>$r.call(e),Ca=e=>nn(e).slice(8,-1),Ir=e=>nn(e)==="[object Object]",In=e=>Ce(e)&&e!=="NaN"&&e[0]!=="-"&&""+parseInt(e,10)===e,Ds=Uo(",key,ref,ref_for,ref_key,onVnodeBeforeMount,onVnodeMounted,onVnodeBeforeUpdate,onVnodeUpdated,onVnodeBeforeUnmount,onVnodeUnmounted"),Rn=e=>{const t=Object.create(null);return(s=>t[s]||(t[s]=e(s)))},Sa=/-\w/g,Ge=Rn(e=>e.replace(Sa,t=>t.slice(1).toUpperCase())),Ea=/\B([A-Z])/g,is=Rn(e=>e.replace(Ea,"-$1").toLowerCase()),Pn=Rn(e=>e.charAt(0).toUpperCase()+e.slice(1)),Xn=Rn(e=>e?`on${Pn(e)}`:""),vt=(e,t)=>!Object.is(e,t),hn=(e,...t)=>{for(let s=0;s<e.length;s++)e[s](...t)},Rr=(e,t,s,n=!1)=>{Object.defineProperty(e,t,{configurable:!0,enumerable:!1,writable:n,value:s})},On=e=>{const t=parseFloat(e);return isNaN(t)?e:t},Ta=e=>{const t=Ce(e)?Number(e):NaN;return isNaN(t)?e:t};let yl;const Mn=()=>yl||(yl=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{});function Ln(e){if(J(e)){const t={};for(let s=0;s<e.length;s++){const n=e[s],o=Ce(n)?Ra(n):Ln(n);if(o)for(const l in o)t[l]=o[l]}return t}else if(Ce(e)||be(e))return e}const Aa=/;(?![^(]*\))/g,$a=/:([^]+)/,Ia=/\/\*[^]*?\*\//g;function Ra(e){const t={};return e.replace(Ia,"").split(Aa).forEach(s=>{if(s){const n=s.split($a);n.length>1&&(t[n[0].trim()]=n[1].trim())}}),t}function G(e){let t="";if(Ce(e))t=e;else if(J(e))for(let s=0;s<e.length;s++){const n=G(e[s]);n&&(t+=n+" ")}else if(be(e))for(const s in e)e[s]&&(t+=s+" ");return t.trim()}const Pa="itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly",Oa=Uo(Pa);function Pr(e){return!!e||e===""}function Ma(e,t){if(e.length!==t.length)return!1;let s=!0;for(let n=0;s&&n<e.length;n++)s=Ts(e[n],t[n]);return s}function Ts(e,t){if(e===t)return!0;let s=xl(e),n=xl(t);if(s||n)return s&&n?e.getTime()===t.getTime():!1;if(s=Xe(e),n=Xe(t),s||n)return e===t;if(s=J(e),n=J(t),s||n)return s&&n?Ma(e,t):!1;if(s=be(e),n=be(t),s||n){if(!s||!n)return!1;const o=Object.keys(e).length,l=Object.keys(t).length;if(o!==l)return!1;for(const r in e){const i=e.hasOwnProperty(r),c=t.hasOwnProperty(r);if(i&&!c||!i&&c||!Ts(e[r],t[r]))return!1}}return String(e)===String(t)}function Wo(e,t){return e.findIndex(s=>Ts(s,t))}const Or=e=>!!(e&&e.__v_isRef===!0),V=e=>Ce(e)?e:e==null?"":J(e)||be(e)&&(e.toString===$r||!le(e.toString))?Or(e)?V(e.value):JSON.stringify(e,Mr,2):String(e),Mr=(e,t)=>Or(t)?Mr(e,t.value):bs(t)?{[`Map(${t.size})`]:[...t.entries()].reduce((s,[n,o],l)=>(s[eo(n,l)+" =>"]=o,s),{})}:Es(t)?{[`Set(${t.size})`]:[...t.values()].map(s=>eo(s))}:Xe(t)?eo(t):be(t)&&!J(t)&&!Ir(t)?String(t):t,eo=(e,t="")=>{var s;return Xe(e)?`Symbol(${(s=e.description)!=null?s:t})`:e};let Me;class Lr{constructor(t=!1){this.detached=t,this._active=!0,this._on=0,this.effects=[],this.cleanups=[],this._isPaused=!1,this._warnOnRun=!0,this.__v_skip=!0,!t&&Me&&(Me.active?(this.parent=Me,this.index=(Me.scopes||(Me.scopes=[])).push(this)-1):(this._active=!1,this._warnOnRun=!1))}get active(){return this._active}pause(){if(this._active){this._isPaused=!0;let t,s;if(this.scopes){const n=this.scopes.slice();for(t=0,s=n.length;t<s;t++)n[t].pause()}for(t=0,s=this.effects.length;t<s;t++)this.effects[t].pause()}}resume(){if(this._active&&this._isPaused){this._isPaused=!1;let t,s;if(this.scopes){const o=this.scopes.slice();for(t=0,s=o.length;t<s;t++)o[t].resume()}const n=this.effects.slice();for(t=0,s=n.length;t<s;t++)n[t].resume()}}run(t){if(this._active){const s=Me;try{return Me=this,t()}finally{Me=s}}}on(){++this._on===1&&(this.prevScope=Me,Me=this)}off(){if(this._on>0&&--this._on===0){if(Me===this)Me=this.prevLine truncated
|
||||
`))),e[bt]=ws(o);const l=n||o.props&&o.props.type==="number";Ht(e,t?"change":"input",r=>{r.target.composing||e[bt](po(e.value,s,l))}),(s||l)&&Ht(e,"change",()=>{e.value=po(e.value,s,l)}),t||(Ht(e,"compositionstart",Gu),Ht(e,"compositionend",sr),Ht(e,"change",sr))},mounted(e,{value:t,modifiers:{trim:s,number:n}}){const o=t??"",l=e[pn];delete e[pn],l!==void 0&&(e.type==="text"||e.type==="textarea")&&e.value!==l?e[bt](po(e.value,s,n)):e.value=o},beforeUpdate(e,{value:t,oldValue:s,modifiers:{lazy:n,trim:o,number:l}},r){if(e[bt]=ws(r),e.composing)return;const i=(l||e.type==="number")&&!/^0\d/.test(e.value)?On(e.value):e.value,c=t??"";if(i===c)return;const f=e.getRootNode();(f instanceof Document||f instanceof ShadowRoot)&&f.activeElement===e&&e.type!=="range"&&(n&&t===s||o&&e.value.trim()===c)||(e.value=c)}},Jt={deep:!0,created(e,t,s){e[bt]=ws(s),Ht(e,"change",()=>{const n=e._modelValue,o=tn(e),l=e.checked,r=e[bt];if(J(n)){const i=Wo(n,o),c=i!==-1;if(l&&!c)r(n.concat(o));else if(!l&&c){const f=[...n];f.splice(i,1),r(f)}}else if(Es(n)){const i=new Set(n);l?i.add(o):i.delete(o),r(i)}else r(Ji(e,l))})},mounted:nr,beforeUpdate(e,t,s){e[bt]=ws(s),nr(e,t,s)}};function nr(e,{value:t,oldValue:s},n){e._modelValue=t;let o;if(J(t))o=Wo(t,n.props.value)>-1;else if(Es(t))o=t.has(n.props.value);else{if(t===s)return;o=Ts(t,Ji(e,!0))}e.checked!==o&&(e.checked=o)}const cl={deep:!0,created(e,{value:t,modifiers:{number:s}},n){e._modelValue=t,Ht(e,"change",()=>{const o=Array.prototype.filter.call(e.options,l=>l.selected).map(l=>s?On(tn(l)):tn(l));e[bt](e.multiple?Es(e._modelValue)?new Set(o):o:o[0]),e._assigning=!0,Rt(()=>{e._assigning=!1})}),e[bt]=ws(n)},mounted(e,{value:t}){or(e,t)},beforeUpdate(e,{value:t},s){e._modelValue=t,e[bt]=ws(s)},updated(e,{value:t}){e._assigning||or(e,t)}};function or(e,t){const s=e.multiple,n=J(t);if(!(s&&!n&&!Es(t))){for(let o=0,l=e.options.length;o<l;o++){const r=e.options[o],i=tn(r);if(s)if(n){const c=typeof i;c==="string"||c==="number"?r.selected=t.some(f=>String(f)===String(i)):r.selected=Wo(t,i)>-1}else r.selected=t.has(i);else if(Ts(tn(r),t)){e.selectedIndex!==o&&(e.selectedIndex=o);return}}!s&&e.selectedIndex!==-1&&(e.selectedIndex=-1)}}function tn(e){return"_value"in e?e._value:e.value}function Ji(e,t){const s=t?"_trueValue":"_falseValue";return s in e?e[s]:t}const qu=["ctrl","shift","alt","meta"],zu={stop:e=>e.stopPropagation(),prevent:e=>e.preventDefault(),self:e=>e.target!==e.currentTarget,ctrl:e=>!e.ctrlKey,shift:e=>!e.shiftKey,alt:e=>!e.altKey,meta:e=>!e.metaKey,left:e=>"button"in e&&e.button!==0,middle:e=>"button"in e&&e.button!==1,right:e=>"button"in e&&e.button!==2,exact:(e,t)=>qu.some(s=>e[`${s}Key`]&&!t.includes(s))},ls=(e,t)=>{if(!e)return e;const s=e._withMods||(e._withMods={}),n=t.join(".");return s[n]||(s[n]=((o,...l)=>{for(let r=0;r<t.length;r++){const i=zu[t[r]];if(i&&i(o,t))return}return e(o,...l)}))},Zu=Re({patchProp:Vu},_u);let lr;function Ju(){return lr||(lr=Xc(Zu))}const Yu=((...e)=>{const t=Ju().createApp(...e),{mount:s}=t;return t.mount=n=>{const o=Xu(n);if(!o)return;const l=t._component;!le(l)&&!l.render&&!l.template&&(l.template=o.innerHTML),o.nodeType===1&&(o.textContent="");const r=s(o,!1,Qu(o));return o instanceof Element&&(o.removeAttribute("v-cloak"),o.setAttribute("data-v-app","")),r},t});function Qu(e){if(e instanceof SVGElement)return"svg";if(typeof MathMLElement=="function"&&e instanceof MathMLElement)return"mathml"}function Xu(e){return Ce(e)?document.querySelector(e):e}let Yi;const Gn=e=>Yi=e,Qi=Symbol();function Oo(e){return e&&typeof e=="object"&&Object.prototype.toString.call(e)==="[object Object]"&&typeof e.toJSON!="function"}var Ks;(function(e){e.direct="direct",e.patchObject="patch object",e.patchFunction="patch function"})(Ks||(Ks={}));function ef(){const e=Nr(!0),t=e.run(()=>oe({}));let s=[],n=[];const o=Yo({install(l){Gn(o),o._a=l,l.provide(Qi,o),l.config.globalProperties.$pinia=o,n.forEach(r=>s.push(r)),n=[]},use(l){return this._a?s.push(l):n.push(l),this},_p:s,_a:null,_e:e,_s:new Map,state:t});return o}const Xi=()=>{};function rr(e,t,s,n=Xi){e.add(t);const o=()=>{e.delete(t)&&n()};return!s&&Vr()&&La(o),o}function ds(e,...t){e.forEach(s=>{s(...t)})}const tf=e=>e(),ir=Symbol(),ho=Symbol();function Mo(e,t){e instanceof Map&&t instanceof Map?t.forEach((s,n)=>e.set(n,s)):e instanceof Set&&t instanceof Set&&t.forEach(e.add,e);for(const s in t){if(!t.hasOwnProperty(s))continue;const n=t[s],o=e[s];Oo(o)&&Oo(n)&&e.hasOwnProperty(s)&&!Te(n)&&!Et(n)?e[s]=Mo(o,n):e[s]=n}return e}const sf=Symbol();function nf(e){return!Oo(e)||!Object.prototype.hasOwnProperty.call(e,sf)}const{assign:Bt}=Object;function of(e){return!!(Te(e)&&e.effect)}function lf(e,t,s,n){const{state:o,actions:l,getters:r}=t,i=s.state.value[e];let c;function f(){i||(s.state.value[e]=o?o():{});const u=nc(s.state.value[e]);return Bt(u,l,Object.keys(r||{}).reduce((d,g)=>(d[g]=Yo(_e(()=>{Gn(s);const h=s._s.get(e);return r[g].call(h,h)})),d),{}))}return c=ea(e,f,t,s,n,!0),c}function ea(e,t,s={},n,o,
Line truncated
|
||||
`);for(const n of s){const o=n.trim();if(!(!o||o.startsWith("#"))){if(o.includes("config_name")){const l=o.match(/config_name\s*=\s*"([^"]*)"/);l&&(t.config_name=l[1])}else if(o.includes("network_code")){const l=o.match(/network_code\s*=\s*"([^"]*)"/);l&&(t.network_code=l[1])}else if(o.startsWith("server")){const l=o.match(/server\s*=\s*\[(.*)\]/);if(l){const r=l[1].match(/"([^"]*)"/g);r&&(t.server=r.map(i=>i.replace(/"/g,"")))}}else if(o.includes("ip =")){const l=o.match(/ip\s*=\s*"([^"]*)"/);l&&(t.ip=l[1])}else if(o.includes("mtu =")){const l=o.match(/mtu\s*=\s*(\d+)/);l&&(t.mtu=parseInt(l[1]))}else if(o.match(/^rtx\s*=/))t.rtx=o.includes("true");else if(o.match(/^fec\s*=/))t.fec=o.includes("true");else if(o.match(/^compress\s*=/))t.compress=o.includes("true");else if(o.match(/^no_punch\s*=/))t.no_punch=o.includes("true");else if(o.startsWith("input")){const l=o.match(/input\s*=\s*\[(.*)\]/);if(l){const r=l[1].match(/"([^"]*)"/g);r&&(t.input=r.map(i=>i.replace(/"/g,"")))}}else if(o.startsWith("output")){const l=o.match(/output\s*=\s*\[(.*)\]/);if(l){const r=l[1].match(/"([^"]*)"/g);r&&(t.output=r.map(i=>i.replace(/"/g,"")))}}else if(o.match(/^no_nat\s*=/))t.no_nat=o.includes("true");else if(o.match(/^no_tun\s*=/))t.no_tun=o.includes("true");else if(o.startsWith("port_mapping")){const l=o.match(/port_mapping\s*=\s*\[(.*)\]/);if(l){const r=l[1].match(/"([^"]*)"/g);r&&(t.port_mapping=r.map(i=>i.replace(/"/g,"")))}}else if(o.match(/^allow_mapping\s*=/))t.allow_mapping=o.includes("true");else if(o.includes("device_name")){const l=o.match(/device_name\s*=\s*"([^"]*)"/);l&&(t.device_name=l[1])}else if(o.includes("device_id")){const l=o.match(/device_id\s*=\s*"([^"]*)"/);l&&(t.device_id=l[1])}else if(o.includes("tun_name")){const l=o.match(/tun_name\s*=\s*"([^"]*)"/);l&&(t.tun_name=l[1])}else if(o.includes("password =")){const l=o.match(/password\s*=\s*"([^"]*)"/);l&&(t.password=l[1])}else if(o.includes("cert_mode")){const l=o.match(/cert_mode\s*=\s*"([^"]*)"/);if(l){const r=l[1];r.startsWith("finger:")?(t.cert_mode="finger",t.fingerprint=r.substring(7)):t.cert_mode=r}}else if(o.startsWith("udp_stun")){const l=o.match(/udp_stun\s*=\s*\[(.*)\]/);if(l){const r=l[1].match(/"([^"]*)"/g);r&&(t.udp_stun=r.map(i=>i.replace(/"/g,"")))}}else if(o.startsWith("tcp_stun")){const l=o.match(/tcp_stun\s*=\s*\[(.*)\]/);if(l){const r=l[1].match(/"([^"]*)"/g);r&&(t.tcp_stun=r.map(i=>i.replace(/"/g,"")))}}}}return t},_o=e=>{let t="";e.config_name&&(t+=`# 配置名称
|
||||
config_name = "${e.config_name}"
|
||||
`),t+=`
|
||||
# --- 网络配置 ---
|
||||
`,t+=`# 网络编号,相同网络编号的会组在同一个虚拟网 (必填)
|
||||
`,t+=`network_code = "${e.network_code}"
|
||||
|
||||
`;const s=e.server.filter(c=>c.trim());s.length>0&&(t+=`# 服务器地址列表(支持 quic / tcp / wss / dynamic) (必填)
|
||||
`,t+=`# dynamic 协议使用dns txt解析记录值
|
||||
`,t+=`server = [${s.map(c=>`"${c}"`).join(", ")}]
|
||||
`),e.ip&&(t+=`
|
||||
# 自定义虚拟 IP (可选)
|
||||
`,t+=`ip = "${e.ip}"
|
||||
`),e.rtx&&(t+=`
|
||||
# 是否启用quic优化传输 (默认 false)
|
||||
`,t+=`# 开启后传输过程几乎不会丢包,但是延迟可能会有波动
|
||||
`,t+=`rtx = true
|
||||
`),e.fec&&(t+=`
|
||||
# 是否启用 FEC 前向纠错 (默认 false)
|
||||
`,t+=`# 开启后可以减少丢包率,损失带宽但是延迟比较稳定,带宽充足时可以使用此功能
|
||||
`,t+=`fec = true
|
||||
`),e.no_punch&&(t+=`
|
||||
# 是否关闭 P2P 打洞 (默认 false)
|
||||
`,t+=`no_punch = true
|
||||
`),e.compress&&(t+=`
|
||||
# 是否启用 LZ4 压缩 (默认 false)
|
||||
`,t+=`compress = true
|
||||
`);const n=e.input.filter(c=>c.trim());n.length>0&&(t+=`
|
||||
# 入栈监听网段 (逗号分隔的 CIDR 和目标 IP),用于点对网,将指定网段的流量发送到目标节点
|
||||
`,t+=`# 例如192.168.0.0/24,10.26.0.2 表示将192.168.0.0/24网段的数据转发到10.26.0.2
|
||||
`,t+=`input = [${n.map(c=>`"${c}"`).join(", ")}]
|
||||
`);const o=e.output.filter(c=>c.trim());o.length>0&&(t+=`
|
||||
# 出栈允许网段,用于点对网,允许指定网段的转发
|
||||
`,t+=`output = [${o.map(c=>`"${c}"`).join(", ")}]
|
||||
`),e.no_nat&&(t+=`
|
||||
# 是否关闭内置子网NAT,关闭后需要配置网卡转发,否则无法使用点对网
|
||||
`,t+=`# 通常关闭内置子网NAT,使用系统的网卡转发,点对网性能会更好
|
||||
`,t+=`no_nat = true
|
||||
`),e.no_tun&&(t+=`
|
||||
# 是否关闭TUN虚拟网卡,关闭后只能充当流量出口或者进行端口映射,关闭后无需管理员权限
|
||||
`,t+=`no_tun = true
|
||||
`);const l=e.port_mapping.filter(c=>c.trim());l.length>0&&(t+=`
|
||||
# 端口映射,格式为:协议://本地监听地址-目标虚拟IP-目标映射地址
|
||||
`,t+=`# 端口映射用于在本地监听指定端口,并将收到的网络流量经由指定虚拟节点转发到目标地址
|
||||
`,t+=`# 例如: tcp://0.0.0.0:81-10.0.0.2-10.0.0.2:80 表示将本地tcp的81端口的数据转发到10.0.0.2:80
|
||||
`,t+=`# 例如: tcp://0.0.0.0:81-10.0.0.2-192.168.1.10:80 则表示将本地tcp的81端口的数据经过10.0.0.2转到192.168.1.10:80
|
||||
`,t+=`# 例如: tcp://0.0.0.0:81-10.0.0.2-anyonehost:80 则表示将本地tcp的81端口的数据经过10.0.0.2转到anyonehost:80
|
||||
`,t+=`port_mapping = [${l.map(c=>`"${c}"`).join(", ")}]
|
||||
`),e.allow_mapping&&(t+=`
|
||||
# 是否允许作为端口映射出口,开启后其他设备才可使用本设备的ip为"目标虚拟IP"
|
||||
`,t+=`# 开启后虚拟网络其他设备可以使用此设备当跳板访问其他网络
|
||||
`,t+=`allow_mapping = true
|
||||
`),e.mtu&&(t+=`
|
||||
# MTU 设置
|
||||
`,t+=`mtu = ${e.mtu}
|
||||
`),t+=`
|
||||
# --- 设备配置 ---
|
||||
`,e.device_name&&(t+=`
|
||||
# 设备名称 (可选,默认读取本机 hostname)
|
||||
`,t+=`device_name = "${e.device_name}"
|
||||
`),e.device_id&&(t+=`
|
||||
# 设备 ID (可选,不填自动生成,不同设备ID不能相同)
|
||||
`,t+=`device_id = "${e.device_id}"
|
||||
`),e.tun_name&&(t+=`
|
||||
# 虚拟网卡名称
|
||||
`,t+=`tun_name = "${e.tun_name}"
|
||||
`),t+=`
|
||||
# --- 安全配置 ---
|
||||
`,e.password&&(t+=`
|
||||
# 组网加密密码 (可选)
|
||||
`,t+=`password = "${e.password}"
|
||||
`),e.cert_mode&&e.cert_mode!=="skip"&&(t+=`
|
||||
# 证书校验方式:
|
||||
`,t+=`# skip 跳过验证(默认)
|
||||
`,t+=`# standard 使用系统证书验证
|
||||
`,t+=`# finger 使用证书指纹验证,服务端启动时日志会输出指纹
|
||||
`,e.cert_mode==="finger"&&e.fingerprint?t+=`cert_mode = "finger:${e.fingerprint}"
|
||||
`:t+=`cert_mode = "${e.cert_mode}"
|
||||
`);const r=e.udp_stun.filter(c=>c.trim());r.length>0&&(t+=`
|
||||
# 自定义UDP STUN地址,不设置则用默认stun
|
||||
`,t+=`udp_stun = [${r.map(c=>`"${c}"`).join(", ")}]
|
||||
`);const i=e.tcp_stun.filter(c=>c.trim());return i.length>0&&(t+=`
|
||||
# 自定义TCP STUN地址,不设置则用默认stun
|
||||
`,t+=`tcp_stun = [${i.map(c=>`"${c}"`).join(", ")}]
|
||||
`),t},rh=`# config_name = "配置名称"
|
||||
# --- 网络配置 ---
|
||||
# 网络编号,相同网络编号的会组在同一个虚拟网 (必填)
|
||||
network_code = "your_network_code"
|
||||
|
||||
# 服务器地址列表(支持 quic / tcp / wss / dynamic) (必填)
|
||||
# dynamic 协议使用dns txt解析记录值
|
||||
server = ["quic://1.2.3.4:29872"]
|
||||
|
||||
# ===简单使用以下参数可以不动===
|
||||
|
||||
# 自定义虚拟 IP (可选)
|
||||
# ip = "10.10.0.2"
|
||||
|
||||
# 是否启用quic优化传输 (默认 false,设置为true时开启)
|
||||
# 开启后传输过程几乎不会丢包,但是延迟会有波动
|
||||
# rtx = false
|
||||
|
||||
# 是否启用 FEC 前向纠错,损失一定带宽来提升网络稳定性(默认 false,设置为true时开启)
|
||||
# 开启后可以减少丢包率,损失带宽但是延迟比较稳定,带宽充足时可以使用此功能
|
||||
# fec = false
|
||||
|
||||
# 是否关闭 P2P 打洞 (默认 false,设置为true时关闭)
|
||||
# no_punch = false
|
||||
|
||||
# 是否启用 LZ4 压缩 (默认 false,设置为true时开启)
|
||||
# compress = false
|
||||
|
||||
# 入栈监听网段 (逗号分隔的 CIDR 和目标 IP),用于点对网,将指定网段的流量发送到目标节点
|
||||
# input = ["192.168.0.0/24,10.26.0.2", "192.168.1.0/24,10.26.0.3"]
|
||||
|
||||
# 出栈允许网段,用于点对网,允许指定网段的转发
|
||||
# output = ["0.0.0.0/0"]
|
||||
|
||||
# 是否关闭内置子网NAT,关闭(设为true)后需要配置网卡转发,否则无法使用点对网。通常关闭内置子网NAT,使用系统的网卡转发,点对网性能会更好
|
||||
# no_nat = false
|
||||
|
||||
# 是否关闭TUN虚拟网卡,关闭(设为true)后只能充当流量出口或者进行端口映射,关闭后无需管理员权限
|
||||
# no_tun = false
|
||||
|
||||
# 端口映射,格式为:协议://本地监听地址-目标虚拟IP-目标映射地址
|
||||
# 端口映射用于在本地监听指定端口,并将收到的网络流量经由指定虚拟节点转发到目标地址,从而实现跨网络或内网服务访问
|
||||
# 例如 port_mapping = ["tcp://0.0.0.0:81-10.0.0.2-10.0.0.2:80"]
|
||||
# tcp://0.0.0.0:81-10.0.0.2-10.0.0.2:80 则表示将本地tcp的81端口的数据转发到10.0.0.2:80
|
||||
# tcp://0.0.0.0:81-10.0.0.2-192.168.1.10:80 则表示将本地tcp的81端口的数据经过10.0.0.2转到192.168.1.10:80
|
||||
# tcp://0.0.0.0:81-10.0.0.2-anyonehost:80 则表示将本地tcp的81端口的数据经过10.0.0.2转到anyonehost:80
|
||||
# port_mapping = []
|
||||
|
||||
# 是否允许作为端口映射出口,开启(设置为true)后其他设备才可使用本设备的ip为"目标虚拟IP"
|
||||
# 开启后虚拟网络其他设备可以使用此设备当跳板访问其他网络
|
||||
# allow_mapping = false
|
||||
|
||||
# MTU 设置
|
||||
# mtu = 1400
|
||||
|
||||
# --- 设备配置 ---
|
||||
|
||||
# 设备名称 (可选,默认读取本机 hostname)
|
||||
# device_name = "my-device"
|
||||
|
||||
# 设备 ID (可选,不填自动生成,不同设备ID不能相同)
|
||||
# device_id = "device-id-xxxx"
|
||||
|
||||
# 虚拟网卡名称
|
||||
# tun_name = "vnt-tun"
|
||||
|
||||
# --- 安全配置 ---
|
||||
|
||||
# 加密密码 (可选)
|
||||
# password = "123456"
|
||||
|
||||
# 证书校验方式:
|
||||
# skip 跳过验证(默认)
|
||||
# standard 使用系统证书验证
|
||||
# finger 使用证书指纹验证,服务端启动时日志会输出指纹,
|
||||
# 例如 finger:3bdd8675606837cdf95d5e13445606315762315a78555f9da652940a25feaec1
|
||||
# cert_mode = "skip"
|
||||
|
||||
# --- 其他配置 ---
|
||||
# 自定义stun地址,分别用于udp打洞和tcp打洞,需要单独配置,不设置则用默认stun
|
||||
# udp_stun = ["stun.chat.bilibili.com"]
|
||||
# tcp_stun = ["stun.nextcloud.com:443"]`,ih={class:"text-lg font-bold text-slate-900 dark:text-white"},ah={class:"flex items-center gap-4"},ch={class:"flex rounded-lg border border-slate-300 bg-slate-100 p-1 dark:border-slate-600 dark:bg-slate-800"},uh={key:0,class:"text-sm text-slate-500 font-mono hidden md:block"},fh={class:"h-full overflow-y-auto scrollbar-hide p-6"},dh={class:"max-w-4xl mx-auto space-y-6"},ph={class:"card"},hh={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},mh={class:"mt-4"},gh={class:"space-y-2"},vh=["onUpdate:modelValue"],bh=["onClick"],_h={class:"card"},xh={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},yh={class:"card"},kh={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},wh={class:"card"},Ch={class:"space-y-4"},Sh={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},Eh={key:0},Th={class:"card"},Ah={class:"space-y-4"},$h={class:"space-y-2"},Ih=["onUpdate:modelValue"],Rh=["onClick"],Ph={class:"space-y-2"},Oh=["onUpdate:modelValue"],Mh=["onClick"],Lh={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},Nh={class:"card"},Vh={class:"space-y-4"},jh={class:"space-y-2"},Dh=["onUpdate:modelValue"],Bh=["onClick"],Fh={class:"card"},Uh={class:"grid grid-cols-1 md:grid-cols-3 gap-4"},Hh={class:"card"},Wh={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},Kh={class:"space-y-2"},Gh=["onUpdate:modelValue"],qh=["onClick"],zh={class:"space-y-2"},Zh=["onUpdate:modelValue"],Jh=["onClick"],Yh={class:"h-full"},Qh={class:"flex-1 text-left text-xs text-slate-500"},Xh={key:0},em={key:1},Yt="h-5 w-5 rounded border-slate-300 bg-white text-indigo-600 focus:ring-indigo-500 dark:border-slate-600 dark:bg-slate-700",Qt="flex cursor-pointer items-center justify-between gap-2 rounded-lg border border-slate-200 bg-slate-50 p-3 transition-colors hover:bg-slate-100 dark:border-slate-700 dark:bg-slate-800/50 dark:hover:bg-slate-800",ps="shrink-0 rounded-lg bg-red-50 px-3 py-2 text-red-500 transition-colors hover:bg-red-100 dark:bg-red-900/20 dark:text-red-500 dark:hover:bg-red-900/40",hs="flex w-full items-center justify-center gap-1 rounded-lg bg-slate-100 px-3 py-2 text-sm text-slate-600 transition-colors hover:bg-slate-200 dark:bg-slate-700/50 dark:text-slate-300 dark:hover:bg-slate-700",Vt="text-md mb-4 flex items-center font-bold text-slate-900 dark:text-white",tm={__name:"ConfigEditor",props:{show:{type:Boolean,default:!1},fileName:{type:String,default:null}},emits:["close","saved"],setup(e,{emit:t}){const s=e,n=t,o=as(),l=oe(""),r=oe(""),i=oe("new"),c=oe("form"),f=oe(""),u=oe(!1),d=oe(!1),g=oe(!1),h=oe(Bo());Be(()=>s.show,async w=>{if(w)if(r.value=s.fileName||"",i.value=s.fileName?"edit":"new",c.value="form",u.value=!1,d.value=!1,s.fileName)try{const p=await Td(s.fileName);l.value=p,f.value=p,g.value=!0,h.value=Sr(p),Rt(()=>{g.value=!1})}catch(p){o.toast.error("获取配置失败: "+p.message),n("close")}else f.value="",h.value=Bo(),l.value=rh});const C=()=>{c.value==="toml"?(c.value="form",g.value=!0,h.value=Sr(l.value),Rt(()=>{g.value=!1})):c.value="form"},x=()=>{c.value==="form"&&(d.value?(l.value=_o(h.value),d.value=!1):f.value&&!u.value?l.value=f.value:l.value=_o(h.value)),c.value="toml"};Be(l,(w,p)=>{c.value==="toml"&&p!==void 0&&(u.value=!0)}),Be(h,()=>{c.value==="form"&&s.show&&!g.value&&(d.value=!0)},{deep:!0});const L=async()=>{try{let w=l.value;if(c.value==="form"){if(!h.value.network_code.trim()){o.toast.error("请填写网络编号");return}if(h.value.server.filter(b=>b.trim()).length===0){o.toast.error("请至少填写一个服务器地址");return}w=_o(h.value)}await Ad(r.value||null,w),o.toast.success("配置已保存"),n("close"),n("saved")}catch(w){o.toast.error("保存失败: "+w.message)}};return(w,p)=>(y(),Ie(gl,{show:e.show,"mask-closable":!1,"panel-class":"w-full max-w-6xl h-[85vh]",onClose:p[26]||(p[26]=b=>n("close"))},{header:Ae(()=>[a("h3",ih,V(i.value==="new"?"新建配置":"编辑配置"),1),a("div",ah,[a("div",ch,[a("button",{onClick:C,class:G([c.value==="form"?"bg-white text-slate-900 shadow-sm dark:bg-indigo-600 dark:text-white":"text-slate-500 hover:text-slate-900 dark:text-slate-400 dark:hover:text-white","px-4 py-1.5 rounded text-sm font-medium transition-colors flex items-center"])},[...p[27]||(p[27]=[a("svg",{class:"w-4 h-4 mr-1.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[a("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})],-1),ae(" 表单模式 ",-1)])],2),a("button",{onClick:x,class:G([c.value==="toml"?"bg-white text-slate-900 shadow-sm dark:bg-indigo-600 dark:text-white":"text-slate-500 hover:text-slate-900 dark:text-slate-400 dark:hover:text-white","px-4 py-1.5 rounded text-sm font-medium transition-colors flex items-center"])},[...p[28]||(p[28]=[a("svg",{class:"w-4 h-4 mr-1.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[a("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M10 20l4-
Line truncated
|
||||
@@ -1,168 +0,0 @@
|
||||
(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))n(o);new MutationObserver(o=>{for(const r of o)if(r.type==="childList")for(const l of r.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&n(l)}).observe(document,{childList:!0,subtree:!0});function s(o){const r={};return o.integrity&&(r.integrity=o.integrity),o.referrerPolicy&&(r.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?r.credentials="include":o.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function n(o){if(o.ep)return;o.ep=!0;const r=s(o);fetch(o.href,r)}})();function Lo(e){const t=Object.create(null);for(const s of e.split(","))t[s]=1;return s=>s in t}const ke={},gs=[],bt=()=>{},gl=()=>!1,An=e=>e.charCodeAt(0)===111&&e.charCodeAt(1)===110&&(e.charCodeAt(2)>122||e.charCodeAt(2)<97),In=e=>e.startsWith("onUpdate:"),Re=Object.assign,No=(e,t)=>{const s=e.indexOf(t);s>-1&&e.splice(s,1)},ua=Object.prototype.hasOwnProperty,ge=(e,t)=>ua.call(e,t),Y=Array.isArray,vs=e=>sn(e)==="[object Map]",Es=e=>sn(e)==="[object Set]",ur=e=>sn(e)==="[object Date]",oe=e=>typeof e=="function",Ce=e=>typeof e=="string",Ze=e=>typeof e=="symbol",ve=e=>e!==null&&typeof e=="object",vl=e=>(ve(e)||oe(e))&&oe(e.then)&&oe(e.catch),_l=Object.prototype.toString,sn=e=>_l.call(e),fa=e=>sn(e).slice(8,-1),bl=e=>sn(e)==="[object Object]",Rn=e=>Ce(e)&&e!=="NaN"&&e[0]!=="-"&&""+parseInt(e,10)===e,js=Lo(",key,ref,ref_for,ref_key,onVnodeBeforeMount,onVnodeMounted,onVnodeBeforeUpdate,onVnodeUpdated,onVnodeBeforeUnmount,onVnodeUnmounted"),$n=e=>{const t=Object.create(null);return(s=>t[s]||(t[s]=e(s)))},da=/-\w/g,Ke=$n(e=>e.replace(da,t=>t.slice(1).toUpperCase())),pa=/\B([A-Z])/g,os=$n(e=>e.replace(pa,"-$1").toLowerCase()),Pn=$n(e=>e.charAt(0).toUpperCase()+e.slice(1)),qn=$n(e=>e?`on${Pn(e)}`:""),vt=(e,t)=>!Object.is(e,t),pn=(e,...t)=>{for(let s=0;s<e.length;s++)e[s](...t)},xl=(e,t,s,n=!1)=>{Object.defineProperty(e,t,{configurable:!0,enumerable:!1,writable:n,value:s})},Mn=e=>{const t=parseFloat(e);return isNaN(t)?e:t},ha=e=>{const t=Ce(e)?Number(e):NaN;return isNaN(t)?e:t};let fr;const On=()=>fr||(fr=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{});function Ln(e){if(Y(e)){const t={};for(let s=0;s<e.length;s++){const n=e[s],o=Ce(n)?_a(n):Ln(n);if(o)for(const r in o)t[r]=o[r]}return t}else if(Ce(e)||ve(e))return e}const ma=/;(?![^(]*\))/g,ga=/:([^]+)/,va=/\/\*[^]*?\*\//g;function _a(e){const t={};return e.replace(va,"").split(ma).forEach(s=>{if(s){const n=s.split(ga);n.length>1&&(t[n[0].trim()]=n[1].trim())}}),t}function q(e){let t="";if(Ce(e))t=e;else if(Y(e))for(let s=0;s<e.length;s++){const n=q(e[s]);n&&(t+=n+" ")}else if(ve(e))for(const s in e)e[s]&&(t+=s+" ");return t.trim()}const ba="itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly",xa=Lo(ba);function yl(e){return!!e||e===""}function ya(e,t){if(e.length!==t.length)return!1;let s=!0;for(let n=0;s&&n<e.length;n++)s=Ts(e[n],t[n]);return s}function Ts(e,t){if(e===t)return!0;let s=ur(e),n=ur(t);if(s||n)return s&&n?e.getTime()===t.getTime():!1;if(s=Ze(e),n=Ze(t),s||n)return e===t;if(s=Y(e),n=Y(t),s||n)return s&&n?ya(e,t):!1;if(s=ve(e),n=ve(t),s||n){if(!s||!n)return!1;const o=Object.keys(e).length,r=Object.keys(t).length;if(o!==r)return!1;for(const l in e){const i=e.hasOwnProperty(l),a=t.hasOwnProperty(l);if(i&&!a||!i&&a||!Ts(e[l],t[l]))return!1}}return String(e)===String(t)}function Vo(e,t){return e.findIndex(s=>Ts(s,t))}const kl=e=>!!(e&&e.__v_isRef===!0),B=e=>Ce(e)?e:e==null?"":Y(e)||ve(e)&&(e.toString===_l||!oe(e.toString))?kl(e)?B(e.value):JSON.stringify(e,wl,2):String(e),wl=(e,t)=>kl(t)?wl(e,t.value):vs(t)?{[`Map(${t.size})`]:[...t.entries()].reduce((s,[n,o],r)=>(s[zn(n,r)+" =>"]=o,s),{})}:Es(t)?{[`Set(${t.size})`]:[...t.values()].map(s=>zn(s))}:Ze(t)?zn(t):ve(t)&&!Y(t)&&!bl(t)?String(t):t,zn=(e,t="")=>{var s;return Ze(e)?`Symbol(${(s=e.description)!=null?s:t})`:e};let Pe;class Cl{constructor(t=!1){this.detached=t,this._active=!0,this._on=0,this.effects=[],this.cleanups=[],this._isPaused=!1,this._warnOnRun=!0,this.__v_skip=!0,!t&&Pe&&(Pe.active?(this.parent=Pe,this.index=(Pe.scopes||(Pe.scopes=[])).push(this)-1):(this._active=!1,this._warnOnRun=!1))}get active(){return this._active}pause(){if(this._active){this._isPaused=!0;let t,s;if(this.scopes){const n=this.scopes.slice();for(t=0,s=n.length;t<s;t++)n[t].pause()}for(t=0,s=this.effects.length;t<s;t++)this.effects[t].pause()}}resume(){if(this._active&&this._isPaused){this._isPaused=!1;let t,s;if(this.scopes){const o=this.scopes.slice();for(t=0,s=o.length;t<s;t++)o[t].resume()}const n=this.effects.slice();for(t=0,s=n.length;t<s;t++)n[t].resume()}}run(t){if(this._active){const s=Pe;try{return Pe=this,t()}finally{Pe=s}}}on(){++this._on===1&&(this.prevScope=Pe,Pe=this)}off(){if(this._on>0&&--this._on===0){if(Pe===this)Pe=this.prevLine truncated
|
||||
`))),e[_t]=ws(o);const r=n||o.props&&o.props.type==="number";Bt(e,t?"change":"input",l=>{l.target.composing||e[_t](lo(e.value,s,r))}),(s||r)&&Bt(e,"change",()=>{e.value=lo(e.value,s,r)}),t||(Bt(e,"compositionstart",Mu),Bt(e,"compositionend",Gr),Bt(e,"change",Gr))},mounted(e,{value:t,modifiers:{trim:s,number:n}}){const o=t??"",r=e[dn];delete e[dn],r!==void 0&&(e.type==="text"||e.type==="textarea")&&e.value!==r?e[_t](lo(e.value,s,n)):e.value=o},beforeUpdate(e,{value:t,oldValue:s,modifiers:{lazy:n,trim:o,number:r}},l){if(e[_t]=ws(l),e.composing)return;const i=(r||e.type==="number")&&!/^0\d/.test(e.value)?Mn(e.value):e.value,a=t??"";if(i===a)return;const f=e.getRootNode();(f instanceof Document||f instanceof ShadowRoot)&&f.activeElement===e&&e.type!=="range"&&(n&&t===s||o&&e.value.trim()===a)||(e.value=a)}},zt={deep:!0,created(e,t,s){e[_t]=ws(s),Bt(e,"change",()=>{const n=e._modelValue,o=en(e),r=e.checked,l=e[_t];if(Y(n)){const i=Vo(n,o),a=i!==-1;if(r&&!a)l(n.concat(o));else if(!r&&a){const f=[...n];f.splice(i,1),l(f)}}else if(Es(n)){const i=new Set(n);r?i.add(o):i.delete(o),l(i)}else l(Bi(e,r))})},mounted:qr,beforeUpdate(e,t,s){e[_t]=ws(s),qr(e,t,s)}};function qr(e,{value:t,oldValue:s},n){e._modelValue=t;let o;if(Y(t))o=Vo(t,n.props.value)>-1;else if(Es(t))o=t.has(n.props.value);else{if(t===s)return;o=Ts(t,Bi(e,!0))}e.checked!==o&&(e.checked=o)}const Fi={deep:!0,created(e,{value:t,modifiers:{number:s}},n){e._modelValue=t,Bt(e,"change",()=>{const o=Array.prototype.filter.call(e.options,r=>r.selected).map(r=>s?Mn(en(r)):en(r));e[_t](e.multiple?Es(e._modelValue)?new Set(o):o:o[0]),e._assigning=!0,$t(()=>{e._assigning=!1})}),e[_t]=ws(n)},mounted(e,{value:t}){zr(e,t)},beforeUpdate(e,{value:t},s){e._modelValue=t,e[_t]=ws(s)},updated(e,{value:t}){e._assigning||zr(e,t)}};function zr(e,t){const s=e.multiple,n=Y(t);if(!(s&&!n&&!Es(t))){for(let o=0,r=e.options.length;o<r;o++){const l=e.options[o],i=en(l);if(s)if(n){const a=typeof i;a==="string"||a==="number"?l.selected=t.some(f=>String(f)===String(i)):l.selected=Vo(t,i)>-1}else l.selected=t.has(i);else if(Ts(en(l),t)){e.selectedIndex!==o&&(e.selectedIndex=o);return}}!s&&e.selectedIndex!==-1&&(e.selectedIndex=-1)}}function en(e){return"_value"in e?e._value:e.value}function Bi(e,t){const s=t?"_trueValue":"_falseValue";return s in e?e[s]:t}const Ou=["ctrl","shift","alt","meta"],Lu={stop:e=>e.stopPropagation(),prevent:e=>e.preventDefault(),self:e=>e.target!==e.currentTarget,ctrl:e=>!e.ctrlKey,shift:e=>!e.shiftKey,alt:e=>!e.altKey,meta:e=>!e.metaKey,left:e=>"button"in e&&e.button!==0,middle:e=>"button"in e&&e.button!==1,right:e=>"button"in e&&e.button!==2,exact:(e,t)=>Ou.some(s=>e[`${s}Key`]&&!t.includes(s))},xs=(e,t)=>{if(!e)return e;const s=e._withMods||(e._withMods={}),n=t.join(".");return s[n]||(s[n]=((o,...r)=>{for(let l=0;l<t.length;l++){const i=Lu[t[l]];if(i&&i(o,t))return}return e(o,...r)}))},Nu=Re({patchProp:Cu},lu);let Jr;function Vu(){return Jr||(Jr=Fc(Nu))}const ju=((...e)=>{const t=Vu().createApp(...e),{mount:s}=t;return t.mount=n=>{const o=Fu(n);if(!o)return;const r=t._component;!oe(r)&&!r.render&&!r.template&&(r.template=o.innerHTML),o.nodeType===1&&(o.textContent="");const l=s(o,!1,Du(o));return o instanceof Element&&(o.removeAttribute("v-cloak"),o.setAttribute("data-v-app","")),l},t});function Du(e){if(e instanceof SVGElement)return"svg";if(typeof MathMLElement=="function"&&e instanceof MathMLElement)return"mathml"}function Fu(e){return Ce(e)?document.querySelector(e):e}let Ui;const Kn=e=>Ui=e,Hi=Symbol();function To(e){return e&&typeof e=="object"&&Object.prototype.toString.call(e)==="[object Object]"&&typeof e.toJSON!="function"}var Ws;(function(e){e.direct="direct",e.patchObject="patch object",e.patchFunction="patch function"})(Ws||(Ws={}));function Bu(){const e=Sl(!0),t=e.run(()=>ue({}));let s=[],n=[];const o=Wo({install(r){Kn(o),o._a=r,r.provide(Hi,o),r.config.globalProperties.$pinia=o,n.forEach(l=>s.push(l)),n=[]},use(r){return this._a?s.push(r):n.push(r),this},_p:s,_a:null,_e:e,_s:new Map,state:t});return o}const Wi=()=>{};function Yr(e,t,s,n=Wi){e.add(t);const o=()=>{e.delete(t)&&n()};return!s&&El()&&ka(o),o}function fs(e,...t){e.forEach(s=>{s(...t)})}const Uu=e=>e(),Qr=Symbol(),io=Symbol();function Ao(e,t){e instanceof Map&&t instanceof Map?t.forEach((s,n)=>e.set(n,s)):e instanceof Set&&t instanceof Set&&t.forEach(e.add,e);for(const s in t){if(!t.hasOwnProperty(s))continue;const n=t[s],o=e[s];To(o)&&To(n)&&e.hasOwnProperty(s)&&!Ae(n)&&!Et(n)?e[s]=Ao(o,n):e[s]=n}return e}const Hu=Symbol();function Wu(e){return!To(e)||!Object.prototype.hasOwnProperty.call(e,Hu)}const{assign:jt}=Object;function Ku(e){return!!(Ae(e)&&e.effect)}function Gu(e,t,s,n){const{state:o,actions:r,getters:l}=t,i=s.state.value[e];let a;function f(){i||(s.state.value[e]=o?o():{});const u=Wa(s.state.value[e]);return jt(u,r,Object.keys(l||{}).reduce((d,g)=>(d[g]=Wo(xe(()=>{Kn(s);const p=s._s.get(e);return l[g].call(p,p)})),d),{}))}return a=Ki(e,f,t,s,n,!0),a}function Ki(e,t,s={},n,o,
Line truncated
|
||||
`);for(const n of s){const o=n.trim();if(!(!o||o.startsWith("#"))){if(o.includes("config_name")){const r=o.match(/config_name\s*=\s*"([^"]*)"/);r&&(t.config_name=r[1])}else if(o.includes("network_code")){const r=o.match(/network_code\s*=\s*"([^"]*)"/);r&&(t.network_code=r[1])}else if(o.startsWith("server")){const r=o.match(/server\s*=\s*\[(.*)\]/);if(r){const l=r[1].match(/"([^"]*)"/g);l&&(t.server=l.map(i=>i.replace(/"/g,"")))}}else if(o.includes("ip =")){const r=o.match(/ip\s*=\s*"([^"]*)"/);r&&(t.ip=r[1])}else if(o.includes("mtu =")){const r=o.match(/mtu\s*=\s*(\d+)/);r&&(t.mtu=parseInt(r[1]))}else if(o.match(/^rtx\s*=/))t.rtx=o.includes("true");else if(o.match(/^fec\s*=/))t.fec=o.includes("true");else if(o.match(/^compress\s*=/))t.compress=o.includes("true");else if(o.match(/^no_punch\s*=/))t.no_punch=o.includes("true");else if(o.startsWith("input")){const r=o.match(/input\s*=\s*\[(.*)\]/);if(r){const l=r[1].match(/"([^"]*)"/g);l&&(t.input=l.map(i=>i.replace(/"/g,"")))}}else if(o.startsWith("output")){const r=o.match(/output\s*=\s*\[(.*)\]/);if(r){const l=r[1].match(/"([^"]*)"/g);l&&(t.output=l.map(i=>i.replace(/"/g,"")))}}else if(o.match(/^no_nat\s*=/))t.no_nat=o.includes("true");else if(o.match(/^no_tun\s*=/))t.no_tun=o.includes("true");else if(o.startsWith("port_mapping")){const r=o.match(/port_mapping\s*=\s*\[(.*)\]/);if(r){const l=r[1].match(/"([^"]*)"/g);l&&(t.port_mapping=l.map(i=>i.replace(/"/g,"")))}}else if(o.match(/^allow_mapping\s*=/))t.allow_mapping=o.includes("true");else if(o.includes("device_name")){const r=o.match(/device_name\s*=\s*"([^"]*)"/);r&&(t.device_name=r[1])}else if(o.includes("device_id")){const r=o.match(/device_id\s*=\s*"([^"]*)"/);r&&(t.device_id=r[1])}else if(o.includes("tun_name")){const r=o.match(/tun_name\s*=\s*"([^"]*)"/);r&&(t.tun_name=r[1])}else if(o.includes("password =")){const r=o.match(/password\s*=\s*"([^"]*)"/);r&&(t.password=r[1])}else if(o.includes("cert_mode")){const r=o.match(/cert_mode\s*=\s*"([^"]*)"/);if(r){const l=r[1];l.startsWith("finger:")?(t.cert_mode="finger",t.fingerprint=l.substring(7)):t.cert_mode=l}}else if(o.startsWith("udp_stun")){const r=o.match(/udp_stun\s*=\s*\[(.*)\]/);if(r){const l=r[1].match(/"([^"]*)"/g);l&&(t.udp_stun=l.map(i=>i.replace(/"/g,"")))}}else if(o.startsWith("tcp_stun")){const r=o.match(/tcp_stun\s*=\s*\[(.*)\]/);if(r){const l=r[1].match(/"([^"]*)"/g);l&&(t.tcp_stun=l.map(i=>i.replace(/"/g,"")))}}}}return t},po=e=>{let t="";e.config_name&&(t+=`# 配置名称
|
||||
config_name = "${e.config_name}"
|
||||
`),t+=`
|
||||
# --- 网络配置 ---
|
||||
`,t+=`# 网络编号,相同网络编号的会组在同一个虚拟网 (必填)
|
||||
`,t+=`network_code = "${e.network_code}"
|
||||
|
||||
`;const s=e.server.filter(a=>a.trim());s.length>0&&(t+=`# 服务器地址列表(支持 quic / tcp / wss / dynamic) (必填)
|
||||
`,t+=`# dynamic 协议使用dns txt解析记录值
|
||||
`,t+=`server = [${s.map(a=>`"${a}"`).join(", ")}]
|
||||
`),e.ip&&(t+=`
|
||||
# 自定义虚拟 IP (可选)
|
||||
`,t+=`ip = "${e.ip}"
|
||||
`),e.rtx&&(t+=`
|
||||
# 是否启用quic优化传输 (默认 false)
|
||||
`,t+=`# 开启后传输过程几乎不会丢包,但是延迟可能会有波动
|
||||
`,t+=`rtx = true
|
||||
`),e.fec&&(t+=`
|
||||
# 是否启用 FEC 前向纠错 (默认 false)
|
||||
`,t+=`# 开启后可以减少丢包率,损失带宽但是延迟比较稳定,带宽充足时可以使用此功能
|
||||
`,t+=`fec = true
|
||||
`),e.no_punch&&(t+=`
|
||||
# 是否关闭 P2P 打洞 (默认 false)
|
||||
`,t+=`no_punch = true
|
||||
`),e.compress&&(t+=`
|
||||
# 是否启用 LZ4 压缩 (默认 false)
|
||||
`,t+=`compress = true
|
||||
`);const n=e.input.filter(a=>a.trim());n.length>0&&(t+=`
|
||||
# 入栈监听网段 (逗号分隔的 CIDR 和目标 IP),用于点对网,将指定网段的流量发送到目标节点
|
||||
`,t+=`# 例如192.168.0.0/24,10.26.0.2 表示将192.168.0.0/24网段的数据转发到10.26.0.2
|
||||
`,t+=`input = [${n.map(a=>`"${a}"`).join(", ")}]
|
||||
`);const o=e.output.filter(a=>a.trim());o.length>0&&(t+=`
|
||||
# 出栈允许网段,用于点对网,允许指定网段的转发
|
||||
`,t+=`output = [${o.map(a=>`"${a}"`).join(", ")}]
|
||||
`),e.no_nat&&(t+=`
|
||||
# 是否关闭内置子网NAT,关闭后需要配置网卡转发,否则无法使用点对网
|
||||
`,t+=`# 通常关闭内置子网NAT,使用系统的网卡转发,点对网性能会更好
|
||||
`,t+=`no_nat = true
|
||||
`),e.no_tun&&(t+=`
|
||||
# 是否关闭TUN虚拟网卡,关闭后只能充当流量出口或者进行端口映射,关闭后无需管理员权限
|
||||
`,t+=`no_tun = true
|
||||
`);const r=e.port_mapping.filter(a=>a.trim());r.length>0&&(t+=`
|
||||
# 端口映射,格式为:协议://本地监听地址-目标虚拟IP-目标映射地址
|
||||
`,t+=`# 端口映射用于在本地监听指定端口,并将收到的网络流量经由指定虚拟节点转发到目标地址
|
||||
`,t+=`# 例如: tcp://0.0.0.0:81-10.0.0.2-10.0.0.2:80 表示将本地tcp的81端口的数据转发到10.0.0.2:80
|
||||
`,t+=`# 例如: tcp://0.0.0.0:81-10.0.0.2-192.168.1.10:80 则表示将本地tcp的81端口的数据经过10.0.0.2转到192.168.1.10:80
|
||||
`,t+=`# 例如: tcp://0.0.0.0:81-10.0.0.2-anyonehost:80 则表示将本地tcp的81端口的数据经过10.0.0.2转到anyonehost:80
|
||||
`,t+=`port_mapping = [${r.map(a=>`"${a}"`).join(", ")}]
|
||||
`),e.allow_mapping&&(t+=`
|
||||
# 是否允许作为端口映射出口,开启后其他设备才可使用本设备的ip为"目标虚拟IP"
|
||||
`,t+=`# 开启后虚拟网络其他设备可以使用此设备当跳板访问其他网络
|
||||
`,t+=`allow_mapping = true
|
||||
`),e.mtu&&(t+=`
|
||||
# MTU 设置
|
||||
`,t+=`mtu = ${e.mtu}
|
||||
`),t+=`
|
||||
# --- 设备配置 ---
|
||||
`,e.device_name&&(t+=`
|
||||
# 设备名称 (可选,默认读取本机 hostname)
|
||||
`,t+=`device_name = "${e.device_name}"
|
||||
`),e.device_id&&(t+=`
|
||||
# 设备 ID (可选,不填自动生成,不同设备ID不能相同)
|
||||
`,t+=`device_id = "${e.device_id}"
|
||||
`),e.tun_name&&(t+=`
|
||||
# 虚拟网卡名称
|
||||
`,t+=`tun_name = "${e.tun_name}"
|
||||
`),t+=`
|
||||
# --- 安全配置 ---
|
||||
`,e.password&&(t+=`
|
||||
# 组网加密密码 (可选)
|
||||
`,t+=`password = "${e.password}"
|
||||
`),e.cert_mode&&e.cert_mode!=="skip"&&(t+=`
|
||||
# 证书校验方式:
|
||||
`,t+=`# skip 跳过验证(默认)
|
||||
`,t+=`# standard 使用系统证书验证
|
||||
`,t+=`# finger 使用证书指纹验证,服务端启动时日志会输出指纹
|
||||
`,e.cert_mode==="finger"&&e.fingerprint?t+=`cert_mode = "finger:${e.fingerprint}"
|
||||
`:t+=`cert_mode = "${e.cert_mode}"
|
||||
`);const l=e.udp_stun.filter(a=>a.trim());l.length>0&&(t+=`
|
||||
# 自定义UDP STUN地址,不设置则用默认stun
|
||||
`,t+=`udp_stun = [${l.map(a=>`"${a}"`).join(", ")}]
|
||||
`);const i=e.tcp_stun.filter(a=>a.trim());return i.length>0&&(t+=`
|
||||
# 自定义TCP STUN地址,不设置则用默认stun
|
||||
`,t+=`tcp_stun = [${i.map(a=>`"${a}"`).join(", ")}]
|
||||
`),t},N0=`# config_name = "配置名称"
|
||||
# --- 网络配置 ---
|
||||
# 网络编号,相同网络编号的会组在同一个虚拟网 (必填)
|
||||
network_code = "your_network_code"
|
||||
|
||||
# 服务器地址列表(支持 quic / tcp / wss / dynamic) (必填)
|
||||
# dynamic 协议使用dns txt解析记录值
|
||||
server = ["quic://1.2.3.4:29872"]
|
||||
|
||||
# ===简单使用以下参数可以不动===
|
||||
|
||||
# 自定义虚拟 IP (可选)
|
||||
# ip = "10.10.0.2"
|
||||
|
||||
# 是否启用quic优化传输 (默认 false,设置为true时开启)
|
||||
# 开启后传输过程几乎不会丢包,但是延迟会有波动
|
||||
# rtx = false
|
||||
|
||||
# 是否启用 FEC 前向纠错,损失一定带宽来提升网络稳定性(默认 false,设置为true时开启)
|
||||
# 开启后可以减少丢包率,损失带宽但是延迟比较稳定,带宽充足时可以使用此功能
|
||||
# fec = false
|
||||
|
||||
# 是否关闭 P2P 打洞 (默认 false,设置为true时关闭)
|
||||
# no_punch = false
|
||||
|
||||
# 是否启用 LZ4 压缩 (默认 false,设置为true时开启)
|
||||
# compress = false
|
||||
|
||||
# 入栈监听网段 (逗号分隔的 CIDR 和目标 IP),用于点对网,将指定网段的流量发送到目标节点
|
||||
# input = ["192.168.0.0/24,10.26.0.2", "192.168.1.0/24,10.26.0.3"]
|
||||
|
||||
# 出栈允许网段,用于点对网,允许指定网段的转发
|
||||
# output = ["0.0.0.0/0"]
|
||||
|
||||
# 是否关闭内置子网NAT,关闭(设为true)后需要配置网卡转发,否则无法使用点对网。通常关闭内置子网NAT,使用系统的网卡转发,点对网性能会更好
|
||||
# no_nat = false
|
||||
|
||||
# 是否关闭TUN虚拟网卡,关闭(设为true)后只能充当流量出口或者进行端口映射,关闭后无需管理员权限
|
||||
# no_tun = false
|
||||
|
||||
# 端口映射,格式为:协议://本地监听地址-目标虚拟IP-目标映射地址
|
||||
# 端口映射用于在本地监听指定端口,并将收到的网络流量经由指定虚拟节点转发到目标地址,从而实现跨网络或内网服务访问
|
||||
# 例如 port_mapping = ["tcp://0.0.0.0:81-10.0.0.2-10.0.0.2:80"]
|
||||
# tcp://0.0.0.0:81-10.0.0.2-10.0.0.2:80 则表示将本地tcp的81端口的数据转发到10.0.0.2:80
|
||||
# tcp://0.0.0.0:81-10.0.0.2-192.168.1.10:80 则表示将本地tcp的81端口的数据经过10.0.0.2转到192.168.1.10:80
|
||||
# tcp://0.0.0.0:81-10.0.0.2-anyonehost:80 则表示将本地tcp的81端口的数据经过10.0.0.2转到anyonehost:80
|
||||
# port_mapping = []
|
||||
|
||||
# 是否允许作为端口映射出口,开启(设置为true)后其他设备才可使用本设备的ip为"目标虚拟IP"
|
||||
# 开启后虚拟网络其他设备可以使用此设备当跳板访问其他网络
|
||||
# allow_mapping = false
|
||||
|
||||
# MTU 设置
|
||||
# mtu = 1400
|
||||
|
||||
# --- 设备配置 ---
|
||||
|
||||
# 设备名称 (可选,默认读取本机 hostname)
|
||||
# device_name = "my-device"
|
||||
|
||||
# 设备 ID (可选,不填自动生成,不同设备ID不能相同)
|
||||
# device_id = "device-id-xxxx"
|
||||
|
||||
# 虚拟网卡名称
|
||||
# tun_name = "vnt-tun"
|
||||
|
||||
# --- 安全配置 ---
|
||||
|
||||
# 加密密码 (可选)
|
||||
# password = "123456"
|
||||
|
||||
# 证书校验方式:
|
||||
# skip 跳过验证(默认)
|
||||
# standard 使用系统证书验证
|
||||
# finger 使用证书指纹验证,服务端启动时日志会输出指纹,
|
||||
# 例如 finger:3bdd8675606837cdf95d5e13445606315762315a78555f9da652940a25feaec1
|
||||
# cert_mode = "skip"
|
||||
|
||||
# --- 其他配置 ---
|
||||
# 自定义stun地址,分别用于udp打洞和tcp打洞,需要单独配置,不设置则用默认stun
|
||||
# udp_stun = ["stun.chat.bilibili.com"]
|
||||
# tcp_stun = ["stun.nextcloud.com:443"]`,V0={class:"text-lg font-bold text-slate-900 dark:text-white"},j0={class:"flex items-center gap-4"},D0={class:"flex rounded-lg border border-slate-300 bg-slate-100 p-1 dark:border-slate-600 dark:bg-slate-800"},F0={key:0,class:"text-sm text-slate-500 font-mono hidden md:block"},B0={class:"h-full overflow-y-auto scrollbar-hide p-6"},U0={class:"max-w-4xl mx-auto space-y-6"},H0={class:"card"},W0={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},K0={class:"mt-4"},G0={class:"space-y-2"},q0=["onUpdate:modelValue"],z0=["onClick"],J0={class:"card"},Y0={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},Q0={class:"card"},Z0={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},X0={class:"card"},eh={class:"space-y-4"},th={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},sh={key:0},nh={class:"card"},oh={class:"space-y-4"},rh={class:"space-y-2"},lh=["onUpdate:modelValue"],ih=["onClick"],ah={class:"space-y-2"},ch=["onUpdate:modelValue"],uh=["onClick"],fh={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},dh={class:"card"},ph={class:"space-y-4"},hh={class:"space-y-2"},mh=["onUpdate:modelValue"],gh=["onClick"],vh={class:"card"},_h={class:"grid grid-cols-1 md:grid-cols-3 gap-4"},bh={class:"card"},xh={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},yh={class:"space-y-2"},kh=["onUpdate:modelValue"],wh=["onClick"],Ch={class:"space-y-2"},Sh=["onUpdate:modelValue"],Eh=["onClick"],Th={class:"h-full"},Ah={class:"flex-1 text-left text-xs text-slate-500"},Ih={key:0},Rh={key:1},Jt="h-5 w-5 rounded border-slate-300 bg-white text-indigo-600 focus:ring-indigo-500 dark:border-slate-600 dark:bg-slate-700",Yt="flex cursor-pointer items-center justify-between gap-2 rounded-lg border border-slate-200 bg-slate-50 p-3 transition-colors hover:bg-slate-100 dark:border-slate-700 dark:bg-slate-800/50 dark:hover:bg-slate-800",ds="shrink-0 rounded-lg bg-red-50 px-3 py-2 text-red-500 transition-colors hover:bg-red-100 dark:bg-red-900/20 dark:text-red-500 dark:hover:bg-red-900/40",ps="flex w-full items-center justify-center gap-1 rounded-lg bg-slate-100 px-3 py-2 text-sm text-slate-600 transition-colors hover:bg-slate-200 dark:bg-slate-700/50 dark:text-slate-300 dark:hover:bg-slate-700",Lt="text-md mb-4 flex items-center font-bold text-slate-900 dark:text-white",$h={__name:"ConfigEditor",props:{show:{type:Boolean,default:!1},fileName:{type:String,default:null}},emits:["close","saved"],setup(e,{emit:t}){const s=e,n=t,o=is(),r=ue(""),l=ue(""),i=ue("new"),a=ue("form"),f=ue(""),u=ue(!1),d=ue(!1),g=ue(!1),p=ue(Mo());Ge(()=>s.show,async R=>{if(R)if(l.value=s.fileName||"",i.value=s.fileName?"edit":"new",a.value="form",u.value=!1,d.value=!1,s.fileName)try{const m=await nf(s.fileName);r.value=m,f.value=m,g.value=!0,p.value=hl(m),$t(()=>{g.value=!1})}catch(m){o.toast.error("获取配置失败: "+m.message),n("close")}else f.value="",p.value=Mo(),r.value=N0});const w=()=>{a.value==="toml"?(a.value="form",g.value=!0,p.value=hl(r.value),$t(()=>{g.value=!1})):a.value="form"},C=()=>{a.value==="form"&&(d.value?(r.value=po(p.value),d.value=!1):f.value&&!u.value?r.value=f.value:r.value=po(p.value)),a.value="toml"};Ge(r,(R,m)=>{a.value==="toml"&&m!==void 0&&(u.value=!0)}),Ge(p,()=>{a.value==="form"&&s.show&&!g.value&&(d.value=!0)},{deep:!0});const L=async()=>{try{let R=r.value;if(a.value==="form"){if(!p.value.network_code.trim()){o.toast.error("请填写网络编号");return}if(p.value.server.filter(_=>_.trim()).length===0){o.toast.error("请至少填写一个服务器地址");return}R=po(p.value)}await of(l.value||null,R),o.toast.success("配置已保存"),n("close"),n("saved")}catch(R){o.toast.error("保存失败: "+R.message)}};return(R,m)=>(y(),Me(nr,{show:e.show,"mask-closable":!1,"panel-class":"w-full max-w-6xl h-[85vh]",onClose:m[26]||(m[26]=_=>n("close"))},{header:Se(()=>[c("h3",V0,B(i.value==="new"?"新建配置":"编辑配置"),1),c("div",j0,[c("div",D0,[c("button",{onClick:w,class:q([a.value==="form"?"bg-white text-slate-900 shadow-sm dark:bg-indigo-600 dark:text-white":"text-slate-500 hover:text-slate-900 dark:text-slate-400 dark:hover:text-white","px-4 py-1.5 rounded text-sm font-medium transition-colors flex items-center"])},[...m[27]||(m[27]=[c("svg",{class:"w-4 h-4 mr-1.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[c("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})],-1),re(" 表单模式 ",-1)])],2),c("button",{onClick:C,class:q([a.value==="toml"?"bg-white text-slate-900 shadow-sm dark:bg-indigo-600 dark:text-white":"text-slate-500 hover:text-slate-900 dark:text-slate-400 dark:hover:text-white","px-4 py-1.5 rounded text-sm font-medium transition-colors flex items-center"])},[...m[28]||(m[28]=[c("svg",{class:"w-4 h-4 mr-1.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[c("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M10 20l4-
Line truncated
|
||||
@@ -1 +0,0 @@
|
||||
@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-translate-x:0;--tw-translate-y:0;--tw-translate-z:0;--tw-rotate-x:initial;--tw-rotate-y:initial;--tw-rotate-z:initial;--tw-skew-x:initial;--tw-skew-y:initial;--tw-space-y-reverse:0;--tw-border-style:solid;--tw-leading:initial;--tw-font-weight:initial;--tw-tracking:initial;--tw-ordinal:initial;--tw-slashed-zero:initial;--tw-numeric-figure:initial;--tw-numeric-spacing:initial;--tw-numeric-fraction:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-backdrop-blur:initial;--tw-backdrop-brightness:initial;--tw-backdrop-contrast:initial;--tw-backdrop-grayscale:initial;--tw-backdrop-hue-rotate:initial;--tw-backdrop-invert:initial;--tw-backdrop-opacity:initial;--tw-backdrop-saturate:initial;--tw-backdrop-sepia:initial;--tw-duration:initial;--tw-scale-x:1;--tw-scale-y:1;--tw-scale-z:1;--tw-divide-y-reverse:0}}}@layer theme{:root,:host{--font-sans:-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;--color-red-50:oklch(97.1% .013 17.38);--color-red-100:oklch(93.6% .032 17.717);--color-red-200:oklch(88.5% .062 18.334);--color-red-300:oklch(80.8% .114 19.571);--color-red-400:oklch(70.4% .191 22.216);--color-red-500:oklch(63.7% .237 25.331);--color-red-600:oklch(57.7% .245 27.325);--color-red-700:oklch(50.5% .213 27.518);--color-red-900:oklch(39.6% .141 25.723);--color-yellow-100:oklch(97.3% .071 103.193);--color-yellow-300:oklch(90.5% .182 98.111);--color-yellow-400:oklch(85.2% .199 91.936);--color-yellow-500:oklch(79.5% .184 86.047);--color-yellow-600:oklch(68.1% .162 75.834);--color-yellow-700:oklch(55.4% .135 66.442);--color-yellow-900:oklch(42.1% .095 57.708);--color-green-100:oklch(96.2% .044 156.743);--color-green-200:oklch(92.5% .084 155.995);--color-green-300:oklch(87.1% .15 154.449);--color-green-400:oklch(79.2% .209 151.711);--color-green-500:oklch(72.3% .219 149.579);--color-green-600:oklch(62.7% .194 149.214);--color-green-700:oklch(52.7% .154 150.069);--color-green-800:oklch(44.8% .119 151.328);--color-green-900:oklch(39.3% .095 152.535);--color-blue-100:oklch(93.2% .032 255.585);--color-blue-300:oklch(80.9% .105 251.813);--color-blue-400:oklch(70.7% .165 254.624);--color-blue-500:oklch(62.3% .214 259.815);--color-blue-600:oklch(54.6% .245 262.881);--color-blue-700:oklch(48.8% .243 264.376);--color-blue-900:oklch(37.9% .146 265.522);--color-indigo-50:oklch(96.2% .018 272.314);--color-indigo-400:oklch(67.3% .182 276.935);--color-indigo-500:oklch(58.5% .233 277.117);--color-indigo-600:oklch(51.1% .262 276.966);--color-purple-100:oklch(94.6% .033 307.174);--color-purple-300:oklch(82.7% .119 306.383);--color-purple-400:oklch(71.4% .203 305.504);--color-purple-600:oklch(55.8% .288 302.321);--color-purple-700:oklch(49.6% .265 301.924);--color-purple-900:oklch(38.1% .176 304.987);--color-slate-50:oklch(98.4% .003 247.858);--color-slate-100:oklch(96.8% .007 247.896);--color-slate-200:oklch(92.9% .013 255.508);--color-slate-300:oklch(86.9% .022 252.894);--color-slate-400:oklch(70.4% .04 256.788);--color-slate-500:oklch(55.4% .046 257.417);--color-slate-600:oklch(44.6% .043 257.281);--color-slate-700:oklch(37.2% .044 257.287);--color-slate-800:oklch(27.9% .041 260.031);--color-slate-900:oklch(20.8% .042 265.755);--color-slate-950:oklch(12.9% .042 264.695);--color-black:#000;--color-white:#fff;--spacing:.25rem;--container-sm:24rem;--container-2xl:42rem;--container-4xl:56rem;--container-6xl:72rem;--text-xs:.75rem;--text-xs--line-height:calc(1 / .75);--text-sm:.875rem;--text-sm--line-height:calc(1.25 / .875);--text-base:1rem;--text-base--line-height: 1.5 ;--text-lg:1.125rem;--text-lg--line-height:calc(1.75 / 1.125);--text-2xl:1.5rem;--text-2xl--line-height:calc(2 / 1.5);--font-weight-normal:400;--font-weight-medium:500;--font-weight-bold:700;--tracking-wide:.025em;--tracking-wider:.05em;--tracking-widest:.1em;--leading-relaxed:1.625;--radius-md:.375rem;--radius-lg:.5rem;--radius-xl:.75rem;--animate-spin:spin 1s linear infinite;--animate-ping:ping 1s cubic-bezier(0, 0, .2, 1) infinite;--animate-pulse:pulse 2s cubic-bezier(.4, 0, .6, 1) infinite;--blur-sm:8px;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4, 0, .2, 1);--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:beLine truncated
|
||||
|
After Width: | Height: | Size: 16 KiB |
@@ -19,8 +19,8 @@
|
||||
if (dark) document.documentElement.classList.add("dark");
|
||||
})();
|
||||
</script>
|
||||
<script type="module" crossorigin src="/assets/index-DM6YOQ55.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-xUGHQxai.css">
|
||||
<script type="module" crossorigin src="/assets/index-BxCqIugQ.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-BgNGjSZS.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
||||
@@ -8,14 +8,14 @@
|
||||
"build": "vite build"
|
||||
},
|
||||
"dependencies": {
|
||||
"pinia": "^3.0.3",
|
||||
"vue": "^3.5.18",
|
||||
"vue-router": "^4.5.1"
|
||||
"pinia": "catalog:",
|
||||
"vue": "catalog:",
|
||||
"vue-router": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/vite": "^4.1.12",
|
||||
"@vitejs/plugin-vue": "^6.0.1",
|
||||
"tailwindcss": "^4.1.12",
|
||||
"vite": "^7.1.3"
|
||||
"@tailwindcss/vite": "catalog:",
|
||||
"@vitejs/plugin-vue": "catalog:",
|
||||
"tailwindcss": "catalog:",
|
||||
"vite": "catalog:"
|
||||
}
|
||||
}
|
||||
@@ -1,203 +1,116 @@
|
||||
<script setup>
|
||||
import { ref, provide } from "vue";
|
||||
import { computed, onBeforeUnmount, onMounted, provide, ref, watch } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { useAppStore } from "./stores/app";
|
||||
import { useStartLogStore } from "./stores/startLog";
|
||||
import { visibleNavItems } from "./navigation";
|
||||
import AppSidebar from "./components/AppSidebar.vue";
|
||||
import AppModal from "./components/AppModal.vue";
|
||||
import ToastHost from "./components/ToastHost.vue";
|
||||
import ConfirmHost from "./components/ConfirmHost.vue";
|
||||
import StatusDot from "./components/StatusDot.vue";
|
||||
import AppTooltip from "./components/AppTooltip.vue";
|
||||
import ConfirmHost from "./components/ConfirmHost.vue";
|
||||
import ToastHost from "./components/ToastHost.vue";
|
||||
import AccessGate from "./components/AccessGate.vue";
|
||||
import { authorized, isDesktop } from "./auth";
|
||||
|
||||
const app = useAppStore();
|
||||
const startLog = useStartLogStore();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const tooltipRef = ref(null);
|
||||
provide("peerTooltip", tooltipRef);
|
||||
|
||||
// 主题切换:localStorage 持久化,默认跟随系统
|
||||
const isDark = ref(document.documentElement.classList.contains("dark"));
|
||||
const mobileNavOpen = ref(false);
|
||||
const items = visibleNavItems();
|
||||
const pageMeta = computed(() => items.find((item) => item.to === route.path) || items[0]);
|
||||
|
||||
const savedTheme = localStorage.getItem("vnt-theme");
|
||||
const isDark = ref(savedTheme
|
||||
? savedTheme === "dark"
|
||||
: window.matchMedia("(prefers-color-scheme: dark)").matches);
|
||||
const applyTheme = () => document.documentElement.classList.toggle("dark", isDark.value);
|
||||
const toggleTheme = () => {
|
||||
isDark.value = !isDark.value;
|
||||
document.documentElement.classList.toggle("dark", isDark.value);
|
||||
localStorage.setItem("vnt-theme", isDark.value ? "dark" : "light");
|
||||
applyTheme();
|
||||
};
|
||||
applyTheme();
|
||||
|
||||
watch(() => route.path, () => { mobileNavOpen.value = false; });
|
||||
|
||||
const handleKeydown = (event) => {
|
||||
if (!(event.ctrlKey || event.metaKey) || event.altKey) return;
|
||||
const index = Number(event.key) - 1;
|
||||
if (index >= 0 && index < items.length) {
|
||||
event.preventDefault();
|
||||
router.push(items[index].to);
|
||||
}
|
||||
};
|
||||
|
||||
const mobileNavOpen = ref(false);
|
||||
const closeMobileNav = () => {
|
||||
mobileNavOpen.value = false;
|
||||
};
|
||||
|
||||
const navItems = [
|
||||
{
|
||||
to: "/",
|
||||
label: "总览",
|
||||
exact: true,
|
||||
icon: "M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6",
|
||||
},
|
||||
{
|
||||
to: "/instances",
|
||||
label: "实例",
|
||||
icon: "M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01",
|
||||
},
|
||||
{
|
||||
to: "/config",
|
||||
label: "配置",
|
||||
icon: "M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z",
|
||||
icon2: "M15 12a3 3 0 11-6 0 3 3 0 016 0z",
|
||||
},
|
||||
{
|
||||
to: "/peers",
|
||||
label: "设备列表",
|
||||
icon: "M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z",
|
||||
},
|
||||
{
|
||||
to: "/routes",
|
||||
label: "路由",
|
||||
icon: "M9 20l-5.447-2.724A1 1 0 013 16.382V5.618a1 1 0 011.447-.894L9 7m0 13l6-3m-6 3V7m6 10l4.553 2.276A1 1 0 0021 18.382V7.618a1 1 0 01-.806-.98l-3.747-1.874M12 7v13m3-13v13m-3 0l3 3",
|
||||
},
|
||||
];
|
||||
onMounted(() => window.addEventListener("keydown", handleKeydown));
|
||||
onBeforeUnmount(() => window.removeEventListener("keydown", handleKeydown));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex min-h-screen flex-col">
|
||||
<!-- 顶部导航栏 -->
|
||||
<header
|
||||
class="sticky top-0 z-30 border-b border-slate-200 bg-white/80 backdrop-blur dark:border-slate-800 dark:bg-slate-900/80"
|
||||
>
|
||||
<div class="mx-auto flex h-14 max-w-6xl items-center gap-3 px-4 lg:px-8">
|
||||
<!-- 移动端汉堡 -->
|
||||
<AccessGate v-if="!isDesktop && !authorized" />
|
||||
<div v-else class="flex h-[100dvh] min-h-0 overflow-hidden bg-slate-50 text-slate-700 dark:bg-slate-950 dark:text-slate-200">
|
||||
<aside class="hidden w-60 shrink-0 border-r border-slate-200 dark:border-slate-800 lg:block">
|
||||
<AppSidebar />
|
||||
</aside>
|
||||
|
||||
<transition name="drawer">
|
||||
<div v-if="mobileNavOpen" class="fixed inset-0 z-40 lg:hidden">
|
||||
<button class="absolute inset-0 bg-slate-950/45 backdrop-blur-[2px]" aria-label="关闭导航" @click="mobileNavOpen = false"></button>
|
||||
<aside class="drawer-panel relative h-full w-[min(82vw,288px)] border-r border-slate-200 shadow-2xl dark:border-slate-700">
|
||||
<AppSidebar @navigate="mobileNavOpen = false" />
|
||||
</aside>
|
||||
</div>
|
||||
</transition>
|
||||
|
||||
<div class="flex min-w-0 flex-1 flex-col">
|
||||
<header class="flex h-16 shrink-0 items-center gap-3 border-b border-slate-200 bg-white/90 px-4 backdrop-blur lg:px-6 dark:border-slate-800 dark:bg-slate-900/90">
|
||||
<button
|
||||
class="rounded-lg p-1.5 text-slate-500 hover:bg-slate-100 hover:text-slate-900 lg:hidden dark:text-slate-400 dark:hover:bg-slate-800 dark:hover:text-white"
|
||||
@click="mobileNavOpen = !mobileNavOpen"
|
||||
class="grid h-9 w-9 shrink-0 place-items-center rounded-lg text-slate-500 hover:bg-slate-100 hover:text-slate-900 lg:hidden dark:text-slate-400 dark:hover:bg-slate-800 dark:hover:text-white"
|
||||
aria-label="打开导航"
|
||||
@click="mobileNavOpen = true"
|
||||
>
|
||||
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
|
||||
</svg>
|
||||
<svg class="h-5 w-5 fill-none stroke-current" viewBox="0 0 24 24"><path d="M4 7h16M4 12h16M4 17h16" stroke-linecap="round" stroke-width="2" /></svg>
|
||||
</button>
|
||||
|
||||
<!-- Logo -->
|
||||
<router-link to="/" class="flex items-center gap-2" @click="closeMobileNav">
|
||||
<span class="text-lg font-bold tracking-wide text-indigo-600 dark:text-indigo-400">VNT</span>
|
||||
<span class="text-sm font-medium text-slate-400 dark:text-slate-500">Web</span>
|
||||
</router-link>
|
||||
<div class="min-w-0">
|
||||
<h1 class="truncate text-lg font-bold text-slate-900 dark:text-white">{{ pageMeta.label }}</h1>
|
||||
<p class="hidden text-xs text-slate-400 sm:block">VNT 虚拟局域网管理</p>
|
||||
</div>
|
||||
|
||||
<!-- 桌面导航 -->
|
||||
<nav class="ml-6 hidden h-14 items-stretch gap-1 lg:flex">
|
||||
<router-link
|
||||
v-for="item in navItems"
|
||||
:key="item.to"
|
||||
:to="item.to"
|
||||
custom
|
||||
v-slot="{ navigate, isActive, isExactActive }"
|
||||
>
|
||||
<button
|
||||
@click="navigate"
|
||||
class="relative flex items-center px-3 text-sm font-medium transition-colors"
|
||||
:class="
|
||||
(item.exact ? isExactActive : isActive)
|
||||
? 'text-indigo-600 dark:text-indigo-400'
|
||||
: 'text-slate-500 hover:text-slate-900 dark:text-slate-400 dark:hover:text-white'
|
||||
"
|
||||
>
|
||||
{{ item.label }}
|
||||
<span
|
||||
v-if="item.exact ? isExactActive : isActive"
|
||||
class="absolute inset-x-3 bottom-0 h-0.5 rounded-full bg-indigo-600 dark:bg-indigo-400"
|
||||
></span>
|
||||
</button>
|
||||
</router-link>
|
||||
</nav>
|
||||
|
||||
<div class="ml-auto flex items-center gap-3">
|
||||
<!-- 全局状态点 -->
|
||||
<div
|
||||
class="flex items-center gap-2 rounded-full border border-slate-200 bg-white px-3 py-1 dark:border-slate-700 dark:bg-slate-800"
|
||||
:title="app.headerStatusText"
|
||||
>
|
||||
<StatusDot
|
||||
:status="app.runningCount > 0 ? 'running' : app.startingCount > 0 ? 'starting' : 'stopped'"
|
||||
/>
|
||||
<span class="hidden text-xs font-medium text-slate-600 sm:inline dark:text-slate-300">{{
|
||||
app.headerStatusText
|
||||
}}</span>
|
||||
<div class="ml-auto flex items-center gap-2">
|
||||
<div class="flex h-8 items-center gap-2 rounded-lg border border-slate-200 bg-white px-2.5 text-xs font-medium text-slate-500 sm:px-3 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-300">
|
||||
<span
|
||||
class="h-1.5 w-1.5 rounded-full"
|
||||
:class="app.runningCount > 0 ? 'bg-green-500' : app.startingCount > 0 ? 'animate-pulse bg-amber-400' : 'bg-slate-300 dark:bg-slate-600'"
|
||||
></span>
|
||||
<span class="hidden sm:inline">{{ app.headerStatusText }}</span>
|
||||
</div>
|
||||
<span class="hidden text-xs text-slate-400 md:inline dark:text-slate-500"
|
||||
>v{{ app.version || "-" }}</span
|
||||
>
|
||||
<!-- 主题切换 -->
|
||||
<button
|
||||
class="rounded-lg border border-slate-200 bg-white p-1.5 text-slate-500 shadow-sm transition-colors hover:bg-slate-50 hover:text-slate-900 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-400 dark:hover:bg-slate-700 dark:hover:text-white"
|
||||
:title="isDark ? '切换到浅色模式' : '切换到深色模式'"
|
||||
class="grid h-8 w-8 place-items-center rounded-lg border border-slate-200 bg-white text-slate-500 hover:border-indigo-300 hover:text-indigo-600 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-400 dark:hover:border-indigo-500 dark:hover:text-indigo-400"
|
||||
:title="isDark ? '切换浅色模式' : '切换深色模式'"
|
||||
:aria-label="isDark ? '切换浅色模式' : '切换深色模式'"
|
||||
@click="toggleTheme"
|
||||
>
|
||||
<svg v-if="isDark" class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"
|
||||
/>
|
||||
</svg>
|
||||
<svg v-else class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"
|
||||
/>
|
||||
</svg>
|
||||
<svg v-if="isDark" class="h-4 w-4 fill-none stroke-current" viewBox="0 0 24 24"><circle cx="12" cy="12" r="4"/><path d="M12 2v2m0 16v2M4.9 4.9l1.4 1.4m11.4 11.4 1.4 1.4M2 12h2m16 0h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4" stroke-linecap="round" stroke-width="1.7"/></svg>
|
||||
<svg v-else class="h-4 w-4 fill-none stroke-current" viewBox="0 0 24 24"><path d="M20.5 15.2A8.5 8.5 0 0 1 8.8 3.5 8.5 8.5 0 1 0 20.5 15.2Z" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.7"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- 移动端下拉导航 -->
|
||||
<transition name="navdrop">
|
||||
<nav
|
||||
v-if="mobileNavOpen"
|
||||
class="border-t border-slate-200 bg-white px-4 py-2 lg:hidden dark:border-slate-800 dark:bg-slate-900"
|
||||
>
|
||||
<router-link
|
||||
v-for="item in navItems"
|
||||
:key="item.to"
|
||||
:to="item.to"
|
||||
custom
|
||||
v-slot="{ navigate, isActive, isExactActive }"
|
||||
>
|
||||
<button
|
||||
@click="
|
||||
navigate();
|
||||
closeMobileNav();
|
||||
"
|
||||
class="flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium transition-colors"
|
||||
:class="
|
||||
(item.exact ? isExactActive : isActive)
|
||||
? 'bg-indigo-50 text-indigo-600 dark:bg-indigo-500/10 dark:text-indigo-400'
|
||||
: 'text-slate-500 hover:bg-slate-50 hover:text-slate-900 dark:text-slate-400 dark:hover:bg-slate-800 dark:hover:text-white'
|
||||
"
|
||||
>
|
||||
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" :d="item.icon" />
|
||||
<path v-if="item.icon2" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" :d="item.icon2" />
|
||||
</svg>
|
||||
{{ item.label }}
|
||||
</button>
|
||||
</router-link>
|
||||
</nav>
|
||||
</transition>
|
||||
</header>
|
||||
<main class="custom-scrollbar min-h-0 flex-1 overflow-x-hidden overflow-y-auto">
|
||||
<div class="mx-auto w-full max-w-7xl px-4 py-5 sm:px-5 lg:px-7 lg:py-6">
|
||||
<router-view v-slot="{ Component }">
|
||||
<transition name="fade" mode="out-in"><component :is="Component" /></transition>
|
||||
</router-view>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<!-- 内容区 -->
|
||||
<main class="flex-1 overflow-x-hidden">
|
||||
<div class="mx-auto w-full max-w-6xl px-4 py-6 lg:px-8">
|
||||
<router-view v-slot="{ Component }">
|
||||
<transition name="fade" mode="out-in">
|
||||
<component :is="Component" />
|
||||
</transition>
|
||||
</router-view>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<!-- 启动日志弹窗 (全局) -->
|
||||
<AppModal
|
||||
:show="startLog.showStartLog"
|
||||
:mask-closable="startLog.startStatus !== 'starting'"
|
||||
@@ -206,66 +119,31 @@ const navItems = [
|
||||
@close="startLog.close"
|
||||
>
|
||||
<template #header>
|
||||
<div class="flex items-center gap-3">
|
||||
<div
|
||||
v-if="startLog.startStatus === 'starting'"
|
||||
class="h-3 w-3 animate-ping rounded-full bg-blue-500"
|
||||
></div>
|
||||
<div v-else-if="startLog.startStatus === 'running'" class="h-3 w-3 rounded-full bg-green-500"></div>
|
||||
<div v-else class="h-3 w-3 rounded-full bg-red-500"></div>
|
||||
<h3 class="text-lg font-bold text-slate-900 dark:text-white">
|
||||
{{
|
||||
startLog.startStatus === "starting"
|
||||
? "正在启动组网..."
|
||||
: startLog.startStatus === "running"
|
||||
? "启动成功"
|
||||
: "启动失败"
|
||||
}}
|
||||
<div class="flex min-w-0 items-center gap-3">
|
||||
<span
|
||||
class="h-2 w-2 shrink-0 rounded-full"
|
||||
:class="startLog.startStatus === 'starting' ? 'animate-pulse bg-amber-400' : startLog.startStatus === 'running' ? 'bg-green-500' : 'bg-red-500'"
|
||||
></span>
|
||||
<h3 class="truncate text-base font-bold text-slate-900 sm:text-lg dark:text-white">
|
||||
{{ startLog.startStatus === "starting" ? "正在建立虚拟网络" : startLog.startStatus === "running" ? "网络已连接" : "连接未完成" }}
|
||||
</h3>
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<span
|
||||
class="max-w-[200px] truncate text-sm font-medium text-indigo-600 dark:text-indigo-400"
|
||||
:title="startLog.logFileName"
|
||||
>{{ startLog.logConfigName }}</span
|
||||
>
|
||||
<span class="font-mono text-xs uppercase tracking-widest text-slate-400">{{
|
||||
startLog.startStatus
|
||||
}}</span>
|
||||
</div>
|
||||
<span class="max-w-[40%] truncate font-mono text-xs text-indigo-600 dark:text-indigo-400">{{ startLog.logConfigName }}</span>
|
||||
</template>
|
||||
<template #body>
|
||||
<div
|
||||
:ref="(el) => (startLog.logContainer = el)"
|
||||
class="scrollbar-hide h-80 space-y-2 overflow-y-auto bg-slate-50 p-6 font-mono text-sm dark:bg-black/20"
|
||||
class="custom-scrollbar h-64 space-y-2 overflow-y-auto border-y border-slate-200 bg-slate-50 p-4 font-mono text-xs text-slate-600 sm:h-80 sm:p-6 dark:border-slate-800 dark:bg-slate-950 dark:text-slate-300"
|
||||
>
|
||||
<div v-for="(log, idx) in startLog.startLogs" :key="idx" class="flex gap-3">
|
||||
<span class="shrink-0 text-indigo-500 dark:text-indigo-400">>>></span>
|
||||
<span class="break-all text-slate-600 dark:text-slate-300">{{ log }}</span>
|
||||
</div>
|
||||
<div v-if="startLog.startStatus === 'starting'" class="mt-4 animate-pulse italic text-blue-500">
|
||||
等待后续步骤...
|
||||
</div>
|
||||
<div
|
||||
v-if="startLog.startStatus === 'stopped' && startLog.startLogs.length > 0"
|
||||
class="mt-4 rounded-lg border border-red-200 bg-red-50 p-3 text-red-600 dark:border-red-900/50 dark:bg-red-900/20 dark:text-red-400"
|
||||
>
|
||||
<strong>启动失败:</strong>
|
||||
请检查配置或网络连接。
|
||||
<span class="text-indigo-600 dark:text-indigo-400">›</span><span class="break-all">{{ log }}</span>
|
||||
</div>
|
||||
<div v-if="startLog.startStatus === 'starting'" class="animate-pulse text-indigo-600 dark:text-indigo-400">等待下一阶段…</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #footer>
|
||||
<button v-if="startLog.startStatus === 'starting'" class="btn-ghost" @click="startLog.cancelStart">
|
||||
取消组网
|
||||
</button>
|
||||
<button
|
||||
v-if="startLog.startStatus === 'stopped' || startLog.startStatus === 'running'"
|
||||
class="btn-primary"
|
||||
@click="startLog.close"
|
||||
>
|
||||
关闭窗口
|
||||
</button>
|
||||
<button v-if="startLog.startStatus === 'starting'" class="btn-ghost" @click="startLog.cancelStart">取消连接</button>
|
||||
<button v-else class="btn-primary" @click="startLog.close">完成</button>
|
||||
</template>
|
||||
</AppModal>
|
||||
|
||||
|
||||
@@ -1,7 +1,23 @@
|
||||
// fetch 封装:统一解包 ApiResponse{code,msg,data},code!==0 抛出带 msg 的错误
|
||||
const request = async (url, options) => {
|
||||
const res = await fetch(url, options);
|
||||
import { clearAccessToken, getAccessToken } from "../auth";
|
||||
|
||||
// HTTP 与 Tauri IPC 共用相同的 ApiResponse{code,msg,data} 协议。
|
||||
const request = async (url, options = {}) => {
|
||||
if (globalThis.__VNT_IPC_REQUEST__) {
|
||||
const json = await globalThis.__VNT_IPC_REQUEST__({
|
||||
method: options.method || "GET",
|
||||
path: url,
|
||||
body: options.body || null,
|
||||
});
|
||||
if (json.code !== 0) throw new Error(json.msg || "请求失败");
|
||||
return json.data;
|
||||
}
|
||||
|
||||
const headers = new Headers(options.headers || {});
|
||||
const token = getAccessToken();
|
||||
if (token) headers.set("Authorization", `Bearer ${token}`);
|
||||
const res = await fetch(url, { ...options, headers });
|
||||
const json = await res.json();
|
||||
if (res.status === 401) clearAccessToken();
|
||||
if (json.code !== 0) {
|
||||
throw new Error(json.msg || "请求失败");
|
||||
}
|
||||
|
||||
|
After Width: | Height: | Size: 16 KiB |
@@ -0,0 +1,32 @@
|
||||
import { ref } from "vue";
|
||||
|
||||
const STORAGE_KEY = "vnt-web-access-token";
|
||||
export const isDesktop = Boolean(globalThis.__VNT_DESKTOP__);
|
||||
|
||||
const url = new URL(window.location.href);
|
||||
const tokenFromUrl = url.searchParams.get("token") || "";
|
||||
if (tokenFromUrl) {
|
||||
localStorage.setItem(STORAGE_KEY, tokenFromUrl);
|
||||
url.searchParams.delete("token");
|
||||
window.history.replaceState({}, "", `${url.pathname}${url.search}${url.hash}`);
|
||||
}
|
||||
|
||||
export const accessToken = ref(
|
||||
isDesktop ? "" : tokenFromUrl || localStorage.getItem(STORAGE_KEY) || "",
|
||||
);
|
||||
export const authorized = ref(isDesktop || Boolean(accessToken.value));
|
||||
|
||||
export const getAccessToken = () => accessToken.value;
|
||||
|
||||
export const saveAccessToken = (token) => {
|
||||
const normalized = token.trim();
|
||||
localStorage.setItem(STORAGE_KEY, normalized);
|
||||
accessToken.value = normalized;
|
||||
authorized.value = Boolean(normalized);
|
||||
};
|
||||
|
||||
export const clearAccessToken = () => {
|
||||
localStorage.removeItem(STORAGE_KEY);
|
||||
accessToken.value = "";
|
||||
authorized.value = false;
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<script setup>
|
||||
import { ref } from "vue";
|
||||
import { saveAccessToken } from "../auth";
|
||||
import vntIcon from "../assets/vnt-icon.png";
|
||||
|
||||
const token = ref("");
|
||||
const submit = () => {
|
||||
if (!token.value.trim()) return;
|
||||
saveAccessToken(token.value);
|
||||
window.location.reload();
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="grid h-[100dvh] place-items-center overflow-y-auto bg-slate-50 p-4 text-slate-700 dark:bg-slate-950 dark:text-slate-200">
|
||||
<form class="w-full max-w-md rounded-2xl border border-slate-200 bg-white p-6 shadow-sm sm:p-8 dark:border-slate-800 dark:bg-slate-900" @submit.prevent="submit">
|
||||
<div class="mb-7 flex items-center gap-3">
|
||||
<img :src="vntIcon" alt="" class="h-10 w-10 shrink-0" />
|
||||
<div>
|
||||
<h1 class="text-lg font-bold text-slate-900 dark:text-white">访问 VNT 控制台</h1>
|
||||
<p class="mt-0.5 text-xs text-slate-400">请输入桌面端 Web 访问设置中的令牌</p>
|
||||
</div>
|
||||
</div>
|
||||
<label class="mb-2 block text-sm font-medium text-slate-700 dark:text-slate-200" for="access-token">访问令牌</label>
|
||||
<input id="access-token" v-model="token" class="input font-mono" type="password" autocomplete="current-password" autofocus placeholder="粘贴访问令牌" />
|
||||
<button class="btn-primary mt-5 w-full" type="submit" :disabled="!token.trim()">进入控制台</button>
|
||||
<p class="mt-5 text-center text-xs leading-5 text-slate-400">令牌只保存在当前浏览器中,可随时在桌面端重新生成。</p>
|
||||
</form>
|
||||
</main>
|
||||
</template>
|
||||
@@ -0,0 +1,60 @@
|
||||
<script setup>
|
||||
import { useRoute } from "vue-router";
|
||||
import { useAppStore } from "../stores/app";
|
||||
import { visibleNavItems } from "../navigation";
|
||||
import vntIcon from "../assets/vnt-icon.png";
|
||||
|
||||
defineEmits(["navigate"]);
|
||||
const route = useRoute();
|
||||
const app = useAppStore();
|
||||
const items = visibleNavItems();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex h-full min-h-0 flex-col bg-white dark:bg-slate-900">
|
||||
<div class="flex h-16 shrink-0 items-center gap-3 border-b border-slate-200 px-5 dark:border-slate-800">
|
||||
<img :src="vntIcon" alt="" class="h-8 w-8 shrink-0" />
|
||||
<div>
|
||||
<div class="text-sm font-bold tracking-wide text-slate-900 dark:text-white">VNT</div>
|
||||
<div class="text-[9px] font-semibold tracking-[0.18em] text-slate-400">CONTROL CENTER</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mx-3 mt-4 flex items-center gap-3 rounded-xl border border-slate-200 bg-slate-50 px-3 py-3 dark:border-slate-700 dark:bg-slate-800/60">
|
||||
<span
|
||||
class="h-2.5 w-2.5 shrink-0 rounded-full"
|
||||
:class="app.runningCount > 0 ? 'bg-green-500' : app.startingCount > 0 ? 'animate-pulse bg-amber-400' : 'bg-slate-300 dark:bg-slate-600'"
|
||||
></span>
|
||||
<div class="min-w-0">
|
||||
<div class="text-[9px] font-semibold tracking-wider text-slate-400">虚拟网络</div>
|
||||
<div class="mt-0.5 truncate text-xs font-medium text-slate-700 dark:text-slate-200">{{ app.headerStatusText }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<nav class="mt-4 flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto px-3" aria-label="主导航">
|
||||
<router-link
|
||||
v-for="item in items"
|
||||
:key="item.to"
|
||||
:to="item.to"
|
||||
class="flex min-h-10 items-center gap-3 rounded-lg px-3 text-sm font-medium transition-colors"
|
||||
:class="route.path === item.to
|
||||
? 'bg-indigo-50 text-indigo-700 dark:bg-indigo-500/10 dark:text-indigo-300'
|
||||
: 'text-slate-500 hover:bg-slate-100 hover:text-slate-900 dark:text-slate-400 dark:hover:bg-slate-800 dark:hover:text-white'"
|
||||
@click="$emit('navigate')"
|
||||
>
|
||||
<svg class="h-[18px] w-[18px] shrink-0 fill-none stroke-current" viewBox="0 0 24 24">
|
||||
<path :d="item.icon" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.7" />
|
||||
</svg>
|
||||
<span>{{ item.label }}</span>
|
||||
</router-link>
|
||||
</nav>
|
||||
|
||||
<div class="mx-3 mt-3 shrink-0 border-t border-slate-200 px-1 py-4 dark:border-slate-800">
|
||||
<div class="flex items-center gap-2 text-xs text-slate-400">
|
||||
<span class="h-1.5 w-1.5 rounded-full" :class="app.version ? 'bg-green-500' : 'bg-amber-400'"></span>
|
||||
<span>{{ app.version ? "本地服务正常" : "正在连接服务…" }}</span>
|
||||
<span class="ml-auto font-mono text-[10px]">v{{ app.version || "2.0" }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -2,6 +2,13 @@ import { createApp } from "vue";
|
||||
import { createPinia } from "pinia";
|
||||
import App from "./App.vue";
|
||||
import router from "./router";
|
||||
import vntIcon from "./assets/vnt-icon.png";
|
||||
import "./style.css";
|
||||
|
||||
const favicon = document.querySelector('link[rel~="icon"]') || document.createElement("link");
|
||||
favicon.rel = "icon";
|
||||
favicon.type = "image/png";
|
||||
favicon.href = vntIcon;
|
||||
document.head.appendChild(favicon);
|
||||
|
||||
createApp(App).use(createPinia()).use(router).mount("#app");
|
||||
@@ -0,0 +1,42 @@
|
||||
export const navItems = [
|
||||
{
|
||||
to: "/",
|
||||
label: "网络总览",
|
||||
shortLabel: "总览",
|
||||
icon: "M4 4h6v6H4V4Zm10 0h6v6h-6V4ZM4 14h6v6H4v-6Zm10 0h6v6h-6v-6Z",
|
||||
},
|
||||
{
|
||||
to: "/instances",
|
||||
label: "运行实例",
|
||||
shortLabel: "实例",
|
||||
icon: "M4 18V8m5 10V4m6 14v-7m5 7V6",
|
||||
},
|
||||
{
|
||||
to: "/peers",
|
||||
label: "在线设备",
|
||||
shortLabel: "设备",
|
||||
icon: "M15 19a6 6 0 0 0-12 0m18 0a5 5 0 0 0-5-5m-7-3a4 4 0 1 0 0-8 4 4 0 0 0 0 8Zm8 0a3 3 0 1 0 0-6",
|
||||
},
|
||||
{
|
||||
to: "/routes",
|
||||
label: "路由表",
|
||||
shortLabel: "路由",
|
||||
icon: "M6 8a2 2 0 1 0 0-4 2 2 0 0 0 0 4Zm12 12a2 2 0 1 0 0-4 2 2 0 0 0 0 4ZM8 6h6a4 4 0 0 1 4 4v2m-3-3 3 3 3-3M16 18h-6a4 4 0 0 1-4-4v-2",
|
||||
},
|
||||
{
|
||||
to: "/config",
|
||||
label: "组网配置",
|
||||
shortLabel: "配置",
|
||||
icon: "M12 15.5a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7Zm7.4-.5a1.7 1.7 0 0 0 .3 1.9l.1.1-2.8 2.8-.1-.1a1.7 1.7 0 0 0-1.9-.3A1.7 1.7 0 0 0 14 21v.2h-4V21a1.7 1.7 0 0 0-1-1.6 1.7 1.7 0 0 0-1.9.3l-.1.1L4.2 17l.1-.1a1.7 1.7 0 0 0 .3-1.9A1.7 1.7 0 0 0 3 14h-.2v-4H3a1.7 1.7 0 0 0 1.6-1 1.7 1.7 0 0 0-.3-1.9L4.2 7 7 4.2l.1.1A1.7 1.7 0 0 0 9 4.6 1.7 1.7 0 0 0 10 3v-.2h4V3a1.7 1.7 0 0 0 1 1.6 1.7 1.7 0 0 0 1.9-.3l.1-.1L19.8 7l-.1.1a1.7 1.7 0 0 0-.3 1.9 1.7 1.7 0 0 0 1.6 1h.2v4H21a1.7 1.7 0 0 0-1.6 1Z",
|
||||
},
|
||||
{
|
||||
to: "/web-access",
|
||||
label: "Web 访问",
|
||||
shortLabel: "Web",
|
||||
desktopOnly: true,
|
||||
icon: "M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18Zm0 0c2.2-2.5 3.3-5.5 3.3-9S14.2 5.5 12 3m0 18c-2.2-2.5-3.3-5.5-3.3-9S9.8 5.5 12 3M3.5 9h17m-17 6h17",
|
||||
},
|
||||
];
|
||||
|
||||
export const visibleNavItems = () =>
|
||||
navItems.filter((item) => !item.desktopOnly || globalThis.__VNT_DESKTOP__);
|
||||
@@ -4,6 +4,7 @@ import InstancesView from "../views/InstancesView.vue";
|
||||
import ConfigView from "../views/ConfigView.vue";
|
||||
import PeersView from "../views/PeersView.vue";
|
||||
import RoutesView from "../views/RoutesView.vue";
|
||||
import WebAccessView from "../views/WebAccessView.vue";
|
||||
|
||||
const routes = [
|
||||
{ path: "/", component: DashboardView },
|
||||
@@ -13,6 +14,7 @@ const routes = [
|
||||
{ path: "/config", component: ConfigView },
|
||||
{ path: "/peers", component: PeersView },
|
||||
{ path: "/routes", component: RoutesView },
|
||||
{ path: "/web-access", component: WebAccessView },
|
||||
];
|
||||
|
||||
export default createRouter({
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
} from "../api";
|
||||
import { useUiStore } from "./ui";
|
||||
import { useStartLogStore } from "./startLog";
|
||||
import { getAccessToken, isDesktop } from "../auth";
|
||||
|
||||
export const useAppStore = defineStore("app", () => {
|
||||
const ui = useUiStore();
|
||||
@@ -217,6 +218,7 @@ export const useAppStore = defineStore("app", () => {
|
||||
startLog.bindApp({ fetchInstances, instanceList, configList });
|
||||
|
||||
const init = async () => {
|
||||
if (!isDesktop && !getAccessToken()) return;
|
||||
document.addEventListener("visibilitychange", visibilityHandler);
|
||||
fetchVersion();
|
||||
await fetchInstances();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
@import "tailwindcss";
|
||||
@source "./**/*.{vue,js}";
|
||||
|
||||
@custom-variant dark (&:where(.dark, .dark *));
|
||||
|
||||
@@ -12,6 +13,13 @@ body {
|
||||
@apply bg-slate-50 text-slate-700 antialiased dark:bg-slate-950 dark:text-slate-200;
|
||||
}
|
||||
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.scrollbar-hide::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
@@ -123,6 +131,27 @@ body {
|
||||
transform: translateY(-6px);
|
||||
}
|
||||
|
||||
/* 移动端侧栏抽屉 */
|
||||
.drawer-enter-active,
|
||||
.drawer-leave-active {
|
||||
transition: opacity 0.2s ease;
|
||||
}
|
||||
|
||||
.drawer-enter-active .drawer-panel,
|
||||
.drawer-leave-active .drawer-panel {
|
||||
transition: transform 0.2s ease;
|
||||
}
|
||||
|
||||
.drawer-enter-from,
|
||||
.drawer-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.drawer-enter-from .drawer-panel,
|
||||
.drawer-leave-to .drawer-panel {
|
||||
transform: translateX(-100%);
|
||||
}
|
||||
|
||||
@utility btn {
|
||||
@apply inline-flex items-center justify-center gap-1.5 px-4 py-2 rounded-lg text-sm font-medium
|
||||
transition-all duration-150 active:scale-95 cursor-pointer
|
||||
@@ -232,9 +261,15 @@ body {
|
||||
@apply text-2xl font-bold text-slate-900 dark:text-white;
|
||||
}
|
||||
|
||||
.page-subtitle {
|
||||
@apply mt-1 text-sm text-slate-500 dark:text-slate-400;
|
||||
}
|
||||
.page-subtitle {
|
||||
@apply mt-1 text-sm text-slate-500 dark:text-slate-400;
|
||||
}
|
||||
|
||||
/* 页面名称由统一外壳标题栏展示,视图只保留自身操作按钮。 */
|
||||
.page-title,
|
||||
.page-subtitle {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* 弱文本 */
|
||||
.muted {
|
||||
|
||||
@@ -111,7 +111,7 @@ onMounted(() => app.fetchConfigList());
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-4 flex justify-end opacity-0 transition-opacity group-hover:opacity-100">
|
||||
<div class="config-card-actions mt-4 flex justify-end transition-opacity">
|
||||
<button
|
||||
class="mr-4 text-sm text-indigo-600 hover:text-indigo-500 dark:text-indigo-400"
|
||||
@click.stop="openEditor(cfg.file_name)"
|
||||
@@ -133,3 +133,22 @@ onMounted(() => app.fetchConfigList());
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 触屏和窄屏设备没有可靠的 hover,操作按钮必须直接可见。 */
|
||||
.config-card-actions {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* 只有宽屏且确实支持精细悬停的设备才使用移入显示。 */
|
||||
@media (min-width: 640px) and (hover: hover) and (pointer: fine) {
|
||||
.config-card-actions {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.group:hover .config-card-actions,
|
||||
.group:focus-within .config-card-actions {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,211 @@
|
||||
<script setup>
|
||||
import { onMounted, reactive, ref } from "vue";
|
||||
|
||||
const bridge = globalThis.__VNT_WEB_ACCESS__;
|
||||
const draft = reactive({ enabled: false, port: 19099, global: false, token: "" });
|
||||
const status = ref(null);
|
||||
const loading = ref(true);
|
||||
const saving = ref(false);
|
||||
const notice = ref("");
|
||||
const error = ref("");
|
||||
|
||||
const sync = (value) => {
|
||||
status.value = value;
|
||||
Object.assign(draft, {
|
||||
enabled: value.enabled,
|
||||
port: value.port,
|
||||
global: value.global,
|
||||
token: value.token,
|
||||
});
|
||||
};
|
||||
|
||||
const load = async () => {
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
try {
|
||||
if (!bridge) throw new Error("Web 访问设置仅在桌面客户端中提供");
|
||||
sync(await bridge.status());
|
||||
} catch (err) {
|
||||
error.value = err.message || String(err);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const update = async (changes, successMessage) => {
|
||||
saving.value = true;
|
||||
error.value = "";
|
||||
notice.value = "";
|
||||
try {
|
||||
sync(await bridge.update({
|
||||
...draft,
|
||||
...changes,
|
||||
port: Number(changes.port ?? draft.port),
|
||||
}));
|
||||
notice.value = successMessage;
|
||||
} catch (err) {
|
||||
const message = err.message || String(err);
|
||||
try {
|
||||
sync(await bridge.status());
|
||||
} catch {
|
||||
// 保留原始操作错误,状态刷新失败不覆盖它。
|
||||
}
|
||||
error.value = message;
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const toggleService = async () => {
|
||||
const enabled = !draft.enabled;
|
||||
await update(
|
||||
{ enabled },
|
||||
enabled ? "Web 服务已启动" : "Web 服务已关闭",
|
||||
);
|
||||
};
|
||||
|
||||
const regenerate = async () => {
|
||||
const token = await bridge.generateToken();
|
||||
await update(
|
||||
{ token },
|
||||
draft.enabled ? "新令牌已生效,Web 服务已重新加载" : "新令牌已生成",
|
||||
);
|
||||
};
|
||||
|
||||
const saveNetworkSettings = async () => {
|
||||
if (draft.enabled) return;
|
||||
await update({}, "监听设置已自动保存");
|
||||
};
|
||||
|
||||
const copyToken = async () => {
|
||||
await navigator.clipboard.writeText(draft.token);
|
||||
notice.value = "访问令牌已复制";
|
||||
};
|
||||
|
||||
const copyUrl = async () => {
|
||||
await navigator.clipboard.writeText(status.value.url);
|
||||
notice.value = "访问地址已复制";
|
||||
};
|
||||
|
||||
const openBrowser = async () => {
|
||||
await bridge.openUrl(status.value.url);
|
||||
};
|
||||
|
||||
onMounted(load);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="mx-auto max-w-4xl space-y-5">
|
||||
<div class="page-title">
|
||||
<div>
|
||||
<h2>Web 访问</h2>
|
||||
<p>从浏览器访问当前 VNT 进程,API 请求由持久访问令牌保护。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="loading" class="card text-sm text-slate-400">正在读取 Web 服务状态…</div>
|
||||
<div v-else-if="!bridge" class="card border-red-200 text-sm text-red-600 dark:border-red-900 dark:text-red-300">{{ error }}</div>
|
||||
<template v-else>
|
||||
<section class="card space-y-6">
|
||||
<div class="flex items-start justify-between gap-5">
|
||||
<div>
|
||||
<h3 class="text-sm font-semibold text-slate-900 dark:text-white">启用 Web 服务</h3>
|
||||
<p class="mt-1 text-xs leading-5 text-slate-400">服务内置于桌面客户端,不会启动单独的 vnt2_web 进程。</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
role="switch"
|
||||
aria-label="启用 Web 服务"
|
||||
:aria-checked="draft.enabled"
|
||||
:disabled="saving"
|
||||
class="web-switch transition-colors disabled:opacity-50"
|
||||
:class="draft.enabled ? 'bg-indigo-600 dark:bg-indigo-500' : 'bg-slate-300 dark:bg-slate-600'"
|
||||
@click="toggleService"
|
||||
>
|
||||
<span class="web-switch-knob bg-white shadow-sm" :class="{ 'web-switch-knob-on': draft.enabled }"></span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-5 sm:grid-cols-2">
|
||||
<label class="block">
|
||||
<span class="mb-2 block text-sm font-medium text-slate-700 dark:text-slate-200">监听端口</span>
|
||||
<input v-model.number="draft.port" class="input font-mono" type="number" min="1" max="65535" :disabled="saving || draft.enabled" @change="saveNetworkSettings" />
|
||||
</label>
|
||||
<label class="block">
|
||||
<span class="mb-2 block text-sm font-medium text-slate-700 dark:text-slate-200">监听范围</span>
|
||||
<select v-model="draft.global" class="input" :disabled="saving || draft.enabled" @change="saveNetworkSettings">
|
||||
<option :value="false">仅本机(推荐)</option>
|
||||
<option :value="true">局域网内所有设备</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<p class="-mt-3 text-xs text-slate-400">端口和监听范围会自动保存;需要修改时请先关闭 Web 服务。</p>
|
||||
|
||||
<div>
|
||||
<div class="mb-2 flex items-center justify-between gap-3">
|
||||
<span class="text-sm font-medium text-slate-700 dark:text-slate-200">访问令牌</span>
|
||||
<button class="text-xs font-medium text-indigo-600 hover:text-indigo-500 disabled:opacity-50 dark:text-indigo-400" type="button" :disabled="saving" @click="regenerate">更换令牌</button>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<code class="min-w-0 flex-1 truncate rounded-lg border border-slate-200 bg-slate-50 px-3 py-2.5 text-xs text-slate-600 dark:border-slate-700 dark:bg-slate-950 dark:text-slate-300">{{ draft.token }}</code>
|
||||
<button class="btn-ghost shrink-0" type="button" :disabled="saving" @click="copyToken">复制令牌</button>
|
||||
</div>
|
||||
<p class="mt-2 text-xs text-slate-400">更换令牌后,已登录的浏览器需要使用新令牌重新鉴权。</p>
|
||||
</div>
|
||||
|
||||
<div v-if="notice || error" class="border-t border-slate-200 pt-5 dark:border-slate-800">
|
||||
<span v-if="notice" class="text-xs text-green-600 dark:text-green-400">{{ notice }}</span>
|
||||
<span v-if="error" class="text-xs text-red-600 dark:text-red-400">{{ error }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<div class="flex items-start gap-3">
|
||||
<span class="mt-1 h-2.5 w-2.5 shrink-0 rounded-full" :class="status?.running ? 'bg-green-500' : 'bg-slate-300 dark:bg-slate-600'"></span>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="text-sm font-semibold text-slate-900 dark:text-white">{{ status?.running ? "运行中" : "未运行" }}</div>
|
||||
<div class="mt-1 text-xs text-slate-400">监听地址:{{ status?.listenAddress }}</div>
|
||||
<div v-if="status?.running" class="mt-4 rounded-lg border border-slate-200 bg-slate-50 px-3 py-2.5 font-mono text-xs text-slate-600 dark:border-slate-700 dark:bg-slate-950 dark:text-slate-300">
|
||||
<span class="block truncate">{{ status.url }}</span>
|
||||
</div>
|
||||
<div v-if="status?.running" class="mt-3 flex flex-wrap gap-2">
|
||||
<button class="btn-primary btn-sm" type="button" @click="openBrowser">打开浏览器</button>
|
||||
<button class="btn-ghost btn-sm" type="button" @click="copyUrl">复制访问地址</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.web-switch {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
flex: 0 0 44px;
|
||||
align-items: center;
|
||||
width: 44px;
|
||||
min-width: 44px;
|
||||
height: 24px;
|
||||
min-height: 24px;
|
||||
padding: 2px;
|
||||
border: 0;
|
||||
border-radius: 9999px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.web-switch-knob {
|
||||
display: block;
|
||||
width: 20px;
|
||||
min-width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 9999px;
|
||||
transform: translateX(0);
|
||||
transition: transform 160ms ease;
|
||||
}
|
||||
|
||||
.web-switch-knob-on {
|
||||
transform: translateX(20px);
|
||||
}
|
||||
</style>
|
||||