Development
This commit is contained in:
parent
465cb9eb0c
commit
01a463bee8
1 changed files with 8 additions and 31 deletions
|
|
@ -526,40 +526,17 @@ def _read_cached_ip():
|
|||
|
||||
def _public_ip_info(ddns_cfg):
|
||||
"""Return (ip_str, domains_sub, next_interval_str, last_obtained_str) for stat cards."""
|
||||
script = f'{CONFIGS_DIR}/ddns.py'
|
||||
enabled_p = [p for p in ddns_cfg.get('providers', []) if p.get('enabled', True)]
|
||||
all_hosts = []
|
||||
for p in enabled_p:
|
||||
all_hosts.extend(p.get('hostnames', p.get('subdomains', [])))
|
||||
domains_sub = ', '.join(all_hosts)
|
||||
interval_secs = _parse_interval_to_seconds(ddns_cfg.get('general', {}).get('timer_interval', ''))
|
||||
next_interval = '-'
|
||||
|
||||
def _last_obtained(mtime):
|
||||
return f'Obtained: {_relative_time(mtime)}' if mtime else ''
|
||||
|
||||
# Path 1: timer healthy and within interval -> use cached IP
|
||||
if interval_secs and enabled_p:
|
||||
status = _run(f'python3 {script} --status 2>/dev/null')
|
||||
if status:
|
||||
is_enabled = '; enabled' in status
|
||||
is_active = 'active (waiting)' in status or 'active (running)' in status
|
||||
remaining = _parse_time_remaining(status)
|
||||
if remaining is not None:
|
||||
next_interval = _fmt_seconds(remaining)
|
||||
if is_enabled and is_active and remaining is not None and remaining < interval_secs:
|
||||
ip, mtime = _read_cached_ip()
|
||||
last_obtained = f'Obtained: {_relative_time(mtime)}' if mtime else ''
|
||||
if ip:
|
||||
return ip, domains_sub, next_interval, _last_obtained(mtime)
|
||||
|
||||
# Path 2: live fetch
|
||||
ip = _run(f'python3 {script} --getip 2>/dev/null')
|
||||
if ip and re.match(r'^\d{1,3}(\.\d{1,3}){3}$', ip):
|
||||
_, mtime = _read_cached_ip()
|
||||
return ip, domains_sub, next_interval, _last_obtained(mtime)
|
||||
|
||||
# Path 3: offline
|
||||
return 'DDNS Offline', domains_sub, next_interval, ''
|
||||
return ip, domains_sub, '-', last_obtained
|
||||
return 'Offline', domains_sub, '-', ''
|
||||
|
||||
def _ddns_last_checked():
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue