mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-07-09 14:16:07 +00:00
567a4ac4fe
* fix(clients): parse only settings.clients across protocols Several inbound settings readers decoded the whole settings object into map[string][]model.Client. Real protocol settings include scalar keys such as VLESS decryption and Hysteria version, so that shape can fail before callers reach settings.clients or leave them relying on decoder side effects. Add one shared helper that extracts only the clients field through json.RawMessage, then use it from GetClients, SearchClientTraffic and the IP-limit job fallback paths. Regression tests cover VLESS and Hysteria settings with scalar protocol fields. * fix(clients): reject empty inbound settings
33 lines
773 B
Go
33 lines
773 B
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
|
|
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
|
"github.com/mhsanaei/3x-ui/v3/internal/util/common"
|
|
)
|
|
|
|
func ParseInboundSettingsClients(settings string) ([]model.Client, error) {
|
|
trimmed := strings.TrimSpace(settings)
|
|
if trimmed == "" || trimmed == "null" {
|
|
return nil, common.NewError("inbound settings is empty")
|
|
}
|
|
|
|
var payload struct {
|
|
Clients json.RawMessage `json:"clients"`
|
|
}
|
|
if err := json.Unmarshal([]byte(trimmed), &payload); err != nil {
|
|
return nil, err
|
|
}
|
|
if len(payload.Clients) == 0 || string(payload.Clients) == "null" {
|
|
return nil, nil
|
|
}
|
|
|
|
var clients []model.Client
|
|
if err := json.Unmarshal(payload.Clients, &clients); err != nil {
|
|
return nil, err
|
|
}
|
|
return clients, nil
|
|
}
|