diff --git a/.gitignore b/.gitignore index 3c36401..67403c5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,15 +2,8 @@ *.pem *.swp __pycache__/ -conf/config.json -conf/wholist.json -conf/counters.json -conf/tokens.json -conf/network.dat -conf/alias.json -conf/irc.json -conf/dist.sh -conf/blacklist.json +conf/live/ +conf/cert/ env/ .idea/ .env diff --git a/conf/example/alias.json b/conf/example/alias.json deleted file mode 100644 index 0967ef4..0000000 --- a/conf/example/alias.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/conf/example/blacklist.json b/conf/example/blacklist.json deleted file mode 100644 index 0967ef4..0000000 --- a/conf/example/blacklist.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/conf/example/counters.json b/conf/example/counters.json deleted file mode 100644 index 0967ef4..0000000 --- a/conf/example/counters.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/conf/example/tokens.json b/conf/example/tokens.json deleted file mode 100644 index 0967ef4..0000000 --- a/conf/example/tokens.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/conf/aliasdata.json b/conf/templates/aliasdata.json similarity index 100% rename from conf/aliasdata.json rename to conf/templates/aliasdata.json diff --git a/conf/example/config.json b/conf/templates/config.json similarity index 100% rename from conf/example/config.json rename to conf/templates/config.json diff --git a/conf/help.json b/conf/templates/help.json similarity index 100% rename from conf/help.json rename to conf/templates/help.json diff --git a/conf/example/irc.json b/conf/templates/irc.json similarity index 100% rename from conf/example/irc.json rename to conf/templates/irc.json diff --git a/docker-compose.yml b/docker-compose.yml index b7df7de..fb036b6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,9 @@ services: build: ./docker volumes: - ${PORTAINER_GIT_DIR}:/code + - ${THRESHOLD_CONFIG_DIR}:/code/conf/live + - ${THRESHOLD_TEMPLATE_DIR}:/code/conf/templates + - ${THRESHOLD_CERT_DIR}:/code/conf/cert ports: - "${THRESHOLD_LISTENER_PORT}:${THRESHOLD_LISTENER_PORT}" - "${THRESHOLD_RELAY_PORT}:${THRESHOLD_RELAY_PORT}" diff --git a/docker/docker-compose.prod.yml b/docker/docker-compose.prod.yml index c4f91c1..7ac7813 100644 --- a/docker/docker-compose.prod.yml +++ b/docker/docker-compose.prod.yml @@ -6,6 +6,9 @@ services: build: ./docker volumes: - ${PORTAINER_GIT_DIR}:/code + - ${THRESHOLD_CONFIG_DIR}:/code/conf/live + - ${THRESHOLD_TEMPLATE_DIR}:/code/conf/templates + - ${THRESHOLD_CERT_DIR}:/code/conf/cert ports: - "${THRESHOLD_LISTENER_PORT}:${THRESHOLD_LISTENER_PORT}" - "${THRESHOLD_RELAY_PORT}:${THRESHOLD_RELAY_PORT}" diff --git a/main.py b/main.py index 972a897..4e16522 100644 --- a/main.py +++ b/main.py @@ -5,13 +5,14 @@ from os.path import exists from string import digits from redis import StrictRedis +from os import getenv # List of errors ZNC can give us ZNCErrors = ["Error:", "Unable to load", "does not exist", "doesn't exist"] -configPath = "conf/" -exampleConfigPath = "conf/example/" -certPath = "cert/" +configPath = getenv("THRESHOLD_CONFIG_DIR", "conf/live/") +templateConfigPath = getenv("THRESHOLD_TEMPLATE_DIR", "conf/templates/") +certPath = getenv("THRESHOLD_CERT_DIR", "conf/cert/") filemap = { # JSON configs @@ -70,6 +71,8 @@ def liveNets(): def saveConf(var): + if var in ("help", "aliasdata"): + return # no need to save this if filemap[var][2] == "json": with open(configPath + filemap[var][0], "w") as f: json.dump(globals()[var], f, indent=4) @@ -83,21 +86,26 @@ def saveConf(var): def loadConf(var): if filemap[var][2] == "json": filename = configPath + filemap[var][0] + # Only take the help from the templates + if var in ("help", "aliasdata"): + filename = templateConfigPath + filemap[var][0] if not exists(filename): + # Load the template config if var == "config": - filename = exampleConfigPath + filemap[var][0] + filename = templateConfigPath + filemap[var][0] else: + # Everything else should be blank globals()[var] = {} return with open(filename, "r") as f: globals()[var] = json.load(f) - return if var == "alias": # This is a workaround to convert all the keys into integers since JSON # turns them into strings... # Dammit Jason! global alias alias = {int(x): y for x, y in alias.items()} + elif filemap[var][2] == "pickle": try: with open(configPath + filemap[var][0], "rb") as f: