models.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. class User {
  2. constructor() {
  3. this.username = "";
  4. this.password = "";
  5. this.LoginSecret = "";
  6. }
  7. }
  8. class Msg {
  9. constructor(success, msg, obj) {
  10. this.success = false;
  11. this.msg = "";
  12. this.obj = null;
  13. if (success != null) {
  14. this.success = success;
  15. }
  16. if (msg != null) {
  17. this.msg = msg;
  18. }
  19. if (obj != null) {
  20. this.obj = obj;
  21. }
  22. }
  23. }
  24. class DBInbound {
  25. constructor(data) {
  26. this.id = 0;
  27. this.userId = 0;
  28. this.up = 0;
  29. this.down = 0;
  30. this.total = 0;
  31. this.remark = "";
  32. this.enable = true;
  33. this.expiryTime = 0;
  34. this.limitIp = 0;
  35. this.listen = "";
  36. this.port = 0;
  37. this.protocol = "";
  38. this.settings = "";
  39. this.streamSettings = "";
  40. this.tag = "";
  41. this.sniffing = "";
  42. this.clientStats = ""
  43. if (data == null) {
  44. return;
  45. }
  46. ObjectUtil.cloneProps(this, data);
  47. }
  48. get totalGB() {
  49. return toFixed(this.total / ONE_GB, 2);
  50. }
  51. set totalGB(gb) {
  52. this.total = toFixed(gb * ONE_GB, 0);
  53. }
  54. get isVMess() {
  55. return this.protocol === Protocols.VMESS;
  56. }
  57. get isVLess() {
  58. return this.protocol === Protocols.VLESS;
  59. }
  60. get isTrojan() {
  61. return this.protocol === Protocols.TROJAN;
  62. }
  63. get isSS() {
  64. return this.protocol === Protocols.SHADOWSOCKS;
  65. }
  66. get isSocks() {
  67. return this.protocol === Protocols.SOCKS;
  68. }
  69. get isHTTP() {
  70. return this.protocol === Protocols.HTTP;
  71. }
  72. get address() {
  73. let address = location.hostname;
  74. if (!ObjectUtil.isEmpty(this.listen) && this.listen !== "0.0.0.0") {
  75. address = this.listen;
  76. }
  77. return address;
  78. }
  79. get _expiryTime() {
  80. if (this.expiryTime === 0) {
  81. return null;
  82. }
  83. return moment(this.expiryTime);
  84. }
  85. set _expiryTime(t) {
  86. if (t == null) {
  87. this.expiryTime = 0;
  88. } else {
  89. this.expiryTime = t.valueOf();
  90. }
  91. }
  92. get isExpiry() {
  93. return this.expiryTime < new Date().getTime();
  94. }
  95. toInbound() {
  96. let settings = {};
  97. if (!ObjectUtil.isEmpty(this.settings)) {
  98. settings = JSON.parse(this.settings);
  99. }
  100. let streamSettings = {};
  101. if (!ObjectUtil.isEmpty(this.streamSettings)) {
  102. streamSettings = JSON.parse(this.streamSettings);
  103. }
  104. let sniffing = {};
  105. if (!ObjectUtil.isEmpty(this.sniffing)) {
  106. sniffing = JSON.parse(this.sniffing);
  107. }
  108. const config = {
  109. port: this.port,
  110. listen: this.listen,
  111. protocol: this.protocol,
  112. settings: settings,
  113. streamSettings: streamSettings,
  114. tag: this.tag,
  115. sniffing: sniffing,
  116. clientStats: this.clientStats,
  117. };
  118. return Inbound.fromJson(config);
  119. }
  120. isMultiUser() {
  121. switch (this.protocol) {
  122. case Protocols.VMESS:
  123. case Protocols.VLESS:
  124. case Protocols.TROJAN:
  125. return true;
  126. case Protocols.SHADOWSOCKS:
  127. return this.toInbound().isSSMultiUser;
  128. default:
  129. return false;
  130. }
  131. }
  132. hasLink() {
  133. switch (this.protocol) {
  134. case Protocols.VMESS:
  135. case Protocols.VLESS:
  136. case Protocols.TROJAN:
  137. case Protocols.SHADOWSOCKS:
  138. return true;
  139. default:
  140. return false;
  141. }
  142. }
  143. genLink(address=this.address, remark=this.remark, clientIndex=0) {
  144. const inbound = this.toInbound();
  145. return inbound.genLink(address, remark, clientIndex);
  146. }
  147. get genInboundLinks() {
  148. const inbound = this.toInbound();
  149. return inbound.genInboundLinks(this.address, this.remark);
  150. }
  151. }
  152. class AllSetting {
  153. constructor(data) {
  154. this.webListen = "";
  155. this.webDomain = "";
  156. this.webPort = 2053;
  157. this.webCertFile = "";
  158. this.webKeyFile = "";
  159. this.webBasePath = "/";
  160. this.sessionMaxAge = "";
  161. this.expireDiff = "";
  162. this.trafficDiff = "";
  163. this.tgBotEnable = false;
  164. this.tgBotToken = "";
  165. this.tgBotChatId = "";
  166. this.tgRunTime = "@daily";
  167. this.tgBotBackup = false;
  168. this.tgBotLoginNotify = true;
  169. this.tgCpu = "";
  170. this.tgLang = "en-US";
  171. this.xrayTemplateConfig = "";
  172. this.secretEnable = false;
  173. this.subEnable = false;
  174. this.subListen = "";
  175. this.subPort = "2096";
  176. this.subPath = "/sub/";
  177. this.subDomain = "";
  178. this.subCertFile = "";
  179. this.subKeyFile = "";
  180. this.subUpdates = 0;
  181. this.subEncrypt = true;
  182. this.subShowInfo = true;
  183. this.timeLocation = "Asia/Tehran";
  184. if (data == null) {
  185. return
  186. }
  187. ObjectUtil.cloneProps(this, data);
  188. }
  189. equals(other) {
  190. return ObjectUtil.equals(this, other);
  191. }
  192. }