models.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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.listen = "";
  34. this.port = 0;
  35. this.protocol = "";
  36. this.settings = "";
  37. this.streamSettings = "";
  38. this.tag = "";
  39. this.sniffing = "";
  40. this.clientStats = ""
  41. if (data == null) {
  42. return;
  43. }
  44. ObjectUtil.cloneProps(this, data);
  45. }
  46. get totalGB() {
  47. return toFixed(this.total / ONE_GB, 2);
  48. }
  49. set totalGB(gb) {
  50. this.total = toFixed(gb * ONE_GB, 0);
  51. }
  52. get isVMess() {
  53. return this.protocol === Protocols.VMESS;
  54. }
  55. get isVLess() {
  56. return this.protocol === Protocols.VLESS;
  57. }
  58. get isTrojan() {
  59. return this.protocol === Protocols.TROJAN;
  60. }
  61. get isSS() {
  62. return this.protocol === Protocols.SHADOWSOCKS;
  63. }
  64. get isSocks() {
  65. return this.protocol === Protocols.SOCKS;
  66. }
  67. get isHTTP() {
  68. return this.protocol === Protocols.HTTP;
  69. }
  70. get address() {
  71. let address = location.hostname;
  72. if (!ObjectUtil.isEmpty(this.listen) && this.listen !== "0.0.0.0") {
  73. address = this.listen;
  74. }
  75. return address;
  76. }
  77. get _expiryTime() {
  78. if (this.expiryTime === 0) {
  79. return null;
  80. }
  81. return moment(this.expiryTime);
  82. }
  83. set _expiryTime(t) {
  84. if (t == null) {
  85. this.expiryTime = 0;
  86. } else {
  87. this.expiryTime = t.valueOf();
  88. }
  89. }
  90. get isExpiry() {
  91. return this.expiryTime < new Date().getTime();
  92. }
  93. toInbound() {
  94. let settings = {};
  95. if (!ObjectUtil.isEmpty(this.settings)) {
  96. settings = JSON.parse(this.settings);
  97. }
  98. let streamSettings = {};
  99. if (!ObjectUtil.isEmpty(this.streamSettings)) {
  100. streamSettings = JSON.parse(this.streamSettings);
  101. }
  102. let sniffing = {};
  103. if (!ObjectUtil.isEmpty(this.sniffing)) {
  104. sniffing = JSON.parse(this.sniffing);
  105. }
  106. const config = {
  107. port: this.port,
  108. listen: this.listen,
  109. protocol: this.protocol,
  110. settings: settings,
  111. streamSettings: streamSettings,
  112. tag: this.tag,
  113. sniffing: sniffing,
  114. clientStats: this.clientStats,
  115. };
  116. return Inbound.fromJson(config);
  117. }
  118. hasLink() {
  119. switch (this.protocol) {
  120. case Protocols.VMESS:
  121. case Protocols.VLESS:
  122. case Protocols.TROJAN:
  123. case Protocols.SHADOWSOCKS:
  124. return true;
  125. default:
  126. return false;
  127. }
  128. }
  129. genLink(clientIndex) {
  130. const inbound = this.toInbound();
  131. return inbound.genLink(this.address, this.remark, clientIndex);
  132. }
  133. }
  134. class AllSetting {
  135. constructor(data) {
  136. this.webListen = "";
  137. this.webPort = 2053;
  138. this.webCertFile = "";
  139. this.webKeyFile = "";
  140. this.webBasePath = "/";
  141. this.tgBotEnable = false;
  142. this.tgBotToken = "";
  143. this.tgBotChatId = 0;
  144. this.tgRunTime = "";
  145. this.xrayTemplateConfig = "";
  146. this.timeLocation = "Asia/Tehran";
  147. if (data == null) {
  148. return
  149. }
  150. ObjectUtil.cloneProps(this, data);
  151. }
  152. equals(other) {
  153. return ObjectUtil.equals(this, other);
  154. }
  155. }