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.

108 lines
3.1 KiB

  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_kinghost_info='King.host
  4. Domains: KingHost.net KingHost.com.br
  5. Site: King.host
  6. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_kinghost
  7. Options:
  8. KINGHOST_Username Username
  9. KINGHOST_Password Password
  10. Author: Felipe Keller Braz <felipebraz@kinghost.com.br>
  11. '
  12. # KingHost API support #
  13. # https://api.kinghost.net/doc/ #
  14. KING_Api="https://api.kinghost.net/acme"
  15. # Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  16. # Used to add txt record
  17. dns_kinghost_add() {
  18. fulldomain=$1
  19. txtvalue=$2
  20. KINGHOST_Username="${KINGHOST_Username:-$(_readaccountconf_mutable KINGHOST_Username)}"
  21. KINGHOST_Password="${KINGHOST_Password:-$(_readaccountconf_mutable KINGHOST_Password)}"
  22. if [ -z "$KINGHOST_Username" ] || [ -z "$KINGHOST_Password" ]; then
  23. KINGHOST_Username=""
  24. KINGHOST_Password=""
  25. _err "You don't specify KingHost api password and email yet."
  26. _err "Please create you key and try again."
  27. return 1
  28. fi
  29. #save the credentials to the account conf file.
  30. _saveaccountconf_mutable KINGHOST_Username "$KINGHOST_Username"
  31. _saveaccountconf_mutable KINGHOST_Password "$KINGHOST_Password"
  32. _debug "Getting txt records"
  33. _kinghost_rest GET "dns" "name=$fulldomain&content=$txtvalue"
  34. #This API call returns "status":"ok" if dns record does not exist
  35. #We are creating a new txt record here, so we expect the "ok" status
  36. if ! echo "$response" | grep '"status":"ok"' >/dev/null; then
  37. _err "Error"
  38. _err "$response"
  39. return 1
  40. fi
  41. _kinghost_rest POST "dns" "name=$fulldomain&content=$txtvalue"
  42. if ! echo "$response" | grep '"status":"ok"' >/dev/null; then
  43. _err "Error"
  44. _err "$response"
  45. return 1
  46. fi
  47. return 0
  48. }
  49. # Usage: fulldomain txtvalue
  50. # Used to remove the txt record after validation
  51. dns_kinghost_rm() {
  52. fulldomain=$1
  53. txtvalue=$2
  54. KINGHOST_Password="${KINGHOST_Password:-$(_readaccountconf_mutable KINGHOST_Password)}"
  55. KINGHOST_Username="${KINGHOST_Username:-$(_readaccountconf_mutable KINGHOST_Username)}"
  56. if [ -z "$KINGHOST_Password" ] || [ -z "$KINGHOST_Username" ]; then
  57. KINGHOST_Password=""
  58. KINGHOST_Username=""
  59. _err "You don't specify KingHost api key and email yet."
  60. _err "Please create you key and try again."
  61. return 1
  62. fi
  63. _kinghost_rest DELETE "dns" "name=$fulldomain&content=$txtvalue"
  64. if ! echo "$response" | grep '"status":"ok"' >/dev/null; then
  65. _err "Error"
  66. _err "$response"
  67. return 1
  68. fi
  69. return 0
  70. }
  71. #################### Private functions below ##################################
  72. _kinghost_rest() {
  73. method=$1
  74. uri="$2"
  75. data="$3"
  76. _debug "$uri"
  77. export _H1="X-Auth-Email: $KINGHOST_Username"
  78. export _H2="X-Auth-Key: $KINGHOST_Password"
  79. if [ "$method" != "GET" ]; then
  80. _debug data "$data"
  81. response="$(_post "$data" "$KING_Api/$uri.json" "" "$method")"
  82. else
  83. response="$(_get "$KING_Api/$uri.json?$data")"
  84. fi
  85. if [ "$?" != "0" ]; then
  86. _err "error $uri"
  87. return 1
  88. fi
  89. _debug2 response "$response"
  90. return 0
  91. }