diff --git a/debian/openwebrx.install b/debian/openwebrx.install index 84b1f9c..99af884 100644 --- a/debian/openwebrx.install +++ b/debian/openwebrx.install @@ -1,5 +1,6 @@ config_webrx.py etc/openwebrx/ bands.json etc/openwebrx/ bookmarks.json etc/openwebrx/ +openwebrx.conf etc/openwebrx/ users.json etc/openwebrx/ systemd/openwebrx.service lib/systemd/system/ \ No newline at end of file diff --git a/docker/scripts/run.sh b/docker/scripts/run.sh index 0f8bd32..a82d8cd 100755 --- a/docker/scripts/run.sh +++ b/docker/scripts/run.sh @@ -15,6 +15,9 @@ fi if [[ ! -f /etc/openwebrx/users.json ]] ; then cp users.json /etc/openwebrx/ fi +if [[ ! -f /etc/openwebrx/openwebrx.conf ]] ; then + cp openwebrx.conf /etc/openwebrx/ +fi _term() { diff --git a/openwebrx.conf b/openwebrx.conf new file mode 100644 index 0000000..072d3e4 --- /dev/null +++ b/openwebrx.conf @@ -0,0 +1,5 @@ +[core] +data_directory = /var/lib/openwebrx + +[web] +port = 8073 diff --git a/owrx/__main__.py b/owrx/__main__.py index 1a39cb1..9512db8 100644 --- a/owrx/__main__.py +++ b/owrx/__main__.py @@ -1,6 +1,6 @@ from http.server import HTTPServer from owrx.http import RequestHandler -from owrx.config import Config +from owrx.config import Config, CoreConfig from owrx.feature import FeatureDetector from owrx.sdr import SdrService from socketserver import ThreadingMixIn @@ -73,7 +73,7 @@ Support and info: https://groups.io/g/openwebrx Services.start() try: - server = ThreadedHttpServer(("0.0.0.0", pm["web_port"]), RequestHandler) + server = ThreadedHttpServer(("0.0.0.0", CoreConfig().get_web_port()), RequestHandler) server.serve_forever() except SignalException: WebSocketConnection.closeAll() diff --git a/owrx/config.py b/owrx/config.py index f668f8e..35f6328 100644 --- a/owrx/config.py +++ b/owrx/config.py @@ -4,6 +4,7 @@ import os import logging import json from abc import ABC, abstractmethod +from configparser import ConfigParser logger = logging.getLogger(__name__) @@ -56,6 +57,31 @@ class ConfigMigratorVersion2(ConfigMigrator): return config +class CoreConfig(object): + defaults = { + "core": { + "data_directory": "/var/lib/openwebrx", + }, + "web": { + "port": 8073, + }, + } + + def __init__(self): + config = ConfigParser() + config.read(["./openwebrx.conf", "/etc/openwebrx/openwebrx.conf"]) + self.data_directory = config.get( + "core", "data_directory", fallback=CoreConfig.defaults["core"]["data_directory"] + ) + self.web_port = config.getint("web", "port", fallback=CoreConfig.defaults["web"]["port"]) + + def get_web_port(self): + return self.web_port + + def get_data_directory(self): + return self.data_directory + + class Config: sharedConfig = None currentVersion = 3 @@ -84,9 +110,14 @@ class Config: pm[k] = v return pm + @staticmethod + def _getSettingsFile(): + coreConfig = CoreConfig() + return "{data_directory}/settings.json".format(data_directory=coreConfig.get_data_directory()) + @staticmethod def _loadConfig(): - for file in ["./settings.json", "/etc/openwebrx/config_webrx.py", "./config_webrx.py"]: + for file in [Config._getSettingsFile(), "/etc/openwebrx/config_webrx.py", "./config_webrx.py"]: try: if file.endswith(".py"): return Config._loadPythonFile(file) @@ -106,7 +137,7 @@ class Config: @staticmethod def store(): - with open("settings.json", "w") as file: + with open(Config._getSettingsFile(), "w") as file: json.dump(Config.get().__dict__(), file, indent=4) @staticmethod