Skip to content

Commit

Permalink
Add interface to show/edit SOA-EDIT
Browse files Browse the repository at this point in the history
Closes #7
  • Loading branch information
silkeh committed May 13, 2017
1 parent 9e5ed20 commit bfe85b0
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 7 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
A simple DNS hook that lets [Dehydrated][] talk to the PowerDNS API.

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

These zones can be added in any order.

## Incrementing the zone's serial
PowerDNS can automatically increment the serial in the SOA record with the [SOA-EDIT][] metadata entry.
`pdns_api.sh` can show and edit this entry.
Usage:

```sh
pdns_api.sh soa_edit <zone> [soa-edit] [soa-edit-api]
```


[dehydrated]: https://github.com/lukas2511/dehydrated
[SOA-EDIT]: https://rtfm.powerdns.com/md/authoritative/dnssec/#soa-edit-ensure-signature-freshness-on-slaves
62 changes: 55 additions & 7 deletions pdns_api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,53 @@ clean_rrset() {
echo '{"name":"'"${name}"'","type":"TXT","changetype":"DELETE"}'
}

main() {
# Main setup
load_config
load_zones
setup
declare -A requests
soa_edit() {
# Show help
if [[ $# -eq 0 ]]; then
echo "Usage: pdns_api.sh soa_edit <zone> [SOA-EDIT] [SOA-EDIT-API]"
exit 1
fi

# Get current values for zone
request "GET" "${url}/$1" ""

# Set variables
if [[ $# -le 1 ]]; then
soa_edit=$(<<< "${res}" get_json_string_value soa_edit)
soa_edit_api=$(<<< "${res}" get_json_string_value soa_edit_api)

echo "Current values:"
else
soa_edit="$2"
if [[ $# -eq 3 ]]; then
soa_edit_api="$3"
else
soa_edit_api="$2"
fi

echo "Setting:"
fi

# Display values
echo "SOA-EDIT: ${soa_edit}"
echo "SOA-EDIT-API: ${soa_edit_api}"

# Update values
if [[ $# -eq 2 ]]; then
request "PUT" "${url}/${1}" '{
"soa_edit":"'"${soa_edit}"'",
"soa_edit_api":"'"${soa_edit_api}"'",
"kind":"'"$(<<< "${res}" get_json_string_value kind)"'"
}'
fi
}

main() {
# Set hook
hook="$1"

# Debug output
debug "Hook: ${hook}"
debug "Hook: ${hook}"

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

# Main setup
load_config
load_zones
setup
declare -A requests

# Interface for SOA-EDIT
if [[ "${hook}" = "soa_edit" ]]; then
shift
soa_edit $@
exit 0
fi

# Loop through arguments per 3
for ((i=2; i<=$#; i=i+3)); do
# Setup for this domain
Expand Down

0 comments on commit bfe85b0

Please sign in to comment.