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.

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