From 6099a07ff0a3f619ace3c7645ee76dce943a97e0 Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Mon, 4 May 2026 23:19:25 +0200 Subject: feat: add configurable auto-restart on client auto-disable Add a configurable option to restart Xray when clients are auto-disabled and persist disable actions. Changes include: - New setting restartXrayOnClientDisable (default true), getters/setters in SettingService, UI toggle in general settings, and translations for multiple locales. - AddTraffic signature updated to return a third bool (clientsDisabled). disableInvalidClients now calls Xray API to remove users, marks client_traffics.enable=false, updates inbound.Settings JSON so clients appear disabled in stored settings, and returns appropriate counts/errors. - XrayTrafficJob now checks the clientsDisabled flag and restarts Xray when the setting is enabled (with fallback to mark Xray as needing restart on failure). - XrayService.GetXrayConfig call adjusted to ignore AddTraffic returns. - Subscription generation (subService/subJson/subClash) no longer filters clients by their enable flag when matching subId. - Minor fixes: check_client_ip_job now checks scanner.Err and improved API error handling/logging. These changes ensure auto-disabled clients are propagated to Xray and the stored inbound settings, and provide an option to restart Xray automatically after auto-disable events. --- web/job/check_client_ip_job.go | 3 +++ web/job/xray_traffic_job.go | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'web/job') diff --git a/web/job/check_client_ip_job.go b/web/job/check_client_ip_job.go index 29aa9775..7f0ac2cf 100644 --- a/web/job/check_client_ip_job.go +++ b/web/job/check_client_ip_job.go @@ -199,6 +199,9 @@ func (j *CheckClientIpJob) processLogFile() bool { inboundClientIps[email][ip] = timestamp } } + if err := scanner.Err(); err != nil { + j.checkError(err) + } shouldCleanLog := false for email, ipTimestamps := range inboundClientIps { diff --git a/web/job/xray_traffic_job.go b/web/job/xray_traffic_job.go index f443aa77..71e90caa 100644 --- a/web/job/xray_traffic_job.go +++ b/web/job/xray_traffic_job.go @@ -33,7 +33,7 @@ func (j *XrayTrafficJob) Run() { if err != nil { return } - err, needRestart0 := j.inboundService.AddTraffic(traffics, clientTraffics) + err, needRestart0, clientsDisabled := j.inboundService.AddTraffic(traffics, clientTraffics) if err != nil { logger.Warning("add inbound traffic failed:", err) } @@ -41,6 +41,18 @@ func (j *XrayTrafficJob) Run() { if err != nil { logger.Warning("add outbound traffic failed:", err) } + if clientsDisabled { + restartOnDisable, settingErr := j.settingService.GetRestartXrayOnClientDisable() + if settingErr != nil { + logger.Warning("get RestartXrayOnClientDisable failed:", settingErr) + } + if restartOnDisable { + if err := j.xrayService.RestartXray(true); err != nil { + logger.Warning("restart xray after disabling clients failed:", err) + j.xrayService.SetToNeedRestart() + } + } + } if ExternalTrafficInformEnable, err := j.settingService.GetExternalTrafficInformEnable(); ExternalTrafficInformEnable { j.informTrafficToExternalAPI(traffics, clientTraffics) } else if err != nil { -- cgit v1.2.3