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