diff options
| author | MHSanaei <mc.sanaei@gmail.com> | 2023-02-09 22:18:06 +0300 |
|---|---|---|
| committer | MHSanaei <mc.sanaei@gmail.com> | 2023-02-09 22:18:06 +0300 |
| commit | b73e4173a3c1e69e02ad6b4e3b43e425e57a5be9 (patch) | |
| tree | d95d2f5e903d97082e11eb9f9023c165b1bde388 /web/assets/js/model/models.js | |
3x-ui
Diffstat (limited to 'web/assets/js/model/models.js')
| -rw-r--r-- | web/assets/js/model/models.js | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/web/assets/js/model/models.js b/web/assets/js/model/models.js new file mode 100644 index 00000000..768bf4de --- /dev/null +++ b/web/assets/js/model/models.js @@ -0,0 +1,185 @@ +class User { + + constructor() { + this.username = ""; + this.password = ""; + } +} + +class Msg { + + constructor(success, msg, obj) { + this.success = false; + this.msg = ""; + this.obj = null; + + if (success != null) { + this.success = success; + } + if (msg != null) { + this.msg = msg; + } + if (obj != null) { + this.obj = obj; + } + } +} + +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; + + 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() { + return toFixed(this.total / ONE_GB, 2); + } + + set totalGB(gb) { + this.total = toFixed(gb * ONE_GB, 0); + } + + 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; + } + + 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); + } + + hasLink() { + switch (this.protocol) { + case Protocols.VMESS: + case Protocols.VLESS: + case Protocols.TROJAN: + case Protocols.SHADOWSOCKS: + return true; + default: + return false; + } + } + + genLink() { + const inbound = this.toInbound(); + return inbound.genLink(this.address, this.remark); + } +} + +class AllSetting { + + constructor(data) { + this.webListen = ""; + this.webPort = 54321; + this.webCertFile = ""; + this.webKeyFile = ""; + this.webBasePath = "/"; + this.tgBotEnable = false; + this.tgBotToken = ""; + this.tgBotChatId = 0; + this.tgRunTime = ""; + this.xrayTemplateConfig = ""; + + this.timeLocation = "Asia/Shanghai"; + + if (data == null) { + return + } + ObjectUtil.cloneProps(this, data); + } + + equals(other) { + return ObjectUtil.equals(this, other); + } +}
\ No newline at end of file |
