1
0

inbound_modal.html 4.4 KB

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