NEXT_TIME=0 # calculated time for next FORCED update
EPOCH_TIME=0 # seconds since 1.1.1970 00:00:00
+CURRENT_IP="" # holds the current IP read from the box
REGISTERED_IP="" # holds the IP read from DNS
-LOCAL_IP="" # holds the local IP read from the box
URL_USER="" # url encoded $username from config file
URL_PASS="" # url encoded $password from config file
UPD_ANSWER="" # Answer given by service on success
ERR_LAST=0 # used to save $? return code of program and function calls
-ERR_UPDATE=0 # error counter on different local and registered ip
+ERR_UPDATE=0 # error counter on different current and registered IPs
PID_SLEEP=0 # ProcessID of current background "sleep"
# set correct program to detect IP
[ $use_ipv6 -eq 0 ] && __RUNPROG="network_get_ipaddr" || __RUNPROG="network_get_ipaddr6"
eval "$__RUNPROG __BINDIP $bind_network" || \
- write_log 13 "Can not detect local IP using '$__RUNPROG $bind_network' - Error: '$?'"
+ write_log 13 "Can not detect current IP using '$__RUNPROG $bind_network' - Error: '$?'"
write_log 7 "Force communication via IP '$__BINDIP'"
__PROG="$__PROG --bind-address=$__BINDIP"
fi
fi
}
-get_local_ip () {
- # $1 Name of Variable to store local IP (LOCAL_IP)
+get_current_ip () {
+ # $1 Name of Variable to store current IP
local __CNT=0 # error counter
local __RUNPROG __DATA __URL __ERR
- [ $# -ne 1 ] && write_log 12 "Error calling 'get_local_ip()' - wrong number of parameters"
- write_log 7 "Detect local IP on '$ip_source'"
+ [ $# -ne 1 ] && write_log 12 "Error calling 'get_current_ip()' - wrong number of parameters"
+ write_log 7 "Detect current IP on '$ip_source'"
while : ; do
if [ -n "$ip_network" -a "$ip_source" = "network" ]; then
[ $use_ipv6 -eq 0 ] && __RUNPROG="network_get_ipaddr" \
|| __RUNPROG="network_get_ipaddr6"
eval "$__RUNPROG __DATA $ip_network" || \
- write_log 13 "Can not detect local IP using $__RUNPROG '$ip_network' - Error: '$?'"
- [ -n "$__DATA" ] && write_log 7 "Local IP '$__DATA' detected on network '$ip_network'"
+ write_log 13 "Can not detect current IP using $__RUNPROG '$ip_network' - Error: '$?'"
+ [ -n "$__DATA" ] && write_log 7 "Current IP '$__DATA' detected on network '$ip_network'"
elif [ -n "$ip_interface" -a "$ip_source" = "interface" ]; then
local __DATA4=""; local __DATA6=""
if [ -n "$(command -v ip)" ]; then # ip program installed
fi
fi
[ $use_ipv6 -eq 0 ] && __DATA="$__DATA4" || __DATA="$__DATA6"
- [ -n "$__DATA" ] && write_log 7 "Local IP '$__DATA' detected on interface '$ip_interface'"
+ [ -n "$__DATA" ] && write_log 7 "Current IP '$__DATA' detected on interface '$ip_interface'"
elif [ -n "$ip_script" -a "$ip_source" = "script" ]; then
write_log 7 "#> $ip_script >$DATFILE 2>$ERRFILE"
eval $ip_script >$DATFILE 2>$ERRFILE
__ERR=$?
if [ $__ERR -eq 0 ]; then
__DATA=$(cat $DATFILE)
- [ -n "$__DATA" ] && write_log 7 "Local IP '$__DATA' detected via script '$ip_script'"
+ [ -n "$__DATA" ] && write_log 7 "Current IP '$__DATA' detected via script '$ip_script'"
else
write_log 3 "$ip_script Error: '$__ERR'"
write_log 7 "$(cat $ERRFILE)" # report error
[ $use_ipv6 -eq 0 ] \
&& __DATA=$(grep -m 1 -o "$IPV4_REGEX" $DATFILE) \
|| __DATA=$(grep -m 1 -o "$IPV6_REGEX" $DATFILE)
- [ -n "$__DATA" ] && write_log 7 "Local IP '$__DATA' detected on web at '$ip_url'"
+ [ -n "$__DATA" ] && write_log 7 "Current IP '$__DATA' detected on web at '$ip_url'"
else
- write_log 12 "Error in 'get_local_ip()' - unhandled ip_source '$ip_source'"
+ write_log 12 "Error in 'get_current_ip()' - unhandled ip_source '$ip_source'"
fi
# valid data found return here
[ -n "$__DATA" ] && {
[ $VERBOSE -gt 1 ] && {
# VERBOSE > 1 then NO retry
- write_log 4 "Get local IP via '$ip_source' failed - Verbose Mode: $VERBOSE - NO retry on error"
+ write_log 4 "Get current IP via '$ip_source' failed - Verbose Mode: $VERBOSE - NO retry on error"
return 1
}
__CNT=$(( $__CNT + 1 )) # increment error counter
# if error count > retry_max_count leave here
[ $retry_max_count -gt 0 -a $__CNT -gt $retry_max_count ] && \
- write_log 14 "Get local IP via '$ip_source' failed after $retry_max_count retries"
- write_log 4 "Get local IP via '$ip_source' failed - retry $__CNT/$retry_max_count in $RETRY_SECONDS seconds"
+ write_log 14 "Get current IP via '$ip_source' failed after $retry_max_count retries"
+ write_log 4 "Get current IP via '$ip_source' failed - retry $__CNT/$retry_max_count in $RETRY_SECONDS seconds"
sleep $RETRY_SECONDS &
PID_SLEEP=$!
wait $PID_SLEEP # enable trap-handler
PID_SLEEP=0
done
# we should never come here there must be a programming error
- write_log 12 "Error in 'get_local_ip()' - program coding error"
+ write_log 12 "Error in 'get_current_ip()' - program coding error"
}
get_registered_ip() {
if [ "$ip_source" = "web" -o "$ip_source" = "script" ]; then
# we wait only 3 seconds for an
# answer from "web" or "script"
- write_log 7 "-----> timeout 3 -- get_local_ip IP"
- timeout 3 -- get_local_ip IP
+ write_log 7 "-----> timeout 3 -- get_current_ip IP"
+ timeout 3 -- get_current_ip IP
else
- write_log 7 "-----> get_local_ip IP"
- get_local_ip IP
+ write_log 7 "-----> get_current_ip IP"
+ get_current_ip IP
fi
__RET=$?
;;
#
# use_syslog log activity to syslog
#
-# ip_source source to detect current local IP ('network' or 'web' or 'script' or 'interface')
+# ip_source source to detect current IP ('network' or 'web' or 'script' or 'interface')
# ip_network local defined network to read IP from i.e. 'wan' or 'wan6'
-# ip_url URL to read local address from i.e. http://checkip.dyndns.com/ or http://checkipv6.dyndns.com/
-# ip_script full path and name of your script to detect local IP
+# ip_url URL to read current IP from i.e. http://checkip.dyndns.com/ or http://checkipv6.dyndns.com/
+# ip_script full path and name of your script to detect current IP
# ip_interface physical interface to use for detecting
#
# check_interval check for changes every !!! checks below 10 minutes make no sense because the Internet
# force_ipversion force usage of IPv4 or IPv6 for the whole detection and update communication
# dns_server using a non default dns server to get Registered IP from Internet
# force_dnstcp force communication with DNS server via TCP instead of default UDP
-# proxy using a proxy for communication !!! ALSO used to detect local IP via web => return proxy's IP !!!
+# proxy using a proxy for communication !!! ALSO used to detect current IP via web => return proxy's IP !!!
# use_logfile self-explanatory "/var/log/ddns/$SECTION_ID.log"
# is_glue the record that should be updated is a glue record
#
# verify ip_source 'script' if script is configured and executable
if [ "$ip_source" = "script" ]; then
set -- $ip_script #handling script with parameters, we need a trick
- [ -z "$1" ] && write_log 14 "No script defined to detect local IP!"
- [ -x "$1" ] || write_log 14 "Script to detect local IP not executable!"
+ [ -z "$1" ] && write_log 14 "No script defined to detect current IP!"
+ [ -x "$1" ] || write_log 14 "Script to detect current IP not executable!"
fi
# compute update interval in seconds
write_log 6 "Starting main loop at $(eval $DATE_PROG)"
while : ; do
- get_local_ip LOCAL_IP # read local IP
- [ $use_ipv6 -eq 1 ] && expand_ipv6 "$LOCAL_IP" LOCAL_IP # on IPv6 we use expanded version
+ get_current_ip CURRENT_IP # read current IP
+ [ $use_ipv6 -eq 1 ] && expand_ipv6 "$CURRENT_IP" CURRENT_IP # on IPv6 we use expanded version
# prepare update
# never updated or forced immediate then NEXT_TIME = 0
get_uptime CURR_TIME # get current uptime
- # send update when current time > next time or local ip different from registered ip
- if [ $CURR_TIME -ge $NEXT_TIME -o "$LOCAL_IP" != "$REGISTERED_IP" ]; then
+ # send update when current time > next time or current ip different from registered ip
+ if [ $CURR_TIME -ge $NEXT_TIME -o "$CURRENT_IP" != "$REGISTERED_IP" ]; then
if [ $VERBOSE -gt 2 ]; then
write_log 7 "Verbose Mode: $VERBOSE - NO UPDATE send"
- elif [ "$LOCAL_IP" != "$REGISTERED_IP" ]; then
- write_log 7 "Update needed - L: '$LOCAL_IP' <> R: '$REGISTERED_IP'"
+ elif [ "$CURRENT_IP" != "$REGISTERED_IP" ]; then
+ write_log 7 "Update needed - L: '$CURRENT_IP' <> R: '$REGISTERED_IP'"
else
- write_log 7 "Forced Update - L: '$LOCAL_IP' == R: '$REGISTERED_IP'"
+ write_log 7 "Forced Update - L: '$CURRENT_IP' == R: '$REGISTERED_IP'"
fi
ERR_LAST=0
[ $VERBOSE -lt 3 ] && {
# only send if VERBOSE < 3
- send_update "$LOCAL_IP"
+ send_update "$CURRENT_IP"
ERR_LAST=$? # save return value
}
- # error sending local IP to provider
+ # error sending current IP to provider
# we have no communication error (handled inside send_update/do_transfer)
# but update was not recognized
# do NOT retry after RETRY_SECONDS, do retry after CHECK_SECONDS
if [ $ERR_LAST -eq 0 ]; then
get_uptime LAST_TIME # we send update, so
echo $LAST_TIME > $UPDFILE # save LASTTIME to file
- [ "$LOCAL_IP" != "$REGISTERED_IP" ] \
- && write_log 6 "Update successful - IP '$LOCAL_IP' send" \
- || write_log 6 "Forced update successful - IP: '$LOCAL_IP' send"
+ [ "$CURRENT_IP" != "$REGISTERED_IP" ] \
+ && write_log 6 "Update successful - IP '$CURRENT_IP' send" \
+ || write_log 6 "Forced update successful - IP: '$CURRENT_IP' send"
elif [ $ERR_LAST -eq 127 ]; then
write_log 3 "No update send to DDNS Provider"
else
[ $use_ipv6 -eq 1 ] && expand_ipv6 "$REGISTERED_IP" REGISTERED_IP # on IPv6 we use expanded version
# IP's are still different
- if [ "$LOCAL_IP" != "$REGISTERED_IP" ]; then
+ if [ "$CURRENT_IP" != "$REGISTERED_IP" ]; then
if [ $VERBOSE -le 1 ]; then # VERBOSE <=1 then retry
ERR_UPDATE=$(( $ERR_UPDATE + 1 ))
[ $retry_max_count -gt 0 -a $ERR_UPDATE -gt $retry_max_count ] && \