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