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.

92 lines
2.6 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #!/usr/bin/env sh
  2. # This API is a wrapper for other API so that you
  3. # are able to put your TXT record to multiple providers.
  4. # The functionality is in the responsibility of the respective API
  5. # therefore please check if your used APIs work.
  6. # e.g. for using NS1 and AWS Route53, use:
  7. # OCTODNS_PROVIDERS=nsone_aws
  8. # --dns octodns
  9. #
  10. # Author: Josef Vogt
  11. #
  12. ######## Public functions #####################
  13. dns_octodns_add() {
  14. fulldomain=$1
  15. txtvalue=$2
  16. _info "Creating DNS entries via octoDNS"
  17. _debug fulldomain "$fulldomain"
  18. _debug txtvalue "$txtvalue"
  19. if [ -z "$OCTODNS_PROVIDERS" ]; then
  20. OCTODNS_PROVIDERS=""
  21. _err "You didn't specify OCTODNS_PROVIDERS yet."
  22. _err "Please specifiy your providers and try again."
  23. return 1
  24. fi
  25. #save the providers list to the account conf file.
  26. _saveaccountconf OCTODNS_PROVIDERS "$OCTODNS_PROVIDERS"
  27. for element in $(echo "$OCTODNS_PROVIDERS" | tr "_" ' '); do
  28. _debug element "$element"
  29. sourcecommand="$_SUB_FOLDER_DNSAPI/dns_${element}.sh"
  30. # shellcheck disable=SC1090
  31. if ! . "$sourcecommand"; then
  32. _err "Load file $sourcecommand error. Please check your api file and try again."
  33. return 1
  34. fi
  35. addcommand="dns_${element}_add"
  36. _debug addcommand "$addcommand"
  37. if ! $addcommand "$fulldomain" "$txtvalue"; then
  38. _err "Adding record via $element API was not successful!"
  39. _err "Please check if this API works."
  40. return 1
  41. fi
  42. done
  43. _info "Finished adding records via octoDNS API"
  44. return 0
  45. }
  46. #Remove the txt record after validation.
  47. dns_octodns_rm() {
  48. fulldomain=$1
  49. txtvalue=$2
  50. _info "Removing DNS entries via octoDNS"
  51. _debug fulldomain "$fulldomain"
  52. _debug txtvalue "$txtvalue"
  53. if [ -z "$OCTODNS_PROVIDERS" ]; then
  54. OCTODNS_PROVIDERS=""
  55. _err "You didn't specify OCTODNS_PROVIDERS yet."
  56. _err "Please specifiy your providers and try again."
  57. return 1
  58. fi
  59. for element in $(echo "$OCTODNS_PROVIDERS" | tr "_" ' '); do
  60. _debug element "$element"
  61. sourcecommand="$_SUB_FOLDER_DNSAPI/dns_${element}.sh"
  62. # shellcheck disable=SC1090
  63. if ! . "$sourcecommand"; then
  64. _err "Load file $sourcecommand error. Please check your api file and try again."
  65. return 1
  66. fi
  67. rmcommand="dns_${element}_rm"
  68. _debug rmcommand "$rmcommand"
  69. if ! $rmcommand "$fulldomain" "$txtvalue"; then
  70. _err "Removing record via $element API was not successful!"
  71. _err "You might have to remove the key manually."
  72. _err "Please check if this API works."
  73. return 1
  74. fi
  75. done
  76. _info "Finished deleting records via octoDNS API"
  77. return 0
  78. }