Merge pull request #2258 from lbschenkel/cloudflare-rec_id-for-15.05
ddns-scripts: allow setting CloudFlare 'rec_id' in the config
This commit is contained in:
commit
f6ee970394
2 changed files with 49 additions and 47 deletions
|
@ -12,7 +12,7 @@ PKG_NAME:=ddns-scripts
|
||||||
PKG_VERSION:=2.4.3
|
PKG_VERSION:=2.4.3
|
||||||
# Release == build
|
# Release == build
|
||||||
# increase on changes of services files or tld_names.dat
|
# increase on changes of services files or tld_names.dat
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=2
|
||||||
|
|
||||||
PKG_LICENSE:=GPL-2.0
|
PKG_LICENSE:=GPL-2.0
|
||||||
PKG_MAINTAINER:=Christian Schoenebeck <christian.schoenebeck@gmail.com>
|
PKG_MAINTAINER:=Christian Schoenebeck <christian.schoenebeck@gmail.com>
|
||||||
|
|
|
@ -57,56 +57,58 @@ cleanup() {
|
||||||
sed -i "#'##g" $DATFILE # remove "'" (single quote)
|
sed -i "#'##g" $DATFILE # remove "'" (single quote)
|
||||||
}
|
}
|
||||||
|
|
||||||
# build url according to cloudflare client api at https://www.cloudflare.com/docs/client-api.html
|
[ -n "$rec_id" ] && __RECID="$rec_id" || {
|
||||||
# to "rec_load_all" to detect rec_id needed for update
|
# build url according to cloudflare client api at https://www.cloudflare.com/docs/client-api.html
|
||||||
__URL="https://www.cloudflare.com/api_json.html" # https://www.cloudflare.com/api_json.html
|
# to "rec_load_all" to detect rec_id needed for update
|
||||||
__URL="${__URL}?a=rec_load_all" # -d 'a=rec_load_all'
|
__URL="https://www.cloudflare.com/api_json.html" # https://www.cloudflare.com/api_json.html
|
||||||
__URL="${__URL}&tkn=$password" # -d 'tkn=8afbe6dea02407989af4dd4c97bb6e25'
|
__URL="${__URL}?a=rec_load_all" # -d 'a=rec_load_all'
|
||||||
__URL="${__URL}&email=$username" # -d 'email=sample@example.com'
|
__URL="${__URL}&tkn=$password" # -d 'tkn=8afbe6dea02407989af4dd4c97bb6e25'
|
||||||
__URL="${__URL}&z=$__DOMAIN" # -d 'z=example.com'
|
__URL="${__URL}&email=$username" # -d 'email=sample@example.com'
|
||||||
|
__URL="${__URL}&z=$__DOMAIN" # -d 'z=example.com'
|
||||||
|
|
||||||
# lets request the data
|
# lets request the data
|
||||||
do_transfer "$__URL" || return 1
|
do_transfer "$__URL" || return 1
|
||||||
|
|
||||||
cleanup # cleanup dat file
|
cleanup # cleanup dat file
|
||||||
json_load "$(cat $DATFILE)" # lets extract data
|
json_load "$(cat $DATFILE)" # lets extract data
|
||||||
__FOUND=0 # found record indicator
|
__FOUND=0 # found record indicator
|
||||||
json_get_var __RES "result" # cloudflare result of last request
|
json_get_var __RES "result" # cloudflare result of last request
|
||||||
json_get_var __MSG "msg" # cloudflare error message
|
json_get_var __MSG "msg" # cloudflare error message
|
||||||
[ "$__RES" != "success" ] && {
|
[ "$__RES" != "success" ] && {
|
||||||
write_log 4 "'rec_load_all' failed with error: \n$__MSG"
|
write_log 4 "'rec_load_all' failed with error: \n$__MSG"
|
||||||
return 1
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
json_select "response"
|
||||||
|
json_select "recs"
|
||||||
|
json_select "objs"
|
||||||
|
json_get_keys __KEYS
|
||||||
|
for __KEY in $__KEYS; do
|
||||||
|
local __ZONE __DISPLAY __NAME __TYPE
|
||||||
|
json_select "$__KEY"
|
||||||
|
# json_get_var __ZONE "zone_name" # for debugging
|
||||||
|
# json_get_var __DISPLAY "display_name" # for debugging
|
||||||
|
json_get_var __NAME "name"
|
||||||
|
json_get_var __TYPE "type"
|
||||||
|
if [ "$__NAME" = "$domain" ]; then
|
||||||
|
# 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'"
|
||||||
}
|
}
|
||||||
|
|
||||||
json_select "response"
|
|
||||||
json_select "recs"
|
|
||||||
json_select "objs"
|
|
||||||
json_get_keys __KEYS
|
|
||||||
for __KEY in $__KEYS; do
|
|
||||||
local __ZONE __DISPLAY __NAME __TYPE
|
|
||||||
json_select "$__KEY"
|
|
||||||
# json_get_var __ZONE "zone_name" # for debugging
|
|
||||||
# json_get_var __DISPLAY "display_name" # for debugging
|
|
||||||
json_get_var __NAME "name"
|
|
||||||
json_get_var __TYPE "type"
|
|
||||||
if [ "$__NAME" = "$domain" ]; then
|
|
||||||
# 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
|
# build url according to cloudflare client api at https://www.cloudflare.com/docs/client-api.html
|
||||||
# for "rec_edit" to update IP address
|
# for "rec_edit" to update IP address
|
||||||
__URL="https://www.cloudflare.com/api_json.html" # https://www.cloudflare.com/api_json.html
|
__URL="https://www.cloudflare.com/api_json.html" # https://www.cloudflare.com/api_json.html
|
||||||
|
|
Loading…
Reference in a new issue