From 5c695ca6520c9cd9c44b18119a862f8f480969af Mon Sep 17 00:00:00 2001 From: Ali Rahimi Date: Sun, 21 Jan 2024 15:26:19 +0100 Subject: add group user with the same subscription id to all inbounds (#1650) --- web/html/xui/client_modal.html | 80 ++++++++++++++++++++++++++++++++++------- web/html/xui/form/client.html | 4 +-- web/html/xui/inbound_modal.html | 4 +++ web/html/xui/inbounds.html | 59 +++++++++++++++++++++++------- 4 files changed, 120 insertions(+), 27 deletions(-) (limited to 'web/html/xui') diff --git a/web/html/xui/client_modal.html b/web/html/xui/client_modal.html index 4b270607..02c548e3 100644 --- a/web/html/xui/client_modal.html +++ b/web/html/xui/client_modal.html @@ -15,7 +15,12 @@ confirmLoading: false, title: '', okText: '', - isEdit: false, + group: { + isGroup: false, + currentClient: null, + inbounds: [], + clients: [], + }, dbInbound: new DBInbound(), inbound: new Inbound(), clients: [], @@ -28,30 +33,76 @@ if (clientModal.isEdit) { ObjectUtil.execute(clientModal.confirm, clientModalApp.client, clientModal.dbInbound.id, clientModal.oldClientId); } else { - ObjectUtil.execute(clientModal.confirm, clientModalApp.client, clientModal.dbInbound.id); + if (clientModal.group.isGroup) { + const currentClient = clientModal.group.currentClient; + + clientModal.group.clients.forEach((client, index) => { + const { email, limitIp, totalGB, expiryTime, reset, enable, subId, tgId, flow } = currentClient; + + client.email = `${email}-${index + 1}`; + client.limitIp = limitIp; + client.totalGB = totalGB; + client.expiryTime = expiryTime; + client.reset = reset; + client.enable = enable; + + if (subId) { + client.subId = subId; + } + if (tgId) { + client.tgId = tgId; + } + if (flow) { + client.flow = flow; + } + }); + ObjectUtil.execute(clientModal.confirm, clientModal.group.clients, clientModal.group.inbounds); + } else { + ObjectUtil.execute(clientModal.confirm, clientModalApp.client, clientModal.dbInbound.id); + } } }, show({ title = '', okText = '{{ i18n "sure" }}', index = null, dbInbound = null, confirm = () => { }, isEdit = false }) { + this.group = { + isGroup: false, + currentClient: null, + inbounds: [], + clients: [], + } this.visible = true; this.title = title; this.okText = okText; this.isEdit = isEdit; + if (Array.isArray(dbInbound)) { + this.group.isGroup = true; + dbInbound.forEach((dbInboundItem) => { + this.showProcess(dbInboundItem); + this.group.inbounds.push(dbInboundItem.id) + this.group.clients.push(this.clients[this.index]) + }) + this.group.currentClient = this.clients[this.index] + } else { + this.showProcess(dbInbound, index); + if (isEdit) { + if (this.clients[index].expiryTime < 0) { + this.delayedStart = true; + } + this.oldClientId = this.getClientId(dbInbound.protocol, clients[index]); + } else { + this.addClient(this.inbound.protocol, this.clients); + } + } + this.clientStats = this.dbInbound.clientStats.find(row => row.email === this.clients[this.index].email); + this.confirm = confirm; + }, + showProcess(dbInbound, index = null) { this.dbInbound = new DBInbound(dbInbound); this.inbound = dbInbound.toInbound(); this.clients = this.inbound.clients; this.index = index === null ? this.clients.length : index; this.delayedStart = false; - if (isEdit) { - if (this.clients[index].expiryTime < 0) { - this.delayedStart = true; - } - this.oldClientId = this.getClientId(dbInbound.protocol, clients[index]); - } else { - this.addClient(this.inbound.protocol, this.clients); - } - this.clientStats = this.dbInbound.clientStats.find(row => row.email === this.clients[this.index].email); - this.confirm = confirm; - }, + this.addClient(this.inbound.protocol, this.clients); + }, getClientId(protocol, client) { switch (protocol) { case Protocols.TROJAN: return client.password; @@ -94,6 +145,9 @@ get isEdit() { return this.clientModal.isEdit; }, + get isGroup() { + return this.clientModal.group.isGroup; + }, get datepicker() { return app.datepicker; }, diff --git a/web/html/xui/form/client.html b/web/html/xui/form/client.html index 204aca72..f4ac25f3 100644 --- a/web/html/xui/form/client.html +++ b/web/html/xui/form/client.html @@ -15,7 +15,7 @@ - + + @@ -373,7 +377,7 @@

[[ clientEmail ]]

[[ clientCount[dbInbound.id].online.length ]] - + @@ -740,6 +744,9 @@ case "delDepletedClients": this.delDepletedClients(-1) break; + case "addGroupClient": + this.openGroupAddClient() + break; } }, clickAction(action, dbInbound) { @@ -883,6 +890,20 @@ await this.submit(`/panel/inbound/update/${dbInbound.id}`, data, inModal); }, + openGroupAddClient() { + clientModal.show({ + title: '{{ i18n "pages.client.groupAdd"}}', + okText: '{{ i18n "pages.client.submitAdd"}}', + dbInbound: this.dbInbounds, + confirm: async (clients, dbInboundIds) => { + clientModal.loading(); + await this.addGroupClient(clients, dbInboundIds); + clientModal.close(); + await this.showQrcode(dbInboundIds[0],clients[0], true) + }, + isEdit: false + }); + }, openAddClient(dbInboundId) { dbInbound = this.dbInbounds.find(row => row.id === dbInboundId); clientModal.show({ @@ -893,6 +914,7 @@ clientModal.loading(); await this.addClient(clients, dbInboundId); clientModal.close(); + await this.showQrcode(dbInboundId,clients) }, isEdit: false }); @@ -936,11 +958,24 @@ } }, async addClient(clients, dbInboundId) { - const data = { + const data = [{ id: dbInboundId, settings: '{"clients": [' + clients.toString() + ']}', - }; - await this.submit(`/panel/inbound/addClient`, data); + }]; + + await this.submit(`/panel/inbound/addClient`, data, true) + }, + + async addGroupClient(clients, dbInboundIds) { + const data = [] + dbInboundIds.forEach((dbInboundId, index) => { + data.push({ + id: dbInboundId, + settings: '{"clients": [' + clients[index].toString() + ']}', + }) + }) + + await this.submit(`/panel/inbound/addClient`, data, true) }, async updateClient(client, dbInboundId, clientId) { const data = { @@ -1001,8 +1036,8 @@ checkFallback(dbInbound) { newDbInbound = new DBInbound(dbInbound); if (dbInbound.listen.startsWith("@")){ - rootInbound = this.inbounds.find((i) => - i.isTcp && + rootInbound = this.inbounds.find((i) => + i.isTcp && ['trojan','vless'].includes(i.protocol) && i.settings.fallbacks.find(f => f.dest === dbInbound.listen) ); @@ -1018,10 +1053,10 @@ } return newDbInbound; }, - showQrcode(dbInboundId, client) { + showQrcode(dbInboundId, client, isJustSub = false) { dbInbound = this.dbInbounds.find(row => row.id === dbInboundId); newDbInbound = this.checkFallback(dbInbound); - qrModal.show('{{ i18n "qrCode"}}', newDbInbound, client); + qrModal.show('{{ i18n "qrCode"}}', newDbInbound, client, isJustSub); }, showInfo(dbInboundId, client) { dbInbound = this.dbInbounds.find(row => row.id === dbInboundId); @@ -1050,8 +1085,8 @@ await this.updateClient(clients[index], dbInboundId, clientId); this.loading(false); }, - async submit(url, data) { - const msg = await HttpUtil.postWithModal(url, data); + async submit(url, data, isJson = false) { + const msg = isJson ? await HttpUtil.postWithModalJson(url, data) : await HttpUtil.postWithModal(url, data); if (msg.success) { await this.getDBInbounds(); } -- cgit v1.2.3