inbound_modal.html 6.6 KB

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