ASR_BASE

Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/external/subpack/net/ddns-scripts/samples/ddns.config_sample b/external/subpack/net/ddns-scripts/samples/ddns.config_sample
new file mode 100644
index 0000000..a3aa7e8
--- /dev/null
+++ b/external/subpack/net/ddns-scripts/samples/ddns.config_sample
@@ -0,0 +1,314 @@
+#
+#
+# Here you find a description on every parameter supported
+# 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.
+# 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
+# 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
+# and those starting with # (comments).
+#
+
+#####################################################################
+# Global application settings
+#
+config ddns "global"
+
+	###########
+	# set date format to use for display date in logfiles
+	# and LuCI web application.
+	# For codes see man pages of date command.
+	# default: "%F %R" (ISO 8601 format)
+#	option ddns_dateformat "%F %R"
+
+	###########
+	# set run directory to use for .pid and .update files
+	# there will be a separate file for every running service section
+	# default: "/var/run/ddns"
+#	option ddns_rundir "/var/run/ddns"
+
+	###########
+	# set log directory to use for .log files
+	# there will be a separate file for every running service section
+	# default: "/var/log/ddns"
+#	option ddns_logdir "/var/log/ddns"
+
+	###########
+	# set number of lines stored in .log file before auto truncated
+	# default: "250" lines
+#	option ddns_loglines "250"
+
+	###########
+	# Whether to allow to send Private/Special IP's to the DDNS provider
+	# IPv4: 0.x, 10.x, 127.x, 172.16.x-172.31.x, 192.168.x
+	# IPv6: ::, Fxxx:
+	# default: "0"	disabled
+#	option upd_privateip "0"
+
+#####################################################################
+# DDNS service settings
+#
+# 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
+# other special characters inside name.
+config service "myddns"
+
+	########### Basic settings ########################
+
+	###########
+	# enable/disable this service section
+	# default: "0"	disabled
+	option enabled "0"
+
+	###########
+	# detecting/sending IPv4 or IPv6 address to the DDNS provider
+	# set to "1" if you want to use IPv6
+	# default: "0"	use IPv4
+	option use_ipv6 "0"
+
+	###########
+	# defines the network as defined in /etc/config/network
+	# 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
+	# 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
+	# "/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
+	# "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
+	# 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,
+	# then you could write your own script to send updates to your ddns provider.
+	# Have a look into /usr/lib/ddns/update_sample.sh
+	# The script is specified in "update_script"
+	# Either set "service_name" or one of "update_url" and "update_script"
+	# default: none
+	option service_name "dyndns.org"
+
+	# sample:
+	# "http://[USERNAME]:[PASSWORD]@members.dyndns.org/nic/update?hostname=[DOMAIN]&myip=[IP]"
+#	option update_url   ""
+
+	# sample:
+	# "/usr/lib/ddns/update_sample.sh"
+#	option update_script   ""
+
+	###########
+	# Keep an eye on providers help pages.
+	#
+	# FQDN of ONE of your defined host at DDNS provider
+	# REQUIRED to verify what the current IP at DNS using nslookup/host command
+	# default: none
+	option lookup_host ""
+
+	# Your DNS name / replace [DOMAIN] in update_url
+	# default: none
+	option domain ""
+
+	# Username of your DDNS service account / replace [USERNAME] in update_url
+	# default: none
+	option username ""
+
+	# Password of your DDNS service account / replace [PASSWORD] in update url
+	# default: none
+	option password ""
+
+	###########
+	# Optional parameters for use inside update_url
+	#
+	# parameter that will be urlencoded before replacement of [PARAMENC] inside update url
+	# default: none
+	option param_enc ""
+
+	# parameter that repace [PARAMOPT] inside update url
+	# default: none
+	option param_opt ""
+
+	###########
+	# 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.
+	# 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
+	# 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)
+	# if you don't want to verify servers certificate (insecure) you should
+	# this parameter to "IGNORE" (in capital letters)
+	# default: (none)	path where CA-certificate package is installed
+	option cacert "/etc/ssl/certs"
+
+	###########
+	# for logging and control if everything work fine you can get information inside
+	# system log . Critical Errors are always send to system log.
+	# You can define which information you like to log
+	# 1 == info, notice, warning, errors
+	# 2 == notice, warning, errors
+	# 3 == warning, errors
+	# 4 == errors
+	# default: "0" off
+	option use_syslog  "0"
+
+	###########
+	# for logging and control if everything work fine you can get information inside
+	# log file. You find the file per default in /var/log/ddns/[sectionname].log
+	# The path can be modified for all log files in ddns.global section (see above)
+	# default: "1" on
+	option use_logfile "1"
+
+	########### Advanced settings #####################
+
+	###########
+	# you need to specify how ddns-scripts should detect you current local ip.
+	# the ip_source could be set to "network", "web", "interface" or "script"
+	# the parameters below specifying the additional information needed for
+	# the corresponding ip_spource configuration
+	# default: "network"
+
+	# ip_source "network" additional uses option ip_network and detects the
+	# current local ip on network as defined in /etc/config/network
+	# default: "wan"  using IPv4
+	# default: "wan6" using IPv6
+	option ip_source  "network"
+	option ip_network "wan"
+
+	# 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.
+	# default: "http://checkip.dyndns.com"   using IPv4
+	# default: "http://checkipv6.dyndns.com" using IPv6
+#	option ip_source "web"
+#	option ip_url    "http://checkip.dyndns.com"
+
+	# ip_source "interface" additional uses option ip_interface
+	# ip_source "interface" uses one of the locally installed physical interfaces
+	# to detect independent from network they configured to.
+	# default: none
+#	option ip_source    "interface"
+#	option ip_interface "eth1"
+
+	# ip_source "script" additional uses option ip_script
+	# it's useful if you want to write your own script to detect the
+	# current local ip. put full path into ip_script option.
+	# The script must be executable.
+	# default: none
+#	option ip_source "script"
+#	option ip_script ""
+
+	###########
+	# 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.
+	# default: "0" disabled
+	option force_ipversion "0"
+
+	###########
+	# Normally the current (in the internet) registered ip is detected using the
+	# local defined name lookup policies (i.e. /etc/resolve.conf etc.)
+	# Specify here a DNS server to use instead of the defaults.
+	# you can use hostname or ip address
+	# i.e. "google-public-dns-a.google.com"
+	# default: none
+#	option dns_server "google-public-dns-a.google.com"
+
+	# By default every DNS call is made via UDP protocol
+	# Some internet provider offer modems that cache UDP DNS requests.
+	# They also redirect calls to external servers to local.
+	# To force the usage of TCP for DNS requests enable this option
+	# Needs BIND's host program be installed
+	# default: "0" disabled
+#	option force_dnstcp "0"
+
+	###########
+	# 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
+	# HTTP proxy. !!! You should not detect your current IP
+	# 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 "[...]"
+	# default: none
+#	option proxy ''
+
+	###########
+	# In some very special configurations i.e. Multi WAN environment
+	# in a NAT cascade it might be necessary to define
+	# a network to use for communication.
+	# should use option ip_source "web" (see above)
+	# Needs GNU Wget (with SSL support) or cURL to be installed.
+	# GNU Wget will use IP address and cURL the physical device 
+	# of the given network
+	# default: none
+#	option bind_network "wan7"
+
+	########### Timer settings ########################
+
+	###########
+	# 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
+	# 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
+	# default 10 minutes
+	option check_interval	'10'
+	option check_unit	'minutes'
+
+	###########
+	# force to send an update to service provider, if no change was detected.
+	# consult DDNS providers documentation if your DDNS entry might timeout.
+	# 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)
+	# default 3 days == 72 hours
+	option force_interval	'72'
+	option force_unit	'hours'
+
+	###########
+	# if error happen on detecting, sending or updating the
+	# script will retry the relevant action for retry_count times
+	# before stopping script execution.
+	# default: 5
+	option retry_count '5'
+
+	###########
+	# if error happen on detecting, sending or updating the
+	# script will retry the relevant action.
+	# here you define the time to wait before retry is started
+	# accepted unit entry’s: 'seconds' 'minutes'
+	# default: 60 seconds
+	option retry_interval	'60'
+	option retry_unit	'seconds'
diff --git a/external/subpack/net/ddns-scripts/samples/getlocalip_sample.sh b/external/subpack/net/ddns-scripts/samples/getlocalip_sample.sh
new file mode 100755
index 0000000..b98806b
--- /dev/null
+++ b/external/subpack/net/ddns-scripts/samples/getlocalip_sample.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+#
+# sample script for detecting local IP
+# 2014-2015 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
+#
+# useful when this box is the only DDNS client in the network
+# IP adresses of "internal" boxes could be detected with this script
+# so no need to install ddns client on every "internal" box
+# On IPv6 every internal box normally has it's own external IP
+#
+# 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
diff --git a/external/subpack/net/ddns-scripts/samples/slaac_sample.sh b/external/subpack/net/ddns-scripts/samples/slaac_sample.sh
new file mode 100755
index 0000000..ea8f24d
--- /dev/null
+++ b/external/subpack/net/ddns-scripts/samples/slaac_sample.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+#
+# script to determine and return SLAAC ipv6 address using prefix from a locally configured interface and the MAC address of the device
+# (c) 2018 Keve Mueller <keve at keve dot hu>
+#
+# activated inside /etc/config/ddns by setting
+#
+# option ip_source      'script'
+# option ip_script      '/usr/lib/ddns/slaac_sample.sh br-lan AA:BB:CC:DD:EE:FF'
+#
+# the script is executed (not parsed) inside get_local_ip() function
+# of /usr/lib/ddns/dynamic_dns_functions.sh
+#
+# useful when this box is the only DDNS client in the network and other clients use SLAAC
+# so no need to install ddns client on every "internal" box
+#
+# NB: this will not catch the actual IPV6 used by the host when it is configured to use temporary addresses
+
+#NB: we need a valid MAC address that is fully expanded with leading zeroes on all positions
+format_eui_64() {
+    local macaddr="$1"
+    echo ${macaddr:0:1}$(echo ${macaddr:1:1}|tr 0123456789abcdefABCDEF 23016745ab89efcd89efcd)${macaddr:3:2}:${macaddr:6:2}ff:fe${macaddr:9:2}:${macaddr:12:2}${macaddr:15:2}
+}
+
+# expand :: in an ipv6 address specification to the appropriate series of 0:
+# result will have 8 ipv6 fragments separated by single colon
+# NB: input must be a valid IPv6 address, e.g. ::1
+# NB: numbers are not prepended with leading zeroes
+expand_ipv6_colons() {
+    local ipv6=$1
+# we need :: to be in the middle, so prepend a 0 if the input starts with : and append 0 if it ends with it
+    if [ "${ipv6:0:1}" = ":" ]; then ipv6=0${ipv6}; fi
+    if [ "${ipv6: -1:1}" = ":" ]; then ipv6=${ipv6}0; fi
+# retain only the real colons
+    local colons=${ipv6//::|[0123456789abcdefABCDEF]/}
+# count them
+    local num_colons=${#colons}
+    local filler=":0:0:0:0:0:0:"
+# replace the :: with the appropriate substring from filler
+    local ipv6_x=${ipv6/::/${filler:0:(7-$num_colons)*2-1}}
+    echo $ipv6_x
+}
+
+# obtain the first ipv6 address of the device passed in $1
+addr_net=$(ip -6 -o addr show dev $1 scope global up | cut -d" " -f 7 | head -1)
+#addr_net=$1
+addr=${addr_net%/*}
+# TODO: we assume /64 subnet
+# get the first 64 bits of the address
+prefix=$(expand_ipv6_colons $addr | cut -d: -f -4)
+# compute the SLAAC 64 bits from the MAC
+suffix=$(format_eui_64 "$2")
+
+echo -n $prefix:$suffix
+exit 0
+
+#echo "Should never come here" >&2
+#exit 2
+
diff --git a/external/subpack/net/ddns-scripts/samples/update_sample.sh b/external/subpack/net/ddns-scripts/samples/update_sample.sh
new file mode 100644
index 0000000..00b51cb
--- /dev/null
+++ b/external/subpack/net/ddns-scripts/samples/update_sample.sh
@@ -0,0 +1,41 @@
+# sample script for sending user defined updates
+# 2014-2015 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'
+#
+# 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
+# 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()
+#
+# tested with spdns.de
+local __URL="http://[USERNAME]:[PASSWORD]@update.spdns.de/nic/update?hostname=[DOMAIN]&myip=[IP]"
+# inside url we need domain, username and password
+[ -z "$domain" ]   && write_log 14 "Service section not configured correctly! Missing 'domain'"
+[ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing 'username'"
+[ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing 'password'"
+
+# do replaces in URL
+__URL=$(echo $__URL |  | sed -e "s#\[USERNAME\]#$URL_USER#g" -e "s#\[PASSWORD\]#$URL_PASS#g" \
+			     -e "s#\[PARAMENC\]#$URL_PENC#g" -e "s#\[PARAMOPT\]#$param_opt#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 "$__URL" || return 1
+
+write_log 7 "DDNS Provider answered:\n$(cat $DATFILE)"
+
+# analyse provider answers
+# "good [IP_ADR]"	= successful
+# "nochg [IP_ADR]"	= no change but OK
+grep -i -E "good|nochg" $DATFILE >/dev/null 2>&1
+return $?	# "0" if "good" or "nochg" found
+