inbound_modal.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. new Vue({
  56. delimiters: ['[[', ']]'],
  57. el: '#inbound-modal',
  58. data: {
  59. inModal: inModal,
  60. delayedStart: false,
  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. get client() {
  71. return inModal.getClients(this.inbound.protocol, this.inbound.settings)[0];
  72. },
  73. get delayedExpireDays() {
  74. return this.client && this.client.expiryTime < 0 ? this.client.expiryTime / -86400000 : 0;
  75. },
  76. set delayedExpireDays(days) {
  77. this.client.expiryTime = -86400000 * days;
  78. },
  79. get multiDomain() {
  80. return this.inbound.stream.tls.settings.domains.length > 0;
  81. },
  82. set multiDomain(value) {
  83. if (value) {
  84. inModal.inbound.stream.tls.server = "";
  85. inModal.inbound.stream.tls.settings.domains = [{ remark: "", domain: window.location.hostname }];
  86. } else {
  87. inModal.inbound.stream.tls.server = "";
  88. inModal.inbound.stream.tls.settings.domains = [];
  89. }
  90. }
  91. },
  92. methods: {
  93. streamNetworkChange() {
  94. if (!inModal.inbound.canSetTls()) {
  95. this.inModal.inbound.stream.security = 'none';
  96. }
  97. if (!inModal.inbound.canEnableReality()) {
  98. this.inModal.inbound.reality = false;
  99. }
  100. if (this.inModal.inbound.protocol == Protocols.VLESS && !inModal.inbound.canEnableTlsFlow()) {
  101. this.inModal.inbound.settings.vlesses.forEach(client => {
  102. client.flow = "";
  103. });
  104. }
  105. },
  106. SSMethodChange() {
  107. if (this.inModal.inbound.isSSMultiUser) {
  108. if (this.inModal.inbound.settings.shadowsockses.length ==0){
  109. this.inModal.inbound.settings.shadowsockses = [new Inbound.ShadowsocksSettings.Shadowsocks()];
  110. }
  111. if (!this.inModal.inbound.isSS2022) {
  112. this.inModal.inbound.settings.shadowsockses.forEach(client => {
  113. client.method = this.inModal.inbound.settings.method;
  114. })
  115. } else {
  116. this.inModal.inbound.settings.shadowsockses.forEach(client => {
  117. client.method = "";
  118. })
  119. }
  120. } else {
  121. if (this.inModal.inbound.settings.shadowsockses.length > 0){
  122. this.inModal.inbound.settings.shadowsockses = [];
  123. }
  124. }
  125. },
  126. setDefaultCertData(index) {
  127. inModal.inbound.stream.tls.certs[index].certFile = app.defaultCert;
  128. inModal.inbound.stream.tls.certs[index].keyFile = app.defaultKey;
  129. },
  130. setDefaultCertXtls(index) {
  131. inModal.inbound.stream.xtls.certs[index].certFile = app.defaultCert;
  132. inModal.inbound.stream.xtls.certs[index].keyFile = app.defaultKey;
  133. },
  134. async getNewX25519Cert() {
  135. inModal.loading(true);
  136. const msg = await HttpUtil.post('/server/getNewX25519Cert');
  137. inModal.loading(false);
  138. if (!msg.success) {
  139. return;
  140. }
  141. inModal.inbound.stream.reality.privateKey = msg.obj.privateKey;
  142. inModal.inbound.stream.reality.settings.publicKey = msg.obj.publicKey;
  143. }
  144. },
  145. });
  146. </script>
  147. {{end}}