🌴 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

+80
View File
@@ -0,0 +1,80 @@
#
# Copyright (c) 2020 xiaoqingfeng (xiaoqingfengatgm@gmail.com)
# Feed site - https://github.com/xiaoqingfengATGH/feeds-xiaoqingfeng
# This is free software, licensed under the GNU General Public License v3.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=HomeRedirect
PKG_VERSION:=1.4
PKG_RELEASE:=1
PKG_DATE:=20210226
PKG_MAINTAINER:=xiaoqingfeng <xiaoqingfengatgm@gmail.com>
PKG_LICENSE:=GPL-3.0-or-later
PKG_LICENSE_FILES:=LICENSE
include $(INCLUDE_DIR)/package.mk
define Package/$(PKG_NAME)
SECTION:=net
CATEGORY:=Network
TITLE:=Port forwarding utility for HomeLede.
DEPENDS:=+bash +coreutils-nohup +socat
PKGARCH:=all
URL:=https://github.com/xiaoqingfengATGH/feeds-xiaoqingfeng
endef
define Package/$(PKG_NAME)/config
help
$(PKG_NAME)
Version: $(PKG_VERSION)-$(PKG_RELEASE)
Port forwarding utility for HomeLede. Support TCP/UDP ipv4 & ipv6.
endef
define Package/$(PKG_NAME)/description
Port forwarding utility for HomeLede. Support TCP/UDP ipv4 & ipv6.
endef
define Package/$(PKG_NAME)/conffiles
/etc/config/homeredirect
endef
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DIR) $(1)/etc/homeredirect
$(INSTALL_BIN) files/etc/init.d/homeredirect $(1)/etc/init.d
$(INSTALL_CONF) files/etc/config/homeredirect $(1)/etc/config
$(INSTALL_DATA) files/etc/homeredirect/firewall.include $(1)/etc/homeredirect/
$(INSTALL_DATA) files/etc/homeredirect/script.sh $(1)/etc/homeredirect/
endef
define Package/$(PKG_NAME)/postinst
#!/bin/sh
exit 0
endef
define Package/$(PKG_NAME)/prerm
#!/bin/sh
/etc/init.d/homeredirect stop
uci -q batch <<-EOF >/dev/null
delete ucitrack.@homeredirect[-1]
commit ucitrack
EOF
uci -q batch <<-EOF >/dev/null
delete firewall.homeredirect
EOF
exit 0
endef
define Build/Configure
endef
define Build/Prepare
endef
define Build/Compile
endef
$(eval $(call BuildPackage,$(PKG_NAME)))
@@ -0,0 +1,38 @@
config global
option enabled '1'
config redirect
option proto 'tcp4'
option src_ip '0.0.0.0'
option src_dport '60609'
option dest_ip '192.168.1.100'
option dest_port '3389'
option name 'TCP_REDIRECT_IPV4'
option enabled '0'
config redirect
option proto 'tcp6'
option src_ip '::'
option src_dport '60608'
option dest_ip 'fd5b:64cf:4ff4::1c4'
option dest_port '3389'
option name 'TCP_REDIRECT_IPV6'
option enabled '0'
config redirect
option proto 'udp4'
option src_ip '0.0.0.0'
option src_dport '64511'
option dest_ip '192.168.1.100'
option dest_port '500'
option name 'UDP_REDIRECT_IPV4'
option enabled '0'
config redirect
option proto 'udp6'
option src_ip '::'
option src_dport '64500'
option dest_ip 'fd5b:64cf:4ff4::1c4'
option dest_port '4500'
option name 'UDP_REDIRECT_IPV6'
option enabled '0'
@@ -0,0 +1 @@
bash /etc/homeredirect/script.sh
@@ -0,0 +1,45 @@
#!/bin/bash
del_rule() {
count=$(iptables -n -L INPUT 2>/dev/null | grep -c "HOME_REDIRECT")
if [ -n "$count" ]; then
until [ "$count" = 0 ]
do
rules=$(iptables -n -L INPUT --line-num 2>/dev/null | grep "HOME_REDIRECT" | awk '{print $1}')
for rule in $rules
do
iptables -D INPUT $rule 2>/dev/null
break
done
count=$(expr $count - 1)
done
fi
iptables -F HOME_REDIRECT 2>/dev/null
iptables -X HOME_REDIRECT 2>/dev/null
}
add_rule(){
iptables -N HOME_REDIRECT
iptables -I INPUT -j HOME_REDIRECT
maxRedirctCount=$(uci show homeredirect | grep @redirect | awk -F '[' '{print $2}' | awk -F ']' '{print $1}' | sort | tail -n 1)
for ((i=($maxRedirctCount);i>=0;i--));
do
enabled=$(uci get homeredirect.@redirect[$i].enabled)
if [ $enabled -eq 1 ]; then
protoAll=$(uci get homeredirect.@redirect[$i].proto)
proto=${protoAll:0:3}
port=$(uci get homeredirect.@redirect[$i].src_dport)
iptables -A HOME_REDIRECT -p $proto --dport $port -j ACCEPT
fi
done
}
del_rule
enable=$(uci get homeredirect.@global[0].enabled)
if [ $enable -eq 1 ]; then
add_rule
fi
+140
View File
@@ -0,0 +1,140 @@
#!/bin/sh /etc/rc.common
START=99
RUNLOG_DIR=/tmp/hr
PROCESSED_REDIRECT=0
log()
{
logger -t homeredirect $1
}
setupDefaultSrcIP() {
if [ -z $src_ip ];then
if [ "$1" = "ipv4" ]; then
src_ip="0.0.0.0"
else
src_ip="::"
fi
fi
}
setup() {
config_get enabled $1 enabled
id=$1
config_get proto $1 proto
config_get src_ip $1 src_ip
config_get src_dport $1 src_dport
config_get dest_ip $1 dest_ip
config_get dest_port $1 dest_port
config_get name $1 name
terminateRedirect $id
[ "$enabled" != "1" ] && return 0
PROCESSED_REDIRECT=1
if [ "$proto" = "tcp4" ]; then
src_addresstype="TCP4-LISTEN"
dest_addresstype="TCP4"
setupDefaultSrcIP "ipv4"
elif [ "$proto" = "tcp6" ]; then
src_addresstype="TCP6-LISTEN"
dest_addresstype="TCP6"
setupDefaultSrcIP "ipv6"
src_ip="[$src_ip]"
dest_ip="[$dest_ip]"
elif [ "$proto" = "udp4" ]; then
src_addresstype="UDP4-LISTEN"
dest_addresstype="UDP4"
setupDefaultSrcIP "ipv4"
elif [ "$proto" = "udp6" ]; then
src_addresstype="UDP6-LISTEN"
dest_addresstype="UDP6"
setupDefaultSrcIP "ipv6"
src_ip="[$src_ip]"
dest_ip="[$dest_ip]"
fi
#echo "nohup socat -lf $RUNLOG_DIR/$id.log $src_addresstype:$src_dport,bind=$src_ip,fork $dest_addresstype:$dest_ip:$dest_port > $RUNLOG_DIR/$id.log 2>&1 &"
nohup socat -lf $RUNLOG_DIR/$id.log $src_addresstype:$src_dport,bind=$src_ip,fork $dest_addresstype:$dest_ip:$dest_port > $RUNLOG_DIR/$id.log 2>&1 &
log "[HomeRedirect] Port redirect from $proto $src_ip:$src_dport==>$dest_addresstype:$dest_ip:$dest_port started."
}
# param $1 is port
showTcpPortState() {
local process=$(netstat -ltnp | awk -F ' ' '{if(NR>2) print $1"/"$4"/"$7}' | grep :$1)
if [ -n "$process" ]; then
echo $process
else
echo 'TCP Port $1 is Free.'
fi
}
# param $1 is port
showUdpPortState() {
local process=$(netstat -lunp | awk -F ' ' '{if(NR>2) print $1"/"$4"/"$6}'|grep :$1)
if [ -n "$process" ]; then
echo $process
else
echo 'UDP Port $1 is Free.'
fi
}
isRedirectRunning() {
local runningPID=$(ps | grep socat | grep $RUNLOG_DIR/$1 | sed '/grep/d' | awk -F ' ' '{print $1}')
if [ -n "$runningPID" ]; then
return 1
else
return 0
fi
}
# param $1 is redirect id
terminateRedirect() {
isRedirectRunning $1
[ "$?" = "1" ] && {
local runningPID=$(ps | grep socat | grep $RUNLOG_DIR/$1 | sed '/grep/d' | awk -F ' ' '{print $1}')
#echo "Going to kill process $runningPID"
kill $runningPID
}
}
terminateAll() {
local runningPIDs=$(ps | grep socat | grep $RUNLOG_DIR | sed '/grep/d' | awk -F ' ' '{print $1}')
[ -n "$runningPIDs" ] && {
kill $runningPIDs
log "Redirect process : $runningPIDs stopped."
}
}
start() {
local vt_enabled=$(uci -q get homeredirect.@global[0].enabled)
if [ "$vt_enabled" = 0 ]; then
terminateAll
fw3 reload
return 1
fi
rm -rf $RUNLOG_DIR
mkdir -p $RUNLOG_DIR
config_load homeredirect
PROCESSED_REDIRECT=0
config_foreach setup redirect
[ "$PROCESSED_REDIRECT" == "1" ] && {
fw3 reload
}
log 'HomeRedirect started.'
}
stop() {
terminateAll
fw3 reload
log 'HomeRedirect stopped.'
}