blob: a19ed13f12b2ec52b86a3fe6b8161b95082e981e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#!/bin/sh
# Derived from update_gandi_net.sh
. /usr/share/libubox/jshn.sh
local __TTL=600
local __RRTYPE
local __STATUS
local __RNAME
[ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing subdomain as 'username'"
[ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing API Key as 'password'"
[ -z "$param_opt" ] && write_log 14 "Service section not configured correctly! Missing PowerDNS URL as 'Optional Parameter'(param_opt)"
# Create endpoint from $param_opt
# e.g. param_opt=http://127.0.0.1:8081
local __ENDPOINT="$param_opt/api/v1/servers/localhost/zones"
[ $use_ipv6 -ne 0 ] && __RRTYPE="AAAA" || __RRTYPE="A"
# Make sure domain is period terminated
if [ ${domain: -1} != '.' ]; then
domain="${domain}."
fi
if [ $username == '@' ]; then
__RNAME="$domain"
else
__RNAME="$username.$domain"
fi
# Build JSON payload
json_init
json_add_array rrsets
json_add_object
json_add_string name "$__RNAME"
json_add_string type "$__RRTYPE"
json_add_int ttl $__TTL
json_add_string changetype "REPLACE"
json_add_array records
json_add_object
json_add_string content "$__IP"
json_add_boolean disabled 0
json_close_object
json_close_array
json_close_object
json_close_array
__STATUS=$(curl -Ss -X PATCH "$__ENDPOINT/$domain" \
-H "X-Api-Key: $password" \
-H "Content-Type: application/json" \
-d "$(json_dump)" \
-w "%{http_code}\n" \
-o $DATFILE 2>$ERRFILE)
if [ $? -ne 0 ]; then
write_log 14 "Curl failed: $(cat $ERRFILE)"
return 1
elif [ -z $__STATUS ] || [ $__STATUS != 204 ]; then
write_log 14 "PowerDNS request failed: $__STATUS \n$(cat $DATFILE)"
return 1
fi
return 0
|