From 36afa3dfce2df5a75dc1df1bd281762152e22e6e Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Tue, 31 Aug 2021 21:54:37 +0900 Subject: ddns-scripts-pdns: Add package Signed-off-by: Cristian Le --- net/ddns-scripts/files/usr/lib/ddns/update_pdns.sh | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 net/ddns-scripts/files/usr/lib/ddns/update_pdns.sh (limited to 'net/ddns-scripts/files/usr/lib/ddns') 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 -- cgit v1.2.3