client_modal.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. {{define "clientsModal"}}
  2. <a-modal id="client-modal" v-model="clientModal.visible" :title="clientModal.title" @ok="clientModal.ok"
  3. :confirm-loading="clientModal.confirmLoading" :closable="true" :mask-closable="false"
  4. :class="themeSwitcher.currentTheme"
  5. :ok-text="clientModal.okText" cancel-text='{{ i18n "close" }}'>
  6. <template v-if="isEdit">
  7. <a-tag v-if="isExpiry || isTrafficExhausted" color="red" style="margin-bottom: 10px;display: block;text-align: center;">Account is (Expired|Traffic Ended) And Disabled</a-tag>
  8. </template>
  9. {{template "form/client"}}
  10. </a-modal>
  11. <script>
  12. const clientModal = {
  13. visible: false,
  14. confirmLoading: false,
  15. title: '',
  16. okText: '',
  17. isEdit: false,
  18. dbInbound: new DBInbound(),
  19. inbound: new Inbound(),
  20. clients: [],
  21. clientStats: [],
  22. oldClientId: "",
  23. index: null,
  24. clientIps: null,
  25. delayedStart: false,
  26. ok() {
  27. if (clientModal.isEdit) {
  28. ObjectUtil.execute(clientModal.confirm, clientModalApp.client, clientModal.dbInbound.id, clientModal.oldClientId);
  29. } else {
  30. ObjectUtil.execute(clientModal.confirm, clientModalApp.client, clientModal.dbInbound.id);
  31. }
  32. },
  33. show({ title = '', okText = '{{ i18n "sure" }}', index = null, dbInbound = null, confirm = () => { }, isEdit = false }) {
  34. this.visible = true;
  35. this.title = title;
  36. this.okText = okText;
  37. this.isEdit = isEdit;
  38. this.dbInbound = new DBInbound(dbInbound);
  39. this.inbound = dbInbound.toInbound();
  40. this.clients = this.getClients(this.inbound.protocol, this.inbound.settings);
  41. this.index = index === null ? this.clients.length : index;
  42. this.delayedStart = false;
  43. if (isEdit) {
  44. if (this.clients[index].expiryTime < 0) {
  45. this.delayedStart = true;
  46. }
  47. this.oldClientId = this.getClientId(dbInbound.protocol, clients[index]);
  48. } else {
  49. this.addClient(this.inbound.protocol, this.clients);
  50. }
  51. this.clientStats = this.dbInbound.clientStats.find(row => row.email === this.clients[this.index].email);
  52. this.confirm = confirm;
  53. },
  54. getClients(protocol, clientSettings) {
  55. switch (protocol) {
  56. case Protocols.VMESS: return clientSettings.vmesses;
  57. case Protocols.VLESS: return clientSettings.vlesses;
  58. case Protocols.TROJAN: return clientSettings.trojans;
  59. case Protocols.SHADOWSOCKS: return clientSettings.shadowsockses;
  60. default: return null;
  61. }
  62. },
  63. getClientId(protocol, client) {
  64. switch (protocol) {
  65. case Protocols.TROJAN: return client.password;
  66. case Protocols.SHADOWSOCKS: return client.email;
  67. default: return client.id;
  68. }
  69. },
  70. addClient(protocol, clients) {
  71. switch (protocol) {
  72. case Protocols.VMESS: return clients.push(new Inbound.VmessSettings.Vmess());
  73. case Protocols.VLESS: return clients.push(new Inbound.VLESSSettings.VLESS());
  74. case Protocols.TROJAN: return clients.push(new Inbound.TrojanSettings.Trojan());
  75. case Protocols.SHADOWSOCKS: return clients.push(new Inbound.ShadowsocksSettings.Shadowsocks(clients[0].method));
  76. default: return null;
  77. }
  78. },
  79. close() {
  80. clientModal.visible = false;
  81. clientModal.loading(false);
  82. },
  83. loading(loading) {
  84. clientModal.confirmLoading = loading;
  85. },
  86. };
  87. const clientModalApp = new Vue({
  88. delimiters: ['[[', ']]'],
  89. el: '#client-modal',
  90. data: {
  91. clientModal,
  92. get inbound() {
  93. return this.clientModal.inbound;
  94. },
  95. get client() {
  96. return this.clientModal.clients[this.clientModal.index];
  97. },
  98. get clientStats() {
  99. return this.clientModal.clientStats;
  100. },
  101. get isEdit() {
  102. return this.clientModal.isEdit;
  103. },
  104. get isTrafficExhausted() {
  105. if (!clientStats) return false
  106. if (clientStats.total <= 0) return false
  107. if (clientStats.up + clientStats.down < clientStats.total) return false
  108. return true
  109. },
  110. get isExpiry() {
  111. return this.clientModal.isEdit && this.client.expiryTime >0 ? (this.client.expiryTime < new Date().getTime()) : false;
  112. },
  113. get delayedStart() {
  114. return this.clientModal.delayedStart;
  115. },
  116. set delayedStart(value) {
  117. this.clientModal.delayedStart = value;
  118. },
  119. get delayedExpireDays() {
  120. return this.client && this.client.expiryTime < 0 ? this.client.expiryTime / -86400000 : 0;
  121. },
  122. set delayedExpireDays(days) {
  123. this.client.expiryTime = -86400000 * days;
  124. },
  125. },
  126. methods: {
  127. async getDBClientIps(email) {
  128. const msg = await HttpUtil.post(`/panel/inbound/clientIps/${email}`);
  129. if (!msg.success) {
  130. document.getElementById("clientIPs").value = msg.obj;
  131. return;
  132. }
  133. let ips = msg.obj;
  134. if (typeof ips === 'string' && ips.startsWith('[') && ips.endsWith(']')) {
  135. try {
  136. ips = JSON.parse(ips);
  137. ips = Array.isArray(ips) ? ips.join("\n") : ips;
  138. } catch (e) {
  139. console.error('Error parsing JSON:', e);
  140. }
  141. }
  142. document.getElementById("clientIPs").value = ips;
  143. },
  144. async clearDBClientIps(email) {
  145. try {
  146. const msg = await HttpUtil.post(`/panel/inbound/clearClientIps/${email}`);
  147. if (!msg.success) {
  148. return;
  149. }
  150. document.getElementById("clientIPs").value = "";
  151. } catch (error) {
  152. }
  153. },
  154. resetClientTraffic(email, dbInboundId, iconElement) {
  155. this.$confirm({
  156. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  157. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  158. class: themeSwitcher.currentTheme,
  159. okText: '{{ i18n "reset"}}',
  160. cancelText: '{{ i18n "cancel"}}',
  161. onOk: async () => {
  162. iconElement.disabled = true;
  163. const msg = await HttpUtil.postWithModal('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + email);
  164. if (msg.success) {
  165. this.clientModal.clientStats.up = 0;
  166. this.clientModal.clientStats.down = 0;
  167. }
  168. iconElement.disabled = false;
  169. },
  170. })
  171. },
  172. },
  173. });
  174. </script>
  175. {{end}}