Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Alireza Ahmadi committed Feb 22, 2023
1 parent 76f774f commit 414669f
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 60 deletions.
19 changes: 13 additions & 6 deletions web/html/xui/client_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
this.inbound = dbInbound.toInbound();
this.clients = this.getClients(this.inbound.protocol, this.inbound.settings);
this.index = index === null ? this.clients.length : index;
this.isExpired = isEdit ? this.inbound.isExpiry(this.index) : false;
if (!isEdit){
this.addClient(this.inbound.protocol, this.clients);
}
Expand Down Expand Up @@ -76,17 +77,23 @@
get isEdit() {
return this.clientModal.isEdit;
},
get isTrafficExhausted() {
if(!clientStats) return false
if(clientStats.total == 0) return false
if(clientStats.up + clientStats.down < clientStats.total) return false
return true
},
get isExpiry() {
return this.clientModal.isExpired
},
get statsColor() {
stats = this.clientModal.clientStats
if(stats.total === 0) return 'blue'
else if(stats.total > 0 && (stats.down+stats.up) < stats.total) return 'cyan'
if(!clientStats) return 'blue'
if(clientStats.total === 0) return 'blue'
else if(clientStats.total > 0 && (clientStats.down+clientStats.up) < clientStats.total) return 'cyan'
else return 'red'
}
},
methods: {
isExpiry() {
return this.clientModal.inbound.isExpiry(this.clientModal.index);
},
getNewEmail(client) {
var chars = 'abcdefghijklmnopqrstuvwxyz1234567890';
var string = '';
Expand Down
6 changes: 3 additions & 3 deletions web/html/xui/form/client.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{define "form/client"}}
<a-form layout="inline" v-if="client">
<template v-if="isEdit">
<a-tag v-if="isExpiry() || (clientStats.up + clientStats.down > client.totalGB && client.totalGB != 0)" color="red" style="margin-bottom: 10px;display: block;text-align: center;">Account is (Expired|Traffic Ended) And Disabled</a-tag>
<a-tag v-if="isExpiry || isTrafficExhausted" color="red" style="margin-bottom: 10px;display: block;text-align: center;">Account is (Expired|Traffic Ended) And Disabled</a-tag>
</template>
<a-form-item>
<span slot="label">
Expand Down Expand Up @@ -52,7 +52,7 @@
</a-tooltip>
</span>
<a-input-number v-model="client._totalGB" :min="0"></a-input-number>
<template v-if="isEdit">
<template v-if="isEdit && clientStats">
{{ i18n "usage" }}:
<a-tag :color="statsColor">
[[ sizeFormat(clientStats.up) ]] /
Expand All @@ -73,7 +73,7 @@
</span>
<a-date-picker :show-time="{ format: 'HH:mm' }" format="YYYY-MM-DD HH:mm"
v-model="client._expiryTime" style="width: 300px;"></a-date-picker>
<a-tag color="red" v-if="isExpiry()">Expired</a-tag>
<a-tag color="red" v-if="isExpiry">Expired</a-tag>
</a-form-item>
</a-form>
{{end}}
4 changes: 2 additions & 2 deletions web/html/xui/inbound_client_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
</a-tooltip>
<a-tooltip>
<template slot="title">{{ i18n "pages.client.edit" }}</template>
<a-icon style="font-size: 24px;" type="edit" @click="openEditClient(record,index);"></a-icon>
<a-icon style="font-size: 24px;" type="edit" @click="openEditClient(record.id,index);"></a-icon>
</a-tooltip>
<a-tooltip>
<template slot="title">{{ i18n "info" }}</template>
<a-icon style="font-size: 24px;" type="info-circle" @click="showInfo(record,index);"></a-icon>
</a-tooltip>
<a-tooltip>
<template slot="title">{{ i18n "pages.inbounds.resetTraffic" }}</template>
<a-icon style="font-size: 24px;" type="retweet" @click="resetClientTraffic(client,record,$event)" v-if="client.email != ''"></a-icon>
<a-icon style="font-size: 24px;" type="retweet" @click="resetClientTraffic(client,record,$event)" v-if="client.email.length > 0"></a-icon>
</a-tooltip>
<a-tooltip>
<template slot="title"><span style="color: #FF4D4F"> {{ i18n "delete"}}</span></template>
Expand Down
11 changes: 9 additions & 2 deletions web/html/xui/inbound_info_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<tr><th>{{ i18n "usage" }}</th><th>{{ i18n "pages.inbounds.totalFlow" }}</th><th>{{ i18n "pages.inbounds.expireDate" }}</th><th>{{ i18n "enable" }}</th></tr>
<tr>
<td>
<a-tag :color="statsColor(infoModal.clientStats)">
<a-tag v-if="infoModal.clientStats" :color="statsColor(infoModal.clientStats)">
[[ sizeFormat(infoModal.clientStats['up']) ]] /
[[ sizeFormat(infoModal.clientStats['down']) ]]
([[ sizeFormat(infoModal.clientStats['up'] + infoModal.clientStats['down']) ]])
Expand All @@ -87,7 +87,7 @@
<a-tag v-else color="green">{{ i18n "indefinite" }}</a-tag>
</td>
<td>
<a-tag v-if="infoModal.clientStats.enable" color="blue">{{ i18n "enabled" }}</a-tag>
<a-tag v-if="isEnable" color="blue">{{ i18n "enabled" }}</a-tag>
<a-tag v-else color="red">{{ i18n "disabled" }}</a-tag>
</td>
</tr>
Expand Down Expand Up @@ -145,6 +145,12 @@
},
get inbound() {
return this.infoModal.inbound;
},
get isEnable() {
if(infoModal.clientStats){
return infoModal.clientStats.enable;
}
return true;
}
},
methods: {
Expand All @@ -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'
Expand Down
59 changes: 15 additions & 44 deletions web/html/xui/inbounds.html
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions web/service/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 414669f

Please sign in to comment.