inbound_modal.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. {{define "modals/inboundModal"}}
  2. <a-modal id="inbound-modal" v-model="inModal.visible" :title="inModal.title" :dialog-style="{ top: '20px' }"
  3. @ok="inModal.ok" :confirm-loading="inModal.confirmLoading" :closable="true" :mask-closable="false"
  4. :class="themeSwitcher.currentTheme" :ok-text="inModal.okText" cancel-text='{{ i18n "close" }}'>
  5. {{template "form/inbound"}}
  6. </a-modal>
  7. <script>
  8. const inModal = {
  9. title: '',
  10. visible: false,
  11. confirmLoading: false,
  12. okText: '{{ i18n "sure" }}',
  13. isEdit: false,
  14. confirm: null,
  15. inbound: new Inbound(),
  16. dbInbound: new DBInbound(),
  17. ok() {
  18. ObjectUtil.execute(inModal.confirm, inModal.inbound, inModal.dbInbound);
  19. },
  20. show({ title = '', okText = '{{ i18n "sure" }}', inbound = null, dbInbound = null, confirm = (inbound, dbInbound) => { }, isEdit = false }) {
  21. this.title = title;
  22. this.okText = okText;
  23. if (inbound) {
  24. this.inbound = Inbound.fromJson(inbound.toJson());
  25. } else {
  26. this.inbound = new Inbound();
  27. }
  28. if (dbInbound) {
  29. this.dbInbound = new DBInbound(dbInbound);
  30. } else {
  31. this.dbInbound = new DBInbound();
  32. }
  33. this.confirm = confirm;
  34. this.visible = true;
  35. this.isEdit = isEdit;
  36. },
  37. close() {
  38. inModal.visible = false;
  39. inModal.loading(false);
  40. },
  41. loading(loading = true) {
  42. inModal.confirmLoading = loading;
  43. },
  44. };
  45. new Vue({
  46. delimiters: ['[[', ']]'],
  47. el: '#inbound-modal',
  48. data: {
  49. inModal: inModal,
  50. delayedStart: false,
  51. get inbound() {
  52. return inModal.inbound;
  53. },
  54. get dbInbound() {
  55. return inModal.dbInbound;
  56. },
  57. get isEdit() {
  58. return inModal.isEdit;
  59. },
  60. get client() {
  61. return inModal.inbound.clients[0];
  62. },
  63. get datepicker() {
  64. return app.datepicker;
  65. },
  66. get delayedExpireDays() {
  67. return this.client && this.client.expiryTime < 0 ? this.client.expiryTime / -86400000 : 0;
  68. },
  69. set delayedExpireDays(days) {
  70. this.client.expiryTime = -86400000 * days;
  71. },
  72. get externalProxy() {
  73. return this.inbound.stream.externalProxy.length > 0;
  74. },
  75. set externalProxy(value) {
  76. if (value) {
  77. inModal.inbound.stream.externalProxy = [{
  78. forceTls: "same",
  79. dest: window.location.hostname,
  80. port: inModal.inbound.port,
  81. remark: ""
  82. }];
  83. } else {
  84. inModal.inbound.stream.externalProxy = [];
  85. }
  86. }
  87. },
  88. methods: {
  89. streamNetworkChange() {
  90. if (!inModal.inbound.canEnableTls()) {
  91. this.inModal.inbound.stream.security = 'none';
  92. }
  93. if (!inModal.inbound.canEnableReality()) {
  94. this.inModal.inbound.reality = false;
  95. }
  96. if (this.inModal.inbound.protocol == Protocols.VLESS && !inModal.inbound.canEnableTlsFlow()) {
  97. this.inModal.inbound.settings.vlesses.forEach(client => {
  98. client.flow = "";
  99. });
  100. }
  101. },
  102. SSMethodChange() {
  103. this.inModal.inbound.settings.password = RandomUtil.randomShadowsocksPassword(this.inModal.inbound.settings.method)
  104. if (this.inModal.inbound.isSSMultiUser) {
  105. if (this.inModal.inbound.settings.shadowsockses.length == 0) {
  106. this.inModal.inbound.settings.shadowsockses = [new Inbound.ShadowsocksSettings.Shadowsocks()];
  107. }
  108. if (!this.inModal.inbound.isSS2022) {
  109. this.inModal.inbound.settings.shadowsockses.forEach(client => {
  110. client.method = this.inModal.inbound.settings.method;
  111. })
  112. } else {
  113. this.inModal.inbound.settings.shadowsockses.forEach(client => {
  114. client.method = "";
  115. })
  116. }
  117. this.inModal.inbound.settings.shadowsockses.forEach(client => {
  118. client.password = RandomUtil.randomShadowsocksPassword(this.inModal.inbound.settings.method)
  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. async getNewX25519Cert() {
  131. inModal.loading(true);
  132. const msg = await HttpUtil.post('/server/getNewX25519Cert');
  133. inModal.loading(false);
  134. if (!msg.success) {
  135. return;
  136. }
  137. inModal.inbound.stream.reality.privateKey = msg.obj.privateKey;
  138. inModal.inbound.stream.reality.settings.publicKey = msg.obj.publicKey;
  139. },
  140. async getNewmldsa65() {
  141. inModal.loading(true);
  142. const msg = await HttpUtil.post('/server/getNewmldsa65');
  143. inModal.loading(false);
  144. if (!msg.success) {
  145. return;
  146. }
  147. inModal.inbound.stream.reality.mldsa65Seed = msg.obj.seed;
  148. inModal.inbound.stream.reality.settings.mldsa65Verify = msg.obj.verify;
  149. },
  150. async getNewEchCert() {
  151. inModal.loading(true);
  152. const msg = await HttpUtil.post('/server/getNewEchCert', { sni: inModal.inbound.stream.tls.sni });
  153. inModal.loading(false);
  154. if (!msg.success) {
  155. return;
  156. }
  157. inModal.inbound.stream.tls.echServerKeys = msg.obj.echServerKeys;
  158. inModal.inbound.stream.tls.settings.echConfigList = msg.obj.echConfigList;
  159. },
  160. async getNewVlessEnc() {
  161. inModal.loading(true);
  162. const msg = await HttpUtil.post('/server/getNewVlessEnc');
  163. inModal.loading(false);
  164. if (!msg.success) {
  165. return;
  166. }
  167. const auths = msg.obj.auths || [];
  168. const selected = inModal.inbound.settings.selectedAuth;
  169. const block = auths.find(a => a.label === selected);
  170. if (!block) {
  171. console.error("No auth block for", selected);
  172. return;
  173. }
  174. inModal.inbound.settings.decryption = block.decryption;
  175. inModal.inbound.settings.encryption = block.encryption;
  176. },
  177. clearKeys() {
  178. this.inbound.settings.decryption = 'none';
  179. this.inbound.settings.encryption = '';
  180. }
  181. },
  182. });
  183. </script>
  184. {{end}}