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.

93 lines
2.9 KiB

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