]>
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 | |
b0561058 J |
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="" | |
d519873f | 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." | |
b0561058 J |
23 | return 1 |
24 | fi | |
25 | ||
0b52645b | 26 | if [ -z "$Infoblox_View" ]; then |
d519873f | 27 | _info "No Infoblox_View set, using fallback value 'default'" |
0b52645b RG |
28 | Infoblox_View="default" |
29 | fi | |
52243d08 | 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 | 35 | |
d519873f | 36 | ## URLencode Infoblox View to deal with e.g. spaces |
37 | Infoblox_ViewEncoded=$(printf "%b" "$Infoblox_View" | _url_encode) | |
38 | ||
b0561058 | 39 | ## Base64 encode the credentials |
7dc548b4 | 40 | Infoblox_CredsEncoded=$(printf "%b" "$Infoblox_Creds" | _base64) |
b0561058 J |
41 | |
42 | ## Construct the HTTP Authorization header | |
43 | export _H1="Accept-Language:en-US" | |
44 | export _H2="Authorization: Basic $Infoblox_CredsEncoded" | |
224cd046 | 45 | |
d519873f | 46 | ## Construct the request URL |
47 | baseurlnObject="https://$Infoblox_Server/wapi/v2.2.2/record:txt?name=$fulldomain&text=$txtvalue&view=${Infoblox_ViewEncoded}" | |
224cd046 | 48 | |
b0561058 | 49 | ## Add the challenge record to the Infoblox grid member |
0b797f59 | 50 | result="$(_post "" "$baseurlnObject" "" "POST")" |
b0561058 J |
51 | |
52 | ## Let's see if we get something intelligible back from the unit | |
d519873f | 53 | if [ "$(echo "$result" | _egrep_o "record:txt/.*:.*/${Infoblox_ViewEncoded}")" ]; then |
b0561058 J |
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 | ||
d519873f | 74 | ## URLencode Infoblox View to deal with e.g. spaces |
75 | Infoblox_ViewEncoded=$(printf "%b" "$Infoblox_View" | _url_encode) | |
76 | ||
b0561058 | 77 | ## Base64 encode the credentials |
0b797f59 | 78 | Infoblox_CredsEncoded="$(printf "%b" "$Infoblox_Creds" | _base64)" |
b0561058 J |
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. | |
d519873f | 85 | baseurlnObject="https://$Infoblox_Server/wapi/v2.2.2/record:txt?name=$fulldomain&text=$txtvalue&view=${Infoblox_ViewEncoded}&_return_type=xml-pretty" |
0b797f59 | 86 | result="$(_get "$baseurlnObject")" |
b0561058 J |
87 | |
88 | ## Let's see if we get something intelligible back from the grid | |
d519873f | 89 | if [ "$(echo "$result" | _egrep_o "record:txt/.*:.*/${Infoblox_ViewEncoded}")" ]; then |
b0561058 | 90 | ## Extract the object reference |
d519873f | 91 | objRef="$(printf "%b" "$result" | _egrep_o "record:txt/.*:.*/${Infoblox_ViewEncoded}")" |
b0561058 J |
92 | objRmUrl="https://$Infoblox_Server/wapi/v2.2.2/$objRef" |
93 | ## Delete them! All the stale records! | |
0b797f59 | 94 | rmResult="$(_post "" "$objRmUrl" "" "DELETE")" |
b0561058 | 95 | ## Let's see if that worked |
d519873f | 96 | if [ "$(echo "$rmResult" | _egrep_o "record:txt/.*:.*/${Infoblox_ViewEncoded}")" ]; then |
b0561058 J |
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 | ||
0a301cdd | 111 | #################### Private functions below ################################## |