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,
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;
});

View File

@ -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;

View File

@ -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,

View File

@ -66,7 +66,8 @@ const defaultForm = ref<Proxy>({
fallbackTimeoutMs: 500,
https2http: false,
https2httpCaFile: "",
https2httpKeyFile: ""
https2httpKeyFile: "",
keepTunnelOpen: false
});
/**
@ -1420,6 +1421,50 @@ onUnmounted(() => {
/>
</el-form-item>
</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>
<el-col :span="24">
<el-form-item>

1
types/global.d.ts vendored
View File

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