3 ## Infoblox API integration by Jason Keller and Elijah Tenai
5 ## Report any bugs via https://github.com/jasonkeller/acme.sh
9 ## Nothing to see here, just some housekeeping
13 _info
"Using Infoblox API"
14 _debug fulldomain
"$fulldomain"
15 _debug txtvalue
"$txtvalue"
17 ## Check for the credentials
18 if [ -z "$Infoblox_Creds" ] ||
[ -z "$Infoblox_Server" ]; then
21 _err
"You didn't specify the Infoblox credentials or server (Infoblox_Creds; Infoblox_Server)."
22 _err
"Please set them via EXPORT Infoblox_Creds=username:password or EXPORT Infoblox_server=ip/hostname and try again."
26 if [ -z "$Infoblox_View" ]; then
27 _info
"No Infoblox_View set, using fallback value 'default'"
28 Infoblox_View
="default"
31 ## Save the credentials to the account file
32 _saveaccountconf Infoblox_Creds
"$Infoblox_Creds"
33 _saveaccountconf Infoblox_Server
"$Infoblox_Server"
34 _saveaccountconf Infoblox_View
"$Infoblox_View"
36 ## URLencode Infoblox View to deal with e.g. spaces
37 Infoblox_ViewEncoded
=$
(printf "%b" "$Infoblox_View" | _url_encode
)
39 ## Base64 encode the credentials
40 Infoblox_CredsEncoded
=$
(printf "%b" "$Infoblox_Creds" | _base64
)
42 ## Construct the HTTP Authorization header
43 export _H1
="Accept-Language:en-US"
44 export _H2
="Authorization: Basic $Infoblox_CredsEncoded"
46 ## Construct the request URL
47 baseurlnObject
="https://$Infoblox_Server/wapi/v2.2.2/record:txt?name=$fulldomain&text=$txtvalue&view=${Infoblox_ViewEncoded}"
49 ## Add the challenge record to the Infoblox grid member
50 result
="$(_post "" "$baseurlnObject" "" "POST
")"
52 ## Let's see if we get something intelligible back from the unit
53 if [ "$(echo "$result" | _egrep_o "record
:txt
/.
*:.
*/${Infoblox_ViewEncoded}")" ]; then
54 _info
"Successfully created the txt record"
57 _err
"Error encountered during record addition"
66 ## Nothing to see here, just some housekeeping
70 _info
"Using Infoblox API"
71 _debug fulldomain
"$fulldomain"
72 _debug txtvalue
"$txtvalue"
74 ## URLencode Infoblox View to deal with e.g. spaces
75 Infoblox_ViewEncoded
=$
(printf "%b" "$Infoblox_View" | _url_encode
)
77 ## Base64 encode the credentials
78 Infoblox_CredsEncoded
="$(printf "%b
" "$Infoblox_Creds" | _base64)"
80 ## Construct the HTTP Authorization header
81 export _H1
="Accept-Language:en-US"
82 export _H2
="Authorization: Basic $Infoblox_CredsEncoded"
84 ## Does the record exist? Let's check.
85 baseurlnObject
="https://$Infoblox_Server/wapi/v2.2.2/record:txt?name=$fulldomain&text=$txtvalue&view=${Infoblox_ViewEncoded}&_return_type=xml-pretty"
86 result
="$(_get "$baseurlnObject")"
88 ## Let's see if we get something intelligible back from the grid
89 if [ "$(echo "$result" | _egrep_o "record
:txt
/.
*:.
*/${Infoblox_ViewEncoded}")" ]; then
90 ## Extract the object reference
91 objRef
="$(printf "%b
" "$result" | _egrep_o "record
:txt
/.
*:.
*/${Infoblox_ViewEncoded}")"
92 objRmUrl
="https://$Infoblox_Server/wapi/v2.2.2/$objRef"
93 ## Delete them! All the stale records!
94 rmResult
="$(_post "" "$objRmUrl" "" "DELETE
")"
95 ## Let's see if that worked
96 if [ "$(echo "$rmResult" | _egrep_o "record
:txt
/.
*:.
*/${Infoblox_ViewEncoded}")" ]; then
97 _info
"Successfully deleted $objRef"
100 _err
"Error occurred during txt record delete"
105 _err
"Record to delete didn't match an existing record"
111 #################### Private functions below ##################################