Skip to content

Commit

Permalink
Merge pull request thuantran#351 from thuantran/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jumpsmm7 authored Apr 27, 2022
2 parents 40ddf3f + eb1c020 commit cdc551f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
46 changes: 33 additions & 13 deletions gen/manager
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ check_dns_environment () {
if [ "$NVCHECK" != "0" ]; then { nvram commit; }; { service restart_dnsmasq >/dev/null 2>&1; }; while { [ "$(ping 1.1.1.1 -c1 -W2 >/dev/null 2>&1; printf "%s" "$?")" = "0" ] && [ "$(nslookup google.com 127.0.0.1 >/dev/null 2>&1; printf "%s" "$?")" != "0" ]; }; do sleep 1; done; fi
}

dnscrypt_proxy_run () {
local lock_dir
local pid_file
lock_dir="/tmp/dnscrypt-proxy"
pid_file="${lock_dir}/pid"
if ( mkdir ${lock_dir} ) 2> /dev/null; then
printf "%s\n" "$$" > $pid_file
trap 'rm -rf "$lock_dir"; exit $?' EXIT
start="$(date +%s)"
$@
end="$(date +%s)"
runtime="$((end-start))"
logger -st "$NAME" "$@ took $runtime second(s) to complete."
rm -rf "$lock_dir"
trap - EXIT
else
logger -st "$NAME" "Lock owned by $(cat $pid_file) exists; preventing duplicate runs!"
fi
}

