From b39ac90f1e96bf93ca75c89fc885cde5541952b6 Mon Sep 17 00:00:00 2001 From: Nikan Zeyaei <72458440+NikanZeyaei@users.noreply.github.com> Date: Tue, 24 Nov 2026 14:29:32 +0330 Subject: [PATCH] feat(settings): configurable public IP refresh, IPv6 detection and override (#7189) Since 3.11.0 the panel asks outside IP-echo services for its public address every five minutes, and on a server with no IPv6 it retried the IPv6 services forever. Operators with static addresses had no way to stop it (#7176). Add four General settings: the refresh interval (0 keeps the first answer), a switch for IPv6 detection, and a fixed IPv4 and IPv6 address that replace the lookup. The defaults keep today's behaviour. Clearing an override forgets the earlier success, so the next lookup is not timed from before the pin. --- docs/public/openapi.json | 38 +++++ frontend/public/openapi.json | 38 +++++ frontend/src/generated/examples.ts | 8 + frontend/src/generated/schemas.ts | 38 +++++ frontend/src/generated/types.ts | 8 + frontend/src/generated/zod.ts | 8 + frontend/src/models/setting.ts | 4 + frontend/src/pages/settings/GeneralTab.tsx | 59 +++++++ frontend/src/schemas/setting.ts | 4 + internal/web/entity/check_valid_test.go | 29 ++++ internal/web/entity/entity.go | 51 ++++-- internal/web/service/server.go | 87 +++++++++- .../service/server_public_ip_async_test.go | 154 +++++++++++++++++- internal/web/service/setting.go | 20 +++ internal/web/translation/ar-EG.json | 7 + internal/web/translation/en-US.json | 7 + internal/web/translation/es-ES.json | 7 + internal/web/translation/fa-IR.json | 7 + internal/web/translation/id-ID.json | 7 + internal/web/translation/ja-JP.json | 7 + internal/web/translation/pt-BR.json | 7 + internal/web/translation/ru-RU.json | 7 + internal/web/translation/sk-SK.json | 7 + internal/web/translation/tr-TR.json | 7 + internal/web/translation/uk-UA.json | 7 + internal/web/translation/vi-VN.json | 7 + internal/web/translation/zh-CN.json | 7 + internal/web/translation/zh-TW.json | 7 + 28 files changed, 625 insertions(+), 19 deletions(-) diff --git a/docs/public/openapi.json b/docs/public/openapi.json index 20cd85b2c..87bb72267 100644 --- a/docs/public/openapi.json +++ b/docs/public/openapi.json @@ -170,6 +170,21 @@ "panelOutbound": { "type": "string" }, + "publicIpRefreshMinutes": { + "description": "0 stops refreshing the detected public IP after the first success.", + "maximum": 10080, + "minimum": 0, + "type": "integer" + }, + "publicIpv4Override": { + "type": "string" + }, + "publicIpv6Detect": { + "type": "boolean" + }, + "publicIpv6Override": { + "type": "string" + }, "realityScanCandidates": { "type": "string" }, @@ -652,6 +667,10 @@ "outboundDownThreshold", "pageSize", "panelOutbound", + "publicIpRefreshMinutes", + "publicIpv4Override", + "publicIpv6Detect", + "publicIpv6Override", "realityScanCandidates", "remarkTemplate", "restartXrayOnClientDisable", @@ -961,6 +980,21 @@ "panelOutbound": { "type": "string" }, + "publicIpRefreshMinutes": { + "description": "0 stops refreshing the detected public IP after the first success.", + "maximum": 10080, + "minimum": 0, + "type": "integer" + }, + "publicIpv4Override": { + "type": "string" + }, + "publicIpv6Detect": { + "type": "boolean" + }, + "publicIpv6Override": { + "type": "string" + }, "realityScanCandidates": { "type": "string" }, @@ -1451,6 +1485,10 @@ "outboundDownThreshold", "pageSize", "panelOutbound", + "publicIpRefreshMinutes", + "publicIpv4Override", + "publicIpv6Detect", + "publicIpv6Override", "realityScanCandidates", "remarkTemplate", "restartXrayOnClientDisable", diff --git a/frontend/public/openapi.json b/frontend/public/openapi.json index 20cd85b2c..87bb72267 100644 --- a/frontend/public/openapi.json +++ b/frontend/public/openapi.json @@ -170,6 +170,21 @@ "panelOutbound": { "type": "string" }, + "publicIpRefreshMinutes": { + "description": "0 stops refreshing the detected public IP after the first success.", + "maximum": 10080, + "minimum": 0, + "type": "integer" + }, + "publicIpv4Override": { + "type": "string" + }, + "publicIpv6Detect": { + "type": "boolean" + }, + "publicIpv6Override": { + "type": "string" + }, "realityScanCandidates": { "type": "string" }, @@ -652,6 +667,10 @@ "outboundDownThreshold", "pageSize", "panelOutbound", + "publicIpRefreshMinutes", + "publicIpv4Override", + "publicIpv6Detect", + "publicIpv6Override", "realityScanCandidates", "remarkTemplate", "restartXrayOnClientDisable", @@ -961,6 +980,21 @@ "panelOutbound": { "type": "string" }, + "publicIpRefreshMinutes": { + "description": "0 stops refreshing the detected public IP after the first success.", + "maximum": 10080, + "minimum": 0, + "type": "integer" + }, + "publicIpv4Override": { + "type": "string" + }, + "publicIpv6Detect": { + "type": "boolean" + }, + "publicIpv6Override": { + "type": "string" + }, "realityScanCandidates": { "type": "string" }, @@ -1451,6 +1485,10 @@ "outboundDownThreshold", "pageSize", "panelOutbound", + "publicIpRefreshMinutes", + "publicIpv4Override", + "publicIpv6Detect", + "publicIpv6Override", "realityScanCandidates", "remarkTemplate", "restartXrayOnClientDisable", diff --git a/frontend/src/generated/examples.ts b/frontend/src/generated/examples.ts index 384de907c..aaf5f7f4a 100644 --- a/frontend/src/generated/examples.ts +++ b/frontend/src/generated/examples.ts @@ -43,6 +43,10 @@ export const EXAMPLES: Record = { "outboundDownThreshold": 1, "pageSize": 0, "panelOutbound": "", + "publicIpRefreshMinutes": 0, + "publicIpv4Override": "", + "publicIpv6Detect": false, + "publicIpv6Override": "", "realityScanCandidates": "", "remarkTemplate": "", "restartXrayOnClientDisable": false, @@ -233,6 +237,10 @@ export const EXAMPLES: Record = { "outboundDownThreshold": 1, "pageSize": 0, "panelOutbound": "", + "publicIpRefreshMinutes": 0, + "publicIpv4Override": "", + "publicIpv6Detect": false, + "publicIpv6Override": "", "realityScanCandidates": "", "remarkTemplate": "", "restartXrayOnClientDisable": false, diff --git a/frontend/src/generated/schemas.ts b/frontend/src/generated/schemas.ts index 479ec9fdb..d2ada3474 100644 --- a/frontend/src/generated/schemas.ts +++ b/frontend/src/generated/schemas.ts @@ -144,6 +144,21 @@ export const SCHEMAS: Record = { "panelOutbound": { "type": "string" }, + "publicIpRefreshMinutes": { + "description": "0 stops refreshing the detected public IP after the first success.", + "maximum": 10080, + "minimum": 0, + "type": "integer" + }, + "publicIpv4Override": { + "type": "string" + }, + "publicIpv6Detect": { + "type": "boolean" + }, + "publicIpv6Override": { + "type": "string" + }, "realityScanCandidates": { "type": "string" }, @@ -626,6 +641,10 @@ export const SCHEMAS: Record = { "outboundDownThreshold", "pageSize", "panelOutbound", + "publicIpRefreshMinutes", + "publicIpv4Override", + "publicIpv6Detect", + "publicIpv6Override", "realityScanCandidates", "remarkTemplate", "restartXrayOnClientDisable", @@ -935,6 +954,21 @@ export const SCHEMAS: Record = { "panelOutbound": { "type": "string" }, + "publicIpRefreshMinutes": { + "description": "0 stops refreshing the detected public IP after the first success.", + "maximum": 10080, + "minimum": 0, + "type": "integer" + }, + "publicIpv4Override": { + "type": "string" + }, + "publicIpv6Detect": { + "type": "boolean" + }, + "publicIpv6Override": { + "type": "string" + }, "realityScanCandidates": { "type": "string" }, @@ -1425,6 +1459,10 @@ export const SCHEMAS: Record = { "outboundDownThreshold", "pageSize", "panelOutbound", + "publicIpRefreshMinutes", + "publicIpv4Override", + "publicIpv6Detect", + "publicIpv6Override", "realityScanCandidates", "remarkTemplate", "restartXrayOnClientDisable", diff --git a/frontend/src/generated/types.ts b/frontend/src/generated/types.ts index c9d50cfc6..de54933a3 100644 --- a/frontend/src/generated/types.ts +++ b/frontend/src/generated/types.ts @@ -52,6 +52,10 @@ export interface AllSetting { outboundDownThreshold: number; pageSize: number; panelOutbound: string; + publicIpRefreshMinutes: number; + publicIpv4Override: string; + publicIpv6Detect: boolean; + publicIpv6Override: string; realityScanCandidates: string; remarkTemplate: string; restartXrayOnClientDisable: boolean; @@ -243,6 +247,10 @@ export interface AllSettingView { outboundDownThreshold: number; pageSize: number; panelOutbound: string; + publicIpRefreshMinutes: number; + publicIpv4Override: string; + publicIpv6Detect: boolean; + publicIpv6Override: string; realityScanCandidates: string; remarkTemplate: string; restartXrayOnClientDisable: boolean; diff --git a/frontend/src/generated/zod.ts b/frontend/src/generated/zod.ts index d86fa6391..5b41a7216 100644 --- a/frontend/src/generated/zod.ts +++ b/frontend/src/generated/zod.ts @@ -70,6 +70,10 @@ export const AllSettingSchema = z.object({ outboundDownThreshold: z.number().int().min(1).max(100), pageSize: z.number().int().min(0).max(1000), panelOutbound: z.string(), + publicIpRefreshMinutes: z.number().int().min(0).max(10080), + publicIpv4Override: z.string(), + publicIpv6Detect: z.boolean(), + publicIpv6Override: z.string(), realityScanCandidates: z.string(), remarkTemplate: z.string(), restartXrayOnClientDisable: z.boolean(), @@ -262,6 +266,10 @@ export const AllSettingViewSchema = z.object({ outboundDownThreshold: z.number().int().min(1).max(100), pageSize: z.number().int().min(0).max(1000), panelOutbound: z.string(), + publicIpRefreshMinutes: z.number().int().min(0).max(10080), + publicIpv4Override: z.string(), + publicIpv6Detect: z.boolean(), + publicIpv6Override: z.string(), realityScanCandidates: z.string(), remarkTemplate: z.string(), restartXrayOnClientDisable: z.boolean(), diff --git a/frontend/src/models/setting.ts b/frontend/src/models/setting.ts index 1dcf9abaf..15de68d8e 100644 --- a/frontend/src/models/setting.ts +++ b/frontend/src/models/setting.ts @@ -9,6 +9,10 @@ export class AllSetting { webKeyFile = ''; webBasePath = '/'; sessionMaxAge = 360; + publicIpRefreshMinutes = 5; + publicIpv6Detect = true; + publicIpv4Override = ''; + publicIpv6Override = ''; trustedProxyCIDRs = '127.0.0.1/32,::1/128'; realityScanCandidates = 'www.cloudflare.com:443,www.microsoft.com:443,www.amazon.com:443,aws.amazon.com:443,www.samsung.com:443,www.nvidia.com:443,www.amd.com:443,www.intel.com:443,www.sony.com:443,dl.google.com:443'; diff --git a/frontend/src/pages/settings/GeneralTab.tsx b/frontend/src/pages/settings/GeneralTab.tsx index a03294fd2..c7e853f9c 100644 --- a/frontend/src/pages/settings/GeneralTab.tsx +++ b/frontend/src/pages/settings/GeneralTab.tsx @@ -253,6 +253,65 @@ export default function GeneralTab({ allSetting, updateSetting }: GeneralTabProp /> + + } + description={t('pages.settings.publicIpRefreshDesc')} + > + updateSetting({ publicIpRefreshMinutes: v }))} + /> + + + + } + description={t('pages.settings.publicIpv6DetectDesc')} + > + updateSetting({ publicIpv6Detect: v })} + /> + + + + updateSetting({ publicIpv4Override: e.target.value.trim() })} + /> + + + + updateSetting({ publicIpv6Override: e.target.value.trim() })} + /> + +