mirror of
https://github.com/alireza0/s-ui.git
synced 2026-08-27 04:17:00 +00:00
fix api: ignoring user/username field of provided json data #1103
This commit is contained in:
parent
b04dec5c80
commit
2bb40b203a
1 changed files with 34 additions and 0 deletions
|
|
@ -58,6 +58,9 @@ func (s *ClientService) Save(tx *gorm.DB, act string, data json.RawMessage, host
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = setConfigIdentity(&client); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = s.updateLinksWithFixedInbounds(tx, []*model.Client{&client}, hostname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -84,6 +87,11 @@ func (s *ClientService) Save(tx *gorm.DB, act string, data json.RawMessage, host
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, client := range clients {
|
||||
if err = setConfigIdentity(client); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
err = json.Unmarshal(clients[0].Inbounds, &inboundIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -107,6 +115,9 @@ func (s *ClientService) Save(tx *gorm.DB, act string, data json.RawMessage, host
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = setConfigIdentity(client); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(changedInboundIds) > 0 {
|
||||
inboundIds = common.UnionUintArray(inboundIds, changedInboundIds)
|
||||
}
|
||||
|
|
@ -513,6 +524,29 @@ func (s *ClientService) ResetClients(tx *gorm.DB, dt int64) ([]uint, error) {
|
|||
return inboundIds, nil
|
||||
}
|
||||
|
||||
func setConfigIdentity(client *model.Client) error {
|
||||
if client.Name == "" || len(client.Config) < 2 {
|
||||
return nil
|
||||
}
|
||||
var configs map[string]map[string]interface{}
|
||||
if err := json.Unmarshal(client.Config, &configs); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, cfg := range configs {
|
||||
if _, ok := cfg["name"]; ok {
|
||||
cfg["name"] = client.Name
|
||||
} else if _, ok := cfg["username"]; ok {
|
||||
cfg["username"] = client.Name
|
||||
}
|
||||
}
|
||||
newConfig, err := json.Marshal(configs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client.Config = newConfig
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *ClientService) findInboundsChanges(tx *gorm.DB, client *model.Client, fillOmitted bool) ([]uint, error) {
|
||||
var err error
|
||||
var oldClient model.Client
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue