1
0

client_modal.html 5.5 KB

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