Files
proxy-suite-flake/windows/tools/winws-dry-run.sh
T
faumarayandClaude Opus 5.5 9eed225ccc windows: zapret2 with z2k's strategies and upstream's Lua layers
The zapret2-extras component (tools/build-zapret2-extras.sh): z2k at
upstream's pinned commit, its strategies made by its own generator as
upstream's z2k-profiles.template.sh runs it, with tokens where upstream
fills in the configuration at build time; its Lua, lists and fakes; and
upstream's own Lua: the extended detector (detect.lua), the per-site key
by public suffix, the fail stamp, every-change persistence and the
strategy log.

winws2 now runs, as upstream's nfqws2 does, with z2k's Lua for its
strategies, then the layers: each site's working strategy kept across
restarts (z2k's state layer), strategies keyed by site, and with
autoHostlist.extendedDetection the detector learning in place of
nfqws2's own (its last TLS profile, the stall watch where the learned
sites are). Lua arguments name paths as Cygwin does (no colon); what
winws2 writes stays under the Low-integrity folder. The server's TLS
handshake and alert records reach the detectors through a WinDivert
filter part: WinDivert has no per-flow packet window to hand them over
by. Options go to winws2 in a file (@file): z2k's alone are 55 KB, past
a Windows command line.

Both sources, with every layer, verified by winws2's --dry-run under
Wine (tools/winws-dry-run.sh). The DPI page picks the strategies and
switches the detection. proxyFallback and the cutoff probe are said to
be not on Windows yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 18:10:57 +03:00

