| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  | {{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" | 
					
						
							| 
									
										
										
										
											2023-05-08 14:44:22 +00:00
										 |  |  |          :class="themeSwitcher.darkCardClass" | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |          :ok-text="clientModal.okText" cancel-text='{{ i18n "close" }}'> | 
					
						
							|  |  |  |     {{template "form/client"}} | 
					
						
							|  |  |  | </a-modal> | 
					
						
							|  |  |  | <script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const clientModal = { | 
					
						
							|  |  |  |         visible: false, | 
					
						
							|  |  |  |         confirmLoading: false, | 
					
						
							|  |  |  |         title: '', | 
					
						
							|  |  |  |         okText: '', | 
					
						
							| 
									
										
										
										
											2023-04-18 18:04:06 +00:00
										 |  |  |         isEdit: false, | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |         dbInbound: new DBInbound(), | 
					
						
							|  |  |  |         inbound: new Inbound(), | 
					
						
							|  |  |  |         clients: [], | 
					
						
							|  |  |  |         clientStats: [], | 
					
						
							| 
									
										
										
										
											2023-04-25 11:08:35 +00:00
										 |  |  |         oldClientId: "", | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |         index: null, | 
					
						
							|  |  |  |         clientIps: null, | 
					
						
							| 
									
										
										
										
											2023-04-09 19:43:18 +00:00
										 |  |  |         delayedStart: false, | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |         ok() { | 
					
						
							| 
									
										
										
										
											2023-05-08 14:44:22 +00:00
										 |  |  |             if (clientModal.isEdit) { | 
					
						
							| 
									
										
										
										
											2023-04-25 11:08:35 +00:00
										 |  |  |                 ObjectUtil.execute(clientModal.confirm, clientModalApp.client, clientModal.dbInbound.id, clientModal.oldClientId); | 
					
						
							| 
									
										
										
										
											2023-04-18 18:04:06 +00:00
										 |  |  |             } else { | 
					
						
							|  |  |  |                 ObjectUtil.execute(clientModal.confirm, clientModalApp.client, clientModal.dbInbound.id); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2023-05-08 14:44:22 +00:00
										 |  |  |         show({ title = '', okText = '{{ i18n "sure" }}', index = null, dbInbound = null, confirm = () => { }, isEdit = false }) { | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |             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; | 
					
						
							| 
									
										
										
										
											2023-04-09 19:43:18 +00:00
										 |  |  |             this.delayedStart = false; | 
					
						
							| 
									
										
										
										
											2023-05-08 14:44:22 +00:00
										 |  |  |             if (isEdit) { | 
					
						
							|  |  |  |                 if (this.clients[index].expiryTime < 0) { | 
					
						
							| 
									
										
										
										
											2023-04-09 19:43:18 +00:00
										 |  |  |                     this.delayedStart = true; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2023-05-08 14:44:22 +00:00
										 |  |  |                 this.oldClientId = this.getClientId(dbInbound.protocol, clients[index]); | 
					
						
							| 
									
										
										
										
											2023-04-25 11:08:35 +00:00
										 |  |  |             } else { | 
					
						
							|  |  |  |                 this.addClient(this.inbound.protocol, this.clients); | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |             this.clientStats = this.dbInbound.clientStats.find(row => row.email === this.clients[this.index].email); | 
					
						
							|  |  |  |             this.confirm = confirm; | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         getClients(protocol, clientSettings) { | 
					
						
							| 
									
										
										
										
											2023-05-08 14:44:22 +00:00
										 |  |  |             switch (protocol) { | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |                 case Protocols.VMESS: return clientSettings.vmesses; | 
					
						
							|  |  |  |                 case Protocols.VLESS: return clientSettings.vlesses; | 
					
						
							|  |  |  |                 case Protocols.TROJAN: return clientSettings.trojans; | 
					
						
							| 
									
										
										
										
											2023-05-06 16:51:14 +00:00
										 |  |  |                 case Protocols.SHADOWSOCKS: return clientSettings.shadowsockses; | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |                 default: return null; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2023-05-06 16:51:14 +00:00
										 |  |  |         getClientId(protocol, client) { | 
					
						
							| 
									
										
										
										
											2023-05-08 14:44:22 +00:00
										 |  |  |             switch (protocol) { | 
					
						
							| 
									
										
										
										
											2023-05-06 16:51:14 +00:00
										 |  |  |                 case Protocols.TROJAN: return client.password; | 
					
						
							|  |  |  |                 case Protocols.SHADOWSOCKS: return client.email; | 
					
						
							|  |  |  |                 default: return client.id; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |         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()); | 
					
						
							| 
									
										
										
										
											2023-07-27 08:28:12 +00:00
										 |  |  |                 case Protocols.SHADOWSOCKS: return clients.push(new Inbound.ShadowsocksSettings.Shadowsocks(clients[0].method)); | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |                 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() { | 
					
						
							| 
									
										
										
										
											2023-05-08 14:44:22 +00:00
										 |  |  |                 if (!clientStats) return false | 
					
						
							|  |  |  |                 if (clientStats.total <= 0) return false | 
					
						
							|  |  |  |                 if (clientStats.up + clientStats.down < clientStats.total) return false | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |                 return true | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             get isExpiry() { | 
					
						
							| 
									
										
										
										
											2023-05-16 22:31:56 +00:00
										 |  |  |                 return this.clientModal.isEdit && this.client.expiryTime >0 ? (this.client.expiryTime < new Date().getTime()) : false; | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |             }, | 
					
						
							|  |  |  |             get statsColor() { | 
					
						
							| 
									
										
										
										
											2023-05-16 22:31:56 +00:00
										 |  |  |                 return usageColor(clientStats.up + clientStats.down, app.trafficDiff, this.client.totalGB); | 
					
						
							| 
									
										
										
										
											2023-04-09 19:43:18 +00:00
										 |  |  |             }, | 
					
						
							|  |  |  |             get delayedExpireDays() { | 
					
						
							|  |  |  |                 return this.client && this.client.expiryTime < 0 ? this.client.expiryTime / -86400000 : 0; | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2023-05-08 14:44:22 +00:00
										 |  |  |             set delayedExpireDays(days) { | 
					
						
							| 
									
										
										
										
											2023-04-09 19:43:18 +00:00
										 |  |  |                 this.client.expiryTime = -86400000 * days; | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |         }, | 
					
						
							|  |  |  |         methods: { | 
					
						
							| 
									
										
										
										
											2023-06-03 15:29:32 +00:00
										 |  |  |             async getDBClientIps(email) { | 
					
						
							| 
									
										
										
										
											2023-06-15 21:38:35 +00:00
										 |  |  |                 const msg = await HttpUtil.post(`/panel/inbound/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); | 
					
						
							| 
									
										
										
										
											2023-06-03 15:29:32 +00:00
										 |  |  |                     } | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2023-06-15 21:38:35 +00:00
										 |  |  |                 document.getElementById("clientIPs").value = ips; | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2023-03-17 18:04:07 +00:00
										 |  |  |             async clearDBClientIps(email) { | 
					
						
							| 
									
										
										
										
											2023-06-03 15:29:32 +00:00
										 |  |  |                 try { | 
					
						
							|  |  |  |                     const msg = await HttpUtil.post(`/panel/inbound/clearClientIps/${email}`); | 
					
						
							|  |  |  |                     if (!msg.success) { | 
					
						
							|  |  |  |                         return; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     document.getElementById("clientIPs").value = ""; | 
					
						
							|  |  |  |                 } catch (error) { | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2023-05-08 14:44:22 +00:00
										 |  |  |             resetClientTraffic(email, dbInboundId, iconElement) { | 
					
						
							| 
									
										
										
										
											2023-04-20 12:25:51 +00:00
										 |  |  |                 this.$confirm({ | 
					
						
							|  |  |  |                     title: '{{ i18n "pages.inbounds.resetTraffic"}}', | 
					
						
							|  |  |  |                     content: '{{ i18n "pages.inbounds.resetTrafficContent"}}', | 
					
						
							| 
									
										
										
										
											2023-05-08 14:44:22 +00:00
										 |  |  |                     class: themeSwitcher.darkCardClass, | 
					
						
							| 
									
										
										
										
											2023-04-20 12:25:51 +00:00
										 |  |  |                     okText: '{{ i18n "reset"}}', | 
					
						
							|  |  |  |                     cancelText: '{{ i18n "cancel"}}', | 
					
						
							|  |  |  |                     onOk: async () => { | 
					
						
							|  |  |  |                         iconElement.disabled = true; | 
					
						
							| 
									
										
										
										
											2023-05-12 18:06:05 +00:00
										 |  |  |                         const msg = await HttpUtil.postWithModal('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + email); | 
					
						
							| 
									
										
										
										
											2023-04-20 12:25:51 +00:00
										 |  |  |                         if (msg.success) { | 
					
						
							|  |  |  |                             this.clientModal.clientStats.up = 0; | 
					
						
							|  |  |  |                             this.clientModal.clientStats.down = 0; | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                         iconElement.disabled = false; | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                 }) | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |         }, | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2023-05-08 14:44:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  | </script> | 
					
						
							|  |  |  | {{end}} |