Merge pull request #420 from chris5560/master
ddns-scripts: add retry loop to verify dns and proxy
This commit is contained in:
commit
d88ade1411
4 changed files with 83 additions and 40 deletions
|
@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=ddns-scripts
|
PKG_NAME:=ddns-scripts
|
||||||
PKG_VERSION:=2.0.1
|
PKG_VERSION:=2.0.1
|
||||||
PKG_RELEASE:=8
|
PKG_RELEASE:=9
|
||||||
PKG_LICENSE:=GPL-2.0
|
PKG_LICENSE:=GPL-2.0
|
||||||
|
|
||||||
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
|
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
|
||||||
|
|
|
@ -63,6 +63,7 @@ ERR_LOCAL_IP=0 # error counter on getting local ip
|
||||||
ERR_REG_IP=0 # error counter on getting DNS registered ip
|
ERR_REG_IP=0 # error counter on getting DNS registered ip
|
||||||
ERR_SEND=0 # error counter on sending update to DNS provider
|
ERR_SEND=0 # error counter on sending update to DNS provider
|
||||||
ERR_UPDATE=0 # error counter on different local and registered ip
|
ERR_UPDATE=0 # error counter on different local and registered ip
|
||||||
|
ERR_VERIFY=0 # error counter verifying proxy- and dns-servers
|
||||||
|
|
||||||
# format to show date information in log and luci-app-ddns default ISO 8601 format
|
# format to show date information in log and luci-app-ddns default ISO 8601 format
|
||||||
DATE_FORMAT=$(uci -q get ddns.global.date_format) || DATE_FORMAT="%F %R"
|
DATE_FORMAT=$(uci -q get ddns.global.date_format) || DATE_FORMAT="%F %R"
|
||||||
|
@ -125,7 +126,7 @@ start_daemon_for_all_ddns_sections()
|
||||||
config_cb()
|
config_cb()
|
||||||
{
|
{
|
||||||
# only look for section type "service", ignore everything else
|
# only look for section type "service", ignore everything else
|
||||||
[ "$1" == "service" ] && __SECTIONS="$__SECTIONS $2"
|
[ "$1" = "service" ] && __SECTIONS="$__SECTIONS $2"
|
||||||
}
|
}
|
||||||
config_load "ddns"
|
config_load "ddns"
|
||||||
|
|
||||||
|
@ -214,7 +215,7 @@ __urlencode() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# extract update_url for given DDNS Provider from
|
# extract url or script for given DDNS Provider from
|
||||||
# file /usr/lib/ddns/services for IPv4 or from
|
# file /usr/lib/ddns/services for IPv4 or from
|
||||||
# file /usr/lib/ddns/services_ipv6 for IPv6
|
# file /usr/lib/ddns/services_ipv6 for IPv6
|
||||||
get_service_data() {
|
get_service_data() {
|
||||||
|
@ -387,25 +388,27 @@ __verify_host_port() {
|
||||||
# command error
|
# command error
|
||||||
[ $__ERR -gt 0 ] && {
|
[ $__ERR -gt 0 ] && {
|
||||||
verbose_echo "\n!!!!!!!!! ERROR =: BusyBox nslookup Error '$__ERR'\n$(eval $__ERRPROG)\n"
|
verbose_echo "\n!!!!!!!!! ERROR =: BusyBox nslookup Error '$__ERR'\n$(eval $__ERRPROG)\n"
|
||||||
syslog_err "DNS Resolver Error - BusyBox nslookup Error: '$__ERR'"
|
syslog_err "DNS Resolver Error - BusyBox nslookup Error '$__ERR'"
|
||||||
return 2
|
return 2
|
||||||
} || {
|
} || {
|
||||||
# we need to run twice because multi-line output needs to be directly piped to grep because
|
# we need to run twice because multi-line output needs to be directly piped to grep because
|
||||||
# pipe returns return code of last prog in pipe but we need errors from nslookup command
|
# pipe returns return code of last prog in pipe but we need errors from nslookup command
|
||||||
__IPV4=$(eval $__RUNPROG | sed '1,2d' | grep -o "Name:\|Address.*" | grep -m 1 -o "$IPV4_REGEX")
|
__IPV4=$(eval $__RUNPROG | sed -ne "3,\$ { s/^Address [0-9]*: \($IPV4_REGEX\).*$/\\1/p }")
|
||||||
__IPV6=$(eval $__RUNPROG | sed '1,2d' | grep -o "Name:\|Address.*" | grep -m 1 -o "$IPV6_REGEX")
|
__IPV6=$(eval $__RUNPROG | sed -ne "3,\$ { s/^Address [0-9]*: \($IPv6_REGEX\).*$/\\1/p }")
|
||||||
}
|
}
|
||||||
|
|
||||||
# check IP version if forced
|
# check IP version if forced
|
||||||
if [ $force_ipversion -ne 0 ]; then
|
if [ $force_ipversion -ne 0 ]; then
|
||||||
[ $use_ipv6 -eq 0 -a -z "$__IPV4" ] && return 4
|
__ERR=0
|
||||||
[ $use_ipv6 -eq 1 -a -z "$__IPV6" ] && return 4
|
[ $use_ipv6 -eq 0 -a -z "$__IPV4" ] && __ERR=4
|
||||||
|
[ $use_ipv6 -eq 1 -a -z "$__IPV6" ] && __ERR=6
|
||||||
|
[ $__ERR -gt 0 ] && critical_error "Invalid host: Error '4' - Force IP Version IPv$__ERR not supported"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# verify nc command
|
# verify nc command
|
||||||
# busybox nc compiled without -l option "NO OPT l!" -> critical error
|
# busybox nc compiled without -l option "NO OPT l!" -> critical error
|
||||||
nc --help 2>&1 | grep -iq "NO OPT l!" && \
|
nc --help 2>&1 | grep -iq "NO OPT l!" && \
|
||||||
critical_error "Busybox nc: netcat compiled with errors"
|
critical_error "Busybox nc: netcat compiled without -l option, error 'NO OPT l!'"
|
||||||
# busybox nc compiled with extensions
|
# busybox nc compiled with extensions
|
||||||
nc --help 2>&1 | grep -q "\-w" && __NCEXT="TRUE"
|
nc --help 2>&1 | grep -q "\-w" && __NCEXT="TRUE"
|
||||||
|
|
||||||
|
@ -428,7 +431,7 @@ __verify_host_port() {
|
||||||
__ERR=$?
|
__ERR=$?
|
||||||
[ $__ERR -eq 0 ] && return 0
|
[ $__ERR -eq 0 ] && return 0
|
||||||
verbose_echo "\n!!!!!!!!! ERROR =: BusyBox nc Error '$__ERR'\n$(eval $__ERRPROG)\n"
|
verbose_echo "\n!!!!!!!!! ERROR =: BusyBox nc Error '$__ERR'\n$(eval $__ERRPROG)\n"
|
||||||
syslog_err "host verify Error - BusyBox nc Error: '$__ERR'"
|
syslog_err "host verify Error - BusyBox nc Error '$__ERR'"
|
||||||
return 3
|
return 3
|
||||||
else # nc compiled without extensions (no timeout support)
|
else # nc compiled without extensions (no timeout support)
|
||||||
__RUNPROG="__timeout 2 -- nc $__IP $__PORT </dev/null >/dev/null 2>&1"
|
__RUNPROG="__timeout 2 -- nc $__IP $__PORT </dev/null >/dev/null 2>&1"
|
||||||
|
@ -437,7 +440,7 @@ __verify_host_port() {
|
||||||
__ERR=$?
|
__ERR=$?
|
||||||
[ $__ERR -eq 0 ] && return 0
|
[ $__ERR -eq 0 ] && return 0
|
||||||
verbose_echo "\n!!!!!!!!! ERROR =: BusyBox nc Error '$__ERR' (timeout)"
|
verbose_echo "\n!!!!!!!!! ERROR =: BusyBox nc Error '$__ERR' (timeout)"
|
||||||
syslog_err "host verify Error - BusyBox nc Error: '$__ERR' (timeout)"
|
syslog_err "host verify Error - BusyBox nc Error '$__ERR' (timeout)"
|
||||||
return 3
|
return 3
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -454,8 +457,9 @@ verify_dns() {
|
||||||
verify_proxy() {
|
verify_proxy() {
|
||||||
# $1 Proxy-String to verify
|
# $1 Proxy-String to verify
|
||||||
# complete entry user:password@host:port
|
# complete entry user:password@host:port
|
||||||
|
# inside user and password NO '@' of ":" allowed
|
||||||
# host and port only host:port
|
# host and port only host:port
|
||||||
# host only host unsupported
|
# host only host ERROR unsupported
|
||||||
# IPv4 address instead of host 123.234.234.123
|
# IPv4 address instead of host 123.234.234.123
|
||||||
# IPv6 address instead of host [xxxx:....:xxxx] in square bracket
|
# IPv6 address instead of host [xxxx:....:xxxx] in square bracket
|
||||||
local __TMP __HOST __PORT
|
local __TMP __HOST __PORT
|
||||||
|
@ -477,8 +481,8 @@ verify_proxy() {
|
||||||
__HOST=$(echo $__TMP | awk -F ":" '{print $1}')
|
__HOST=$(echo $__TMP | awk -F ":" '{print $1}')
|
||||||
__PORT=$(echo $__TMP | awk -F ":" '{print $2}')
|
__PORT=$(echo $__TMP | awk -F ":" '{print $2}')
|
||||||
fi
|
fi
|
||||||
# No Port detected ERROR 5
|
# No Port detected
|
||||||
[ -z "$__PORT" ] && return 5
|
[ -z "$__PORT" ] && critical_error "Invalid Proxy server Error '5' - proxy port missing"
|
||||||
|
|
||||||
__verify_host_port "$__HOST" "$__PORT"
|
__verify_host_port "$__HOST" "$__PORT"
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,36 +213,75 @@ fi
|
||||||
verbose_echo " waiting =: 10 seconds for interfaces to fully come up"
|
verbose_echo " waiting =: 10 seconds for interfaces to fully come up"
|
||||||
sleep 10
|
sleep 10
|
||||||
|
|
||||||
# verify DNS server
|
# verify DNS server:
|
||||||
[ -n "$dns_server" ] && {
|
# do with retry's because there might be configurations
|
||||||
verbose_echo "******* VERIFY =: DNS server '$dns_server'"
|
# not directly could connect to outside dns when interface is already up
|
||||||
|
ERR_VERIFY=0 # reset err counter
|
||||||
|
while [ -n "$dns_server" ]; do
|
||||||
|
[ $ERR_VERIFY -eq 0 ] && verbose_echo "******* VERIFY =: DNS server '$dns_server'"
|
||||||
verify_dns "$dns_server"
|
verify_dns "$dns_server"
|
||||||
case $? in
|
ERR_LAST=$? # save return value
|
||||||
0) ;; # everything OK
|
[ $ERR_LAST -eq 0 ] && break # everything ok leave while loop
|
||||||
2) critical_error "Invalid DNS server Error: '2' - nslookup can not resolve host";;
|
ERR_VERIFY=$(( $ERR_VERIFY + 1 ))
|
||||||
3) critical_error "Invalid DNS server Error: '3' - nc (netcat) can not connect";;
|
# if error count > retry_count leave here with critical error
|
||||||
4) critical_error "Invalid DNS server Error: '4' - Forced IP Version don't matched";;
|
[ $ERR_VERIFY -gt $retry_count ] && {
|
||||||
*) critical_error "Invalid DNS server Error: '1' - unspecific error";;
|
case $ERR_LAST in
|
||||||
|
2) critical_error "Invalid DNS server Error: '2' - nslookup can not resolve host";;
|
||||||
|
3) critical_error "Invalid DNS server Error: '3' - nc (netcat) can not connect";;
|
||||||
|
*) critical_error "Invalid DNS server Error: '$ERR_LAST' - unspecific error";;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
case $ERR_LAST in
|
||||||
|
2) syslog_err "Invalid DNS server Error: '2' - nslookup can not resolve host - retry $ERR_VERIFY/$retry_count in $RETRY_SECONDS seconds\n";;
|
||||||
|
3) syslog_err "Invalid DNS server Error: '3' - nc (netcat) can not connect - retry $ERR_VERIFY/$retry_count in $RETRY_SECONDS seconds\n";;
|
||||||
|
*) syslog_err "Invalid DNS server Error: '$ERR_LAST' - unspecific error - retry $ERR_VERIFY/$retry_count in $RETRY_SECONDS seconds\n";;
|
||||||
esac
|
esac
|
||||||
}
|
[ $VERBOSE_MODE -gt 1 ] && {
|
||||||
|
# VERBOSE_MODE > 1 then NO retry
|
||||||
|
verbose_echo "\n!!!!!!!!! ERROR =: Verbose Mode - NO retry\n"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
verbose_echo "******** RETRY =: DNS server '$dns_server' - retry $ERR_VERIFY/$retry_count in $RETRY_SECONDS seconds"
|
||||||
|
sleep $RETRY_SECONDS
|
||||||
|
done
|
||||||
|
|
||||||
# verify Proxy server and set environment
|
# verify Proxy server and set environment
|
||||||
|
# do with retry's because there might be configurations
|
||||||
|
# not directly could connect to outside dns when interface is already up
|
||||||
|
ERR_VERIFY=0 # reset err counter
|
||||||
[ -n "$proxy" ] && {
|
[ -n "$proxy" ] && {
|
||||||
verbose_echo "******* VERIFY =: Proxy server 'http://$proxy'"
|
[ $ERR_VERIFY -eq 0 ] && verbose_echo "******* VERIFY =: Proxy server 'http://$proxy'"
|
||||||
verify_proxy "$proxy"
|
verify_proxy "$proxy"
|
||||||
case $? in
|
ERR_LAST=$? # save return value
|
||||||
0) # everything OK
|
[ $ERR_LAST -eq 0 ] && {
|
||||||
export HTTP_PROXY="http://$proxy"
|
# everything ok set proxy and leave while loop
|
||||||
export HTTPS_PROXY="http://$proxy"
|
export HTTP_PROXY="http://$proxy"
|
||||||
export http_proxy="http://$proxy"
|
export HTTPS_PROXY="http://$proxy"
|
||||||
export https_proxy="http://$proxy"
|
export http_proxy="http://$proxy"
|
||||||
;;
|
export https_proxy="http://$proxy"
|
||||||
2) critical_error "Invalid Proxy server Error: '2' - nslookup can not resolve host";;
|
break
|
||||||
3) critical_error "Invalid Proxy server Error: '3' - nc (netcat) can not connect";;
|
}
|
||||||
4) critical_error "Invalid Proxy server Error: '4' - Forced IP Version don't matched";;
|
ERR_VERIFY=$(( $ERR_VERIFY + 1 ))
|
||||||
5) critical_error "Invalid Proxy server Error: '5' - proxy port missing";;
|
# if error count > retry_count leave here with critical error
|
||||||
*) critical_error "Invalid Proxy server Error: '1' - unspecific error";;
|
[ $ERR_VERIFY -gt $retry_count ] && {
|
||||||
|
case $ERR_LAST in
|
||||||
|
2) critical_error "Invalid Proxy server Error '2' - nslookup can not resolve host";;
|
||||||
|
3) critical_error "Invalid Proxy server Error '3' - nc (netcat) can not connect";;
|
||||||
|
*) critical_error "Invalid Proxy server Error '$ERR_LAST' - unspecific error";;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
case $ERR_LAST in
|
||||||
|
2) syslog_err "Invalid Proxy server Error '2' - nslookup can not resolve host - retry $ERR_VERIFY/$retry_count in $RETRY_SECONDS seconds\n";;
|
||||||
|
3) syslog_err "Invalid Proxy server Error '3' - nc (netcat) can not connect - retry $ERR_VERIFY/$retry_count in $RETRY_SECONDS seconds\n";;
|
||||||
|
*) syslog_err "Invalid Proxy server Error '$ERR_LAST' - unspecific error - retry $ERR_VERIFY/$retry_count in $RETRY_SECONDS seconds\n";;
|
||||||
esac
|
esac
|
||||||
|
[ $VERBOSE_MODE -gt 1 ] && {
|
||||||
|
# VERBOSE_MODE > 1 then NO retry
|
||||||
|
verbose_echo "\n!!!!!!!!! ERROR =: Verbose Mode - NO retry\n"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
verbose_echo "******** RETRY =: Proxy server 'http://$proxy' - retry $ERR_VERIFY/$retry_count in $RETRY_SECONDS seconds"
|
||||||
|
sleep $RETRY_SECONDS
|
||||||
}
|
}
|
||||||
|
|
||||||
# let's check if there is already an IP registered at the web
|
# let's check if there is already an IP registered at the web
|
||||||
|
@ -304,7 +343,7 @@ while : ; do
|
||||||
if [ $VERBOSE_MODE -gt 2 ]; then
|
if [ $VERBOSE_MODE -gt 2 ]; then
|
||||||
verbose_echo " VERBOSE MODE =: NO UPDATE send to DDNS provider"
|
verbose_echo " VERBOSE MODE =: NO UPDATE send to DDNS provider"
|
||||||
elif [ "$LOCAL_IP" != "$REGISTERED_IP" ]; then
|
elif [ "$LOCAL_IP" != "$REGISTERED_IP" ]; then
|
||||||
verbose_echo "******* UPDATE =: LOCAL: '$LOCAL_IP' <=> REGISTERED: '$REGISTERED_IP'"
|
verbose_echo "******* UPDATE =: LOCAL: '$LOCAL_IP' <> REGISTERED: '$REGISTERED_IP'"
|
||||||
else
|
else
|
||||||
verbose_echo "******* FORCED =: LOCAL: '$LOCAL_IP' == REGISTERED: '$REGISTERED_IP'"
|
verbose_echo "******* FORCED =: LOCAL: '$LOCAL_IP' == REGISTERED: '$REGISTERED_IP'"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -71,7 +71,7 @@
|
||||||
"duiadns.net" "http://ipv4.duia.ro/dynamic.duia?host=[DOMAIN]&password=[PASSWORD]&ip4=[IP]"
|
"duiadns.net" "http://ipv4.duia.ro/dynamic.duia?host=[DOMAIN]&password=[PASSWORD]&ip4=[IP]"
|
||||||
|
|
||||||
# Two-DNS - Simply. Connected. Everywhere.
|
# Two-DNS - Simply. Connected. Everywhere.
|
||||||
"Two-DNS" "http://[USERNAME]:[PASSWORD]@update.twodns.de/update?hostname=[DOMAIN]&ip=[IP]"
|
"twodns.de" "http://[USERNAME]:[PASSWORD]@update.twodns.de/update?hostname=[DOMAIN]&ip=[IP]"
|
||||||
|
|
||||||
# MyDNS.JP
|
# MyDNS.JP
|
||||||
"mydns.jp" "http://www.mydns.jp/directip.html?MID=[USERNAME]&PWD=[PASSWORD]&IPV4ADDR=[IP]"
|
"mydns.jp" "http://www.mydns.jp/directip.html?MID=[USERNAME]&PWD=[PASSWORD]&IPV4ADDR=[IP]"
|
||||||
|
|
Loading…
Reference in a new issue