From d4250fce313700ffa806881527c425c81aac9f70 Mon Sep 17 00:00:00 2001 From: SerinaNya <34389622+SerinaNya@users.noreply.github.com> Date: Wed, 26 Aug 2026 00:22:59 +0800 Subject: [PATCH] feat(settings): adopt externalEndpoints/denyExternalEndpoint* keys - read externalEndpoints first, fall back to openConnections/LineTable - deny toggles mirror new canonical keys plus legacy aliases on save so both updated and legacy backends keep working --- src/pages/settings.tsx | 52 +++++++++++++++++++++++++++++++----------- src/types/api.ts | 3 +++ 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/pages/settings.tsx b/src/pages/settings.tsx index dd602c6..38b058f 100644 --- a/src/pages/settings.tsx +++ b/src/pages/settings.tsx @@ -96,11 +96,13 @@ interface ConnectionItem { function parseConnectionsFromConfig(config: KLALBControllerConfig | null): ConnectionItem[] { if (!config) return [] const lineTable = ( - Array.isArray(config.openConnections) - ? config.openConnections - : Array.isArray(config.LineTable) - ? config.LineTable - : [] + Array.isArray(config.externalEndpoints) + ? config.externalEndpoints + : Array.isArray(config.openConnections) + ? config.openConnections + : Array.isArray(config.LineTable) + ? config.LineTable + : [] ).map(toAddrString) const connectTable = ( Array.isArray(config.autoConnections) @@ -191,19 +193,29 @@ function SettingsForm({ e.preventDefault() const cleanConnections = connections.filter((c) => c.address.trim() !== '') - // 互斥分离:选中自动连接的进 autoConnections,未选中的进 openConnections - const updatedOpenConnections = cleanConnections + // 互斥分离:选中自动连接的进 autoConnections,未选中的进 externalEndpoints + const updatedExternalEndpoints = cleanConnections .filter((c) => !c.autoConnect) .map((c) => c.address.trim()) const updatedAutoConnections = cleanConnections .filter((c) => c.autoConnect) .map((c) => c.address.trim()) + // 保存时同时携带新键名与历史别名,兼容新旧后端 + const denyQuery = + form.denyExternalEndpointQuery ?? form.denyConnectionQuery ?? form.denyLineTableQuery ?? false + const denyBroadcast = + form.denyExternalEndpointBroadcast ?? + form.denyConnectionBroadcast ?? + form.denyLineTableBroadcast ?? + false + const updatedConfig: Record = { ...form, - openConnections: updatedOpenConnections, + externalEndpoints: updatedExternalEndpoints, + openConnections: updatedExternalEndpoints, autoConnections: updatedAutoConnections, - LineTable: updatedOpenConnections, + LineTable: updatedExternalEndpoints, ConnectLineTable: updatedAutoConnections, ntpServers: ntpServers.filter((s) => s.trim() !== ''), ntpServerTable: ntpServers.filter((s) => s.trim() !== ''), @@ -212,8 +224,10 @@ function SettingsForm({ NetworkInterfaceExcepts: interfaceExcepts.filter((s) => s.trim() !== ''), enableTUN: tunEnabled, TUNName: form.TUNName?.trim() || 'KLALB_SRv6', - denyConnectionQuery: form.denyConnectionQuery ?? form.denyLineTableQuery ?? false, - denyConnectionBroadcast: form.denyConnectionBroadcast ?? form.denyLineTableBroadcast ?? false, + denyExternalEndpointQuery: denyQuery, + denyExternalEndpointBroadcast: denyBroadcast, + denyConnectionQuery: denyQuery, + denyConnectionBroadcast: denyBroadcast, Type: 'KLALBController', } @@ -981,10 +995,16 @@ function SettingsForm({ setForm((prev) => ({ ...prev, + denyExternalEndpointQuery: checked, denyConnectionQuery: checked, denyLineTableQuery: checked, })) @@ -1004,10 +1024,16 @@ function SettingsForm({ setForm((prev) => ({ ...prev, + denyExternalEndpointBroadcast: checked, denyConnectionBroadcast: checked, denyLineTableBroadcast: checked, })) diff --git a/src/types/api.ts b/src/types/api.ts index 379128e..d6a7fc9 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -114,6 +114,7 @@ export interface KLALBControllerConfig { TCPListen?: string UDPListen?: string VirtualSocketName?: string + externalEndpoints?: string[] openConnections?: string[] autoConnections?: string[] ntpServers?: string[] @@ -123,6 +124,8 @@ export interface KLALBControllerConfig { DNS?: string[] ExtraRoutes?: string[] NetworkInterfaceExcepts?: string[] + denyExternalEndpointQuery?: boolean + denyExternalEndpointBroadcast?: boolean denyConnectionQuery?: boolean denyConnectionBroadcast?: boolean denyLineTableQuery?: boolean