#!/bin/bash # autotest.sh - Automatic strategy tester v4 # Modes: --auto, --list-all, interactive # FIXED: removed set -e which caused exit on ((i++)) when i=0 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=$((passed + 1)) 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 </dev/null || true pkill -f "nfqws.*qnum=$NFQUEUE_NUM" 2>/dev/null || true sleep 1 [[ "$mode" == "interactive" ]] && read -rp "Press Enter to start..." cleanup_firewall >/dev/null 2>&1 || true sleep 1 local working_strategies=() working_descs=() first_working="" local failed_strategies=() failed_descs=() 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" else failed_strategies+=("$strat") failed_descs+=("$(describe_strategy "$SCRIPT_DIR/general_${strat}.sh")") fi done echo "" echo "==============================================" echo "" # Summary report echo "[*] TEST SUMMARY" echo "" echo " Total tested: ${#STRATEGIES[@]}" echo " Working: ${#working_strategies[@]}" echo " Failed: ${#failed_strategies[@]}" echo "" # Working strategies if [[ ${#working_strategies[@]} -gt 0 ]]; then echo "==============================================" print_green " WORKING STRATEGIES (${#working_strategies[@]}):" local i=0 while [[ $i -lt ${#working_strategies[@]} ]]; do echo " $(print_green "$((i + 1)).") ${working_strategies[$i]} — ${working_descs[$i]}" i=$((i + 1)) done echo "==============================================" echo "" if [[ "$mode" == "--auto" ]]; then install_strategy "$first_working" elif [[ "$mode" == "--list-all" ]]; then echo "[*] To install any working strategy, run:" echo " sudo ./service.sh" echo " → 1. Install Service" echo " → Pick the number matching the strategy above" echo "" echo "[*] Or run directly without systemd:" echo " sudo ./run_strategy.sh ALT3 (replace ALT3 with your choice)" 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 fi # Failed strategies (show only in list-all mode for completeness) if [[ ${#failed_strategies[@]} -gt 0 ]] && [[ "$mode" == "--list-all" ]]; then echo "" echo "==============================================" print_red " FAILED STRATEGIES (${#failed_strategies[@]}):" local j=0 while [[ $j -lt ${#failed_strategies[@]} ]]; do echo " $((j + 1)). ${failed_strategies[$j]} — ${failed_descs[$j]}" j=$((j + 1)) done echo "==============================================" fi if [[ ${#working_strategies[@]} -eq 0 ]]; then echo "" 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