]>
Commit | Line | Data |
---|---|---|
b6f00ea2 | 1 | #!/usr/bin/env sh |
b0561058 | 2 | |
1424e8a2 J |
3 | ## Infoblox API integration by Jason Keller and Elijah Tenai |
4 | ## | |
5 | ## Report any bugs via https://github.com/jasonkeller/acme.sh | |
6 | ||
b0561058 J |
7 | dns_infoblox_add() { |
8 | ||
9 | ## Nothing to see here, just some housekeeping | |
10 | fulldomain=$1 | |
11 | txtvalue=$2 | |
0b52645b | 12 | baseurlnObject="https://$Infoblox_Server/wapi/v2.2.2/record:txt?name=$fulldomain&text=$txtvalue&view=$Infoblox_View" |
b0561058 J |
13 | |
14 | _info "Using Infoblox API" | |
15 | _debug fulldomain "$fulldomain" | |
16 | _debug txtvalue "$txtvalue" | |
17 | ||
18 | ## Check for the credentials | |
19 | if [ -z "$Infoblox_Creds" ] || [ -z "$Infoblox_Server" ]; then | |
20 | Infoblox_Creds="" | |
21 | Infoblox_Server="" | |
0b52645b RG |
22 | _err "You didn't specify the credentials, server or infoblox view yet (Infoblox_Creds, Infoblox_Server and Infoblox_View)." |
23 | _err "Please set them via EXPORT ([username:password], [ip or hostname]) and try again." | |
b0561058 J |
24 | return 1 |
25 | fi | |
26 | ||
0b52645b RG |
27 | if [ -z "$Infoblox_View" ]; then |
28 | Infoblox_View="default" | |
29 | fi | |
30 | ||
b0561058 J |
31 | ## Save the credentials to the account file |
32 | _saveaccountconf Infoblox_Creds "$Infoblox_Creds" | |
33 | _saveaccountconf Infoblox_Server "$Infoblox_Server" | |
3b74ac84 | 34 | _saveaccountconf Infoblox_View "$Infoblox_View" |
b0561058 J |
35 | |
36 | ## Base64 encode the credentials | |
7dc548b4 | 37 | Infoblox_CredsEncoded=$(printf "%b" "$Infoblox_Creds" | _base64) |
b0561058 J |
38 | |
39 | ## Construct the HTTP Authorization header | |
40 | export _H1="Accept-Language:en-US" | |
41 | export _H2="Authorization: Basic $Infoblox_CredsEncoded" | |
42 | ||
43 | ## Add the challenge record to the Infoblox grid member | |
0b797f59 | 44 | result="$(_post "" "$baseurlnObject" "" "POST")" |
b0561058 J |
45 | |
46 | ## Let's see if we get something intelligible back from the unit | |
0b797f59 | 47 | if [ "$(echo "$result" | _egrep_o "record:txt/.*:.*/$Infoblox_View")" ]; then |
b0561058 J |
48 | _info "Successfully created the txt record" |
49 | return 0 | |
50 | else | |
51 | _err "Error encountered during record addition" | |
52 | _err "$result" | |
53 | return 1 | |
54 | fi | |
55 | ||
56 | } | |
57 | ||
58 | dns_infoblox_rm() { | |
59 | ||
60 | ## Nothing to see here, just some housekeeping | |
61 | fulldomain=$1 | |
62 | txtvalue=$2 | |
63 | ||
64 | _info "Using Infoblox API" | |
65 | _debug fulldomain "$fulldomain" | |
66 | _debug txtvalue "$txtvalue" | |
67 | ||
68 | ## Base64 encode the credentials | |
0b797f59 | 69 | Infoblox_CredsEncoded="$(printf "%b" "$Infoblox_Creds" | _base64)" |
b0561058 J |
70 | |
71 | ## Construct the HTTP Authorization header | |
72 | export _H1="Accept-Language:en-US" | |
73 | export _H2="Authorization: Basic $Infoblox_CredsEncoded" | |
74 | ||
75 | ## Does the record exist? Let's check. | |
0b52645b | 76 | baseurlnObject="https://$Infoblox_Server/wapi/v2.2.2/record:txt?name=$fulldomain&text=$txtvalue&view=$Infoblox_View&_return_type=xml-pretty" |
0b797f59 | 77 | result="$(_get "$baseurlnObject")" |
b0561058 J |
78 | |
79 | ## Let's see if we get something intelligible back from the grid | |
0b797f59 | 80 | if [ "$(echo "$result" | _egrep_o "record:txt/.*:.*/$Infoblox_View")" ]; then |
b0561058 | 81 | ## Extract the object reference |
0b797f59 | 82 | objRef="$(printf "%b" "$result" | _egrep_o "record:txt/.*:.*/$Infoblox_View")" |
b0561058 J |
83 | objRmUrl="https://$Infoblox_Server/wapi/v2.2.2/$objRef" |
84 | ## Delete them! All the stale records! | |
0b797f59 | 85 | rmResult="$(_post "" "$objRmUrl" "" "DELETE")" |
b0561058 | 86 | ## Let's see if that worked |
0b797f59 | 87 | if [ "$(echo "$rmResult" | _egrep_o "record:txt/.*:.*/$Infoblox_View")" ]; then |
b0561058 J |
88 | _info "Successfully deleted $objRef" |
89 | return 0 | |
90 | else | |
91 | _err "Error occurred during txt record delete" | |
92 | _err "$rmResult" | |
93 | return 1 | |
94 | fi | |
95 | else | |
96 | _err "Record to delete didn't match an existing record" | |
97 | _err "$result" | |
98 | return 1 | |
99 | fi | |
100 | } | |
101 | ||
0a301cdd | 102 | #################### Private functions below ################################## |