From 41cba886fd0b588a46956f6aa266c7563abf4704 Mon Sep 17 00:00:00 2001 From: Hossin Asaadi Date: Mon, 21 Nov 2022 05:27:53 -0500 Subject: [PATCH] [bug] fix parse config at starting xray --- web/service/xray.go | 46 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/web/service/xray.go b/web/service/xray.go index d4aa58b5..37fd3b05 100644 --- a/web/service/xray.go +++ b/web/service/xray.go @@ -79,37 +79,35 @@ func (s *XrayService) GetXrayConfig() (*xray.Config, error) { // get settings clients settings := map[string]interface{}{} json.Unmarshal([]byte(inbound.Settings), &settings) - clients := settings["clients"].([]interface{}) - + clients, ok := settings["clients"].([]interface{}) + if ok { + // check users active or not + clientStats := inbound.ClientStats + for _, clientTraffic := range clientStats { + + for index, client := range clients { + c := client.(map[string]interface{}) + if c["email"] == clientTraffic.Email { + if ! clientTraffic.Enable { + clients = RemoveIndex(clients,index) + logger.Info("Remove Inbound User",c["email"] ,"due the expire or traffic limit") - // check users active or not - - clientStats := inbound.ClientStats - for _, clientTraffic := range clientStats { - - for index, client := range clients { - c := client.(map[string]interface{}) - if c["email"] == clientTraffic.Email { - if ! clientTraffic.Enable { - clients = RemoveIndex(clients,index) - logger.Info("Remove Inbound User",c["email"] ,"due the expire or traffic limit") + } } - } + + } - - + settings["clients"] = clients + modifiedSettings, err := json.Marshal(settings) + if err != nil { + return nil, err + } + + inbound.Settings = string(modifiedSettings) } - settings["clients"] = clients - modifiedSettings, err := json.Marshal(settings) - if err != nil { - return nil, err - } - - inbound.Settings = string(modifiedSettings) - inboundConfig := inbound.GenXrayInboundConfig() xrayConfig.InboundConfigs = append(xrayConfig.InboundConfigs, *inboundConfig) }