mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-02 01:23:56 +08:00
🌈 Sync 2026-08-27 14:56:13
This commit is contained in:
1 parent
1b91eb3175
commit
3ebef8b234
25 files changed
+416
-168
No files matched your search
@@ -13,6 +13,12 @@ handle_section(){
|
||||
config_get iface "$s" iface
|
||||
config_get proxy "$s" proxy
|
||||
|
||||
case "$inet" in
|
||||
ipv4) family="ip"; IPT="iptables" ;;
|
||||
ipv6) family="ip6"; IPT="ip6tables" ;;
|
||||
*) family="ip ip6"; IPT="iptables ip6tables" ;;
|
||||
esac
|
||||
|
||||
[ -n "$iface" ] && ifn="$iface" || ifn="lan"
|
||||
DEV=$(ifstatus "$ifn" | jsonfilter -e '@["l3_device"]')
|
||||
|
||||
@@ -22,6 +28,35 @@ handle_section(){
|
||||
esac
|
||||
}
|
||||
|
||||
# --- Input validation ---
|
||||
validate_ttl(){
|
||||
echo "$1" | grep -qE '^([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$' || {
|
||||
logger -t ttl "Invalid TTL value: '$1' (must be 0-255)"; exit 1
|
||||
}
|
||||
}
|
||||
|
||||
validate_ports(){
|
||||
case "$1" in
|
||||
all|http|"") return 0 ;;
|
||||
esac
|
||||
echo "$1" | grep -qE '^[0-9]+(,[0-9]+)*$' || {
|
||||
logger -t ttl "Invalid ports value: '$1'"; exit 1
|
||||
}
|
||||
}
|
||||
|
||||
validate_iface(){
|
||||
echo "$1" | grep -qE '^[a-zA-Z0-9._-]{1,15}$' || {
|
||||
logger -t ttl "Invalid iface value: '$1'"; exit 1
|
||||
}
|
||||
}
|
||||
|
||||
validate_proxy(){
|
||||
echo "$1" | grep -qE '^(\[?[0-9a-fA-F:.]+\]?):([0-9]{1,5})$' || {
|
||||
logger -t ttl "Invalid proxy value: '$1'"; exit 1
|
||||
}
|
||||
}
|
||||
# --- End validation ---
|
||||
|
||||
config_load ttl
|
||||
|
||||
# Choose firewall backend: nft takes priority over iptables
|
||||
|
||||
@@ -1,34 +1,4 @@
|
||||
# --- Input validation ---
|
||||
validate_ttl(){
|
||||
echo "$1" | grep -qE '^([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$' || {
|
||||
logger -t ttl "Invalid TTL value: '$1' (must be 0-255)"; exit 1
|
||||
}
|
||||
}
|
||||
|
||||
validate_ports(){
|
||||
# accepts: "all", "http", or comma-separated port numbers
|
||||
case "$1" in
|
||||
all|http|"") return 0 ;;
|
||||
esac
|
||||
echo "$1" | grep -qE '^[0-9]+(,[0-9]+)*$' || {
|
||||
logger -t ttl "Invalid ports value: '$1'"; exit 1
|
||||
}
|
||||
}
|
||||
|
||||
validate_iface(){
|
||||
# interface name: alphanumeric, dash, dot, underscore, max 15 chars
|
||||
echo "$1" | grep -qE '^[a-zA-Z0-9._-]{1,15}$' || {
|
||||
logger -t ttl "Invalid iface value: '$1'"; exit 1
|
||||
}
|
||||
}
|
||||
|
||||
validate_proxy(){
|
||||
# IP:port or [IPv6]:port
|
||||
echo "$1" | grep -qE '^(\[?[0-9a-fA-F:.]+\]?):([0-9]{1,5})$' || {
|
||||
logger -t ttl "Invalid proxy value: '$1'"; exit 1
|
||||
}
|
||||
}
|
||||
# --- End validation ---
|
||||
# IPTABLES backend
|
||||
|
||||
method_ttl(){
|
||||
|
||||
@@ -74,6 +44,9 @@ method_proxy(){
|
||||
[ -n "$proxy" ] && validate_proxy "$proxy"
|
||||
[ -n "$iface" ] && validate_iface "$iface"
|
||||
|
||||
# check nat66 module
|
||||
[ -f /lib/modules/$(uname -r)/ip6table_nat.ko ] || IPT="iptables"
|
||||
|
||||
for T in $IPT; do
|
||||
[ "$proxy" ] && {
|
||||
IPADDR=${proxy%:*}
|
||||
@@ -123,13 +96,6 @@ method_proxy(){
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# check nat66 module
|
||||
if [ -f /lib/modules/$(uname -r)/ip6table_nat.ko ]; then
|
||||
IPT="iptables ip6tables"
|
||||
else
|
||||
IPT="iptables"
|
||||
fi
|
||||
|
||||
# Create and flush mangle table
|
||||
for T in $IPT; do
|
||||
|
||||
@@ -1,31 +1,4 @@
|
||||
# --- Input validation ---
|
||||
validate_ttl(){
|
||||
echo "$1" | grep -qE '^([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$' || {
|
||||
logger -t ttl "Invalid TTL value: '$1' (must be 0-255)"; exit 1
|
||||
}
|
||||
}
|
||||
|
||||
validate_ports(){
|
||||
case "$1" in
|
||||
all|http|"") return 0 ;;
|
||||
esac
|
||||
echo "$1" | grep -qE '^[0-9]+(,[0-9]+)*$' || {
|
||||
logger -t ttl "Invalid ports value: '$1'"; exit 1
|
||||
}
|
||||
}
|
||||
|
||||
validate_iface(){
|
||||
echo "$1" | grep -qE '^[a-zA-Z0-9._-]{1,15}$' || {
|
||||
logger -t ttl "Invalid iface value: '$1'"; exit 1
|
||||
}
|
||||
}
|
||||
|
||||
validate_proxy(){
|
||||
echo "$1" | grep -qE '^(\[?[0-9a-fA-F:.]+\]?):([0-9]{1,5})$' || {
|
||||
logger -t ttl "Invalid proxy value: '$1'"; exit 1
|
||||
}
|
||||
}
|
||||
# --- End validation ---
|
||||
# nftables backend
|
||||
|
||||
method_ttl(){
|
||||
|
||||
|
||||
Reference in new issue
Block a user