dbinbound.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 address() {
  49. let address = location.hostname;
  50. if (!ObjectUtil.isEmpty(this.listen) && this.listen !== "0.0.0.0") {
  51. address = this.listen;
  52. }
  53. return address;
  54. }
  55. get _expiryTime() {
  56. if (this.expiryTime === 0) {
  57. return null;
  58. }
  59. return moment(this.expiryTime);
  60. }
  61. set _expiryTime(t) {
  62. if (t == null) {
  63. this.expiryTime = 0;
  64. } else {
  65. this.expiryTime = t.valueOf();
  66. }
  67. }
  68. get isExpiry() {
  69. return this.expiryTime < new Date().getTime();
  70. }
  71. toInbound() {
  72. let settings = {};
  73. if (!ObjectUtil.isEmpty(this.settings)) {
  74. settings = JSON.parse(this.settings);
  75. }
  76. let streamSettings = {};
  77. if (!ObjectUtil.isEmpty(this.streamSettings)) {
  78. streamSettings = JSON.parse(this.streamSettings);
  79. }
  80. let sniffing = {};
  81. if (!ObjectUtil.isEmpty(this.sniffing)) {
  82. sniffing = JSON.parse(this.sniffing);
  83. }
  84. const config = {
  85. port: this.port,
  86. listen: this.listen,
  87. protocol: this.protocol,
  88. settings: settings,
  89. streamSettings: streamSettings,
  90. tag: this.tag,
  91. sniffing: sniffing,
  92. clientStats: this.clientStats,
  93. };
  94. return Inbound.fromJson(config);
  95. }
  96. isMultiUser() {
  97. switch (this.protocol) {
  98. case Protocols.VMESS:
  99. case Protocols.VLESS:
  100. case Protocols.TROJAN:
  101. return true;
  102. case Protocols.SHADOWSOCKS:
  103. return this.toInbound().isSSMultiUser;
  104. default:
  105. return false;
  106. }
  107. }
  108. hasLink() {
  109. switch (this.protocol) {
  110. case Protocols.VMESS:
  111. case Protocols.VLESS:
  112. case Protocols.TROJAN:
  113. case Protocols.SHADOWSOCKS:
  114. return true;
  115. default:
  116. return false;
  117. }
  118. }
  119. get genInboundLinks() {
  120. const inbound = this.toInbound();
  121. return inbound.genInboundLinks(this.remark);
  122. }
  123. }