mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-09-10 18:34:18 +08:00
🏅 Sync 2026-08-09 09:19:32
This commit is contained in:
@@ -60,6 +60,15 @@ chmod +x /usr/share/passwall/*.sh
|
||||
[ "$(uci -q get passwall.@global_xray[0].sniffing)" == "1" ] && [ "$(uci -q get passwall.@global_xray[0].route_only)" != "1" ] && uci -q set passwall.@global_xray[0].sniffing_override_dest=1
|
||||
uci -q delete passwall.@global_xray[0].sniffing
|
||||
uci -q delete passwall.@global_xray[0].route_only
|
||||
|
||||
for sid in $(uci show passwall | grep "=socks" | awk -F '.' '{print $2}' | awk -F '=' '{print $1}'); do
|
||||
if [ -z "$(echo ${sid} | grep '^socks_')" ]; then
|
||||
new_id="socks_$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 5)"
|
||||
uci -q rename passwall.${sid}="${new_id}"
|
||||
unset sid new_id
|
||||
fi
|
||||
done
|
||||
|
||||
uci -q commit passwall
|
||||
|
||||
sed -i "s#add_from#group#g" /etc/config/passwall 2>/dev/null
|
||||
|
||||
@@ -341,8 +341,8 @@ run_socks() {
|
||||
|
||||
local node2socks_port=0
|
||||
local type remarks server_host server_port
|
||||
if is_socks_wrap "$node"; then
|
||||
node2socks_port=$(config_n_get ${node#Socks_} port 0)
|
||||
if [ "$(config_get_type $node)" = "socks" ]; then
|
||||
node2socks_port=$(config_n_get $node port 0)
|
||||
fi
|
||||
if [ "$node2socks_port" = "0" ]; then
|
||||
type=$(echo $(config_n_get $node type) | tr 'A-Z' 'a-z')
|
||||
@@ -546,8 +546,8 @@ run_redir() {
|
||||
|
||||
local node2socks_port=0
|
||||
local type remarks server_host port
|
||||
if is_socks_wrap "$node"; then
|
||||
node2socks_port=$(config_n_get ${node#Socks_} port 0)
|
||||
if [ "$(config_get_type $node)" = "socks" ]; then
|
||||
node2socks_port=$(config_n_get $node port 0)
|
||||
fi
|
||||
if [ "$node2socks_port" = "0" ]; then
|
||||
type=$(echo $(config_n_get $node type) | tr 'A-Z' 'a-z')
|
||||
@@ -999,8 +999,8 @@ start_socks() {
|
||||
local bind="0.0.0.0"
|
||||
[ "$bind_local" = "1" ] && bind="127.0.0.1"
|
||||
local port=$(config_n_get $id port)
|
||||
local config_file="SOCKS_${id}.json"
|
||||
local log_file="SOCKS_${id}.log"
|
||||
local config_file="${id}.json"
|
||||
local log_file="${id}.log"
|
||||
local log=$(config_n_get $id log 1)
|
||||
[ "$log" = "0" ] && log_file=""
|
||||
local http_port=$(config_n_get $id http_port 0)
|
||||
@@ -1009,7 +1009,7 @@ start_socks() {
|
||||
local no_rec=0
|
||||
[ "$enable_autoswitch" = "1" ] && no_rec=1
|
||||
NO_REC_PROCESS=$no_rec $APP_PATH/app.sh run_socks flag=$id node=$node bind=$bind socks_port=$port config_file=$config_file http_port=$http_port http_config_file=$http_config_file log_file=$log_file
|
||||
set_cache_var "socks_${id}" "$node"
|
||||
set_cache_var "${id}" "$node"
|
||||
#自动切换逻辑
|
||||
[ "$enable_autoswitch" = "1" ] && { $APP_PATH/socks_auto_switch.sh ${id} > /dev/null 2>&1 & }
|
||||
done
|
||||
@@ -1024,13 +1024,13 @@ socks_node_switch() {
|
||||
local prefix pf filename
|
||||
# 结束 SS 插件进程
|
||||
for prefix in "" "HTTP_"; do
|
||||
pf="$TMP_PATH/${prefix}SOCKS_${flag}_plugin.pid"
|
||||
pf="$TMP_PATH/${prefix}${flag}_plugin.pid"
|
||||
[ -s "$pf" ] && kill -9 "$(head -n1 "$pf")" >/dev/null 2>&1
|
||||
done
|
||||
|
||||
busybox pgrep -af "$TMP_BIN_PATH" | awk -v P1="${flag}" 'BEGIN{IGNORECASE=1}$0~P1 && !/acl\/|acl_/{print $1}' | xargs kill -9 >/dev/null 2>&1
|
||||
for prefix in "" "HTTP_" "HTTP2"; do
|
||||
rm -rf "$TMP_PATH/${prefix}SOCKS_${flag}"*
|
||||
rm -rf "$TMP_PATH/${prefix}${flag}"*
|
||||
done
|
||||
|
||||
for filename in $(ls ${TMP_SCRIPT_FUNC_PATH}); do
|
||||
@@ -1041,15 +1041,15 @@ socks_node_switch() {
|
||||
local bind="0.0.0.0"
|
||||
[ "$bind_local" = "1" ] && bind="127.0.0.1"
|
||||
local port=$(config_n_get $flag port)
|
||||
local config_file="SOCKS_${flag}.json"
|
||||
local log_file="SOCKS_${flag}.log"
|
||||
local config_file="${flag}.json"
|
||||
local log_file="${flag}.log"
|
||||
local log=$(config_n_get $flag log 1)
|
||||
[ "$log" = "0" ] && log_file=""
|
||||
local http_port=$(config_n_get $flag http_port 0)
|
||||
local http_config_file="HTTP2SOCKS_${flag}.json"
|
||||
LOG_FILE="/dev/null"
|
||||
run_socks flag=$flag node=$new_node bind=$bind socks_port=$port config_file=$config_file http_port=$http_port http_config_file=$http_config_file log_file=$log_file
|
||||
set_cache_var "socks_${flag}" "$new_node"
|
||||
set_cache_var "${flag}" "$new_node"
|
||||
local ENABLED_DEFAULT_ACL=$(get_cache_var "ENABLED_DEFAULT_ACL")
|
||||
local ENABLED_ACLS=$(get_cache_var "ENABLED_ACLS")
|
||||
[ "$ENABLED_DEFAULT_ACL" != "1" ] && [ "$ENABLED_ACLS" != "1" ] && return
|
||||
@@ -1604,7 +1604,7 @@ acl_app() {
|
||||
echolog " - 全局节点未启用,跳过【${remarks}】"
|
||||
fi
|
||||
else
|
||||
[ "$(config_get_type $tcp_node)" = "nodes" ] || [ "$(config_get_type ${tcp_node#Socks_})" = "socks" ] && {
|
||||
[ "$(config_get_type $tcp_node)" = "nodes" ] || [ "$(config_get_type $tcp_node)" = "socks" ] && {
|
||||
if [ -n "${GLOBAL_TCP_NODE}" ] && [ "$tcp_node" = "${GLOBAL_TCP_NODE}" ]; then
|
||||
set_cache_var "ACL_${sid}_tcp_node" "${GLOBAL_TCP_NODE}"
|
||||
set_cache_var "ACL_${sid}_tcp_redir_port" "${GLOBAL_TCP_redir_port}"
|
||||
@@ -1613,7 +1613,7 @@ acl_app() {
|
||||
[ "$GLOBAL_SHUNT_NODE_FAKEDNS" = "1" ] && use_fakedns=1
|
||||
else
|
||||
local type protocol
|
||||
if [ "$(config_get_type ${tcp_node#Socks_})" = "socks" ]; then
|
||||
if [ "$(config_get_type $tcp_node)" = "socks" ]; then
|
||||
if [ "${dns_mode}" = "xray" ]; then
|
||||
type="xray"
|
||||
elif [ "${dns_mode}" = "sing-box" ]; then
|
||||
@@ -1800,7 +1800,7 @@ acl_app() {
|
||||
set_cache_var "ACL_${sid}_udp_node" "${udp_node}"
|
||||
set_cache_var "ACL_${sid}_udp_redir_port" "${udp_port}"
|
||||
else
|
||||
[ "$(config_get_type $udp_node)" = "nodes" ] || [ "$(config_get_type ${udp_node#Socks_})" = "socks" ] && {
|
||||
[ "$(config_get_type $udp_node)" = "nodes" ] || [ "$(config_get_type $udp_node)" = "socks" ] && {
|
||||
if [ -n "${GLOBAL_UDP_NODE}" ] && [ "$udp_node" = "${GLOBAL_UDP_NODE}" ]; then
|
||||
set_cache_var "ACL_${sid}_udp_node" "${GLOBAL_UDP_NODE}"
|
||||
set_cache_var "ACL_${sid}_udp_redir_port" "${GLOBAL_UDP_redir_port}"
|
||||
@@ -1821,7 +1821,7 @@ acl_app() {
|
||||
[ "${log}" = "1" ] && log_file="${TMP_ACL_PATH}/${sid}/UDP.log"
|
||||
|
||||
local type
|
||||
if [ "$(config_get_type ${udp_node#Socks_})" = "socks" ]; then
|
||||
if [ "$(config_get_type $udp_node)" = "socks" ]; then
|
||||
if [ "${dns_mode}" = "xray" ]; then
|
||||
type="xray"
|
||||
elif [ "${dns_mode}" = "sing-box" ]; then
|
||||
@@ -1997,10 +1997,9 @@ get_config() {
|
||||
[ "$ENABLED" = 1 ] && {
|
||||
local _node
|
||||
for _node in "$TCP_NODE" "$UDP_NODE"; do
|
||||
[ -n "$_node" ] && case "$_node" in
|
||||
Socks_*) [ "$(config_get_type "${_node#Socks_}")" = "socks" ] && ENABLED_DEFAULT_ACL=1 ;;
|
||||
*) [ "$(config_get_type "$_node")" = "nodes" ] && ENABLED_DEFAULT_ACL=1 ;;
|
||||
esac
|
||||
if [ -n "$_node" ] && ([ "$(config_get_type $_node)" = "nodes" ] || [ "$(config_get_type $_node)" = "socks" ]); then
|
||||
ENABLED_DEFAULT_ACL=1
|
||||
fi
|
||||
done
|
||||
}
|
||||
ENABLED_ACLS=$(config_t_get global acl_enable 0)
|
||||
|
||||
@@ -142,8 +142,8 @@ test_auto_switch() {
|
||||
local b_nodes=$1
|
||||
local now_node=$2
|
||||
[ -z "$now_node" ] && {
|
||||
if [ -n "$(get_cache_var "socks_${id}")" ]; then
|
||||
now_node=$(get_cache_var "socks_${id}")
|
||||
if [ -n "$(get_cache_var "${id}")" ]; then
|
||||
now_node=$(get_cache_var "${id}")
|
||||
else
|
||||
#echolog "Socks切换检测:未知错误"
|
||||
return 1
|
||||
|
||||
@@ -180,10 +180,10 @@ do
|
||||
local flag = "Socks节点列表[" .. i .. "]备用节点的列表"
|
||||
local currentNodes = {}
|
||||
local newNodes = {}
|
||||
for k, node_id in ipairs(t.autoswitch_backup_node) do
|
||||
if node_id then
|
||||
local currentNode = uci:get_all(appname, node_id) or nil
|
||||
if currentNode then
|
||||
for k, asb_node in ipairs(t.autoswitch_backup_node) do
|
||||
if asb_node then
|
||||
local currentNode = uci:get_all(appname, asb_node) or {}
|
||||
if currentNode[".type"] == "nodes" then
|
||||
currentNodes[#currentNodes + 1] = {
|
||||
log = true,
|
||||
remarks = flag .. "[" .. k .. "]",
|
||||
@@ -291,17 +291,20 @@ do
|
||||
|
||||
for k, e in pairs(rules) do
|
||||
local _node_id = node[e[".name"]] or nil
|
||||
if _node_id and not _node_id:find("Socks_") then
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = false,
|
||||
currentNode = _node_id and uci:get_all(appname, _node_id) or nil,
|
||||
remarks = "分流" .. e.remarks .. "节点",
|
||||
set = function(o, server)
|
||||
if not server then server = "" end
|
||||
uci:set(appname, node_id, e[".name"], server)
|
||||
o.newNodeId = server
|
||||
end
|
||||
}
|
||||
if _node_id then
|
||||
local section = uci:get_all(appname, _node_id) or {}
|
||||
if section[".type"] == "nodes" then
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = false,
|
||||
currentNode = section,
|
||||
remarks = "分流" .. e.remarks .. "节点",
|
||||
set = function(o, server)
|
||||
if not server then server = "" end
|
||||
uci:set(appname, node_id, e[".name"], server)
|
||||
o.newNodeId = server
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif node.protocol and node.protocol == '_balancing' then
|
||||
@@ -309,17 +312,18 @@ do
|
||||
local currentNodes = {}
|
||||
local newNodes = {}
|
||||
if node.balancing_node then
|
||||
for k, node in pairs(node.balancing_node) do
|
||||
for k, b_node_id in pairs(node.balancing_node) do
|
||||
currentNodes[#currentNodes + 1] = {
|
||||
log = true,
|
||||
node = node,
|
||||
node = b_node_id,
|
||||
currentNode = (function()
|
||||
if node and node:find("Socks_") then
|
||||
return { Socks = node }
|
||||
local section = uci:get_all(appname, b_node_id) or {}
|
||||
if section[".type"] == "socks" then
|
||||
return { Socks = b_node_id }
|
||||
end
|
||||
return node and uci:get_all(appname, node) or nil
|
||||
return section
|
||||
end)(),
|
||||
remarks = node,
|
||||
remarks = b_node_id,
|
||||
set = function(o, server)
|
||||
if o and server and server ~= "nil" then
|
||||
table.insert(o.newNodes, server)
|
||||
@@ -342,37 +346,41 @@ do
|
||||
|
||||
--后备节点
|
||||
local currentNode = uci:get_all(appname, node_id) or nil
|
||||
if currentNode and currentNode.fallback_node and not currentNode.fallback_node:find("Socks_") then
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = true,
|
||||
id = node_id,
|
||||
remarks = "Xray负载均衡节点[" .. node_id .. "]后备节点",
|
||||
currentNode = uci:get_all(appname, currentNode.fallback_node) or nil,
|
||||
set = function(o, server)
|
||||
uci:set(appname, node_id, "fallback_node", server)
|
||||
o.newNodeId = server
|
||||
end,
|
||||
delete = function(o)
|
||||
uci:delete(appname, node_id, "fallback_node")
|
||||
end
|
||||
}
|
||||
if currentNode and currentNode.fallback_node then
|
||||
local section = uci:get_all(appname, currentNode.fallback_node) or {}
|
||||
if section[".type"] == "nodes" then
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = true,
|
||||
id = node_id,
|
||||
remarks = "Xray负载均衡节点[" .. node_id .. "]后备节点",
|
||||
currentNode = section,
|
||||
set = function(o, server)
|
||||
uci:set(appname, node_id, "fallback_node", server)
|
||||
o.newNodeId = server
|
||||
end,
|
||||
delete = function(o)
|
||||
uci:delete(appname, node_id, "fallback_node")
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
elseif node.protocol and node.protocol == '_urltest' then
|
||||
local flag = "Sing-Box URLTest节点[" .. node_id .. "]列表"
|
||||
local currentNodes = {}
|
||||
local newNodes = {}
|
||||
if node.urltest_node then
|
||||
for k, node in pairs(node.urltest_node) do
|
||||
for k, u_node_id in pairs(node.urltest_node) do
|
||||
currentNodes[#currentNodes + 1] = {
|
||||
log = true,
|
||||
node = node,
|
||||
node = u_node_id,
|
||||
currentNode = (function()
|
||||
if node and node:find("Socks_") then
|
||||
return { Socks = node }
|
||||
local section = uci:get_all(appname, u_node_id) or {}
|
||||
if section[".type"] == "socks" then
|
||||
return { Socks = u_node_id }
|
||||
end
|
||||
return node and uci:get_all(appname, node) or nil
|
||||
return section
|
||||
end)(),
|
||||
remarks = node,
|
||||
remarks = u_node_id,
|
||||
set = function(o, server)
|
||||
if o and server and server ~= "nil" then
|
||||
table.insert(o.newNodes, server)
|
||||
@@ -395,37 +403,43 @@ do
|
||||
else
|
||||
--前置代理节点
|
||||
local currentNode = uci:get_all(appname, node_id) or nil
|
||||
if currentNode and currentNode.preproxy_node and not currentNode.preproxy_node:find("Socks_") then
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = true,
|
||||
id = node_id,
|
||||
remarks = "节点[" .. node_id .. "]前置代理节点",
|
||||
currentNode = uci:get_all(appname, currentNode.preproxy_node) or nil,
|
||||
set = function(o, server)
|
||||
uci:set(appname, node_id, "preproxy_node", server)
|
||||
o.newNodeId = server
|
||||
end,
|
||||
delete = function(o)
|
||||
uci:delete(appname, node_id, "preproxy_node")
|
||||
end
|
||||
}
|
||||
if currentNode and currentNode.preproxy_node then
|
||||
local section = uci:get_all(appname, currentNode.preproxy_node) or {}
|
||||
if section[".type"] == "nodes" then
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = true,
|
||||
id = node_id,
|
||||
remarks = "节点[" .. node_id .. "]前置代理节点",
|
||||
currentNode = uci:get_all(appname, currentNode.preproxy_node) or nil,
|
||||
set = function(o, server)
|
||||
uci:set(appname, node_id, "preproxy_node", server)
|
||||
o.newNodeId = server
|
||||
end,
|
||||
delete = function(o)
|
||||
uci:delete(appname, node_id, "preproxy_node")
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
--落地节点
|
||||
local currentNode = uci:get_all(appname, node_id) or nil
|
||||
if currentNode and currentNode.to_node and not currentNode.to_node:find("Socks_") then
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = true,
|
||||
id = node_id,
|
||||
remarks = "节点[" .. node_id .. "]落地节点",
|
||||
currentNode = uci:get_all(appname, currentNode.to_node) or nil,
|
||||
set = function(o, server)
|
||||
uci:set(appname, node_id, "to_node", server)
|
||||
o.newNodeId = server
|
||||
end,
|
||||
delete = function(o)
|
||||
uci:delete(appname, node_id, "to_node")
|
||||
end
|
||||
}
|
||||
if currentNode and currentNode.to_node then
|
||||
local section = uci:get_all(appname, currentNode.to_node) or {}
|
||||
if section[".type"] == "nodes" then
|
||||
CONFIG[#CONFIG + 1] = {
|
||||
log = true,
|
||||
id = node_id,
|
||||
remarks = "节点[" .. node_id .. "]落地节点",
|
||||
currentNode = uci:get_all(appname, currentNode.to_node) or nil,
|
||||
set = function(o, server)
|
||||
uci:set(appname, node_id, "to_node", server)
|
||||
o.newNodeId = server
|
||||
end,
|
||||
delete = function(o)
|
||||
uci:delete(appname, node_id, "to_node")
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -508,13 +508,6 @@ ln_run() {
|
||||
echo "${file_func:-echolog " - ${ln_name}"} $@ >${output}" > $TMP_SCRIPT_FUNC_PATH/$process_count
|
||||
}
|
||||
|
||||
is_socks_wrap() {
|
||||
case "$1" in
|
||||
Socks_*) return 0 ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
kill_all() {
|
||||
kill -9 $(pidof "$@") >/dev/null 2>&1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user