1
0

inbound_modal.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. },
  104. SSMethodChange() {
  105. if (this.inModal.inbound.isSSMultiUser) {
  106. if (this.inModal.inbound.settings.shadowsockses.length ==0){
  107. this.inModal.inbound.settings.shadowsockses = [new Inbound.ShadowsocksSettings.Shadowsocks()];
  108. }
  109. if (!this.inModal.inbound.isSS2022) {
  110. this.inModal.inbound.settings.shadowsockses.forEach(client => {
  111. client.method = this.inModal.inbound.settings.method;
  112. })
  113. } else {
  114. this.inModal.inbound.settings.shadowsockses.forEach(client => {
  115. client.method = "";
  116. })
  117. }
  118. } else {
  119. if (this.inModal.inbound.settings.shadowsockses.length > 0){
  120. this.inModal.inbound.settings.shadowsockses = [];
  121. }
  122. }
  123. },
  124. setDefaultCertData(index) {
  125. inModal.inbound.stream.tls.certs[index].certFile = app.defaultCert;
  126. inModal.inbound.stream.tls.certs[index].keyFile = app.defaultKey;
  127. },
  128. async getNewX25519Cert() {
  129. inModal.loading(true);
  130. const msg = await HttpUtil.post('/server/getNewX25519Cert');
  131. inModal.loading(false);
  132. if (!msg.success) {
  133. return;
  134. }
  135. inModal.inbound.stream.reality.privateKey = msg.obj.privateKey;
  136. inModal.inbound.stream.reality.settings.publicKey = msg.obj.publicKey;
  137. }
  138. },
  139. });
  140. </script>
  141. {{end}}