Merge pull request #59 from itdoginfo/feat/multiple-mixed-inbounds

Add support for multiple mixed inbounds with unique ports
This commit is contained in:
itdoginfo
2025-03-07 13:10:32 +03:00
committed by GitHub

View File

@@ -459,30 +459,45 @@ sing_box_uci() {
fi fi
} }
# Future: for every section. +1 port? add_socks5_for_section() {
process_socks5() { local section="$1"
config_get_bool socks5 "main" "socks5" "0" local port="$2"
if [ "$socks5" -eq 1 ]; then local tag="$section-mixed-in"
log "Socks5 local enable port 2080"
jq '.inbounds += [{ log "Adding Socks5 for $section on port $port"
"tag": "mixed-in",
jq \
--arg tag "$tag" \
--arg port "$port" \
--arg section "$section" \
'.inbounds += [{
"tag": $tag,
"type": "mixed", "type": "mixed",
"listen": "0.0.0.0", "listen": "0.0.0.0",
"listen_port": 2080, "listen_port": ($port|tonumber),
"set_system_proxy": false "set_system_proxy": false
}]' $SING_BOX_CONFIG >/tmp/sing-box-config-tmp.json && mv /tmp/sing-box-config-tmp.json $SING_BOX_CONFIG }] |
.route.rules += [{
#local rule_exists=$(jq -r '.route.rules[] | select(.inbound[] == "mixed-in")' $SING_BOX_CONFIG) "inbound": [$tag],
local rule_exists=$(jq -r '.route.rules // [] | map(select(.inbound // [] | index("mixed-in"))) | length' $SING_BOX_CONFIG) "outbound": $section,
if [ -z "$rule_exists" ]; then
jq '.route.rules += [{
"inbound": ["mixed-in"],
"outbound": "main",
"action": "route" "action": "route"
}]' $SING_BOX_CONFIG >/tmp/sing-box-config-tmp.json && mv /tmp/sing-box-config-tmp.json $SING_BOX_CONFIG }]' $SING_BOX_CONFIG >/tmp/sing-box-config-tmp.json && mv /tmp/sing-box-config-tmp.json $SING_BOX_CONFIG
}
process_socks5() {
config_get_bool main_socks5 "main" "socks5" "0"
if [ "$main_socks5" -eq 1 ]; then
add_socks5_for_section "main" "2080"
fi fi
local port=2081
for section in $(uci show podkop | awk -F'[.=]' '/=extra/ {print $2}'); do
config_get_bool section_socks5 "$section" "socks5" "0"
if [ "$section_socks5" -eq 1 ]; then
add_socks5_for_section "$section" "$port"
port=$((port + 1))
fi fi
done
} }
sing_box_inbound_proxy() { sing_box_inbound_proxy() {