1
0

client_modal.html 5.1 KB

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