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.

117 lines
3.9 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. #!/usr/bin/env sh
  2. # shellcheck disable=SC2034
  3. dns_infoblox_info='Infoblox.com
  4. Site: Infoblox.com
  5. Docs: github.com/acmesh-official/acme.sh/wiki/dnsapi#dns_infoblox
  6. Options:
  7. Infoblox_Creds Credentials. E.g. "username:password"
  8. Infoblox_Server Server hostname. IP or FQDN of infoblox appliance
  9. Issues: github.com/jasonkeller/acme.sh
  10. Author: Jason Keller, Elijah Tenai
  11. '
  12. dns_infoblox_add() {
  13. ## Nothing to see here, just some housekeeping
  14. fulldomain=$1
  15. txtvalue=$2
  16. _info "Using Infoblox API"
  17. _debug fulldomain "$fulldomain"
  18. _debug txtvalue "$txtvalue"
  19. ## Check for the credentials
  20. if [ -z "$Infoblox_Creds" ] || [ -z "$Infoblox_Server" ]; then
  21. Infoblox_Creds=""
  22. Infoblox_Server=""
  23. _err "You didn't specify the Infoblox credentials or server (Infoblox_Creds; Infoblox_Server)."
  24. _err "Please set them via EXPORT Infoblox_Creds=username:password or EXPORT Infoblox_server=ip/hostname and try again."
  25. return 1
  26. fi
  27. if [ -z "$Infoblox_View" ]; then
  28. _info "No Infoblox_View set, using fallback value 'default'"
  29. Infoblox_View="default"
  30. fi
  31. ## Save the credentials to the account file
  32. _saveaccountconf Infoblox_Creds "$Infoblox_Creds"
  33. _saveaccountconf Infoblox_Server "$Infoblox_Server"
  34. _saveaccountconf Infoblox_View "$Infoblox_View"
  35. ## URLencode Infoblox View to deal with e.g. spaces
  36. Infoblox_ViewEncoded=$(printf "%b" "$Infoblox_View" | _url_encode)
  37. ## Base64 encode the credentials
  38. Infoblox_CredsEncoded=$(printf "%b" "$Infoblox_Creds" | _base64)
  39. ## Construct the HTTP Authorization header
  40. export _H1="Accept-Language:en-US"
  41. export _H2="Authorization: Basic $Infoblox_CredsEncoded"
  42. ## Construct the request URL
  43. baseurlnObject="https://$Infoblox_Server/wapi/v2.2.2/record:txt?name=$fulldomain&text=$txtvalue&view=${Infoblox_ViewEncoded}"
  44. ## Add the challenge record to the Infoblox grid member
  45. result="$(_post "" "$baseurlnObject" "" "POST")"
  46. ## Let's see if we get something intelligible back from the unit
  47. if [ "$(echo "$result" | _egrep_o "record:txt/.*:.*/${Infoblox_ViewEncoded}")" ]; then
  48. _info "Successfully created the txt record"
  49. return 0
  50. else
  51. _err "Error encountered during record addition"
  52. _err "$result"
  53. return 1
  54. fi
  55. }
  56. dns_infoblox_rm() {
  57. ## Nothing to see here, just some housekeeping
  58. fulldomain=$1
  59. txtvalue=$2
  60. _info "Using Infoblox API"
  61. _debug fulldomain "$fulldomain"
  62. _debug txtvalue "$txtvalue"
  63. ## URLencode Infoblox View to deal with e.g. spaces
  64. Infoblox_ViewEncoded=$(printf "%b" "$Infoblox_View" | _url_encode)
  65. ## Base64 encode the credentials
  66. Infoblox_CredsEncoded="$(printf "%b" "$Infoblox_Creds" | _base64)"
  67. ## Construct the HTTP Authorization header
  68. export _H1="Accept-Language:en-US"
  69. export _H2="Authorization: Basic $Infoblox_CredsEncoded"
  70. ## Does the record exist? Let's check.
  71. baseurlnObject="https://$Infoblox_Server/wapi/v2.2.2/record:txt?name=$fulldomain&text=$txtvalue&view=${Infoblox_ViewEncoded}&_return_type=xml-pretty"
  72. result="$(_get "$baseurlnObject")"
  73. ## Let's see if we get something intelligible back from the grid
  74. if [ "$(echo "$result" | _egrep_o "record:txt/.*:.*/${Infoblox_ViewEncoded}")" ]; then
  75. ## Extract the object reference
  76. objRef="$(printf "%b" "$result" | _egrep_o "record:txt/.*:.*/${Infoblox_ViewEncoded}")"
  77. objRmUrl="https://$Infoblox_Server/wapi/v2.2.2/$objRef"
  78. ## Delete them! All the stale records!
  79. rmResult="$(_post "" "$objRmUrl" "" "DELETE")"
  80. ## Let's see if that worked
  81. if [ "$(echo "$rmResult" | _egrep_o "record:txt/.*:.*/${Infoblox_ViewEncoded}")" ]; then
  82. _info "Successfully deleted $objRef"
  83. return 0
  84. else
  85. _err "Error occurred during txt record delete"
  86. _err "$rmResult"
  87. return 1
  88. fi
  89. else
  90. _err "Record to delete didn't match an existing record"
  91. _err "$result"
  92. return 1
  93. fi
  94. }
  95. #################### Private functions below ##################################