ddns-scripts: various fixes
* use '$ddns_rundir' in 'get_service_data' for pipe creation, fix #8971
* add missing local variables in 'get_service_data'
* change DNS server verification with drill in 'verify_host_port',
fix/supersed #8935
* remove needless cat calls in 'verify_host_port'
* set cloudfare TTL to min. 120 seconds, fix #7745
* bump/align package version number
Signed-off-by: Dirk Brenken <dev@brenken.org>
(cherry picked from commit 2e06c4ec93
)
This commit is contained in:
parent
f1d6464537
commit
3415e6738b
3 changed files with 21 additions and 18 deletions
|
@ -12,7 +12,7 @@ PKG_NAME:=ddns-scripts
|
||||||
PKG_VERSION:=2.7.8
|
PKG_VERSION:=2.7.8
|
||||||
# Release == build
|
# Release == build
|
||||||
# increase on changes of services files or tld_names.dat
|
# increase on changes of services files or tld_names.dat
|
||||||
PKG_RELEASE:=10
|
PKG_RELEASE:=11
|
||||||
|
|
||||||
PKG_LICENSE:=GPL-2.0
|
PKG_LICENSE:=GPL-2.0
|
||||||
PKG_MAINTAINER:=
|
PKG_MAINTAINER:=
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
. /lib/functions/network.sh
|
. /lib/functions/network.sh
|
||||||
|
|
||||||
# GLOBAL VARIABLES #
|
# GLOBAL VARIABLES #
|
||||||
VERSION="2.7.8-6"
|
VERSION="2.7.8-11"
|
||||||
SECTION_ID="" # hold config's section name
|
SECTION_ID="" # hold config's section name
|
||||||
VERBOSE=0 # default mode is log to console, but easily changed with parameter
|
VERBOSE=0 # default mode is log to console, but easily changed with parameter
|
||||||
MYPROG=$(basename $0) # my program call name
|
MYPROG=$(basename $0) # my program call name
|
||||||
|
@ -319,16 +319,19 @@ urlencode() {
|
||||||
# $2 Name of Variable to store script to
|
# $2 Name of Variable to store script to
|
||||||
# $3 Name of Variable to store service answer to
|
# $3 Name of Variable to store service answer to
|
||||||
get_service_data() {
|
get_service_data() {
|
||||||
|
local __FILE __SERVICE __DATA __ANSWER __URL __SCRIPT __PIPE
|
||||||
|
|
||||||
[ $# -ne 3 ] && write_log 12 "Error calling 'get_service_data()' - wrong number of parameters"
|
[ $# -ne 3 ] && write_log 12 "Error calling 'get_service_data()' - wrong number of parameters"
|
||||||
|
|
||||||
__FILE="/etc/ddns/services" # IPv4
|
__FILE="/etc/ddns/services" # IPv4
|
||||||
[ $use_ipv6 -ne 0 ] && __FILE="/etc/ddns/services_ipv6" # IPv6
|
[ $use_ipv6 -ne 0 ] && __FILE="/etc/ddns/services_ipv6" # IPv6
|
||||||
|
|
||||||
# workaround with variables; pipe create subshell with no give back of variable content
|
# workaround with variables; pipe create subshell with no give back of variable content
|
||||||
mkfifo pipe_$$
|
__PIPE="$ddns_rundir/pipe_$$"
|
||||||
|
mkfifo "$__PIPE"
|
||||||
|
|
||||||
# only grep without # or whitespace at linestart | remove "
|
# only grep without # or whitespace at linestart | remove "
|
||||||
# grep -v -E "(^#|^[[:space:]]*$)" $__FILE | sed -e s/\"//g > pipe_$$ &
|
sed '/^#/d; /^[ \t]*$/d; s/\"//g' "$__FILE" > "$__PIPE" &
|
||||||
sed '/^#/d; /^[ \t]*$/d; s/\"//g' $__FILE > pipe_$$ &
|
|
||||||
|
|
||||||
while read __SERVICE __DATA __ANSWER; do
|
while read __SERVICE __DATA __ANSWER; do
|
||||||
if [ "$__SERVICE" = "$service_name" ]; then
|
if [ "$__SERVICE" = "$service_name" ]; then
|
||||||
|
@ -339,11 +342,11 @@ get_service_data() {
|
||||||
eval "$1=\"$__URL\""
|
eval "$1=\"$__URL\""
|
||||||
eval "$2=\"$__SCRIPT\""
|
eval "$2=\"$__SCRIPT\""
|
||||||
eval "$3=\"$__ANSWER\""
|
eval "$3=\"$__ANSWER\""
|
||||||
rm pipe_$$
|
rm "$__PIPE"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
done < pipe_$$
|
done < "$__PIPE"
|
||||||
rm pipe_$$
|
rm "$__PIPE"
|
||||||
|
|
||||||
eval "$1=\"\"" # no service match clear variables
|
eval "$1=\"\"" # no service match clear variables
|
||||||
eval "$2=\"\""
|
eval "$2=\"\""
|
||||||
|
@ -533,17 +536,17 @@ verify_host_port() {
|
||||||
}
|
}
|
||||||
# extract IP address
|
# extract IP address
|
||||||
if [ -n "$BIND_HOST" -o -n "$KNOT_HOST" ]; then # use BIND host or Knot host if installed
|
if [ -n "$BIND_HOST" -o -n "$KNOT_HOST" ]; then # use BIND host or Knot host if installed
|
||||||
__IPV4=$(cat $DATFILE | awk -F "address " '/has address/ {print $2; exit}' )
|
__IPV4="$(awk -F "address " '/has address/ {print $2; exit}' "$DATFILE")"
|
||||||
__IPV6=$(cat $DATFILE | awk -F "address " '/has IPv6/ {print $2; exit}' )
|
__IPV6="$(awk -F "address " '/has IPv6/ {print $2; exit}' "$DATFILE")"
|
||||||
elif [ -n "$DRILL" ]; then # use drill if installed
|
elif [ -n "$DRILL" ]; then # use drill if installed
|
||||||
__IPV4=$(cat $DATFILE | awk '/^'"$lookup_host"'/ {print $5}' | grep -m 1 -o "$IPV4_REGEX")
|
__IPV4="$(awk '/^'"$__HOST"'/ {print $5}' "$DATFILE" | grep -m 1 -o "$IPV4_REGEX")"
|
||||||
__IPV6=$(cat $DATFILE | awk '/^'"$lookup_host"'/ {print $5}' | grep -m 1 -o "$IPV6_REGEX")
|
__IPV6="$(awk '/^'"$__HOST"'/ {print $5}' "$DATFILE" | grep -m 1 -o "$IPV6_REGEX")"
|
||||||
elif [ -n "$HOSTIP" ]; then # use hostip if installed
|
elif [ -n "$HOSTIP" ]; then # use hostip if installed
|
||||||
__IPV4=$(cat $DATFILE | grep -m 1 -o "$IPV4_REGEX")
|
__IPV4="$(grep -m 1 -o "$IPV4_REGEX" "$DATFILE")"
|
||||||
__IPV6=$(cat $DATFILE | grep -m 1 -o "$IPV6_REGEX")
|
__IPV6="$(grep -m 1 -o "$IPV6_REGEX" "$DATFILE")"
|
||||||
else # use BusyBox nslookup
|
else # use BusyBox nslookup
|
||||||
__IPV4=$(cat $DATFILE | sed -ne "/^Name:/,\$ { s/^Address[0-9 ]\{0,\}: \($IPV4_REGEX\).*$/\\1/p }")
|
__IPV4="$(sed -ne "/^Name:/,\$ { s/^Address[0-9 ]\{0,\}: \($IPV4_REGEX\).*$/\\1/p }" "$DATFILE")"
|
||||||
__IPV6=$(cat $DATFILE | sed -ne "/^Name:/,\$ { s/^Address[0-9 ]\{0,\}: \($IPV6_REGEX\).*$/\\1/p }")
|
__IPV6="$(sed -ne "/^Name:/,\$ { s/^Address[0-9 ]\{0,\}: \($IPV6_REGEX\).*$/\\1/p }" "$DATFILE")"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
# used variables
|
# used variables
|
||||||
local __HOST __DOMAIN __TYPE __URLBASE __PRGBASE __RUNPROG __DATA __IPV6 __ZONEID __RECID __PROXIED
|
local __HOST __DOMAIN __TYPE __URLBASE __PRGBASE __RUNPROG __DATA __IPV6 __ZONEID __RECID __PROXIED
|
||||||
local __URLBASE="https://api.cloudflare.com/client/v4"
|
local __URLBASE="https://api.cloudflare.com/client/v4"
|
||||||
|
local __TTL=120
|
||||||
|
|
||||||
# split __HOST __DOMAIN from $domain
|
# split __HOST __DOMAIN from $domain
|
||||||
# given data:
|
# given data:
|
||||||
|
@ -127,7 +128,6 @@ fi
|
||||||
__PRGBASE="$__PRGBASE --header 'X-Auth-Email: $username' "
|
__PRGBASE="$__PRGBASE --header 'X-Auth-Email: $username' "
|
||||||
__PRGBASE="$__PRGBASE --header 'X-Auth-Key: $password' "
|
__PRGBASE="$__PRGBASE --header 'X-Auth-Key: $password' "
|
||||||
__PRGBASE="$__PRGBASE --header 'Content-Type: application/json' "
|
__PRGBASE="$__PRGBASE --header 'Content-Type: application/json' "
|
||||||
# __PRGBASE="$__PRGBASE --header 'Accept: application/json' "
|
|
||||||
|
|
||||||
# read zone id for registered domain.TLD
|
# read zone id for registered domain.TLD
|
||||||
__RUNPROG="$__PRGBASE --request GET '$__URLBASE/zones?name=$__DOMAIN'"
|
__RUNPROG="$__PRGBASE --request GET '$__URLBASE/zones?name=$__DOMAIN'"
|
||||||
|
@ -182,7 +182,7 @@ __PROXIED=$(grep -o '"proxied":[^",]*' $DATFILE | grep -o '[^:]*$')
|
||||||
|
|
||||||
# use file to work around " needed for json
|
# use file to work around " needed for json
|
||||||
cat > $DATFILE << EOF
|
cat > $DATFILE << EOF
|
||||||
{"id":"$__ZONEID","type":"$__TYPE","name":"$__HOST","content":"$__IP","proxied":$__PROXIED}
|
{"id":"$__ZONEID","type":"$__TYPE","name":"$__HOST","content":"$__IP","ttl":$__TTL,"proxied":$__PROXIED}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# let's complete transfer command
|
# let's complete transfer command
|
||||||
|
|
Loading…
Reference in a new issue