diff options
author | Florian Eckert <fe@dev.tdt.de> | 2021-08-31 16:00:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-31 16:00:03 +0200 |
commit | dfbd09c6f643fb89828a3d08f2dee4dad6937bde (patch) | |
tree | d518a47ccb88a811d5519c441bea66c8bef92181 /net/ddns-scripts/files/usr/lib/ddns | |
parent | c5d49e35f333fe60cbd0f3e6d68125a1de5fcba1 (diff) | |
parent | 36afa3dfce2df5a75dc1df1bd281762152e22e6e (diff) |
Merge pull request #16429 from LecrisUT/PowerDNS
ddns-scripts: PowerDNS script
Diffstat (limited to 'net/ddns-scripts/files/usr/lib/ddns')
-rwxr-xr-x | net/ddns-scripts/files/usr/lib/ddns/update_pdns.sh | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/net/ddns-scripts/files/usr/lib/ddns/update_pdns.sh b/net/ddns-scripts/files/usr/lib/ddns/update_pdns.sh new file mode 100755 index 000000000..d3fc2d2c9 --- /dev/null +++ b/net/ddns-scripts/files/usr/lib/ddns/update_pdns.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# Derived from update_gandi_net.sh +. /usr/share/libubox/jshn.sh + +local __TTL=600 +local __RRTYPE +local __STATUS + +[ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing subdomain as 'username'" +[ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing API Key as 'password'" +[ -z "$param_opt" ] && write_log 14 "Service section not configured correctly! Missing PowerDNS URL as 'Optional Parameter'(param_opt)" + +# Create endpoint from $param_opt +# e.g. param_opt=http://127.0.0.1:8081 +local __ENDPOINT="$param_opt/api/v1/servers/localhost/zones" + +[ $use_ipv6 -ne 0 ] && __RRTYPE="AAAA" || __RRTYPE="A" + +# Build JSON payload +json_init +json_add_array rrsets +json_add_object + json_add_string name "$username.$domain" + json_add_string type "$__RRTYPE" + json_add_int ttl $__TTL + json_add_string changetype "REPLACE" + json_add_array records + json_add_object + json_add_string content "$__IP" + json_add_boolean disabled 0 + json_close_object + json_close_array +json_close_object +json_close_array + +__STATUS=$(curl -Ss -X PATCH "$__ENDPOINT/$domain" \ + -H "X-Api-Key: $password" \ + -H "Content-Type: application/json" \ + -d "$(json_dump)" \ + -w "%{http_code}\n" \ + -o $DATFILE 2>$ERRFILE) + + +if [ $? -ne 0 ]; then + write_log 14 "Curl failed: $(cat $ERRFILE)" + return 1 +elif [ -z $__STATUS ] || [ $__STATUS != 204 ]; then + write_log 14 "PowerDNS request failed: $__STATUS \n$(cat $DATFILE)" + return 1 +fi + +return 0 |