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.

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