mirror of
https://github.com/skoelle/dyndns-updater.git
synced 2026-09-17 16:10:25 +00:00
Add SPEC, PLAN, Dockerfile, compose, env example, app modules, CI workflow
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
|
||||
logging.basicConfig(
|
||||
level=os.environ.get("LOG_LEVEL", "INFO"),
|
||||
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
||||
)
|
||||
|
||||
log = logging.getLogger("config")
|
||||
|
||||
REQUIRED_VARS = [
|
||||
"FRITZBOX_HOST",
|
||||
"FRITZBOX_USER",
|
||||
"FRITZBOX_PASSWORD",
|
||||
"CLOUDFLARE_API_TOKEN",
|
||||
"CLOUDFLARE_ZONE_ID",
|
||||
"CLOUDFLARE_RECORDS",
|
||||
]
|
||||
|
||||
|
||||
class Config:
|
||||
def __init__(self):
|
||||
self.fritzbox_host = os.environ.get("FRITZBOX_HOST", "192.168.178.1")
|
||||
self.fritzbox_port = int(os.environ.get("FRITZBOX_PORT", "49000"))
|
||||
self.fritzbox_user = os.environ.get("FRITZBOX_USER")
|
||||
self.fritzbox_password = os.environ.get("FRITZBOX_PASSWORD")
|
||||
|
||||
self.cloudflare_api_token = os.environ.get("CLOUDFLARE_API_TOKEN")
|
||||
self.cloudflare_zone_id = os.environ.get("CLOUDFLARE_ZONE_ID")
|
||||
records_raw = os.environ.get("CLOUDFLARE_RECORDS", "")
|
||||
self.cloudflare_records = [r.strip() for r in records_raw.split(",") if r.strip()]
|
||||
|
||||
self.freedns_update_url = os.environ.get("FREEDNS_UPDATE_URL", "")
|
||||
|
||||
self.webhook_port = int(os.environ.get("WEBHOOK_PORT", "8090"))
|
||||
self.poll_interval_minutes = int(os.environ.get("POLL_INTERVAL_MINUTES", "15"))
|
||||
|
||||
self.healthcheck_ping_url = os.environ.get("HEALTHCHECK_PING_URL", "")
|
||||
|
||||
self.state_path = os.environ.get("STATE_PATH", "/data/last-known-ip.json")
|
||||
|
||||
def validate(self):
|
||||
missing = [v for v in REQUIRED_VARS if not os.environ.get(v)]
|
||||
if missing:
|
||||
log.error("Fehlende Pflicht-ENV-Variablen: %s", ", ".join(missing))
|
||||
sys.exit(1)
|
||||
if not self.cloudflare_records:
|
||||
log.error("CLOUDFLARE_RECORDS ist leer - mindestens eine Subdomain angeben.")
|
||||
sys.exit(1)
|
||||
log.info(
|
||||
"Konfiguration geladen: %d Cloudflare-Record(s), Poll-Intervall=%d Min, Webhook-Port=%d",
|
||||
len(self.cloudflare_records),
|
||||
self.poll_interval_minutes,
|
||||
self.webhook_port,
|
||||
)
|
||||
|
||||
|
||||
config = Config()
|
||||
Reference in New Issue
Block a user