|
-
+
[[ sizeFormat(infoModal.clientStats['up']) ]] /
[[ sizeFormat(infoModal.clientStats['down']) ]]
([[ sizeFormat(infoModal.clientStats['up'] + infoModal.clientStats['down']) ]])
@@ -87,7 +87,7 @@
{{ i18n "indefinite" }}
|
- {{ i18n "enabled" }}
+ {{ i18n "enabled" }}
{{ i18n "disabled" }}
|
@@ -145,6 +145,12 @@
},
get inbound() {
return this.infoModal.inbound;
+ },
+ get isEnable() {
+ if(infoModal.clientStats){
+ return infoModal.clientStats.enable;
+ }
+ return true;
}
},
methods: {
@@ -167,6 +173,7 @@
});
},
statsColor(stats) {
+ if(!stats) return 'blue'
if(stats['total'] === 0) return 'blue'
else if(stats['total'] > 0 && (stats['down']+stats['up']) < stats['total']) return 'cyan'
else return 'red'
diff --git a/web/html/xui/inbounds.html b/web/html/xui/inbounds.html
index 0dd8be35..a6d4339a 100644
--- a/web/html/xui/inbounds.html
+++ b/web/html/xui/inbounds.html
@@ -363,11 +363,12 @@
isEdit: false
});
},
- openEditClient(inbound, index) {
+ openEditClient(dbInbound_id, index) {
+ dbInbound = this.dbInbounds.find(row => row.id === dbInbound_id);
clientModal.show({
title: '{{ i18n "pages.client.edit"}}',
okText: '{{ i18n "pages.client.submitEdit"}}',
- dbInbound: inbound,
+ dbInbound: dbInbound,
index: index,
confirm: async (inbound, dbInbound, index) => {
clientModal.loading();
@@ -488,60 +489,30 @@
if (!msg.success) {
return;
}
- clientStats = inbound.clientStats
+ clientStats = inbound.clientStats.find(stats => stats.email == client.email)
if(clientStats.length > 0)
{
- for (const key in clientStats) {
- if (Object.hasOwnProperty.call(clientStats, key)) {
- if(clientStats[key]['email'] == client.email){
- clientStats[key]['up'] = 0
- clientStats[key]['down'] = 0
- }
- }
- }
+ clientStats.up = 0
+ clientStats.down = 0
}
},
isExpiry(dbInbound, index) {
return dbInbound.toInbound().isExpiry(index)
},
getUpStats(dbInbound, email) {
- clientStats = dbInbound.clientStats
- if(clientStats.length > 0)
- {
- for (const key in clientStats) {
- if (Object.hasOwnProperty.call(clientStats, key)) {
- if(clientStats[key]['email'] == email)
- return clientStats[key]['up']
-
- }
- }
- }
+ if(email.length == 0) return 0
+ clientStats = dbInbound.clientStats.find(stats => stats.email === email)
+ return clientStats ? clientStats.up : 0
},
getDownStats(dbInbound, email) {
- clientStats = dbInbound.clientStats
- if(clientStats.length > 0)
- {
- for (const key in clientStats) {
- if (Object.hasOwnProperty.call(clientStats, key)) {
- if(clientStats[key]['email'] == email)
- return clientStats[key]['down']
-
- }
- }
- }
+ if(email.length == 0) return 0
+ clientStats = dbInbound.clientStats.find(stats => stats.email === email)
+ return clientStats ? clientStats.down : 0
},
isTrafficExhausted(dbInbound, email) {
- clientStats = dbInbound.clientStats
- if(clientStats.length > 0)
- {
- for (const key in clientStats) {
- if (Object.hasOwnProperty.call(clientStats, key)) {
- if(clientStats[key]['email'] == email)
- return clientStats[key]['down']+clientStats[key]['up'] > clientStats[key]['total']
-
- }
- }
- }
+ if(email.length == 0) return false
+ clientStats = dbInbound.clientStats.find(stats => stats.email === email)
+ return clientStats.down + clientStats.up > clientStats.total
},
isClientEnabled(dbInbound, email) {
clientStats = dbInbound.clientStats ? dbInbound.clientStats.find(stats => stats.email === email) : null
diff --git a/web/service/inbound.go b/web/service/inbound.go
index db9686e7..38254d36 100644
--- a/web/service/inbound.go
+++ b/web/service/inbound.go
@@ -251,7 +251,9 @@ func (s *InboundService) AddInboundClient(inbound *model.Inbound) error {
oldInbound.Settings = inbound.Settings
- s.AddClientStat(inbound.Id, &clients[len(clients)-1])
+ if len(clients[len(clients)-1].Email) > 0 {
+ s.AddClientStat(inbound.Id, &clients[len(clients)-1])
+ }
db := database.GetDB()
return db.Save(oldInbound).Error
}
@@ -264,6 +266,7 @@ func (s *InboundService) DelInboundClient(inboundId int, index int) error {
settings := map[string][]model.Client{}
json.Unmarshal([]byte(oldInbound.Settings), &settings)
clients := settings["clients"]
+ email := clients[index].Email
settings["clients"] = append(clients[:index], clients[index+1:]...)
newSetting, err := json.Marshal(settings)
@@ -273,7 +276,10 @@ func (s *InboundService) DelInboundClient(inboundId int, index int) error {
oldInbound.Settings = string(newSetting)
db := database.GetDB()
- s.DelClientStat(db, clients[index].Email)
+ err = s.DelClientStat(db, email)
+ if err != nil {
+ return err
+ }
return db.Save(oldInbound).Error
}
@@ -303,8 +309,17 @@ func (s *InboundService) UpdateInboundClient(inbound *model.Inbound, index int)
oldInbound.Settings = inbound.Settings
- s.UpdateClientStat(oldClients[index].Email, &clients[index])
db := database.GetDB()
+
+ if len(clients[index].Email) > 0 {
+ if len(oldClients[index].Email) > 0 {
+ s.UpdateClientStat(oldClients[index].Email, &clients[index])
+ } else {
+ s.AddClientStat(inbound.Id, &clients[index])
+ }
+ } else {
+ s.DelClientStat(db, oldClients[index].Email)
+ }
return db.Save(oldInbound).Error
}