Skip to content

Commit bfe85b0

Browse files
committed
Add interface to show/edit SOA-EDIT
Closes #7
1 parent 9e5ed20 commit bfe85b0

File tree

2 files changed

+67
-7
lines changed

2 files changed

+67
-7
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
A simple DNS hook that lets [Dehydrated][] talk to the PowerDNS API.
33

44
# Usage
5+
## Configuration
56
Add the settings for your PowerDNS API to Dehydrated's `config`
67
(in `/etc/dehydrated` or `/usr/local/etc/dehydrated`),
78
or a `config` file next to `pdns_api.sh`:
@@ -38,4 +39,15 @@ test.domain.tld
3839

3940
These zones can be added in any order.
4041

42+
## Incrementing the zone's serial
43+
PowerDNS can automatically increment the serial in the SOA record with the [SOA-EDIT][] metadata entry.
44+
`pdns_api.sh` can show and edit this entry.
45+
Usage:
46+
47+
```sh
48+
pdns_api.sh soa_edit <zone> [soa-edit] [soa-edit-api]
49+
```
50+
51+
4152
[dehydrated]: https://github.com/lukas2511/dehydrated
53+
[SOA-EDIT]: https://rtfm.powerdns.com/md/authoritative/dnssec/#soa-edit-ensure-signature-freshness-on-slaves

pdns_api.sh

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,18 +254,53 @@ clean_rrset() {
254254
echo '{"name":"'"${name}"'","type":"TXT","changetype":"DELETE"}'
255255
}
256256

257-
main() {
258-
# Main setup
259-
load_config
260-
load_zones
261-
setup
262-
declare -A requests
257+
soa_edit() {
258+
# Show help
259+
if [[ $# -eq 0 ]]; then
260+
echo "Usage: pdns_api.sh soa_edit <zone> [SOA-EDIT] [SOA-EDIT-API]"
261+
exit 1
262+
fi
263+
264+
# Get current values for zone
265+
request "GET" "${url}/$1" ""
266+
267+
# Set variables
268+
if [[ $# -le 1 ]]; then
269+
soa_edit=$(<<< "${res}" get_json_string_value soa_edit)
270+
soa_edit_api=$(<<< "${res}" get_json_string_value soa_edit_api)
271+
272+
echo "Current values:"
273+
else
274+
soa_edit="$2"
275+
if [[ $# -eq 3 ]]; then
276+
soa_edit_api="$3"
277+
else
278+
soa_edit_api="$2"
279+
fi
280+
281+
echo "Setting:"
282+
fi
283+
284+
# Display values
285+
echo "SOA-EDIT: ${soa_edit}"
286+
echo "SOA-EDIT-API: ${soa_edit_api}"
287+
288+
# Update values
289+
if [[ $# -eq 2 ]]; then
290+
request "PUT" "${url}/${1}" '{
291+
"soa_edit":"'"${soa_edit}"'",
292+
"soa_edit_api":"'"${soa_edit_api}"'",
293+
"kind":"'"$(<<< "${res}" get_json_string_value kind)"'"
294+
}'
295+
fi
296+
}
263297

298+
main() {
264299
# Set hook
265300
hook="$1"
266301

267302
# Debug output
268-
debug "Hook: ${hook}"
303+
debug "Hook: ${hook}"
269304

270305
# Deployment of a certificate
271306
if [[ "${hook}" = "deploy_cert" ]]; then
@@ -277,6 +312,19 @@ main() {
277312
exit 0
278313
fi
279314

315+
# Main setup
316+
load_config
317+
load_zones
318+
setup
319+
declare -A requests
320+
321+
# Interface for SOA-EDIT
322+
if [[ "${hook}" = "soa_edit" ]]; then
323+
shift
324+
soa_edit $@
325+
exit 0
326+
fi
327+
280328
# Loop through arguments per 3
281329
for ((i=2; i<=$#; i=i+3)); do
282330
# Setup for this domain

0 commit comments

Comments
 (0)