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.

133 lines
3.1 KiB

2 months ago
  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_nederhost_info='NederHost.nl
  4. Site: NederHost.nl
  5. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_nederhost
  6. Options:
  7. NederHost_Key API Key
  8. Issues: github.com/acmesh-official/acme.sh/issues/2089
  9. '
  10. NederHost_Api="https://api.nederhost.nl/dns/v1"
  11. ######## Public functions #####################
  12. #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  13. dns_nederhost_add() {
  14. fulldomain=$1
  15. txtvalue=$2
  16. NederHost_Key="${NederHost_Key:-$(_readaccountconf_mutable NederHost_Key)}"
  17. if [ -z "$NederHost_Key" ]; then
  18. NederHost_Key=""
  19. _err "You didn't specify a NederHost api key."
  20. _err "You can get yours from https://www.nederhost.nl/mijn_nederhost"
  21. return 1
  22. fi
  23. #save the api key and email to the account conf file.
  24. _saveaccountconf_mutable NederHost_Key "$NederHost_Key"
  25. _debug "First detect the root zone"
  26. if ! _get_root "$fulldomain"; then
  27. _err "invalid domain"
  28. return 1
  29. fi
  30. _debug _sub_domain "$_sub_domain"
  31. _debug _domain "$_domain"
  32. _info "Adding record"
  33. if _nederhost_rest PATCH "zones/$_domain/records/$fulldomain/TXT" "[{\"content\":\"$txtvalue\",\"ttl\":60}]"; then
  34. if _contains "$response" "$fulldomain"; then
  35. _info "Added, OK"
  36. return 0
  37. else
  38. _err "Add txt record error."
  39. return 1
  40. fi
  41. fi
  42. _err "Add txt record error."
  43. return 1
  44. }
  45. #fulldomain txtvalue
  46. dns_nederhost_rm() {
  47. fulldomain=$1
  48. txtvalue=$2
  49. NederHost_Key="${NederHost_Key:-$(_readaccountconf_mutable NederHost_Key)}"
  50. if [ -z "$NederHost_Key" ]; then
  51. NederHost_Key=""
  52. _err "You didn't specify a NederHost api key."
  53. _err "You can get yours from https://www.nederhost.nl/mijn_nederhost"
  54. return 1
  55. fi
  56. _debug "First detect the root zone"
  57. if ! _get_root "$fulldomain"; then
  58. _err "invalid domain"
  59. return 1
  60. fi
  61. _debug _sub_domain "$_sub_domain"
  62. _debug _domain "$_domain"
  63. _debug "Removing txt record"
  64. _nederhost_rest DELETE "zones/${_domain}/records/$fulldomain/TXT?content=$txtvalue"
  65. }
  66. #################### Private functions below ##################################
  67. #_acme-challenge.www.domain.com
  68. #returns
  69. # _sub_domain=_acme-challenge.www
  70. # _domain=domain.com
  71. _get_root() {
  72. domain=$1
  73. i=2
  74. p=1
  75. while true; do
  76. _domain=$(printf "%s" "$domain" | cut -d . -f "$i"-100)
  77. _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-"$p")
  78. _debug _domain "$_domain"
  79. if [ -z "$_domain" ]; then
  80. #not valid
  81. return 1
  82. fi
  83. if _nederhost_rest GET "zones/${_domain}"; then
  84. if [ "${_code}" = "204" ]; then
  85. return 0
  86. fi
  87. else
  88. return 1
  89. fi
  90. p=$i
  91. i=$(_math "$i" + 1)
  92. done
  93. return 1
  94. }
  95. _nederhost_rest() {
  96. m=$1
  97. ep="$2"
  98. data="$3"
  99. _debug "$ep"
  100. export _H1="Authorization: Bearer $NederHost_Key"
  101. export _H2="Content-Type: application/json"
  102. _debug data "$data"
  103. response="$(_post "$data" "$NederHost_Api/$ep" "" "$m")"
  104. _code="$(grep "^HTTP" "$HTTP_HEADER" | _tail_n 1 | cut -d " " -f 2 | tr -d "\\r\\n")"
  105. _debug "http response code $_code"
  106. if [ "$?" != "0" ]; then
  107. _err "error $ep"
  108. return 1
  109. fi
  110. _debug2 response "$response"
  111. return 0
  112. }