From b274c9878501033c8a1673737843ac79970bf69c Mon Sep 17 00:00:00 2001 From: Jakub Filo Date: Tue, 6 Jun 2023 19:53:17 +0000 Subject: [PATCH] Trying to allow nsd usage with zonesdir and multiple domains for same cert --- dnsapi/dns_nsd.sh | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/dnsapi/dns_nsd.sh b/dnsapi/dns_nsd.sh index 0d29a485..bae61e48 100644 --- a/dnsapi/dns_nsd.sh +++ b/dnsapi/dns_nsd.sh @@ -1,7 +1,8 @@ -#!/usr/bin/env sh +#!/bin/bash #Nsd_ZoneFile="/etc/nsd/zones/example.com.zone" #Nsd_Command="sudo nsd-control reload" +#Nsd_ZonesDir="/etc/nsd/zones" # args: fulldomain txtvalue dns_nsd_add() { @@ -11,8 +12,14 @@ dns_nsd_add() { Nsd_ZoneFile="${Nsd_ZoneFile:-$(_readdomainconf Nsd_ZoneFile)}" Nsd_Command="${Nsd_Command:-$(_readdomainconf Nsd_Command)}" + Nsd_ZonesDir="${Nsd_ZonesDir:-$(_readdomainconf Nsd_ZonesDir)}" + # Arg checks + if [ -n "$Nsd_ZonesDir" ]; then + Nsd_ZoneFile="$Nsd_ZonesDir/$fulldomain.zone" + fi + if [ -z "$Nsd_ZoneFile" ] || [ -z "$Nsd_Command" ]; then Nsd_ZoneFile="" Nsd_Command="" @@ -27,8 +34,16 @@ dns_nsd_add() { return 1 fi - _savedomainconf Nsd_ZoneFile "$Nsd_ZoneFile" - _savedomainconf Nsd_Command "$Nsd_Command" + if [ -n "$Nsd_ZonesDir" ]; then + Nsd_ZoneFile="$Nsd_ZonesDir/$fulldomain.zone" + _cleardomainconf Nsd_ZoneFile + _savedomainconf Nsd_Command "$Nsd_Command" + _savedomainconf Nsd_ZonesDir "$Nsd_ZonesDir" + else + _cleardomainconf Nsd_ZonesDir + _savedomainconf Nsd_ZoneFile "$Nsd_ZoneFile" + _savedomainconf Nsd_Command "$Nsd_Command" + fi echo "$fulldomain. $ttlvalue IN TXT \"$txtvalue\"" >>"$Nsd_ZoneFile" _info "Added TXT record for $fulldomain" @@ -50,8 +65,9 @@ dns_nsd_rm() { Nsd_ZoneFile="${Nsd_ZoneFile:-$(_readdomainconf Nsd_ZoneFile)}" Nsd_Command="${Nsd_Command:-$(_readdomainconf Nsd_Command)}" + Nsd_ZonesDir="${Nsd_ZonesDir:-$(_readdomainconf Nsd_ZonesDir)}" - _sed_i "/$fulldomain. $ttlvalue IN TXT \"$txtvalue\"/d" "$Nsd_ZoneFile" + sed -i "/$fulldomain. $ttlvalue IN TXT \"$txtvalue\"/d" "$Nsd_ZoneFile" _info "Removed TXT record for $fulldomain" _debug "Running $Nsd_Command" if eval "$Nsd_Command"; then