86 lines
4.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Every preset of Flowseal's release, with the arguments and lists the service builds,
# checked by its own winws.exe (`--dry-run`) under Wine; then zapret2's command line, by
# winws2.exe.
#
# nix develop --command nix shell nixpkgs#wineWow64Packages.stable -c tools/winws-dry-run.sh STAGE_DIR
set -euo pipefail
cd "$(dirname "$0")/.."
STAGE=${1:?staged components directory}
REL="$STAGE/zapret"
WORK=$(mktemp -d)
export WINEPREFIX=${WINEPREFIX:-$WORK/prefix} WINEDEBUG=-all
trap 'wineserver -k 2>/dev/null || true; rm -rf "$WORK"' EXIT
cargo build -q -p ps-core --example zapret_args --example zapret2_args
win() { echo "Z:$(realpath "$1" | sed 's|/|\\|g')\\"; }
# The lists as the service writes them: the release's, and the user's placeholders.
mkdir -p "$WORK/lists" && cp "$REL"/lists/*.txt "$WORK/lists/"
echo domain.example.abc > "$WORK/lists/list-general-user.txt"
echo domain.example.abc > "$WORK/lists/list-exclude-user.txt"
echo 203.0.113.113/32 > "$WORK/lists/ipset-exclude-user.txt"
fail=0 n=0
while IFS= read -r preset; do
for game in null all; do
mapfile -t args < <(target/debug/examples/zapret_args "$REL" "$(win "$REL")" "$(win "$WORK/lists")" "$preset" "$game")
n=$((n + 1))
if out=$(cd "$REL/bin" && wine ./winws.exe --dry-run "${args[@]}" 2>&1) && grep -q "parameters verified" <<<"$out"; then
:
else
fail=$((fail + 1)); echo "FAIL: $preset ($game)"; grep -v Cygwin <<<"$out" | tail -4
fi
done
done < <(ls "$REL"/*.bat | xargs -n1 -d '\n' basename | grep -vi '^service' | sed 's/\.bat$//')
echo "$((n - fail))/$n preset runs verified by winws.exe"
# The same presets with hostlistRules (tools/zapret-rules-sample.json): their profiles ahead.
r=0 na=0
while IFS= read -r preset; do
built=$(target/debug/examples/zapret_args "$REL" "$(win "$REL")" "$(win "$WORK/lists")" "$preset" null tools/zapret-rules-sample.json "$WORK/lists" 2>&1) || {
# A preset without a profile a rule's family needs: refused, as upstream refuses it.
if grep -q "the preset has no .* profile to copy" <<<"$built"; then na=$((na + 1)); echo " $preset: $built"; continue; fi
fail=$((fail + 1)); echo "FAIL: $preset with rules: $built"; continue
}
mapfile -t args <<<"$built"
r=$((r + 1))
if out=$(cd "$REL/bin" && wine ./winws.exe --dry-run "${args[@]}" 2>&1) && grep -q "parameters verified" <<<"$out"; then
:
else
fail=$((fail + 1)); echo "FAIL: $preset with rules"; grep -v Cygwin <<<"$out" | tail -4
fi
done < <(ls "$REL"/*.bat | xargs -n1 -d '\n' basename | grep -vi '^service' | sed 's/\.bat$//')
echo "$r presets with hostlist rules verified by winws.exe; $na refused, lacking a profile a rule copies"
# zapret2: nfqws2-keenetic's strategies as the service renders them, its lists in place.
Z2="$STAGE/zapret2"
mkdir -p "$WORK/z2/learned" && : > "$WORK/z2/zapret-hosts-user.txt" && : > "$WORK/z2/zapret-hosts-user-exclude.txt" && : > "$WORK/z2/learned/zapret-hosts-auto.txt"
mapfile -t args < <(target/debug/examples/zapret2_args "$Z2" "$(win "$Z2")" "$(win "$WORK/z2")")
if out=$(cd "$Z2" && wine ./winws2.exe --dry-run "${args[@]}" 2>&1) && grep -q "parameters verified" <<<"$out"; then
echo "zapret2: verified by winws2.exe"
else
fail=$((fail + 1)); echo "FAIL: zapret2"; grep -v -i cygwin <<<"$out" | tail -4
fi
# With the zapret2-extras component: upstream's Lua layers loaded and the extended detector
# learning, for nfqws2-keenetic's strategies and for z2k's, with the environment the service
# gives winws2.
X="$STAGE/zapret2-extras"
if [ -d "$X" ]; then
cyg() { echo "/cygdrive/z$(realpath "$1")"; }
mkdir -p "$WORK/z2/learned/circular" "$WORK/z2/learned/run"
for kind in keenetic z2k; do
# Through an options file (@file), as the service starts winws2: z2k's run past the
# 32767 characters of a Windows command line. One a line, quoted when it holds a space.
{ echo --dry-run; target/debug/examples/zapret2_args "$Z2" "$(win "$Z2")" "$(win "$WORK/z2")" "$X" "$(win "$X")" "$(cyg "$X")/" "$kind"; } |
python3 -I -c 'import sys
for a in sys.stdin.read().splitlines():
print(("\"" + a.replace("\\", "\\\\").replace("\"", "\\\"") + "\"") if (" " in a or "\"" in a) else a)' >"$WORK/winws2.conf"
if out=$(cd "$Z2" && Z2K_STATE_DIR_OVERRIDE="$(cyg "$WORK/z2/learned/circular")" Z2K_AUTOCIRCULAR_FALLBACK_OVERRIDE="$(cyg "$WORK/z2/learned/run")" \
PROXY_SUITE_ZAPRET2_VERDICTS="$(cyg "$WORK/z2/learned")/verdicts.tsv" PROXY_SUITE_PUBLIC_SUFFIXES="$(cyg "$X")/public_suffixes.txt" \
WINEDEBUG=-all wine ./winws2.exe "@$(win "$WORK")winws2.conf" 2>&1) && grep -q "parameters verified" <<<"$out"; then
echo "zapret2 ($kind, extended detection, upstream's Lua layers): verified by winws2.exe, $(grep -c -- '--lua-init' "$WORK/winws2.conf") Lua files, $(wc -l <"$WORK/winws2.conf") options"
else
fail=$((fail + 1)); echo "FAIL: zapret2 ($kind with the extras)"; grep -v -i cygwin <<<"$out" | tail -6
fi
done
fi
[ "$fail" = 0 ]