fix: improve proxy-ctl
This commit is contained in:
5 files changed
+29
-11
No files matched your search
@@ -123,7 +123,7 @@ A group without a verb shows its status or list.
|
|||||||
proxy tun [status|on|off] global TUN mode
|
proxy tun [status|on|off] global TUN mode
|
||||||
proxy tproxy [status|on|off] global TProxy mode
|
proxy tproxy [status|on|off] global TProxy mode
|
||||||
proxy auto [list] what autoProxy routed, and via which exit (sudo, or userControl)
|
proxy auto [list] what autoProxy routed, and via which exit (sudo, or userControl)
|
||||||
proxy auto probe <domain>[/path] [--json] [--exits a,b | --via tag]
|
proxy auto probe <domain>[/path] [--json] [--keep-going] [--exits a,b | --via tag]
|
||||||
find an exit that reaches a domain
|
find an exit that reaches a domain
|
||||||
proxy auto learn <domain> probe now and route it if an exit works (sudo)
|
proxy auto learn <domain> probe now and route it if an exit works (sudo)
|
||||||
proxy auto queue [count] destinations waiting to be probed (sudo, or userControl)
|
proxy auto queue [count] destinations waiting to be probed (sudo, or userControl)
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ let
|
|||||||
dir = constants.zapret2CutoffDir;
|
dir = constants.zapret2CutoffDir;
|
||||||
unit = "proxy-suite-zapret2-cutoff";
|
unit = "proxy-suite-zapret2-cutoff";
|
||||||
table = "proxy_suite_cutoff_probe";
|
table = "proxy_suite_cutoff_probe";
|
||||||
|
# try-restart fails on a unit that is not installed, so only name the ones built.
|
||||||
|
restartUnits =
|
||||||
|
lib.optional cfg.zapret.enable "zapret-discord-youtube.service"
|
||||||
|
++ lib.optional cfg.perAppRouting.zapret.enable "proxy-suite-per-app-zapret.service";
|
||||||
|
|
||||||
z2kDetect = pkgs.buildGoModule {
|
z2kDetect = pkgs.buildGoModule {
|
||||||
pname = "z2k-detect";
|
pname = "z2k-detect";
|
||||||
@@ -119,7 +123,7 @@ let
|
|||||||
|
|
||||||
# nfqws2 reads the maps once; learned strategies survive the restart.
|
# nfqws2 reads the maps once; learned strategies survive the restart.
|
||||||
if [ "$changed" = 1 ]; then
|
if [ "$changed" = 1 ]; then
|
||||||
systemctl try-restart zapret-discord-youtube.service proxy-suite-per-app-zapret.service
|
systemctl try-restart ${lib.escapeShellArgs restartUnits}
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -503,7 +503,8 @@
|
|||||||
grep -q '"url":"https://example.test/robots.txt"' <<<"$out"
|
grep -q '"url":"https://example.test/robots.txt"' <<<"$out"
|
||||||
|
|
||||||
# A working apex is never second-guessed by the fallback path.
|
# A working apex is never second-guessed by the fallback path.
|
||||||
out="$(probe_with '0|0.10|200|500|' '0|0.20|200|500|' '0|0.10|403|10|' '0|0.20|200|10|')"
|
# set -e: proxy-ctl runs under it, and $() does not inherit it.
|
||||||
|
out="$(set -e; probe_with '0|0.10|200|500|' '0|0.20|200|500|' '0|0.10|403|10|' '0|0.20|200|10|')"
|
||||||
grep -q '"verdict":"ok"' <<<"$out"
|
grep -q '"verdict":"ok"' <<<"$out"
|
||||||
|
|
||||||
# --- walking more than two exits ---
|
# --- walking more than two exits ---
|
||||||
@@ -522,6 +523,11 @@
|
|||||||
out="$(cmd_proxy_probe --json sekai.test)"
|
out="$(cmd_proxy_probe --json sekai.test)"
|
||||||
jq -e '.verdict == "destination" and .exit == "de"' <<<"$out" > /dev/null
|
jq -e '.verdict == "destination" and .exit == "de"' <<<"$out" > /dev/null
|
||||||
|
|
||||||
|
# --keep-going tries every exit but keeps the first that worked.
|
||||||
|
out="$(cmd_proxy_probe --json --keep-going --exits de,fi sekai.test)"
|
||||||
|
jq -e '.exit == "de" and [.exits[].tag] == ["direct", "de", "fi", "direct", "de", "fi"]' \
|
||||||
|
<<<"$out" > /dev/null
|
||||||
|
|
||||||
# --exits restricts and orders the walk; direct is always tried first.
|
# --exits restricts and orders the walk; direct is always tried first.
|
||||||
out="$(cmd_proxy_probe --json --exits de sekai.test)"
|
out="$(cmd_proxy_probe --json --exits de sekai.test)"
|
||||||
jq -e '[.exits[].tag] == ["direct", "de"]' <<<"$out" > /dev/null
|
jq -e '[.exits[].tag] == ["direct", "de"]' <<<"$out" > /dev/null
|
||||||
|
|||||||
@@ -174,6 +174,10 @@ in
|
|||||||
detect=$(grep -o '/nix/store/[^:]*-z2k-detect-[^:/]*/bin' ${cutoffProbe} | head -n1)
|
detect=$(grep -o '/nix/store/[^:]*-z2k-detect-[^:/]*/bin' ${cutoffProbe} | head -n1)
|
||||||
"$detect/z2k-detect" tcp16 -h 2>/dev/null
|
"$detect/z2k-detect" tcp16 -h 2>/dev/null
|
||||||
|
|
||||||
|
# New maps restart only the zapret units this config installs.
|
||||||
|
grep -qF 'try-restart zapret-discord-youtube.service' ${cutoffProbe}
|
||||||
|
if grep -qF 'proxy-suite-per-app-zapret.service' ${cutoffProbe}; then exit 1; fi
|
||||||
|
|
||||||
# The proxy carries what no name fixes, unless the fallback is off.
|
# The proxy carries what no name fixes, unless the fallback is off.
|
||||||
grep -qF 'tag: "zapret-cutoff"' ${socksStart zapret2Global}
|
grep -qF 'tag: "zapret-cutoff"' ${socksStart zapret2Global}
|
||||||
if grep -qF 'zapret-cutoff' ${socksStart zapret2NoFallback}; then exit 1; fi
|
if grep -qF 'zapret-cutoff' ${socksStart zapret2NoFallback}; then exit 1; fi
|
||||||
|
|||||||
+12
-8
@@ -41,7 +41,7 @@ A group without a verb shows its status or list.
|
|||||||
proxy tun [status|on|off] global TUN mode
|
proxy tun [status|on|off] global TUN mode
|
||||||
proxy tproxy [status|on|off] global TProxy mode
|
proxy tproxy [status|on|off] global TProxy mode
|
||||||
proxy auto [list] what autoProxy routed, and via which exit (sudo, or userControl)
|
proxy auto [list] what autoProxy routed, and via which exit (sudo, or userControl)
|
||||||
proxy auto probe <domain>[/path] [--json] [--exits a,b | --via tag]
|
proxy auto probe <domain>[/path] [--json] [--keep-going] [--exits a,b | --via tag]
|
||||||
find an exit that reaches a domain
|
find an exit that reaches a domain
|
||||||
proxy auto learn <domain> probe now and route it if an exit works (sudo)
|
proxy auto learn <domain> probe now and route it if an exit works (sudo)
|
||||||
proxy auto queue [count] destinations waiting to be probed (sudo, or userControl)
|
proxy auto queue [count] destinations waiting to be probed (sudo, or userControl)
|
||||||
@@ -762,11 +762,13 @@ _probe_fetch_exit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Walks EXIT_TAGS/EXIT_URLS (direct first) and stops at the first exit that
|
# Walks EXIT_TAGS/EXIT_URLS (direct first) and stops at the first exit that
|
||||||
# gets content. Sets WALK_VERDICT, WALK_EXIT, WALK_PATH, WALK_DIRECT, WALK_VIA
|
# gets content; PROBE_KEEP_GOING=1 still tries the rest, keeping that one.
|
||||||
|
# Sets WALK_VERDICT, WALK_EXIT, WALK_PATH, WALK_DIRECT, WALK_VIA
|
||||||
# and WALK_ROWS ("tag<TAB>path<TAB>result<TAB>judgement" per request).
|
# and WALK_ROWS ("tag<TAB>path<TAB>result<TAB>judgement" per request).
|
||||||
_probe_walk() {
|
_probe_walk() {
|
||||||
local domain="$1" path direct result judgement i first_direct=""
|
local domain="$1" path direct result judgement i first_direct=""
|
||||||
WALK_ROWS=()
|
WALK_ROWS=()
|
||||||
|
WALK_VERDICT=""
|
||||||
WALK_EXIT=""
|
WALK_EXIT=""
|
||||||
WALK_VIA=""
|
WALK_VIA=""
|
||||||
for path in "$PROBE_PATH" ${PROBE_PATH_FALLBACK:+"$PROBE_PATH_FALLBACK"}; do
|
for path in "$PROBE_PATH" ${PROBE_PATH_FALLBACK:+"$PROBE_PATH_FALLBACK"}; do
|
||||||
@@ -774,26 +776,27 @@ _probe_walk() {
|
|||||||
judgement="$(_probe_exit_verdict "$direct")"
|
judgement="$(_probe_exit_verdict "$direct")"
|
||||||
WALK_ROWS+=("${EXIT_TAGS[0]}"$'\t'"$path"$'\t'"$direct"$'\t'"$judgement")
|
WALK_ROWS+=("${EXIT_TAGS[0]}"$'\t'"$path"$'\t'"$direct"$'\t'"$judgement")
|
||||||
[ -n "$first_direct" ] || first_direct="$direct"
|
[ -n "$first_direct" ] || first_direct="$direct"
|
||||||
if [ "$judgement" = ok ]; then
|
if [ "$judgement" = ok ] && [ -z "$WALK_VERDICT" ]; then
|
||||||
WALK_VERDICT=ok
|
WALK_VERDICT=ok
|
||||||
WALK_PATH="$path"
|
WALK_PATH="$path"
|
||||||
WALK_DIRECT="$direct"
|
WALK_DIRECT="$direct"
|
||||||
return
|
[ "${PROBE_KEEP_GOING:-0}" = 1 ] || return 0
|
||||||
fi
|
fi
|
||||||
for ((i = 1; i < ${#EXIT_TAGS[@]}; i++)); do
|
for ((i = 1; i < ${#EXIT_TAGS[@]}; i++)); do
|
||||||
result="$(_probe_fetch_exit "$domain" "$path" "${EXIT_URLS[i]}")"
|
result="$(_probe_fetch_exit "$domain" "$path" "${EXIT_URLS[i]}")"
|
||||||
judgement="$(_probe_exit_verdict "$result")"
|
judgement="$(_probe_exit_verdict "$result")"
|
||||||
WALK_ROWS+=("${EXIT_TAGS[i]}"$'\t'"$path"$'\t'"$result"$'\t'"$judgement")
|
WALK_ROWS+=("${EXIT_TAGS[i]}"$'\t'"$path"$'\t'"$result"$'\t'"$judgement")
|
||||||
if [ "$judgement" = ok ]; then
|
if [ "$judgement" = ok ] && [ -z "$WALK_VERDICT" ]; then
|
||||||
WALK_VERDICT="$(_probe_verdict "$direct" "$result")"
|
WALK_VERDICT="$(_probe_verdict "$direct" "$result")"
|
||||||
WALK_EXIT="${EXIT_TAGS[i]}"
|
WALK_EXIT="${EXIT_TAGS[i]}"
|
||||||
WALK_PATH="$path"
|
WALK_PATH="$path"
|
||||||
WALK_DIRECT="$direct"
|
WALK_DIRECT="$direct"
|
||||||
WALK_VIA="$result"
|
WALK_VIA="$result"
|
||||||
return
|
[ "${PROBE_KEEP_GOING:-0}" = 1 ] || return 0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
[ -z "$WALK_VERDICT" ] || return 0
|
||||||
WALK_PATH="$PROBE_PATH"
|
WALK_PATH="$PROBE_PATH"
|
||||||
WALK_DIRECT="$first_direct"
|
WALK_DIRECT="$first_direct"
|
||||||
if [ "$(_probe_exit_verdict "$first_direct")" = dead ]; then
|
if [ "$(_probe_exit_verdict "$first_direct")" = dead ]; then
|
||||||
@@ -829,11 +832,12 @@ _probe_stand_in() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd_proxy_probe() {
|
cmd_proxy_probe() {
|
||||||
local json=0 domain="" want="" have_want=0 via="" row tag
|
local json=0 domain="" want="" have_want=0 via="" row tag PROBE_KEEP_GOING=0
|
||||||
local -a rows wanted
|
local -a rows wanted
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--json) json=1 ;;
|
--json) json=1 ;;
|
||||||
|
--keep-going) PROBE_KEEP_GOING=1 ;;
|
||||||
--exits)
|
--exits)
|
||||||
want="${2?--exits needs a comma-separated list of exit tags}"
|
want="${2?--exits needs a comma-separated list of exit tags}"
|
||||||
have_want=1
|
have_want=1
|
||||||
@@ -851,7 +855,7 @@ cmd_proxy_probe() {
|
|||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
[ -n "$domain" ] || _usage "proxy auto probe <domain>[/path] [--json] [--exits a,b | --via tag]"
|
[ -n "$domain" ] || _usage "proxy auto probe <domain>[/path] [--json] [--keep-going] [--exits a,b | --via tag]"
|
||||||
domain="${domain#*://}"
|
domain="${domain#*://}"
|
||||||
if [[ "$domain" == */* ]]; then
|
if [[ "$domain" == */* ]]; then
|
||||||
local PROBE_PATH="/${domain#*/}" PROBE_PATH_FALLBACK=""
|
local PROBE_PATH="/${domain#*/}" PROBE_PATH_FALLBACK=""
|
||||||
|
|||||||
Reference in new issue
Block a user