mirror of
https://github.com/openwrt/packages.git
synced 2025-12-26 11:16:31 +04:00
ddns-scripts: bugfixes/update to version 2.4.1-1
* fix problem with lucihelper script reported in OpenWrt Ticket 19419 * rewritten split_FQDN fixing detection errors and using zcat * updated tld_names.dat and .gz compressed to save space * add LoopiaDNS (loopia.se) to services_ipv6 Signed-off-by: Christian Schoenebeck <christian.schoenebeck@gmail.com>
This commit is contained in:
80
net/ddns-scripts/files/dynamic_dns_functions.sh
Normal file → Executable file
80
net/ddns-scripts/files/dynamic_dns_functions.sh
Normal file → Executable file
@@ -37,7 +37,7 @@ PIDFILE="" # pid file
|
||||
UPDFILE="" # store UPTIME of last update
|
||||
DATFILE="" # save stdout data of WGet and other external programs called
|
||||
ERRFILE="" # save stderr output of WGet and other external programs called
|
||||
TLDFILE=/usr/lib/ddns/tld_names.dat # TLD file used by split_FQDN
|
||||
TLDFILE=/usr/lib/ddns/tld_names.dat.gz # TLD file used by split_FQDN
|
||||
|
||||
CHECK_SECONDS=0 # calculated seconds out of given
|
||||
FORCE_SECONDS=0 # interval and unit
|
||||
@@ -1058,43 +1058,63 @@ split_FQDN() {
|
||||
# $4 name of variable to store Host/Subdomain
|
||||
|
||||
[ $# -ne 4 ] && write_log 12 "Error calling 'split_FQDN()' - wrong number of parameters"
|
||||
[ -z "$1" ] && write_log 12 "Error calling 'split_FQDN()' - missing FQDN to split"
|
||||
[ -f $TLDFILE ] || write_log 12 "Error calling 'split_FQDN()' - missing file '$TLDFILE'"
|
||||
|
||||
_SET="$@" # save given parameters
|
||||
local _FHOST _FTLD _FOUND
|
||||
local _FDOM=$(echo "$1" | tr [A-Z] [a-z]) # to lower
|
||||
local _HOST _FDOM _CTLD _FTLD
|
||||
local _SET="$@" # save given function parameters
|
||||
|
||||
set -- $(echo "$_FDOM" | tr "." " ") # replace DOT with SPACE and set as script parameters
|
||||
_FDOM="" # clear variable for later reuse
|
||||
local _PAR=$(echo "$1" | tr [A-Z] [a-z] | tr "." " ") # to lower and replace DOT with SPACE
|
||||
set -- $_PAR # set new as function parameters
|
||||
_PAR="" # clear variable for later reuse
|
||||
while [ -n "$1" ] ; do # as long we have parameters
|
||||
_PAR="$1 $_PAR" # invert order of parameters
|
||||
shift
|
||||
done
|
||||
set -- $_PAR # use new as function parameters
|
||||
_PAR="" # clear variable
|
||||
|
||||
while [ -n "$1" ] ; do # as long we have parameters
|
||||
_FTLD=$(echo $@ | tr " " ".") # build back dot separated as TLD
|
||||
# look if match excludes "!" in tld_names.dat
|
||||
grep -E "^!$_FTLD$" $TLDFILE >/dev/null 2>&1 || {
|
||||
# Don't match excludes
|
||||
# check if match any "*" in tld_names.dat
|
||||
grep -E "^*.$_FTLD$" $TLDFILE >/dev/null 2>&1 && {
|
||||
_FOUND="VALID"
|
||||
break # found leave while
|
||||
}
|
||||
# check if exact match in tld_names.dat
|
||||
grep -E "^$_FTLD$" $TLDFILE >/dev/null 2>&1 && {
|
||||
_FOUND="VALID"
|
||||
break # found leave while
|
||||
}
|
||||
if [ -z "$_CTLD" ]; then # first loop
|
||||
_CTLD="$1" # CURRENT TLD to look at
|
||||
shift
|
||||
else
|
||||
_CTLD="$1.$_CTLD" # Next TLD to look at
|
||||
shift
|
||||
fi
|
||||
# check if TLD exact match in tld_names.dat, save TLD
|
||||
zcat $TLDFILE | grep -E "^$_CTLD$" >/dev/null 2>&1 && {
|
||||
_FTLD="$_CTLD" # save found
|
||||
_FDOM="$1" # save domain next step might be invalid
|
||||
continue
|
||||
}
|
||||
# nothing match so
|
||||
_FHOST="$_FHOST $_FDOM" # append DOMAIN to last found HOST
|
||||
_FDOM="$1" # set 1st parameter as DOMAIN
|
||||
_FTLD="" # clear TLD
|
||||
shift # delete 1st parameter and retry with the rest
|
||||
# check if match any "*" in tld_names.dat,
|
||||
zcat $TLDFILE | grep -E "^\*.$_CTLD$" >/dev/null 2>&1 && {
|
||||
[ -z "$1" ] && break # no more data break
|
||||
# check if next level TLD match excludes "!" in tld_names.dat
|
||||
if zcat $TLDFILE | grep -E "^!$1.$_CTLD$" >/dev/null 2>&1 ; then
|
||||
_FTLD="$_CTLD" # Yes
|
||||
else
|
||||
_FTLD="$1.$_CTLD"
|
||||
shift
|
||||
fi
|
||||
_FDOM="$1"; shift
|
||||
}
|
||||
[ -n "$_FTLD" ] && break # we have something valid, break
|
||||
done
|
||||
|
||||
# the leftover parameters are the HOST/SUBDOMAIN
|
||||
while [ -n "$1" ]; do
|
||||
_HOST="$1 $HOST" # remember we need to invert
|
||||
shift
|
||||
done
|
||||
_HOST=$(echo $_HOST | tr " " ".") # insert DOT
|
||||
|
||||
set -- $_SET # set back parameters from function call
|
||||
[ -n "$_FHOST" ] && _FHOST=$(echo $_FHOST | tr " " ".") # put dots back into HOST
|
||||
[ -n "$_FOUND" ] && {
|
||||
eval "$2=$_FTLD" # set found TLD
|
||||
eval "$3=$_FDOM" # set found registrable domain
|
||||
eval "$4=$_FHOST" # set found HOST/SUBDOMAIN
|
||||
[ -n "$_FTLD" ] && {
|
||||
eval "$2=$_FTLD" # set TLD
|
||||
eval "$3=$_FDOM" # set registrable domain
|
||||
eval "$4=$_HOST" # set HOST/SUBDOMAIN
|
||||
return 0
|
||||
}
|
||||
eval "$2=''" # clear TLD
|
||||
|
||||
Reference in New Issue
Block a user