1
0

client_modal.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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="siderDrawer.isDarkTheme ? darkClass : ''"
  5. :ok-text="clientModal.okText" cancel-text='{{ i18n "close" }}'>
  6. {{template "form/client"}}
  7. </a-modal>
  8. <script>
  9. const clientModal = {
  10. visible: false,
  11. confirmLoading: false,
  12. title: '',
  13. okText: '',
  14. isEdit: false,
  15. dbInbound: new DBInbound(),
  16. inbound: new Inbound(),
  17. clients: [],
  18. clientStats: [],
  19. oldClientId: "",
  20. index: null,
  21. clientIps: null,
  22. isExpired: false,
  23. delayedStart: false,
  24. ok() {
  25. if(clientModal.isEdit){
  26. ObjectUtil.execute(clientModal.confirm, clientModalApp.client, clientModal.dbInbound.id, clientModal.oldClientId);
  27. } else {
  28. ObjectUtil.execute(clientModal.confirm, clientModalApp.client, clientModal.dbInbound.id);
  29. }
  30. },
  31. show({ title='', okText='{{ i18n "sure" }}', index=null, dbInbound=null, confirm=()=>{}, isEdit=false }) {
  32. this.visible = true;
  33. this.title = title;
  34. this.okText = okText;
  35. this.isEdit = isEdit;
  36. this.dbInbound = new DBInbound(dbInbound);
  37. this.inbound = dbInbound.toInbound();
  38. this.clients = this.getClients(this.inbound.protocol, this.inbound.settings);
  39. this.index = index === null ? this.clients.length : index;
  40. this.isExpired = isEdit ? this.inbound.isExpiry(this.index) : false;
  41. this.delayedStart = false;
  42. if (isEdit){
  43. if (this.clients[index].expiryTime < 0){
  44. this.delayedStart = true;
  45. }
  46. this.oldClientId = this.dbInbound.protocol == "trojan" ? this.clients[index].password : this.clients[index].id;
  47. } else {
  48. this.addClient(this.inbound.protocol, this.clients);
  49. }
  50. this.clientStats = this.dbInbound.clientStats.find(row => row.email === this.clients[this.index].email);
  51. this.confirm = confirm;
  52. },
  53. getClients(protocol, clientSettings) {
  54. switch(protocol){
  55. case Protocols.VMESS: return clientSettings.vmesses;
  56. case Protocols.VLESS: return clientSettings.vlesses;
  57. case Protocols.TROJAN: return clientSettings.trojans;
  58. default: return null;
  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. default: return null;
  67. }
  68. },
  69. close() {
  70. clientModal.visible = false;
  71. clientModal.loading(false);
  72. },
  73. loading(loading) {
  74. clientModal.confirmLoading = loading;
  75. },
  76. };
  77. const clientModalApp = new Vue({
  78. delimiters: ['[[', ']]'],
  79. el: '#client-modal',
  80. data: {
  81. clientModal,
  82. get inbound() {
  83. return this.clientModal.inbound;
  84. },
  85. get client() {
  86. return this.clientModal.clients[this.clientModal.index];
  87. },
  88. get clientStats() {
  89. return this.clientModal.clientStats;
  90. },
  91. get isEdit() {
  92. return this.clientModal.isEdit;
  93. },
  94. get isTrafficExhausted() {
  95. if(!clientStats) return false
  96. if(clientStats.total <= 0) return false
  97. if(clientStats.up + clientStats.down < clientStats.total) return false
  98. return true
  99. },
  100. get isExpiry() {
  101. return this.clientModal.isExpired
  102. },
  103. get statsColor() {
  104. if(!clientStats) return 'blue'
  105. if(clientStats.total <= 0) return 'blue'
  106. else if(clientStats.total > 0 && (clientStats.down+clientStats.up) < clientStats.total) return 'cyan'
  107. else return 'red'
  108. },
  109. get delayedExpireDays() {
  110. return this.client && this.client.expiryTime < 0 ? this.client.expiryTime / -86400000 : 0;
  111. },
  112. set delayedExpireDays(days){
  113. this.client.expiryTime = -86400000 * days;
  114. },
  115. },
  116. methods: {
  117. getNewEmail(client) {
  118. var chars = 'abcdefghijklmnopqrstuvwxyz1234567890';
  119. var string = '';
  120. var len = 6 + Math.floor(Math.random() * 5);
  121. for(var ii=0; ii<len; ii++){
  122. string += chars[Math.floor(Math.random() * chars.length)];
  123. }
  124. client.email = string;
  125. },
  126. async getDBClientIps(email,event) {
  127. const msg = await HttpUtil.post('/xui/inbound/clientIps/'+ email);
  128. if (!msg.success) {
  129. return;
  130. }
  131. try {
  132. ips = JSON.parse(msg.obj)
  133. ips = ips.join(",")
  134. event.target.value = ips
  135. } catch (error) {
  136. // text
  137. event.target.value = msg.obj
  138. }
  139. },
  140. async clearDBClientIps(email) {
  141. const msg = await HttpUtil.post('/xui/inbound/clearClientIps/'+ email);
  142. if (!msg.success) {
  143. return;
  144. }
  145. document.getElementById("clientIPs").value = ""
  146. },
  147. resetClientTraffic(email,dbInboundId,iconElement) {
  148. this.$confirm({
  149. title: '{{ i18n "pages.inbounds.resetTraffic"}}',
  150. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  151. class: siderDrawer.isDarkTheme ? darkClass : '',
  152. okText: '{{ i18n "reset"}}',
  153. cancelText: '{{ i18n "cancel"}}',
  154. onOk: async () => {
  155. iconElement.disabled = true;
  156. const msg = await HttpUtil.postWithModal('/xui/inbound/' + dbInboundId + '/resetClientTraffic/'+ email);
  157. if (msg.success) {
  158. this.clientModal.clientStats.up = 0;
  159. this.clientModal.clientStats.down = 0;
  160. }
  161. iconElement.disabled = false;
  162. },
  163. })
  164. },
  165. },
  166. });
  167. </script>
  168. {{end}}