195 lines
6.1 KiB
Bash
Executable File
195 lines
6.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# autotest.sh - Automatic strategy tester v3
|
|
# Modes: --auto, --list-all, interactive
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/lib/functions.sh"
|
|
|
|
TEST_URLS=(
|
|
"https://www.youtube.com|YouTube"
|
|
"https://discord.com|Discord"
|
|
"https://discordapp.com|DiscordApp"
|
|
)
|
|
|
|
STRATEGIES=(
|
|
general ALT ALT2 ALT3 ALT4 ALT6 ALT7 ALT8 ALT9 ALT10 ALT11
|
|
FAKE_TLS_AUTO FAKE_TLS_AUTO_ALT FAKE_TLS_AUTO_ALT2 FAKE_TLS_AUTO_ALT3
|
|
SIMPLE_FAKE SIMPLE_FAKE_ALT SIMPLE_FAKE_ALT2 ALT5
|
|
)
|
|
|
|
test_url() {
|
|
local url="$1" timeout=8 code
|
|
code=$(curl -o /dev/null -s -w "%{http_code}" --max-time "$timeout" -L "$url" 2>/dev/null)
|
|
[[ "$code" == "200" || "$code" == "301" || "$code" == "302" || "$code" == "307" ]]
|
|
}
|
|
|
|
test_strategy() {
|
|
local passed=0 total=${#TEST_URLS[@]}
|
|
echo " [*] Testing connectivity..."
|
|
for entry in "${TEST_URLS[@]}"; do
|
|
IFS="|" read -r url name <<< "$entry"
|
|
if test_url "$url"; then
|
|
echo " $(print_green "[OK]") $name"
|
|
((passed++))
|
|
else
|
|
echo " $(print_red "[FAIL]") $name"
|
|
fi
|
|
done
|
|
echo " [*] Result: $passed/$total passed"
|
|
[[ "$passed" -eq "$total" ]]
|
|
}
|
|
|
|
run_strategy_test() {
|
|
local strategy="$1" strategy_path="$SCRIPT_DIR/run_strategy.sh"
|
|
echo ""
|
|
echo "=============================================="
|
|
echo " Testing: $strategy"
|
|
echo " $(describe_strategy "$SCRIPT_DIR/general_${strategy}.sh")"
|
|
echo "=============================================="
|
|
|
|
[[ -f "$SCRIPT_DIR/strategies/${strategy}.conf" ]] || { print_yellow " [!] Config not found, skipping..."; return 1; }
|
|
|
|
cleanup_firewall >/dev/null 2>&1 || true
|
|
sleep 1
|
|
|
|
echo " [*] Starting $strategy..."
|
|
"$strategy_path" "$strategy" >/dev/null 2>&1 &
|
|
local strategy_pid=$!
|
|
sleep 3
|
|
|
|
if ! pgrep -f "nfqws.*qnum=$NFQUEUE_NUM" >/dev/null 2>&1; then
|
|
print_yellow " [!] nfqws did not start for $strategy, skipping..."
|
|
kill "$strategy_pid" 2>/dev/null || true
|
|
wait "$strategy_pid" 2>/dev/null || true
|
|
cleanup_firewall >/dev/null 2>&1 || true
|
|
sleep 1
|
|
return 1
|
|
fi
|
|
|
|
local success=0
|
|
test_strategy && success=1
|
|
|
|
echo " [*] Stopping $strategy..."
|
|
kill -TERM "$strategy_pid" 2>/dev/null || true
|
|
sleep 2
|
|
pkill -f "nfqws.*qnum=$NFQUEUE_NUM" 2>/dev/null || true
|
|
wait "$strategy_pid" 2>/dev/null || true
|
|
cleanup_firewall >/dev/null 2>&1 || true
|
|
sleep 1
|
|
|
|
[[ "$success" -eq 1 ]]
|
|
}
|
|
|
|
install_strategy() {
|
|
local strategy="$1"
|
|
mkdir -p "$SCRIPT_DIR/.service"
|
|
echo "$strategy" > "$SCRIPT_DIR/.service/installed_strategy"
|
|
cat > /etc/systemd/system/zapret.service <<EOS
|
|
[Unit]
|
|
Description=Zapret DPI bypass (strategy: $strategy)
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
ExecStart=$SCRIPT_DIR/run_strategy.sh $strategy
|
|
Restart=on-failure
|
|
RestartSec=5
|
|
StandardOutput=journal
|
|
StandardError=journal
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOS
|
|
systemctl daemon-reload
|
|
systemctl enable zapret.service
|
|
systemctl start zapret.service
|
|
print_green "[OK] Installed and started!"
|
|
echo ""
|
|
systemctl status zapret --no-pager
|
|
}
|
|
|
|
main() {
|
|
local mode="${1:-interactive}"
|
|
echo ""
|
|
echo "=============================================="
|
|
echo " Zapret Auto-Test v$LOCAL_VERSION"
|
|
echo " Will test ${#STRATEGIES[@]} strategies"
|
|
echo "=============================================="
|
|
echo ""
|
|
|
|
[[ "${EUID:-$(id -u)}" -eq 0 ]] || { print_red "[!] Run as root"; exit 1; }
|
|
|
|
check_nfqws || { bash "$SCRIPT_DIR/install_nfqws.sh"; }
|
|
|
|
echo "[*] Test targets:"
|
|
for entry in "${TEST_URLS[@]}"; do
|
|
IFS="|" read -r url name <<< "$entry"
|
|
echo " - $name ($url)"
|
|
done
|
|
echo ""
|
|
|
|
[[ "$mode" == "interactive" ]] && read -rp "Press Enter to start..."
|
|
|
|
cleanup_firewall >/dev/null 2>&1 || true
|
|
sleep 1
|
|
|
|
local working_strategies=() working_descs=() first_working=""
|
|
|
|
for strat in "${STRATEGIES[@]}"; do
|
|
if run_strategy_test "$strat"; then
|
|
working_strategies+=("$strat")
|
|
working_descs+=("$(describe_strategy "$SCRIPT_DIR/general_${strat}.sh")")
|
|
[[ -z "$first_working" ]] && first_working="$strat"
|
|
fi
|
|
done
|
|
|
|
echo ""
|
|
echo "=============================================="
|
|
if [[ ${#working_strategies[@]} -gt 0 ]]; then
|
|
print_green " WORKING STRATEGIES FOUND: ${#working_strategies[@]}"
|
|
echo "=============================================="
|
|
echo ""
|
|
local i=0
|
|
for strat in "${working_strategies[@]}"; do
|
|
echo " $(print_green "[$((i+1))]") $strat — ${working_descs[$i]}"
|
|
((i++))
|
|
done
|
|
echo ""
|
|
|
|
if [[ "$mode" == "--auto" ]]; then
|
|
install_strategy "$first_working"
|
|
elif [[ "$mode" == "--list-all" ]]; then
|
|
echo "[*] To install a strategy, run: sudo ./service.sh → 1. Install Service"
|
|
echo " Or directly: sudo ./run_strategy.sh ALT3"
|
|
else
|
|
echo "[*] Next steps:"
|
|
echo " 1. Test in browser: youtube.com, discord.com"
|
|
echo " 2. To install: sudo ./service.sh → 1. Install Service → Pick a strategy"
|
|
echo ""
|
|
read -rp "Install first working strategy ($first_working)? [Y/n]: " ans
|
|
[[ "${ans:-Y}" == [yY]* ]] && install_strategy "$first_working"
|
|
fi
|
|
else
|
|
print_red " NO WORKING STRATEGY FOUND"
|
|
echo "=============================================="
|
|
echo ""
|
|
echo "[*] Suggestions:"
|
|
echo " - Add custom domains to lists/list-general-user.txt"
|
|
echo " - Check Secure DNS is enabled"
|
|
echo " - Modify strategy parameters in strategies/*.conf"
|
|
echo " - Run diagnostics: sudo ./service.sh → 10. Run Diagnostics"
|
|
fi
|
|
echo ""
|
|
echo "[*] Auto-test complete."
|
|
echo ""
|
|
}
|
|
|
|
case "${1:-interactive}" in
|
|
--auto|-a) main --auto ;;
|
|
--list-all|-l) main --list-all ;;
|
|
interactive|"") main interactive ;;
|
|
*) echo "Usage: sudo ./autotest.sh [--auto|-a] [--list-all|-l]"; exit 1 ;;
|
|
esac
|