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.

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