From aa4982a5268ef430aad8cc73e82d0f5a92fbefe4 Mon Sep 17 00:00:00 2001 From: bol-van Date: Mon, 22 Sep 2025 14:48:55 +0300 Subject: [PATCH] blockcheck: working strategies intersection print for multiple domains --- blockcheck.sh | 71 +++++++++++++++++++++++++++++++++++++++++++----- common/base.sh | 9 ++++-- docs/changes.txt | 1 + 3 files changed, 72 insertions(+), 9 deletions(-) diff --git a/blockcheck.sh b/blockcheck.sh index ff7b8a94..2a582e2a 100755 --- a/blockcheck.sh +++ b/blockcheck.sh @@ -1097,7 +1097,7 @@ tpws_curl_test() shift; shift; strategy="$@" strategy_append_extra_tpws - report_append "ipv${IPV} $dom $testf : tpws ${WF:+$WF }$strategy" + report_append "$dom" "$testf ipv${IPV}" "tpws ${WF:+$WF }$strategy" } return $code } @@ -1116,7 +1116,7 @@ pktws_curl_test() [ "$code" = 0 ] && { strategy="$@" strategy_append_extra_pktws - report_append "ipv${IPV} $dom $testf : $PKTWSD ${WF:+$WF }$strategy" + report_append "$dom" "$testf ipv${IPV}" "$PKTWSD ${WF:+$WF }$strategy" } return $code } @@ -1156,8 +1156,35 @@ tpws_curl_test_update() report_append() { + # $1 - domain + # $2 - test function + ipver + # $3 - value + local hashstr hash hashvar hashcountvar val ct + + # save resources if only one domain + [ "$DOMAINS_COUNT" -gt 1 ] && { + hashstr="$2 : $3" + hash="$(echo -n "$hashstr" | md5)" + hashvar=RESHASH_${hash} + hashcountvar=${hashvar}_COUNTER + + NRESHASH=${NRESHASH:-0} + + eval val="\$$hashvar" + if [ -n "$val" ]; then + eval ct="\$$hashcountvar" + ct=$(($ct + 1)) + eval $hashcountvar="\$ct" + else + eval $hashvar=\"$hashstr\" + eval $hashcountvar=1 + eval RES_$NRESHASH="\$hash" + NRESHASH=$(($NRESHASH+1)) + fi + } + NREPORT=${NREPORT:-0} - eval REPORT_${NREPORT}=\"$@\" + eval REPORT_${NREPORT}=\"$2 $1 : $3\" NREPORT=$(($NREPORT+1)) } report_print() @@ -1170,6 +1197,22 @@ report_print() n=$(($n+1)) done } +result_intersection_print() +{ + local n=0 hash hashvar hashcountvar ct val + while : ; do + eval hash=\"\$RES_$n\" + [ -n "$hash" ] || break + hashvar=RESHASH_${hash} + hashcountvar=${hashvar}_COUNTER + eval ct=\"\$$hashcountvar\" + [ "$ct" = "$DOMAINS_COUNT" ] && { + eval val=\"\$$hashvar\" + echo "$val" + } + n=$(($n + 1)) + done +} report_strategy() { # $1 - test function @@ -1181,12 +1224,11 @@ report_strategy() strategy="$(echo "$strategy" | xargs)" echo "!!!!! $1: working strategy found for ipv${IPV} $2 : $3 $strategy !!!!!" echo -# report_append "ipv${IPV} $2 $1 : $3 ${WF:+$WF }$strategy" return 0 else echo "$1: $3 strategy for ipv${IPV} $2 not found" echo - report_append "ipv${IPV} $2 $1 : $3 not working" + report_append "$2" "$1 ipv${IPV}" "$3 not working" return 1 fi } @@ -1675,17 +1717,19 @@ check_domain_prolog() local code + [ "$SIMULATE" = 1 ] && return 0 + echo echo \* $1 ipv$IPV $3 echo "- checking without DPI bypass" curl_test $1 $3 && { - report_append "ipv${IPV} $3 $1 : working without bypass" + report_append "$3" "$1 ipv${IPV}" "working without bypass" [ "$SCANLEVEL" = force ] || return 1 } code=$? curl_has_reason_to_continue $code || { - report_append "ipv${IPV} $3 $1 : test aborted, no reason to continue. curl code $(curl_translate_code $code)" + report_append "$3" "$1 ipv${IPV}" "test aborted, no reason to continue. curl code $(curl_translate_code $code)" return 1 } return 0 @@ -1869,6 +1913,7 @@ ask_params() [ -n "$dom" ] && DOMAINS="$dom" } } + DOMAINS_COUNT="$(echo "$DOMAINS" | wc -w | trim)" local IPVS_def=4 [ -n "$IPVS" ] || { @@ -2248,6 +2293,18 @@ cleanup echo echo \* SUMMARY report_print +[ "$DOMAINS_COUNT" -gt 1 ] && { + echo + echo \* COMMON + result_intersection_print + echo + [ "$SCANLEVEL" = force ] || { + echo "blockcheck optimizes test sequence. To save time some strategies can be skipped if their test is considered useless." + echo "That's why COMMON intersection can miss strategies that would work for all domains." + echo "Use \"force\" scan level to test all strategies and generate trustable intersection." + echo "Current scan level was \"$SCANLEVEL\"". + } +} echo echo "Please note this SUMMARY does not guarantee a magic pill for you to copy/paste and be happy." echo "Understanding how strategies work is very desirable." diff --git a/common/base.sh b/common/base.sh index d368d2a6..97584bb0 100644 --- a/common/base.sh +++ b/common/base.sh @@ -318,6 +318,12 @@ setup_md5() exists $MD5 || MD5=md5 } +md5() +{ + setup_md5 + $MD5 | cut -d ' ' -f1 +} + setup_random() { [ -n "$RCUT" ] && return @@ -330,7 +336,6 @@ random() { # $1 - min, $2 - max local r rs - setup_md5 setup_random if [ -c /dev/urandom ]; then read rs