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.

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