xtcp keepTunnelOpen

This commit is contained in:
刘嘉伟 2025-01-09 12:10:55 +08:00
parent 27c1d42596
commit f25dec4c87
5 changed files with 75 additions and 24 deletions

View File

@ -207,7 +207,11 @@ export const initConfigApi = win => {
bindPort: null, bindPort: null,
status: m?.status || true, status: m?.status || true,
fallbackTo: m?.fallbackTo, 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; return rm;
}); });
@ -237,7 +241,11 @@ export const initConfigApi = win => {
bindPort: m?.bindPort, bindPort: m?.bindPort,
status: m?.status || true, status: m?.status || true,
fallbackTo: m?.fallbackTo, 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; return rm;
}); });

View File

@ -63,8 +63,7 @@ export const genTomlConfig = (config: FrpConfig, proxys: Proxy[]) => {
: "proxies" : "proxies"
}]] }]]
${rangePort ? "" : `name = "${m.name}"`} ${rangePort ? "" : `name = "${m.name}"`}
type = "${m.type}" type = "${m.type}"\n`;
`;
switch (m.type) { switch (m.type) {
case "tcp": case "tcp":
@ -72,25 +71,25 @@ type = "${m.type}"
if (rangePort) { if (rangePort) {
toml += `name = "${m.name}-{{ $v.First }}" toml += `name = "${m.name}-{{ $v.First }}"
localPort = {{ $v.First }} localPort = {{ $v.First }}
remotePort = {{ $v.Second }}`; remotePort = {{ $v.Second }}\n`;
} else { } else {
toml += `localIP = "${m.localIp}" toml += `localIP = "${m.localIp}"
localPort = ${m.localPort} localPort = ${m.localPort}
remotePort = ${m.remotePort}`; remotePort = ${m.remotePort}\n`;
} }
break; break;
case "http": case "http":
case "https": case "https":
const customDomains = m.customDomains.filter(f1 => f1 !== ""); const customDomains = m.customDomains.filter(f1 => f1 !== "");
if (customDomains && customDomains.length > 0) { if (customDomains && customDomains.length > 0) {
toml += `customDomains=[${m.customDomains.map(m => `"${m}"`)}]`; toml += `customDomains=[${m.customDomains.map(m => `"${m}"`)}]\n`;
} }
if (m.subdomain) { if (m.subdomain) {
toml += `subdomain="${m.subdomain}"`; toml += `subdomain="${m.subdomain}"\n`;
} }
if (m.basicAuth) { if (m.basicAuth) {
toml += `httpUser = "${m.httpUser}" toml += `httpUser = "${m.httpUser}"
httpPassword = "${m.httpPassword}"`; httpPassword = "${m.httpPassword}"\n`;
} }
if (m.https2http) { if (m.https2http) {
toml += `[proxies.plugin] toml += `[proxies.plugin]
@ -98,32 +97,35 @@ type = "https2http"
localAddr = "${m.localIp}:${m.localPort}" localAddr = "${m.localIp}:${m.localPort}"
crtPath = "${m.https2httpCaFile}" crtPath = "${m.https2httpCaFile}"
keyPath = "${m.https2httpKeyFile}"`; keyPath = "${m.https2httpKeyFile}"\n`;
} else { } else {
toml += `localIP = "${m.localIp}" toml += `localIP = "${m.localIp}"
localPort = ${m.localPort}`; localPort = ${m.localPort}\n`;
} }
break; break;
case "stcp":
case "xtcp": case "xtcp":
if (m.stcpModel === "visitors") {
toml += `keepTunnelOpen = ${m.keepTunnelOpen}\n`;
}
case "stcp":
case "sudp": case "sudp":
if (m.stcpModel === "visitors") { if (m.stcpModel === "visitors") {
// 访问者 // 访问者
toml += `serverName = "${m.serverName}" toml += `serverName = "${m.serverName}"
bindAddr = "${m.bindAddr}" bindAddr = "${m.bindAddr}"
bindPort = ${m.bindPort}`; bindPort = ${m.bindPort}\n`;
if (m.fallbackTo) { if (m.fallbackTo) {
toml += `fallbackTo = "${m.fallbackTo}" toml += `fallbackTo = "${m.fallbackTo}"
fallbackTimeoutMs = ${m.fallbackTimeoutMs || 500}`; fallbackTimeoutMs = ${m.fallbackTimeoutMs || 500}\n`;
} }
} else if (m.stcpModel === "visited") { } else if (m.stcpModel === "visited") {
// 被访问者 // 被访问者
toml += `localIP = "${m.localIp}" toml += `localIP = "${m.localIp}"
localPort = ${m.localPort}`; localPort = ${m.localPort}\n`;
} }
toml += `secretKey="${m.secretKey}"
`; toml += `secretKey="${m.secretKey}"\n`;
break; break;
default: default:
break; break;

View File

@ -31,7 +31,6 @@ export const deleteProxyById = (
_id: string, _id: string,
cb?: (err: Error | null, n: number) => void cb?: (err: Error | null, n: number) => void
) => { ) => {
logDebug(`删除代理:${_id}`);
logInfo(LogModule.DB, `Deleting proxy with ID: ${_id}`); logInfo(LogModule.DB, `Deleting proxy with ID: ${_id}`);
proxyDB.remove({ _id: _id }, (err, n) => { proxyDB.remove({ _id: _id }, (err, n) => {
if (err) { if (err) {
@ -50,7 +49,6 @@ export const updateProxyById = (
proxy: Proxy, proxy: Proxy,
cb?: (err: Error | null, numberOfUpdated: number, upsert: boolean) => void cb?: (err: Error | null, numberOfUpdated: number, upsert: boolean) => void
) => { ) => {
logDebug(`修改代理:${proxy}`);
logInfo(LogModule.DB, `Updating proxy: ${JSON.stringify(proxy)}`); logInfo(LogModule.DB, `Updating proxy: ${JSON.stringify(proxy)}`);
proxyDB.update( proxyDB.update(
{ _id: proxy._id }, { _id: proxy._id },
@ -132,10 +130,7 @@ export const updateProxyStatus = (
{}, {},
(err, numberOfUpdated, upsert) => { (err, numberOfUpdated, upsert) => {
if (err) { if (err) {
logError( logError(LogModule.DB, `Error updating proxy status: ${err.message}`);
LogModule.DB,
`Error updating proxy status: ${err.message}`
);
} else { } else {
logInfo( logInfo(
LogModule.DB, LogModule.DB,

View File

@ -66,7 +66,8 @@ const defaultForm = ref<Proxy>({
fallbackTimeoutMs: 500, fallbackTimeoutMs: 500,
https2http: false, https2http: false,
https2httpCaFile: "", https2httpCaFile: "",
https2httpKeyFile: "" https2httpKeyFile: "",
keepTunnelOpen: false
}); });
/** /**
@ -1420,6 +1421,50 @@ onUnmounted(() => {
/> />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12">
<el-form-item
label="保持隧道开启:"
prop="keepTunnelOpen"
:rules="[
{
required: true,
message: '保持隧道开启不能为空',
trigger: 'blur'
}
]"
>
<template #label>
<div class="inline-block">
<div class="flex items-center">
<div class="mr-1">
<el-popover placement="top" trigger="hover" width="300">
<template #default>
对应参数<span class="font-black text-[#5A3DAA]"
>keepTunnelOpen</span
>
开启后即使没有流量通过会保持隧道(即连接)打开
</template>
<template #reference>
<IconifyIconOffline
class="text-base"
color="#5A3DAA"
icon="info"
/>
</template>
</el-popover>
</div>
保持隧道开启
</div>
</div>
</template>
<el-switch
active-text="开"
inline-prompt
inactive-text="关"
v-model="editForm.keepTunnelOpen"
/>
</el-form-item>
</el-col>
</template> </template>
<el-col :span="24"> <el-col :span="24">
<el-form-item> <el-form-item>

1
types/global.d.ts vendored
View File

@ -36,6 +36,7 @@ declare global {
https2http: boolean; https2http: boolean;
https2httpCaFile: string; https2httpCaFile: string;
https2httpKeyFile: string; https2httpKeyFile: string;
keepTunnelOpen: boolean;
}; };
/** /**