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.

131 lines
3.4 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. # Response after adding a TXT record should be something like this:
  37. # {"status":true,"id":28160443,"error":null}
  38. if ! _contains "$response" '"error":null' >/dev/null; then
  39. _err "Error while adding TXT record: '$response'"
  40. return 1
  41. fi
  42. return 0
  43. }
  44. #fulldomain txtvalue
  45. dns_rage4_rm() {
  46. fulldomain=$1
  47. txtvalue=$2
  48. RAGE4_USERNAME="${RAGE4_USERNAME:-$(_readaccountconf_mutable RAGE4_USERNAME)}"
  49. RAGE4_TOKEN="${RAGE4_TOKEN:-$(_readaccountconf_mutable RAGE4_TOKEN)}"
  50. _debug "First detect the root zone"
  51. if ! _get_root "$fulldomain"; then
  52. _err "invalid domain"
  53. return 1
  54. fi
  55. _debug _domain_id "$_domain_id"
  56. _debug "Getting txt records"
  57. _rage4_rest "getrecords/?id=${_domain_id}"
  58. _record_id=$(echo "$response" | tr '{' '\n' | grep '"TXT"' | grep "\"$txtvalue" | sed -rn 's/.*"id":([[:digit:]]+),.*/\1/p')
  59. if [ -z "$_record_id" ]; then
  60. _err "error retrieving the record_id of the new TXT record in order to delete it, got: '$_record_id'."
  61. return 1
  62. fi
  63. _rage4_rest "deleterecord/?id=${_record_id}"
  64. return 0
  65. }
  66. #################### Private functions below ##################################
  67. #_acme-challenge.www.domain.com
  68. #returns
  69. # _domain=domain.com
  70. # _domain_id=sdjkglgdfewsdfg
  71. _get_root() {
  72. domain=$1
  73. if ! _rage4_rest "getdomains"; then
  74. return 1
  75. fi
  76. _debug _get_root_domain "$domain"
  77. for line in $(echo "$response" | tr '}' '\n'); do
  78. __domain=$(echo "$line" | sed -rn 's/.*"name":"([^"]*)",.*/\1/p')
  79. __domain_id=$(echo "$line" | sed -rn 's/.*"id":([^,]*),.*/\1/p')
  80. if [ "$domain" != "${domain%"$__domain"*}" ]; then
  81. _domain_id="$__domain_id"
  82. break
  83. fi
  84. done
  85. if [ -z "$_domain_id" ]; then
  86. return 1
  87. fi
  88. return 0
  89. }
  90. _rage4_rest() {
  91. ep="$1"
  92. _debug "$ep"
  93. username_trimmed=$(echo "$RAGE4_USERNAME" | tr -d '"')
  94. token_trimmed=$(echo "$RAGE4_TOKEN" | tr -d '"')
  95. auth=$(printf '%s:%s' "$username_trimmed" "$token_trimmed" | _base64)
  96. export _H1="Authorization: Basic $auth"
  97. response="$(_get "$RAGE4_Api$ep")"
  98. if [ "$?" != "0" ]; then
  99. _err "error $ep"
  100. return 1
  101. fi
  102. _debug2 response "$response"
  103. return 0
  104. }