update 2024-12-29 00:14:07

This commit is contained in:
actions-user 2024-12-29 00:14:07 +08:00
parent 0201130bd2
commit 926dd737c6
8 changed files with 1059 additions and 888 deletions

View File

@ -12,7 +12,7 @@ LUCI_DEPENDS:= \
+firewall4 \
+kmod-inet-diag \
+kmod-nft-tproxy \
+yq +wget-ssl \
+yq +wget-ssl +coreutils-timeout \
# +ip-full +kmod-tun +dnsmasq-full \
PKG_NAME:=luci-app-fchomo

View File

@ -208,6 +208,15 @@ return baseclass.extend({
'2022-blake3-chacha20-poly1305': 32
},
stunserver: [
['stun.fitauto.ru:3478'],
['stun.hot-chilli.net:3478'],
['stun.pure-ip.com:3478'],
['stun.voipgate.com:3478'],
['stun.voipia.net:3478'],
['stunserver2024.stunprotocol.org:3478']
],
tls_client_fingerprints: [
['chrome'],
['firefox'],

View File

@ -1,5 +1,6 @@
'use strict';
'require form';
'require fs';
'require network';
'require poll';
'require rpc';
@ -25,6 +26,16 @@ const callCrondSet = rpc.declare({
expect: { '': {} }
});
function getRandom(min, max) {
const floatRandom = Math.random()
const difference = max - min
// A random number between 0 and the difference
const random = Math.round(difference * floatRandom)
return random + min
}
function handleResUpdate(type, repo) {
const callResUpdate = rpc.declare({
object: 'luci.fchomo',
@ -95,6 +106,43 @@ function updateResVersion(El, version) {
return El;
}
function renderNATBehaviorTest(El) {
var 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() {
var stun = this.formvalue(this.section.section);
var l4proto = document.getElementById('_status_nattest_l4proto').value;
var 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 = '<details><summary>' + _('Expand/Collapse result') + '</summary>' + stdout + '</details>';
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: function() {
return Promise.all([
@ -198,6 +246,29 @@ return view.extend({
]);
}
so = ss.option(form.Value, '_nattest', _('Check routerself NAT Behavior'));
so.default = hm.stunserver[0][0];
hm.stunserver.forEach((res) => {
so.value.apply(so, res);
})
so.rmempty = false;
if (!features.hm_has_stunclient) {
so.description = _('To check NAT Behavior you need to install <a href="%s"><b>stuntman-client</b></a> first')
.format('https://github.com/muink/openwrt-stuntman');
so.readonly = true;
} else {
so.renderWidget = function(/* ... */) {
var El = form.Value.prototype.renderWidget.apply(this, arguments);
return renderNATBehaviorTest.call(this, El);
}
}
so.onchange = function(ev, section_id, value) {
this.default = value;
}
so.write = function() {};
so.remove = function() {};
/* Resources management */
o = s.taboption('status', form.SectionValue, '_config', form.NamedSection, 'resources', 'fchomo', _('Resources management'));
ss = o.subsection;
@ -248,7 +319,7 @@ return view.extend({
so.renderWidget = function(/* ... */) {
var El = form.ListValue.prototype.renderWidget.apply(this, arguments);
El.className = 'control-group';
El.classList.add('control-group');
El.firstChild.style.width = '10em';
return renderResVersion.call(this, El, 'dashboard', this.default);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,44 @@
#!/bin/sh
#
# Depends: coreutils-timeout
#
# Author: muink
# Ref: https://github.com/muink/luci-app-natmapt/blob/master/root/usr/libexec/natmap/natcheck.sh
#
# Args: <stun server:port> <udp/tcp> <localport>
[ "$#" -ge 3 ] || exit 1
stun="$1" && shift
l4proto="$1" && shift
port="$1" && shift
echo "$stun" | grep -qE "^[A-Za-z0-9.-]+:[0-9]+$" || exit 1
echo "$l4proto" | grep -qE "^(udp|tcp)$" || exit 1
echo "$port" | grep -qE "^[0-9]*$" || exit 1
PROG="$(command -v stunclient)"
result="$(timeout 30 $PROG --protocol $l4proto --mode full ${port:+--localport $port} ${stun%:*} ${stun#*:} 2>/dev/null)"
render() {
echo "$1" | sed -E "\
s,\b((S|s)uccess)\b,<font color=\"green\">\1</font>,g;\
s,\b((F|f)ail)\b,<font color=\"#ff331f\">\1</font>,g;\
s|(Nat behavior:\s*)\b(Unknown Behavior)\b|\1<font color=\"#808080\">\2</font>|g;\
s|(Nat behavior:\s*)\b(Direct Mapping)\b|\1<font color=\"#1e96fc\">\2</font>|g;\
s|(Nat behavior:\s*)\b(Endpoint Independent Mapping)\b|\1<font color=\"#7cfc00\">\2</font>|g;\
s|(Nat behavior:\s*)\b(Address Dependent Mapping)\b|\1<font color=\"#ffc100\">\2</font>|g;\
s|(Nat behavior:\s*)\b(Address and Port Dependent Mapping)\b|\1<font color=\"#ff8200\">\2</font>|g;\
s|(Nat behavior:\s*)\b(Unknown NAT Behavior)\b|\1<font color=\"#808080\">\2</font>|g;\
s|(Nat filtering:\s*)\b(Unknown Filtering)\b|\1<font color=\"#808080\">\2</font>|g;\
s|(Nat filtering:\s*)\b(Direct Mapping (Filtering))\b|\1<font color=\"#1e96fc\">\2</font>|g;\
s|(Nat filtering:\s*)\b(Endpoint Independent Filtering)\b|\1<font color=\"#7cfc00\">\2</font>|g;\
s|(Nat filtering:\s*)\b(Address Dependent Filtering)\b|\1<font color=\"#ffc100\">\2</font>|g;\
s|(Nat filtering:\s*)\b(Address and Port Dependent Filtering)\b|\1<font color=\"#ff8200\">\2</font>|g;\
s|(Nat filtering:\s*)\b(Unknown NAT Filtering)\b|\1<font color=\"#808080\">\2</font>|g;\
s|(:\s*)(.*)$|\1<b>\2</b><br>|g"
}
cat <<- EOF
$(echo ${l4proto} | tr 'a-z' 'A-Z') TEST:<br>
$(render "${result:-<font color=\"red\">Test timeout</font>}")
EOF

View File

@ -3,6 +3,7 @@
"description": "Grant access to fchomo configuration",
"read": {
"file": {
"/etc/fchomo/scripts/natcheck.sh": [ "exec" ],
"/etc/init.d/fchomo reload *": [ "exec" ],
"/var/run/fchomo/fchomo.log": [ "read" ],
"/var/run/fchomo/mihomo-c.log": [ "read" ],

View File

@ -94,6 +94,7 @@ const methods = {
features.hm_has_dnsmasq_full = system(`[ -n "$(${use_apk ? 'apk list -qI' : 'opkg list-installed'} dnsmasq-full)" ]`) == 0 || null;
features.hm_has_ip_full = access('/usr/libexec/ip-full');
features.hm_has_stunclient = access('/usr/bin/stunclient');
features.hm_has_tcp_brutal = hasKernelModule('brutal.ko');
features.hm_has_tproxy = hasKernelModule('nft_tproxy.ko') || access('/etc/modules.d/nft-tproxy');
features.hm_has_tun = hasKernelModule('tun.ko') || access('/etc/modules.d/30-tun');