mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-10-31 01:45:13 +08:00
update 2026-08-12 17:06:12
This commit is contained in:
1 parent
f7ac09ba87
commit
0d04308d7f
1968 files changed
+59
-1523151
No files matched your search
@@ -46,6 +46,8 @@ FWI=$(uci -q get firewall.passwall.path 2>/dev/null)
|
||||
FAKE_IP="198.18.0.0/15"
|
||||
FAKE_IP_6="fc00::/18"
|
||||
|
||||
USE_GEOVIEW=0
|
||||
|
||||
factor() {
|
||||
if [ -z "$1" ] || [ -z "$2" ]; then
|
||||
echo ""
|
||||
@@ -392,6 +394,28 @@ load_acl() {
|
||||
shunt6_set_name="psw_${sid}_shunt6"
|
||||
ipset -! create $shunt_set_name nethash maxelem 1048576 timeout 172800
|
||||
ipset -! create $shunt6_set_name nethash family inet6 maxelem 1048576 timeout 172800
|
||||
# 预加载分流规则 ip 到 ipset
|
||||
local GEOIP_CODE=""
|
||||
local shunt_ids=$(uci show $CONFIG | grep "=shunt_rules" | awk -F '.' '{print $2}' | awk -F '=' '{print $1}')
|
||||
local shunt_group shunt_id
|
||||
if [ "${use_shunt_tcp}" = "1" ]; then
|
||||
shunt_group=$(config_n_get $tcp_node shunt_group)
|
||||
elif [ "${use_shunt_udp}" = "1" ]; then
|
||||
shunt_group=$(config_n_get $udp_node shunt_group)
|
||||
fi
|
||||
for shunt_id in $shunt_ids; do
|
||||
[ "${shunt_group}" != "$(config_n_get ${shunt_id} group)" ] && continue
|
||||
config_n_get $shunt_id ip_list | tr -s "\r\n" "\n" | grep -v "^#" | sed -e "/^$/d" | grep -E "(\.((2(5[0-5]|[0-4][0-9]))|[0-1]?[0-9]{1,2})){3}" | sed -e "s/^/add $shunt_set_name &/g" -e "s/$/ timeout 0/g" | ipset -! -R
|
||||
config_n_get $shunt_id ip_list | tr -s "\r\n" "\n" | grep -v "^#" | sed -e "/^$/d" | grep -E "([A-Fa-f0-9]{1,4}::?){1,7}[A-Fa-f0-9]{1,4}" | sed -e "s/^/add $shunt6_set_name &/g" -e "s/$/ timeout 0/g" | ipset -! -R
|
||||
[ "$USE_GEOVIEW" = "1" ] && {
|
||||
local geoip_code=$(config_n_get $shunt_id ip_list | tr -s "\r\n" "\n" | sed -e "/^$/d" | grep -E "^geoip:" | grep -v "^geoip:private" | sed -E 's/^geoip:(.*)/\1/' | sed ':a;N;$!ba;s/\n/,/g')
|
||||
[ -n "$geoip_code" ] && GEOIP_CODE="${GEOIP_CODE:+$GEOIP_CODE,}$geoip_code"
|
||||
}
|
||||
done
|
||||
if [ -n "$GEOIP_CODE" ]; then
|
||||
get_geoip $GEOIP_CODE ipv4 | grep -E "(\.((2(5[0-5]|[0-4][0-9]))|[0-1]?[0-9]{1,2})){3}" | sed -e "s/^/add $shunt_set_name &/g" -e "s/$/ timeout 0/g" | ipset -! -R
|
||||
get_geoip $GEOIP_CODE ipv6 | grep -E "([A-Fa-f0-9]{1,4}::?){1,7}[A-Fa-f0-9]{1,4}" | sed -e "s/^/add $shunt6_set_name &/g" -e "s/$/ timeout 0/g" | ipset -! -R
|
||||
fi
|
||||
}
|
||||
}
|
||||
[ -n "${dns_redirect_port}" ] && dns_redirect=${dns_redirect_port}
|
||||
@@ -891,7 +915,7 @@ add_firewall_rule() {
|
||||
local USE_BLOCK_LIST_ALL=${USE_BLOCK_LIST}
|
||||
local _TCP_NODE=$(config_t_get global tcp_node)
|
||||
local _UDP_NODE=$(config_t_get global udp_node)
|
||||
local USE_GEOVIEW=$(config_t_get global_rules enable_geoview)
|
||||
USE_GEOVIEW=$(config_t_get global_rules enable_geoview)
|
||||
[ -z "$(first_type $(config_t_get global_app geoview_file) geoview)" ] && USE_GEOVIEW=0
|
||||
|
||||
[ -n "$_TCP_NODE" ] && [ "$(config_n_get $_TCP_NODE protocol)" = "_shunt" ] && USE_SHUNT_TCP=1 && USE_SHUNT_NODE=1
|
||||
@@ -957,7 +981,7 @@ add_firewall_rule() {
|
||||
[ "$USE_SHUNT_NODE" = "1" ] && {
|
||||
local GEOIP_CODE=""
|
||||
local shunt_ids=$(uci show $CONFIG | grep "=shunt_rules" | awk -F '.' '{print $2}' | awk -F '=' '{print $1}')
|
||||
local shunt_group
|
||||
local shunt_group shunt_id
|
||||
if [ "${USE_SHUNT_TCP}" = "1" ]; then
|
||||
shunt_group=$(config_n_get $_TCP_NODE shunt_group)
|
||||
elif [ "${USE_SHUNT_UDP}" = "1" ]; then
|
||||
|
||||
@@ -52,6 +52,8 @@ FWI=$(uci -q get firewall.passwall.path 2>/dev/null)
|
||||
FAKE_IP="198.18.0.0/15"
|
||||
FAKE_IP_6="fc00::/18"
|
||||
|
||||
USE_GEOVIEW=0
|
||||
|
||||
factor() {
|
||||
local ports="$1"
|
||||
if [ -z "$1" ] || [ -z "$2" ] || [ "$ports" = "1:65535" ]; then
|
||||
@@ -453,6 +455,28 @@ load_acl() {
|
||||
gen_nftset $shunt_set_name_static ipv4_addr 0
|
||||
gen_nftset $shunt6_set_name ipv6_addr "2d"
|
||||
gen_nftset $shunt6_set_name_static ipv6_addr 0
|
||||
# 预加载分流规则 ip 到 nftset
|
||||
local GEOIP_CODE=""
|
||||
local shunt_ids=$(uci show $CONFIG | grep "=shunt_rules" | awk -F '.' '{print $2}' | awk -F '=' '{print $1}')
|
||||
local shunt_group shunt_id
|
||||
if [ "${use_shunt_tcp}" = "1" ]; then
|
||||
shunt_group=$(config_n_get $tcp_node shunt_group)
|
||||
elif [ "${use_shunt_udp}" = "1" ]; then
|
||||
shunt_group=$(config_n_get $udp_node shunt_group)
|
||||
fi
|
||||
for shunt_id in $shunt_ids; do
|
||||
[ "${shunt_group}" != "$(config_n_get ${shunt_id} group)" ] && continue
|
||||
config_n_get $shunt_id ip_list | sed 's/#.*//' | grep -E "(\.((2(5[0-5]|[0-4][0-9]))|[0-1]?[0-9]{1,2})){3}" | insert_nftset $shunt_set_name_static
|
||||
config_n_get $shunt_id ip_list | sed 's/#.*//' | grep -E "([A-Fa-f0-9]{1,4}::?){1,7}[A-Fa-f0-9]{1,4}" | insert_nftset $shunt6_set_name_static
|
||||
[ "$USE_GEOVIEW" = "1" ] && {
|
||||
local geoip_code=$(config_n_get $shunt_id ip_list | tr -s "\r\n" "\n" | sed -e "/^$/d" | grep -E "^geoip:" | grep -v "^geoip:private" | sed -E 's/^geoip:(.*)/\1/' | sed ':a;N;$!ba;s/\n/,/g')
|
||||
[ -n "$geoip_code" ] && GEOIP_CODE="${GEOIP_CODE:+$GEOIP_CODE,}$geoip_code"
|
||||
}
|
||||
done
|
||||
if [ -n "$GEOIP_CODE" ]; then
|
||||
get_geoip $GEOIP_CODE ipv4 | grep -E "(\.((2(5[0-5]|[0-4][0-9]))|[0-1]?[0-9]{1,2})){3}" | insert_nftset $shunt_set_name_static
|
||||
get_geoip $GEOIP_CODE ipv6 | grep -E "([A-Fa-f0-9]{1,4}::?){1,7}[A-Fa-f0-9]{1,4}" | insert_nftset $shunt6_set_name_static
|
||||
fi
|
||||
}
|
||||
}
|
||||
[ -n "${dns_redirect_port}" ] && dns_redirect=${dns_redirect_port}
|
||||
@@ -954,7 +978,8 @@ add_firewall_rule() {
|
||||
if [ -f $RULES_PATH/chnroute.nft ] && [ -s $RULES_PATH/chnroute.nft ] && [ $(awk 'END{print NR}' $RULES_PATH/chnroute.nft) -ge 8 ]; then
|
||||
nft -f $RULES_PATH/chnroute.nft
|
||||
else
|
||||
cat $RULES_PATH/chnroute | tr -s '\n' | sed 's/#.*//' | gen_nftset $NFTSET_CHN_STATIC ipv4_addr 0
|
||||
gen_nftset $NFTSET_CHN_STATIC ipv4_addr 0
|
||||
cat $RULES_PATH/chnroute | tr -s '\n' | sed 's/#.*//' | insert_nftset $NFTSET_CHN_STATIC
|
||||
fi
|
||||
gen_nftset $NFTSET_BLACK ipv4_addr "2d"
|
||||
gen_nftset $NFTSET_BLACK_STATIC ipv4_addr 0
|
||||
@@ -975,7 +1000,8 @@ add_firewall_rule() {
|
||||
#echolog "使用缓存加载chnroute6..."
|
||||
nft -f $RULES_PATH/chnroute6.nft
|
||||
else
|
||||
cat $RULES_PATH/chnroute6 | tr -s '\n' | sed 's/#.*//' | gen_nftset $NFTSET_CHN6_STATIC ipv6_addr 0
|
||||
gen_nftset $NFTSET_CHN6_STATIC ipv6_addr 0
|
||||
cat $RULES_PATH/chnroute6 | tr -s '\n' | sed 's/#.*//' | insert_nftset $NFTSET_CHN6_STATIC
|
||||
fi
|
||||
gen_nftset $NFTSET_BLACK6 ipv6_addr "2d"
|
||||
gen_nftset $NFTSET_BLACK6_STATIC ipv6_addr 0
|
||||
@@ -993,7 +1019,7 @@ add_firewall_rule() {
|
||||
local USE_BLOCK_LIST_ALL=${USE_BLOCK_LIST}
|
||||
local _TCP_NODE=$(config_t_get global tcp_node)
|
||||
local _UDP_NODE=$(config_t_get global udp_node)
|
||||
local USE_GEOVIEW=$(config_t_get global_rules enable_geoview)
|
||||
USE_GEOVIEW=$(config_t_get global_rules enable_geoview)
|
||||
[ -z "$(first_type $(config_t_get global_app geoview_file) geoview)" ] && USE_GEOVIEW=0
|
||||
|
||||
[ -n "$_TCP_NODE" ] && [ "$(config_n_get $_TCP_NODE protocol)" = "_shunt" ] && USE_SHUNT_TCP=1 && USE_SHUNT_NODE=1
|
||||
@@ -1059,7 +1085,7 @@ add_firewall_rule() {
|
||||
[ "$USE_SHUNT_NODE" = "1" ] && {
|
||||
local GEOIP_CODE=""
|
||||
local shunt_ids=$(uci show $CONFIG | grep "=shunt_rules" | awk -F '.' '{print $2}' | awk -F '=' '{print $1}')
|
||||
local shunt_group
|
||||
local shunt_group shunt_id
|
||||
if [ "${USE_SHUNT_TCP}" = "1" ]; then
|
||||
shunt_group=$(config_n_get $_TCP_NODE shunt_group)
|
||||
elif [ "${USE_SHUNT_UDP}" = "1" ]; then
|
||||
|
||||
Reference in new issue
Block a user