From a6d11796da0f3a323b99e9b2ac65e42e431ba1a3 Mon Sep 17 00:00:00 2001 From: Awal Garg Date: Mon, 19 Mar 2018 02:00:41 +0530 Subject: [PATCH] Add dns_maradns.sh MaraDNS is a lightweight self-hosting DNS server. This patch adds support for adding records to zone files stored on the server in the format expected by MaraDNS. Path to the file should be exported in MARA_ZONE_FILE environment variable. To reload the configuration automatically, the user must provide pid of duende (the daemonization tool that ships with MaraDNS) in MARA_DUENDE_PID or path to the pid file (--pid argument to duende) in MARA_DUENDE_PID_PATH. --- dnsapi/dns_maradns.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 dnsapi/dns_maradns.sh diff --git a/dnsapi/dns_maradns.sh b/dnsapi/dns_maradns.sh new file mode 100755 index 00000000..17665dba --- /dev/null +++ b/dnsapi/dns_maradns.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env sh + +dns_maradns_add() { + _checkZoneFile || return 1 + fulldomain="$1" + txtvalue="$2" + printf "%s. TXT '%s' ~\n" "$fulldomain" "$txtvalue" | tee -a "$MARA_ZONE_FILE" || return 1 + _try_reload_maradns +} + +dns_maradns_rm() { + _checkZoneFile || return 1 + fulldomain="$1" + txtvalue="$2" + sed -i "/^$fulldomain.\+TXT '$txtvalue' ~/d" "$MARA_ZONE_FILE" + _try_reload_maradns +} + +_checkZoneFile() { + if [ -w "$MARA_ZONE_FILE" ]; then + return 0 + fi + _err "MARA_ZONE_FILE not set or not writable" + return 1 +} + +_try_reload_maradns() { + if [ -n "$MARA_DUENDE_PID" ]; then + kill -s HUP -- "$MARA_DUENDE_PID" + return $? + fi + if [ -r "$MARA_DUENDE_PID_PATH" ]; then + kill -s HUP -- "$(cat $MARA_DUENDE_PID_PATH)" + return $? + fi + _info "Reload MaraDNS manually (or provide MARA_DUENDE_PID or MARA_DUENDE_PID_PATH)" +}