Files
trihuy-russian/web/html/modals/client_modal.html
T

193 lines
7.6 KiB
HTML
Raw Normal View History

{{define "modals/clientsModal"}}
2026-05-04 13:20:24 +02:00
<a-modal id="client-modal" v-model="clientModal.visible" :title="clientModal.title" @ok="clientModal.ok"
:confirm-loading="clientModal.confirmLoading" :closable="true" :mask-closable="false"
:class="themeSwitcher.currentTheme" :ok-text="clientModal.okText" cancel-text='{{ i18n "close" }}'>
2023-12-04 19:17:38 +01:00
<template v-if="isEdit">
2026-04-20 16:05:27 +02:00
<a-tag v-if="isExpiry || isTrafficExhausted" color="red"
:style="{ marginBottom: '10px', display: 'block', textAlign: 'center' }">Account
is (Expired|Traffic Ended) And Disabled</a-tag>
2023-12-04 19:17:38 +01:00
</template>
{{template "form/client" .}}
2023-03-17 19:37:49 +03:30
</a-modal>
<script>
const clientModal = {
visible: false,
confirmLoading: false,
title: '',
okText: '',
2024-01-26 22:07:15 +03:30
isEdit: false,
2023-03-17 19:37:49 +03:30
dbInbound: new DBInbound(),
inbound: new Inbound(),
clients: [],
clientStats: [],
2023-04-25 14:38:35 +03:30
oldClientId: "",
2023-03-17 19:37:49 +03:30
index: null,
clientIps: null,
2023-04-09 23:13:18 +03:30
delayedStart: false,
2023-03-17 19:37:49 +03:30
ok() {
2025-02-04 11:27:58 +01:00
if (clientModal.isEdit) {
2026-05-04 13:20:24 +02:00
ObjectUtil.execute(clientModal.confirm, clientModalApp.client, clientModal.dbInbound.id, clientModal
.oldClientId);
} else {
2025-02-04 11:27:58 +01:00
ObjectUtil.execute(clientModal.confirm, clientModalApp.client, clientModal.dbInbound.id);
2023-04-18 21:34:06 +03:30
}
2023-03-17 19:37:49 +03:30
},
2026-05-04 13:20:24 +02:00
show({
title = '',
okText = '{{ i18n "sure" }}',
index = null,
dbInbound = null,
confirm = () => {},
isEdit = false
}) {
2023-03-17 19:37:49 +03:30
this.visible = true;
this.title = title;
this.okText = okText;
this.isEdit = isEdit;
2025-02-04 11:27:58 +01:00
this.dbInbound = new DBInbound(dbInbound);
this.inbound = Inbound.fromJson(dbInbound.toInbound().toJson());
2025-02-04 11:27:58 +01:00
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;
}
2025-02-04 11:27:58 +01:00
this.oldClientId = this.getClientId(dbInbound.protocol, clients[index]);
} else {
this.addClient(this.inbound, this.clients);
}
this.clientStats = this.dbInbound.clientStats.find(row => row.email === this.clients[this.index].email);
this.confirm = confirm;
2026-05-04 13:20:24 +02:00
},
2023-05-06 20:21:14 +03:30
getClientId(protocol, client) {
2023-05-08 19:14:22 +04:30
switch (protocol) {
2026-05-04 13:20:24 +02:00
case Protocols.TROJAN:
return client.password;
case Protocols.SHADOWSOCKS:
return client.email;
case Protocols.HYSTERIA:
return client.auth;
default:
return client.id;
2023-05-06 20:21:14 +03:30
}
},
addClient(inbound, clients) {
switch (inbound.protocol) {
2026-05-04 13:20:24 +02:00
case Protocols.VMESS:
return clients.push(new Inbound.VmessSettings.VMESS());
case Protocols.VLESS:
return clients.push(new Inbound.VLESSSettings.VLESS());
case Protocols.TROJAN:
return clients.push(new Inbound.TrojanSettings.Trojan());
case Protocols.SHADOWSOCKS:
return clients.push(new Inbound.ShadowsocksSettings.Shadowsocks(clients[0].method, RandomUtil
.randomShadowsocksPassword(inbound.settings.method)));
case Protocols.HYSTERIA:
return clients.push(new Inbound.HysteriaSettings.Hysteria());
default:
return null;
2023-03-17 19:37:49 +03:30
}
},
close() {
clientModal.visible = false;
clientModal.loading(false);
},
2026-05-04 13:20:24 +02:00
loading(loading = true) {
2023-03-17 19:37:49 +03:30
clientModal.confirmLoading = loading;
},
};
const clientModalApp = new Vue({
delimiters: ['[[', ']]'],
el: '#client-modal',
data: {
clientModal,
get inbound() {
return this.clientModal.inbound;
},
get client() {
return this.clientModal.clients[this.clientModal.index];
},
get clientStats() {
return this.clientModal.clientStats;
},
get isEdit() {
return this.clientModal.isEdit;
},
2024-01-02 09:32:21 +01:00
get datepicker() {
return app.datepicker;
},
2023-03-17 19:37:49 +03:30
get isTrafficExhausted() {
if (!this.clientStats) return false
if (this.clientStats.total <= 0) return false
if (this.clientStats.up + this.clientStats.down < this.clientStats.total) return false
2023-03-17 19:37:49 +03:30
return true
},
get isExpiry() {
2026-05-04 13:20:24 +02:00
return this.clientModal.isEdit && this.client.expiryTime > 0 ? (this.client.expiryTime <
new Date().getTime()) : false;
2023-03-17 19:37:49 +03:30
},
2023-12-04 19:20:16 +01:00
get delayedStart() {
return this.clientModal.delayedStart;
},
set delayedStart(value) {
this.clientModal.delayedStart = value;
},
2023-04-09 23:13:18 +03:30
get delayedExpireDays() {
return this.client && this.client.expiryTime < 0 ? this.client.expiryTime / -86400000 : 0;
},
2023-05-08 19:14:22 +04:30
set delayedExpireDays(days) {
2023-04-09 23:13:18 +03:30
this.client.expiryTime = -86400000 * days;
},
2023-03-17 19:37:49 +03:30
},
methods: {
2025-01-24 17:16:16 +01:00
async getDBClientIps(email) {
2025-09-09 01:22:43 +02:00
const msg = await HttpUtil.post(`/panel/api/inbounds/clientIps/${email}`);
2025-01-24 17:16:16 +01:00
if (!msg.success) {
document.getElementById("clientIPs").value = msg.obj;
return;
}
let ips = msg.obj;
if (typeof ips === 'string' && ips.startsWith('[') && ips.endsWith(']')) {
try {
ips = JSON.parse(ips);
ips = Array.isArray(ips) ? ips.join("\n") : ips;
} catch (e) {
console.error('Error parsing JSON:', e);
}
}
document.getElementById("clientIPs").value = ips;
},
2023-03-17 19:04:07 +01:00
async clearDBClientIps(email) {
2023-06-03 18:59:32 +03:30
try {
2025-09-09 01:22:43 +02:00
const msg = await HttpUtil.post(`/panel/api/inbounds/clearClientIps/${email}`);
2023-06-03 18:59:32 +03:30
if (!msg.success) {
return;
}
document.getElementById("clientIPs").value = "";
2026-05-04 13:20:24 +02:00
} catch (error) {}
2023-03-17 19:37:49 +03:30
},
2025-02-04 11:27:58 +01:00
resetClientTraffic(email, dbInboundId, iconElement) {
2023-04-20 15:55:51 +03:30
this.$confirm({
title: '{{ i18n "pages.inbounds.resetTraffic"}}',
content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
2023-12-04 19:17:38 +01:00
class: themeSwitcher.currentTheme,
2023-04-20 15:55:51 +03:30
okText: '{{ i18n "reset"}}',
cancelText: '{{ i18n "cancel"}}',
onOk: async () => {
iconElement.disabled = true;
2026-05-04 13:20:24 +02:00
const msg = await HttpUtil.postWithModal('/panel/api/inbounds/' +
dbInboundId + '/resetClientTraffic/' + email);
2025-02-04 11:27:58 +01:00
if (msg.success) {
2023-04-20 15:55:51 +03:30
this.clientModal.clientStats.up = 0;
this.clientModal.clientStats.down = 0;
}
iconElement.disabled = false;
},
})
},
2023-03-17 19:37:49 +03:30
},
});
</script>
2026-05-04 13:20:24 +02:00
{{end}}