1
0

inbound_modal.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. {{define "inboundModal"}}
  2. <a-modal id="inbound-modal" v-model="inModal.visible" :title="inModal.title"
  3. :dialog-style="{ top: '20px' }" @ok="inModal.ok"
  4. :confirm-loading="inModal.confirmLoading" :closable="true" :mask-closable="false"
  5. :class="themeSwitcher.currentTheme"
  6. :ok-text="inModal.okText" cancel-text='{{ i18n "close" }}'>
  7. {{template "form/inbound"}}
  8. </a-modal>
  9. <script>
  10. const inModal = {
  11. title: '',
  12. visible: false,
  13. confirmLoading: false,
  14. okText: '{{ i18n "sure" }}',
  15. isEdit: false,
  16. confirm: null,
  17. inbound: new Inbound(),
  18. dbInbound: new DBInbound(),
  19. ok() {
  20. ObjectUtil.execute(inModal.confirm, inModal.inbound, inModal.dbInbound);
  21. },
  22. show({ title = '', okText = '{{ i18n "sure" }}', inbound = null, dbInbound = null, confirm = (inbound, dbInbound) => {}, isEdit = false }) {
  23. this.title = title;
  24. this.okText = okText;
  25. if (inbound) {
  26. this.inbound = Inbound.fromJson(inbound.toJson());
  27. } else {
  28. this.inbound = new Inbound();
  29. }
  30. if (dbInbound) {
  31. this.dbInbound = new DBInbound(dbInbound);
  32. } else {
  33. this.dbInbound = new DBInbound();
  34. }
  35. this.confirm = confirm;
  36. this.visible = true;
  37. this.isEdit = isEdit;
  38. },
  39. close() {
  40. inModal.visible = false;
  41. inModal.loading(false);
  42. },
  43. loading(loading=true) {
  44. inModal.confirmLoading = loading;
  45. },
  46. };
  47. new Vue({
  48. delimiters: ['[[', ']]'],
  49. el: '#inbound-modal',
  50. data: {
  51. inModal: inModal,
  52. delayedStart: false,
  53. get inbound() {
  54. return inModal.inbound;
  55. },
  56. get dbInbound() {
  57. return inModal.dbInbound;
  58. },
  59. get isEdit() {
  60. return inModal.isEdit;
  61. },
  62. get client() {
  63. return inModal.inbound.clients[0];
  64. },
  65. get datepicker() {
  66. return app.datepicker;
  67. },
  68. get delayedExpireDays() {
  69. return this.client && this.client.expiryTime < 0 ? this.client.expiryTime / -86400000 : 0;
  70. },
  71. set delayedExpireDays(days) {
  72. this.client.expiryTime = -86400000 * days;
  73. },
  74. get externalProxy() {
  75. return this.inbound.stream.externalProxy.length > 0;
  76. },
  77. set externalProxy(value) {
  78. if (value) {
  79. inModal.inbound.stream.externalProxy = [{
  80. forceTls: "same",
  81. dest: window.location.hostname,
  82. port: inModal.inbound.port,
  83. remark: ""
  84. }];
  85. } else {
  86. inModal.inbound.stream.externalProxy = [];
  87. }
  88. }
  89. },
  90. methods: {
  91. streamNetworkChange() {
  92. if (!inModal.inbound.canEnableTls()) {
  93. this.inModal.inbound.stream.security = 'none';
  94. }
  95. if (!inModal.inbound.canEnableReality()) {
  96. this.inModal.inbound.reality = false;
  97. }
  98. if (this.inModal.inbound.protocol == Protocols.VLESS && !inModal.inbound.canEnableTlsFlow()) {
  99. this.inModal.inbound.settings.vlesses.forEach(client => {
  100. client.flow = "";
  101. });
  102. }
  103. if ((this.inModal.inbound.protocol == Protocols.VLESS || this.inModal.inbound.protocol == Protocols.TROJAN) && !inModal.inbound.xtls) {
  104. this.inModal.inbound.settings.vlesses.forEach(client => {
  105. client.flow = "";
  106. });
  107. }
  108. },
  109. SSMethodChange() {
  110. if (this.inModal.inbound.isSSMultiUser) {
  111. if (this.inModal.inbound.settings.shadowsockses.length ==0){
  112. this.inModal.inbound.settings.shadowsockses = [new Inbound.ShadowsocksSettings.Shadowsocks()];
  113. }
  114. if (!this.inModal.inbound.isSS2022) {
  115. this.inModal.inbound.settings.shadowsockses.forEach(client => {
  116. client.method = this.inModal.inbound.settings.method;
  117. })
  118. } else {
  119. this.inModal.inbound.settings.shadowsockses.forEach(client => {
  120. client.method = "";
  121. })
  122. }
  123. } else {
  124. if (this.inModal.inbound.settings.shadowsockses.length > 0){
  125. this.inModal.inbound.settings.shadowsockses = [];
  126. }
  127. }
  128. },
  129. setDefaultCertData(index) {
  130. inModal.inbound.stream.tls.certs[index].certFile = app.defaultCert;
  131. inModal.inbound.stream.tls.certs[index].keyFile = app.defaultKey;
  132. },
  133. setDefaultCertXtls(index) {
  134. inModal.inbound.stream.xtls.certs[index].certFile = app.defaultCert;
  135. inModal.inbound.stream.xtls.certs[index].keyFile = app.defaultKey;
  136. },
  137. async getNewX25519Cert() {
  138. inModal.loading(true);
  139. const msg = await HttpUtil.post('/server/getNewX25519Cert');
  140. inModal.loading(false);
  141. if (!msg.success) {
  142. return;
  143. }
  144. inModal.inbound.stream.reality.privateKey = msg.obj.privateKey;
  145. inModal.inbound.stream.reality.settings.publicKey = msg.obj.publicKey;
  146. }
  147. },
  148. });
  149. </script>
  150. {{end}}