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.

112 lines
4.4 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. #$passedDomain=$_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. _debug _domain_id "$_domain_id"
  44. _debug _sub_domain "$_sub_domain"
  45. _debug _domain "$_domain"
  46. #_err "Not implemented!"
  47. response="$(_post "{\"domain\":\"${_domain}\",\"update\": {\"type\":\"TXT\",\"name\":\"$fullchallengedomain\",\"content\":\"$txtvalue\",\"ttl\":0}}" $JAPIendpoint "" POST "application/json")"
  48. if ! printf "%s" "$response" | grep \"code\":0>/dev/null; then
  49. _err "There was an error updating the TXT record..."
  50. _err "DNS Exit API response: $response"
  51. _err "Please refer to this site for additional information related to this error code - https://dnsexit.com/dns/dns-api/"
  52. return 1
  53. fi
  54. return 0
  55. }
  56. #Usage: fulldomain txtvalue
  57. #Remove the txt record after validation.
  58. dns_japi_rm() {
  59. fulldomain=$1
  60. txtvalue=$2
  61. JAPIendpoint="https://api.dnsexit.com/dns/"
  62. #_debug "Domain being used with custom script is: $domain"
  63. fullchallengedomain="${JAPI_domain:-$(_readaccountconf_mutable JAPI_domain)}"
  64. _debug "Full Challenge Domain is: $fullchallengedomain"
  65. JAPI_apikey="${JAPI_apikey:-$(_readaccountconf_mutable JAPI_apikey)}"
  66. #Set H1,H2 headers with DNS Exit API key
  67. $passedDomain=$_domain
  68. export _H1="Content-Type: application/json"
  69. export _H2="apikey: $JAPI_apikey"
  70. #domainUpdate=$domain
  71. _debug "Defined apikey $JAPI_apikey"
  72. if [ -z "$JAPI_apikey" ] || [ -z "$fullchallengedomain" ]; then
  73. JAPI_apikey=""
  74. _info "You didn't specify the api key or the full zone domain name for the TXT record removal"
  75. _info "Please define --> 'export xxx' your api key and fully qualified zone and domain name"
  76. _info "Example: 'export JAPI_apikey=<your DNS Exit api key>'"
  77. _info "Cont: 'export JAPI_domain=<_acme-challenge.your domain name>'"
  78. return 1
  79. fi
  80. _debug "First detect the root zone"
  81. _debug "Calling DNS Exit DNS API..."
  82. _info "Using JAPI"
  83. _debug "Passed domain to function: $fulldomain"
  84. _debug "Full Challenge domain: $fullchallengedomain"
  85. _debug txtvalue "$txtvalue"
  86. _debug _domain_id "$_domain_id"
  87. _debug _sub_domain "$_sub_domain"
  88. _debug _domain "$_domain"
  89. #_err "Not implemented!"
  90. response="$(_post "{\"domain\":\"${_domain}\",\"delete\": {\"type\":\"TXT\",\"name\":\"$fullchallengedomain\",\"content\":\"$txtvalue\",\"ttl\":0}}" $JAPIendpoint "" POST "application/json")"
  91. if ! printf "%s" "$response" | grep \"code\":0>/dev/null; then
  92. _err "There was an error deleting the TXT record..."
  93. _err "DNS Exit API response: $response"
  94. _err "Please refer to this site for additional information related to this error code - https://dnsexit.com/dns/dns-api/"
  95. return 1
  96. fi
  97. return 0
  98. _debug fulldomain "$fulldomain"
  99. _debug txtvalue "$txtvalue"
  100. }