1
0

inbound_modal.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. isExpiry(index) {
  90. return this.inbound.isExpiry(index)
  91. },
  92. isClientEnable(email) {
  93. clientStats = this.dbInbound.clientStats ? this.dbInbound.clientStats.find(stats => stats.email === email) : null
  94. return clientStats ? clientStats['enable'] : true
  95. },
  96. setDefaultCertData(){
  97. inModal.inbound.stream.tls.certs[0].certFile = app.defaultCert;
  98. inModal.inbound.stream.tls.certs[0].keyFile = app.defaultKey;
  99. },
  100. getNewEmail(client) {
  101. var chars = 'abcdefghijklmnopqrstuvwxyz1234567890';
  102. var string = '';
  103. var len = 6 + Math.floor(Math.random() * 5);
  104. for(var ii=0; ii<len; ii++){
  105. string += chars[Math.floor(Math.random() * chars.length)];
  106. }
  107. client.email = string;
  108. }
  109. },
  110. });
  111. </script>
  112. {{end}}