Add Harbor Gateway auto-detection for client routing
This commit is contained in:
@@ -16,14 +16,18 @@ function findOutbound(subscriptionConfig, selectedTag) {
|
||||
));
|
||||
}
|
||||
|
||||
export function buildGatewayConfig(subscriptionConfig, selectedTag) {
|
||||
export function buildGatewayConfig(subscriptionConfig, selectedTag, { clientDirect = false } = {}) {
|
||||
const clientMode = settings.appMode === 'client';
|
||||
const vpnOutbound = structuredClone(findOutbound(subscriptionConfig, selectedTag));
|
||||
if (!vpnOutbound) throw new Error(`Outbound не найден: ${selectedTag}`);
|
||||
if (!vpnOutbound.tag) vpnOutbound.tag = 'vpn-out';
|
||||
if (vpnOutbound.type === 'vless' && !vpnOutbound.packet_encoding) {
|
||||
const directClient = clientMode && clientDirect;
|
||||
const vpnOutbound = directClient
|
||||
? null
|
||||
: structuredClone(findOutbound(subscriptionConfig, selectedTag));
|
||||
if (!directClient && !vpnOutbound) throw new Error(`Outbound не найден: ${selectedTag}`);
|
||||
if (vpnOutbound && !vpnOutbound.tag) vpnOutbound.tag = 'vpn-out';
|
||||
if (vpnOutbound?.type === 'vless' && !vpnOutbound.packet_encoding) {
|
||||
vpnOutbound.packet_encoding = 'xudp';
|
||||
}
|
||||
const outboundTag = directClient ? 'direct' : vpnOutbound.tag;
|
||||
|
||||
const inbounds = [
|
||||
...(!clientMode ? [{
|
||||
@@ -44,10 +48,10 @@ export function buildGatewayConfig(subscriptionConfig, selectedTag) {
|
||||
},
|
||||
];
|
||||
const rules = clientMode
|
||||
? [{ inbound: [MIXED_INBOUND], outbound: vpnOutbound.tag }]
|
||||
? [{ inbound: [MIXED_INBOUND], outbound: outboundTag }]
|
||||
: [
|
||||
{ inbound: [TPROXY_INBOUND], outbound: vpnOutbound.tag },
|
||||
{ inbound: [MIXED_INBOUND], outbound: vpnOutbound.tag },
|
||||
{ inbound: [TPROXY_INBOUND], outbound: outboundTag },
|
||||
{ inbound: [MIXED_INBOUND], outbound: outboundTag },
|
||||
];
|
||||
|
||||
return {
|
||||
@@ -58,14 +62,14 @@ export function buildGatewayConfig(subscriptionConfig, selectedTag) {
|
||||
dns: { independent_cache: true },
|
||||
inbounds,
|
||||
outbounds: [
|
||||
vpnOutbound,
|
||||
...(vpnOutbound ? [vpnOutbound] : []),
|
||||
{ type: 'direct', tag: 'direct' },
|
||||
{ type: 'block', tag: 'block' },
|
||||
],
|
||||
route: {
|
||||
rule_set: [],
|
||||
rules,
|
||||
final: vpnOutbound.tag,
|
||||
final: outboundTag,
|
||||
...(clientMode ? {} : { auto_detect_interface: true }),
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user