dnsmasq_params () {
local DNS
local VAR
Expand Down Expand Up @@ -82,7 +102,7 @@ proc_optimizations () {
fi
}

start_dnscrypt () {
start_dnscrypt_proxy () {
local COUNTER
local LIMIT
local STATE
Expand All @@ -102,10 +122,10 @@ start_dnscrypt () {
[ -z "$1" ] && NW_STATE="$(ping 1.1.1.1 -c1 -W2 >/dev/null 2>&1; printf "%s" "$?")"
[ -z "$1" ] && RES_STATE="$(nslookup google.com 127.0.0.1 >/dev/null 2>&1; printf "%s" "$?")"
[ -z "$1" ] && while { [ "$NW_STATE" = "0" ] && [ "$RES_STATE" != "0" ] && [ "$STATE" -lt "10" ]; }; do sleep 1; NW_STATE="$(ping 1.1.1.1 -c1 -W2 >/dev/null 2>&1; printf "%s" "$?")"; RES_STATE="$(nslookup google.com 127.0.0.1 >/dev/null 2>&1; printf "%s" "$?")"; STATE="$((STATE + 1))"; done
[ "$STATE" -eq "10" ] && start_dnscrypt x
[ "$STATE" -eq "10" ] && start_dnscrypt_proxy x
}

stop_dnscrypt () {
stop_dnscrypt_proxy () {
local COUNTER
local LIMIT
{ cd /jffs/dnscrypt; } || exit
Expand All @@ -117,9 +137,9 @@ stop_dnscrypt () {
}

start_monitor () {
trap "" 1 2 3 6 15
trap 'EXIT="1"' 10
trap 'EXIT="2"' 12
trap '' HUP INT QUIT ABRT TERM
trap 'EXIT="1"' USR1
trap 'EXIT="2"' USR2
while [ "$(nvram get ntp_ready)" -eq 0 ]; do sleep 1; done
local NW_STATE
local RES_STATE
Expand All @@ -128,10 +148,10 @@ start_monitor () {
local RANDOM
EXIT="0"
RANDOM="0"
logger -st "$NAME" "Starting_Monitor: $NAME"
logger -st "$NAME" "Starting Monitor!"
while true; do
if [ "$EXIT" = "1" ]; then logger -st "$NAME" "Stopping_Monitor: $NAME"; trap - 1 2 3 6 10 12 15; stop_dnscrypt; break; fi
if [ "$EXIT" = "2" ]; then start_dnscrypt; EXIT="0"; fi
if [ "$EXIT" = "1" ]; then logger -st "$NAME" "Stopping Monitor!"; trap - HUP INT QUIT ABRT USR1 USR2 TERM; { dnscrypt_proxy_run stop_dnscrypt_proxy; }; break; fi
if [ "$EXIT" = "2" ]; then { dnscrypt_proxy_run start_dnscrypt_proxy; }; EXIT="0"; fi
if [ -z "$COUNT" ]; then COUNT="0"; timezone; "$0" opendns-update; fi
if [ "$COUNT" = "90" ]; then COUNT="0"; else COUNT="$((COUNT + 1))"; fi
if [ -f "/jffs/dnscrypt/dnscrypt-proxy" ]; then
Expand All @@ -145,14 +165,14 @@ start_monitor () {
esac
if [ -z "$(pidof dnscrypt-proxy)" ]; then
logger -st "$NAME" "Warning: dnscrypt-proxy is dead; $NAME will start it!"
start_dnscrypt
dnscrypt_proxy_run start_dnscrypt_proxy
elif { [ "$COUNT" -eq "30" ] || [ "$COUNT" -eq "60" ] || [ "$COUNT" -eq "90" ]; } && { [ "$NW_STATE" = "0" ] && [ "$RES_STATE" != "0" ]; }; then
logger -st "$NAME" "Warning: dnscrypt-proxy is not responding; $NAME will re-start it!"
start_dnscrypt
dnscrypt_proxy_run start_dnscrypt_proxy
elif [ "$RANDOM" -eq 4320 ]; then
RANDOM="0"
logger -st "$NAME" "Randomization: Health Check; $NAME will randomize it!"
start_dnscrypt
dnscrypt_proxy_run start_dnscrypt_proxy
fi
RANDOM="$((RANDOM + 1))"
fi
Expand All @@ -167,7 +187,7 @@ stop_monitor () {
SIGNAL="12"
;;
"$$")
if [ -n "$MON_PID" ]; then SIGNAL="10"; else { stop_dnscrypt; }; fi
if [ -n "$MON_PID" ]; then SIGNAL="10"; else { dnscrypt_proxy_run stop_dnscrypt_proxy; }; fi
;;
esac
[ -n "$SIGNAL" ] && { kill -s "$SIGNAL" "$MON_PID" 2>/dev/null; };
Expand Down
2 changes: 1 addition & 1 deletion gen/manager.md5sum
Original file line number Diff line number Diff line change
@@ -1 +1 @@
eeaa2f37e291553580ba6234b6389728
101b8f9953de3c1c2c8d96488f44a59c
8 changes: 4 additions & 4 deletions installer
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# | | | \| | (___ | | / \ | | | | | |__ | |__) | Current Maintainer: #
# | | | . ` |\___ \ | | / /\ \ | | | | | __| | _ / SomeWhereOverTheRainBow #
# _| |_| |\ |____) | | |/ ____ \| |____| |____| |____| | \ \ #
#|_____|_| \_|_____/ |_/_/ \_|______|______|______|_| \_\ v2.4.0 #
#|_____|_| \_|_____/ |_/_/ \_|______|______|______|_| \_\ v2.4.1 #
# #
########################################################################################################

Expand All @@ -37,7 +37,7 @@
# shellcheck disable=SC3057
# shellcheck disable=SC3060

DI_VERSION="v2.4.0"
DI_VERSION="v2.4.1"
readonly LATEST_URL="https://api.github.com/repos/jedisct1/dnscrypt-proxy/releases/latest"
readonly DNSCRYPT_VER="$(curl -sL "$LATEST_URL" | grep "tag_name" | head -1 | cut -d \" -f 4)"

Expand Down Expand Up @@ -1746,8 +1746,8 @@ write_manager_script () {
fi
}

trap - 1 2 3 6 15
trap 'clear; end_op_message 2' 1 2 3 6 15
trap - HUP INT QUIT ABRT TERM
trap 'clear; end_op_message 2' HUP INT QUIT ABRT TERM
[ "$1" ] && BRANCH="$1" || BRANCH="master"
[ -z "$(nvram get odmpid)" ] && ROUTER_MODEL="$(nvram get productid)" || ROUTER_MODEL="$(nvram get odmpid)"
RURL="https://raw.githubusercontent.com/thuantran/dnscrypt-asuswrt-installer/${BRANCH}"
Expand Down
2 changes: 1 addition & 1 deletion installer.md5sum
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6e8ab5fbe2ecd061822f6b78182ac1bc
2799ceb41f687cb180898c56b9dc8041

0 comments on commit cdc551f

Please sign in to comment.