Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synology DSM DNS Server API #3045

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions dnsapi/dns_synology_dsm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

# Here is a script to add/remove TXT records to DNS Server on Synology DSM
#
# 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.

_DNS_TTL="1"

######## Public functions #####################

dns_synology_dsm_add() {

_info "Using API for Synology DSM - adding TXT to Synology DNS Server"

fulldomain=$1
txtvalue=$2
_debug fulldomain "$fulldomain"
_debug txtvalue "$txtvalue"

maindomain="${fulldomain//_acme-challenge\./}"
_debug3 maindomain "$maindomain"

# 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 \
arabezar marked this conversation as resolved.
Show resolved Hide resolved
zone_name='"'"${maindomain}"'"' \
domain_name='"'"${maindomain}"'"' \
rr_owner='"'"${fulldomain}"\.'"' \
rr_ttl='"'${_DNS_TTL}'"' \
rr_type='"'"TXT"'"' \
rr_info='"'"${txtvalue}"'"' 2> /dev/null)

_debug3 response "$response"

if [ "$(echo "$response" | jq '.success')" == true ]; then
return 0
fi

return 1
}

dns_synology_dsm_rm() {

_info "Using API for Synology DSM - removing TXT from Synology DNS Server"

fulldomain=$1
txtvalue=$2
_debug fulldomain "$fulldomain"
_debug txtvalue "$txtvalue"

maindomain="${fulldomain//_acme-challenge\./}"
_debug3 maindomain "$maindomain"

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)

# 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
}