mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-02 11:15:03 +03:00
fix(database): keep disabled clients disabled in the ClientsTable seeder
The one-time ClientsTable migration builds client records from each inbound's settings with a plain Create, and gorm's default:true on ClientRecord.Enable drops an explicit false from that insert. Every client an operator had disabled before v3.1.0 was therefore stored enabled on an in-place upgrade or a restored backup, and Xray, which now reads that column, let the customer back in. The seeder restates enable=false after Create, as the service paths do since #6478, and a legacy client whose settings carry no switch stays enabled, as releases before 3.1.0 served it.
This commit is contained in:
@@ -3197,6 +3197,11 @@ func seedClientsFromInboundJSON() error {
|
||||
continue
|
||||
}
|
||||
model.NormalizeLegacyClientFields(obj)
|
||||
// Releases before 3.1.0 served a client whose JSON carries no
|
||||
// switch; only an explicit false means disabled.
|
||||
if obj["enable"] == nil {
|
||||
obj["enable"] = true
|
||||
}
|
||||
blob, err := json.Marshal(obj)
|
||||
if err != nil {
|
||||
continue
|
||||
@@ -3218,6 +3223,14 @@ func seedClientsFromInboundJSON() error {
|
||||
if err := tx.Create(incoming).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
// gorm default:true drops enable=false on Create — restate (#6478).
|
||||
if !c.Enable {
|
||||
if err := tx.Model(&model.ClientRecord{}).Where("id = ?", incoming.Id).
|
||||
UpdateColumn("enable", false).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
incoming.Enable = false
|
||||
}
|
||||
byEmail[email] = incoming
|
||||
row = incoming
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user