dbinbound.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. class DBInbound {
  2. constructor(data) {
  3. this.id = 0;
  4. this.userId = 0;
  5. this.up = 0;
  6. this.down = 0;
  7. this.total = 0;
  8. this.allTime = 0;
  9. this.remark = "";
  10. this.enable = true;
  11. this.expiryTime = 0;
  12. this.listen = "";
  13. this.port = 0;
  14. this.protocol = "";
  15. this.settings = "";
  16. this.streamSettings = "";
  17. this.tag = "";
  18. this.sniffing = "";
  19. this.clientStats = ""
  20. if (data == null) {
  21. return;
  22. }
  23. ObjectUtil.cloneProps(this, data);
  24. }
  25. get totalGB() {
  26. return NumberFormatter.toFixed(this.total / SizeFormatter.ONE_GB, 2);
  27. }
  28. set totalGB(gb) {
  29. this.total = NumberFormatter.toFixed(gb * SizeFormatter.ONE_GB, 0);
  30. }
  31. get isVMess() {
  32. return this.protocol === Protocols.VMESS;
  33. }
  34. get isVLess() {
  35. return this.protocol === Protocols.VLESS;
  36. }
  37. get isTrojan() {
  38. return this.protocol === Protocols.TROJAN;
  39. }
  40. get isSS() {
  41. return this.protocol === Protocols.SHADOWSOCKS;
  42. }
  43. get isSocks() {
  44. return this.protocol === Protocols.SOCKS;
  45. }
  46. get isHTTP() {
  47. return this.protocol === Protocols.HTTP;
  48. }
  49. get isWireguard() {
  50. return this.protocol === Protocols.WIREGUARD;
  51. }
  52. get address() {
  53. let address = location.hostname;
  54. if (!ObjectUtil.isEmpty(this.listen) && this.listen !== "0.0.0.0") {
  55. address = this.listen;
  56. }
  57. return address;
  58. }
  59. get _expiryTime() {
  60. if (this.expiryTime === 0) {
  61. return null;
  62. }
  63. return moment(this.expiryTime);
  64. }
  65. set _expiryTime(t) {
  66. if (t == null) {
  67. this.expiryTime = 0;
  68. } else {
  69. this.expiryTime = t.valueOf();
  70. }
  71. }
  72. get isExpiry() {
  73. return this.expiryTime < new Date().getTime();
  74. }
  75. toInbound() {
  76. let settings = {};
  77. if (!ObjectUtil.isEmpty(this.settings)) {
  78. settings = JSON.parse(this.settings);
  79. }
  80. let streamSettings = {};
  81. if (!ObjectUtil.isEmpty(this.streamSettings)) {
  82. streamSettings = JSON.parse(this.streamSettings);
  83. }
  84. let sniffing = {};
  85. if (!ObjectUtil.isEmpty(this.sniffing)) {
  86. sniffing = JSON.parse(this.sniffing);
  87. }
  88. const config = {
  89. port: this.port,
  90. listen: this.listen,
  91. protocol: this.protocol,
  92. settings: settings,
  93. streamSettings: streamSettings,
  94. tag: this.tag,
  95. sniffing: sniffing,
  96. clientStats: this.clientStats,
  97. };
  98. return Inbound.fromJson(config);
  99. }
  100. isMultiUser() {
  101. switch (this.protocol) {
  102. case Protocols.VMESS:
  103. case Protocols.VLESS:
  104. case Protocols.TROJAN:
  105. return true;
  106. case Protocols.SHADOWSOCKS:
  107. return this.toInbound().isSSMultiUser;
  108. default:
  109. return false;
  110. }
  111. }
  112. hasLink() {
  113. switch (this.protocol) {
  114. case Protocols.VMESS:
  115. case Protocols.VLESS:
  116. case Protocols.TROJAN:
  117. case Protocols.SHADOWSOCKS:
  118. return true;
  119. default:
  120. return false;
  121. }
  122. }
  123. genInboundLinks(remarkModel) {
  124. const inbound = this.toInbound();
  125. return inbound.genInboundLinks(this.remark, remarkModel);
  126. }
  127. }