From e1da43053d23c995bcd6e7267cb20042398cd64f Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Sun, 9 Apr 2023 23:13:18 +0330 Subject: alireza update pack Co-Authored-By: Alireza Ahmadi --- web/html/xui/inbounds.html | 245 ++++++++++++++++++++++++++++++++------------- 1 file changed, 176 insertions(+), 69 deletions(-) (limited to 'web/html/xui/inbounds.html') diff --git a/web/html/xui/inbounds.html b/web/html/xui/inbounds.html index 90250869..728e62a0 100644 --- a/web/html/xui/inbounds.html +++ b/web/html/xui/inbounds.html @@ -41,8 +41,24 @@ {{ i18n "clients" }}: [[ total.clients ]] - {{ i18n "enabled" }} [[ total.active ]] - {{ i18n "disabled" }} [[ total.deactive ]] + + + [[ total.deactive.length ]] + + + + [[ total.depleted.length ]] + + + + [[ total.expiring.length ]] + @@ -52,7 +68,7 @@
{{ i18n "pages.inbounds.addInbound" }} {{ i18n "pages.inbounds.export" }} - {{ i18n "pages.inbounds.resetAllTraffic" }} + {{ i18n "pages.inbounds.resetAllTraffic" }}
- {{ i18n "pages.inbounds.operate" }} - + {{ i18n "pages.inbounds.operate" }} + {{ i18n "qrCode" }} @@ -76,13 +92,17 @@ + {{ i18n "unlimited" }} - @@ -191,26 +231,26 @@ align: 'center', width: 80, dataIndex: "remark", - }, { - title: '{{ i18n "pages.inbounds.protocol" }}', - align: 'center', - width: 50, - scopedSlots: { customRender: 'protocol' }, }, { title: '{{ i18n "pages.inbounds.port" }}', align: 'center', dataIndex: "port", width: 40, + }, { + title: '{{ i18n "pages.inbounds.protocol" }}', + align: 'left', + width: 70, + scopedSlots: { customRender: 'protocol' }, + }, { + title: '{{ i18n "clients" }}', + align: 'left', + width: 50, + scopedSlots: { customRender: 'clients' }, }, { title: '{{ i18n "pages.inbounds.traffic" }}↑|↓', align: 'center', - width: 150, + width: 120, scopedSlots: { customRender: 'traffic' }, - }, { - title: '{{ i18n "pages.inbounds.transportConfig" }}', - align: 'center', - width: 60, - scopedSlots: { customRender: 'stream' }, }, { title: '{{ i18n "pages.inbounds.expireDate" }}', align: 'center', @@ -220,15 +260,18 @@ const innerColumns = [ { title: '{{ i18n "pages.inbounds.operate" }}', width: 70, scopedSlots: { customRender: 'actions' } }, - { title: '{{ i18n "pages.inbounds.client" }}', width: 60, scopedSlots: { customRender: 'client' } }, - { title: '{{ i18n "pages.inbounds.traffic" }}↑|↓', width: 100, scopedSlots: { customRender: 'traffic' } }, + { title: '{{ i18n "pages.inbounds.enable" }}', width: 30, scopedSlots: { customRender: 'enable' } }, + { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } }, + { title: '{{ i18n "pages.inbounds.traffic" }}↑|↓', width: 70, scopedSlots: { customRender: 'traffic' } }, { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 70, scopedSlots: { customRender: 'expiryTime' } }, - { title: 'UID', width: 150, dataIndex: "id" }, + { title: 'UID', width: 120, dataIndex: "id" }, ]; + const innerTrojanColumns = [ { title: '{{ i18n "pages.inbounds.operate" }}', width: 70, scopedSlots: { customRender: 'actions' } }, - { title: '{{ i18n "pages.inbounds.client" }}', width: 60, scopedSlots: { customRender: 'client' } }, - { title: '{{ i18n "pages.inbounds.traffic" }}↑|↓', width: 100, scopedSlots: { customRender: 'traffic' } }, + { title: '{{ i18n "pages.inbounds.enable" }}', width: 30, scopedSlots: { customRender: 'enable' } }, + { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } }, + { title: '{{ i18n "pages.inbounds.traffic" }}↑|↓', width: 70, scopedSlots: { customRender: 'traffic' } }, { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 70, scopedSlots: { customRender: 'expiryTime' } }, { title: 'Password', width: 100, dataIndex: "password" }, ]; @@ -243,6 +286,11 @@ dbInbounds: [], searchKey: '', searchedInbounds: [], + expireDiff: 0, + trafficDiff: 0, + defaultCert: '', + defaultKey: '', + clientCount: {}, }, methods: { loading(spinning=true) { @@ -258,16 +306,65 @@ this.setInbounds(msg.obj); this.searchKey = ''; }, + async getDefaultSettings() { + this.loading(); + const msg = await HttpUtil.post('/xui/setting/defaultSettings'); + this.loading(false); + if (!msg.success) { + return; + } + this.expireDiff = msg.obj.expireDiff * 86400000; + this.trafficDiff = msg.obj.trafficDiff * 1073741824; + this.defaultCert = msg.obj.defaultCert; + this.defaultKey = msg.obj.defaultKey; + }, setInbounds(dbInbounds) { this.inbounds.splice(0); this.dbInbounds.splice(0); this.searchedInbounds.splice(0); for (const inbound of dbInbounds) { const dbInbound = new DBInbound(inbound); - this.inbounds.push(dbInbound.toInbound()); + to_inbound = dbInbound.toInbound() + this.inbounds.push(to_inbound); this.dbInbounds.push(dbInbound); this.searchedInbounds.push(dbInbound); + if([Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN].includes(inbound.protocol) ){ + this.clientCount[inbound.id] = this.getClientCounts(inbound,to_inbound); + } + } + }, + getClientCounts(dbInbound,inbound){ + let clientCount = 0,active = [], deactive = [], depleted = [], expiring = []; + clients = this.getClients(dbInbound.protocol, inbound.settings); + clientStats = dbInbound.clientStats + now = new Date().getTime() + if(clients){ + clientCount = clients.length; + if(dbInbound.enable){ + clients.forEach(client => { + client.enable ? active.push(client.email) : deactive.push(client.email); + }); + clientStats.forEach(client => { + if(!client.enable) { + depleted.push(client.email); + } else { + if ((client.expiryTime > 0 && (client.expiryTime-now < this.expireDiff)) || + (client.total > 0 && (client.total-client.up+client.down < this.trafficDiff ))) expiring.push(client.email); + } + }); + } else { + clients.forEach(client => { + deactive.push(client.email); + }); + } } + return { + clients: clientCount, + active: active, + deactive: deactive, + depleted: depleted, + expiring: expiring, + }; }, searchInbounds(key) { if (ObjectUtil.isEmpty(key)) { @@ -315,7 +412,10 @@ case "resetTraffic": this.resetTraffic(dbInbound.id); break; - case "clone": + case "resetClients": + this.resetAllClientTraffics(dbInbound.id); + break; + case "clone": this.openCloneInbound(dbInbound); break; case "delete": @@ -477,7 +577,7 @@ id: dbInbound.id, settings: inbound.settings.toString(), }; - await this.submit('/xui/inbound/addClient', data); + await this.submit('/xui/inbound/addClient/', data); }, async updateClient(inbound, dbInbound, index) { const data = { @@ -501,22 +601,6 @@ this.updateInbound(inbound, dbInbound); }, }); - }, - resetAllTraffic() { - this.$confirm({ - title: '{{ i18n "pages.inbounds.resetAllTrafficTitle"}}', - content: '{{ i18n "pages.inbounds.resetAllTrafficContent"}}', - okText: '{{ i18n "pages.inbounds.resetAllTrafficOkText"}}', - cancelText: '{{ i18n "pages.inbounds.resetAllTrafficCancelText"}}', - onOk: async () => { - for (const dbInbound of this.dbInbounds) { - const inbound = dbInbound.toInbound(); - dbInbound.up = 0; - dbInbound.down = 0; - this.updateInbound(inbound, dbInbound); - } - }, - }); }, delInbound(dbInboundId) { this.$confirm({ @@ -567,6 +651,16 @@ dbInbound = this.dbInbounds.find(row => row.id === dbInboundId); this.submit(`/xui/inbound/update/${dbInboundId}`, dbInbound); }, + async switchEnableClient(dbInboundId, client) { + this.loading() + dbInbound = this.dbInbounds.find(row => row.id === dbInboundId); + inbound = dbInbound.toInbound(); + clients = this.getClients(dbInbound.protocol, inbound.settings); + index = this.findIndexOfClient(clients, client); + clients[index].enable = ! clients[index].enable + await this.updateClient(inbound, dbInbound, index); + this.loading(false); + }, async submit(url, data) { const msg = await HttpUtil.postWithModal(url, data); if (msg.success) { @@ -592,6 +686,26 @@ onOk: () => this.submit('/xui/inbound/' + dbInboundId + '/resetClientTraffic/'+ client.email), }) }, + resetAllTraffic() { + this.$confirm({ + title: '{{ i18n "pages.inbounds.resetAllTrafficTitle"}}', + content: '{{ i18n "pages.inbounds.resetAllTrafficContent"}}', + class: siderDrawer.isDarkTheme ? darkClass : '', + okText: '{{ i18n "reset"}}', + cancelText: '{{ i18n "cancel"}}', + onOk: () => this.submit('/xui/inbound/resetAllTraffics'), + }); + }, + resetAllClientTraffics(dbInboundId) { + this.$confirm({ + title: '{{ i18n "pages.inbounds.resetAllClientTrafficTitle"}}', + content: '{{ i18n "pages.inbounds.resetAllClientTrafficContent"}}', + class: siderDrawer.isDarkTheme ? darkClass : '', + okText: '{{ i18n "reset"}}', + cancelText: '{{ i18n "cancel"}}', + onOk: () => this.submit('/xui/inbound/resetAllClientTraffics/' + dbInboundId), + }) + }, isExpiry(dbInbound, index) { return dbInbound.toInbound().isExpiry(index) }, @@ -635,37 +749,30 @@ }, 500) }, mounted() { + this.getDefaultSettings(); this.getDBInbounds(); }, computed: { total() { let down = 0, up = 0; - let clients = 0, active = 0, deactive = 0; + let clients = 0, deactive = [], depleted = [], expiring = []; this.dbInbounds.forEach(dbInbound => { down += dbInbound.down; up += dbInbound.up; - inbound = dbInbound.toInbound(); - clients = this.getClients(dbInbound.protocol, inbound.settings); - if(clients){ - if(dbInbound.enable){ - isClientEnable = false; - clients.forEach(client => { - isClientEnable = client.email == "" ? true: this.isClientEnabled(dbInbound,client.email); - isClientEnable ? active++ : deactive++; - }); - } else { - deactive += clients.length; - } - } else { - dbInbound.enable ? active++ : deactive++; + if (this.clientCount[dbInbound.id]) { + clients += this.clientCount[dbInbound.id].clients; + deactive = deactive.concat(this.clientCount[dbInbound.id].deactive); + depleted = depleted.concat(this.clientCount[dbInbound.id].depleted); + expiring = expiring.concat(this.clientCount[dbInbound.id].expiring); } }); return { down: down, up: up, - clients: active + deactive, - active: active, + clients: clients, deactive: deactive, + depleted: depleted, + expiring: expiring, }; } }, -- cgit v1.2.3