1
0

inbound_modal.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 resetClientTraffic(client,event) {
  89. const msg = await HttpUtil.post('/xui/inbound/resetClientTraffic/'+ client.email);
  90. if (!msg.success) {
  91. return;
  92. }
  93. clientStats = this.inbound.clientStats
  94. if(clientStats.length > 0)
  95. {
  96. for (const key in clientStats) {
  97. if (Object.hasOwnProperty.call(clientStats, key)) {
  98. if(clientStats[key]['email'] == client.email){
  99. clientStats[key]['up'] = 0
  100. clientStats[key]['down'] = 0
  101. }
  102. }
  103. }
  104. }
  105. },
  106. isExpiry(index) {
  107. return this.inbound.isExpiry(index)
  108. },
  109. getUpStats(email) {
  110. clientStats = this.inbound.clientStats
  111. if(clientStats.length > 0)
  112. {
  113. for (const key in clientStats) {
  114. if (Object.hasOwnProperty.call(clientStats, key)) {
  115. if(clientStats[key]['email'] == email)
  116. return clientStats[key]['up']
  117. }
  118. }
  119. }
  120. },
  121. getDownStats(email) {
  122. clientStats = this.inbound.clientStats
  123. if(clientStats.length > 0)
  124. {
  125. for (const key in clientStats) {
  126. if (Object.hasOwnProperty.call(clientStats, key)) {
  127. if(clientStats[key]['email'] == email)
  128. return clientStats[key]['down']
  129. }
  130. }
  131. }
  132. },
  133. isClientEnable(email) {
  134. clientStats = this.inbound.clientStats
  135. if(clientStats.length > 0)
  136. {
  137. for (const key in clientStats) {
  138. if (Object.hasOwnProperty.call(clientStats, key)) {
  139. if(clientStats[key]['email'] == email)
  140. return clientStats[key]['enable']
  141. }
  142. }
  143. }
  144. },
  145. getHeaderText(email) {
  146. if(email == "")
  147. return "Add Client"
  148. return email + (this.isClientEnable(email) == true ? ' Active' : ' Deactive')
  149. },
  150. getHeaderStyle(email) {
  151. return (this.isClientEnable(email) == true ? '' : 'deactive-client')
  152. },
  153. getNewEmail(client) {
  154. var chars = 'abcdefghijklmnopqrstuvwxyz1234567890';
  155. var string = '';
  156. var len = 6 + Math.floor(Math.random() * 5)
  157. for(var ii=0; ii<len; ii++){
  158. string += chars[Math.floor(Math.random() * chars.length)];
  159. }
  160. client.email = string + "@gmail.com"
  161. }
  162. },
  163. });
  164. </script>
  165. {{end}}