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.

105 lines
4.2 KiB

  1. #!/usr/bin/env sh
  2. #This is a working API script to add a TXT record to the DNS Exit-managed DNS service.
  3. # dns_myapi_add()
  4. #Which will be called by acme.sh to add the txt record to th DNS Exit DNS service as part
  5. #of the SSL certificate provisioning request.
  6. #returns 0 means success, otherwise error.
  7. #
  8. #Author: John Berlet
  9. #Date: 31/01/2022
  10. #Report Bugs here: https://github.com/acmesh-official/acme.sh/issues/3925
  11. #
  12. ######## Public functions #####################
  13. dns_japi_add() {
  14. fulldomain=$1
  15. txtvalue=$2
  16. JAPIendpoint="https://api.dnsexit.com/dns/"
  17. #_debug "Domain being used with custom script is: $domain"
  18. fullchallengedomain="${JAPI_domain:-$(_readaccountconf_mutable JAPI_domain)}"
  19. _debug "Full Challenge Domain is: $fullchallengedomain"
  20. JAPI_apikey="${JAPI_apikey:-$(_readaccountconf_mutable JAPI_apikey)}"
  21. "$_domain"
  22. #Set H1,H2 headers with DNS Exit API key
  23. export _H1="Content-Type: application/json"
  24. export _H2="apikey: $JAPI_apikey"
  25. _debug "Defined apikey $JAPI_apikey"
  26. if [ -z "$JAPI_apikey" ] || [ -z "$fullchallengedomain" ]; then
  27. JAPI_apikey=""
  28. _info "You didn't specify the api key or the full zone domain name"
  29. _info "Please define --> 'export xxx' your api key and fully qualified zone and domain name"
  30. _info "Example: 'export JAPI_apikey=<your DNS Exit api key>'"
  31. _info "Cont: 'export JAPI_domain=<_acme-challenge.your domain name>'"
  32. return 1
  33. fi
  34. #Save DNS Exit account API/domain challenge zone/domain name in account.conf for future renewals
  35. _saveaccountconf_mutable JAPI_apikey "$JAPI_apikey"
  36. _saveaccountconf_mutable JAPI_domain "$JAPI_domain"
  37. _debug "First detect the root zone"
  38. _debug "Calling DNS Exit DNS API..."
  39. _info "Using JAPI"
  40. _debug "Passed domain to function: $fulldomain"
  41. _debug "Full Challenge domain: $fullchallengedomain"
  42. _debug txtvalue "$txtvalue"
  43. #_err "Not implemented!"
  44. response="$(_post "{\"domain\":\"$_domain\",\"update\": {\"type\":\"TXT\",\"name\":\"$fullchallengedomain\",\"content\":\"$txtvalue\",\"ttl\":0}}" $JAPIendpoint "" POST "application/json")"
  45. if ! printf "%s" "$response" | grep \"code\":0>/dev/null; then
  46. _err "There was an error updating the TXT record..."
  47. _err "DNS Exit API response: $response"
  48. _err "Please refer to this site for additional information related to this error code - https://dnsexit.com/dns/dns-api/"
  49. return 1
  50. fi
  51. return 0
  52. }
  53. #Usage: fulldomain txtvalue
  54. #Remove the txt record after validation.
  55. dns_japi_rm() {
  56. fulldomain=$1
  57. txtvalue=$2
  58. JAPIendpoint="https://api.dnsexit.com/dns/"
  59. #_debug "Domain being used with custom script is: $domain"
  60. fullchallengedomain="${JAPI_domain:-$(_readaccountconf_mutable JAPI_domain)}"
  61. _debug "Full Challenge Domain is: $fullchallengedomain"
  62. JAPI_apikey="${JAPI_apikey:-$(_readaccountconf_mutable JAPI_apikey)}"
  63. #Set H1,H2 headers with DNS Exit API key
  64. export _H1="Content-Type: application/json"
  65. export _H2="apikey: $JAPI_apikey"
  66. #domainUpdate=$domain
  67. _debug "Defined apikey $JAPI_apikey"
  68. if [ -z "$JAPI_apikey" ] || [ -z "$fullchallengedomain" ]; then
  69. JAPI_apikey=""
  70. _info "You didn't specify the api key or the full zone domain name for the TXT record removal"
  71. _info "Please define --> 'export xxx' your api key and fully qualified zone and domain name"
  72. _info "Example: 'export JAPI_apikey=<your DNS Exit api key>'"
  73. _info "Cont: 'export JAPI_domain=<_acme-challenge.your domain name>'"
  74. return 1
  75. fi
  76. _debug "First detect the root zone"
  77. _debug "Calling DNS Exit DNS API..."
  78. _info "Using JAPI"
  79. _debug "Passed domain to function: $fulldomain"
  80. _debug "Full Challenge domain: $fullchallengedomain"
  81. _debug txtvalue "$txtvalue"
  82. #_err "Not implemented!"
  83. response="$(_post "{\"domain\":\"$_domain\",\"delete\": {\"type\":\"TXT\",\"name\":\"$fullchallengedomain\",\"content\":\"$txtvalue\",\"ttl\":0}}" $JAPIendpoint "" POST "application/json")"
  84. if ! printf "%s" "$response" | grep \"code\":0>/dev/null; then
  85. _err "There was an error deleting the TXT record..."
  86. _err "DNS Exit API response: $response"
  87. _err "Please refer to this site for additional information related to this error code - https://dnsexit.com/dns/dns-api/"
  88. return 1
  89. fi
  90. return 0
  91. _debug fulldomain "$fulldomain"
  92. _debug txtvalue "$txtvalue"
  93. }