models.js 3.8 KB

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