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.

127 lines
3.5 KiB

  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_ddnss_info='DDNSS.de
  4. Site: DDNSS.de
  5. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_ddnss
  6. Options:
  7. DDNSS_Token API Token
  8. Issues: github.com/acmesh-official/acme.sh/issues/2230
  9. Author: RaidenII, helbgd, mod242
  10. '
  11. DDNSS_DNS_API="https://ddnss.de/upd.php"
  12. ######## Public functions #####################
  13. #Usage: dns_ddnss_add _acme-challenge.domain.ddnss.de "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  14. dns_ddnss_add() {
  15. fulldomain=$1
  16. txtvalue=$2
  17. DDNSS_Token="${DDNSS_Token:-$(_readaccountconf_mutable DDNSS_Token)}"
  18. if [ -z "$DDNSS_Token" ]; then
  19. _err "You must export variable: DDNSS_Token"
  20. _err "The token for your DDNSS account is necessary."
  21. _err "You can look it up in your DDNSS account."
  22. return 1
  23. fi
  24. # Now save the credentials.
  25. _saveaccountconf_mutable DDNSS_Token "$DDNSS_Token"
  26. # Unfortunately, DDNSS does not seems to support lookup domain through API
  27. # So I assume your credentials (which are your domain and token) are correct
  28. # If something goes wrong, we will get a KO response from DDNSS
  29. if ! _ddnss_get_domain; then
  30. return 1
  31. fi
  32. # Now add the TXT record to DDNSS DNS
  33. _info "Trying to add TXT record"
  34. if _ddnss_rest GET "key=$DDNSS_Token&host=$_ddnss_domain&txtm=1&txt=$txtvalue"; then
  35. if [ "$response" = "Updated 1 hostname." ]; then
  36. _info "TXT record has been successfully added to your DDNSS domain."
  37. _info "Note that all subdomains under this domain uses the same TXT record."
  38. return 0
  39. else
  40. _err "Errors happened during adding the TXT record, response=$response"
  41. return 1
  42. fi
  43. else
  44. _err "Errors happened during adding the TXT record."
  45. return 1
  46. fi
  47. }
  48. #Usage: fulldomain txtvalue
  49. #Remove the txt record after validation.
  50. dns_ddnss_rm() {
  51. fulldomain=$1
  52. txtvalue=$2
  53. DDNSS_Token="${DDNSS_Token:-$(_readaccountconf_mutable DDNSS_Token)}"
  54. if [ -z "$DDNSS_Token" ]; then
  55. _err "You must export variable: DDNSS_Token"
  56. _err "The token for your DDNSS account is necessary."
  57. _err "You can look it up in your DDNSS account."
  58. return 1
  59. fi
  60. if ! _ddnss_get_domain; then
  61. return 1
  62. fi
  63. # Now remove the TXT record from DDNS DNS
  64. _info "Trying to remove TXT record"
  65. if _ddnss_rest GET "key=$DDNSS_Token&host=$_ddnss_domain&txtm=2"; then
  66. if [ "$response" = "Updated 1 hostname." ]; then
  67. _info "TXT record has been successfully removed from your DDNSS domain."
  68. return 0
  69. else
  70. _err "Errors happened during removing the TXT record, response=$response"
  71. return 1
  72. fi
  73. else
  74. _err "Errors happened during removing the TXT record."
  75. return 1
  76. fi
  77. }
  78. #################### Private functions below ##################################
  79. #fulldomain=_acme-challenge.domain.ddnss.de
  80. #returns
  81. # _ddnss_domain=domain
  82. _ddnss_get_domain() {
  83. # We'll extract the domain/username from full domain
  84. _ddnss_domain="$(echo "$fulldomain" | _lower_case | _egrep_o '[.][^.][^.]*[.](ddnss|dyn-ip24|dyndns|dyn|dyndns1|home-webserver|myhome-server|dynip)\..*' | cut -d . -f 2-)"
  85. if [ -z "$_ddnss_domain" ]; then
  86. _err "Error extracting the domain."
  87. return 1
  88. fi
  89. return 0
  90. }
  91. #Usage: method URI
  92. _ddnss_rest() {
  93. method=$1
  94. param="$2"
  95. _debug param "$param"
  96. url="$DDNSS_DNS_API?$param"
  97. _debug url "$url"
  98. # DDNSS uses GET to update domain info
  99. if [ "$method" = "GET" ]; then
  100. response="$(_get "$url" | sed 's/<[a-zA-Z\/][^>]*>//g' | tr -s "\n" | _tail_n 1)"
  101. else
  102. _err "Unsupported method"
  103. return 1
  104. fi
  105. _debug2 response "$response"
  106. return 0
  107. }