1
0

client_modal.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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.inbound.clients;
  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. getClientId(protocol, client) {
  55. switch (protocol) {
  56. case Protocols.TROJAN: return client.password;
  57. case Protocols.SHADOWSOCKS: return client.email;
  58. default: return client.id;
  59. }
  60. },
  61. addClient(protocol, clients) {
  62. switch (protocol) {
  63. case Protocols.VMESS: return clients.push(new Inbound.VmessSettings.Vmess());
  64. case Protocols.VLESS: return clients.push(new Inbound.VLESSSettings.VLESS());
  65. case Protocols.TROJAN: return clients.push(new Inbound.TrojanSettings.Trojan());
  66. case Protocols.SHADOWSOCKS: return clients.push(new Inbound.ShadowsocksSettings.Shadowsocks(clients[0].method));
  67. default: return null;
  68. }
  69. },
  70. close() {
  71. clientModal.visible = false;
  72. clientModal.loading(false);
  73. },
  74. loading(loading=true) {
  75. clientModal.confirmLoading = loading;
  76. },
  77. };
  78. const clientModalApp = new Vue({
  79. delimiters: ['[[', ']]'],
  80. el: '#client-modal',
  81. data: {
  82. clientModal,
  83. get inbound() {
  84. return this.clientModal.inbound;
  85. },
  86. get client() {
  87. return this.clientModal.clients[this.clientModal.index];
  88. },
  89. get clientStats() {
  90. return this.clientModal.clientStats;
  91. },
  92. get isEdit() {
  93. return this.clientModal.isEdit;
  94. },
  95. get datepicker() {
  96. return app.datepicker;
  97. },
  98. get isTrafficExhausted() {
  99. if (!clientStats) return false
  100. if (clientStats.total <= 0) return false
  101. if (clientStats.up + clientStats.down < clientStats.total) return false
  102. return true
  103. },
  104. get isExpiry() {
  105. return this.clientModal.isEdit && this.client.expiryTime >0 ? (this.client.expiryTime < new Date().getTime()) : false;
  106. },
  107. get delayedStart() {
  108. return this.clientModal.delayedStart;
  109. },
  110. set delayedStart(value) {
  111. this.clientModal.delayedStart = value;
  112. },
  113. get delayedExpireDays() {
  114. return this.client && this.client.expiryTime < 0 ? this.client.expiryTime / -86400000 : 0;
  115. },
  116. set delayedExpireDays(days) {
  117. this.client.expiryTime = -86400000 * days;
  118. },
  119. },
  120. methods: {
  121. async getDBClientIps(email) {
  122. const msg = await HttpUtil.post(`/panel/inbound/clientIps/${email}`);
  123. if (!msg.success) {
  124. document.getElementById("clientIPs").value = msg.obj;
  125. return;
  126. }
  127. let ips = msg.obj;
  128. if (typeof ips === 'string' && ips.startsWith('[') && ips.endsWith(']')) {
  129. try {
  130. ips = JSON.parse(ips);
  131. ips = Array.isArray(ips) ? ips.join("\n") : ips;
  132. } catch (e) {
  133. console.error('Error parsing JSON:', e);
  134. }
  135. }
  136. document.getElementById("clientIPs").value = ips;
  137. },
  138. async clearDBClientIps(email) {
  139. try {
  140. const msg = await HttpUtil.post(`/panel/inbound/clearClientIps/${email}`);
  141. if (!msg.success) {
  142. return;
  143. }
  144. document.getElementById("clientIPs").value = "";
  145. } catch (error) {
  146. }
  147. },
  148. resetClientTraffic(email, dbInboundId, iconElement) {
  149. this.$confirm({
  150. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  151. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  152. class: themeSwitcher.currentTheme,
  153. okText: '{{ i18n "reset"}}',
  154. cancelText: '{{ i18n "cancel"}}',
  155. onOk: async () => {
  156. iconElement.disabled = true;
  157. const msg = await HttpUtil.postWithModal('/panel/inbound/' + dbInboundId + '/resetClientTraffic/' + email);
  158. if (msg.success) {
  159. this.clientModal.clientStats.up = 0;
  160. this.clientModal.clientStats.down = 0;
  161. }
  162. iconElement.disabled = false;
  163. },
  164. })
  165. },
  166. },
  167. });
  168. </script>
  169. {{end}}