1
0

client_modal.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. {{define "modals/clientsModal"}}
  2. <a-modal id="client-modal" v-model="clientModal.visible"
  3. :title="clientModal.title" @ok="clientModal.ok"
  4. :confirm-loading="clientModal.confirmLoading" :closable="true"
  5. :mask-closable="false"
  6. :class="themeSwitcher.currentTheme"
  7. :ok-text="clientModal.okText" cancel-text='{{ i18n "close" }}'>
  8. <template v-if="isEdit">
  9. <a-tag v-if="isExpiry || isTrafficExhausted" color="red"
  10. :style="{ marginBottom: '10px', display: 'block', textAlign: 'center' }">Account
  11. is (Expired|Traffic Ended) And Disabled</a-tag>
  12. </template>
  13. {{template "form/client"}}
  14. </a-modal>
  15. <script>
  16. const clientModal = {
  17. visible: false,
  18. confirmLoading: false,
  19. title: '',
  20. okText: '',
  21. isEdit: false,
  22. dbInbound: new DBInbound(),
  23. inbound: new Inbound(),
  24. clients: [],
  25. clientStats: [],
  26. oldClientId: "",
  27. index: null,
  28. clientIps: null,
  29. delayedStart: false,
  30. ok() {
  31. if (clientModal.isEdit) {
  32. ObjectUtil.execute(clientModal.confirm, clientModalApp.client, clientModal.dbInbound.id, clientModal.oldClientId);
  33. } else {
  34. ObjectUtil.execute(clientModal.confirm, clientModalApp.client, clientModal.dbInbound.id);
  35. }
  36. },
  37. show({ title = '', okText = '{{ i18n "sure" }}', index = null, dbInbound = null, confirm = () => { }, isEdit = false }) {
  38. this.visible = true;
  39. this.title = title;
  40. this.okText = okText;
  41. this.isEdit = isEdit;
  42. this.dbInbound = new DBInbound(dbInbound);
  43. this.inbound = Inbound.fromJson(dbInbound.toInbound().toJson());
  44. this.clients = this.inbound.clients;
  45. this.index = index === null ? this.clients.length : index;
  46. this.delayedStart = false;
  47. if (isEdit) {
  48. if (this.clients[index].expiryTime < 0) {
  49. this.delayedStart = true;
  50. }
  51. this.oldClientId = this.getClientId(dbInbound.protocol, clients[index]);
  52. } else {
  53. this.addClient(this.inbound, this.clients);
  54. }
  55. this.clientStats = this.dbInbound.clientStats.find(row => row.email === this.clients[this.index].email);
  56. this.confirm = confirm;
  57. },
  58. getClientId(protocol, client) {
  59. switch (protocol) {
  60. case Protocols.TROJAN: return client.password;
  61. case Protocols.SHADOWSOCKS: return client.email;
  62. case Protocols.HYSTERIA: return client.auth;
  63. default: return client.id;
  64. }
  65. },
  66. addClient(inbound, clients) {
  67. switch (inbound.protocol) {
  68. case Protocols.VMESS: return clients.push(new Inbound.VmessSettings.VMESS());
  69. case Protocols.VLESS: return clients.push(new Inbound.VLESSSettings.VLESS());
  70. case Protocols.TROJAN: return clients.push(new Inbound.TrojanSettings.Trojan());
  71. case Protocols.SHADOWSOCKS: return clients.push(new Inbound.ShadowsocksSettings.Shadowsocks(clients[0].method, RandomUtil.randomShadowsocksPassword(inbound.settings.method)));
  72. case Protocols.HYSTERIA: return clients.push(new Inbound.HysteriaSettings.Hysteria());
  73. default: return null;
  74. }
  75. },
  76. close() {
  77. clientModal.visible = false;
  78. clientModal.loading(false);
  79. },
  80. loading(loading=true) {
  81. clientModal.confirmLoading = loading;
  82. },
  83. };
  84. const clientModalApp = new Vue({
  85. delimiters: ['[[', ']]'],
  86. el: '#client-modal',
  87. data: {
  88. clientModal,
  89. get inbound() {
  90. return this.clientModal.inbound;
  91. },
  92. get client() {
  93. return this.clientModal.clients[this.clientModal.index];
  94. },
  95. get clientStats() {
  96. return this.clientModal.clientStats;
  97. },
  98. get isEdit() {
  99. return this.clientModal.isEdit;
  100. },
  101. get datepicker() {
  102. return app.datepicker;
  103. },
  104. get isTrafficExhausted() {
  105. if (!this.clientStats) return false
  106. if (this.clientStats.total <= 0) return false
  107. if (this.clientStats.up + this.clientStats.down < this.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/api/inbounds/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/api/inbounds/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/api/inbounds/' + 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}}