From f25dec4c8747c41d2717754142332f722249edbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=98=89=E4=BC=9F?= <8473136@qq.com> Date: Thu, 9 Jan 2025 12:10:55 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20xtcp=20keepTunnelOpen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/api/config.ts | 12 ++++++++-- electron/api/frpc.ts | 32 +++++++++++++------------- electron/storage/proxy.ts | 7 +----- src/views/proxy/index.vue | 47 ++++++++++++++++++++++++++++++++++++++- types/global.d.ts | 1 + 5 files changed, 75 insertions(+), 24 deletions(-) diff --git a/electron/api/config.ts b/electron/api/config.ts index 22b0130..ef90b87 100644 --- a/electron/api/config.ts +++ b/electron/api/config.ts @@ -207,7 +207,11 @@ export const initConfigApi = win => { bindPort: null, status: m?.status || true, fallbackTo: m?.fallbackTo, - fallbackTimeoutMs: m?.fallbackTimeoutMs || 500 + fallbackTimeoutMs: m?.fallbackTimeoutMs || 500, + keepTunnelOpen: m?.keepTunnelOpen || false, + https2http: m?.https2http || false, + https2httpCaFile: m?.https2httpCaFile || "", + https2httpKeyFile: m?.https2httpKeyFile || "" }; return rm; }); @@ -237,7 +241,11 @@ export const initConfigApi = win => { bindPort: m?.bindPort, status: m?.status || true, fallbackTo: m?.fallbackTo, - fallbackTimeoutMs: m?.fallbackTimeoutMs || 500 + fallbackTimeoutMs: m?.fallbackTimeoutMs || 500, + keepTunnelOpen: m?.keepTunnelOpen || false, + https2http: m?.https2http || false, + https2httpCaFile: m?.https2httpCaFile || "", + https2httpKeyFile: m?.https2httpKeyFile || "" }; return rm; }); diff --git a/electron/api/frpc.ts b/electron/api/frpc.ts index 97baf50..037d0cc 100644 --- a/electron/api/frpc.ts +++ b/electron/api/frpc.ts @@ -63,8 +63,7 @@ export const genTomlConfig = (config: FrpConfig, proxys: Proxy[]) => { : "proxies" }]] ${rangePort ? "" : `name = "${m.name}"`} -type = "${m.type}" -`; +type = "${m.type}"\n`; switch (m.type) { case "tcp": @@ -72,25 +71,25 @@ type = "${m.type}" if (rangePort) { toml += `name = "${m.name}-{{ $v.First }}" localPort = {{ $v.First }} -remotePort = {{ $v.Second }}`; +remotePort = {{ $v.Second }}\n`; } else { toml += `localIP = "${m.localIp}" localPort = ${m.localPort} -remotePort = ${m.remotePort}`; +remotePort = ${m.remotePort}\n`; } break; case "http": case "https": const customDomains = m.customDomains.filter(f1 => f1 !== ""); if (customDomains && customDomains.length > 0) { - toml += `customDomains=[${m.customDomains.map(m => `"${m}"`)}]`; + toml += `customDomains=[${m.customDomains.map(m => `"${m}"`)}]\n`; } if (m.subdomain) { - toml += `subdomain="${m.subdomain}"`; + toml += `subdomain="${m.subdomain}"\n`; } if (m.basicAuth) { toml += `httpUser = "${m.httpUser}" -httpPassword = "${m.httpPassword}"`; +httpPassword = "${m.httpPassword}"\n`; } if (m.https2http) { toml += `[proxies.plugin] @@ -98,32 +97,35 @@ type = "https2http" localAddr = "${m.localIp}:${m.localPort}" crtPath = "${m.https2httpCaFile}" -keyPath = "${m.https2httpKeyFile}"`; +keyPath = "${m.https2httpKeyFile}"\n`; } else { toml += `localIP = "${m.localIp}" -localPort = ${m.localPort}`; +localPort = ${m.localPort}\n`; } break; - case "stcp": case "xtcp": + if (m.stcpModel === "visitors") { + toml += `keepTunnelOpen = ${m.keepTunnelOpen}\n`; + } + case "stcp": case "sudp": if (m.stcpModel === "visitors") { // 访问者 toml += `serverName = "${m.serverName}" bindAddr = "${m.bindAddr}" -bindPort = ${m.bindPort}`; +bindPort = ${m.bindPort}\n`; if (m.fallbackTo) { toml += `fallbackTo = "${m.fallbackTo}" -fallbackTimeoutMs = ${m.fallbackTimeoutMs || 500}`; +fallbackTimeoutMs = ${m.fallbackTimeoutMs || 500}\n`; } } else if (m.stcpModel === "visited") { // 被访问者 toml += `localIP = "${m.localIp}" -localPort = ${m.localPort}`; +localPort = ${m.localPort}\n`; } - toml += `secretKey="${m.secretKey}" -`; + + toml += `secretKey="${m.secretKey}"\n`; break; default: break; diff --git a/electron/storage/proxy.ts b/electron/storage/proxy.ts index 1dc99c2..6020d2a 100644 --- a/electron/storage/proxy.ts +++ b/electron/storage/proxy.ts @@ -31,7 +31,6 @@ export const deleteProxyById = ( _id: string, cb?: (err: Error | null, n: number) => void ) => { - logDebug(`删除代理:${_id}`); logInfo(LogModule.DB, `Deleting proxy with ID: ${_id}`); proxyDB.remove({ _id: _id }, (err, n) => { if (err) { @@ -50,7 +49,6 @@ export const updateProxyById = ( proxy: Proxy, cb?: (err: Error | null, numberOfUpdated: number, upsert: boolean) => void ) => { - logDebug(`修改代理:${proxy}`); logInfo(LogModule.DB, `Updating proxy: ${JSON.stringify(proxy)}`); proxyDB.update( { _id: proxy._id }, @@ -132,10 +130,7 @@ export const updateProxyStatus = ( {}, (err, numberOfUpdated, upsert) => { if (err) { - logError( - LogModule.DB, - `Error updating proxy status: ${err.message}` - ); + logError(LogModule.DB, `Error updating proxy status: ${err.message}`); } else { logInfo( LogModule.DB, diff --git a/src/views/proxy/index.vue b/src/views/proxy/index.vue index a44eb25..055337a 100644 --- a/src/views/proxy/index.vue +++ b/src/views/proxy/index.vue @@ -66,7 +66,8 @@ const defaultForm = ref({ fallbackTimeoutMs: 500, https2http: false, https2httpCaFile: "", - https2httpKeyFile: "" + https2httpKeyFile: "", + keepTunnelOpen: false }); /** @@ -1420,6 +1421,50 @@ onUnmounted(() => { /> + + + + + + diff --git a/types/global.d.ts b/types/global.d.ts index ba6c0ff..fcaca54 100644 --- a/types/global.d.ts +++ b/types/global.d.ts @@ -36,6 +36,7 @@ declare global { https2http: boolean; https2httpCaFile: string; https2httpKeyFile: string; + keepTunnelOpen: boolean; }; /**