fix: various fixes and additions
This commit is contained in:
30 files changed
+462
-127
No files matched your search
@@ -20,7 +20,6 @@ let
|
||||
inherit (constants)
|
||||
xrayDnsBridgePorts
|
||||
;
|
||||
direct = rules.direct;
|
||||
defaultTunAutoRouteTableIndex = constants.tunAutoRouteTableIndex;
|
||||
defaultTunAutoRouteRulePriority = constants.tunAutoRouteRulePriority;
|
||||
|
||||
@@ -62,14 +61,7 @@ let
|
||||
# The route mode keeps the user's rules and fake IP, and may drop what sits between.
|
||||
rules =
|
||||
proxyCfg.dns.singBox.rules
|
||||
++ lib.optional (builtins.elem "google" proxyCfg.routing.proxy.geosites) {
|
||||
rule_set = [ "geosite-google" ];
|
||||
server = "remote";
|
||||
}
|
||||
++ lib.optional (direct.geosites != [ ]) {
|
||||
rule_set = map (s: "geosite-${s}") direct.geosites;
|
||||
server = "local";
|
||||
}
|
||||
++ rules.singBoxDnsRules
|
||||
# Only what apps ask through the TUN: the XRay sidecar's and sing-box's own lookups
|
||||
# need real addresses.
|
||||
++ lib.optional fakeIp {
|
||||
@@ -119,14 +111,19 @@ let
|
||||
enableClashApi ? clashApiEnabled,
|
||||
enableXrayDnsBridge ? hybridEnabled,
|
||||
xrayDnsBridgePort ? xrayDnsBridgePorts.socks,
|
||||
# Names the fake IP cache: TUN configs only.
|
||||
fakeIpCache ? null,
|
||||
}:
|
||||
let
|
||||
fakeIp = fakeIpCache != null && proxyCfg.dns.fakeIp.enable;
|
||||
in
|
||||
lib.recursiveUpdate (
|
||||
{
|
||||
log.level = "warn";
|
||||
|
||||
dns = mkDnsConfig {
|
||||
localDetour = if forceLocalDnsViaProxy then "proxy" else null;
|
||||
inherit useOutboundRoutingMark;
|
||||
fakeIp = enableTun && proxyCfg.dns.fakeIp.enable;
|
||||
inherit useOutboundRoutingMark fakeIp;
|
||||
};
|
||||
|
||||
inbounds =
|
||||
@@ -190,7 +187,17 @@ let
|
||||
auto_detect_interface = true;
|
||||
};
|
||||
}
|
||||
// lib.optionalAttrs enableClashApi clashApiBlock;
|
||||
// lib.optionalAttrs enableClashApi clashApiBlock)
|
||||
# Fake addresses handed out survive a restart, so apps still holding one keep working. The
|
||||
# start script creates the directory; nothing else is stored, since TUN configs have no
|
||||
# Clash API to switch a selector with.
|
||||
(lib.optionalAttrs fakeIp {
|
||||
experimental.cache_file = {
|
||||
enabled = true;
|
||||
path = "${constants.fakeIpCacheDir}/${fakeIpCache}.db";
|
||||
store_fakeip = true;
|
||||
};
|
||||
});
|
||||
in
|
||||
{
|
||||
tproxy = mkConfig {
|
||||
@@ -211,6 +218,7 @@ in
|
||||
forceLocalDnsViaProxy = false;
|
||||
enableClashApi = false;
|
||||
xrayDnsBridgePort = xrayDnsBridgePorts.tun;
|
||||
fakeIpCache = "tun";
|
||||
};
|
||||
|
||||
perAppTun = mkConfig {
|
||||
@@ -225,5 +233,6 @@ in
|
||||
useOutboundRoutingMark = globalTproxy.enable;
|
||||
enableClashApi = false;
|
||||
xrayDnsBridgePort = xrayDnsBridgePorts.perAppTun;
|
||||
fakeIpCache = "per-app-tun";
|
||||
};
|
||||
}
|
||||
@@ -104,8 +104,21 @@ let
|
||||
proxyInboundViaTags = lib.unique (
|
||||
builtins.filter (via: !builtins.elem via builtinTags) (map (ib: ib.via) proxyInbounds)
|
||||
);
|
||||
# The pinned outbounds and every hop they chain through, which the inbound service renders
|
||||
# too. A hop that is not a static outbound (a subscription entry, warp) has no tag here.
|
||||
proxyInboundViaHops =
|
||||
tags:
|
||||
let
|
||||
hops = lib.unique (
|
||||
builtins.filter (hop: hop != null && !builtins.elem hop tags) (
|
||||
map (ob: ob.detour) (builtins.filter (ob: builtins.elem ob.tag tags) proxyCfg.outbounds)
|
||||
)
|
||||
);
|
||||
in
|
||||
if hops == [ ] then tags else proxyInboundViaHops (tags ++ hops);
|
||||
proxyInboundViaChain = proxyInboundViaHops proxyInboundViaTags;
|
||||
proxyInboundViaOutbounds = builtins.filter (
|
||||
ob: builtins.elem ob.tag proxyInboundViaTags
|
||||
ob: builtins.elem ob.tag proxyInboundViaChain
|
||||
) proxyCfg.outbounds;
|
||||
|
||||
proxyInboundUdpTypes = [
|
||||
@@ -242,6 +255,8 @@ let
|
||||
outboundInventoryFile = "/run/proxy-suite-socks/outbounds.json";
|
||||
|
||||
inboundStatsApiPort = 18536;
|
||||
# sing-box's fake IP caches, one per TUN config; the start script hands it to the backend.
|
||||
fakeIpCacheDir = "/var/lib/proxy-suite/fakeip";
|
||||
# Loopback listener behind the selector `proxy-ctl proxy outbounds test` switches.
|
||||
outboundTestPort = 18537;
|
||||
inboundStatsFile = "/var/lib/proxy-suite/inbound-stats.json";
|
||||
@@ -275,7 +290,7 @@ let
|
||||
# Subscription tags are deliberately not accepted: they only exist at runtime.
|
||||
invalidInboundViaTargets = builtins.filter (
|
||||
tag: !builtins.elem tag outboundTags
|
||||
) proxyInboundViaTags;
|
||||
) proxyInboundViaChain;
|
||||
|
||||
invalidRoutingTargets = lib.unique (
|
||||
map (rule: rule.outbound) (
|
||||
|
||||
@@ -24,7 +24,11 @@ in
|
||||
remote = mkOption {
|
||||
type = t.dnsUpstreamType;
|
||||
default = cloudflare;
|
||||
description = "Resolver used through the proxy; the DNS default when proxy.routing.default is proxy.";
|
||||
description = ''
|
||||
Resolver used through the proxy; the DNS default when proxy.routing.default is proxy. On
|
||||
sing-box, names the routing sends through the proxy are always looked up here, so the ISP
|
||||
never sees them, and direct ones locally.
|
||||
'';
|
||||
example = {
|
||||
type = "tls";
|
||||
address = "1.1.1.1";
|
||||
@@ -64,9 +68,9 @@ in
|
||||
In TUN mode (global and per-app), answer A queries from the TUN with a fake address and
|
||||
AAAA ones with nothing; sing-box maps the address back to the name when the connection
|
||||
comes. Saves a lookup per new site and no real lookup leaves for proxied names. Names that
|
||||
proxy.dns.singBox.rules or the direct geosites send elsewhere keep real answers. Mappings
|
||||
do not survive a restart: an app holding a fake address fails until it looks the name up
|
||||
again. sing-box and hybrid backends; XRay's TUN already uses its own fake DNS.
|
||||
proxy.dns.singBox.rules or the direct routing lists send elsewhere keep real answers. The
|
||||
addresses handed out are kept in /var/lib/proxy-suite/fakeip, so they survive a restart.
|
||||
sing-box and hybrid backends; XRay's TUN already uses its own fake DNS.
|
||||
'';
|
||||
};
|
||||
|
||||
|
||||
@@ -68,6 +68,18 @@ in
|
||||
example = "urltest";
|
||||
};
|
||||
|
||||
selectionExclude = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Outbound tags selection never picks on its own: hops other outbounds chain through
|
||||
(`detour`), or exits only routing rules name. Subscription entries, `warp`, `ssh-proxy`
|
||||
and AmneziaWG tags work too. A pin still reaches them, and so does a selector switched by
|
||||
hand.
|
||||
'';
|
||||
example = [ "ru-vps" "warp" ];
|
||||
};
|
||||
|
||||
urlTest = {
|
||||
url = mkOption {
|
||||
type = types.str;
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
# the backend: sing-box sets detour, XRay sockopt.dialerProxy. In hybrid, .xray holds the
|
||||
# sidecar's outbounds, each also standing in .outbounds as a loopback SOCKS hop: a
|
||||
# sing-box outbound may chain through either, a sidecar one only through another
|
||||
# sidecar one, since the sidecar cannot dial through sing-box.
|
||||
# sidecar one, since the sidecar cannot dial through sing-box. Each error is
|
||||
# {tag, message}, the tag being the outbound that cannot be chained.
|
||||
def dialer($h): .streamSettings.sockopt.dialerProxy = $h;
|
||||
|
||||
([.outbounds[].tag]) as $tags
|
||||
@@ -19,14 +20,14 @@ def dialer($h): .streamSettings.sockopt.dialerProxy = $h;
|
||||
) | from_entries) as $hops
|
||||
| .errors = (
|
||||
[$hops | to_entries[] | select(.value as $v | $tags | index([$v]) | not)
|
||||
| "outbound '\(.key)' chains through '\(.value)', which is not an outbound"]
|
||||
| {tag: .key, message: "outbound '\(.key)' chains through '\(.value)', which is not an outbound"}]
|
||||
+ [$hops | keys[] as $t
|
||||
| select([limit($hops | length + 1; $t | recurse($hops[.] // empty))][1:] | any(. == $t))
|
||||
| "outbound '\($t)' chains back to itself"]
|
||||
| {tag: $t, message: "outbound '\($t)' chains back to itself"}]
|
||||
+ (if $kind == "hybrid" then
|
||||
[$hops | to_entries[]
|
||||
| select((.key as $t | $xtags | index([$t])) and (.value as $v | $xtags | index([$v]) | not))
|
||||
| "outbound '\(.key)' runs on XRay and can only chain through another XRay outbound, not '\(.value)'"]
|
||||
| {tag: .key, message: "outbound '\(.key)' runs on XRay and can only chain through another XRay outbound, not '\(.value)'"}]
|
||||
else [] end)
|
||||
)
|
||||
| if .errors != [] then .
|
||||
|
||||
@@ -84,6 +84,7 @@ let
|
||||
geoIPRuleSets
|
||||
singBoxRoutingRules
|
||||
singBoxRouteModeRules
|
||||
singBoxDnsRules
|
||||
;
|
||||
|
||||
xrayRules = import ./rules/xray.nix {
|
||||
@@ -111,6 +112,7 @@ in
|
||||
geoIPRuleSets
|
||||
singBoxRoutingRules
|
||||
singBoxRouteModeRules
|
||||
singBoxDnsRules
|
||||
xrayRoutingRules
|
||||
xrayRouteModeRules
|
||||
routeModeRules
|
||||
|
||||
@@ -116,6 +116,31 @@ let
|
||||
++ blockRules
|
||||
++ proxyGeoRules;
|
||||
|
||||
# DNS follows the routing: a name that goes through the proxy is looked up through it, so
|
||||
# the ISP's resolver never sees it and cannot spoof the answer; a direct one is looked up
|
||||
# locally. In the routing's order; block entries resolve however the final says.
|
||||
mkDnsRules =
|
||||
server: domains: geosites:
|
||||
lib.optional (domains != [ ]) {
|
||||
domain_suffix = domains;
|
||||
inherit server;
|
||||
}
|
||||
++ lib.optional (geosites != [ ]) {
|
||||
rule_set = map (s: "geosite-${s}") geosites;
|
||||
inherit server;
|
||||
};
|
||||
dnsServerFor = category: if category == "direct" then "local" else "remote";
|
||||
singBoxDnsRules =
|
||||
lib.concatMap (
|
||||
rule:
|
||||
lib.optionals (customRuleCategory rule.outbound != "block") (
|
||||
mkDnsRules (dnsServerFor (customRuleCategory rule.outbound)) rule.domains rule.geosites
|
||||
)
|
||||
) customRules
|
||||
++ mkDnsRules "remote" r.proxy.domains [ ]
|
||||
++ mkDnsRules "local" direct.domains direct.geosites
|
||||
++ mkDnsRules "remote" [ ] r.proxy.geosites;
|
||||
|
||||
singBoxRouteModeRules = {
|
||||
common = commonRules;
|
||||
custom = customRouteRules;
|
||||
@@ -132,5 +157,6 @@ in
|
||||
geoIPRuleSets
|
||||
singBoxRoutingRules
|
||||
singBoxRouteModeRules
|
||||
singBoxDnsRules
|
||||
;
|
||||
}
|
||||
@@ -269,14 +269,11 @@ let
|
||||
|
||||
proxyInboundAssertions = [
|
||||
(mkAssertion (!proxyInboundsEnabled || derived.invalidInboundViaTargets == [ ])
|
||||
"proxy-suite: inbounds via targets are not defined in proxy.outbounds: ${lib.concatStringsSep ", " derived.invalidInboundViaTargets}. Subscription proxies cannot be named here because their tags only exist at runtime; use via = \"proxy\" to reach those."
|
||||
"proxy-suite: inbounds via targets, or the hops they chain through, are not defined in proxy.outbounds: ${lib.concatStringsSep ", " derived.invalidInboundViaTargets}. Subscription proxies, warp, ssh-proxy and AmneziaWG outbounds cannot be named here because the inbound service does not run them; use via = \"proxy\" to reach those."
|
||||
)
|
||||
(mkAssertion (!proxyInboundsEnabled || singBoxOnlyPinnedTags == [ ])
|
||||
"proxy-suite: inbounds via targets a sing-box-only outbound: ${lib.concatStringsSep ", " singBoxOnlyPinnedTags}. The inbound service runs XRay, so a pinned outbound needs url, urlFile, or xrayJson."
|
||||
)
|
||||
(mkAssertion (
|
||||
!proxyInboundsEnabled || builtins.all (ob: ob.detour == null) derived.proxyInboundViaOutbounds
|
||||
) "proxy-suite: inbounds via targets a chained outbound (one with detour), which the inbound service cannot render; use via = \"proxy\"")
|
||||
(requireEnabled (proxyInboundsEnabled && derived.proxyInboundViaTags != [ ]) proxyEnabled
|
||||
"proxy-suite: inbounds pins a listener to a proxy.outbounds tag, which requires proxy.enable = true"
|
||||
)
|
||||
|
||||
@@ -54,6 +54,10 @@ let
|
||||
mkViaOutboundBlock =
|
||||
ob:
|
||||
let
|
||||
# A chained one dials through its hop, which the chain put in this config too.
|
||||
dialerBlock = lib.optionalString (ob.detour != null) ''
|
||||
OB_JSON=$(${jq} -c --arg hop ${lib.escapeShellArg ob.detour} '.streamSettings.sockopt.dialerProxy = $hop' <<< "$OB_JSON")
|
||||
'';
|
||||
urlSource =
|
||||
if ob.urlFile != null then
|
||||
ob.urlFile
|
||||
@@ -70,6 +74,7 @@ let
|
||||
builtins.toJSON (ob.xrayJson // { inherit (ob) tag; })
|
||||
)
|
||||
})
|
||||
${dialerBlock}
|
||||
OUTBOUNDS_JSON=$(${jq} --argjson ob "$OB_JSON" '. + [$ob]' <<< "$OUTBOUNDS_JSON")
|
||||
''
|
||||
else
|
||||
@@ -78,6 +83,7 @@ let
|
||||
URL=$(cat ${lib.escapeShellArg urlSource})
|
||||
OB_JSON=$(printf '%s' "$URL" | PYTHONPATH="${parserScriptsPythonPath}" ${python3} ${buildOutboundPy} \
|
||||
--backend xray --tag ${lib.escapeShellArg ob.tag})
|
||||
${dialerBlock}
|
||||
OUTBOUNDS_JSON=$(${jq} --argjson ob "$OB_JSON" '. + [$ob]' <<< "$OUTBOUNDS_JSON")
|
||||
'';
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
pureXrayEnabled,
|
||||
selectionMode,
|
||||
proxyInboundsGuardPrivate,
|
||||
userDnsRules,
|
||||
userDnsRules ? [ ],
|
||||
selectionExclude ? [ ],
|
||||
}:
|
||||
|
||||
if pureXrayEnabled then
|
||||
@@ -76,6 +77,14 @@ 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
|
||||
''}
|
||||
| if $xray_single_proxy_tag == "" then
|
||||
.
|
||||
else
|
||||
|
||||
@@ -441,13 +441,18 @@ let
|
||||
mkBackendOutboundBlock = if hybridEnabled then mkHybridOutboundBlock else mkOutboundBlock;
|
||||
|
||||
runtimeOutboundsBlock = ''
|
||||
# outbounds added at runtime
|
||||
# outbounds added at runtime, and the hop each one chains through (<tag>.detour)
|
||||
RUNTIME_DETOURS_JSON='{}'
|
||||
while IFS=$'\t' read -r RUNTIME_OB_TAG RUNTIME_OB_SRC; do
|
||||
[ -n "$RUNTIME_OB_TAG" ] || continue
|
||||
case "$RUNTIME_OB_SRC" in
|
||||
*.json) _proxy_suite_add_json_outbound "$RUNTIME_OB_TAG" "$RUNTIME_OB_SRC" runtime ;;
|
||||
*) _proxy_suite_add_url_outbound "$RUNTIME_OB_TAG" "$(cat "$RUNTIME_OB_SRC")" runtime ;;
|
||||
esac || echo "proxy-suite: warning: ignoring runtime outbound '$RUNTIME_OB_TAG'" >&2
|
||||
esac || { echo "proxy-suite: warning: ignoring runtime outbound '$RUNTIME_OB_TAG'" >&2; continue; }
|
||||
if [ -s "${runtimeOutboundsDir}/$RUNTIME_OB_TAG.detour" ]; then
|
||||
RUNTIME_DETOURS_JSON=$(${jq} -c --arg t "$RUNTIME_OB_TAG" --rawfile h "${runtimeOutboundsDir}/$RUNTIME_OB_TAG.detour" \
|
||||
'.[$t] = ($h | rtrimstr("\n"))' <<< "$RUNTIME_DETOURS_JSON")
|
||||
fi
|
||||
done < <(_proxy_suite_runtime_outbounds)
|
||||
'';
|
||||
|
||||
@@ -465,26 +470,43 @@ let
|
||||
"xray"
|
||||
else
|
||||
"sing-box";
|
||||
detourBlock = lib.optionalString (detours.outbounds != { } || detours.subscriptions != { }) ''
|
||||
# Always there: `proxy-ctl proxy outbounds add --detour` chains runtime outbounds too. A
|
||||
# declared chain that cannot be built fails the start. A runtime one is left out with a
|
||||
# warning, like any other runtime outbound that does not come up, rather than going out
|
||||
# unchained; whatever chained through it is checked again.
|
||||
detourBlock = ''
|
||||
# outbound chaining
|
||||
DETOUR_RESULT=$(${jq} -c --argjson xob "${
|
||||
if hybridEnabled then "$XRAY_OUTBOUNDS_JSON" else "[]"
|
||||
}" '{outbounds: ., xray: $xob}' <<< "$OUTBOUNDS_JSON" \
|
||||
| ${jq} -c -f ${
|
||||
builtins.path {
|
||||
name = "proxy-suite-outbound-detours";
|
||||
path = ../../outbound-detours.jq;
|
||||
}
|
||||
} \
|
||||
--argjson d ${lib.escapeShellArg (builtins.toJSON detours)} \
|
||||
--argjson sources "$OUTBOUND_SOURCES_JSON" \
|
||||
--arg kind ${detourKind})
|
||||
if ${jq} -e '.errors != []' <<< "$DETOUR_RESULT" >/dev/null; then
|
||||
${jq} -r '.errors[] | "proxy-suite: " + .' <<< "$DETOUR_RESULT" >&2
|
||||
exit 1
|
||||
fi
|
||||
OUTBOUNDS_JSON=$(${jq} -c '.outbounds' <<< "$DETOUR_RESULT")
|
||||
${lib.optionalString hybridEnabled ''XRAY_OUTBOUNDS_JSON=$(${jq} -c '.xray' <<< "$DETOUR_RESULT")''}
|
||||
DETOURS_JSON=$(${jq} -c --argjson runtime "$RUNTIME_DETOURS_JSON" '.outbounds = $runtime + .outbounds' \
|
||||
<<< ${lib.escapeShellArg (builtins.toJSON detours)})
|
||||
while [ "$DETOURS_JSON" != '{"outbounds":{},"subscriptions":{}}' ]; do
|
||||
DETOUR_RESULT=$(${jq} -c --argjson xob "${
|
||||
if hybridEnabled then "$XRAY_OUTBOUNDS_JSON" else "[]"
|
||||
}" '{outbounds: ., xray: $xob}' <<< "$OUTBOUNDS_JSON" \
|
||||
| ${jq} -c -f ${
|
||||
builtins.path {
|
||||
name = "proxy-suite-outbound-detours";
|
||||
path = ../../outbound-detours.jq;
|
||||
}
|
||||
} \
|
||||
--argjson d "$DETOURS_JSON" \
|
||||
--argjson sources "$OUTBOUND_SOURCES_JSON" \
|
||||
--arg kind ${detourKind})
|
||||
DETOUR_DROP=$(${jq} -c --argjson sources "$OUTBOUND_SOURCES_JSON" \
|
||||
'[.errors[] | select($sources[.tag] == "runtime")] | unique_by(.tag)' <<< "$DETOUR_RESULT")
|
||||
if ${jq} -e --argjson sources "$OUTBOUND_SOURCES_JSON" 'any(.errors[]; $sources[.tag] != "runtime")' <<< "$DETOUR_RESULT" >/dev/null; then
|
||||
${jq} -r '.errors[] | "proxy-suite: " + .message' <<< "$DETOUR_RESULT" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ "$DETOUR_DROP" = '[]' ]; then
|
||||
OUTBOUNDS_JSON=$(${jq} -c '.outbounds' <<< "$DETOUR_RESULT")
|
||||
${lib.optionalString hybridEnabled ''XRAY_OUTBOUNDS_JSON=$(${jq} -c '.xray' <<< "$DETOUR_RESULT")''}
|
||||
break
|
||||
fi
|
||||
${jq} -r '.[] | "proxy-suite: warning: ignoring runtime outbound '"'"'\(.tag)'"'"': \(.message)"' <<< "$DETOUR_DROP" >&2
|
||||
OUTBOUNDS_JSON=$(${jq} -c --argjson drop "$DETOUR_DROP" '[.[] | select(.tag as $t | $drop | any(.tag == $t) | not)]' <<< "$OUTBOUNDS_JSON")
|
||||
${lib.optionalString hybridEnabled ''XRAY_OUTBOUNDS_JSON=$(${jq} -c --argjson drop "$DETOUR_DROP" '[.[] | select(.tag as $t | $drop | any(.tag == $t) | not)]' <<< "$XRAY_OUTBOUNDS_JSON")''}
|
||||
DETOURS_JSON=$(${jq} -c --argjson drop "$DETOUR_DROP" '.outbounds |= with_entries(select(.key as $t | $drop | any(.tag == $t) | not))' <<< "$DETOURS_JSON")
|
||||
done
|
||||
'';
|
||||
|
||||
requireOutboundsBlock = ''
|
||||
@@ -510,14 +532,32 @@ let
|
||||
fi
|
||||
'';
|
||||
|
||||
# proxy-ctl reads this unprivileged: tags, where each came from, and the pin.
|
||||
# What selection may pick on its own: all but proxy.selectionExclude. A pin and a
|
||||
# selector switched by hand still reach the excluded ones.
|
||||
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")
|
||||
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
|
||||
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.
|
||||
inventoryBlock = ''
|
||||
${jq} -n \
|
||||
--argjson tags "$OUTBOUND_TAGS_JSON" \
|
||||
--argjson sources "$OUTBOUND_SOURCES_JSON" \
|
||||
--arg pinned "$PINNED_OUTBOUND" \
|
||||
--arg selection ${lib.escapeShellArg selectionMode} \
|
||||
'{tags: $tags, sources: $sources, pinned: $pinned, selection: $selection}' \
|
||||
--argjson obs "$OUTBOUNDS_JSON" \
|
||||
--argjson xobs "${if hybridEnabled then "$XRAY_OUTBOUNDS_JSON" else "[]"}" \
|
||||
--argjson selectable "$SELECTABLE_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)}' \
|
||||
> "$RUNTIME_DIR/outbounds.json"
|
||||
chmod 644 "$RUNTIME_DIR/outbounds.json"
|
||||
'';
|
||||
@@ -548,15 +588,15 @@ let
|
||||
# which is the same path a single-outbound config already takes.
|
||||
if [ -n "$PINNED_OUTBOUND" ]; then
|
||||
XRAY_SINGLE_PROXY_TAG="proxy-suite-ob-$PINNED_OUTBOUND"
|
||||
elif [ "$(${jq} 'length' <<< "$OUTBOUNDS_JSON")" -eq 1 ]; then
|
||||
XRAY_SINGLE_PROXY_TAG="$(${jq} -r '.[0].tag' <<< "$OUTBOUNDS_JSON")"
|
||||
elif [ "$(${jq} 'length' <<< "$SELECTABLE_TAGS_JSON")" -eq 1 ]; then
|
||||
XRAY_SINGLE_PROXY_TAG="proxy-suite-ob-$(${jq} -r '.[0]' <<< "$SELECTABLE_TAGS_JSON")"
|
||||
fi
|
||||
''
|
||||
else if collapseNamedOutbounds then
|
||||
''
|
||||
PROXY_TAG="$PINNED_OUTBOUND"
|
||||
if [ -z "$PROXY_TAG" ]; then
|
||||
PROXY_TAG=$(${jq} -r '.[0].tag' <<< "$OUTBOUNDS_JSON")
|
||||
PROXY_TAG=$(${jq} -r '.[0]' <<< "$SELECTABLE_TAGS_JSON")
|
||||
fi
|
||||
OUTBOUNDS_JSON=$(${jq} --arg t "$PROXY_TAG" \
|
||||
'map(if .tag == $t then .tag = "proxy" else . end
|
||||
@@ -568,7 +608,7 @@ let
|
||||
TAGS=$(${jq} '[.[].tag]' <<< "$OUTBOUNDS_JSON")
|
||||
DEFAULT_TAG="$PINNED_OUTBOUND"
|
||||
if [ -z "$DEFAULT_TAG" ]; then
|
||||
DEFAULT_TAG=$(${jq} -r '.[0].tag' <<< "$OUTBOUNDS_JSON")
|
||||
DEFAULT_TAG=$(${jq} -r '.[0]' <<< "$SELECTABLE_TAGS_JSON")
|
||||
fi
|
||||
WRAPPER=$(${jq} -n \
|
||||
--argjson tags "$TAGS" \
|
||||
@@ -588,7 +628,7 @@ let
|
||||
'{type:"selector",tag:"proxy",outbounds:$tags,default:$default}')
|
||||
else
|
||||
WRAPPER=$(${jq} -n \
|
||||
--argjson tags "$TAGS" \
|
||||
--argjson tags "$SELECTABLE_TAGS_JSON" \
|
||||
--arg url ${lib.escapeShellArg proxyCfg.urlTest.url} \
|
||||
--arg interval ${lib.escapeShellArg proxyCfg.urlTest.interval} \
|
||||
--argjson tolerance ${toString singBoxCfg.urlTest.tolerance} \
|
||||
@@ -614,6 +654,7 @@ let
|
||||
+ detourBlock
|
||||
+ requireOutboundsBlock
|
||||
+ pinBlock
|
||||
+ selectableBlock
|
||||
+ inventoryBlock
|
||||
+ wrapperBlock
|
||||
+ exitTagsBlock;
|
||||
|
||||
@@ -151,6 +151,7 @@ let
|
||||
proxyInboundsGuardPrivate
|
||||
;
|
||||
userDnsRules = proxyCfg.dns.singBox.rules;
|
||||
inherit (proxyCfg) selectionExclude;
|
||||
};
|
||||
backendJqFilterFile = pkgs.writeText "proxy-suite-core" backendJqFilter;
|
||||
|
||||
|
||||
@@ -338,6 +338,7 @@ let
|
||||
--arg xray_loglevel "$XRAY_LOGLEVEL" \
|
||||
--arg xray_bind_interface "$XRAY_TUN_BIND_INTERFACE" \
|
||||
--arg xray_single_proxy_tag "$XRAY_SINGLE_PROXY_TAG" \
|
||||
--argjson xray_selectable "$SELECTABLE_TAGS_JSON" \
|
||||
--argjson xray_tun_dns_runtime ${if xrayTunDnsRuntime then "true" else "false"} \
|
||||
--arg xray_dns_local_client ${lib.escapeShellArg proxyCfg.dns.local.address} \
|
||||
--arg xray_dns_remote_client ${lib.escapeShellArg proxyCfg.dns.remote.address} \
|
||||
@@ -349,6 +350,10 @@ let
|
||||
${pkgs.coreutils}/bin/chgrp ${constants.serviceUser} "$backend_config"
|
||||
chmod ${if enableLocalProxyAuth then "640" else "g+r"} "$backend_config"
|
||||
done
|
||||
FAKE_IP_CACHE=$(${jq} -r '.experimental.cache_file.path? // empty' "$RUNTIME_DIR/config.json")
|
||||
if [ -n "$FAKE_IP_CACHE" ]; then
|
||||
install -d -m 0700 -o ${constants.serviceUser} -g ${constants.serviceUser} "$(dirname "$FAKE_IP_CACHE")"
|
||||
fi
|
||||
|
||||
${
|
||||
if hybridEnabled then
|
||||
|
||||
Reference in new issue
Block a user