You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB

  1. #!/bin/bash
  2. # Here is a script to add/remove TXT records to DNS Server on Synology DSM
  3. #
  4. # Author: Arabezar (on github) aka Arkadii Zhuchenko ©13.07.2020
  5. #
  6. #returns 0 means success, otherwise error.
  7. _DNS_TTL="1"
  8. ######## Public functions #####################
  9. dns_synology_dsm_add() {
  10. _info "Using API for Synology DSM - adding TXT to Synology DNS Server"
  11. fulldomain=$1
  12. txtvalue=$2
  13. _debug fulldomain "$fulldomain"
  14. _debug txtvalue "$txtvalue"
  15. maindomain="${fulldomain//_acme-challenge\./}"
  16. _debug3 maindomain "$maindomain"
  17. # WebAPI-call can be replaced by adding line to the "/var/packages/DNSServer/target/named/etc/zone/master/$maindomain" file
  18. response=$(synowebapi --exec api=SYNO.DNSServer.Zone.Record method=create version=1 runner=admin \
  19. zone_name='"'"${maindomain}"'"' \
  20. domain_name='"'"${maindomain}"'"' \
  21. rr_owner='"'"${fulldomain}"\.'"' \
  22. rr_ttl='"'${_DNS_TTL}'"' \
  23. rr_type='"'"TXT"'"' \
  24. rr_info='"'"${txtvalue}"'"' 2> /dev/null)
  25. _debug3 response "$response"
  26. if [ "$(echo "$response" | jq '.success')" == true ]; then
  27. return 0
  28. fi
  29. return 1
  30. }
  31. dns_synology_dsm_rm() {
  32. _info "Using API for Synology DSM - removing TXT from Synology DNS Server"
  33. fulldomain=$1
  34. txtvalue=$2
  35. _debug fulldomain "$fulldomain"
  36. _debug txtvalue "$txtvalue"
  37. maindomain="${fulldomain//_acme-challenge\./}"
  38. _debug3 maindomain "$maindomain"
  39. # Just removing TXT record from file (calling synowebapi failed due to some bug in specifying "items" param)
  40. _dns_zone_url="/var/packages/DNSServer/target/named/etc/zone/master/$maindomain"
  41. sed -i "/^${fulldomain}.[[:blank:]]${_DNS_TTL}[[:blank:]]TXT[[:blank:]]\"${txtvalue}\"/d" "$_dns_zone_url"
  42. return 0
  43. }