Browse Source

ddns-scripts: load ddsn service provider parameter from json

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
lilik-openwrt-22.03
Florian Eckert 4 years ago
parent
commit
1b3bb98fcf
2 changed files with 40 additions and 32 deletions
  1. +36
    -31
      net/ddns-scripts/files/dynamic_dns_functions.sh
  2. +4
    -1
      net/ddns-scripts/files/dynamic_dns_updater.sh

+ 36
- 31
net/ddns-scripts/files/dynamic_dns_functions.sh View File

@ -313,45 +313,50 @@ urlencode() {
}
# extract url or script for given DDNS Provider from
# file /etc/ddns/services for IPv4 or from
# file /etc/ddns/services_ipv6 for IPv6
# directory /usr/share/ddns/services/ipv4/ for IPv4
# or from
# directory /usr/share/ddns/services/ipv6/ for IPv6
# $1 Name of the provider
# $1 Name of Variable to store url to
# $2 Name of Variable to store script to
# $3 Name of Variable to store service answer to
get_service_data() {
local __FILE __SERVICE __DATA __ANSWER __URL __SCRIPT __PIPE
local provider="$1"
shift
[ $# -ne 3 ] && write_log 12 "Error calling 'get_service_data()' - wrong number of parameters"
__FILE="/etc/ddns/services" # IPv4
[ $use_ipv6 -ne 0 ] && __FILE="/etc/ddns/services_ipv6" # IPv6
# workaround with variables; pipe create subshell with no give back of variable content
__PIPE="$ddns_rundir/pipe_$$"
mkfifo "$__PIPE"
# only grep without # or whitespace at linestart | remove "
sed '/^#/d; /^[ \t]*$/d; s/\"//g' "$__FILE" > "$__PIPE" &
. /usr/share/libubox/jshn.sh
local dir="/usr/share/ddns/services"
local name data url answer script
while read __SERVICE __DATA __ANSWER; do
if [ "$__SERVICE" = "$service_name" ]; then
# check if URL or SCRIPT is given
__URL=$(echo "$__DATA" | grep "^http")
[ -z "$__URL" ] && __SCRIPT="/usr/lib/ddns/$__DATA"
[ $# -ne 3 ] && write_log 12 "Error calling 'get_service_data()' - wrong number of parameters"
eval "$1=\"$__URL\""
eval "$2=\"$__SCRIPT\""
eval "$3=\"$__ANSWER\""
rm "$__PIPE"
return 0
fi
done < "$__PIPE"
rm "$__PIPE"
[ -f "${dir}/${provider}.json" ] || {
eval "$1=\"\""
eval "$2=\"\""
eval "$3=\"\""
return 1
}
eval "$1=\"\"" # no service match clear variables
eval "$2=\"\""
eval "$3=\"\""
return 1
json_load_file "${dir}/${provider}.json"
json_get_var name "name"
if [ "$use_ipv6" -eq "1" ]; then
json_select "ipv6"
else
json_select "ipv4"
fi
json_get_var data "url"
json_get_var answer "answer"
json_select ".."
json_cleanup
# check if URL or SCRIPT is given
url=$(echo "$data" | grep "^http")
[ -z "$url" ] && script="/usr/lib/ddns/${data}"
eval "$1=\"$url\""
eval "$2=\"$script\""
eval "$3=\"$answer\""
return 0
}
# Calculate seconds from interval and unit


+ 4
- 1
net/ddns-scripts/files/dynamic_dns_updater.sh View File

@ -232,7 +232,10 @@ esac
# determine what update url we're using if a service_name is supplied
# otherwise update_url is set inside configuration (custom update url)
# or update_script is set inside configuration (custom update script)
[ -n "$service_name" ] && get_service_data update_url update_script UPD_ANSWER
[ -n "$service_name" ] && {
get_service_data "$service_name" update_url update_script UPD_ANSWER
}
[ -z "$update_url" -a -z "$update_script" ] && write_log 14 "No update_url found/defined or no update_script found/defined!"
[ -n "$update_script" -a ! -f "$update_script" ] && write_log 14 "Custom update_script not found!"


Loading…
Cancel
Save