| 
									
										
										
										
											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, | 
					
						
							|  |  |  |         isExpired: false, | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  |             this.isExpired = isEdit ? this.inbound.isExpiry(this.index) : false; | 
					
						
							| 
									
										
										
										
											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-05-06 16:51:14 +00:00
										 |  |  |                 case Protocols.SHADOWSOCKS: return clients.push(new Inbound.ShadowsocksSettings.Shadowsocks()); | 
					
						
							| 
									
										
										
										
											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() { | 
					
						
							|  |  |  |                 return this.clientModal.isExpired | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             get statsColor() { | 
					
						
							| 
									
										
										
										
											2023-05-08 14:44:22 +00:00
										 |  |  |                 if (!clientStats) return 'blue' | 
					
						
							|  |  |  |                 if (clientStats.total <= 0) return 'blue' | 
					
						
							|  |  |  |                 else if (clientStats.total > 0 && (clientStats.down + clientStats.up) < clientStats.total) return 'cyan' | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |                 else return 'red' | 
					
						
							| 
									
										
										
										
											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: { | 
					
						
							|  |  |  |             getNewEmail(client) { | 
					
						
							|  |  |  |                 var chars = 'abcdefghijklmnopqrstuvwxyz1234567890'; | 
					
						
							|  |  |  |                 var string = ''; | 
					
						
							|  |  |  |                 var len = 6 + Math.floor(Math.random() * 5); | 
					
						
							| 
									
										
										
										
											2023-05-08 14:44:22 +00:00
										 |  |  |                 for (var ii = 0; ii < len; ii++) { | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |                     string += chars[Math.floor(Math.random() * chars.length)]; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 client.email = string; | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2023-05-08 14:44:22 +00:00
										 |  |  |             async getDBClientIps(email, event) { | 
					
						
							|  |  |  |                 const msg = await HttpUtil.post('/xui/inbound/clientIps/' + email); | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |                 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 | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2023-03-17 18:04:07 +00:00
										 |  |  |             async clearDBClientIps(email) { | 
					
						
							| 
									
										
										
										
											2023-05-08 14:44:22 +00:00
										 |  |  |                 const msg = await HttpUtil.post('/xui/inbound/clearClientIps/' + email); | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  |                 if (!msg.success) { | 
					
						
							|  |  |  |                     return; | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2023-03-17 18:04:07 +00:00
										 |  |  |                 document.getElementById("clientIPs").value = "" | 
					
						
							| 
									
										
										
										
											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-08 14:44:22 +00:00
										 |  |  |                         const msg = await HttpUtil.postWithModal('/xui/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}} |