]> git.proxmox.com Git - mirror_acme.sh.git/blob - dnsapi/dns_infoblox.sh
Merge remote-tracking branch 'upstream/dev' into dev
[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"
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 or server yet (Infoblox_Creds and Infoblox_Server)."
23 _err "Please set them via EXPORT ([username:password] and [ip or hostname]) and try again."
24 return 1
25 fi
26
27 ## Save the credentials to the account file
28 _saveaccountconf Infoblox_Creds "$Infoblox_Creds"
29 _saveaccountconf Infoblox_Server "$Infoblox_Server"
30
31 ## Base64 encode the credentials
32 Infoblox_CredsEncoded=$(printf "%b" "$Infoblox_Creds" | _base64)
33
34 ## Construct the HTTP Authorization header
35 export _H1="Accept-Language:en-US"
36 export _H2="Authorization: Basic $Infoblox_CredsEncoded"
37
38 ## Add the challenge record to the Infoblox grid member
39 result=$(_post "" "$baseurlnObject" "" "POST")
40
41 ## Let's see if we get something intelligible back from the unit
42 if echo "$result" | egrep 'record:txt/.*:.*/default'; then
43 _info "Successfully created the txt record"
44 return 0
45 else
46 _err "Error encountered during record addition"
47 _err "$result"
48 return 1
49 fi
50
51 }
52
53 dns_infoblox_rm() {
54
55 ## Nothing to see here, just some housekeeping
56 fulldomain=$1
57 txtvalue=$2
58
59 _info "Using Infoblox API"
60 _debug fulldomain "$fulldomain"
61 _debug txtvalue "$txtvalue"
62
63 ## Base64 encode the credentials
64 Infoblox_CredsEncoded=$(printf "%b" "$Infoblox_Creds" | _base64)
65
66 ## Construct the HTTP Authorization header
67 export _H1="Accept-Language:en-US"
68 export _H2="Authorization: Basic $Infoblox_CredsEncoded"
69
70 ## Does the record exist? Let's check.
71 baseurlnObject="https://$Infoblox_Server/wapi/v2.2.2/record:txt?name=$fulldomain&text=$txtvalue&_return_type=xml-pretty"
72 result=$(_get "$baseurlnObject")
73
74 ## Let's see if we get something intelligible back from the grid
75 if echo "$result" | egrep 'record:txt/.*:.*/default'; then
76 ## Extract the object reference
77 objRef=$(printf "%b" "$result" | _egrep_o 'record:txt/.*:.*/default')
78 objRmUrl="https://$Infoblox_Server/wapi/v2.2.2/$objRef"
79 ## Delete them! All the stale records!
80 rmResult=$(_post "" "$objRmUrl" "" "DELETE")
81 ## Let's see if that worked
82 if echo "$rmResult" | egrep 'record:txt/.*:.*/default'; then
83 _info "Successfully deleted $objRef"
84 return 0
85 else
86 _err "Error occurred during txt record delete"
87 _err "$rmResult"
88 return 1
89 fi
90 else
91 _err "Record to delete didn't match an existing record"
92 _err "$result"
93 return 1
94 fi
95 }
96
97 #################### Private functions below ##################################