fix: multiple fixes
This commit is contained in:
23 files changed
+940
-96
No files matched your search
@@ -7,6 +7,7 @@
|
||||
routeModeStateFile,
|
||||
pinnedOutboundFile,
|
||||
outboundInventoryFile,
|
||||
runtimeOutboundsDir,
|
||||
subscriptionCacheDir,
|
||||
subscriptionCacheHelpersBlock,
|
||||
mkSubscriptionFetchBlock,
|
||||
@@ -95,6 +96,16 @@ let
|
||||
echo "proxy-suite: unknown outbound '$tag'" >&2
|
||||
exit 1
|
||||
fi
|
||||
# Disabled means nothing picks it on its own, a pin included.
|
||||
case "$tag" in
|
||||
*/* | . | ..) ;;
|
||||
*)
|
||||
if [ -e "${runtimeOutboundsDir}/$tag.disabled" ]; then
|
||||
echo "proxy-suite: outbound '$tag' is disabled; enable it first: proxy-ctl proxy outbounds enable $tag" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
mkdir -p "$(dirname "${pinnedOutboundFile}")"
|
||||
printf '%s\n' "$tag" > "${pinnedOutboundFile}"
|
||||
# Live switch when the running config exposes a selector; the persisted pin
|
||||
@@ -147,6 +158,21 @@ let
|
||||
esac
|
||||
done
|
||||
|
||||
# A pin on a disabled outbound goes with it, so enabling the outbound later does not
|
||||
# bring the pin back. Here rather than through the unpin unit: disabling is the
|
||||
# outbounds scope's, pinning the routing scope's.
|
||||
if [ -r "${pinnedOutboundFile}" ]; then
|
||||
PINNED="$(tr -d '\r\n[:space:]' < "${pinnedOutboundFile}" 2>/dev/null || true)"
|
||||
case "$PINNED" in
|
||||
"" | */* | . | ..) ;;
|
||||
*)
|
||||
if [ -e "${runtimeOutboundsDir}/$PINNED.disabled" ]; then
|
||||
rm -f "${pinnedOutboundFile}"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
${restartActiveConfigConsumersBlock}
|
||||
'';
|
||||
in
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
selectionMode,
|
||||
proxyInboundsGuardPrivate,
|
||||
userDnsRules ? [ ],
|
||||
selectionExclude ? [ ],
|
||||
}:
|
||||
|
||||
if pureXrayEnabled then
|
||||
@@ -72,14 +71,15 @@ if pureXrayEnabled then
|
||||
| if $route_enabled then
|
||||
.routing.rules = (xray_preserved_rules + $route_rules + [xray_final_rule($route_final; $xray_single_proxy_tag)])
|
||||
else . end
|
||||
${lib.optionalString (selectionExclude != [ ]) ''
|
||||
# The balancer's prefix would take in proxy.selectionExclude too: name the rest instead.
|
||||
# ponytail: selectors are prefixes still, so "de" also takes in an excluded "de-hop";
|
||||
# rename one of them if that matters.
|
||||
| ($xray_selectable | map("proxy-suite-ob-" + .)) as $candidates
|
||||
| if .routing.balancers then .routing.balancers |= map(.selector = $candidates) else . end
|
||||
| if .observatory then .observatory.subjectSelector = $candidates else . end
|
||||
''}
|
||||
# The balancer's prefix would take in proxy.selectionExclude and disabled outbounds
|
||||
# too: name the rest instead. Disabling is a runtime decision, so always.
|
||||
# ponytail: selectors are prefixes still, so "de" also takes in an excluded "de-hop";
|
||||
# rename one of them if that matters.
|
||||
| if $ARGS.named.xray_selectable == null then . else
|
||||
($ARGS.named.xray_selectable | map("proxy-suite-ob-" + .)) as $candidates
|
||||
| if .routing.balancers then .routing.balancers |= map(.selector = $candidates) else . end
|
||||
| if .observatory then .observatory.subjectSelector = $candidates else . end
|
||||
end
|
||||
| if $xray_single_proxy_tag == "" then
|
||||
.
|
||||
else
|
||||
|
||||
@@ -496,6 +496,20 @@ let
|
||||
# entry that went away, say - is dropped rather than left to break the config.
|
||||
pinBlock = ''
|
||||
OUTBOUND_TAGS_JSON=$(${jq} -c '[.[].tag]' <<< "$OUTBOUNDS_JSON")
|
||||
|
||||
# `proxy-ctl proxy outbounds disable` leaves <tag>.disabled next to the runtime entries:
|
||||
# the outbound stays, so rules and chains naming it still work, but nothing picks it on
|
||||
# its own - selection, autoProxy and a pin. Markers for tags that are gone are ignored.
|
||||
DISABLED_TAGS_JSON='[]'
|
||||
if [ -d "${runtimeOutboundsDir}" ]; then
|
||||
for DISABLED_MARKER in "${runtimeOutboundsDir}"/*.disabled; do
|
||||
[ -e "$DISABLED_MARKER" ] || continue
|
||||
DISABLED_TAG="''${DISABLED_MARKER##*/}"
|
||||
DISABLED_TAGS_JSON=$(${jq} -c --arg t "''${DISABLED_TAG%.disabled}" '. + [$t]' <<< "$DISABLED_TAGS_JSON")
|
||||
done
|
||||
fi
|
||||
DISABLED_TAGS_JSON=$(${jq} -c --argjson tags "$OUTBOUND_TAGS_JSON" 'map(select(. as $t | $tags | index([$t]))) | unique' <<< "$DISABLED_TAGS_JSON")
|
||||
|
||||
PINNED_OUTBOUND=""
|
||||
if [ -r "${pinnedOutboundFile}" ]; then
|
||||
PINNED_OUTBOUND="$(tr -d '\r\n[:space:]' < "${pinnedOutboundFile}" 2>/dev/null || true)"
|
||||
@@ -505,21 +519,27 @@ let
|
||||
echo "proxy-suite: warning: pinned outbound '$PINNED_OUTBOUND' is not available; picking automatically" >&2
|
||||
PINNED_OUTBOUND=""
|
||||
fi
|
||||
if [ -n "$PINNED_OUTBOUND" ] \
|
||||
&& ${jq} -e --arg t "$PINNED_OUTBOUND" 'index($t) != null' <<< "$DISABLED_TAGS_JSON" >/dev/null; then
|
||||
echo "proxy-suite: warning: pinned outbound '$PINNED_OUTBOUND' is disabled; picking automatically" >&2
|
||||
PINNED_OUTBOUND=""
|
||||
fi
|
||||
'';
|
||||
|
||||
# What selection may pick on its own: all but proxy.selectionExclude. A pin and a
|
||||
# selector switched by hand still reach the excluded ones.
|
||||
# What selection may pick on its own: all but proxy.selectionExclude and disabled
|
||||
# outbounds. A pin still reaches the excluded ones, and a selector switched by hand both.
|
||||
selectableBlock = ''
|
||||
SELECTABLE_TAGS_JSON=$(${jq} -c --argjson ex ${lib.escapeShellArg (builtins.toJSON proxyCfg.selectionExclude)} \
|
||||
'map(select(. as $t | $ex | index([$t]) | not))' <<< "$OUTBOUND_TAGS_JSON")
|
||||
--argjson disabled "$DISABLED_TAGS_JSON" \
|
||||
'map(select(. as $t | ($ex + $disabled) | index([$t]) | not))' <<< "$OUTBOUND_TAGS_JSON")
|
||||
if [ -z "$PINNED_OUTBOUND" ] && [ "$(${jq} 'length' <<< "$SELECTABLE_TAGS_JSON")" -eq 0 ]; then
|
||||
echo "proxy-suite: every outbound is in proxy.selectionExclude, so there is nothing to select; pin one, or exclude fewer" >&2
|
||||
echo "proxy-suite: every outbound is in proxy.selectionExclude or disabled, so there is nothing to select; pin one, enable one (proxy-ctl proxy outbounds enable), or exclude fewer" >&2
|
||||
exit 1
|
||||
fi
|
||||
'';
|
||||
|
||||
# proxy-ctl reads this unprivileged: tags, where each came from, the pin, what each one
|
||||
# chains through, and what selection leaves alone.
|
||||
# chains through, what selection leaves alone, and what was disabled.
|
||||
inventoryBlock = ''
|
||||
${jq} -n \
|
||||
--argjson tags "$OUTBOUND_TAGS_JSON" \
|
||||
@@ -529,10 +549,11 @@ let
|
||||
--argjson obs "$OUTBOUNDS_JSON" \
|
||||
--argjson xobs "${if hybridEnabled then "$XRAY_OUTBOUNDS_JSON" else "[]"}" \
|
||||
--argjson selectable "$SELECTABLE_TAGS_JSON" \
|
||||
--argjson disabled "$DISABLED_TAGS_JSON" \
|
||||
'{tags: $tags, sources: $sources, pinned: $pinned, selection: $selection,
|
||||
detours: ([($xobs + $obs)[] | (.detour // .streamSettings.sockopt.dialerProxy?) as $h
|
||||
| select($h != null) | {key: .tag, value: $h}] | from_entries),
|
||||
excluded: ($tags - $selectable)}' \
|
||||
excluded: ($tags - $selectable), disabled: $disabled}' \
|
||||
> "$RUNTIME_DIR/outbounds.json"
|
||||
chmod 644 "$RUNTIME_DIR/outbounds.json"
|
||||
'';
|
||||
@@ -640,4 +661,6 @@ let
|
||||
in
|
||||
{
|
||||
inherit mkOutboundScript rawOutboundJson;
|
||||
# For the checks: which outbounds a pin and selection may take.
|
||||
selectionBlocks = pinBlock + selectableBlock + inventoryBlock;
|
||||
}
|
||||
@@ -154,7 +154,6 @@ let
|
||||
proxyInboundsGuardPrivate
|
||||
;
|
||||
userDnsRules = proxyCfg.dns.singBox.rules;
|
||||
inherit (proxyCfg) selectionExclude;
|
||||
};
|
||||
backendJqFilterFile = pkgs.writeText "proxy-suite-core" backendJqFilter;
|
||||
|
||||
@@ -234,6 +233,7 @@ let
|
||||
routeModeStateFile
|
||||
pinnedOutboundFile
|
||||
outboundInventoryFile
|
||||
runtimeOutboundsDir
|
||||
subscriptionCacheDir
|
||||
subscriptionCacheHelpersBlock
|
||||
mkSubscriptionFetchBlock
|
||||
|
||||
@@ -205,12 +205,14 @@ let
|
||||
[ -s "$AUTOPROXY_DIR/state.json" ] || echo '{"domains":{},"hosts":{},"exits":{},"backlog":{}}' > "$AUTOPROXY_DIR/state.json"
|
||||
|
||||
# direct is always exit 0; state is keyed by tag, so shifting indices are
|
||||
# harmless.
|
||||
# harmless. Disabled outbounds are no exit: the prober drops what was learned
|
||||
# through them.
|
||||
PROBE_EXITS_JSON=$(${jq} -c \
|
||||
--argjson max ${toString proxyCfg.autoProxy.maxExits} \
|
||||
--argjson base ${toString proxyCfg.autoProxy.probeBasePort} \
|
||||
--argjson disabled "''${DISABLED_TAGS_JSON:-[]}" \
|
||||
--arg dir "$AUTOPROXY_DIR" '
|
||||
(["direct"] + map(select(. != "direct")))[0:$max]
|
||||
(["direct"] + map(select(. != "direct" and (. as $t | $disabled | index([$t]) | not))))[0:$max]
|
||||
| to_entries
|
||||
| map({i: .key, tag: .value, port: ($base + .key),
|
||||
rule_set: ("autoproxy-" + (.key | tostring)),
|
||||
|
||||
Reference in new issue
Block a user