update 2026-08-07 08:51:09

This commit is contained in:
action committed 2026-08-07 08:51:09 +08:00
1 parent d9d5e43e0e
commit b99c98d91e
16 files changed
+281 -70

No files matched your search

@@ -1105,6 +1105,9 @@ function gen_config(var)
local dns_socks_address = var["dns_socks_address"]
local dns_socks_port = var["dns_socks_port"]
local no_run = var["no_run"]
local use_proxy_list = var["use_proxy_list"]
local use_gfw_list = var["use_gfw_list"]
local chn_list = var["chn_list"]
local dns_domain_rules = {}
local dns = nil
@@ -1552,7 +1555,50 @@ function gen_config(var)
end
--shunt rule
uci:foreach(appname, "shunt_rules", function(e)
local function foreach_shunt_rule(callback)
uci:foreach(appname, "shunt_rules", callback)
if use_gfw_list ~= "1" or chn_list ~= "0" then return end
-- GFW 模式下使用分流节点时添加特定规则
local function read_proxy_list(path)
if use_proxy_list ~= "1" then return "" end
local map, list = {}, {}
local f = io.open(path)
if f then
for line in f:lines() do
if line ~= "" and not line:find("#", 1, true) and not map[line] then
map[line] = 1
list[#list + 1] = line
end
end
f:close()
end
return table.concat(list, "\n")
end
local domain_list = read_proxy_list("/usr/share/passwall/rules/proxy_host")
local ip_list = read_proxy_list("/usr/share/passwall/rules/proxy_ip")
local bin = api.finded_com("geoview")
if bin then
local geo_file = (uci:get(appname, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/") .. "/geosite.dat"
if luci.sys.call('"' .. bin .. '" -type geosite -input "' .. geo_file .. '" | grep -q "^GFW$"') == 0 then
domain_list = (domain_list == "") and "geosite:gfw" or domain_list .. "\ngeosite:gfw"
end
end
if domain_list ~= "" or ip_list ~= "" then
node["GFW_Mode_List"] = "_default"
callback({
[".name"] = "GFW_Mode_List",
remarks = "GFW_Mode_List",
domain_list = (domain_list ~= "") and domain_list or nil,
ip_list = (ip_list ~= "") and ip_list or nil
})
end
end
foreach_shunt_rule(function(e)
local outboundTag = gen_shunt_node(e[".name"])
if outboundTag and e.remarks then
if outboundTag == "default" then
@@ -1755,6 +1801,14 @@ function gen_config(var)
table.insert(rules, rule)
end
end)
if use_gfw_list == "1" and chn_list == "0" then -- GFW 模式下使用分流节点时添加兜底规则
table.insert(rules, {
action = "route",
port_range = { "0:65535" },
outbound = "direct"
})
end
else
COMMON.default_outbound_tag = gen_outbound_get_tag(flag, node or node_id, nil, {
fragment = singbox_settings.fragment == "1" or nil,
@@ -868,6 +868,9 @@ function gen_config(var)
local dns_socks_port = var["dns_socks_port"]
local loglevel = var["loglevel"] or "warning"
local no_run = var["no_run"]
local use_proxy_list = var["use_proxy_list"]
local use_gfw_list = var["use_gfw_list"]
local chn_list = var["chn_list"]
local dns_domain_rules = {}
local dns = nil
@@ -1363,7 +1366,50 @@ function gen_config(var)
end
--shunt rule
uci:foreach(appname, "shunt_rules", function(e)
local function foreach_shunt_rule(callback)
uci:foreach(appname, "shunt_rules", callback)
if use_gfw_list ~= "1" or chn_list ~= "0" then return end
-- GFW 模式下使用分流节点时添加特定规则
local function read_proxy_list(path)
if use_proxy_list ~= "1" then return "" end
local map, list = {}, {}
local f = io.open(path)
if f then
for line in f:lines() do
if line ~= "" and not line:find("#", 1, true) and not map[line] then
map[line] = 1
list[#list + 1] = line
end
end
f:close()
end
return table.concat(list, "\n")
end
local domain_list = read_proxy_list("/usr/share/passwall/rules/proxy_host")
local ip_list = read_proxy_list("/usr/share/passwall/rules/proxy_ip")
local bin = api.finded_com("geoview")
if bin then
local geo_file = (uci:get(appname, "@global_rules[0]", "v2ray_location_asset") or "/usr/share/v2ray/"):match("^(.*)/") .. "/geosite.dat"
if luci.sys.call('"' .. bin .. '" -type geosite -input "' .. geo_file .. '" | grep -q "^GFW$"') == 0 then
domain_list = (domain_list == "") and "geosite:gfw" or domain_list .. "\ngeosite:gfw"
end
end
if domain_list ~= "" or ip_list ~= "" then
node["GFW_Mode_List"] = "_default"
callback({
[".name"] = "GFW_Mode_List",
remarks = "GFW_Mode_List",
domain_list = (domain_list ~= "") and domain_list or nil,
ip_list = (ip_list ~= "") and ip_list or nil
})
end
end
foreach_shunt_rule(function(e)
local outbound_tag = gen_shunt_node(e[".name"])
if outbound_tag and e.remarks then
if outbound_tag == "default" then
@@ -1463,6 +1509,15 @@ function gen_config(var)
end
end)
if use_gfw_list == "1" and chn_list == "0" then -- GFW 模式下使用分流节点时添加兜底规则
table.insert(rules, {
ruleTag = "GFW_Mode_Default",
outboundTag = "direct",
port = (node.domainStrategy == "IPIfNonMatch") and "1-65535" or nil,
network = (node.domainStrategy ~= "IPIfNonMatch") and "tcp,udp" or nil
})
end
table.insert(rules, {
outboundTag = "direct",
ip = { "geoip:private" }
@@ -99,7 +99,7 @@ run_ipt2socks() {
run_singbox() {
local flag type node tcp_redir_port tcp_proxy_way udp_redir_port socks_address socks_port socks_username socks_password http_address http_port http_username http_password
local dns_listen_port direct_dns_query_strategy direct_dns_port direct_dns_udp_server direct_dns_tcp_server remote_dns_protocol remote_dns_udp_server remote_dns_tcp_server remote_dns_doh remote_dns_client_ip remote_fakedns remote_dns_query_strategy dns_cache dns_socks_address dns_socks_port
local loglevel log_file config_file server_host server_port no_run
local loglevel log_file config_file server_host server_port no_run use_proxy_list use_gfw_list chn_list
eval_set_val "$@"
[ -z "$type" ] && {
type=$(echo $(config_n_get $node type) | tr 'A-Z' 'a-z')
@@ -120,6 +120,9 @@ run_singbox() {
[ -n "$flag" ] && json_add_string "flag" "$flag"
[ -n "$node" ] && json_add_string "node" "$node"
[ -n "$use_proxy_list" ] && json_add_string "use_proxy_list" "$use_proxy_list"
[ -n "$use_gfw_list" ] && json_add_string "use_gfw_list" "$use_gfw_list"
[ -n "$chn_list" ] && json_add_string "chn_list" "$chn_list"
[ -n "$server_host" ] && json_add_string "server_host" "$server_host"
[ -n "$server_port" ] && json_add_string "server_port" "$server_port"
[ -n "$tcp_redir_port" ] && json_add_string "tcp_redir_port" "$tcp_redir_port"
@@ -197,7 +200,7 @@ run_singbox() {
run_xray() {
local flag type node tcp_redir_port tcp_proxy_way udp_redir_port socks_address socks_port socks_username socks_password http_address http_port http_username http_password
local dns_listen_port direct_dns_query_strategy direct_dns_port direct_dns_udp_server direct_dns_tcp_server remote_dns_protocol remote_dns_udp_server remote_dns_tcp_server remote_dns_doh remote_dns_client_ip remote_fakedns remote_dns_query_strategy dns_cache dns_socks_address dns_socks_port
local loglevel log_file config_file server_host server_port no_run
local loglevel log_file config_file server_host server_port no_run use_proxy_list use_gfw_list chn_list
eval_set_val "$@"
[ -z "$type" ] && {
type=$(echo $(config_n_get $node type) | tr 'A-Z' 'a-z')
@@ -209,6 +212,9 @@ run_xray() {
[ -z "$loglevel" ] && local loglevel=$(config_t_get global loglevel "warning")
[ -n "$flag" ] && json_add_string "flag" "$flag"
[ -n "$node" ] && json_add_string "node" "$node"
[ -n "$use_proxy_list" ] && json_add_string "use_proxy_list" "$use_proxy_list"
[ -n "$use_gfw_list" ] && json_add_string "use_gfw_list" "$use_gfw_list"
[ -n "$chn_list" ] && json_add_string "chn_list" "$chn_list"
[ -n "$server_host" ] && json_add_string "server_host" "$server_host"
[ -n "$server_port" ] && json_add_string "server_port" "$server_port"
[ -n "$tcp_redir_port" ] && json_add_string "tcp_redir_port" "$tcp_redir_port"
@@ -760,6 +766,7 @@ run_redir() {
}
NEXT_DNS_LISTEN_PORT=$(expr $NEXT_DNS_LISTEN_PORT + 1)
}
_args="${_args} use_proxy_list=$USE_PROXY_LIST use_gfw_list=$USE_GFW_LIST chn_list=$CHN_LIST"
run_singbox flag=$_flag node=$node tcp_redir_port=$local_port tcp_proxy_way=$TCP_PROXY_WAY config_file=$config_file log_file=$log_file ${_args}
;;
xray)
@@ -846,6 +853,7 @@ run_redir() {
}
NEXT_DNS_LISTEN_PORT=$(expr $NEXT_DNS_LISTEN_PORT + 1)
}
_args="${_args} use_proxy_list=$USE_PROXY_LIST use_gfw_list=$USE_GFW_LIST chn_list=$CHN_LIST"
run_xray flag=$_flag node=$node tcp_redir_port=$local_port tcp_proxy_way=$TCP_PROXY_WAY config_file=$config_file log_file=$log_file ${_args}
;;
naiveproxy)
@@ -1743,6 +1751,7 @@ acl_app() {
}
config_file="$TMP_PATH/$config_file"
[ "${type}" = "sing-box" ] && type="singbox"
_extra_param="${_extra_param} use_proxy_list=$use_proxy_list use_gfw_list=$use_gfw_list chn_list=$chn_list"
run_${type} flag=$tcp_node node=$tcp_node tcp_redir_port=$redir_port ${_extra_param} config_file=$config_file log_file=$log_file loglevel=$loglevel
else
config_file="acl/${tcp_node}_SOCKS_${socks_port}.json"
@@ -1398,8 +1398,8 @@ del_firewall_rule() {
done
for ipt in "$ipt_f" "$ip6t_f"; do
for chain in "FORWARD" "INPUT" "OUTPUT"; do
for i in $(seq 1 $($ipt -nL $chain | grep -c PSW)); do
local index=$($ipt --line-number -nL $chain | grep PSW | head -1 | awk '{print $1}')
for i in $(seq 1 $($ipt -nL $chain | grep -c PSW_REJECT)); do
local index=$($ipt --line-number -nL $chain | grep PSW_REJECT | head -1 | awk '{print $1}')
$ipt -D $chain $index 2>/dev/null
done
done