inbound_modal.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. isGroup: false,
  17. confirm: null,
  18. inbound: new Inbound(),
  19. dbInbound: new DBInbound(),
  20. ok() {
  21. ObjectUtil.execute(inModal.confirm, inModal.inbound, inModal.dbInbound);
  22. },
  23. show({ title = '', okText = '{{ i18n "sure" }}', inbound = null, dbInbound = null, confirm = (inbound, dbInbound) => {}, isEdit = false }) {
  24. this.title = title;
  25. this.okText = okText;
  26. if (inbound) {
  27. this.inbound = Inbound.fromJson(inbound.toJson());
  28. } else {
  29. this.inbound = new Inbound();
  30. }
  31. if (dbInbound) {
  32. this.dbInbound = new DBInbound(dbInbound);
  33. } else {
  34. this.dbInbound = new DBInbound();
  35. }
  36. this.confirm = confirm;
  37. this.visible = true;
  38. this.isEdit = isEdit;
  39. },
  40. close() {
  41. inModal.visible = false;
  42. inModal.loading(false);
  43. },
  44. loading(loading=true) {
  45. inModal.confirmLoading = loading;
  46. },
  47. };
  48. new Vue({
  49. delimiters: ['[[', ']]'],
  50. el: '#inbound-modal',
  51. data: {
  52. inModal: inModal,
  53. delayedStart: false,
  54. get inbound() {
  55. return inModal.inbound;
  56. },
  57. get dbInbound() {
  58. return inModal.dbInbound;
  59. },
  60. get isEdit() {
  61. return inModal.isEdit;
  62. },
  63. get isGroup() {
  64. return inModal.isGroup;
  65. },
  66. get client() {
  67. return inModal.inbound.clients[0];
  68. },
  69. get datepicker() {
  70. return app.datepicker;
  71. },
  72. get delayedExpireDays() {
  73. return this.client && this.client.expiryTime < 0 ? this.client.expiryTime / -86400000 : 0;
  74. },
  75. set delayedExpireDays(days) {
  76. this.client.expiryTime = -86400000 * days;
  77. },
  78. get externalProxy() {
  79. return this.inbound.stream.externalProxy.length > 0;
  80. },
  81. set externalProxy(value) {
  82. if (value) {
  83. inModal.inbound.stream.externalProxy = [{
  84. forceTls: "same",
  85. dest: window.location.hostname,
  86. port: inModal.inbound.port,
  87. remark: ""
  88. }];
  89. } else {
  90. inModal.inbound.stream.externalProxy = [];
  91. }
  92. }
  93. },
  94. methods: {
  95. streamNetworkChange() {
  96. if (!inModal.inbound.canEnableTls()) {
  97. this.inModal.inbound.stream.security = 'none';
  98. }
  99. if (!inModal.inbound.canEnableReality()) {
  100. this.inModal.inbound.reality = false;
  101. }
  102. if (this.inModal.inbound.protocol == Protocols.VLESS && !inModal.inbound.canEnableTlsFlow()) {
  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. async getNewX25519Cert() {
  133. inModal.loading(true);
  134. const msg = await HttpUtil.post('/server/getNewX25519Cert');
  135. inModal.loading(false);
  136. if (!msg.success) {
  137. return;
  138. }
  139. inModal.inbound.stream.reality.privateKey = msg.obj.privateKey;
  140. inModal.inbound.stream.reality.settings.publicKey = msg.obj.publicKey;
  141. }
  142. },
  143. });
  144. </script>
  145. {{end}}