inbound_modal.html 5.8 KB

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