]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env sh | |
2 | ||
3 | ## Infoblox API integration by Jason Keller and Elijah Tenai | |
4 | ## | |
5 | ## Report any bugs via https://github.com/jasonkeller/acme.sh | |
6 | ||
7 | dns_infoblox_add() { | |
8 | ||
9 | ## Nothing to see here, just some housekeeping | |
10 | fulldomain=$1 | |
11 | txtvalue=$2 | |
12 | ||
13 | _info "Using Infoblox API" | |
14 | _debug fulldomain "$fulldomain" | |
15 | _debug txtvalue "$txtvalue" | |
16 | ||
17 | ## Check for the credentials | |
18 | if [ -z "$Infoblox_Creds" ] || [ -z "$Infoblox_Server" ]; then | |
19 | Infoblox_Creds="" | |
20 | Infoblox_Server="" | |
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." | |
23 | return 1 | |
24 | fi | |
25 | ||
26 | if [ -z "$Infoblox_View" ]; then | |
27 | _info "No Infoblox_View set, using fallback value 'default'" | |
28 | Infoblox_View="default" | |
29 | fi | |
30 | ||
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" | |
35 | ||
36 | ## URLencode Infoblox View to deal with e.g. spaces | |
37 | Infoblox_ViewEncoded=$(printf "%b" "$Infoblox_View" | _url_encode) | |
38 | ||
39 | ## Base64 encode the credentials | |
40 | Infoblox_CredsEncoded=$(printf "%b" "$Infoblox_Creds" | _base64) | |
41 | ||
42 | ## Construct the HTTP Authorization header | |
43 | export _H1="Accept-Language:en-US" | |
44 | export _H2="Authorization: Basic $Infoblox_CredsEncoded" | |
45 | ||
46 | ## Construct the request URL | |
47 | baseurlnObject="https://$Infoblox_Server/wapi/v2.2.2/record:txt?name=$fulldomain&text=$txtvalue&view=${Infoblox_ViewEncoded}" | |
48 | ||
49 | ## Add the challenge record to the Infoblox grid member | |
50 | result="$(_post "" "$baseurlnObject" "" "POST")" | |
51 | ||
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" | |
55 | return 0 | |
56 | else | |
57 | _err "Error encountered during record addition" | |
58 | _err "$result" | |
59 | return 1 | |
60 | fi | |
61 | ||
62 | } | |
63 | ||
64 | dns_infoblox_rm() { | |
65 | ||
66 | ## Nothing to see here, just some housekeeping | |
67 | fulldomain=$1 | |
68 | txtvalue=$2 | |
69 | ||
70 | _info "Using Infoblox API" | |
71 | _debug fulldomain "$fulldomain" | |
72 | _debug txtvalue "$txtvalue" | |
73 | ||
74 | ## URLencode Infoblox View to deal with e.g. spaces | |
75 | Infoblox_ViewEncoded=$(printf "%b" "$Infoblox_View" | _url_encode) | |
76 | ||
77 | ## Base64 encode the credentials | |
78 | Infoblox_CredsEncoded="$(printf "%b" "$Infoblox_Creds" | _base64)" | |
79 | ||
80 | ## Construct the HTTP Authorization header | |
81 | export _H1="Accept-Language:en-US" | |
82 | export _H2="Authorization: Basic $Infoblox_CredsEncoded" | |
83 | ||
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")" | |
87 | ||
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" | |
98 | return 0 | |
99 | else | |
100 | _err "Error occurred during txt record delete" | |
101 | _err "$rmResult" | |
102 | return 1 | |
103 | fi | |
104 | else | |
105 | _err "Record to delete didn't match an existing record" | |
106 | _err "$result" | |
107 | return 1 | |
108 | fi | |
109 | } | |
110 | ||
111 | #################### Private functions below ################################## |