ddns-scripts: various fixes 9107/head
authorDirk Brenken <dev@brenken.org>
Tue, 28 May 2019 07:30:45 +0000 (09:30 +0200)
committerDirk Brenken <dev@brenken.org>
Wed, 3 Jul 2019 20:41:26 +0000 (22:41 +0200)
* 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>
net/ddns-scripts/Makefile
net/ddns-scripts/files/dynamic_dns_functions.sh
net/ddns-scripts/files/update_cloudflare_com_v4.sh

index 8445fd2313ffa974e9f9eae66d74657507c7216d..f11c3d52b5382f43981bdf7409b2f0e06e711425 100755 (executable)
@@ -12,7 +12,7 @@ PKG_NAME:=ddns-scripts
 PKG_VERSION:=2.7.8
 # Release == build
 # increase on changes of services files or tld_names.dat
-PKG_RELEASE:=10
+PKG_RELEASE:=11
 
 PKG_LICENSE:=GPL-2.0
 PKG_MAINTAINER:=
index f409d16c6704220da76696a3f21957f79815dfd5..0c6befbbcfe3e8be246a03f557274ff00974d114 100755 (executable)
@@ -21,7 +21,7 @@
 . /lib/functions/network.sh
 
 # GLOBAL VARIABLES #
-VERSION="2.7.8-6"
+VERSION="2.7.8-11"
 SECTION_ID=""          # hold config's section name
 VERBOSE=0              # default mode is log to console, but easily changed with parameter
 MYPROG=$(basename $0)  # my program call name
@@ -319,16 +319,19 @@ urlencode() {
 # $2   Name of Variable to store script to
 # $3   Name of Variable to store service answer to
 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"
 
        __FILE="/etc/ddns/services"                             # IPv4
        [ $use_ipv6 -ne 0 ] && __FILE="/etc/ddns/services_ipv6" # IPv6
 
        # 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 "
-#      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
                if [ "$__SERVICE" = "$service_name" ]; then
@@ -339,11 +342,11 @@ get_service_data() {
                        eval "$1=\"$__URL\""
                        eval "$2=\"$__SCRIPT\""
                        eval "$3=\"$__ANSWER\""
-                       rm pipe_$$
+                       rm "$__PIPE"
                        return 0
                fi
-       done < pipe_$$
-       rm pipe_$$
+       done < "$__PIPE"
+       rm "$__PIPE"
 
        eval "$1=\"\""  # no service match clear variables
        eval "$2=\"\""
@@ -533,17 +536,17 @@ verify_host_port() {
                }
                # extract IP address
                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}' )
-                       __IPV6=$(cat $DATFILE | awk -F "address " '/has IPv6/ {print $2; exit}' )
+                       __IPV4="$(awk -F "address " '/has address/ {print $2; exit}' "$DATFILE")"
+                       __IPV6="$(awk -F "address " '/has IPv6/ {print $2; exit}' "$DATFILE")"
                elif [ -n "$DRILL" ]; then      # use drill if installed
-                       __IPV4=$(cat $DATFILE | awk '/^'"$lookup_host"'/ {print $5}' | grep -m 1 -o "$IPV4_REGEX")
-                       __IPV6=$(cat $DATFILE | awk '/^'"$lookup_host"'/ {print $5}' | grep -m 1 -o "$IPV6_REGEX")
+                       __IPV4="$(awk '/^'"$__HOST"'/ {print $5}' "$DATFILE" | grep -m 1 -o "$IPV4_REGEX")"
+                       __IPV6="$(awk '/^'"$__HOST"'/ {print $5}' "$DATFILE" | grep -m 1 -o "$IPV6_REGEX")"
                elif [ -n "$HOSTIP" ]; then     # use hostip if installed
-                       __IPV4=$(cat $DATFILE | grep -m 1 -o "$IPV4_REGEX")
-                       __IPV6=$(cat $DATFILE | grep -m 1 -o "$IPV6_REGEX")
+                       __IPV4="$(grep -m 1 -o "$IPV4_REGEX" "$DATFILE")"
+                       __IPV6="$(grep -m 1 -o "$IPV6_REGEX" "$DATFILE")"
                else    # use BusyBox nslookup
-                       __IPV4=$(cat $DATFILE | sed -ne "/^Name:/,\$ { s/^Address[0-9 ]\{0,\}: \($IPV4_REGEX\).*$/\\1/p }")
-                       __IPV6=$(cat $DATFILE | sed -ne "/^Name:/,\$ { s/^Address[0-9 ]\{0,\}: \($IPV6_REGEX\).*$/\\1/p }")
+                       __IPV4="$(sed -ne "/^Name:/,\$ { s/^Address[0-9 ]\{0,\}: \($IPV4_REGEX\).*$/\\1/p }" "$DATFILE")"
+                       __IPV6="$(sed -ne "/^Name:/,\$ { s/^Address[0-9 ]\{0,\}: \($IPV6_REGEX\).*$/\\1/p }" "$DATFILE")"
                fi
        }
 
index f78bce0bcaca4cea72d2ae6df158cd0e70585719..dbf6f592bfba7dc0c2432402c72ef19b8c7f5608 100755 (executable)
@@ -29,6 +29,7 @@
 # used variables
 local __HOST __DOMAIN __TYPE __URLBASE __PRGBASE __RUNPROG __DATA __IPV6 __ZONEID __RECID __PROXIED
 local __URLBASE="https://api.cloudflare.com/client/v4"
+local __TTL=120
 
 # split __HOST __DOMAIN from $domain
 # given data:
@@ -127,7 +128,6 @@ fi
 __PRGBASE="$__PRGBASE --header 'X-Auth-Email: $username' "
 __PRGBASE="$__PRGBASE --header 'X-Auth-Key: $password' "
 __PRGBASE="$__PRGBASE --header 'Content-Type: application/json' "
-# __PRGBASE="$__PRGBASE --header 'Accept: application/json' "
 
 # read zone id for registered domain.TLD
 __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
 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
 
 # let's complete transfer command