inbound_modal.html 5.9 KB

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