inbound_modal.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. {{define "modals/inboundModal"}}
  2. <a-modal id="inbound-modal" v-model="inModal.visible" :title="inModal.title" :dialog-style="{ top: '20px' }"
  3. @ok="inModal.ok" :confirm-loading="inModal.confirmLoading" :closable="true" :mask-closable="false"
  4. :class="themeSwitcher.currentTheme" :ok-text="inModal.okText" cancel-text='{{ i18n "close" }}'>
  5. {{template "form/inbound"}}
  6. </a-modal>
  7. <script>
  8. // Make inModal globally available to ensure it works with any base path
  9. const inModal = window.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. // Always ensure testseed is initialized for VLESS protocol (even if vision flow is not set yet)
  30. // This ensures Vue reactivity works properly
  31. if (this.inbound.protocol === Protocols.VLESS && this.inbound.settings) {
  32. if (!this.inbound.settings.testseed || !Array.isArray(this.inbound.settings.testseed) || this.inbound.settings.testseed.length < 4) {
  33. // Create a new array to ensure Vue reactivity
  34. this.inbound.settings.testseed = [900, 500, 900, 256].slice();
  35. }
  36. }
  37. if (dbInbound) {
  38. this.dbInbound = new DBInbound(dbInbound);
  39. } else {
  40. this.dbInbound = new DBInbound();
  41. }
  42. this.confirm = confirm;
  43. this.visible = true;
  44. this.isEdit = isEdit;
  45. },
  46. close() {
  47. inModal.visible = false;
  48. inModal.loading(false);
  49. },
  50. loading(loading = true) {
  51. inModal.confirmLoading = loading;
  52. },
  53. // Vision Seed methods - always available regardless of Vue context
  54. updateTestseed(index, value) {
  55. // Use inModal.inbound explicitly to ensure correct context
  56. if (!inModal.inbound || !inModal.inbound.settings) return;
  57. // Ensure testseed is initialized
  58. if (!inModal.inbound.settings.testseed || !Array.isArray(inModal.inbound.settings.testseed)) {
  59. inModal.inbound.settings.testseed = [900, 500, 900, 256];
  60. }
  61. // Ensure array has enough elements
  62. while (inModal.inbound.settings.testseed.length <= index) {
  63. inModal.inbound.settings.testseed.push(0);
  64. }
  65. // Update value
  66. inModal.inbound.settings.testseed[index] = value;
  67. },
  68. setRandomTestseed() {
  69. // Use inModal.inbound explicitly to ensure correct context
  70. if (!inModal.inbound || !inModal.inbound.settings) return;
  71. // Ensure testseed is initialized
  72. if (!inModal.inbound.settings.testseed || !Array.isArray(inModal.inbound.settings.testseed) || inModal.inbound.settings.testseed.length < 4) {
  73. inModal.inbound.settings.testseed = [900, 500, 900, 256].slice();
  74. }
  75. // Create new array with random values
  76. inModal.inbound.settings.testseed = [Math.floor(Math.random()*1000), Math.floor(Math.random()*1000), Math.floor(Math.random()*1000), Math.floor(Math.random()*1000)];
  77. },
  78. resetTestseed() {
  79. // Use inModal.inbound explicitly to ensure correct context
  80. if (!inModal.inbound || !inModal.inbound.settings) return;
  81. // Reset testseed to default values
  82. inModal.inbound.settings.testseed = [900, 500, 900, 256].slice();
  83. }
  84. };
  85. // Store Vue instance globally to ensure methods are always accessible
  86. let inboundModalVueInstance = null;
  87. inboundModalVueInstance = new Vue({
  88. delimiters: ['[[', ']]'],
  89. el: '#inbound-modal',
  90. data: {
  91. inModal: inModal,
  92. delayedStart: false,
  93. get inbound() {
  94. return inModal.inbound;
  95. },
  96. get dbInbound() {
  97. return inModal.dbInbound;
  98. },
  99. get isEdit() {
  100. return inModal.isEdit;
  101. },
  102. get client() {
  103. return inModal.inbound && inModal.inbound.clients && inModal.inbound.clients.length > 0 ? inModal.inbound.clients[0] : null;
  104. },
  105. get datepicker() {
  106. return app.datepicker;
  107. },
  108. get delayedExpireDays() {
  109. return this.client && this.client.expiryTime < 0 ? this.client.expiryTime / -86400000 : 0;
  110. },
  111. set delayedExpireDays(days) {
  112. this.client.expiryTime = -86400000 * days;
  113. },
  114. get externalProxy() {
  115. return this.inbound.stream.externalProxy.length > 0;
  116. },
  117. set externalProxy(value) {
  118. if (value) {
  119. inModal.inbound.stream.externalProxy = [{
  120. forceTls: "same",
  121. dest: window.location.hostname,
  122. port: inModal.inbound.port,
  123. remark: ""
  124. }];
  125. } else {
  126. inModal.inbound.stream.externalProxy = [];
  127. }
  128. }
  129. },
  130. watch: {
  131. 'inModal.inbound.stream.security'(newVal, oldVal) {
  132. // Clear flow when security changes from reality/tls to none
  133. if (inModal.inbound.protocol == Protocols.VLESS && !inModal.inbound.canEnableTlsFlow()) {
  134. inModal.inbound.settings.vlesses.forEach(client => {
  135. client.flow = "";
  136. });
  137. }
  138. },
  139. // Ensure testseed is always initialized when vision flow is enabled
  140. 'inModal.inbound.settings.vlesses': {
  141. handler() {
  142. if (inModal.inbound.protocol === Protocols.VLESS && inModal.inbound.settings && inModal.inbound.settings.vlesses) {
  143. const hasVisionFlow = inModal.inbound.settings.vlesses.some(c => c.flow === 'xtls-rprx-vision' || c.flow === 'xtls-rprx-vision-udp443');
  144. if (hasVisionFlow && (!inModal.inbound.settings.testseed || !Array.isArray(inModal.inbound.settings.testseed) || inModal.inbound.settings.testseed.length < 4)) {
  145. inModal.inbound.settings.testseed = [900, 500, 900, 256];
  146. }
  147. }
  148. },
  149. deep: true
  150. }
  151. },
  152. methods: {
  153. streamNetworkChange() {
  154. if (!inModal.inbound.canEnableTls()) {
  155. this.inModal.inbound.stream.security = 'none';
  156. }
  157. if (!inModal.inbound.canEnableReality()) {
  158. this.inModal.inbound.reality = false;
  159. }
  160. if (this.inModal.inbound.protocol == Protocols.VLESS && !inModal.inbound.canEnableTlsFlow()) {
  161. this.inModal.inbound.settings.vlesses.forEach(client => {
  162. client.flow = "";
  163. });
  164. }
  165. },
  166. SSMethodChange() {
  167. this.inModal.inbound.settings.password = RandomUtil.randomShadowsocksPassword(this.inModal.inbound.settings.method)
  168. if (this.inModal.inbound.isSSMultiUser) {
  169. if (this.inModal.inbound.settings.shadowsockses.length == 0) {
  170. this.inModal.inbound.settings.shadowsockses = [new Inbound.ShadowsocksSettings.Shadowsocks()];
  171. }
  172. if (!this.inModal.inbound.isSS2022) {
  173. this.inModal.inbound.settings.shadowsockses.forEach(client => {
  174. client.method = this.inModal.inbound.settings.method;
  175. })
  176. } else {
  177. this.inModal.inbound.settings.shadowsockses.forEach(client => {
  178. client.method = "";
  179. })
  180. }
  181. this.inModal.inbound.settings.shadowsockses.forEach(client => {
  182. client.password = RandomUtil.randomShadowsocksPassword(this.inModal.inbound.settings.method)
  183. })
  184. } else {
  185. if (this.inModal.inbound.settings.shadowsockses.length > 0) {
  186. this.inModal.inbound.settings.shadowsockses = [];
  187. }
  188. }
  189. },
  190. setDefaultCertData(index) {
  191. inModal.inbound.stream.tls.certs[index].certFile = app.defaultCert;
  192. inModal.inbound.stream.tls.certs[index].keyFile = app.defaultKey;
  193. },
  194. async getNewX25519Cert() {
  195. inModal.loading(true);
  196. const msg = await HttpUtil.get('/panel/api/server/getNewX25519Cert');
  197. inModal.loading(false);
  198. if (!msg.success) {
  199. return;
  200. }
  201. inModal.inbound.stream.reality.privateKey = msg.obj.privateKey;
  202. inModal.inbound.stream.reality.settings.publicKey = msg.obj.publicKey;
  203. },
  204. clearX25519Cert() {
  205. this.inbound.stream.reality.privateKey = '';
  206. this.inbound.stream.reality.settings.publicKey = '';
  207. },
  208. async getNewmldsa65() {
  209. inModal.loading(true);
  210. const msg = await HttpUtil.get('/panel/api/server/getNewmldsa65');
  211. inModal.loading(false);
  212. if (!msg.success) {
  213. return;
  214. }
  215. inModal.inbound.stream.reality.mldsa65Seed = msg.obj.seed;
  216. inModal.inbound.stream.reality.settings.mldsa65Verify = msg.obj.verify;
  217. },
  218. clearMldsa65() {
  219. this.inbound.stream.reality.mldsa65Seed = '';
  220. this.inbound.stream.reality.settings.mldsa65Verify = '';
  221. },
  222. randomizeRealityTarget() {
  223. if (typeof getRandomRealityTarget !== 'undefined') {
  224. const randomTarget = getRandomRealityTarget();
  225. this.inbound.stream.reality.target = randomTarget.target;
  226. this.inbound.stream.reality.serverNames = randomTarget.sni;
  227. }
  228. },
  229. async getNewEchCert() {
  230. inModal.loading(true);
  231. const msg = await HttpUtil.post('/panel/api/server/getNewEchCert', { sni: inModal.inbound.stream.tls.sni });
  232. inModal.loading(false);
  233. if (!msg.success) {
  234. return;
  235. }
  236. inModal.inbound.stream.tls.echServerKeys = msg.obj.echServerKeys;
  237. inModal.inbound.stream.tls.settings.echConfigList = msg.obj.echConfigList;
  238. },
  239. clearEchCert() {
  240. this.inbound.stream.tls.echServerKeys = '';
  241. this.inbound.stream.tls.settings.echConfigList = '';
  242. },
  243. async getNewVlessEnc() {
  244. inModal.loading(true);
  245. const msg = await HttpUtil.get('/panel/api/server/getNewVlessEnc');
  246. inModal.loading(false);
  247. if (!msg.success) {
  248. return;
  249. }
  250. const auths = msg.obj.auths || [];
  251. const selected = inModal.inbound.settings.selectedAuth;
  252. const block = auths.find(a => a.label === selected);
  253. if (!block) {
  254. console.error("No auth block for", selected);
  255. return;
  256. }
  257. inModal.inbound.settings.decryption = block.decryption;
  258. inModal.inbound.settings.encryption = block.encryption;
  259. },
  260. clearVlessEnc() {
  261. this.inbound.settings.decryption = 'none';
  262. this.inbound.settings.encryption = 'none';
  263. this.inbound.settings.selectedAuth = undefined;
  264. },
  265. // Vision Seed methods - must be in Vue methods for proper binding
  266. updateTestseed(index, value) {
  267. // Ensure testseed is initialized
  268. if (!this.inbound.settings.testseed || !Array.isArray(this.inbound.settings.testseed)) {
  269. this.$set(this.inbound.settings, 'testseed', [900, 500, 900, 256]);
  270. }
  271. // Ensure array has enough elements
  272. while (this.inbound.settings.testseed.length <= index) {
  273. this.inbound.settings.testseed.push(0);
  274. }
  275. // Update value using Vue.set for reactivity
  276. this.$set(this.inbound.settings.testseed, index, value);
  277. },
  278. setRandomTestseed() {
  279. // Create new array with random values and use Vue.set for reactivity
  280. const newSeed = [Math.floor(Math.random()*1000), Math.floor(Math.random()*1000), Math.floor(Math.random()*1000), Math.floor(Math.random()*1000)];
  281. this.$set(this.inbound.settings, 'testseed', newSeed);
  282. },
  283. resetTestseed() {
  284. // Reset testseed to default values using Vue.set for reactivity
  285. this.$set(this.inbound.settings, 'testseed', [900, 500, 900, 256]);
  286. }
  287. },
  288. });
  289. </script>
  290. {{end}}