mirror of
				https://github.com/MHSanaei/3x-ui.git
				synced 2025-11-04 06:12:52 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			166 lines
		
	
	
	
		
			6.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			166 lines
		
	
	
	
		
			6.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
{{define "clientsModal"}}
 | 
						|
<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.darkCardClass"
 | 
						|
         :ok-text="clientModal.okText" cancel-text='{{ i18n "close" }}'>
 | 
						|
    {{template "form/client"}}
 | 
						|
</a-modal>
 | 
						|
<script>
 | 
						|
 | 
						|
    const clientModal = {
 | 
						|
        visible: false,
 | 
						|
        confirmLoading: false,
 | 
						|
        title: '',
 | 
						|
        okText: '',
 | 
						|
        isEdit: false,
 | 
						|
        dbInbound: new DBInbound(),
 | 
						|
        inbound: new Inbound(),
 | 
						|
        clients: [],
 | 
						|
        clientStats: [],
 | 
						|
        oldClientId: "",
 | 
						|
        index: null,
 | 
						|
        clientIps: null,
 | 
						|
        delayedStart: false,
 | 
						|
        ok() {
 | 
						|
            if (clientModal.isEdit) {
 | 
						|
                ObjectUtil.execute(clientModal.confirm, clientModalApp.client, clientModal.dbInbound.id, clientModal.oldClientId);
 | 
						|
            } else {
 | 
						|
                ObjectUtil.execute(clientModal.confirm, clientModalApp.client, clientModal.dbInbound.id);
 | 
						|
            }
 | 
						|
        },
 | 
						|
        show({ title = '', okText = '{{ i18n "sure" }}', index = null, dbInbound = null, confirm = () => { }, isEdit = false }) {
 | 
						|
            this.visible = true;
 | 
						|
            this.title = title;
 | 
						|
            this.okText = okText;
 | 
						|
            this.isEdit = isEdit;
 | 
						|
            this.dbInbound = new DBInbound(dbInbound);
 | 
						|
            this.inbound = dbInbound.toInbound();
 | 
						|
            this.clients = this.getClients(this.inbound.protocol, this.inbound.settings);
 | 
						|
            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;
 | 
						|
        },
 | 
						|
        getClients(protocol, clientSettings) {
 | 
						|
            switch (protocol) {
 | 
						|
                case Protocols.VMESS: return clientSettings.vmesses;
 | 
						|
                case Protocols.VLESS: return clientSettings.vlesses;
 | 
						|
                case Protocols.TROJAN: return clientSettings.trojans;
 | 
						|
                case Protocols.SHADOWSOCKS: return clientSettings.shadowsockses;
 | 
						|
                default: return null;
 | 
						|
            }
 | 
						|
        },
 | 
						|
        getClientId(protocol, client) {
 | 
						|
            switch (protocol) {
 | 
						|
                case Protocols.TROJAN: return client.password;
 | 
						|
                case Protocols.SHADOWSOCKS: return client.email;
 | 
						|
                default: return client.id;
 | 
						|
            }
 | 
						|
        },
 | 
						|
        addClient(protocol, clients) {
 | 
						|
            switch (protocol) {
 | 
						|
                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());
 | 
						|
                default: return null;
 | 
						|
            }
 | 
						|
        },
 | 
						|
        close() {
 | 
						|
            clientModal.visible = false;
 | 
						|
            clientModal.loading(false);
 | 
						|
        },
 | 
						|
        loading(loading) {
 | 
						|
            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;
 | 
						|
            },
 | 
						|
            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.isEdit && this.client.expiryTime >0 ? (this.client.expiryTime < new Date().getTime()) : false;
 | 
						|
            },
 | 
						|
            get statsColor() {
 | 
						|
                return usageColor(clientStats.up + clientStats.down, app.trafficDiff, this.client.totalGB);
 | 
						|
            },
 | 
						|
            get delayedExpireDays() {
 | 
						|
                return this.client && this.client.expiryTime < 0 ? this.client.expiryTime / -86400000 : 0;
 | 
						|
            },
 | 
						|
            set delayedExpireDays(days) {
 | 
						|
                this.client.expiryTime = -86400000 * days;
 | 
						|
            },
 | 
						|
        },
 | 
						|
        methods: {
 | 
						|
            async getDBClientIps(email, event) {
 | 
						|
                const msg = await HttpUtil.post('/panel/inbound/clientIps/' + email);
 | 
						|
                if (!msg.success) {
 | 
						|
                    return;
 | 
						|
                }
 | 
						|
                try {
 | 
						|
                    ips = JSON.parse(msg.obj)
 | 
						|
                    ips = ips.join(",")
 | 
						|
                    event.target.value = ips
 | 
						|
                } catch (error) {
 | 
						|
                    // text
 | 
						|
                    event.target.value = msg.obj
 | 
						|
                }
 | 
						|
            },
 | 
						|
            async clearDBClientIps(email) {
 | 
						|
                const msg = await HttpUtil.post('/panel/inbound/clearClientIps/' + email);
 | 
						|
                if (!msg.success) {
 | 
						|
                    return;
 | 
						|
                }
 | 
						|
                document.getElementById("clientIPs").value = ""
 | 
						|
            },
 | 
						|
            resetClientTraffic(email, dbInboundId, iconElement) {
 | 
						|
                this.$confirm({
 | 
						|
                    title: '{{ i18n "pages.inbounds.resetTraffic"}}',
 | 
						|
                    content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
 | 
						|
                    class: themeSwitcher.darkCardClass,
 | 
						|
                    okText: '{{ i18n "reset"}}',
 | 
						|
                    cancelText: '{{ i18n "cancel"}}',
 | 
						|
                    onOk: async () => {
 | 
						|
                        iconElement.disabled = true;
 | 
						|
                        const msg = await HttpUtil.postWithModal('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + email);
 | 
						|
                        if (msg.success) {
 | 
						|
                            this.clientModal.clientStats.up = 0;
 | 
						|
                            this.clientModal.clientStats.down = 0;
 | 
						|
                        }
 | 
						|
                        iconElement.disabled = false;
 | 
						|
                    },
 | 
						|
                })
 | 
						|
            },
 | 
						|
        },
 | 
						|
    });
 | 
						|
 | 
						|
</script>
 | 
						|
{{end}}
 |