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.

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