models.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. hasLink() {
  121. switch (this.protocol) {
  122. case Protocols.VMESS:
  123. case Protocols.VLESS:
  124. case Protocols.TROJAN:
  125. case Protocols.SHADOWSOCKS:
  126. return true;
  127. default:
  128. return false;
  129. }
  130. }
  131. genLink(address=this.address, remark=this.remark, clientIndex=0) {
  132. const inbound = this.toInbound();
  133. return inbound.genLink(address, remark, clientIndex);
  134. }
  135. get genInboundLinks() {
  136. const inbound = this.toInbound();
  137. return inbound.genInboundLinks(this.address, this.remark);
  138. }
  139. }
  140. class AllSetting {
  141. constructor(data) {
  142. this.webListen = "";
  143. this.webDomain = "";
  144. this.webPort = 2053;
  145. this.webCertFile = "";
  146. this.webKeyFile = "";
  147. this.webBasePath = "/";
  148. this.sessionMaxAge = "";
  149. this.expireDiff = "";
  150. this.trafficDiff = "";
  151. this.tgBotEnable = false;
  152. this.tgBotToken = "";
  153. this.tgBotChatId = "";
  154. this.tgRunTime = "@daily";
  155. this.tgBotBackup = false;
  156. this.tgCpu = "";
  157. this.tgLang = "en-US";
  158. this.xrayTemplateConfig = "";
  159. this.secretEnable = false;
  160. this.subEnable = false;
  161. this.subListen = "";
  162. this.subPort = "2096";
  163. this.subPath = "/sub/";
  164. this.subDomain = "";
  165. this.subCertFile = "";
  166. this.subKeyFile = "";
  167. this.subUpdates = 0;
  168. this.timeLocation = "Asia/Tehran";
  169. if (data == null) {
  170. return
  171. }
  172. ObjectUtil.cloneProps(this, data);
  173. }
  174. equals(other) {
  175. return ObjectUtil.equals(this, other);
  176. }
  177. }