introduce core config file (settings that cannot be edited from the web)
This commit is contained in:
parent
54fb58755d
commit
3226c01f60
1
debian/openwebrx.install
vendored
1
debian/openwebrx.install
vendored
@ -1,5 +1,6 @@
|
|||||||
config_webrx.py etc/openwebrx/
|
config_webrx.py etc/openwebrx/
|
||||||
bands.json etc/openwebrx/
|
bands.json etc/openwebrx/
|
||||||
bookmarks.json etc/openwebrx/
|
bookmarks.json etc/openwebrx/
|
||||||
|
openwebrx.conf etc/openwebrx/
|
||||||
users.json etc/openwebrx/
|
users.json etc/openwebrx/
|
||||||
systemd/openwebrx.service lib/systemd/system/
|
systemd/openwebrx.service lib/systemd/system/
|
@ -15,6 +15,9 @@ fi
|
|||||||
if [[ ! -f /etc/openwebrx/users.json ]] ; then
|
if [[ ! -f /etc/openwebrx/users.json ]] ; then
|
||||||
cp users.json /etc/openwebrx/
|
cp users.json /etc/openwebrx/
|
||||||
fi
|
fi
|
||||||
|
if [[ ! -f /etc/openwebrx/openwebrx.conf ]] ; then
|
||||||
|
cp openwebrx.conf /etc/openwebrx/
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
_term() {
|
_term() {
|
||||||
|
5
openwebrx.conf
Normal file
5
openwebrx.conf
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
[core]
|
||||||
|
data_directory = /var/lib/openwebrx
|
||||||
|
|
||||||
|
[web]
|
||||||
|
port = 8073
|
@ -1,6 +1,6 @@
|
|||||||
from http.server import HTTPServer
|
from http.server import HTTPServer
|
||||||
from owrx.http import RequestHandler
|
from owrx.http import RequestHandler
|
||||||
from owrx.config import Config
|
from owrx.config import Config, CoreConfig
|
||||||
from owrx.feature import FeatureDetector
|
from owrx.feature import FeatureDetector
|
||||||
from owrx.sdr import SdrService
|
from owrx.sdr import SdrService
|
||||||
from socketserver import ThreadingMixIn
|
from socketserver import ThreadingMixIn
|
||||||
@ -73,7 +73,7 @@ Support and info: https://groups.io/g/openwebrx
|
|||||||
Services.start()
|
Services.start()
|
||||||
|
|
||||||
try:
|
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()
|
server.serve_forever()
|
||||||
except SignalException:
|
except SignalException:
|
||||||
WebSocketConnection.closeAll()
|
WebSocketConnection.closeAll()
|
||||||
|
@ -4,6 +4,7 @@ import os
|
|||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
from configparser import ConfigParser
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -56,6 +57,31 @@ class ConfigMigratorVersion2(ConfigMigrator):
|
|||||||
return config
|
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:
|
class Config:
|
||||||
sharedConfig = None
|
sharedConfig = None
|
||||||
currentVersion = 3
|
currentVersion = 3
|
||||||
@ -84,9 +110,14 @@ class Config:
|
|||||||
pm[k] = v
|
pm[k] = v
|
||||||
return pm
|
return pm
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _getSettingsFile():
|
||||||
|
coreConfig = CoreConfig()
|
||||||
|
return "{data_directory}/settings.json".format(data_directory=coreConfig.get_data_directory())
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _loadConfig():
|
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:
|
try:
|
||||||
if file.endswith(".py"):
|
if file.endswith(".py"):
|
||||||
return Config._loadPythonFile(file)
|
return Config._loadPythonFile(file)
|
||||||
@ -106,7 +137,7 @@ class Config:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def store():
|
def store():
|
||||||
with open("settings.json", "w") as file:
|
with open(Config._getSettingsFile(), "w") as file:
|
||||||
json.dump(Config.get().__dict__(), file, indent=4)
|
json.dump(Config.get().__dict__(), file, indent=4)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
Loading…
Reference in New Issue
Block a user