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.

59 lines
1.8 KiB

2 years ago
2 years ago
2 years ago
  1. #!/usr/bin/env sh
  2. # Official DNS API for Nanelo.com
  3. # Provide the required API Key like this:
  4. # NANELO_TOKEN="FmD408PdqT1E269gUK57"
  5. NANELO_API="https://api.nanelo.com/v1/"
  6. ######## Public functions #####################
  7. # Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  8. dns_nanelo_add() {
  9. fulldomain=$1
  10. txtvalue=$2
  11. NANELO_TOKEN="${NANELO_TOKEN:-$(_readaccountconf_mutable NANELO_TOKEN)}"
  12. if [ -z "$NANELO_TOKEN" ]; then
  13. NANELO_TOKEN=""
  14. _err "You didn't configure a Nanelo API Key yet."
  15. _err "Please set NANELO_TOKEN and try again."
  16. _err "Login to Nanelo.com and go to Settings > API Keys to get a Key"
  17. return 1
  18. fi
  19. _saveaccountconf_mutable NANELO_TOKEN "$NANELO_TOKEN"
  20. _info "Adding TXT record to ${fulldomain}"
  21. response="$(_get "$NANELO_API$NANELO_TOKEN/dns/addrecord?type=TXT&ttl=60&name=${fulldomain}&value=${txtvalue}")"
  22. if _contains "${response}" 'success'; then
  23. return 0
  24. fi
  25. _err "Could not create resource record, please check the logs"
  26. _err "${response}"
  27. return 1
  28. }
  29. dns_nanelo_rm() {
  30. fulldomain=$1
  31. txtvalue=$2
  32. NANELO_TOKEN="${NANELO_TOKEN:-$(_readaccountconf_mutable NANELO_TOKEN)}"
  33. if [ -z "$NANELO_TOKEN" ]; then
  34. NANELO_TOKEN=""
  35. _err "You didn't configure a Nanelo API Key yet."
  36. _err "Please set NANELO_TOKEN and try again."
  37. _err "Login to Nanelo.com and go to Settings > API Keys to get a Key"
  38. return 1
  39. fi
  40. _saveaccountconf_mutable NANELO_TOKEN "$NANELO_TOKEN"
  41. _info "Deleting resource record $fulldomain"
  42. response="$(_get "$NANELO_API$NANELO_TOKEN/dns/deleterecord?type=TXT&ttl=60&name=${fulldomain}&value=${txtvalue}")"
  43. if _contains "${response}" 'success'; then
  44. return 0
  45. fi
  46. _err "Could not delete resource record, please check the logs"
  47. _err "${response}"
  48. return 1
  49. }