| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  | class DBInbound { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     constructor(data) { | 
					
						
							|  |  |  |         this.id = 0; | 
					
						
							|  |  |  |         this.userId = 0; | 
					
						
							|  |  |  |         this.up = 0; | 
					
						
							|  |  |  |         this.down = 0; | 
					
						
							|  |  |  |         this.total = 0; | 
					
						
							|  |  |  |         this.remark = ""; | 
					
						
							|  |  |  |         this.enable = true; | 
					
						
							|  |  |  |         this.expiryTime = 0; | 
					
						
							| 
									
										
										
										
											2023-03-17 16:07:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |         this.listen = ""; | 
					
						
							|  |  |  |         this.port = 0; | 
					
						
							|  |  |  |         this.protocol = ""; | 
					
						
							|  |  |  |         this.settings = ""; | 
					
						
							|  |  |  |         this.streamSettings = ""; | 
					
						
							|  |  |  |         this.tag = ""; | 
					
						
							|  |  |  |         this.sniffing = ""; | 
					
						
							|  |  |  |         this.clientStats = "" | 
					
						
							|  |  |  |         if (data == null) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         ObjectUtil.cloneProps(this, data); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     get totalGB() { | 
					
						
							| 
									
										
										
										
											2025-03-07 09:07:23 +00:00
										 |  |  |         return NumberFormatter.toFixed(this.total / SizeFormatter.ONE_GB, 2); | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     set totalGB(gb) { | 
					
						
							| 
									
										
										
										
											2025-03-07 09:07:23 +00:00
										 |  |  |         this.total = NumberFormatter.toFixed(gb * SizeFormatter.ONE_GB, 0); | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     get isVMess() { | 
					
						
							|  |  |  |         return this.protocol === Protocols.VMESS; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     get isVLess() { | 
					
						
							|  |  |  |         return this.protocol === Protocols.VLESS; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     get isTrojan() { | 
					
						
							|  |  |  |         return this.protocol === Protocols.TROJAN; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     get isSS() { | 
					
						
							|  |  |  |         return this.protocol === Protocols.SHADOWSOCKS; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     get isSocks() { | 
					
						
							|  |  |  |         return this.protocol === Protocols.SOCKS; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     get isHTTP() { | 
					
						
							|  |  |  |         return this.protocol === Protocols.HTTP; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-11 14:56:54 +00:00
										 |  |  |     get isWireguard() { | 
					
						
							|  |  |  |         return this.protocol === Protocols.WIREGUARD; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |     get address() { | 
					
						
							|  |  |  |         let address = location.hostname; | 
					
						
							|  |  |  |         if (!ObjectUtil.isEmpty(this.listen) && this.listen !== "0.0.0.0") { | 
					
						
							|  |  |  |             address = this.listen; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return address; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     get _expiryTime() { | 
					
						
							|  |  |  |         if (this.expiryTime === 0) { | 
					
						
							|  |  |  |             return null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return moment(this.expiryTime); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     set _expiryTime(t) { | 
					
						
							|  |  |  |         if (t == null) { | 
					
						
							|  |  |  |             this.expiryTime = 0; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             this.expiryTime = t.valueOf(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     get isExpiry() { | 
					
						
							|  |  |  |         return this.expiryTime < new Date().getTime(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     toInbound() { | 
					
						
							|  |  |  |         let settings = {}; | 
					
						
							|  |  |  |         if (!ObjectUtil.isEmpty(this.settings)) { | 
					
						
							|  |  |  |             settings = JSON.parse(this.settings); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         let streamSettings = {}; | 
					
						
							|  |  |  |         if (!ObjectUtil.isEmpty(this.streamSettings)) { | 
					
						
							|  |  |  |             streamSettings = JSON.parse(this.streamSettings); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         let sniffing = {}; | 
					
						
							|  |  |  |         if (!ObjectUtil.isEmpty(this.sniffing)) { | 
					
						
							|  |  |  |             sniffing = JSON.parse(this.sniffing); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const config = { | 
					
						
							|  |  |  |             port: this.port, | 
					
						
							|  |  |  |             listen: this.listen, | 
					
						
							|  |  |  |             protocol: this.protocol, | 
					
						
							|  |  |  |             settings: settings, | 
					
						
							|  |  |  |             streamSettings: streamSettings, | 
					
						
							|  |  |  |             tag: this.tag, | 
					
						
							|  |  |  |             sniffing: sniffing, | 
					
						
							|  |  |  |             clientStats: this.clientStats, | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         return Inbound.fromJson(config); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-04 18:17:38 +00:00
										 |  |  |     isMultiUser() { | 
					
						
							|  |  |  |         switch (this.protocol) { | 
					
						
							|  |  |  |             case Protocols.VMESS: | 
					
						
							|  |  |  |             case Protocols.VLESS: | 
					
						
							|  |  |  |             case Protocols.TROJAN: | 
					
						
							|  |  |  |                 return true; | 
					
						
							|  |  |  |             case Protocols.SHADOWSOCKS: | 
					
						
							|  |  |  |                 return this.toInbound().isSSMultiUser; | 
					
						
							|  |  |  |             default: | 
					
						
							|  |  |  |                 return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |     hasLink() { | 
					
						
							|  |  |  |         switch (this.protocol) { | 
					
						
							|  |  |  |             case Protocols.VMESS: | 
					
						
							|  |  |  |             case Protocols.VLESS: | 
					
						
							|  |  |  |             case Protocols.TROJAN: | 
					
						
							|  |  |  |             case Protocols.SHADOWSOCKS: | 
					
						
							|  |  |  |                 return true; | 
					
						
							|  |  |  |             default: | 
					
						
							|  |  |  |                 return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-10-17 08:36:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     genInboundLinks(remarkModel) { | 
					
						
							| 
									
										
										
										
											2023-02-28 19:54:29 +00:00
										 |  |  |         const inbound = this.toInbound(); | 
					
						
							| 
									
										
										
										
											2024-10-17 08:36:05 +00:00
										 |  |  |         return inbound.genInboundLinks(this.remark, remarkModel); | 
					
						
							| 
									
										
										
										
											2023-02-09 19:18:06 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } |