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.

148 lines
3.2 KiB

  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_active24_info='Active24.com
  4. Site: Active24.com
  5. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_active24
  6. Options:
  7. ACTIVE24_Token API Token
  8. Issues: github.com/acmesh-official/acme.sh/issues/2059
  9. Author: Milan Pála
  10. '
  11. ACTIVE24_Api="https://api.active24.com"
  12. ######## Public functions #####################
  13. # Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  14. # Used to add txt record
  15. dns_active24_add() {
  16. fulldomain=$1
  17. txtvalue=$2
  18. _active24_init
  19. _info "Adding txt record"
  20. if _active24_rest POST "dns/$_domain/txt/v1" "{\"name\":\"$_sub_domain\",\"text\":\"$txtvalue\",\"ttl\":0}"; then
  21. if _contains "$response" "errors"; then
  22. _err "Add txt record error."
  23. return 1
  24. else
  25. _info "Added, OK"
  26. return 0
  27. fi
  28. fi
  29. _err "Add txt record error."
  30. return 1
  31. }
  32. # Usage: fulldomain txtvalue
  33. # Used to remove the txt record after validation
  34. dns_active24_rm() {
  35. fulldomain=$1
  36. txtvalue=$2
  37. _active24_init
  38. _debug "Getting txt records"
  39. _active24_rest GET "dns/$_domain/records/v1"
  40. if _contains "$response" "errors"; then
  41. _err "Error"
  42. return 1
  43. fi
  44. hash_ids=$(echo "$response" | _egrep_o "[^{]+${txtvalue}[^}]+" | _egrep_o "hashId\":\"[^\"]+" | cut -c10-)
  45. for hash_id in $hash_ids; do
  46. _debug "Removing hash_id" "$hash_id"
  47. if _active24_rest DELETE "dns/$_domain/$hash_id/v1" ""; then
  48. if _contains "$response" "errors"; then
  49. _err "Unable to remove txt record."
  50. return 1
  51. else
  52. _info "Removed txt record."
  53. return 0
  54. fi
  55. fi
  56. done
  57. _err "No txt records found."
  58. return 1
  59. }
  60. #################### Private functions below ##################################
  61. #_acme-challenge.www.domain.com
  62. #returns
  63. # _sub_domain=_acme-challenge.www
  64. # _domain=domain.com
  65. # _domain_id=sdjkglgdfewsdfg
  66. _get_root() {
  67. domain=$1
  68. if ! _active24_rest GET "dns/domains/v1"; then
  69. return 1
  70. fi
  71. i=2
  72. p=1
  73. while true; do
  74. h=$(printf "%s" "$domain" | cut -d . -f $i-100)
  75. _debug "h" "$h"
  76. if [ -z "$h" ]; then
  77. #not valid
  78. return 1
  79. fi
  80. if _contains "$response" "\"$h\"" >/dev/null; then
  81. _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
  82. _domain=$h
  83. return 0
  84. fi
  85. p=$i
  86. i=$(_math "$i" + 1)
  87. done
  88. return 1
  89. }
  90. _active24_rest() {
  91. m=$1
  92. ep="$2"
  93. data="$3"
  94. _debug "$ep"
  95. export _H1="Authorization: Bearer $ACTIVE24_Token"
  96. if [ "$m" != "GET" ]; then
  97. _debug "data" "$data"
  98. response="$(_post "$data" "$ACTIVE24_Api/$ep" "" "$m" "application/json")"
  99. else
  100. response="$(_get "$ACTIVE24_Api/$ep")"
  101. fi
  102. if [ "$?" != "0" ]; then
  103. _err "error $ep"
  104. return 1
  105. fi
  106. _debug2 response "$response"
  107. return 0
  108. }
  109. _active24_init() {
  110. ACTIVE24_Token="${ACTIVE24_Token:-$(_readaccountconf_mutable ACTIVE24_Token)}"
  111. if [ -z "$ACTIVE24_Token" ]; then
  112. ACTIVE24_Token=""
  113. _err "You didn't specify a Active24 api token yet."
  114. _err "Please create the token and try again."
  115. return 1
  116. fi
  117. _saveaccountconf_mutable ACTIVE24_Token "$ACTIVE24_Token"
  118. _debug "First detect the root zone"
  119. if ! _get_root "$fulldomain"; then
  120. _err "invalid domain"
  121. return 1
  122. fi
  123. _debug _sub_domain "$_sub_domain"
  124. _debug _domain "$_domain"
  125. }