Add last ip override
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user