mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-28 18:22:05 +00:00
66 lines
3.1 KiB
Python
66 lines
3.1 KiB
Python
import importlib
|
|
import logging
|
|
import os
|
|
import sys
|
|
|
|
import yaml
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# Check you have a config file
|
|
if not os.path.isfile("config.yml"):
|
|
logger.error(
|
|
"Your config file is missing. Ensure you have copied config-example.yml to config.yml and updated it according to your needs."
|
|
)
|
|
sys.exit()
|
|
|
|
# Load config
|
|
with open("config.yml") as f:
|
|
config = yaml.safe_load(f)
|
|
logger.info("Loaded config.")
|
|
|
|
BASE_URL = config.get("base_url", "http://localhost:8080")
|
|
MAX_SPOT_AGE = config.get("max_spot_age_sec", 3600)
|
|
MAX_ALERT_AGE = config.get("max_alert_age_sec", 604800)
|
|
SERVER_OWNER_CALLSIGN = config.get("server_owner_callsign", "N0CALL")
|
|
WEB_SERVER_PORT = config.get("web_server_port", 8080)
|
|
TELNET_SERVER_ENABLED = config.get("telnet_server_enabled", False)
|
|
TELNET_SERVER_ADDRESS = config.get("telnet_server_address", "localhost")
|
|
TELNET_SERVER_PORT = config.get("telnet_server_port", 7373)
|
|
ALLOW_SPOTTING = config.get("allow_spotting", True)
|
|
ALLOW_UPSTREAM_SPOTTING = config.get("allow_upstream_spotting", True)
|
|
WEB_UI_OPTIONS = config.get("web_ui_options", {})
|
|
API_ONLY_MODE = config.get("api_only_mode", False)
|
|
API_KEYS = [k for k in (config.get("api_keys") or []) if k]
|
|
RECAPTCHA_SECRET_KEY = config.get("recaptcha_secret_key", "")
|
|
RECAPTCHA_SITE_KEY = config.get("recaptcha_site_key", "")
|
|
# If not explicitly set, protect spot submission if CAPTCHA is configured, as this was the behaviour before the option
|
|
# existed. This avoids silently opening up spot submission on servers that upgrade without updating their config.
|
|
PROTECT_SPOT_SUBMISSION = config.get("protect_spot_submission", bool(RECAPTCHA_SECRET_KEY))
|
|
LOG_LEVEL = config.get("log_level", "INFO")
|
|
LOG_WEB_REQUESTS = config.get("log_web_requests", False)
|
|
|
|
WEB_UI_OPTIONS["qrz_enabled"] = any(p["class"] == "QRZ" and p["enabled"] for p in config["callsign_data_providers"])
|
|
WEB_UI_OPTIONS["hamqth_enabled"] = any(
|
|
p["class"] == "HamQTH" and p["enabled"] for p in config["callsign_data_providers"]
|
|
)
|
|
# The web UI only needs to show a CAPTCHA if spot submission is protected
|
|
WEB_UI_OPTIONS["recaptcha_site_key"] = RECAPTCHA_SITE_KEY if PROTECT_SPOT_SUBMISSION else ""
|
|
WEB_UI_OPTIONS["allow_upstream_spotting"] = ALLOW_SPOTTING and ALLOW_UPSTREAM_SPOTTING
|
|
|
|
|
|
if ALLOW_SPOTTING and PROTECT_SPOT_SUBMISSION and not (RECAPTCHA_SITE_KEY and RECAPTCHA_SECRET_KEY):
|
|
logger.warning(
|
|
"Spot submission is protected but reCAPTCHA keys are not set, so only clients with an API key will be able to submit spots. Users of the web interface will not be able to add spots."
|
|
)
|
|
|
|
|
|
def create_provider_from_config(package, config_providers_entry):
|
|
"""Utility method to get a provider based on the class specified in its config entry. You must also provide the
|
|
package to look for it in, as there are several types of provider. e.g. package "providers.spot", where the config
|
|
entry is for a POTA spot provider."""
|
|
|
|
module = importlib.import_module(f"{package}.{config_providers_entry['class'].lower()}")
|
|
provider_class = getattr(module, config_providers_entry["class"])
|
|
return provider_class(config_providers_entry)
|