]> git.proxmox.com Git - mirror_acme.sh.git/blob - dnsapi/dns_infoblox.sh
save Infoblox_View to account config
[mirror_acme.sh.git] / dnsapi / dns_infoblox.sh
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 baseurlnObject="https://$Infoblox_Server/wapi/v2.2.2/record:txt?name=$fulldomain&text=$txtvalue&view=$Infoblox_View"
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=""
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."
24 return 1
25 fi
26
27 if [ -z "$Infoblox_View" ]; then
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 ## Base64 encode the credentials
37 Infoblox_CredsEncoded=$(printf "%b" "$Infoblox_Creds" | _base64)
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
44 result=$(_post "" "$baseurlnObject" "" "POST")
45
46 ## Let's see if we get something intelligible back from the unit
47 if echo "$result" | egrep "record:txt/.*:.*/$Infoblox_View"; then
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
69 Infoblox_CredsEncoded=$(printf "%b" "$Infoblox_Creds" | _base64)
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.
76 baseurlnObject="https://$Infoblox_Server/wapi/v2.2.2/record:txt?name=$fulldomain&text=$txtvalue&view=$Infoblox_View&_return_type=xml-pretty"
77 result=$(_get "$baseurlnObject")
78
79 ## Let's see if we get something intelligible back from the grid
80 if echo "$result" | egrep 'record:txt/.*:.*/default'; then
81 ## Extract the object reference
82 objRef=$(printf "%b" "$result" | _egrep_o "record:txt/.*:.*/$Infoblox_View")
83 objRmUrl="https://$Infoblox_Server/wapi/v2.2.2/$objRef"
84 ## Delete them! All the stale records!
85 rmResult=$(_post "" "$objRmUrl" "" "DELETE")
86 ## Let's see if that worked
87 if echo "$rmResult" | egrep "record:txt/.*:.*/$Infoblox_View"; then
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
102 #################### Private functions below ##################################