From 7313b321145df60456f471726ca905090942f0e6 Mon Sep 17 00:00:00 2001 From: kenzok8 Date: Mon, 3 Feb 2025 16:25:52 +0800 Subject: [PATCH] update 2025-02-03 16:25:52 --- .../resources/view/fchomo/global.js | 93 ++++++++++--------- mihomo/files/mihomo.init | 2 +- 2 files changed, 52 insertions(+), 43 deletions(-) diff --git a/luci-app-fchomo/htdocs/luci-static/resources/view/fchomo/global.js b/luci-app-fchomo/htdocs/luci-static/resources/view/fchomo/global.js index 340dbb342..bae18af3b 100644 --- a/luci-app-fchomo/htdocs/luci-static/resources/view/fchomo/global.js +++ b/luci-app-fchomo/htdocs/luci-static/resources/view/fchomo/global.js @@ -106,43 +106,6 @@ function updateResVersion(El, version) { return El; } -function renderNATBehaviorTest(El) { - let resEl = E('div', { 'class': 'control-group' }, [ - E('select', { - 'id': '_status_nattest_l4proto', - 'class': 'cbi-input-select', - 'style': 'width: 5em' - }, [ - E('option', { 'value': 'udp' }, 'UDP'), - E('option', { 'value': 'tcp' }, 'TCP') - ]), - E('button', { - 'class': 'cbi-button cbi-button-apply', - 'click': ui.createHandlerFn(this, function() { - const stun = this.formvalue(this.section.section); - const l4proto = document.getElementById('_status_nattest_l4proto').value; - const l4proto_idx = document.getElementById('_status_nattest_l4proto').selectedIndex; - - return fs.exec_direct('/etc/fchomo/scripts/natcheck.sh', [stun, l4proto, getRandom(32768, 61000)]).then((stdout) => { - this.description = '
' + _('Expand/Collapse result') + '' + stdout + '
'; - - return this.map.reset().then((res) => { - document.getElementById('_status_nattest_l4proto').selectedIndex = l4proto_idx; - }); - }); - }) - }, [ _('Check') ]) - ]); - - let newEl = E('div', { style: 'font-weight: bold; align-items: center; display: flex' }, []); - if (El) { - newEl.appendChild(E([El, resEl])); - } else - newEl.appendChild(resEl); - - return newEl; -} - return view.extend({ load() { return Promise.all([ @@ -247,7 +210,7 @@ return view.extend({ } so = ss.option(form.Value, '_nattest', _('Check routerself NAT Behavior')); - so.default = hm.stunserver[0][0]; + so.default = `udp://${hm.stunserver[0][0]}`; hm.stunserver.forEach((res) => { so.value.apply(so, res); }) @@ -257,14 +220,60 @@ return view.extend({ .format('https://github.com/muink/openwrt-stuntman'); so.readonly = true; } else { - so.renderWidget = function(/* ... */) { - let El = form.Value.prototype.renderWidget.apply(this, arguments); + so.renderWidget = function(section_id, option_index, cfgvalue) { + const cval = new URL(cfgvalue || this.default); + //console.info(cval.toString()); + let El = form.Value.prototype.renderWidget.call(this, section_id, option_index, cval.host); - return renderNATBehaviorTest.call(this, El); + let resEl = E('div', { 'class': 'control-group' }, [ + E('select', { + 'id': '_status_nattest_l4proto', + 'class': 'cbi-input-select', + 'style': 'width: 5em' + }, [ + ...[ + ['udp', 'UDP'], // default + ['tcp', 'TCP'] + ].map(res => E('option', { + value: res[0], + selected: (cval.protocol === `${res[0]}:`) ? "" : null + }, res[1])) + ]), + E('button', { + 'class': 'cbi-button cbi-button-apply', + 'click': ui.createHandlerFn(this, function() { + const stun = this.formvalue(this.section.section); + const l4proto = document.getElementById('_status_nattest_l4proto').value; + + return fs.exec_direct('/etc/fchomo/scripts/natcheck.sh', [stun, l4proto, getRandom(32768, 61000)]).then((stdout) => { + this.description = '
' + _('Expand/Collapse result') + '' + stdout + '
'; + + return this.map.reset().then((res) => { + }); + }); + }) + }, [ _('Check') ]) + ]); + ui.addValidator(resEl.querySelector('#_status_nattest_l4proto'), 'string', false, (v) => { + const section_id = this.section.section; + const stun = this.formvalue(section_id); + + this.onchange.call(this, {}, section_id, stun); + return true; + }, 'change'); + + let newEl = E('div', { style: 'font-weight: bold; align-items: center; display: flex' }, []); + if (El) { + newEl.appendChild(E([El, resEl])); + } else + newEl.appendChild(resEl); + + return newEl; } } so.onchange = function(ev, section_id, value) { - this.default = value; + const l4proto = document.getElementById('_status_nattest_l4proto').value; + this.default = `${l4proto}://${value}`; } so.write = function() {}; so.remove = function() {}; diff --git a/mihomo/files/mihomo.init b/mihomo/files/mihomo.init index 12f06fe95..80ecc213b 100644 --- a/mihomo/files/mihomo.init +++ b/mihomo/files/mihomo.init @@ -617,7 +617,7 @@ mixin_authentications() { } mixin_tun_dns_hijacks() { - dns_hijack="$1" yq -M -i '.tun.dns_hijack += [strenv(dns_hijack)]' "$RUN_PROFILE_PATH" + dns_hijack="$1" yq -M -i '.tun.dns-hijack += [strenv(dns_hijack)]' "$RUN_PROFILE_PATH" } mixin_fake_ip_filters() {