mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-26 13:07:14 +00:00
fix(clients): reuse stored credentials when re-adding an existing identity
Create permits a repeat add for an email that already exists when the payload subId matches the stored one (the documented way to attach an identity to more inbounds), but it never seeded the payload from the existing record, so an omitted id minted a fresh UUID via fillProtocolDefaults. SyncInbound then overwrote the shared clients.uuid row by email while previously-attached inbounds kept the original UUID in their settings JSON, silently desyncing panel credentials from subscription links. BulkCreate had the identical gap. Seed ID/Password/Auth/Secret from the existing record in both paths (mirroring what Update, Attach and BulkAttach already do), and preserve Secret in Update too so partial edits of MTProto clients cannot rotate the stored secret. Closes #5903
This commit is contained in:
@@ -1208,7 +1208,7 @@ func (s *ClientService) BulkCreate(inboundSvc *InboundService, payloads []Client
|
||||
|
||||
db := database.GetDB()
|
||||
const lookupChunk = 400
|
||||
existingEmailSub := make(map[string]string, len(emails))
|
||||
existingByEmail := make(map[string]model.ClientRecord, len(emails))
|
||||
for start := 0; start < len(emails); start += lookupChunk {
|
||||
end := min(start+lookupChunk, len(emails))
|
||||
var rows []model.ClientRecord
|
||||
@@ -1216,7 +1216,7 @@ func (s *ClientService) BulkCreate(inboundSvc *InboundService, payloads []Client
|
||||
return result, false, e
|
||||
}
|
||||
for i := range rows {
|
||||
existingEmailSub[strings.ToLower(rows[i].Email)] = rows[i].SubID
|
||||
existingByEmail[strings.ToLower(rows[i].Email)] = rows[i]
|
||||
}
|
||||
}
|
||||
existingSubOwner := make(map[string]string, len(subIDs))
|
||||
@@ -1252,10 +1252,24 @@ func (s *ClientService) BulkCreate(inboundSvc *InboundService, payloads []Client
|
||||
|
||||
for idx := range prep {
|
||||
le := strings.ToLower(prep[idx].client.Email)
|
||||
if existSub, ok := existingEmailSub[le]; ok && existSub != prep[idx].client.SubID {
|
||||
failed[idx] = true
|
||||
reason[idx] = "email already in use: " + prep[idx].client.Email
|
||||
continue
|
||||
if rec, ok := existingByEmail[le]; ok {
|
||||
if rec.SubID != prep[idx].client.SubID {
|
||||
failed[idx] = true
|
||||
reason[idx] = "email already in use: " + prep[idx].client.Email
|
||||
continue
|
||||
}
|
||||
if prep[idx].client.ID == "" {
|
||||
prep[idx].client.ID = rec.UUID
|
||||
}
|
||||
if prep[idx].client.Password == "" {
|
||||
prep[idx].client.Password = rec.Password
|
||||
}
|
||||
if prep[idx].client.Auth == "" {
|
||||
prep[idx].client.Auth = rec.Auth
|
||||
}
|
||||
if prep[idx].client.Secret == "" {
|
||||
prep[idx].client.Secret = rec.Secret
|
||||
}
|
||||
}
|
||||
if owner, ok := existingSubOwner[prep[idx].client.SubID]; ok && owner != le {
|
||||
failed[idx] = true
|
||||
|
||||
Reference in New Issue
Block a user