inbound_modal.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. get multiDomain() {
  91. return this.inbound.stream.tls.settings.domains.length > 0;
  92. },
  93. set multiDomain(value) {
  94. if (value) {
  95. inModal.inbound.stream.tls.server = "";
  96. inModal.inbound.stream.tls.settings.domains = [{remark: "", domain: window.location.host.split(":")[0]}];
  97. } else {
  98. inModal.inbound.stream.tls.server = "";
  99. inModal.inbound.stream.tls.settings.domains = [];
  100. }
  101. }
  102. },
  103. methods: {
  104. streamNetworkChange() {
  105. if (!inModal.inbound.canSetTls()) {
  106. this.inModal.inbound.stream.security = 'none';
  107. }
  108. if (!inModal.inbound.canEnableReality()) {
  109. this.inModal.inbound.reality = false;
  110. }
  111. },
  112. setDefaultCertData(index) {
  113. inModal.inbound.stream.tls.certs[index].certFile = app.defaultCert;
  114. inModal.inbound.stream.tls.certs[index].keyFile = app.defaultKey;
  115. },
  116. setDefaultCertXtls(index) {
  117. inModal.inbound.stream.xtls.certs[index].certFile = app.defaultCert;
  118. inModal.inbound.stream.xtls.certs[index].keyFile = app.defaultKey;
  119. },
  120. async getNewX25519Cert() {
  121. inModal.loading(true);
  122. const msg = await HttpUtil.post('/server/getNewX25519Cert');
  123. inModal.loading(false);
  124. if (!msg.success) {
  125. return;
  126. }
  127. inModal.inbound.stream.reality.privateKey = msg.obj.privateKey;
  128. inModal.inbound.stream.reality.settings.publicKey = msg.obj.publicKey;
  129. }
  130. },
  131. });
  132. </script>
  133. {{end}}