models.js 4.3 KB

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