fix: zapret2 & naming fixes
This commit is contained in:
32 files changed
+580
-261
No files matched your search
@@ -5,7 +5,7 @@
|
||||
proxyCfg,
|
||||
clashApi,
|
||||
routeModeStateFile,
|
||||
priorityOutboundFile,
|
||||
pinnedOutboundFile,
|
||||
outboundInventoryFile,
|
||||
subscriptionCacheDir,
|
||||
subscriptionCacheHelpersBlock,
|
||||
@@ -77,20 +77,15 @@ let
|
||||
${restartActiveConfigConsumersBlock}
|
||||
'';
|
||||
|
||||
# Pins the outbound the proxy prefers, or "auto" to hand the choice back to the
|
||||
# configured selection. The pin is persisted either way; a live Clash API switch
|
||||
# only saves the restart.
|
||||
setPriorityOutboundScript = pkgs.writeShellScript "proxy-suite-core" ''
|
||||
# Pins the outbound the proxy prefers; without a tag, unpins it and hands the choice
|
||||
# back to the configured selection. The pin is persisted either way; a live Clash
|
||||
# API switch only saves the restart.
|
||||
pinOutboundScript = pkgs.writeShellScript "proxy-suite-core" ''
|
||||
set -euo pipefail
|
||||
tag="''${1:-}"
|
||||
|
||||
if [ -z "$tag" ]; then
|
||||
echo "proxy-suite: usage: proxy-suite-set-priority-outbound <tag|auto>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$tag" = "auto" ]; then
|
||||
rm -f "${priorityOutboundFile}"
|
||||
rm -f "${pinnedOutboundFile}"
|
||||
else
|
||||
# The inventory only exists once the proxy has run. Without it there is
|
||||
# nothing to check against, so accept the tag and let the start script warn
|
||||
@@ -100,8 +95,8 @@ let
|
||||
echo "proxy-suite: unknown outbound '$tag'" >&2
|
||||
exit 1
|
||||
fi
|
||||
mkdir -p "$(dirname "${priorityOutboundFile}")"
|
||||
printf '%s\n' "$tag" > "${priorityOutboundFile}"
|
||||
mkdir -p "$(dirname "${pinnedOutboundFile}")"
|
||||
printf '%s\n' "$tag" > "${pinnedOutboundFile}"
|
||||
# Live switch when the running config exposes a selector; the persisted pin
|
||||
# is what keeps it after the next restart.
|
||||
if ${curl} -sf -X PUT "${clashApi}/proxies/proxy" \
|
||||
@@ -146,7 +141,7 @@ in
|
||||
inherit
|
||||
subscriptionUpdateScript
|
||||
setRouteModeScript
|
||||
setPriorityOutboundScript
|
||||
pinOutboundScript
|
||||
reloadOutboundsScript
|
||||
;
|
||||
}
|
||||
@@ -46,7 +46,6 @@
|
||||
zapretAutoEnabled = if zapretEngine == "zapret2" then "1" else "0";
|
||||
zapretStateDir = constants.zapret2StateDir;
|
||||
zapretCutoffEnabled = if zapretCutoffEnabled then "1" else "0";
|
||||
priorityOutboundFile = constants.priorityOutboundFile;
|
||||
outboundInventoryFile = constants.outboundInventoryFile;
|
||||
runtimeOutboundsDir = constants.runtimeOutboundsDir;
|
||||
runtimeSubscriptionsDir = constants.runtimeSubscriptionsDir;
|
||||
|
||||
@@ -15,9 +15,8 @@ let
|
||||
}
|
||||
''
|
||||
+ lib.optionalString (builtins.elem "global" userControlCfg.allow) ''
|
||||
if ((unit.indexOf("proxy-suite-") === 0 &&
|
||||
unit.indexOf("proxy-suite-per-app-") !== 0) ||
|
||||
unit === "zapret-discord-youtube.service") {
|
||||
if (unit.indexOf("proxy-suite-") === 0 &&
|
||||
unit.indexOf("proxy-suite-per-app-") !== 0) {
|
||||
return polkit.Result.YES;
|
||||
}
|
||||
'';
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
backend,
|
||||
backendArg,
|
||||
xraySidecarRoutingMark,
|
||||
priorityOutboundFile,
|
||||
pinnedOutboundFile,
|
||||
runtimeOutboundsDir,
|
||||
jq,
|
||||
python3,
|
||||
@@ -373,14 +373,14 @@ let
|
||||
# entry that went away, say - is dropped rather than left to break the config.
|
||||
pinBlock = ''
|
||||
OUTBOUND_TAGS_JSON=$(${jq} -c '[.[].tag]' <<< "$OUTBOUNDS_JSON")
|
||||
PRIORITY_OUTBOUND=""
|
||||
if [ -r "${priorityOutboundFile}" ]; then
|
||||
PRIORITY_OUTBOUND="$(tr -d '\r\n[:space:]' < "${priorityOutboundFile}" 2>/dev/null || true)"
|
||||
PINNED_OUTBOUND=""
|
||||
if [ -r "${pinnedOutboundFile}" ]; then
|
||||
PINNED_OUTBOUND="$(tr -d '\r\n[:space:]' < "${pinnedOutboundFile}" 2>/dev/null || true)"
|
||||
fi
|
||||
if [ -n "$PRIORITY_OUTBOUND" ] \
|
||||
&& ! ${jq} -e --arg t "$PRIORITY_OUTBOUND" 'index($t) != null' <<< "$OUTBOUND_TAGS_JSON" >/dev/null; then
|
||||
echo "proxy-suite: warning: pinned outbound '$PRIORITY_OUTBOUND' is not available; picking automatically" >&2
|
||||
PRIORITY_OUTBOUND=""
|
||||
if [ -n "$PINNED_OUTBOUND" ] \
|
||||
&& ! ${jq} -e --arg t "$PINNED_OUTBOUND" 'index($t) != null' <<< "$OUTBOUND_TAGS_JSON" >/dev/null; then
|
||||
echo "proxy-suite: warning: pinned outbound '$PINNED_OUTBOUND' is not available; picking automatically" >&2
|
||||
PINNED_OUTBOUND=""
|
||||
fi
|
||||
'';
|
||||
|
||||
@@ -389,7 +389,7 @@ let
|
||||
${jq} -n \
|
||||
--argjson tags "$OUTBOUND_TAGS_JSON" \
|
||||
--argjson sources "$OUTBOUND_SOURCES_JSON" \
|
||||
--arg pinned "$PRIORITY_OUTBOUND" \
|
||||
--arg pinned "$PINNED_OUTBOUND" \
|
||||
--arg selection ${lib.escapeShellArg selectionMode} \
|
||||
'{tags: $tags, sources: $sources, pinned: $pinned, selection: $selection}' \
|
||||
> "$RUNTIME_DIR/outbounds.json"
|
||||
@@ -416,15 +416,15 @@ let
|
||||
OUTBOUNDS_JSON=$(${jq} 'map(.tag = ("proxy-suite-ob-" + .tag))' <<< "$OUTBOUNDS_JSON")
|
||||
# XRay has no selector: a pin degrades the balancer to the one outbound,
|
||||
# which is the same path a single-outbound config already takes.
|
||||
if [ -n "$PRIORITY_OUTBOUND" ]; then
|
||||
XRAY_SINGLE_PROXY_TAG="proxy-suite-ob-$PRIORITY_OUTBOUND"
|
||||
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")"
|
||||
fi
|
||||
''
|
||||
else if collapseNamedOutbounds then
|
||||
''
|
||||
PROXY_TAG="$PRIORITY_OUTBOUND"
|
||||
PROXY_TAG="$PINNED_OUTBOUND"
|
||||
if [ -z "$PROXY_TAG" ]; then
|
||||
PROXY_TAG=$(${jq} -r '.[0].tag' <<< "$OUTBOUNDS_JSON")
|
||||
fi
|
||||
@@ -434,7 +434,7 @@ let
|
||||
else if selectionMode == "selector" then
|
||||
''
|
||||
TAGS=$(${jq} '[.[].tag]' <<< "$OUTBOUNDS_JSON")
|
||||
DEFAULT_TAG="$PRIORITY_OUTBOUND"
|
||||
DEFAULT_TAG="$PINNED_OUTBOUND"
|
||||
if [ -z "$DEFAULT_TAG" ]; then
|
||||
DEFAULT_TAG=$(${jq} -r '.[0].tag' <<< "$OUTBOUNDS_JSON")
|
||||
fi
|
||||
@@ -447,12 +447,12 @@ let
|
||||
else
|
||||
''
|
||||
TAGS=$(${jq} '[.[].tag]' <<< "$OUTBOUNDS_JSON")
|
||||
if [ -n "$PRIORITY_OUTBOUND" ]; then
|
||||
if [ -n "$PINNED_OUTBOUND" ]; then
|
||||
# A pin beats latency ranking: the same outbounds, behind a selector
|
||||
# the Clash API can also switch live.
|
||||
WRAPPER=$(${jq} -n \
|
||||
--argjson tags "$TAGS" \
|
||||
--arg default "$PRIORITY_OUTBOUND" \
|
||||
--arg default "$PINNED_OUTBOUND" \
|
||||
'{type:"selector",tag:"proxy",outbounds:$tags,default:$default}')
|
||||
else
|
||||
WRAPPER=$(${jq} -n \
|
||||
|
||||
@@ -57,7 +57,7 @@ let
|
||||
null;
|
||||
routeModeStateFile = "/run/proxy-suite/route-mode";
|
||||
inherit (constants)
|
||||
priorityOutboundFile
|
||||
pinnedOutboundFile
|
||||
runtimeOutboundsDir
|
||||
runtimeSubscriptionsDir
|
||||
outboundInventoryFile
|
||||
@@ -118,7 +118,7 @@ let
|
||||
backend
|
||||
backendArg
|
||||
xraySidecarRoutingMark
|
||||
priorityOutboundFile
|
||||
pinnedOutboundFile
|
||||
runtimeOutboundsDir
|
||||
jq
|
||||
python3
|
||||
@@ -220,7 +220,7 @@ let
|
||||
proxyCfg
|
||||
clashApi
|
||||
routeModeStateFile
|
||||
priorityOutboundFile
|
||||
pinnedOutboundFile
|
||||
outboundInventoryFile
|
||||
subscriptionCacheDir
|
||||
subscriptionCacheHelpersBlock
|
||||
@@ -232,7 +232,7 @@ let
|
||||
inherit (controlScripts)
|
||||
subscriptionUpdateScript
|
||||
setRouteModeScript
|
||||
setPriorityOutboundScript
|
||||
pinOutboundScript
|
||||
reloadOutboundsScript
|
||||
;
|
||||
|
||||
@@ -250,13 +250,13 @@ in
|
||||
proxyInboundsSubscriptionsFile
|
||||
routeModeStateFile
|
||||
setRouteModeScript
|
||||
setPriorityOutboundScript
|
||||
pinOutboundScript
|
||||
reloadOutboundsScript
|
||||
subscriptionUpdateScript
|
||||
subscriptionTagsFile
|
||||
subscriptionCacheDir
|
||||
runtimeProxychainsConfig
|
||||
priorityOutboundFile
|
||||
pinnedOutboundFile
|
||||
runtimeOutboundsDir
|
||||
runtimeSubscriptionsDir
|
||||
outboundInventoryFile
|
||||
|
||||
@@ -242,10 +242,20 @@ let
|
||||
}
|
||||
{
|
||||
enable = proxyEnabled;
|
||||
name = "proxy-suite-outbound-select@";
|
||||
name = "proxy-suite-outbound-pin@";
|
||||
value = mkOneshotService {
|
||||
description = "Pin the proxy-suite priority outbound to %i";
|
||||
execStart = "${scripts.setPriorityOutboundScript} %i";
|
||||
description = "Pin the proxy-suite outbound to %i";
|
||||
execStart = "${scripts.pinOutboundScript} %i";
|
||||
stateDirectory = "proxy-suite";
|
||||
extraServiceConfig.RemainAfterExit = false;
|
||||
};
|
||||
}
|
||||
{
|
||||
enable = proxyEnabled;
|
||||
name = "proxy-suite-outbound-unpin";
|
||||
value = mkOneshotService {
|
||||
description = "Unpin the proxy-suite outbound";
|
||||
execStart = "${scripts.pinOutboundScript}";
|
||||
stateDirectory = "proxy-suite";
|
||||
extraServiceConfig.RemainAfterExit = false;
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user