1
0

client_modal.html 7.6 KB

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