From 5674bf339cd0d988e9ac53f739dffba07c07e2e4 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 2 Aug 2021 19:08:33 +0200 Subject: [PATCH] Added path-vars --- daemon.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/daemon.py b/daemon.py index ac1b5e2..0487488 100755 --- a/daemon.py +++ b/daemon.py @@ -163,7 +163,7 @@ def updateNsData(zone): hasToDelete = True - adaptFileForRequire(zone, dumpFile) + adaptFileForRequire(zone, HOSTS_PATH, dumpFile) if dnscontrolPush(zone) != 0: raise Exception("Pushing data failed!") @@ -173,7 +173,7 @@ def updateNsData(zone): log.warning(f'{adaptedZone} |\tUpdating NS-Data failed!') if(hasToDelete): - deleteFile(dumpFile) + deleteFile(os.path.join(HOSTS_PATH, dumpFile)) def adaptZoneName(zone): if config['zone']['public-suffix'] != "" and zone.endswith(config['zone']['public-suffix']): @@ -190,17 +190,19 @@ def deleteFile(file): os.remove(file) ignoreLinesRexp = r"^\s*(var|D\(|DnsProvider\(|DefaultTTL\()" -def adaptFileForRequire(zone, dumpFile): +def adaptFileForRequire(zone, path, dumpFile): log.debug(f"{zone} |\tRewriting file '{dumpFile}'..") - with open(f"{HOSTS_PATH}/{dumpFile}", 'r') as fin: - with open(f"{HOSTS_PATH}/{dumpFile}.tmp", 'w+') as fout: + dumpFilePath = os.path.join(path, dumpFile) + + with open(dumpFilePath, 'r') as fin: + with open(f"{dumpFilePath}.tmp", 'w+') as fout: fout.write(f'D_EXTEND("{zone}",\n') for line in fin: if not re.match(ignoreLinesRexp, line): fout.write(line) - os.replace(f"{HOSTS_PATH}/{dumpFile}.tmp", dumpFile) + os.replace(f"{dumpFilePath}.tmp", dumpFilePath) def dnscontrolPush(zone): log.debug(f'{zone} |\tPushing..')