4 #https://doc.powerdns.com/md/httpapi/api_spec/
6 #PDNS_Url="http://ns.example.com:8081"
7 #PDNS_ServerId="localhost"
8 #PDNS_Token="0123456789ABCDEF"
13 ######## Public functions #####################
14 #Usage: add _acme-challenge.www.domain.com "123456789ABCDEF0000000000000000000000000000000000000"
21 if [ -z "$PDNS_Url" ]; then
23 _err
"You don't specify PowerDNS address."
24 _err
"Please set PDNS_Url and try again."
28 if [ -z "$PDNS_ServerId" ]; then
30 _err
"You don't specify PowerDNS server id."
31 _err
"Please set you PDNS_ServerId and try again."
35 if [ -z "$PDNS_Token" ]; then
37 _err
"You don't specify PowerDNS token."
38 _err
"Please create you PDNS_Token and try again."
42 if [ -z "$PDNS_Ttl" ]; then
43 PDNS_Ttl
="$DEFAULT_PDNS_TTL"
46 #save the api addr and key to the account conf file.
47 _saveaccountconf PDNS_Url
"$PDNS_Url"
48 _saveaccountconf PDNS_ServerId
"$PDNS_ServerId"
49 _saveaccountconf PDNS_Token
"$PDNS_Token"
51 if [ "$PDNS_Ttl" != "$DEFAULT_PDNS_TTL" ]; then
52 _saveaccountconf PDNS_Ttl
"$PDNS_Ttl"
55 _debug
"Detect root zone"
56 if ! _get_root
"$fulldomain"; then
60 _debug _domain
"$_domain"
62 if ! set_record
"$_domain" "$fulldomain" "$txtvalue"; then
73 _debug
"Detect root zone"
74 if ! _get_root
"$fulldomain"; then
78 _debug _domain
"$_domain"
80 if ! rm_record
"$_domain" "$fulldomain"; then
93 if ! _pdns_rest
"PATCH" "/api/v1/servers/$PDNS_ServerId/zones/$root" "{\"rrsets\": [{\"changetype\": \"REPLACE\", \"name\": \"$full.\", \"type\": \"TXT\", \"ttl\": $PDNS_Ttl, \"records\": [{\"name\": \"$full.\", \"type\": \"TXT\", \"content\": \"\\\"$txtvalue\\\"\", \"disabled\": false, \"ttl\": $PDNS_Ttl}]}]}"; then
94 _err
"Set txt record error."
98 if ! notify_slaves
"$root"; then
106 _info
"Remove record"
110 if ! _pdns_rest
"PATCH" "/api/v1/servers/$PDNS_ServerId/zones/$root" "{\"rrsets\": [{\"changetype\": \"DELETE\", \"name\": \"$full.\", \"type\": \"TXT\"}]}"; then
111 _err
"Delete txt record error."
115 if ! notify_slaves
"$root"; then
125 if ! _pdns_rest
"PUT" "/api/v1/servers/$PDNS_ServerId/zones/$root/notify"; then
126 _err
"Notify slaves error."
133 #################### Private functions below ##################################
134 #_acme-challenge.www.domain.com
141 if _pdns_rest
"GET" "/api/v1/servers/$PDNS_ServerId/zones"; then
142 _zones_response
="$response"
146 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
148 if _contains
"$_zones_response" "\"name\": \"$h.\""; then
161 _debug
"$domain not found"
171 export _H1
="X-API-Key: $PDNS_Token"
173 if [ ! "$method" = "GET" ]; then
175 response
="$(_post "$data" "$PDNS_Url$ep" "" "$method")"
177 response
="$(_get "$PDNS_Url$ep")"
180 if [ "$?" != "0" ]; then
184 _debug2 response
"$response"