2024-10-21 19:14:10 +00:00
|
|
|
DISABLE_IPV6=0
|
2024-10-21 15:29:51 +00:00
|
|
|
TP_PORT=900
|
|
|
|
TP_USER=daemon
|
|
|
|
|
2024-10-21 19:18:30 +00:00
|
|
|
EXCLUDE4="10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 169.254.0.0/16 127.0.0.0/8"
|
|
|
|
EXCLUDE6="fc00::/7 fe80::/10 ::1"
|
2024-10-21 19:14:10 +00:00
|
|
|
IPTS="iptables ip6tables"
|
|
|
|
[ "$DISABLE_IPV6" = 1 ] && IPTS=iptables
|
2024-10-21 17:50:28 +00:00
|
|
|
|
2024-10-21 15:29:51 +00:00
|
|
|
exists()
|
|
|
|
{
|
|
|
|
which "$1" >/dev/null 2>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
ipt()
|
|
|
|
{
|
2024-10-21 17:50:28 +00:00
|
|
|
$IPTABLES -C "$@" >/dev/null 2>/dev/null || $IPTABLES -I "$@"
|
2024-10-21 15:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
redirect_port()
|
|
|
|
{
|
2024-10-21 17:50:28 +00:00
|
|
|
ipt tpws -t nat -p tcp --dport $1 -j REDIRECT --to-port $2
|
2024-10-21 15:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
redirect()
|
|
|
|
{
|
|
|
|
redirect_port 80 $TP_PORT
|
|
|
|
redirect_port 443 $TP_PORT
|
|
|
|
}
|
|
|
|
|
2024-10-21 19:14:10 +00:00
|
|
|
for IPTABLES in $IPTS; do
|
2024-10-21 17:50:28 +00:00
|
|
|
$IPTABLES -t nat -N tpws 2>/dev/null
|
|
|
|
$IPTABLES -t nat -F tpws
|
2024-10-21 17:54:22 +00:00
|
|
|
redirect
|
2024-10-21 15:29:51 +00:00
|
|
|
done
|
2024-10-21 17:50:28 +00:00
|
|
|
|
2024-10-21 19:14:10 +00:00
|
|
|
for net in $EXCLUDE4; do
|
2024-10-21 17:50:28 +00:00
|
|
|
iptables -t nat -I tpws -d $net -j RETURN
|
|
|
|
done
|
2024-10-21 19:14:10 +00:00
|
|
|
[ "$DISABLE_IPV6" = 1 ] || {
|
|
|
|
for net in $EXCLUDE6; do
|
|
|
|
ip6tables -t nat -I tpws -d $net -j RETURN
|
|
|
|
done
|
|
|
|
}
|
2024-10-21 17:50:28 +00:00
|
|
|
|
2024-10-21 19:14:10 +00:00
|
|
|
for IPTABLES in $IPTS; do
|
2024-10-21 17:50:28 +00:00
|
|
|
ipt PREROUTING -t nat -j tpws
|
|
|
|
ipt OUTPUT -t nat -m owner ! --uid-owner $TP_USER -j tpws
|
|
|
|
done
|