From 8ab85c002ef763c0e66bf5c8f59ec83bfeb45713 Mon Sep 17 00:00:00 2001 From: Nik Rozman Date: Sat, 3 Jan 2026 10:32:02 +0100 Subject: [PATCH] Add last ip override --- cloudflare_dyndns.py | 8 ++++++-- config.example.ini | 2 ++ docker-compose.yml | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cloudflare_dyndns.py b/cloudflare_dyndns.py index 28da70f..ee7f790 100644 --- a/cloudflare_dyndns.py +++ b/cloudflare_dyndns.py @@ -14,7 +14,7 @@ Config (config.ini by default): poll_seconds = 3600 ; optional Environment overrides (take precedence over config file): - CLOUDFLARE_API_TOKEN, CLOUDFLARE_ZONE_ID, IPINFO_URL, POLL_SECONDS, CONFIG_PATH + CLOUDFLARE_API_TOKEN, CLOUDFLARE_ZONE_ID, IPINFO_URL, POLL_SECONDS, CONFIG_PATH, LAST_IP_OVERRIDE Install dependency: pip install requests @@ -52,6 +52,7 @@ def load_config(path: str) -> dict: "zone_id": get_opt("cloudflare", "zone_id"), "ipinfo_url": get_opt("service", "ipinfo_url"), "poll_seconds": None, + "last_ip_override": get_opt("service", "last_ip_override"), } poll_raw = get_opt("service", "poll_seconds") @@ -135,12 +136,15 @@ def main() -> None: ipinfo_url = os.getenv("IPINFO_URL") or config.get("ipinfo_url") or IPINFO_DEFAULT poll_seconds = os.getenv("POLL_SECONDS") poll_seconds = int(poll_seconds) if poll_seconds else config.get("poll_seconds", DEFAULT_POLL_SECONDS) + last_ip_override = os.getenv("LAST_IP_OVERRIDE") or config.get("last_ip_override") session = requests.Session() - last_ip: Optional[str] = None + last_ip: Optional[str] = last_ip_override print(f"Starting Cloudflare DDNS watcher (interval={poll_seconds}s)") print(f"Using IP endpoint: {ipinfo_url}") + if last_ip_override: + print(f"Starting with overridden last_ip: {last_ip_override}") try: while True: diff --git a/config.example.ini b/config.example.ini index c94d551..5a4111b 100644 --- a/config.example.ini +++ b/config.example.ini @@ -5,3 +5,5 @@ zone_id = YOUR_ZONE_ID [service] ipinfo_url = https://ipinfo.io/ip poll_seconds = 3600 +; Optionally seed last_ip to force an update on first run +; last_ip_override = 203.0.113.10 diff --git a/docker-compose.yml b/docker-compose.yml index 7bb366b..99478ff 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,3 +1,5 @@ +version: "3.9" + services: cloudflare-dyndns: image: python:3.11-slim @@ -8,6 +10,7 @@ services: - ./config.ini:/app/config.ini:ro environment: - CONFIG_PATH=/app/config.ini + - PYTHONUNBUFFERED=1 command: > - sh -c "pip install --no-cache-dir requests && python cloudflare_dyndns.py" + sh -c "pip install --no-cache-dir requests && python -u cloudflare_dyndns.py" restart: unless-stopped