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.

97 lines
2.1 KiB

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