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.

101 lines
2.3 KiB

  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_dreamhost_info='DreamHost.com
  4. Site: DreamHost.com
  5. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_dreamhost
  6. Options:
  7. DH_API_KEY API Key
  8. Issues: github.com/RhinoLance/acme.sh
  9. Author: RhinoLance
  10. '
  11. DH_API_ENDPOINT="https://api.dreamhost.com/"
  12. querystring=""
  13. ######## Public functions #####################
  14. #Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  15. dns_dreamhost_add() {
  16. fulldomain=$1
  17. txtvalue=$2
  18. if ! validate "$fulldomain" "$txtvalue"; then
  19. return 1
  20. fi
  21. querystring="key=$DH_API_KEY&cmd=dns-add_record&record=$fulldomain&type=TXT&value=$txtvalue"
  22. if ! submit "$querystring"; then
  23. return 1
  24. fi
  25. return 0
  26. }
  27. #Usage: fulldomain txtvalue
  28. #Remove the txt record after validation.
  29. dns_dreamhost_rm() {
  30. fulldomain=$1
  31. txtvalue=$2
  32. if ! validate "$fulldomain" "$txtvalue"; then
  33. return 1
  34. fi
  35. querystring="key=$DH_API_KEY&cmd=dns-remove_record&record=$fulldomain&type=TXT&value=$txtvalue"
  36. if ! submit "$querystring"; then
  37. return 1
  38. fi
  39. return 0
  40. }
  41. #################### Private functions below ##################################
  42. #send the command to the api endpoint.
  43. submit() {
  44. querystring=$1
  45. url="$DH_API_ENDPOINT?$querystring"
  46. _debug url "$url"
  47. if ! response="$(_get "$url")"; then
  48. _err "Error <$1>"
  49. return 1
  50. fi
  51. if [ -z "$2" ]; then
  52. message="$(echo "$response" | _egrep_o "\"Message\":\"[^\"]*\"" | cut -d : -f 2 | tr -d \")"
  53. if [ -n "$message" ]; then
  54. _err "$message"
  55. return 1
  56. fi
  57. fi
  58. _debug response "$response"
  59. return 0
  60. }
  61. #check that we have a valid API Key
  62. validate() {
  63. fulldomain=$1
  64. txtvalue=$2
  65. _info "Using dreamhost"
  66. _debug fulldomain "$fulldomain"
  67. _debug txtvalue "$txtvalue"
  68. #retrieve the API key from the environment variable if it exists, otherwise look for a saved key.
  69. DH_API_KEY="${DH_API_KEY:-$(_readaccountconf_mutable DH_API_KEY)}"
  70. if [ -z "$DH_API_KEY" ]; then
  71. DH_API_KEY=""
  72. _err "You didn't specify the DreamHost api key yet (export DH_API_KEY=\"<api key>\")"
  73. _err "Please login to your control panel, create a key and try again."
  74. return 1
  75. fi
  76. #save the api key to the account conf file.
  77. _saveaccountconf_mutable DH_API_KEY "$DH_API_KEY"
  78. }