inbound_modal.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. getClients(protocol, clientSettings) {
  46. switch(protocol){
  47. case Protocols.VMESS: return clientSettings.vmesses;
  48. case Protocols.VLESS: return clientSettings.vlesses;
  49. case Protocols.TROJAN: return clientSettings.trojans;
  50. default: return null;
  51. }
  52. },
  53. };
  54. const protocols = {
  55. VMESS: Protocols.VMESS,
  56. VLESS: Protocols.VLESS,
  57. TROJAN: Protocols.TROJAN,
  58. SHADOWSOCKS: Protocols.SHADOWSOCKS,
  59. DOKODEMO: Protocols.DOKODEMO,
  60. SOCKS: Protocols.SOCKS,
  61. HTTP: Protocols.HTTP,
  62. };
  63. new Vue({
  64. delimiters: ['[[', ']]'],
  65. el: '#inbound-modal',
  66. data: {
  67. inModal: inModal,
  68. Protocols: protocols,
  69. SSMethods: SSMethods,
  70. delayedStart: false,
  71. get inbound() {
  72. return inModal.inbound;
  73. },
  74. get dbInbound() {
  75. return inModal.dbInbound;
  76. },
  77. get isEdit() {
  78. return inModal.isEdit;
  79. },
  80. get client() {
  81. return inModal.getClients(this.inbound.protocol, this.inbound.settings)[0];
  82. },
  83. get delayedExpireDays() {
  84. return this.client && this.client.expiryTime < 0 ? this.client.expiryTime / -86400000 : 0;
  85. },
  86. set delayedExpireDays(days){
  87. this.client.expiryTime = -86400000 * days;
  88. },
  89. },
  90. methods: {
  91. streamNetworkChange() {
  92. if (!inModal.inbound.canSetTls()) {
  93. this.inModal.inbound.stream.security = 'none';
  94. }
  95. if (!inModal.inbound.canEnableReality()) {
  96. this.inModal.inbound.reality = false;
  97. }
  98. },
  99. setDefaultCertData(){
  100. inModal.inbound.stream.tls.certs[0].certFile = app.defaultCert;
  101. inModal.inbound.stream.tls.certs[0].keyFile = app.defaultKey;
  102. },
  103. async getNewX25519Cert(){
  104. inModal.loading(true);
  105. const msg = await HttpUtil.post('/server/getNewX25519Cert');
  106. inModal.loading(false);
  107. if (!msg.success) {
  108. return;
  109. }
  110. inModal.inbound.stream.reality.privateKey = msg.obj.privateKey;
  111. inModal.inbound.stream.reality.settings.publicKey = msg.obj.publicKey;
  112. },
  113. getNewEmail(client) {
  114. var chars = 'abcdefghijklmnopqrstuvwxyz1234567890';
  115. var string = '';
  116. var len = 6 + Math.floor(Math.random() * 5);
  117. for(var ii=0; ii<len; ii++){
  118. string += chars[Math.floor(Math.random() * chars.length)];
  119. }
  120. client.email = string;
  121. }
  122. },
  123. });
  124. </script>
  125. {{end}}