From a5b52f93cb0712e8b494a77c3dab760d3f70b107 Mon Sep 17 00:00:00 2001 From: Arabezar Date: Tue, 14 Jul 2020 11:40:24 +0300 Subject: [PATCH] Synology DSM DNS Server API Code with file operations replaced with the SynoWebAPI call --- dnsapi/dns_synology_dsm.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/dnsapi/dns_synology_dsm.sh b/dnsapi/dns_synology_dsm.sh index 5909f96b..934eb9e7 100644 --- a/dnsapi/dns_synology_dsm.sh +++ b/dnsapi/dns_synology_dsm.sh @@ -2,7 +2,8 @@ # Here is a script to add/remove TXT records to DNS Server on Synology DSM # -# Author: Arabezar (on github) aka Arkadii Zhuchenko ©13.07.2020 +# Author: Arabezar aka Arkadii Zhuchenko © 13.07.2020 +# Great thanks to loderunner84 for the invaluable help in synowebapi research # #returns 0 means success, otherwise error. @@ -22,7 +23,7 @@ dns_synology_dsm_add() { maindomain="${fulldomain//_acme-challenge\./}" _debug3 maindomain "$maindomain" - # WebAPI-call can be replaced by adding line to the "/var/packages/DNSServer/target/named/etc/zone/master/$maindomain" file + # SynoWebAPI call can be replaced by adding the line to the "/var/packages/DNSServer/target/named/etc/zone/master/$maindomain" file response=$(synowebapi --exec api=SYNO.DNSServer.Zone.Record method=create version=1 runner=admin \ zone_name='"'"${maindomain}"'"' \ domain_name='"'"${maindomain}"'"' \ @@ -52,9 +53,18 @@ dns_synology_dsm_rm() { maindomain="${fulldomain//_acme-challenge\./}" _debug3 maindomain "$maindomain" - # Just removing TXT record from file (calling synowebapi failed due to some bug in specifying "items" param) - _dns_zone_url="/var/packages/DNSServer/target/named/etc/zone/master/$maindomain" - sed -i "/^${fulldomain}.[[:blank:]]${_DNS_TTL}[[:blank:]]TXT[[:blank:]]\"${txtvalue}\"/d" "$_dns_zone_url" + response=$(synowebapi --exec api=SYNO.DNSServer.Zone.Record method=delete version=1 runner=admin \ + items=["{\"zone_name\":\"$maindomain\",\"domain_name\":\"$maindomain\",\"rr_owner\":\"$fulldomain.\",\"rr_type\":\"TXT\",\"rr_ttl\":\"$_DNS_TTL\",\"rr_info\":\"\\\"$txtvalue\\\"\",\"full_record\":\"$fulldomain.\t$_DNS_TTL\tTXT\t\\\"$txtvalue\\\"\"}"] 2> /dev/null) - return 0 + # WebAPI-call can be replaced by removing the line from the "/var/packages/DNSServer/target/named/etc/zone/master/$maindomain" file + #_dns_zone_url="/var/packages/DNSServer/target/named/etc/zone/master/$maindomain" + #sed -i "/^${fulldomain}.[[:blank:]]${_DNS_TTL}[[:blank:]]TXT[[:blank:]]\"${txtvalue}\"/d" "$_dns_zone_url" + + _debug3 response "$response" + + if [ "$(echo "$response" | jq '.success')" == true ]; then + return 0 + fi + + return 1 }