🌴 Sync 2026-03-05 23:51:42

This commit is contained in:
github-actions[bot] committed 2026-03-05 23:51:42 +08:00
1 parent 97c049ed0a
commit 0acff03804
14253 files changed
+3893239

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
config base
option tmp_path '/tmp/natter2'
option enable '0'
+111
View File
@@ -0,0 +1,111 @@
#!/bin/sh /etc/rc.common
USE_PROCD=1
START=98
script_path="/usr/share/natter2/natter.py"
start_service() {
local basic_list="enable tmp_path"
local instance_list="enable_instance id remark protocol enable_stun_server \
stun_server enable_keepalive_server keepalive_server \
interval enable_bonding bonding_interface bonding_port \
enable_forwarding forwarding_method target_address target_port \
enable_forwarding_retry enable_quit delay log_level enable_notify \
notify_path enable_upnp_service"
for i in $basic_list; do
local eval $i="$(uci_get_by_type base 0 $i)"
done ; unset i
if [ "$enable" == 1 ]; then
mkdir -p ${tmp_path}
mkdir -p /var/etc/natter2
for u in $(seq 0 $(($(uci show natter2 2> /dev/null | grep -E '@instances\[[0-9]\]+=instances' | wc -l) - 1)))
do
for i in $instance_list; do
local eval $i="$(uci_get_by_type instances $u $i)"
done ; unset i
[ "$enable_instance" != 1 ] && continue
script_command=""
[ "$protocol" == udp ] && script_command="$script_command -u"
if [ "$enable_stun_server" == 1 ]; then
for i in $stun_server; do
script_command="$script_command -s $i"
done ; unset i
fi
[ "$enable_keepalive_server" == 1 ] && script_command="$script_command -h $keepalive_server"
[ "$interval" ] && script_command="$script_command -k $interval"
[ "$enable_upnp_service" == 1 ] && script_command="$script_command -U"
if [ "$enable_bonding" == 1 ]; then
[ "$bonding_interface" ] && script_command="$script_command -i $bonding_interface"
[ "$bonding_port" ] && script_command="$script_command -b $bonding_port"
fi
if [ "$enable_forwarding" == 1 ]; then
[ "$forwarding_method" ] && script_command="$script_command -m $forwarding_method"
[ "$target_address" ] && script_command="$script_command -t $target_address"
[ "$target_port" ] && script_command="$script_command -p $target_port"
[ "$enable_forwarding_retry" == 1 ] && script_command="$script_command -r"
fi
[ "$enable_quit" == 1 ] && script_command="$script_command -q"
[ "$log_level" == "verbose" ] && script_command="$script_command -v"
if [ "$enable_notify" == 1 ]; then
echo "$notify_path" > /var/etc/natter2/${id}-notify
var_file=/var/etc/natter2/${id}-${u}-1
else
var_file=/var/etc/natter2/${id}-${u}-0
fi
cp -a /usr/share/luci-app-natter2/notify-base.sh $var_file
chmod +x $var_file
procd_open_instance "natter2_${id}"
procd_set_param command $(command -v python) "$script_path" $script_command -e $var_file
procd_set_param stdout 1
procd_set_param stderr 1
[ -n "$delay" ] && procd_set_param delay "$delay"
procd_set_param respawn
procd_close_instance
for i in $instance_list; do
unset $(echo $i)
done ; unset i
unset script_command
done ; unset u
else
stop_service
fi
}
stop_service() {
rm -rf "/var/etc/natter2" 2> /dev/null
for u in $(seq 0 $(($(uci show natter2 2> /dev/null | grep -E '@instances\[[0-9]\]+=instances' | wc -l) - 1)))
do
uci set natter2.@instances[$u].tmp_public_port=""
uci commit natter2
done
rm -f /tmp/natter2_nat_type
}
service_triggers() {
procd_add_reload_trigger "natter2"
}
uci_get_by_type() {
local ret=$(uci get natter2.@$1[$2].$3 2>/dev/null)
echo ${ret:=$4}
}
reload_service() {
restart
}
@@ -0,0 +1,18 @@
#!/bin/sh
[ ! -f "/usr/share/ucitrack/luci-app-natter2.json" ] && {
cat > /usr/share/ucitrack/luci-app-natter2.json << EEOF
{
"config": "natter2",
"init": "natter2"
}
EEOF
}
uci -q batch <<-EOF >/dev/null
delete ucitrack.@natter2[-1]
add ucitrack natter2
set ucitrack.@natter2[-1].init=natter2
commit ucitrack
EOF
exit 0
+19
View File
@@ -0,0 +1,19 @@
#!/bin/sh
log_path=$(uci get natter2.@base[0].tmp_path 2> /dev/null)
for i in $(ls -1 ${log_path} | grep natter2 | grep .log)
do
case $1 in
print)
echo -e "\n======> $i <======"
tail -n 30 ${log_path}/$i 2> /dev/null
echo -e "======> END of $i <======"
;;
del)
echo > ${log_path}/$i
;;
esac
done
exit 0
@@ -0,0 +1,39 @@
#!/bin/sh
script_file='/usr/share/natter2/natter-check/natter-check.py'
natter2_nat_type_file="/tmp/natter2_nat_type"
tmp_natter2_nat_type_file="/tmp/tmp_natter2_nat_type"
rm -f $natter2_nat_type_file
rm -f $tmp_natter2_nat_type_file
$(which python) $script_file | egrep 'Checking TCP|Checking UDP' > $tmp_natter2_nat_type_file
TCP=$(awk -F '[:]+' '/TCP/{print $2}' $tmp_natter2_nat_type_file | sed 's/\[//g;s/\]//g')
UDP=$(awk -F '[:]+' '/UDP/{print $2}' $tmp_natter2_nat_type_file | sed 's/\[//g;s/\]//g')
[ ! "$TCP" ] && TCP="未知"
[ ! "$UDP" ] && UDP="未知"
function NAT_Type() {
case $1 in
0)
echo "Public Network"
;;
1)
echo "Full Cone"
;;
2)
echo "Restricted Cone"
;;
3)
echo "Port Restricted Cone"
;;
4)
echo "Symmetric"
;;
esac
}
echo "TCP: NAT $TCP | $(NAT_Type $TCP)" > $natter2_nat_type_file
echo "UDP: NAT $UDP | $(NAT_Type $UDP)" >> $natter2_nat_type_file
rm -f $tmp_natter2_nat_type_file
@@ -0,0 +1,28 @@
#!/bin/sh
protocol="$1"; private_ip="$2"; private_port="$3"; public_ip="$4"; public_port="$5"
script_name=$(basename $0)
script_path=$(dirname $0)
instance_id=$(echo $script_name | cut -d '-' -f1)
instance_num=$(echo $script_name | cut -d '-' -f2)
instance_isnotify=$(echo $script_name | cut -d '-' -f3)
# echo script_path:$script_path
# echo script_name:$script_name
# echo instance_id:$instance_id
# echo instance_num:$instance_num
# echo instance_isnotify:$instance_isnotify
uci set natter2.@instances[$instance_num].tmp_public_port="$public_port"
uci commit natter2
if [ "$instance_isnotify" == 1 ]
then
notify_path=$(cat $script_path/${instance_id}-notify)
if [ -f "${notify_path}" ]
then
chmod +x ${notify_path}
${notify_path} $1 $2 $3 $4 $5
fi
fi
@@ -0,0 +1,12 @@
#!/bin/sh
# 参数序号 参数说明 参数格式
# 1 传输层协议 tcp, udp 二者之一
# 2 内部 IP 点分十进制 IPv4 地址
# 3 内部端口 1 - 65535 的整数
# 4 外部 IP 点分十进制 IPv4 地址
# 5 外部端口 1 - 65535 的整数
protocol="$1"; private_ip="$2"; private_port="$3"; public_ip="$4"; public_port="$5"
echo $1 $2 $3 $4 $5
@@ -0,0 +1,11 @@
{
"luci-app-natter2": {
"description": "Grant UCI access for luci-app-natter2",
"read": {
"uci": [ "natter2" ]
},
"write": {
"uci": [ "natter2" ]
}
}
}