- moved /usr/lib/ddns/dynamic_dns_lucihelper.sh from luci-app-ddns into this package
(Github openwrt/luci issue 251)
(OpenWrt Trac tickets 18326 18347)
- fix: dynamic_dns_update.sh did not loop
(OpenWrt Trac ticket 18336)
- add provider cloudflare.com IPv4 and IPv6 (Thanks to Paul for support and testing)
(OpenWrt Trac ticket 12500)
- modified detection, if dynamic_dns_fuctions are used by dynamic_dns_lucihelper.sh
- redirect stdout of wget,curl,host,nslookup,nc etc to /tmp/ddns_$$.dat and *.err instead of variables
- extended error detection in get_local_ip function
- modified verify of option ip_script to allow parameters, when calling
- add provider selfhost.de IPv4
- add provider no-ip.pl (nothing to do with no-ip.com)
(Github openwrt/packages issue #542)
IPv4 (tested) and also added for
IPv6 (NOT tested) because client IP is autodetected be provider
- add getlocalip_sample.sh as sample script for usage of
option ip_source 'script' together with
option ip_script '/usr/lib/ddns/getlocalip.sh -4'
- cleanup whitespaces at line ends
Signed-off-by: Christian Schoenebeck <christian.schoenebeck@gmail.com>
+Version 2.1.0-2
+Date 2014-11-15
+
+- moved /usr/lib/ddns/dynamic_dns_lucihelper.sh from luci-app-ddns into this package
+ (Github openwrt/luci issue 251)
+ (OpenWrt Trac tickets 18326 18347)
+- fix: dynamic_dns_update.sh did not loop
+ (OpenWrt Trac ticket 18336)
+- add provider cloudflare.com IPv4 and IPv6 (Thanks to Paul for support and testing)
+ (OpenWrt Trac ticket 12500)
+- modified detection, if dynamic_dns_fuctions are used by dynamic_dns_lucihelper.sh
+- redirect stdout of wget,curl,host,nslookup,nc etc to /tmp/ddns_$$.dat and *.err instead of variables
+- extended error detection in get_local_ip function
+- modified verify of option ip_script to allow parameters, when calling
+- add provider selfhost.de IPv4
+- add provider no-ip.pl (nothing to do with no-ip.com)
+ (Github openwrt/packages issue #542)
+ IPv4 (tested) and also added for
+ IPv6 (NOT tested) because client IP is autodetected be provider
+- add getlocalip_sample.sh as sample script for usage of
+ option ip_source 'script' together with
+ option ip_script '/usr/lib/ddns/getlocalip.sh -4'
+- cleanup whitespaces at line ends
+
+--------------------------------------------------------------------------------
Version 2.1.0-1
Date 2014-11-09
first Provider "no-ip.com" - Thanks to DarkStarXxX for request and testing
- finished uci/ddns wiki at http://wiki.openwrt.org/doc/uci/ddns
- rewritten retry management
-- rewritten logging including following Issue 469
+- rewritten logging including following Issue 469
https://github.com/openwrt/packages/issues/469
- stop running sections on hotplug ifdown event (like start on ifup)
- implement trap detection
PKG_NAME:=ddns-scripts
PKG_VERSION:=2.1.0
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_LICENSE:=GPL-2.0
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
endef
define Package/ddns-scripts/description
- A highly configurable set of scripts for doing dynamic dns updates.
+ A highly configurable set of scripts for doing dynamic dns updates.
NEW in this version:
- IPv6 support
- force communication to IPv4 or IPv6 only
# remove old sed script file
[ -f /usr/lib/ddns/url_escape.sed ] && rm -f /usr/lib/ddns/url_escape.sed
+ # luci updates are not in sync with ddns-script updates !!!
+ # if old luci-app-ddns then errors during install because exist from differnt package
+ # copy dynamic_dns_helper.tmp.sh -> dynamic_dns_helper.sh
+ cp -f /usr/lib/ddns/dynamic_dns_lucihelper.tmp.sh /usr/lib/ddns/dynamic_dns_lucihelper.sh
+
# add new section "ddns" "global" if not exists
uci -q get ddns.global > /dev/null || uci -q set ddns.global='ddns'
uci -q get ddns.global.date_format > /dev/null || uci -q set ddns.global.date_format='%F %R'
uci -q get ddns.global.log_lines > /dev/null || uci -q set ddns.global.log_lines='250'
uci -q commit ddns
- # clear LuCI indexcache
+ # clear LuCI indexcache
rm -f /tmp/luci-indexcache >/dev/null 2>&1
exit 0
/etc/init.d/ddns disable
/etc/init.d/ddns stop
- # clear LuCI indexcache
+ # clear LuCI indexcache
rm -f /tmp/luci-indexcache >/dev/null 2>&1
exit 0
option interface "wan6"
option ip_source "network"
option ip_network "wan6"
-
+
# and used by ddns-scripts and corresponding LuCI application
#
# Inside your ddns configuration file (/etc/config/ddns)
-# you might not find some of below described options.
+# you might not find some of below described options.
# This is because you don't need to define options
# if using there defaults. The LuCI application will delete
# options that configured to there default values.
#
# If you have a working ddns configuration from old ddns-scripts (Version 1.x)
-# everything will function the same with new scripts
+# everything will function the same with new scripts
# without any changes to the configuration.
#
# If you like to use this file for your configuration then
-# use a copy, because the used software to modify the
-# configuration files will throw away all empty lines
+# use a copy, because the used software to modify the
+# configuration files will throw away all empty lines
# and those starting with # (comments).
#
# for each service you want to serve you need a separate configuration
# if you need IPv4 and IPv6 you need to setup 2 separate configurations
# with different names. (i.e. "myddns_ipv4" and "myddns_ipv6")
-# do not use white-spaces or dashes "-" or "@" ":" "!" or
+# do not use white-spaces or dashes "-" or "@" ":" "!" or
# other special characters inside name.
config service "myddns"
-
+
########### Basic settings ########################
###########
###########
# defines the network as defined in /etc/config/network
- # to be monitored for up/down events to start via hotplug
+ # to be monitored for up/down events to start via hotplug
default: "wan" for IPv4
default: "wan6" for IPv6
option interface "wan"
###########
- # Next you need to specify the name of the service you are
+ # Next you need to specify the name of the service you are
# connecting to "eg. dyndns.org". The format of the update
# urls for several different dynamic dns services is specified
- # in the "/usr/lib/ddns/services" file for IPv4 and in
+ # in the "/usr/lib/ddns/services" file for IPv4 and in
# "/usr/lib/ddns/service_ipv6" file. This list is hardly complete
# as there are many, many different dynamic dns services.
- # If your service is on the list you can merely specify it with the
+ # If your service is on the list you can merely specify it with the
# "service_name" option. Otherwise you will need to determine
# the format of the url to update with. You can either add an
- # entry to the "/usr/lib/ddns/services" or "services_ipv6" file
+ # entry to the "/usr/lib/ddns/services" or "services_ipv6" file
# or specify this with the "update_url" option.
# If your ddns provider doesn't work with ddns-scripts because
# there are additional parameters or other special thinks to be done,
# default: none
option service_name "dyndns.org"
- # sample:
+ # sample:
# "http://[USERNAME]:[PASSWORD]@members.dyndns.org/nic/update?hostname=[DOMAIN]&myip=[IP]"
# option update_url ""
- # sample:
+ # sample:
# "/usr/lib/ddns/update_sample.sh"
# option update_script ""
###########
# You must specify your domain/host name, your username and your password
# as you get from you DDNS provider. Keep an eye on providers help pages.
- #
+ #
# Your DNS name / replace [DOMAIN] in update_url
# default: none
option domain ""
###########
# use HTTPS for secure communication with you DDNS provider
- # personally found some providers having problems when not sending
- # updates via HTTPS. You must not specify "https://" in update_url.
+ # personally found some providers having problems when not sending
+ # updates via HTTPS. You must not specify "https://" in update_url.
# It's modified by the scripts themselves
# Needs GNU Wget (with SSL support) or cURL to be installed.
# default: "0" do not use HTTPS
option use_https "0"
- # if using HTTPS (see above) the transfer program tries to verify
+ # if using HTTPS (see above) the transfer program tries to verify
# the providers server certificate. For verification there needs to be
# the counterpart on this machine. Specify the path or path/file where
# the transfer program can find them. (might need package CA-certificates)
option ip_source "network"
option ip_network "wan"
- # ip_source "web" additional uses option ip_url and detects the current
+ # ip_source "web" additional uses option ip_url and detects the current
# local ip from special web sides that response with the ip address of
# calling host. If you are behind a firewall/NAT this is the best option
# since none of the local networks or interfaces will have the external ip.
# option ip_script ""
###########
- # force_ipversion option will set the "-4" respectively "-6" parameter
- # on command line of transfer and DNS lookup program.
+ # force_ipversion option will set the "-4" respectively "-6" parameter
+ # on command line of transfer and DNS lookup program.
# So the whole communication uses the selected IP version between both ends.
# needs GNU Wget or cURL installed for transfer and
# BIND's host for DNS lookup.
# If a Proxy is need to access HTTP/HTTPS pages on the WEB
# it can be configured here also for sending updates to the
# DDNS provider. If you configured use_https='1' above, you
- # need to setup your HTTPS proxy here, otherwise your
+ # need to setup your HTTPS proxy here, otherwise your
# HTTP proxy. !!! You should not detect your current IP
- # ip_source='web' (see above) because this request is also
+ # ip_source='web' (see above) because this request is also
# send via the configured proxy !!!
# Syntax: [user:password@]proxy:port !port is required !
# IPv6 address must be in squared brackets "[...]"
# defines the time interval to check if local IP has changed
# After the first start and first update send, the system will
# wait this time before verify if update was successful send.
- # !!! checks below 5 minutes make no sense because the Internet
+ # !!! checks below 5 minutes make no sense because the Internet
# needs about 5-10 minutes to sync an IP-change to all DNS servers !!!
# accepted unit entry’s: 'seconds' 'minutes' 'hours'
# minimum 5 minutes == 300 seconds
# accepted unit entry’s: 'minutes' 'hours' 'days'
# minimum needs to be greater or equal check interval (see above)
# A special setting of '0' is allowed, which forces the script to run once.
- # It sends an update, verify if update was accepted by DNS
- # (retry if not) and finish. Useful if you want to start by your own (i.e. cron)
+ # It sends an update, verify if update was accepted by DNS
+ # (retry if not) and finish. Useful if you want to start by your own (i.e. cron)
# default 3 days == 72 hours
option force_interval '72'
option force_unit 'hours'
}
reload() {
- killall -1 dynamic_dns_updater.sh # send SIGHUP
+ killall -1 dynamic_dns_updater.sh 2>/dev/null # send SIGHUP
}
restart() {
}
stop() {
- killall dynamic_dns_updater.sh
+ killall dynamic_dns_updater.sh 2>/dev/null
}
+++ /dev/null
-#!/bin/sh
-#
-#set -vx
-
-[ -d /etc/ssl/certs ] || {
- echo "CA-Certificates not istalled - please install first"
- exit 1
-}
-
-NUMCERT=$(find /etc/ssl/certs -name *.crt 2>/dev/null | wc -l)
-NUMLINK=$(find /etc/ssl/certs -type l 2>/dev/null | wc -l)
-
-[ $NUMLINK -gt 0 ] && {
- echo "File-Links already exist. Exiting"
- exit 0
-}
-
-[ -f /usr/bin/openssl ] && OPENSSL="EXIST"
-[ -z "$OPENSSL" ] && {
- opkg update || exit 1
- opkg install openssl-util 2>/dev/null
-}
-
-for CERTFILE in `ls -1 $(1)/etc/ssl/certs`; do \
- HASH=`openssl x509 -hash -noout -in /etc/ssl/certs/$CERTFILE`
- SUFFIX=0
- while [ -h "/etc/ssl/certs/$HASH.$SUFFIX" ]; do
- let "SUFFIX += 1"
- done
- ln -s "$CERTFILE" "/etc/ssl/certs/$HASH.$SUFFIX"
- echo "link $HASH.$SUFFIX created for $CERTFILE"
-done
-
-[ -z "$OPENSSL" ] && opkg remove --force-remove --autoremove openssl-util 2>/dev/null
# (Loosely) based on the script on the one posted by exobyte in the forums here:
# http://forum.openwrt.org/viewtopic.php?id=14040
#
-# extended and partial rewritten in August 2014
+# extended and partial rewritten in August 2014
# by Christian Schoenebeck <christian dot schoenebeck at gmail dot com>
# to support:
# - IPv6 DDNS services
# - Proxy Server to send out updates or retrieving WEB based IP detection
# - force_interval=0 to run once (usefull for cron jobs etc.)
# - the usage of BIND's host instead of BusyBox's nslookup if installed (DNS via TCP)
-# - extended Verbose Mode and log file support for better error detection
+# - extended Verbose Mode and log file support for better error detection
#
# function timeout
# copied from http://www.ict.griffith.edu.au/anthony/software/timeout.sh
SECTION_ID="" # hold config's section name
VERBOSE_MODE=1 # default mode is log to console, but easily changed with parameter
-PIDFILE="" # pid file
-UPDFILE="" # store UPTIME of last update
-
-# directory to store run information to.
+# directory to store run information to.
RUNDIR=$(uci -q get ddns.global.run_dir) || RUNDIR="/var/run/ddns"
# NEW # directory to store log files
LOGDIR=$(uci -q get ddns.global.log_dir) || LOGDIR="/var/log/ddns"
LOGFILE="" # NEW # logfile can be enabled as new option
+PIDFILE="" # pid file
+UPDFILE="" # store UPTIME of last update
+DATFILE="/tmp/ddns_$$.dat" # save stdout data of WGet and other extern programs called
+ERRFILE="/tmp/ddns_$$.err" # save stderr output of WGet and other extern programs called
+
# number of lines to before rotate logfile
LOGLINES=$(uci -q get ddns.global.log_lines) || LOGLINES=250
LOGLINES=$((LOGLINES + 1)) # correct sed handling
# IPv6 ( ( 0-9a-f 1-4char ":") min 1x) ( ( 0-9a-f 1-4char )optional) ( (":" 0-9a-f 1-4char ) min 1x)
IPV6_REGEX="\(\([0-9A-Fa-f]\{1,4\}:\)\{1,\}\)\(\([0-9A-Fa-f]\{1,4\}\)\{0,1\}\)\(\(:[0-9A-Fa-f]\{1,4\}\)\{1,\}\)"
+# detect if called by dynamic_dns_lucihelper.sh script, disable retrys (empty variable == false)
+[ "$(basename $0)" = "dynamic_dns_lucihelper.sh" ] && LUCI_HELPER="TRUE" || LUCI_HELPER=""
+
# loads all options for a given package and section
# also, sets all_option_variables to a list of the variable names
# $1 = ddns, $2 = SECTION_ID
}
config_load "$__PKGNAME"
-
+
# Given SECTION_ID not found so no data, so return 1
[ -z "$__ALL_OPTION_VARIABLES" ] && return 1
}
# read's all service sections from ddns config
-# $1 = Name of variable to store
+# $1 = Name of variable to store
load_all_service_sections() {
local __DATA=""
- config_cb()
+ config_cb()
{
# only look for section type "service", ignore everything else
[ "$1" = "service" ] && __DATA="$__DATA $2"
}
config_load "ddns"
- eval "$1='$__DATA'"
+ eval "$1=\"$__DATA\""
return
}
for __SECTIONID in $__SECTIONS; do
config_get __IFACE "$__SECTIONID" interface "wan"
[ -z "$__EVENTIF" -o "$__IFACE" = "$__EVENTIF" ] || continue
- /usr/lib/ddns/dynamic_dns_updater.sh $__SECTIONID 0 > /dev/null 2>&1 &
+ /usr/lib/ddns/dynamic_dns_updater.sh $__SECTIONID 0 >/dev/null 2>&1 &
done
}
# VERBOSE_MODE > 1 then NO loop so NO truncate log to $LOGLINES lines
[ $VERBOSE_MODE -gt 1 ] || sed -i -e :a -e '$q;N;'$LOGLINES',$D;ba' $LOGFILE
fi
- [ "$SECTION_ID" = "lucihelper" ] && return # nothing else todo when running LuCI helper script
+ [ $LUCI_HELPER ] && return # nothing else todo when running LuCI helper script
[ $__LEVEL -eq 7 ] && return # no syslog for debug messages
[ $__EXIT -eq 1 ] && {
$__CMD # force syslog before exit
__POS=$(( $__POS + 1 )) # increment position
done
- eval "$1='$__ENC'" # transfer back to variable
+ eval "$1=\"$__ENC\"" # transfer back to variable
return 0
}
# check is URL or SCRIPT is given
__URL=$(echo "$__DATA" | grep "^http:")
[ -z "$__URL" ] && __SCRIPT="/usr/lib/ddns/$__DATA"
-
- eval "$1='$__URL'"
- eval "$2='$__SCRIPT'"
+
+ eval "$1=\"$__URL\""
+ eval "$2=\"$__SCRIPT\""
return 0
}
verify_host_port() {
local __HOST=$1
local __PORT=$2
- local __TMP __IP __IPV4 __IPV6 __RUNPROG __ERRPROG __ERR
+ local __IP __IPV4 __IPV6 __RUNPROG __ERR
# return codes
# 1 system specific error
# 2 nslookup error
[ $# -ne 2 ] && write_log 12 "Error calling 'verify_host_port()' - wrong number of parameters"
- __RUNPROG="nslookup $__HOST 2>/dev/null"
- __ERRPROG="nslookup $__HOST 2>&1"
+ __RUNPROG="/usr/bin/nslookup $__HOST >$DATFILE 2>$ERRFILE"
write_log 7 "#> $__RUNPROG"
- __TMP=$(eval $__RUNPROG) # test if nslookup runs without errors
+ eval $__RUNPROG
__ERR=$?
# command error
[ $__ERR -gt 0 ] && {
- write_log 7 "Error:\n$(eval $__ERRPROG)"
write_log 3 "DNS Resolver Error - BusyBox nslookup Error '$__ERR'"
+ write_log 7 "Error:\n$(cat $ERRFILE)"
return 2
}
# extract IP address
- __IPV4=$(echo "$__TMP" | sed -ne "3,\$ { s/^Address [0-9]*: \($IPV4_REGEX\).*$/\\1/p }")
- __IPV6=$(echo "$__TMP" | sed -ne "3,\$ { s/^Address [0-9]*: \($IPV6_REGEX\).*$/\\1/p }")
+ __IPV4=$(cat $DATFILE | sed -ne "3,\$ { s/^Address [0-9]*: \($IPV4_REGEX\).*$/\\1/p }")
+ __IPV6=$(cat $DATFILE | sed -ne "3,\$ { s/^Address [0-9]*: \($IPV6_REGEX\).*$/\\1/p }")
# check IP version if forced
if [ $force_ipversion -ne 0 ]; then
[ $use_ipv6 -eq 0 -a -z "$__IPV4" ] && __ERR=4
[ $use_ipv6 -eq 1 -a -z "$__IPV6" ] && __ERR=6
[ $__ERR -gt 0 ] && {
- [ "$SECTION_ID" = "lucihelper" ] && return 4
- write_log 14 "Invalid host Error '4' - Forced IP Version IPv$__ERR don't match"
+ [ $LUCI_HELPER ] && return 4
+ write_log 14 "Verify host Error '4' - Forced IP Version IPv$__ERR don't match"
}
fi
# verify nc command
# busybox nc compiled without -l option "NO OPT l!" -> critical error
- nc --help 2>&1 | grep -i "NO OPT l!" >/dev/null 2>&1 && \
+ /usr/bin/nc --help 2>&1 | grep -i "NO OPT l!" >/dev/null 2>&1 && \
write_log 12 "Busybox nc (netcat) compiled without '-l' option, error 'NO OPT l!'"
# busybox nc compiled with extensions
- nc --help 2>&1 | grep "\-w" >/dev/null 2>&1 && __NCEXT="TRUE"
+ /usr/bin/nc --help 2>&1 | grep "\-w" >/dev/null 2>&1 && __NCEXT="TRUE"
# connectivity test
# run busybox nc to HOST PORT
# so if not "force_ipversion" to use_ipv6 then connect test via ipv4, if availible
[ $force_ipversion -ne 0 -a $use_ipv6 -ne 0 -o -z "$__IPV4" ] && __IP=$__IPV6 || __IP=$__IPV4
- if [ -n "$__NCEXT" ]; then # nc compiled with extensions (timeout support)
- __RUNPROG="nc -w 1 $__IP $__PORT </dev/null >/dev/null 2>&1"
- __ERRPROG="nc -vw 1 $__IP $__PORT </dev/null 2>&1"
+ if [ -n "$__NCEXT" ]; then # BusyBox nc compiled with extensions (timeout support)
+ __RUNPROG="/usr/bin/nc -vw 1 $__IP $__PORT </dev/null >$DATFILE 2>$ERRFILE"
write_log 7 "#> $__RUNPROG"
eval $__RUNPROG
__ERR=$?
[ $__ERR -eq 0 ] && return 0
- write_log 7 "Error:\n$(eval $__ERRPROG)"
write_log 3 "Connect error - BusyBox nc (netcat) Error '$__ERR'"
+ write_log 7 "Error:\n$(cat $ERRFILE)"
return 3
else # nc compiled without extensions (no timeout support)
- __RUNPROG="timeout 2 -- nc $__IP $__PORT </dev/null >/dev/null 2>&1"
+ __RUNPROG="timeout 2 -- /usr/bin/nc $__IP $__PORT </dev/null >$DATFILE 2>$ERRFILE"
write_log 7 "#> $__RUNPROG"
eval $__RUNPROG
__ERR=$?
verify_dns() {
local __ERR=255 # last error buffer
local __CNT=0 # error counter
-
+
[ $# -ne 1 ] && write_log 12 "Error calling 'verify_dns()' - wrong number of parameters"
write_log 7 "Verify DNS server '$1'"
- while [ $__ERR -gt 0 ]; do
+ while [ $__ERR -ne 0 ]; do
# DNS uses port 53
verify_host_port "$1" "53"
__ERR=$?
- if [ "$SECTION_ID" = "lucihelper" ]; then # no retry if called by LuCI helper script
+ if [ $LUCI_HELPER ]; then # no retry if called by LuCI helper script
return $__ERR
- elif [ $__ERR -gt 0 -a $VERBOSE_MODE -gt 1 ]; then # VERBOSE_MODE > 1 then NO retry
- write_log 7 "Verbose Mode: $VERBOSE_MODE - NO retry on error"
+ elif [ $__ERR -ne 0 -a $VERBOSE_MODE -gt 1 ]; then # VERBOSE_MODE > 1 then NO retry
+ write_log 4 "Verify DNS server '$1' failed - Verbose Mode: $VERBOSE_MODE - NO retry on error"
return $__ERR
- elif [ $__ERR -gt 0 ]; then
+ elif [ $__ERR -ne 0 ]; then
__CNT=$(( $__CNT + 1 )) # increment error counter
# if error count > retry_count leave here
[ $__CNT -gt $retry_count ] && \
# $1 Proxy-String to verify
verify_proxy() {
# complete entry user:password@host:port
- # inside user and password NO '@' of ":" allowed
+ # inside user and password NO '@' of ":" allowed
# host and port only host:port
# host only host ERROR unsupported
# IPv4 address instead of host 123.234.234.123
fi
# No Port detected - EXITING
[ -z "$__PORT" ] && {
- [ "$SECTION_ID" = "lucihelper" ] && return 5
+ [ $LUCI_HELPER ] && return 5
write_log 14 "Invalid Proxy server Error '5' - proxy port missing"
}
while [ $__ERR -gt 0 ]; do
verify_host_port "$__HOST" "$__PORT"
__ERR=$?
- if [ "$SECTION_ID" = "lucihelper" ]; then # no retry if called by LuCI helper script
+ if [ $LUCI_HELPER ]; then # no retry if called by LuCI helper script
return $__ERR
elif [ $__ERR -gt 0 -a $VERBOSE_MODE -gt 1 ]; then # VERBOSE_MODE > 1 then NO retry
- write_log 7 "Verbose Mode: $VERBOSE_MODE - NO retry on error"
+ write_log 4 "Verify Proxy server '$1' failed - Verbose Mode: $VERBOSE_MODE - NO retry on error"
return $__ERR
elif [ $__ERR -gt 0 ]; then
__CNT=$(( $__CNT + 1 )) # increment error counter
}
do_transfer() {
- # $1 # Variable to store Answer of transfer
- # $2 # URL to use
- local __URL="$2"
+ # $1 # URL to use
+ local __URL="$1"
local __ERR=0
local __CNT=0 # error counter
- local __PROG __RUNPROG __ERRPROG __DATA
+ local __PROG __RUNPROG
- [ $# -ne 2 ] && write_log 12 "Error in 'do_transfer()' - wrong number of parameters"
+ [ $# -ne 1 ] && write_log 12 "Error in 'do_transfer()' - wrong number of parameters"
# lets prefer GNU Wget because it does all for us - IPv4/IPv6/HTTPS/PROXY/force IP version
if /usr/bin/wget --version 2>&1 | grep "\+ssl" >/dev/null 2>&1 ; then
- __PROG="/usr/bin/wget -t 2 -O -" # standard output only 2 retrys on error
+ __PROG="/usr/bin/wget -nv -t 1 -O $DATFILE -o $ERRFILE" # non_verbose no_retry outfile errfile
# force ip version to use
if [ $force_ipversion -eq 1 ]; then
[ $use_ipv6 -eq 0 ] && __PROG="$__PROG -4" || __PROG="$__PROG -6" # force IPv4/IPv6
# disable proxy if no set (there might be .wgetrc or .curlrc or wrong environment set)
[ -z "$proxy" ] && __PROG="$__PROG --no-proxy"
- __RUNPROG="$__PROG -q '$__URL' 2>/dev/null" # do transfer with "-q" to suppress not needed output
- __ERRPROG="$__PROG -d '$__URL' 2>&1" # do transfer with "-d" for debug mode
- __PROG="GNU Wget" # reuse for error logging
+ __RUNPROG="$__PROG $__URL" # build final command
+ __PROG="GNU Wget" # reuse for error logging
# 2nd choice is cURL IPv4/IPv6/HTTPS
# libcurl might be compiled without Proxy Support (default in trunk)
elif [ -x /usr/bin/curl ]; then
- __PROG="/usr/bin/curl"
+ __PROG="/usr/bin/curl -sS -o $DATFILE --stderr $ERRFILE"
# force ip version to use
if [ $force_ipversion -eq 1 ]; then
[ $use_ipv6 -eq 0 ] && __PROG="$__PROG -4" || __PROG="$__PROG -6" # force IPv4/IPv6
write_log 13 "cURL: libcurl compiled without Proxy support"
fi
- __RUNPROG="$__PROG -q '$__URL' 2>/dev/null" # do transfer with "-s" to suppress not needed output
- __ERRPROG="$__PROG -v '$__URL' 2>&1" # do transfer with "-v" for verbose mode
- __PROG="cURL" # reuse for error logging
+ __RUNPROG="$__PROG $__URL" # build final command
+ __PROG="cURL" # reuse for error logging
# busybox Wget (did not support neither IPv6 nor HTTPS)
elif [ -x /usr/bin/wget ]; then
- __PROG="/usr/bin/wget -O -"
+ __PROG="/usr/bin/wget -q -O $DATFILE"
# force ip version not supported
[ $force_ipversion -eq 1 ] && \
write_log 14 "BusyBox Wget: can not force IP version to use"
# disable proxy if no set (there might be .wgetrc or .curlrc or wrong environment set)
[ -z "$proxy" ] && __PROG="$__PROG -Y off"
- __RUNPROG="$__PROG -q '$__URL' 2>/dev/null" # do transfer with "-q" to suppress not needed output
- __ERRPROG="$__PROG '$__URL' 2>&1" #
- __PROG="Busybox Wget" # reuse for error logging
+ __RUNPROG="$__PROG $__URL 2>$ERRFILE" # build final command
+ __PROG="Busybox Wget" # reuse for error logging
else
write_log 13 "Neither 'Wget' nor 'cURL' installed or executable"
while : ; do
write_log 7 "#> $__RUNPROG"
- __DATA=$(eval $__RUNPROG)
- __ERR=$?
- [ $__ERR -eq 0 ] && {
- eval "$1='$__DATA'" # everything ok
- return 0 # return
- }
-
- [ "$SECTION_ID" = "lucihelper" ] && return 1 # no retry if called by LuCI helper script
+ $__RUNPROG # DO transfer
+ __ERR=$? # save error code
+ [ $__ERR -eq 0 ] && return 0 # no error leave
+ [ $LUCI_HELPER ] && return 1 # no retry if called by LuCI helper script
- write_log 7 "Error:\n$(eval $__ERRPROG)" # report error
- write_log 3 "$__PROG error: '$__ERR'"
- __DATA=""
+ write_log 3 "$__PROG Error: '$__ERR'"
+ write_log 7 "$(cat $ERRFILE)" # report error
[ $VERBOSE_MODE -gt 1 ] && {
# VERBOSE_MODE > 1 then NO retry
- write_log 7 "Verbose Mode: $VERBOSE_MODE - NO retry on error"
+ write_log 4 "Transfer failed - Verbose Mode: $VERBOSE_MODE - NO retry on error"
return 1
}
# verify given IP / no private IPv4's / no IPv6 addr starting with fxxx of with ":"
[ $use_ipv6 -eq 0 ] && __IP=$(echo $1 | grep -v -E "(^0|^10\.|^127|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-1]\.|^192\.168)")
[ $use_ipv6 -eq 1 ] && __IP=$(echo $1 | grep "^[0-9a-eA-E]")
- [ -z "$__IP" ] && write_log 14 "Private or invalid or no IP '$1' given"
+ [ -z "$__IP" ] && write_log 4 "Private or invalid or no IP '$1' given"
if [ -n "$update_script" ]; then
write_log 7 "parsing script '$update_script'"
. $update_script
else
- local __URL __ANSWER __ERR
+ local __URL __ERR
# do replaces in URL
__URL=$(echo $update_url | sed -e "s#\[USERNAME\]#$URL_USER#g" -e "s#\[PASSWORD\]#$URL_PASS#g" \
-e "s#\[DOMAIN\]#$domain#g" -e "s#\[IP\]#$__IP#g")
[ $use_https -ne 0 ] && __URL=$(echo $__URL | sed -e 's#^http:#https:#')
- do_transfer __ANSWER "$__URL" || return 1 # if VERBOSE_MODE > 1
+ do_transfer "$__URL" || return 1
- write_log 7 "DDNS Provider answered:\n$__ANSWER"
+ write_log 7 "DDNS Provider answered:\n$(cat $DATFILE)"
# analyse provider answers
# "good [IP_ADR]" = successful
# "nochg [IP_ADR]" = no change but OK
- echo "$__ANSWER" | grep -E "good|nochg" >/dev/null 2>&1
+ grep -E "good|nochg" $DATFILE >/dev/null 2>&1
return $? # "0" if "good" or "nochg" found
fi
}
get_local_ip () {
# $1 Name of Variable to store local IP (LOCAL_IP)
local __CNT=0 # error counter
- local __RUNPROG __DATA __URL __ANSWER
+ 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"
[ $use_ipv6 -eq 0 ] && __RUNPROG="network_get_ipaddr" \
|| __RUNPROG="network_get_ipaddr6"
write_log 7 "#> $__RUNPROG __DATA '$ip_network'"
- $__RUNPROG __DATA "$ip_network"
+ eval "$__RUNPROG __DATA $ip_network" || write_log 3 "$__RUNPROG Error: '$?'"
[ -n "$__DATA" ] && write_log 7 "Local IP '$__DATA' detected on network '$ip_network'"
;;
interface)
- write_log 7 "#> ifconfig '$ip_interface'"
- if [ $use_ipv6 -eq 0 ]; then
- __DATA=$(ifconfig $ip_interface | awk '
- /inet addr:/ { # Filter IPv4
- # inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
- $1=""; # remove inet
- $3=""; # remove Bcast: ...
- $4=""; # remove Mask: ...
- FS=":"; # separator ":"
- $0=$0; # reread to activate separator
- $1=""; # remove addr
- FS=" "; # set back separator to default " "
- $0=$0; # reread to activate separator (remove whitespaces)
- print $1; # print IPv4 addr
- }'
- )
+ write_log 7 "#> ifconfig $ip_interface >$DATFILE 2>$ERRFILE"
+ ifconfig $ip_interface >$DATFILE 2>$ERRFILE
+ __ERR=$?
+ if [ $__ERR -eq 0 ]; then
+ if [ $use_ipv6 -eq 0 ]; then
+ __DATA=$(awk '
+ /inet addr:/ { # Filter IPv4
+ # inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
+ $1=""; # remove inet
+ $3=""; # remove Bcast: ...
+ $4=""; # remove Mask: ...
+ FS=":"; # separator ":"
+ $0=$0; # reread to activate separator
+ $1=""; # remove addr
+ FS=" "; # set back separator to default " "
+ $0=$0; # reread to activate separator (remove whitespaces)
+ print $1; # print IPv4 addr
+ }' $DATFILE
+ )
+ else
+ __DATA=$(awk '
+ /inet6/ && /: [0-9a-eA-E]/ && !/\/128/ { # Filter IPv6 exclude fxxx and /128 prefix
+ # inet6 addr: 2001:db8::xxxx:xxxx/32 Scope:Global
+ FS="/"; # separator "/"
+ $0=$0; # reread to activate separator
+ $2=""; # remove everything behind "/"
+ FS=" "; # set back separator to default " "
+ $0=$0; # reread to activate separator
+ print $3; # print IPv6 addr
+ }' $DATFILE
+ )
+ fi
+ [ -n "$__DATA" ] && write_log 7 "Local IP '$__DATA' detected on interface '$ip_interface'"
else
- __DATA=$(ifconfig $ip_interface | awk '
- /inet6/ && /: [0-9a-eA-E]/ && !/\/128/ { # Filter IPv6 exclude fxxx and /128 prefix
- # inet6 addr: 2001:db8::xxxx:xxxx/32 Scope:Global
- FS="/"; # separator "/"
- $0=$0; # reread to activate separator
- $2=""; # remove everything behind "/"
- FS=" "; # set back separator to default " "
- $0=$0; # reread to activate separator
- print $3; # print IPv6 addr
- }'
- )
+ write_log 3 "ifconfig Error: '$__ERR'"
+ write_log 7 "$(cat $ERRFILE)" # report error
fi
- [ -n "$__DATA" ] && write_log 7 "Local IP '$__DATA' detected on interface '$ip_interface'"
;;
script)
- write_log 7 "#> $ip_script"
- __DATA=$($ip_script) # get ip from script
- [ -n "$__DATA" ] && write_log 7 "Local IP '$__DATA' detected via script '$ip_script'"
+ 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'"
+ else
+ write_log 3 "$ip_script Error: '$__ERR'"
+ write_log 7 "$(cat $ERRFILE)" # report error
+ fi
;;
web)
- for __URL in $ip_url; do
- do_transfer __ANSWER "$__URL"
- [ -n "$__ANSWER" ] && break # Answer detected, leave "for do done"
- done
+ do_transfer "$ip_url"
# use correct regular expression
[ $use_ipv6 -eq 0 ] \
- && __DATA=$(echo "$__ANSWER" | grep -m 1 -o "$IPV4_REGEX") \
- || __DATA=$(echo "$__ANSWER" | grep -m 1 -o "$IPV6_REGEX")
+ && __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 '$__URL'"
;;
*)
esac
# valid data found return here
[ -n "$__DATA" ] && {
- eval "$1='$__DATA'"
+ eval "$1=\"$__DATA\""
return 0
}
- [ "$SECTION_ID" = "lucihelper" ] && return 1 # no retry if called by LuCI helper script
+ [ $LUCI_HELPER ] && return 1 # no retry if called by LuCI helper script
[ $VERBOSE_MODE -gt 1 ] && {
# VERBOSE_MODE > 1 then NO retry
- write_log 7 "Verbose Mode: $VERBOSE_MODE - NO retry on error"
+ write_log 4 "Get local IP via '$ip_source' failed - Verbose Mode: $VERBOSE_MODE - NO retry on error"
return 1
}
# $2 (optional) if set, do not retry on error
local __CNT=0 # error counter
local __ERR=255
- local __REGEX __PROG __RUNPROG __ERRPROG __DATA
+ local __REGEX __PROG __RUNPROG __DATA
# return codes
# 1 no IP detected
# set correct regular expression
[ $use_ipv6 -eq 0 ] && __REGEX="$IPV4_REGEX" || __REGEX="$IPV6_REGEX"
- if [ -x /usr/bin/host ]; then
+ if [ -x /usr/bin/host ]; then
__PROG="/usr/bin/host"
[ $use_ipv6 -eq 0 ] && __PROG="$__PROG -t A" || __PROG="$__PROG -t AAAA"
if [ $force_ipversion -eq 1 ]; then # force IP version
[ $use_ipv6 -eq 0 ] && __PROG="$__PROG -4" || __PROG="$__PROG -6"
- fi
+ fi
[ $force_dnstcp -eq 1 ] && __PROG="$__PROG -T" # force TCP
- __RUNPROG="$__PROG $domain $dns_server 2>/dev/null"
- __ERRPROG="$__PROG -v $domain $dns_server 2>&1"
+ __RUNPROG="$__PROG $domain $dns_server >$DATFILE 2>$ERRFILE"
__PROG="BIND host"
elif [ -x /usr/bin/nslookup ]; then # last use BusyBox nslookup
[ $force_ipversion -ne 0 -o $force_dnstcp -ne 0 ] && \
write_log 14 "Busybox nslookup - no support to 'force IP Version' or 'DNS over TCP'"
- __RUNPROG="nslookup $domain $dns_server 2>/dev/null"
- __ERRPROG="nslookup $domain $dns_server 2>&1"
+ __RUNPROG="/usr/bin/nslookup $domain $dns_server >$DATFILE 2>$ERRFILE"
__PROG="BusyBox nslookup"
else # there must be an error
write_log 12 "Error in 'get_registered_ip()' - no supported Name Server lookup software accessible"
while : ; do
write_log 7 "#> $__RUNPROG"
- __DATA=$(eval $__RUNPROG)
+ eval $__RUNPROG
__ERR=$?
if [ $__ERR -ne 0 ]; then
- write_log 7 "Error:\n$(eval $__ERRPROG)"
write_log 3 "$__PROG error: '$__ERR'"
- __DATA=""
+ write_log 7 "Error:\n$(cat $ERRFILE)"
else
- if [ "$__PROG" = "BIND host" ]; then
- __DATA=$(echo "$__DATA" | awk -F "address " '/has/ {print $2; exit}' )
+ if [ "$__PROG" = "BIND host" ]; then
+ __DATA=$(cat $DATFILE | awk -F "address " '/has/ {print $2; exit}' )
else
- __DATA=$(echo "$__DATA" | sed -ne "3,\$ { s/^Address [0-9]*: \($__REGEX\).*$/\\1/p }" )
+ __DATA=$(cat $DATFILE | sed -ne "3,\$ { s/^Address [0-9]*: \($__REGEX\).*$/\\1/p }" )
fi
[ -n "$__DATA" ] && {
write_log 7 "Registered IP '$__DATA' detected"
- eval "$1='$__DATA'" # valid data found
+ eval "$1=\"$__DATA\"" # valid data found
return 0 # leave here
}
write_log 4 "NO valid IP found"
__ERR=127
fi
- [ "$SECTION_ID" = "lucihelper" ] && return $__ERR # no retry if called by LuCI helper script
+ [ $LUCI_HELPER ] && return $__ERR # no retry if called by LuCI helper script
[ -n "$2" ] && return $__ERR # $2 is given -> no retry
[ $VERBOSE_MODE -gt 1 ] && {
# VERBOSE_MODE > 1 then NO retry
- write_log 7 "Verbose Mode: $VERBOSE_MODE - NO retry on error"
+ write_log 4 "Get registered/public IP for '$domain' failed - Verbose Mode: $VERBOSE_MODE - NO retry on error"
return $__ERR
}
# $1 Variable to store result in
[ $# -ne 1 ] && write_log 12 "Error calling 'verify_host_port()' - wrong number of parameters"
local __UPTIME=$(cat /proc/uptime)
- eval "$1='${__UPTIME%%.*}'"
+ eval "$1=\"${__UPTIME%%.*}\""
}
trap_handler() {
kill -$1 $__PID # terminate it
done
IFS=$__OLD_IFS
-
+
+ # remove out and err file
+ [ -f $DATFILE ] && rm -f $DATFILE
+ [ -f $ERRFILE ] && rm -f $ERRFILE
+
# exit with correct handling:
# remove trap handling settings and send kill to myself
trap - 0 1 2 3 15
--- /dev/null
+#!/bin/sh
+# /usr/lib/ddns/luci_dns_helper.sh
+#
+# Written in August 2014
+# by Christian Schoenebeck <christian dot schoenebeck at gmail dot com>
+# This script is used by luci-app-ddns
+# - getting registered IP
+# - check if possible to get local IP
+# - verifing given DNS- or Proxy-Server
+#
+# variables in small chars are read from /etc/config/ddns as parameter given here
+# variables in big chars are defined inside these scripts as gloval vars
+# variables in big chars beginning with "__" are local defined inside functions only
+# set -vx #script debugger
+
+[ $# -lt 2 ] && exit 1
+
+. /usr/lib/ddns/dynamic_dns_functions.sh # global vars are also defined here
+
+# set -vx #script debugger
+
+# preset some variables, wrong or not set in dynamic_dns_functions.sh
+SECTION_ID="lucihelper"
+LOGFILE="$LOGDIR/$SECTION_ID.log"
+VERBOSE_MODE=0 # no console logging
+# global variables normally set by reading DDNS UCI configuration
+use_syslog=0 # no syslog
+use_logfile=0 # by default no logfile, can be changed here
+
+__RET=0
+case "$1" in
+ get_registered_ip)
+ local IP
+ domain=$2 # Hostname/Domain
+ use_ipv6=${3:-"0"} # Use IPv6 - default IPv4
+ force_ipversion=${4:-"0"} # Force IP Version - default 0 - No
+ force_dnstcp=${5:-"0"} # Force TCP on DNS - default 0 - No
+ dns_server=${6:-""} # DNS server - default No DNS
+ write_log 7 "-----> get_registered_ip IP"
+ get_registered_ip IP
+ __RET=$?
+ [ $__RET -ne 0 ] && IP=""
+ echo -n "$IP" # suppress LF
+ ;;
+ verify_dns)
+ # $2 : dns-server to verify # no need for force_dnstcp because
+ # verify with nc (netcat) uses tcp anyway
+ use_ipv6=${3:-"0"} # Use IPv6 - default IPv4
+ force_ipversion=${4:-"0"} # Force IP Version - default 0 - No
+ write_log 7 "-----> verify_dns '$2'"
+ verify_dns "$2"
+ __RET=$?
+ ;;
+ verify_proxy)
+ # $2 : proxy string to verify
+ use_ipv6=${3:-"0"} # Use IPv6 - default IPv4
+ force_ipversion=${4:-"0"} # Force IP Version - default 0 - No
+ write_log 7 "-----> verify_proxy '$2'"
+ verify_proxy "$2"
+ __RET=$?
+ ;;
+ get_local_ip)
+ local IP
+ use_ipv6="$2" # Use IPv6
+ ip_source="$3" # IP source
+ ip_network="$4" # set if source = "network" otherwise "-"
+ ip_url="$5" # set if source = "web" otherwise "-"
+ ip_interface="$6" # set if source = "interface" itherwiase "-"
+ ip_script="$7" # set if source = "script" otherwise "-"
+ proxy="$8" # proxy if set
+ force_ipversion="0" # not needed but must be set
+ use_https="0" # not needed but must be set
+ [ -n "$proxy" -a "$ip_source" = "web" ] && {
+ # proxy defined, used for ip_source=web
+ export HTTP_PROXY="http://$proxy"
+ export HTTPS_PROXY="http://$proxy"
+ export http_proxy="http://$proxy"
+ export https_proxy="http://$proxy"
+ }
+ # don't need IP only the return code
+ [ "$ip_source" = "web" -o "$ip_source" = "script" ] && {
+ # 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 "-----> get_local_ip IP"
+ get_local_ip IP
+ }
+ __RET=$?
+ ;;
+ *)
+ __RET=255
+ ;;
+esac
+
+# remove out and err file
+[ -f $DATFILE ] && rm -f $DATFILE
+[ -f $ERRFILE ] && rm -f $ERRFILE
+return $__RET
\ No newline at end of file
# (Loosely) based on the script on the one posted by exobyte in the forums here:
# http://forum.openwrt.org/viewtopic.php?id=14040
#
-# extended and partial rewritten in August 2014
+# extended and partial rewritten in August 2014
# by Christian Schoenebeck <christian dot schoenebeck at gmail dot com>
# to support:
# - IPv6 DDNS services
# - Proxy Server to send out updates
# - force_interval=0 to run once (Luci Ticket 538)
# - the usage of BIND's host command instead of BusyBox's nslookup if installed
-# - extended Verbose Mode and log file support for better error detection
+# - extended Verbose Mode and log file support for better error detection
# - wait for interface to fully come up, before the first update is done
#
# variables in small chars are read from /etc/config/ddns
# config_get <variable> $SECTION_ID <option>
#
# defined options (also used as variable):
-#
+#
# enable self-explanatory
# interface network interface used by hotplug.d i.e. 'wan' or 'wan6'
#
# 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_interface physical interface to use for detecting
+# ip_interface physical interface to use for detecting
#
-# check_interval check for changes every !!! checks below 10 minutes make no sense because the Internet
+# check_interval check for changes every !!! checks below 10 minutes make no sense because the Internet
# check_unit 'days' 'hours' 'minutes' !!! needs about 5-10 minutes to sync an IP-change for an DNS entry
#
# force_interval force to send an update to your service if no change was detected
# proxy #NEW# using a proxy for communication !!! ALSO used to detect local IP via web => return proxy's IP !!!
# use_logfile #NEW# self-explanatory "/var/log/ddns/$SECTION_ID.log"
#
-# some functionality needs
+# some functionality needs
# - GNU Wget or cURL installed for sending updates to DDNS service
# - BIND host installed to detect Registered IP
#
}
load_all_config_options "ddns" "$SECTION_ID"
-write_log 7 "************ ************** ************** **************"
-write_log 5 "PID '$$' started at $(eval $DATE_PROG)"
+write_log 7 "************ ************** ************** **************"
+write_log 5 "PID '$$' started at $(eval $DATE_PROG)"
+write_log 7 "uci configuraion:\n$(uci -q show ddns.$SECTION_ID | sort)"
case $VERBOSE_MODE in
- 0) write_log 7 "verbose mode '0' - run normal, NO console output";;
- 1) write_log 7 "verbose mode '1' - run normal, console mode";;
- 2) write_log 7 "verbose mode '2' - run once, NO retry on error";;
- 3) write_log 7 "verbose mode '3' - run once, NO retry on error, NOT sending update";;
+ 0) write_log 7 "verbose mode : 0 - run normal, NO console output";;
+ 1) write_log 7 "verbose mode : 1 - run normal, console mode";;
+ 2) write_log 7 "verbose mode : 2 - run once, NO retry on error";;
+ 3) write_log 7 "verbose mode : 3 - run once, NO retry on error, NOT sending update";;
*) write_log 14 "error detecting VERBOSE_MODE '$VERBOSE_MODE'";;
esac
-write_log 7 "uci configuraion:\n$(uci -q show ddns.$SECTION_ID | sort)"
# set defaults if not defined
[ -z "$enabled" ] && enabled=0
# verify ip_source script if configured and executable
if [ "$ip_source" = "script" ]; then
- [ -z "$ip_script" ] && write_log 14 "No script defined to detect local IP!"
- [ -x "$ip_script" ] || write_log 14 "Script to detect local IP not found or not executable!"
+ 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!"
fi
# compute update interval in seconds
echo $$ > $PIDFILE
# determine when the last update was
-# the following lines should prevent multiple updates if hotplug fires multiple startups
+# the following lines should prevent multiple updates if hotplug fires multiple startups
# as described in Ticket #7820, but did not function if never an update take place
# i.e. after a reboot (/var is linked to /tmp)
-# using uptime as reference because date might not be updated via NTP client
+# using uptime as reference because date might not be updated via NTP client
get_uptime CURR_TIME
[ -e "$UPDFILE" ] && {
LAST_TIME=$(cat $UPDFILE)
wait $PID_SLEEP # enable trap-handler
PID_SLEEP=0
-# verify DNS server
+# verify DNS server
[ -n "$dns_server" ] && verify_dns "$dns_server"
# verify Proxy server and set environment
ERR_LAST=$? # save return value
}
- # error sending local IP to provider
+ # error sending local 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
# to early retrys will block most DDNS provider
# providers answer is checked inside send_update() function
- [ $ERR_LAST -eq 0 ] && {
+ 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"
- } || write_log 3 "Can not update IP at DDNS Provider"
+ [ "$LOCAL_IP" != "$REGISTERED_IP" ] && write_log 6 "Update successful - IP '$LOCAL_IP' send"
+ [ "$LOCAL_IP" = "$REGISTERED_IP" ] || write_log 6 "Forced update successful - IP: '$LOCAL_IP' send"
+ else
+ write_log 3 "Can not update IP at DDNS Provider"
+ fi
fi
# now we wait for check interval before testing if update was recognized
fi
# force_update=0 or VERBOSE_MODE > 1 - leave here
- [ $VERBOSE_MODE -gt 1 ] && write_log 7 "Verbose Mode: $VERBOSE_MODE - NO reloop"; exit 0
- [ $FORCE_SECONDS -eq 0 ] && write_log 6 "Configured to run once"; exit 0
+ [ $VERBOSE_MODE -gt 1 ] && write_log 7 "Verbose Mode: $VERBOSE_MODE - NO reloop"
+ [ $FORCE_SECONDS -eq 0 ] && write_log 6 "Configured to run once"
+ [ $VERBOSE_MODE -gt 1 -o $FORCE_SECONDS -eq 0 ] && exit 0
+
write_log 6 "Rerun IP check at $(eval $DATE_PROG)"
done
# we should never come here there must be a programming error
--- /dev/null
+#!/bin/sh
+#
+# sample script for detecting local IP
+# 2014 Christian Schoenebeck <christian dot schoenebeck at gmail dot com>
+#
+# activated inside /etc/config/ddns by setting
+#
+# option ip_source 'script'
+# option ip_script '/usr/lib/ddns/getlocalip_sample.sh -6' !!! parameters ALLOWED
+#
+# the script is executed (not parsed) inside get_local_ip() function
+# of /usr/lib/ddns/dynamic_dns_functions.sh
+#
+# This script should
+# - return the IP address via stdout echo -n "...." !!! without line feed
+# - report errors via stderr echo "...." >&2
+# - return an error code ('0' for success) exit 123
+
+case $1 in
+ -4) echo -n "8.8.8.8" # never append linefeed or simular
+ exit 0
+ ;; # IP's of Googles public DNS
+ -6) echo -n "2001:4860:4860::8888"
+ exit 0
+ ;;
+ *) echo "$0 - Invalid or missing parameter" >&2
+ exit 1
+esac
+echo "Should never come here" >&2
+exit 2
#4
#4 This file contains the update urls for various dynamic dns services.
#4 Column one contains the service name, column two contains the update url.
-#4 within the update url there are 4 variables you can use: [USERNAME],
-#4 [PASSWORD], [DOMAIN] and [IP]. These are substituted for the username,
-#4 password, and domain name specified in the /etc/config/ddns file when an
+#4 within the update url there are 4 variables you can use: [USERNAME],
+#4 [PASSWORD], [DOMAIN] and [IP]. These are substituted for the username,
+#4 password, and domain name specified in the /etc/config/ddns file when an
#4 update is performed. The IP is substituted for the current ip address of the
-#4 router. These variables are case sensitive, while urls generally are not, so
-#4 if you need to enter the same text in the url (which seems very unlikely) put
+#4 router. These variables are case sensitive, while urls generally are not, so
+#4 if you need to enter the same text in the url (which seems very unlikely) put
#4 that text in lowercase, while the variables should remain in uppercase
#4
#4 There are TONS of dynamic dns services out there. There's a huge list of them at:
#4
#4 !!! Since ddns-scripts Version 2.x the update of IPv6 addresses is also supported
#4 !!! This file is used for update of IPv4 adresses only. For IPv6 use services_ipv6
-#4
-#4 !!! Since ddns-scripts Version 2.x the update via provider specific update scripts is supported.
+#4
+#4 !!! Since ddns-scripts Version 2.x the update via provider specific update scripts is supported.
#4 !!! This scripts must be located at /usr/lib/ddns directory if defined inside this file.
-#4 !!! Use only the script name (without path). Sample:
+#4 !!! Use only the script name (without path). Sample:
#4 !!! "example.com" "update_sample.sh"
#4
#444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
"thatip.com" "http://update.dnsmax.com/update/?username=[USERNAME]&password=[PASSWORD]&resellerid=2&clientname=openwrt&clientversion=8.09&protocolversion=2.0&updatehostname=[DOMAIN]&ip=[IP]"
# Hurricane Electric Dynamic DNS
-"he.net" "http://[DOMAIN]:[PASSWORD]@dyn.dns.he.net/nic/update?hostname=[DOMAIN]&myip=[IP]"
+"he.net" "http://[DOMAIN]:[PASSWORD]@dyn.dns.he.net/nic/update?hostname=[DOMAIN]&myip=[IP]"
# DNSdynamic.org
"dnsdynamic.org" "http://[USERNAME]:[PASSWORD]@www.dnsdynamic.org/api/?hostname=[DOMAIN]&myip=[IP]"
# LoopiaDNS
"loopia.se" "http://[USERNAME]:[PASSWORD]@dns.loopia.se/XDynDNSServer/XDynDNS.php?system=custom&hostname=[DOMAIN]&myip=[IP]"
+
+# Cloudflare
+"cloudflare.com" "update_cloudflare.sh"
+
+# SelfHost.de
+"selfhost.de" "http://carol.selfhost.de/update?username=[USERNAME]&password=[PASSWORD]&myip=[IP]&hostname=1"
+
+# no-ip.pl nothing to do with no-ip.com (domain registered to www.domeny.tv) (IP autodetected by provider)
+"no-ip.pl" "http://[USERNAME]:[PASSWORD]@update.no-ip.pl/?hostname=[DOMAIN]"
#6
#6 This file contains the update urls for various dynamic dns services.
#6 Column one contains the service name, column two contains the update url.
-#6 within the update url there are 4 variables you can use: [USERNAME],
-#6 [PASSWORD], [DOMAIN] and [IP]. These are substituted for the username,
-#6 password, and domain name specified in the /etc/config/ddns file when an
+#6 within the update url there are 4 variables you can use: [USERNAME],
+#6 [PASSWORD], [DOMAIN] and [IP]. These are substituted for the username,
+#6 password, and domain name specified in the /etc/config/ddns file when an
#6 update is performed. The IP is substituted for the current ip address of the
-#6 router. These variables are case sensitive, while urls generally are not, so
-#6 if you need to enter the same text in the url (which seems very unlikely) put
+#6 router. These variables are case sensitive, while urls generally are not, so
+#6 if you need to enter the same text in the url (which seems very unlikely) put
#6 that text in lowercase, while the variables should remain in uppercase
#6
#6 There are TONS of dynamic dns services out there. There's a huge list of them at:
#6
#6 !!! Since ddns-scripts Version 2.x the update of IPv6 addresses is also supported
#6 !!! This file is used for update of IPv6 adresses only. For IPv4 use services
-#6
-#6 !!! Since ddns-scripts Version 2.x the update via provider specific update scripts is supported.
+#6
+#6 !!! Since ddns-scripts Version 2.x the update via provider specific update scripts is supported.
#6 !!! This scripts must be located at /usr/lib/ddns directory if defined inside this file.
#6 !!! Use only the script name (without path). Sample:
#6 !!! "example.com" "update_sample.sh"
"spdns.de" "http://[USERNAME]:[PASSWORD]@update.spdns.de/nic/update?hostname=[DOMAIN]&myip=[IP]"
#IPv6 @ Hurricane Electric Dynamic DNS
-"he.net" "http://[DOMAIN]:[PASSWORD]@dyn.dns.he.net/nic/update?hostname=[DOMAIN]&myip=[IP]"
+"he.net" "http://[DOMAIN]:[PASSWORD]@dyn.dns.he.net/nic/update?hostname=[DOMAIN]&myip=[IP]"
#IPv6 @ MyDNS.JP
"mydns.jp" "http://www.mydns.jp/directip.html?MID=[USERNAME]&PWD=[PASSWORD]&IPV6ADDR=[IP]"
+
+#IPv6 @ Cloudflare
+"cloudflare.com" "update_cloudflare.sh"
+
+#IPv6 @ no-ip.pl nothing to do with no-ip.com (domain registered to www.domeny.tv) (IP autodetected by provider)
+"no-ip.pl" "http://[USERNAME]:[PASSWORD]@update.no-ip.pl/?hostname=[DOMAIN]"
--- /dev/null
+#
+# script for sending updates to cloudflare.com
+# 2014 Christian Schoenebeck <christian dot schoenebeck at gmail dot com>
+# many thanks to Paul for testing and feedback during development
+#
+# This script is parsed by dynamic_dns_functions.sh inside send_update() function
+#
+# using following options from /etc/config/ddns
+# option username - your cloudflare e-mail
+# option password - cloudflare api key, you can get it from cloudflare.com/my-account/
+# option domain - your full hostname to update, in cloudflare its subdomain.domain
+# i.e. myhost.example.com where myhost is the subdomain and example.com is your domain
+#
+# Attention !!! script will only work if there is only one subdomain-level at your domain
+# subdomain2.subdomain1.domain i.e. mail.host.example.com will not work
+#
+# variable __IP already defined with the ip-address to use for update
+#
+[ $use_https -eq 0 ] && write_log 14 "Cloudflare only support updates via Secure HTTP (HTTPS). Please correct configuration!"
+
+local __RECID __URL __KEY __KEYS __FOUND __DOMREC
+local __SUBDOM=$(echo $domain | awk -F "." '{print $1}')
+local __DOMAIN=$(echo $domain | awk -F "${__SUBDOM}." '{print $2}')
+local __TMP="/tmp/$$.json"
+
+# parse OpenWrt script with
+# functions for parsing and generating json
+. /usr/share/libubox/jshn.sh
+
+# function copied from /usr/share/libubox/jshn.sh
+# from BB14.09 for backward compatibility to AA12.09
+json_get_keys() {
+ local __dest="$1"
+ local _tbl_cur
+
+ if [ -n "$2" ]; then
+ json_get_var _tbl_cur "$2"
+ else
+ _json_get_var _tbl_cur JSON_CUR
+ fi
+ local __var="${JSON_PREFIX}KEYS_${_tbl_cur}"
+ eval "export -- \"$__dest=\${$__var}\"; [ -n \"\${$__var+x}\" ]"
+}
+
+# function to "sed" unwanted string parts from DATFILE
+cleanup() {
+ #based on the sample output on cloudflare.com homepage we need to do some cleanup
+ sed -i 's/^[ \t]*//;s/[ \t]*$//' $DATFILE # remove invisible chars at beginning and end of lines
+ sed -i '/^-$/d' $DATFILE # remove lines with "-" (dash)
+ sed -i '/^$/d' $DATFILE # remove empty lines
+ sed -i "#'##g" $DATFILE # remove "'" (single quote)
+}
+
+# build url according to cloudflare client api at https://www.cloudflare.com/docs/client-api.html
+# to "rec_load_all" to detect rec_id needed for update
+__URL="https://www.cloudflare.com/api_json.html" # https://www.cloudflare.com/api_json.html
+__URL="${__URL}?a=rec_load_all" # -d 'a=rec_load_all'
+__URL="${__URL}&tkn=$password" # -d 'tkn=8afbe6dea02407989af4dd4c97bb6e25'
+__URL="${__URL}&email=$username" # -d 'email=sample@example.com'
+__URL="${__URL}&z=$__DOMAIN" # -d 'z=example.com'
+
+# lets request the data
+do_transfer "$__URL" || return 1
+
+cleanup # cleanup dat file
+json_load "$(cat $DATFILE)" # lets extract data
+__FOUND=0 # found record indicator
+json_get_var __RES "result" # cloudflare result of last request
+json_get_var __MSG "msg" # cloudflare error message
+[ "$__RES" != "success" ] && {
+ write_log 4 "'rec_load_all' failed with error: \n$__MSG"
+ return 1
+}
+
+json_select "response"
+json_select "recs"
+json_select "objs"
+json_get_keys __KEYS
+for __KEY in $__KEYS; do
+ local __ZONE __NAME __DISPLAY __TYPE
+ json_select "$__KEY"
+ json_get_var __ZONE "zone_name"
+ json_get_var __NAME "name"
+ json_get_var __DISPLAY "display_name"
+ json_get_var __TYPE "type"
+ # if "zone_name" == "name" == "display_name" == $domain, then we found a valid domain record
+ if [ "$__NAME" = "$domain" ]; then
+ [ "$__DISPLAY" = "$__ZONE" ] && __DOMREC=1 || __DOMREC=0
+ # we must verify IPv4 and IPv6 because there might be both for the same host
+ [ \( $use_ipv6 -eq 0 -a "$__TYPE" = "A" \) -o \( $use_ipv6 -eq 1 -a "$__TYPE" = "AAAA" \) ] && {
+ __FOUND=1 # mark found
+ break # found leave for loop
+ }
+ fi
+ json_select ..
+done
+[ $__FOUND -eq 0 ] && {
+ # we don't need to continue trying to update cloudflare because record to update does not exist
+ # user has to setup record first outside ddns-scripts
+ write_log 14 "No valid record found at Cloudflare setup. Please create first!"
+}
+json_get_var __RECID "rec_id" # last thing to do get rec_id
+json_cleanup # cleanup
+write_log 7 "rec_id '$__RECID' detected for host/domain '$domain'"
+
+# build url according to cloudflare client api at https://www.cloudflare.com/docs/client-api.html
+# for "rec_edit" to update IP address
+__URL="https://www.cloudflare.com/api_json.html" # https://www.cloudflare.com/api_json.html
+__URL="${__URL}?a=rec_edit" # -d 'a=rec_edit'
+__URL="${__URL}&tkn=$password" # -d 'tkn=8afbe6dea02407989af4dd4c97bb6e25'
+__URL="${__URL}&id=$__RECID" # -d 'id=9001'
+__URL="${__URL}&email=$username" # -d 'email=sample@example.com'
+[ $__DOMREC -eq 0 ] && __URL="${__URL}&z=$__DOMAIN" # -d 'z=example.com'
+[ $__DOMREC -eq 1 ] && __URL="${__URL}&z=$domain" # -d 'z=example.com'
+
+[ $use_ipv6 -eq 0 ] && __URL="${__URL}&type=A" # -d 'type=A' (IPv4)
+[ $use_ipv6 -eq 1 ] && __URL="${__URL}&type=AAAA" # -d 'type=AAAA' (IPv6)
+
+[ $__DOMREC -eq 0 ] && __URL="${__URL}&name=$__SUBDOM" # -d 'name=sub' (HOST/SUBDOMAIN)
+[ $__DOMREC -eq 1 ] && __URL="${__URL}&name=$domain" # -d 'name=example.com'(DOMAIN)
+
+__URL="${__URL}&content=$__IP" # -d 'content=1.2.3.4'
+__URL="${__URL}&service_mode=0" # -d 'service_mode=0'
+__URL="${__URL}&ttl=1" # -d 'ttl=1'
+
+# lets do the update
+do_transfer "$__URL" || return 1
+
+cleanup # cleanup tmp file
+json_load "$(cat $DATFILE)" # lets extract data
+json_get_var __RES "result" # cloudflare result of last request
+json_get_var __MSG "msg" # cloudflare error message
+[ "$__RES" != "success" ] && {
+ write_log 4 "'rec_edit' failed with error:\n$__MSG"
+ return 1
+}
+write_log 7 "Update of rec_id '$__RECID' successful"
+return 0
# provider did not reactivate records, if no IP change was recognized
# so we send a dummy (localhost) and a seconds later we send the correct IP addr
#
-local __ANSWER __LH
+local __DUMMY
local __UPDURL="http://[USERNAME]:[PASSWORD]@dynupdate.no-ip.com/nic/update?hostname=[DOMAIN]&myip=[IP]"
# set IP version dependend dummy (localhost)
-[ $use_ipv6 -eq 0 ] && __LH="127.0.0.1" || __LH="::1"
+[ $use_ipv6 -eq 0 ] && __DUMMY="127.0.0.1" || __DUMMY="::1"
# lets do DUMMY transfer
write_log 7 "sending dummy IP to 'no-ip.com'"
__URL=$(echo $__UPDURL | sed -e "s#\[USERNAME\]#$URL_USER#g" -e "s#\[PASSWORD\]#$URL_PASS#g" \
- -e "s#\[DOMAIN\]#$domain#g" -e "s#\[IP\]#$__LH#g")
+ -e "s#\[DOMAIN\]#$domain#g" -e "s#\[IP\]#$__DUMMY#g")
[ $use_https -ne 0 ] && __URL=$(echo $__URL | sed -e 's#^http:#https:#')
-do_transfer __ANSWER "$__URL" || return 1
+do_transfer "$__URL" || return 1
-write_log 7 "'no-ip.com' answered:\n$__ANSWER"
+write_log 7 "'no-ip.com' answered:\n$(cat $DATFILE)"
# analyse provider answers
# "good [IP_ADR]" = successful
# "nochg [IP_ADR]" = no change but OK
-echo "$__ANSWER" | grep -E "good|nochg" >/dev/null 2>&1 || return 1
+grep -E "good|nochg" $DATFILE >/dev/null 2>&1 || return 1
# lets wait a seconds
sleep 1
-e "s#\[DOMAIN\]#$domain#g" -e "s#\[IP\]#$__IP#g")
[ $use_https -ne 0 ] && __URL=$(echo $__URL | sed -e 's#^http:#https:#')
-do_transfer __ANSWER "$__URL" || return 1
+do_transfer "$__URL" || return 1
-write_log 7 "'no-ip.com' answered:\n$__ANSWER"
+write_log 7 "'no-ip.com' answered:\n$(cat $DATFILE)"
# analyse provider answers
# "good [IP_ADR]" = successful
# "nochg [IP_ADR]" = no change but OK
-echo "$__ANSWER" | grep -E "good|nochg" >/dev/null 2>&1
+grep -E "good|nochg" $DATFILE >/dev/null 2>&1
return $? # "0" if "good" or "nochg" found
-# sample script for sending user defined updates
+# sample script for sending user defined updates
# 2014 Christian Schoenebeck <christian dot schoenebeck at gmail dot com>
#
# activated inside /etc/config/ddns by setting
#
-# option update_script '/usr/lib/ddns/update_sample.sh'
+# option update_script '/usr/lib/ddns/update_sample.sh'
#
# the script is parsed (not executed) inside send_update() function
# of /usr/lib/ddns/dynamic_dns_functions.sh
# so you can use all available functions and global variables inside this script
# already defined in dynamic_dns_updater.sh and dynamic_dns_functions.sh
#
-# It make sence to define the update url ONLY inside this script
+# It make sence to define the update url ONLY inside this script
# because it's anyway unique to the update script
# otherwise it should work with the default scripts
#
# the code here is the copy of the default used inside send_update()
#
-local __ANSWER
# tested with spdns.de
local __URL="http://[USERNAME]:[PASSWORD]@update.spdns.de/nic/update?hostname=[DOMAIN]&myip=[IP]"
-e "s#\[DOMAIN\]#$domain#g" -e "s#\[IP\]#$__IP#g")
[ $use_https -ne 0 ] && __URL=$(echo $__URL | sed -e 's#^http:#https:#')
-do_transfer __ANSWER "$__URL" || return 1
+do_transfer "$__URL" || return 1
-write_log 7 "DDNS Provider answered:\n$__ANSWER"
+write_log 7 "DDNS Provider answered:\n$(cat $DATFILE)"
# analyse provider answers
# "good [IP_ADR]" = successful
# "nochg [IP_ADR]" = no change but OK
-echo "$__ANSWER" | grep -E "good|nochg" >/dev/null 2>&1
+grep -E "good|nochg" $DATFILE >/dev/null 2>&1
return $? # "0" if "good" or "nochg" found