1
0

dbinbound.js 3.4 KB

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