|
@@ -29,6 +29,7 @@
|
29
|
29
|
. /lib/functions/network.sh
|
30
|
30
|
|
31
|
31
|
# GLOBAL VARIABLES #
|
|
32
|
+VERSION="2.5.0-1"
|
32
|
33
|
SECTION_ID="" # hold config's section name
|
33
|
34
|
VERBOSE_MODE=1 # default mode is log to console, but easily changed with parameter
|
34
|
35
|
|
|
@@ -53,6 +54,9 @@ LOCAL_IP="" # holds the local IP read from the box
|
53
|
54
|
|
54
|
55
|
URL_USER="" # url encoded $username from config file
|
55
|
56
|
URL_PASS="" # url encoded $password from config file
|
|
57
|
+URL_PENC="" # url encoded $param_enc from config file
|
|
58
|
+
|
|
59
|
+SRV_ANSWER="" # Answer given by service on success
|
56
|
60
|
|
57
|
61
|
ERR_LAST=0 # used to save $? return code of program and function calls
|
58
|
62
|
ERR_UPDATE=0 # error counter on different local and registered ip
|
|
@@ -299,40 +303,38 @@ urlencode() {
|
299
|
303
|
# file /usr/lib/ddns/services_ipv6 for IPv6
|
300
|
304
|
# $1 Name of Variable to store url to
|
301
|
305
|
# $2 Name of Variable to store script to
|
|
306
|
+# $3 Name of Variable to store service answer to
|
302
|
307
|
get_service_data() {
|
303
|
|
- local __LINE __FILE __NAME __URL __SERVICES __DATA
|
304
|
|
- local __SCRIPT=""
|
305
|
|
- local __OLD_IFS=$IFS
|
306
|
|
- local __NEWLINE_IFS='
|
307
|
|
-' # __NEWLINE_IFS
|
308
|
|
- [ $# -ne 2 ] && write_log 12 "Error calling 'get_service_data()' - wrong number of parameters"
|
|
308
|
+ [ $# -ne 3 ] && write_log 12 "Error calling 'get_service_data()' - wrong number of parameters"
|
309
|
309
|
|
310
|
310
|
__FILE="/usr/lib/ddns/services" # IPv4
|
311
|
311
|
[ $use_ipv6 -ne 0 ] && __FILE="/usr/lib/ddns/services_ipv6" # IPv6
|
312
|
312
|
|
313
|
|
- # remove any lines not containing data, and then make sure fields are enclosed in double quotes
|
314
|
|
- __SERVICES=$(cat $__FILE | grep "^[\t ]*[^#]" | \
|
315
|
|
- awk ' gsub("\x27", "\"") { if ($1~/^[^\"]*$/) $1="\""$1"\"" }; { if ( $NF~/^[^\"]*$/) $NF="\""$NF"\"" }; { print $0 }')
|
316
|
|
-
|
317
|
|
- IFS=$__NEWLINE_IFS
|
318
|
|
- for __LINE in $__SERVICES; do
|
319
|
|
- # grep out proper parts of data and use echo to remove quotes
|
320
|
|
- __NAME=$(echo $__LINE | grep -o "^[\t ]*\"[^\"]*\"" | xargs -r -n1 echo)
|
321
|
|
- __DATA=$(echo $__LINE | grep -o "\"[^\"]*\"[\t ]*$" | xargs -r -n1 echo)
|
322
|
|
-
|
323
|
|
- if [ "$__NAME" = "$service_name" ]; then
|
324
|
|
- break # found so leave for loop
|
|
313
|
+ # workaround with variables; pipe create subshell with no give back of variable content
|
|
314
|
+ mkfifo pipe_$$
|
|
315
|
+ # only grep without # or whitespace at linestart | remove "
|
|
316
|
+# grep -v -E "(^#|^[[:space:]]*$)" $__FILE | sed -e s/\"//g > pipe_$$ &
|
|
317
|
+ sed '/^#/d/^[ \t]*$/ds/\"//g' $__FILE > pipe_$$ &
|
|
318
|
+
|
|
319
|
+ while read __SERVICE __DATA __ANSWER; do
|
|
320
|
+ if [ "$__SERVICE" = "$service_name" ]; then
|
|
321
|
+ # check if URL or SCRIPT is given
|
|
322
|
+ __URL=$(echo "$__DATA" | grep "^http")
|
|
323
|
+ [ -z "$__URL" ] && __SCRIPT="/usr/lib/ddns/$__DATA"
|
|
324
|
+
|
|
325
|
+ eval "$1=\"$__URL\""
|
|
326
|
+ eval "$2=\"$__SCRIPT\""
|
|
327
|
+ eval "$3=\"$__ANSWER\""
|
|
328
|
+ rm pipe_$$
|
|
329
|
+ return 0
|
325
|
330
|
fi
|
326
|
|
- done
|
327
|
|
- IFS=$__OLD_IFS
|
|
331
|
+ done < pipe_$$
|
|
332
|
+ rm pipe_$$
|
328
|
333
|
|
329
|
|
- # check if URL or SCRIPT is given
|
330
|
|
- __URL=$(echo "$__DATA" | grep "^http")
|
331
|
|
- [ -z "$__URL" ] && __SCRIPT="/usr/lib/ddns/$__DATA"
|
332
|
|
-
|
333
|
|
- eval "$1=\"$__URL\""
|
334
|
|
- eval "$2=\"$__SCRIPT\""
|
335
|
|
- return 0
|
|
334
|
+ eval "$1=\"\"" # no service match clear variables
|
|
335
|
+ eval "$2=\"\""
|
|
336
|
+ eval "$3=\"\""
|
|
337
|
+ return 1
|
336
|
338
|
}
|
337
|
339
|
|
338
|
340
|
# Calculate seconds from interval and unit
|
|
@@ -793,19 +795,19 @@ send_update() {
|
793
|
795
|
local __URL __ERR
|
794
|
796
|
|
795
|
797
|
# do replaces in URL
|
796
|
|
- __URL=$(echo $update_url | sed -e "s#\[USERNAME\]#$URL_USER#g" -e "s#\[PASSWORD\]#$URL_PASS#g" \
|
797
|
|
- -e "s#\[DOMAIN\]#$domain#g" -e "s#\[IP\]#$__IP#g")
|
|
798
|
+ __URL=$(echo $update_url | sed -e "s#\[USERNAME\]#$URL_USER#g" -e "s#\[PASSWORD\]#$URL_PASS#g" \
|
|
799
|
+ -e "s#\[PARAMENC\]#$URL_PENC#g" -e "s#\[PARAMOPT\]#$param_opt#g" \
|
|
800
|
+ -e "s#\[DOMAIN\]#$domain#g" -e "s#\[IP\]#$__IP#g")
|
798
|
801
|
[ $use_https -ne 0 ] && __URL=$(echo $__URL | sed -e 's#^http:#https:#')
|
799
|
802
|
|
800
|
803
|
do_transfer "$__URL" || return 1
|
801
|
804
|
|
802
|
805
|
write_log 7 "DDNS Provider answered:\n$(cat $DATFILE)"
|
803
|
806
|
|
804
|
|
- return 0
|
805
|
|
- # TODO analyze providers answer
|
806
|
|
- # "good" or "nochg" = dyndns.com compatible API
|
807
|
|
- # grep -i -E "good|nochg" $DATFILE >/dev/null 2>&1
|
808
|
|
- # return $? # "0" if found
|
|
807
|
+ [ -z "$SRV_ANSWER" ] && return 0 # not set then ignore
|
|
808
|
+
|
|
809
|
+ grep -i -E "$SRV_ANSWER" $DATFILE >/dev/null 2>&1
|
|
810
|
+ return $? # "0" if found
|
809
|
811
|
fi
|
810
|
812
|
}
|
811
|
813
|
|
|
@@ -943,13 +945,13 @@ get_registered_ip() {
|
943
|
945
|
fi
|
944
|
946
|
[ $force_dnstcp -eq 1 ] && __PROG="$__PROG -T" # force TCP
|
945
|
947
|
|
946
|
|
- __RUNPROG="$__PROG $domain $dns_server >$DATFILE 2>$ERRFILE"
|
|
948
|
+ __RUNPROG="$__PROG $lookup_host $dns_server >$DATFILE 2>$ERRFILE"
|
947
|
949
|
__PROG="BIND host"
|
948
|
950
|
elif [ -x /usr/bin/nslookup ]; then # last use BusyBox nslookup
|
949
|
951
|
[ $force_ipversion -ne 0 -o $force_dnstcp -ne 0 ] && \
|
950
|
952
|
write_log 14 "Busybox nslookup - no support to 'force IP Version' or 'DNS over TCP'"
|
951
|
953
|
|
952
|
|
- __RUNPROG="/usr/bin/nslookup $domain $dns_server >$DATFILE 2>$ERRFILE"
|
|
954
|
+ __RUNPROG="/usr/bin/nslookup $lookup_host $dns_server >$DATFILE 2>$ERRFILE"
|
953
|
955
|
__PROG="BusyBox nslookup"
|
954
|
956
|
else # there must be an error
|
955
|
957
|
write_log 12 "Error in 'get_registered_ip()' - no supported Name Server lookup software accessible"
|
|
@@ -981,16 +983,16 @@ get_registered_ip() {
|
981
|
983
|
[ -n "$2" ] && return $__ERR # $2 is given -> no retry
|
982
|
984
|
[ $VERBOSE_MODE -gt 1 ] && {
|
983
|
985
|
# VERBOSE_MODE > 1 then NO retry
|
984
|
|
- write_log 4 "Get registered/public IP for '$domain' failed - Verbose Mode: $VERBOSE_MODE - NO retry on error"
|
|
986
|
+ write_log 4 "Get registered/public IP for '$lookup_host' failed - Verbose Mode: $VERBOSE_MODE - NO retry on error"
|
985
|
987
|
return $__ERR
|
986
|
988
|
}
|
987
|
989
|
|
988
|
990
|
__CNT=$(( $__CNT + 1 )) # increment error counter
|
989
|
991
|
# if error count > retry_count leave here
|
990
|
992
|
[ $retry_count -gt 0 -a $__CNT -gt $retry_count ] && \
|
991
|
|
- write_log 14 "Get registered/public IP for '$domain' failed after $retry_count retries"
|
|
993
|
+ write_log 14 "Get registered/public IP for '$lookup_host' failed after $retry_count retries"
|
992
|
994
|
|
993
|
|
- write_log 4 "Get registered/public IP for '$domain' failed - retry $__CNT/$retry_count in $RETRY_SECONDS seconds"
|
|
995
|
+ write_log 4 "Get registered/public IP for '$lookup_host' failed - retry $__CNT/$retry_count in $RETRY_SECONDS seconds"
|
994
|
996
|
sleep $RETRY_SECONDS &
|
995
|
997
|
PID_SLEEP=$!
|
996
|
998
|
wait $PID_SLEEP # enable trap-handler
|