client_modal.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. index: null,
  20. clientIps: null,
  21. isExpired: false,
  22. delayedStart: false,
  23. ok() {
  24. if(clientModal.isEdit){
  25. ObjectUtil.execute(clientModal.confirm, clientModalApp.client, clientModal.dbInbound.id, clientModal.index);
  26. } else {
  27. ObjectUtil.execute(clientModal.confirm, clientModalApp.client, clientModal.dbInbound.id);
  28. }
  29. },
  30. show({ title='', okText='{{ i18n "sure" }}', index=null, dbInbound=null, confirm=()=>{}, isEdit=false }) {
  31. this.visible = true;
  32. this.title = title;
  33. this.okText = okText;
  34. this.isEdit = isEdit;
  35. this.dbInbound = new DBInbound(dbInbound);
  36. this.inbound = dbInbound.toInbound();
  37. this.clients = this.getClients(this.inbound.protocol, this.inbound.settings);
  38. this.index = index === null ? this.clients.length : index;
  39. this.isExpired = isEdit ? this.inbound.isExpiry(this.index) : false;
  40. this.delayedStart = false;
  41. if (!isEdit){
  42. this.addClient(this.inbound.protocol, this.clients);
  43. } else {
  44. if (this.clients[index].expiryTime < 0){
  45. this.delayedStart = true;
  46. }
  47. }
  48. this.clientStats = this.dbInbound.clientStats.find(row => row.email === this.clients[this.index].email);
  49. this.confirm = confirm;
  50. },
  51. getClients(protocol, clientSettings) {
  52. switch(protocol){
  53. case Protocols.VMESS: return clientSettings.vmesses;
  54. case Protocols.VLESS: return clientSettings.vlesses;
  55. case Protocols.TROJAN: return clientSettings.trojans;
  56. default: return null;
  57. }
  58. },
  59. addClient(protocol, clients) {
  60. switch (protocol) {
  61. case Protocols.VMESS: return clients.push(new Inbound.VmessSettings.Vmess());
  62. case Protocols.VLESS: return clients.push(new Inbound.VLESSSettings.VLESS());
  63. case Protocols.TROJAN: return clients.push(new Inbound.TrojanSettings.Trojan());
  64. default: return null;
  65. }
  66. },
  67. close() {
  68. clientModal.visible = false;
  69. clientModal.loading(false);
  70. },
  71. loading(loading) {
  72. clientModal.confirmLoading = loading;
  73. },
  74. };
  75. const clientModalApp = new Vue({
  76. delimiters: ['[[', ']]'],
  77. el: '#client-modal',
  78. data: {
  79. clientModal,
  80. get inbound() {
  81. return this.clientModal.inbound;
  82. },
  83. get client() {
  84. return this.clientModal.clients[this.clientModal.index];
  85. },
  86. get clientStats() {
  87. return this.clientModal.clientStats;
  88. },
  89. get isEdit() {
  90. return this.clientModal.isEdit;
  91. },
  92. get isTrafficExhausted() {
  93. if(!clientStats) return false
  94. if(clientStats.total <= 0) return false
  95. if(clientStats.up + clientStats.down < clientStats.total) return false
  96. return true
  97. },
  98. get isExpiry() {
  99. return this.clientModal.isExpired
  100. },
  101. get statsColor() {
  102. if(!clientStats) return 'blue'
  103. if(clientStats.total <= 0) return 'blue'
  104. else if(clientStats.total > 0 && (clientStats.down+clientStats.up) < clientStats.total) return 'cyan'
  105. else return 'red'
  106. },
  107. get delayedExpireDays() {
  108. return this.client && this.client.expiryTime < 0 ? this.client.expiryTime / -86400000 : 0;
  109. },
  110. set delayedExpireDays(days){
  111. this.client.expiryTime = -86400000 * days;
  112. },
  113. },
  114. methods: {
  115. getNewEmail(client) {
  116. var chars = 'abcdefghijklmnopqrstuvwxyz1234567890';
  117. var string = '';
  118. var len = 6 + Math.floor(Math.random() * 5);
  119. for(var ii=0; ii<len; ii++){
  120. string += chars[Math.floor(Math.random() * chars.length)];
  121. }
  122. client.email = string;
  123. },
  124. async getDBClientIps(email,event) {
  125. const msg = await HttpUtil.post('/xui/inbound/clientIps/'+ email);
  126. if (!msg.success) {
  127. return;
  128. }
  129. try {
  130. ips = JSON.parse(msg.obj)
  131. ips = ips.join(",")
  132. event.target.value = ips
  133. } catch (error) {
  134. // text
  135. event.target.value = msg.obj
  136. }
  137. },
  138. async clearDBClientIps(email) {
  139. const msg = await HttpUtil.post('/xui/inbound/clearClientIps/'+ email);
  140. if (!msg.success) {
  141. return;
  142. }
  143. document.getElementById("clientIPs").value = ""
  144. },
  145. },
  146. });
  147. </script>
  148. {{end}}