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.

97 lines
3.0 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
  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. baseurlnObject="https://$Infoblox_Server/wapi/v2.2.2/record:txt?name=$fulldomain&text=$txtvalue"
  10. _info "Using Infoblox API"
  11. _debug fulldomain "$fulldomain"
  12. _debug txtvalue "$txtvalue"
  13. ## Check for the credentials
  14. if [ -z "$Infoblox_Creds" ] || [ -z "$Infoblox_Server" ]; then
  15. Infoblox_Creds=""
  16. Infoblox_Server=""
  17. _err "You didn't specify the credentials or server yet (Infoblox_Creds and Infoblox_Server)."
  18. _err "Please set them via EXPORT ([username:password] and [ip or hostname]) and try again."
  19. return 1
  20. fi
  21. ## Save the credentials to the account file
  22. _saveaccountconf Infoblox_Creds "$Infoblox_Creds"
  23. _saveaccountconf Infoblox_Server "$Infoblox_Server"
  24. ## Base64 encode the credentials
  25. Infoblox_CredsEncoded=$(printf "%b" "$Infoblox_Creds" | _base64)
  26. ## Construct the HTTP Authorization header
  27. export _H1="Accept-Language:en-US"
  28. export _H2="Authorization: Basic $Infoblox_CredsEncoded"
  29. ## Add the challenge record to the Infoblox grid member
  30. result=$(_post "" "$baseurlnObject" "" "POST")
  31. ## Let's see if we get something intelligible back from the unit
  32. if echo "$result" | egrep 'record:txt/.*:.*/default'; then
  33. _info "Successfully created the txt record"
  34. return 0
  35. else
  36. _err "Error encountered during record addition"
  37. _err "$result"
  38. return 1
  39. fi
  40. }
  41. dns_infoblox_rm() {
  42. ## Nothing to see here, just some housekeeping
  43. fulldomain=$1
  44. txtvalue=$2
  45. _info "Using Infoblox API"
  46. _debug fulldomain "$fulldomain"
  47. _debug txtvalue "$txtvalue"
  48. ## Base64 encode the credentials
  49. Infoblox_CredsEncoded=$(printf "%b" "$Infoblox_Creds" | _base64)
  50. ## Construct the HTTP Authorization header
  51. export _H1="Accept-Language:en-US"
  52. export _H2="Authorization: Basic $Infoblox_CredsEncoded"
  53. ## Does the record exist? Let's check.
  54. baseurlnObject="https://$Infoblox_Server/wapi/v2.2.2/record:txt?name=$fulldomain&text=$txtvalue&_return_type=xml-pretty"
  55. result=$(_get "$baseurlnObject")
  56. ## Let's see if we get something intelligible back from the grid
  57. if echo "$result" | egrep 'record:txt/.*:.*/default'; then
  58. ## Extract the object reference
  59. objRef=$(printf "%b" "$result" | _egrep_o 'record:txt/.*:.*/default')
  60. objRmUrl="https://$Infoblox_Server/wapi/v2.2.2/$objRef"
  61. ## Delete them! All the stale records!
  62. rmResult=$(_post "" "$objRmUrl" "" "DELETE")
  63. ## Let's see if that worked
  64. if echo "$rmResult" | egrep 'record:txt/.*:.*/default'; then
  65. _info "Successfully deleted $objRef"
  66. return 0
  67. else
  68. _err "Error occurred during txt record delete"
  69. _err "$rmResult"
  70. return 1
  71. fi
  72. else
  73. _err "Record to delete didn't match an existing record"
  74. _err "$result"
  75. return 1
  76. fi
  77. }
  78. #################### Private functions below ##################################