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>2023-04-24 13:43:25 +0300
committerMHSanaei <ho3ein.sanaei@gmail.com>2023-04-24 13:43:25 +0300
commit262e3c0985c8c315c78f86370e8b338df9e69593 (patch)
tree1604b62009ab3f4ea1d60c27c96c97d8ed698614 /web
parent2b460bac1ab87c8a478af51cbb00aa1ffd3bd99a (diff)
Add database migration
Co-Authored-By: Alireza Ahmadi <alireza7@gmail.com>
Diffstat (limited to 'web')
-rw-r--r--web/service/inbound.go45
-rw-r--r--web/service/xray.go3
2 files changed, 45 insertions, 3 deletions
diff --git a/web/service/inbound.go b/web/service/inbound.go
index fac6fc47..3f736470 100644
--- a/web/service/inbound.go
+++ b/web/service/inbound.go
@@ -528,14 +528,17 @@ func (s *InboundService) adjustTraffics(tx *gorm.DB, dbClientTraffics []*xray.Cl
if err != nil {
return nil, err
}
+
inbounds[inbound_index].Settings = string(modifiedSettings)
+ }
}
err = tx.Save(inbounds).Error
if err != nil {
logger.Warning("AddClientTraffic update inbounds ", err)
logger.Error(inbounds)
- }
+ }
}
+
return dbClientTraffics, nil
}
@@ -778,3 +781,43 @@ func (s *InboundService) SearchInbounds(query string) ([]*model.Inbound, error)
}
return inbounds, nil
}
+func (s *InboundService) MigrationRequirements() {
+ db := database.GetDB()
+ var inbounds []*model.Inbound
+ err := db.Model(model.Inbound{}).Where("protocol IN (?)", []string{"vmess", "vless", "trojan"}).Find(&inbounds).Error
+ if err != nil && err != gorm.ErrRecordNotFound {
+ return
+ }
+ for inbound_index := range inbounds {
+ settings := map[string]interface{}{}
+ json.Unmarshal([]byte(inbounds[inbound_index].Settings), &settings)
+ clients, ok := settings["clients"].([]interface{})
+ if ok {
+ var newClients []interface{}
+ for client_index := range clients {
+ c := clients[client_index].(map[string]interface{})
+
+ // Add email='' if it is not exists
+ if _, ok := c["email"]; !ok {
+ c["email"] = ""
+ }
+
+ // Remove "flow": "xtls-rprx-direct"
+ if _, ok := c["flow"]; ok {
+ if c["flow"] == "xtls-rprx-direct" {
+ c["flow"] = ""
+ }
+ }
+ newClients = append(newClients, interface{}(c))
+ }
+ settings["clients"] = newClients
+ modifiedSettings, err := json.MarshalIndent(settings, "", " ")
+ if err != nil {
+ return
+ }
+
+ inbounds[inbound_index].Settings = string(modifiedSettings)
+ }
+ }
+ db.Save(inbounds)
+}
diff --git a/web/service/xray.go b/web/service/xray.go
index 9c23f7a4..6008a493 100644
--- a/web/service/xray.go
+++ b/web/service/xray.go
@@ -69,7 +69,6 @@ func (s *XrayService) GetXrayConfig() (*xray.Config, error) {
}
s.inboundService.DisableInvalidClients()
- s.inboundService.RemoveOrphanedTraffics()
inbounds, err := s.inboundService.GetAllInbounds()
if err != nil {
@@ -124,7 +123,7 @@ func (s *XrayService) GetXrayConfig() (*xray.Config, error) {
}
settings["clients"] = final_clients
- modifiedSettings, err := json.Marshal(settings)
+ modifiedSettings, err := json.MarshalIndent(settings, "", " ")
if err != nil {
return nil, err
}