inbound_modal.html 5.7 KB

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