inbound_modal.html 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. {{define "inboundModal"}}
  2. <a-modal id="inbound-modal" v-model="inModal.visible" :title="inModal.title" @ok="inModal.ok"
  3. :confirm-loading="inModal.confirmLoading" :closable="true" :mask-closable="false"
  4. :class="siderDrawer.isDarkTheme ? darkClass : ''"
  5. :ok-text="inModal.okText" cancel-text='{{ i18n "close" }}'>
  6. {{template "form/inbound"}}
  7. </a-modal>
  8. <script>
  9. const inModal = {
  10. title: '',
  11. visible: false,
  12. confirmLoading: false,
  13. okText: '{{ i18n "sure" }}',
  14. isEdit: false,
  15. confirm: null,
  16. inbound: new Inbound(),
  17. dbInbound: new DBInbound(),
  18. ok() {
  19. ObjectUtil.execute(inModal.confirm, inModal.inbound, inModal.dbInbound);
  20. },
  21. show({ title='', okText='{{ i18n "sure" }}', inbound=null, dbInbound=null, confirm=(inbound, dbInbound)=>{}, isEdit=false }) {
  22. this.title = title;
  23. this.okText = okText;
  24. if (inbound) {
  25. this.inbound = Inbound.fromJson(inbound.toJson());
  26. } else {
  27. this.inbound = new Inbound();
  28. }
  29. if (dbInbound) {
  30. this.dbInbound = new DBInbound(dbInbound);
  31. } else {
  32. this.dbInbound = new DBInbound();
  33. }
  34. this.confirm = confirm;
  35. this.visible = true;
  36. this.isEdit = isEdit;
  37. },
  38. close() {
  39. inModal.visible = false;
  40. inModal.loading(false);
  41. },
  42. loading(loading) {
  43. inModal.confirmLoading = loading;
  44. },
  45. };
  46. const protocols = {
  47. VMESS: Protocols.VMESS,
  48. VLESS: Protocols.VLESS,
  49. TROJAN: Protocols.TROJAN,
  50. SHADOWSOCKS: Protocols.SHADOWSOCKS,
  51. DOKODEMO: Protocols.DOKODEMO,
  52. SOCKS: Protocols.SOCKS,
  53. HTTP: Protocols.HTTP,
  54. };
  55. new Vue({
  56. delimiters: ['[[', ']]'],
  57. el: '#inbound-modal',
  58. data: {
  59. inModal: inModal,
  60. Protocols: protocols,
  61. SSMethods: SSMethods,
  62. get inbound() {
  63. return inModal.inbound;
  64. },
  65. get dbInbound() {
  66. return inModal.dbInbound;
  67. },
  68. get isEdit() {
  69. return inModal.isEdit;
  70. }
  71. },
  72. methods: {
  73. streamNetworkChange(oldValue) {
  74. if (oldValue === 'kcp') {
  75. this.inModal.inbound.tls = false;
  76. }
  77. },
  78. addClient(protocol, clients) {
  79. switch (protocol) {
  80. case Protocols.VMESS: return clients.push(new Inbound.VmessSettings.Vmess());
  81. case Protocols.VLESS: return clients.push(new Inbound.VLESSSettings.VLESS());
  82. case Protocols.TROJAN: return clients.push(new Inbound.TrojanSettings.Trojan());
  83. default: return null;
  84. }
  85. },
  86. removeClient(index, clients) {
  87. clients.splice(index, 1);
  88. },
  89. async getDBClientIps(email, event) {
  90. const msg = await HttpUtil.post('/xui/inbound/clientIps/' + email);
  91. if (!msg.success) {
  92. return;
  93. }
  94. try {
  95. let ips = JSON.parse(msg.obj);
  96. ips = ips.join(",");
  97. event.target.value = ips;
  98. } catch (error) {
  99. event.target.value = msg.obj;
  100. }
  101. },
  102. async clearDBClientIps(email,event) {
  103. const msg = await HttpUtil.post('/xui/inbound/clearClientIps/'+ email);
  104. if (!msg.success) {
  105. return;
  106. }
  107. event.target.value = ""
  108. },
  109. async resetClientTraffic(client, event) {
  110. const msg = await HttpUtil.post(`/xui/inbound/resetClientTraffic/${client.email}`);
  111. if (!msg.success) {
  112. return;
  113. }
  114. const clientStats = this.inbound.clientStats;
  115. if (clientStats.length > 0) {
  116. for (let i = 0; i < clientStats.length; i++) {
  117. if (clientStats[i].email === client.email) {
  118. clientStats[i].up = 0;
  119. clientStats[i].down = 0;
  120. break; // Stop looping once we've found the matching client.
  121. }
  122. }
  123. }
  124. },
  125. isExpiry(index) {
  126. return this.inbound.isExpiry(index)
  127. },
  128. getUpStats(email) {
  129. clientStats = this.inbound.clientStats
  130. if(clientStats.length > 0)
  131. {
  132. for (const key in clientStats) {
  133. if (Object.hasOwnProperty.call(clientStats, key)) {
  134. if(clientStats[key]['email'] == email)
  135. return clientStats[key]['up']
  136. }
  137. }
  138. }
  139. },
  140. getDownStats(email) {
  141. clientStats = this.inbound.clientStats
  142. if(clientStats.length > 0)
  143. {
  144. for (const key in clientStats) {
  145. if (Object.hasOwnProperty.call(clientStats, key)) {
  146. if(clientStats[key]['email'] == email)
  147. return clientStats[key]['down']
  148. }
  149. }
  150. }
  151. },
  152. isClientEnable(email) {
  153. clientStats = this.dbInbound.clientStats ? this.dbInbound.clientStats.find(stats => stats.email === email) : null
  154. return clientStats ? clientStats['enable'] : true
  155. },
  156. getHeaderText(email) {
  157. if(email == "")
  158. return "Add Client"
  159. return email + (this.isClientEnable(email) == true ? ' Active' : ' Deactive')
  160. },
  161. getHeaderStyle(email) {
  162. return (this.isClientEnable(email) == true ? '' : 'deactive-client')
  163. },
  164. getNewEmail(client) {
  165. var chars = 'abcdefghijklmnopqrstuvwxyz1234567890';
  166. var string = '';
  167. var len = 7 + Math.floor(Math.random() * 5)
  168. for(var ii=0; ii<len; ii++){
  169. string += chars[Math.floor(Math.random() * chars.length)];
  170. }
  171. client.email = string
  172. }
  173. },
  174. });
  175. </script>
  176. {{end}}