Changed to using absolute-paths and path-vars

master
Ruakij 3 years ago
parent b7cf8f185a
commit 238bd37d40

@ -4,6 +4,10 @@ import shutil, os, re, _thread, socket, sys, re, yaml, logging as log
import dnslib as dns import dnslib as dns
DATA_PATH="/data"
APP_PATH="/app"
HOSTS_PATH="/app/hosts"
config = None config = None
def main(args): def main(args):
setupLogging(True) setupLogging(True)
@ -11,23 +15,26 @@ def main(args):
setupEnvironment() setupEnvironment()
global config global config
config = readConfig("/data/config.yml") config = readConfig(os.path.join(DATA_PATH, "config.yml"))
s = setupSocket(config['socket']['address'], config['socket']['port']) s = setupSocket(config['socket']['address'], config['socket']['port'])
startListen(s) startListen(s)
def setupEnvironment(): def setupEnvironment():
if not os.path.exists('/data'): if not os.path.exists(DATA_PATH):
os.mkdir("/data") os.mkdir(DATA_PATH)
(all, some) = copyAllFiles("data/", "/data") (all, some) = copyAllFiles(f"{APP_PATH}/data/", DATA_PATH)
if all: if all:
log.warning("Configuration-files were created!") log.warning("Configuration-files were created!")
log.warning(" Make sure to change them according to your setup") log.warning(" Make sure to change them according to your setup")
elif some: elif some:
log.warning("Some configuration-files were recreated, because they were missing") log.warning("Some configuration-files were recreated, because they were missing")
if not os.path.exists(HOSTS_PATH):
os.mkdir(HOSTS_PATH)
def copyAllFiles(src, dst, overwrite=False): def copyAllFiles(src, dst, overwrite=False):
all=True all=True
some=False some=False
@ -176,7 +183,7 @@ def adaptZoneName(zone):
def dumpZoneData(zone, dumpFile): def dumpZoneData(zone, dumpFile):
log.debug(f"{zone} |\tDumping to '{dumpFile}'..") log.debug(f"{zone} |\tDumping to '{dumpFile}'..")
return os.system(f"dnscontrol get-zones --creds /data/creds.json --format=js --out={dumpFile} powerdns POWERDNS {zone}") return os.system(f"dnscontrol get-zones --creds {DATA_PATH}/creds.json --format=js --out={HOSTS_PATH}/{dumpFile} powerdns POWERDNS {zone}")
def deleteFile(file): def deleteFile(file):
log.debug(f"Deleting file '{file}'") log.debug(f"Deleting file '{file}'")
@ -197,7 +204,7 @@ def adaptFileForRequire(zone, dumpFile):
def dnscontrolPush(zone): def dnscontrolPush(zone):
log.debug(f'{zone} |\tPushing..') log.debug(f'{zone} |\tPushing..')
return os.system(f"dnscontrol push --config /data/dnsconfig.js --creds /data/creds.json --domains {zone}") return os.system(f"dnscontrol push --config {DATA_PATH}/dnsconfig.js --creds {DATA_PATH}/creds.json --domains {zone}")
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(main(sys.argv)) sys.exit(main(sys.argv))

Loading…
Cancel
Save