ddns-scripts: load ddsn service provider parameter from json
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
This commit is contained in:
parent
07d82c9140
commit
1b3bb98fcf
2 changed files with 38 additions and 30 deletions
|
@ -313,45 +313,50 @@ urlencode() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# extract url or script for given DDNS Provider from
|
# extract url or script for given DDNS Provider from
|
||||||
# file /etc/ddns/services for IPv4 or from
|
# directory /usr/share/ddns/services/ipv4/ for IPv4
|
||||||
# file /etc/ddns/services_ipv6 for IPv6
|
# or from
|
||||||
|
# directory /usr/share/ddns/services/ipv6/ for IPv6
|
||||||
|
# $1 Name of the provider
|
||||||
# $1 Name of Variable to store url to
|
# $1 Name of Variable to store url to
|
||||||
# $2 Name of Variable to store script to
|
# $2 Name of Variable to store script to
|
||||||
# $3 Name of Variable to store service answer to
|
# $3 Name of Variable to store service answer to
|
||||||
get_service_data() {
|
get_service_data() {
|
||||||
local __FILE __SERVICE __DATA __ANSWER __URL __SCRIPT __PIPE
|
local provider="$1"
|
||||||
|
shift
|
||||||
|
|
||||||
|
. /usr/share/libubox/jshn.sh
|
||||||
|
local dir="/usr/share/ddns/services"
|
||||||
|
local name data url answer script
|
||||||
|
|
||||||
[ $# -ne 3 ] && write_log 12 "Error calling 'get_service_data()' - wrong number of parameters"
|
[ $# -ne 3 ] && write_log 12 "Error calling 'get_service_data()' - wrong number of parameters"
|
||||||
|
|
||||||
__FILE="/etc/ddns/services" # IPv4
|
[ -f "${dir}/${provider}.json" ] || {
|
||||||
[ $use_ipv6 -ne 0 ] && __FILE="/etc/ddns/services_ipv6" # IPv6
|
eval "$1=\"\""
|
||||||
|
|
||||||
# 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" &
|
|
||||||
|
|
||||||
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"
|
|
||||||
|
|
||||||
eval "$1=\"$__URL\""
|
|
||||||
eval "$2=\"$__SCRIPT\""
|
|
||||||
eval "$3=\"$__ANSWER\""
|
|
||||||
rm "$__PIPE"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
done < "$__PIPE"
|
|
||||||
rm "$__PIPE"
|
|
||||||
|
|
||||||
eval "$1=\"\"" # no service match clear variables
|
|
||||||
eval "$2=\"\""
|
eval "$2=\"\""
|
||||||
eval "$3=\"\""
|
eval "$3=\"\""
|
||||||
return 1
|
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
|
# Calculate seconds from interval and unit
|
||||||
|
|
|
@ -232,7 +232,10 @@ esac
|
||||||
# determine what update url we're using if a service_name is supplied
|
# determine what update url we're using if a service_name is supplied
|
||||||
# otherwise update_url is set inside configuration (custom update url)
|
# otherwise update_url is set inside configuration (custom update url)
|
||||||
# or update_script is set inside configuration (custom update script)
|
# 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!"
|
[ -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!"
|
[ -n "$update_script" -a ! -f "$update_script" ] && write_log 14 "Custom update_script not found!"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue