diff --git a/CU2/handle-control-change.sh b/CU2/handle-control-change.sh index 061718e..cec132f 100755 --- a/CU2/handle-control-change.sh +++ b/CU2/handle-control-change.sh @@ -4,10 +4,10 @@ touch "${STATES_DIR}/updating" if [ -e "$DNSCRYPT_FILE" ]; then - ./switch-to-dnscrypt.sh + ./switch-to-dnscrypt-if-required.sh else ./stop-dnscrypt-proxy.sh - ./switch-to-dhcp.sh + ./switch-to-dhcp-if-required-.sh fi rm -f "${STATES_DIR}/updating" rm -f "${STATES_DIR}/update-request" diff --git a/CU2/handle-network-change.sh b/CU2/handle-network-change.sh index 226efea..9604116 100755 --- a/CU2/handle-network-change.sh +++ b/CU2/handle-network-change.sh @@ -8,4 +8,4 @@ FALLBACK_FILE="${CONTROL_DIR}/fallback" ./check-network-change.sh || exit 0 ./set-dns-to-dhcp.sh [ ! -e "$DNSCRYPT_FILE" ] && exit 0 -./switch-to-dnscrypt.sh +./switch-to-dnscrypt-if-required.sh diff --git a/CU2/start-dnscrypt-proxy.sh b/CU2/start-dnscrypt-proxy.sh index 659cb81..9ff7c66 100755 --- a/CU2/start-dnscrypt-proxy.sh +++ b/CU2/start-dnscrypt-proxy.sh @@ -30,8 +30,8 @@ try_resolver() { case "$line" in *Proxying\ from\ *) answers=$(exec dig +time=1 +short +tries=2 -p $priority \ - @"$INTERFACE_PROBES" dailymotion.com 2> /dev/null | \ - fgrep -v 67.215.65. | wc -l) + TXT @"$INTERFACE_PROBES" debug.opendns.com. 2> /dev/null | \ + fgrep -ic 'dnscrypt enabled') [ -r "$pid_file" ] && kill $(cat -- "$pid_file") if [ $answers -gt 0 ]; then echo "$args" > "${RES_DIR}/${priority}" diff --git a/CU2/switch-to-dhcp-if-required.sh b/CU2/switch-to-dhcp-if-required.sh new file mode 100755 index 0000000..3716de0 --- /dev/null +++ b/CU2/switch-to-dhcp-if-required.sh @@ -0,0 +1,7 @@ +#! /bin/sh + +. ./common.inc + +[ -e "$DNSCRYPT_FILE" ] && exit 0 + +./set-dns-to-dhcp.sh diff --git a/CU2/switch-to-dhcp.sh b/CU2/switch-to-dhcp.sh index 3716de0..ed5cf2e 100755 --- a/CU2/switch-to-dhcp.sh +++ b/CU2/switch-to-dhcp.sh @@ -2,6 +2,5 @@ . ./common.inc -[ -e "$DNSCRYPT_FILE" ] && exit 0 - -./set-dns-to-dhcp.sh +rm -f "$DNSCRYPT_FILE" +exec ./switch-to-dhcp-if-required.sh diff --git a/CU2/switch-to-dnscrypt-if-required.sh b/CU2/switch-to-dnscrypt-if-required.sh new file mode 100755 index 0000000..27ebd2f --- /dev/null +++ b/CU2/switch-to-dnscrypt-if-required.sh @@ -0,0 +1,30 @@ +#! /bin/ksh + +. ./common.inc + +PAUSE_MAX=10 +PAUSE_INCREMENT=0.1 + +[ ! -e "$DNSCRYPT_FILE" ] && exit 0 + +pause=0 +while :; do + if [ $pause -lt $PAUSE_MAX ]; then + pause=$((pause + $PAUSE_INCREMENT)) + fi + sleep $pause + ./check-hijacking.sh || continue + ./start-dnscrypt-proxy.sh || continue + ./check-local-dns.sh || continue + ./set-dns.sh "$INTERFACE_PROXY" + if [ $? != 0 ]; then + ./set-dns-to-dhcp.sh + continue + fi + ./check-hijacking.sh + if [ $? != 0 ]; then + ./set-dns-to-dhcp.sh + continue + fi + break +done diff --git a/CU2/switch-to-dnscrypt.sh b/CU2/switch-to-dnscrypt.sh index 27ebd2f..88ba72f 100755 --- a/CU2/switch-to-dnscrypt.sh +++ b/CU2/switch-to-dnscrypt.sh @@ -1,30 +1,6 @@ -#! /bin/ksh +#! /bin/sh . ./common.inc -PAUSE_MAX=10 -PAUSE_INCREMENT=0.1 - -[ ! -e "$DNSCRYPT_FILE" ] && exit 0 - -pause=0 -while :; do - if [ $pause -lt $PAUSE_MAX ]; then - pause=$((pause + $PAUSE_INCREMENT)) - fi - sleep $pause - ./check-hijacking.sh || continue - ./start-dnscrypt-proxy.sh || continue - ./check-local-dns.sh || continue - ./set-dns.sh "$INTERFACE_PROXY" - if [ $? != 0 ]; then - ./set-dns-to-dhcp.sh - continue - fi - ./check-hijacking.sh - if [ $? != 0 ]; then - ./set-dns-to-dhcp.sh - continue - fi - break -done +touch "$DNSCRYPT_FILE" +exec ./switch-to-dnscrypt-if-required.sh