Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorMHSanaei <ho3ein.sanaei@gmail.com>2026-04-20 20:45:21 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2026-04-20 20:46:21 +0300
commit9f0055d1938a41794cf93cd633b14eb9d1484284 (patch)
treecc3325723e10ab0e8b15cdab6ab3bc1b2463941e /web
parent88dafa6cdf6fbd13c2ea842ee403330a043ce8ff (diff)
bug fix
Diffstat (limited to 'web')
-rw-r--r--web/service/inbound.go79
1 files changed, 72 insertions, 7 deletions
diff --git a/web/service/inbound.go b/web/service/inbound.go
index 59dc9e65..5153b700 100644
--- a/web/service/inbound.go
+++ b/web/service/inbound.go
@@ -498,17 +498,23 @@ func (s *InboundService) UpdateInbound(inbound *model.Inbound) (*model.Inbound,
logger.Debug("Old inbound deleted by api:", tag)
}
if inbound.Enable {
- inboundJson, err2 := json.MarshalIndent(oldInbound.GenXrayInboundConfig(), "", " ")
+ runtimeInbound, err2 := s.buildRuntimeInboundForAPI(tx, oldInbound)
if err2 != nil {
- logger.Debug("Unable to marshal updated inbound config:", err2)
+ logger.Debug("Unable to prepare runtime inbound config:", err2)
needRestart = true
} else {
- err2 = s.xrayApi.AddInbound(inboundJson)
- if err2 == nil {
- logger.Debug("Updated inbound added by api:", oldInbound.Tag)
- } else {
- logger.Debug("Unable to update inbound by api:", err2)
+ inboundJson, err2 := json.MarshalIndent(runtimeInbound.GenXrayInboundConfig(), "", " ")
+ if err2 != nil {
+ logger.Debug("Unable to marshal updated inbound config:", err2)
needRestart = true
+ } else {
+ err2 = s.xrayApi.AddInbound(inboundJson)
+ if err2 == nil {
+ logger.Debug("Updated inbound added by api:", oldInbound.Tag)
+ } else {
+ logger.Debug("Unable to update inbound by api:", err2)
+ needRestart = true
+ }
}
}
}
@@ -517,6 +523,65 @@ func (s *InboundService) UpdateInbound(inbound *model.Inbound) (*model.Inbound,
return inbound, needRestart, tx.Save(oldInbound).Error
}
+func (s *InboundService) buildRuntimeInboundForAPI(tx *gorm.DB, inbound *model.Inbound) (*model.Inbound, error) {
+ if inbound == nil {
+ return nil, fmt.Errorf("inbound is nil")
+ }
+
+ runtimeInbound := *inbound
+ settings := map[string]any{}
+ if err := json.Unmarshal([]byte(inbound.Settings), &settings); err != nil {
+ return nil, err
+ }
+
+ clients, ok := settings["clients"].([]any)
+ if !ok {
+ return &runtimeInbound, nil
+ }
+
+ var clientStats []xray.ClientTraffic
+ err := tx.Model(xray.ClientTraffic{}).
+ Where("inbound_id = ?", inbound.Id).
+ Select("email", "enable").
+ Find(&clientStats).Error
+ if err != nil {
+ return nil, err
+ }
+
+ enableMap := make(map[string]bool, len(clientStats))
+ for _, clientTraffic := range clientStats {
+ enableMap[clientTraffic.Email] = clientTraffic.Enable
+ }
+
+ finalClients := make([]any, 0, len(clients))
+ for _, client := range clients {
+ c, ok := client.(map[string]any)
+ if !ok {
+ continue
+ }
+
+ email, _ := c["email"].(string)
+ if enable, exists := enableMap[email]; exists && !enable {
+ continue
+ }
+
+ if manualEnable, ok := c["enable"].(bool); ok && !manualEnable {
+ continue
+ }
+
+ finalClients = append(finalClients, c)
+ }
+
+ settings["clients"] = finalClients
+ modifiedSettings, err := json.MarshalIndent(settings, "", " ")
+ if err != nil {
+ return nil, err
+ }
+ runtimeInbound.Settings = string(modifiedSettings)
+
+ return &runtimeInbound, nil
+}
+
func (s *InboundService) updateClientTraffics(tx *gorm.DB, oldInbound *model.Inbound, newInbound *model.Inbound) error {
oldClients, err := s.GetClients(oldInbound)
if err != nil {