DDNS and REST API call

Hello,

I have DNS provider who support REST API call.

Is there easy way to configure it in DDNS?
I tried to write simple script but i have problem that I cannot make it working, [DOMAIN], [USERNAME] and [PASSWORD] not to be replaced.

I have it here /usr/lib/ddns

I expect it should be very simple script


#!/bin/sh
#env > /tmp/ddns_env.txt
logger -t dynamic_zone "HELLO"

curl -X PUT "https://api.zone.eu/v2/dns1/[DOMAIN]/a/[USERNAME]" 
-H "Authorization: Basic [PASSWORD]" 
-H "Content-Type: application/json" 
-d '{"destination":"[IP]"}' \

If [USERNAME], [PASSWORD], and [IP] come initialized in the environment, then you would recall them using "${[PASSWORD]}" instead.

This already seems wrong to me. See ZoneID API

It is correct, I set there ready token value, not real password.

I found example and made it working

#!/bin/sh

Use Command for testing

/usr/lib/ddns/dynamic_dns_updater.sh -S my_service_name -v 1

local __URL="https://api.zone.eu/v2/dns/[DOMAIN]/a/[PARAMOPT]"
local __TOKEN="Authorization: Basic [PASSWORD]"
local __JSON_DATA='{"destination":"[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'"
[ -z "$param_opt" ] && write_log 14 "Service section not configured correctly! Missing 'param_opt'"

do replaces in URL

__URL=$(echo $__URL | sed -e "s#[PARAMOPT]#$param_opt#g" -e "s#[DOMAIN]#$domain#g")

do replaces in JSON_DATA

__JSON_DATA=$(echo $__JSON_DATA | sed -e "s#[IP]#$__IP#g")

do replaces in TOKEN

__TOKEN=$(echo $__TOKEN | sed -e "s#[PASSWORD]#$URL_PASS#g")

http_code=$(curl -s -o /dev/null -w "%{http_code}" 
-X PUT "$__URL" 
-H "$__TOKEN" 
-H "Content-Type: application/json" 
-d "$__JSON_DATA")

if [ "$http_code" = "200" ]; then
return 0
else
return 1
fi

Nice that you got it working. One small hardening point: avoid leaving real tokens in debug output (env > /tmp/...) or hard-coded in a world-readable helper script. I’d keep the script root-owned and let ddns pass the values through UCI variables, then build the header from a shell variable as late as possible. It does not change the API call, but it prevents the token from being copied into logs or temp files while testing.

I posted final version to GitHub

openwrt_ddns_zone_api_script