Welcome to mirror list, hosted at ThFree Co, Russian Federation.

client_modal.html « modals « html « web - github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 65a481f6bbc923233c25cec75bf925b1e7b44529 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
{{define "modals/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.currentTheme" :ok-text="clientModal.okText" cancel-text='{{ i18n "close" }}'>
    <template v-if="isEdit">
        <a-tag v-if="isExpiry || isTrafficExhausted" color="red"
            :style="{ marginBottom: '10px', display: 'block', textAlign: 'center' }">Account
            is (Expired|Traffic Ended) And Disabled</a-tag>
    </template>
    {{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 = Inbound.fromJson(dbInbound.toInbound().toJson());
            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, this.clients);
            }
            this.clientStats = this.dbInbound.clientStats.find(row => row.email === this.clients[this.index].email);
            this.confirm = confirm;
        },
        getClientId(protocol, client) {
            switch (protocol) {
                case Protocols.TROJAN:
                    return client.password;
                case Protocols.SHADOWSOCKS:
                    return client.email;
                case Protocols.HYSTERIA:
                    return client.auth;
                default:
                    return client.id;
            }
        },
        addClient(inbound, clients) {
            switch (inbound.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(clients[0].method, RandomUtil
                        .randomShadowsocksPassword(inbound.settings.method)));
                case Protocols.HYSTERIA:
                    return clients.push(new Inbound.HysteriaSettings.Hysteria());
                default:
                    return null;
            }
        },
        close() {
            clientModal.visible = false;
            clientModal.loading(false);
        },
        loading(loading = true) {
            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 datepicker() {
                return app.datepicker;
            },
            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
                return true
            },
            get isExpiry() {
                return this.clientModal.isEdit && this.client.expiryTime > 0 ? (this.client.expiryTime <
                    new Date().getTime()) : false;
            },
            get delayedStart() {
                return this.clientModal.delayedStart;
            },
            set delayedStart(value) {
                this.clientModal.delayedStart = value;
            },
            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) {
                const msg = await HttpUtil.post(`/panel/api/inbounds/clientIps/${email}`);
                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;
            },
            async clearDBClientIps(email) {
                try {
                    const msg = await HttpUtil.post(`/panel/api/inbounds/clearClientIps/${email}`);
                    if (!msg.success) {
                        return;
                    }
                    document.getElementById("clientIPs").value = "";
                } catch (error) {}
            },
            resetClientTraffic(email, dbInboundId, iconElement) {
                this.$confirm({
                    title: '{{ i18n "pages.inbounds.resetTraffic"}}',
                    content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
                    class: themeSwitcher.currentTheme,
                    okText: '{{ i18n "reset"}}',
                    cancelText: '{{ i18n "cancel"}}',
                    onOk: async () => {
                        iconElement.disabled = true;
                        const msg = await HttpUtil.postWithModal('/panel/api/inbounds/' +
                            dbInboundId + '/resetClientTraffic/' + email);
                        if (msg.success) {
                            this.clientModal.clientStats.up = 0;
                            this.clientModal.clientStats.down = 0;
                        }
                        iconElement.disabled = false;
                    },
                })
            },
        },
    });
</script>
{{end}}