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.

119 lines
3.0 KiB

  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_rage4_info='rage4.com
  4. Site: rage4.com
  5. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_rage4
  6. Options:
  7. RAGE4_TOKEN API Key
  8. RAGE4_USERNAME Username
  9. Issues: github.com/acmesh-official/acme.sh/issues/4306
  10. '
  11. RAGE4_Api="https://rage4.com/rapi/"
  12. ######## Public functions #####################
  13. #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  14. dns_rage4_add() {
  15. fulldomain=$1
  16. txtvalue=$2
  17. unquotedtxtvalue=$(echo "$txtvalue" | tr -d \")
  18. RAGE4_USERNAME="${RAGE4_USERNAME:-$(_readaccountconf_mutable RAGE4_USERNAME)}"
  19. RAGE4_TOKEN="${RAGE4_TOKEN:-$(_readaccountconf_mutable RAGE4_TOKEN)}"
  20. if [ -z "$RAGE4_USERNAME" ] || [ -z "$RAGE4_TOKEN" ]; then
  21. RAGE4_USERNAME=""
  22. RAGE4_TOKEN=""
  23. _err "You didn't specify a Rage4 api token and username yet."
  24. return 1
  25. fi
  26. #save the api key and email to the account conf file.
  27. _saveaccountconf_mutable RAGE4_USERNAME "$RAGE4_USERNAME"
  28. _saveaccountconf_mutable RAGE4_TOKEN "$RAGE4_TOKEN"
  29. _debug "First detect the root zone"
  30. if ! _get_root "$fulldomain"; then
  31. _err "invalid domain"
  32. return 1
  33. fi
  34. _debug _domain_id "$_domain_id"
  35. _rage4_rest "createrecord/?id=$_domain_id&name=$fulldomain&content=$unquotedtxtvalue&type=TXT&active=true&ttl=1"
  36. return 0
  37. }
  38. #fulldomain txtvalue
  39. dns_rage4_rm() {
  40. fulldomain=$1
  41. txtvalue=$2
  42. RAGE4_USERNAME="${RAGE4_USERNAME:-$(_readaccountconf_mutable RAGE4_USERNAME)}"
  43. RAGE4_TOKEN="${RAGE4_TOKEN:-$(_readaccountconf_mutable RAGE4_TOKEN)}"
  44. _debug "First detect the root zone"
  45. if ! _get_root "$fulldomain"; then
  46. _err "invalid domain"
  47. return 1
  48. fi
  49. _debug _domain_id "$_domain_id"
  50. _debug "Getting txt records"
  51. _rage4_rest "getrecords/?id=${_domain_id}"
  52. _record_id=$(echo "$response" | sed -rn 's/.*"id":([[:digit:]]+)[^\}]*'"$txtvalue"'.*/\1/p')
  53. _rage4_rest "deleterecord/?id=${_record_id}"
  54. return 0
  55. }
  56. #################### Private functions below ##################################
  57. #_acme-challenge.www.domain.com
  58. #returns
  59. # _domain=domain.com
  60. # _domain_id=sdjkglgdfewsdfg
  61. _get_root() {
  62. domain=$1
  63. if ! _rage4_rest "getdomains"; then
  64. return 1
  65. fi
  66. _debug _get_root_domain "$domain"
  67. for line in $(echo "$response" | tr '}' '\n'); do
  68. __domain=$(echo "$line" | sed -rn 's/.*"name":"([^"]*)",.*/\1/p')
  69. __domain_id=$(echo "$line" | sed -rn 's/.*"id":([^,]*),.*/\1/p')
  70. if [ "$domain" != "${domain%"$__domain"*}" ]; then
  71. _domain_id="$__domain_id"
  72. break
  73. fi
  74. done
  75. if [ -z "$_domain_id" ]; then
  76. return 1
  77. fi
  78. return 0
  79. }
  80. _rage4_rest() {
  81. ep="$1"
  82. _debug "$ep"
  83. username_trimmed=$(echo "$RAGE4_USERNAME" | tr -d '"')
  84. token_trimmed=$(echo "$RAGE4_TOKEN" | tr -d '"')
  85. auth=$(printf '%s:%s' "$username_trimmed" "$token_trimmed" | _base64)
  86. export _H1="Content-Type: application/json"
  87. export _H2="Authorization: Basic $auth"
  88. response="$(_get "$RAGE4_Api$ep")"
  89. if [ "$?" != "0" ]; then
  90. _err "error $ep"
  91. return 1
  92. fi
  93. _debug2 response "$response"
  94. return 0
  95. }