Development

This commit is contained in:
Matthew Grotke 2026-05-23 16:47:19 -04:00
parent 44ae8f0fe8
commit ceb8082e0c
2 changed files with 25 additions and 9 deletions

View file

@ -460,16 +460,28 @@ def _blocklist_stats_html(core):
)
def _ddns_log_tail(n=50):
DDNS_LOG_MAX = 50
def _ddns_log_tail():
log_path = f'{CONFIGS_DIR}/ddns.log'
try:
with open(log_path) as f:
lines = f.readlines()
return ''.join(lines[-n:]).strip() or '(log is empty)'
if not lines:
return '(log is empty)', ''
total = len(lines)
tail = lines[-DDNS_LOG_MAX:]
shown = len(tail)
hidden = total - shown
if hidden > 0:
summary = f'Showing last {shown} lines ({hidden} lines not shown)'
else:
summary = f'Showing {shown} lines'
return ''.join(tail).strip(), f'<p class="text-muted" style="margin-top:0.5em;">{summary}</p>'
except FileNotFoundError:
return '(log file not found)'
return '(log file not found)', ''
except Exception:
return '(error reading log)'
return '(error reading log)', ''
def _fmt_seconds(secs):
secs = int(secs)
@ -696,7 +708,7 @@ def collect_tokens():
tokens['STAT_PUBLIC_IP'] = ip_str
tokens['STAT_DDNS_HOSTNAME'] = sub_str
tokens['STAT_DDNS_NEXT_INTERVAL'] = next_interval
tokens['DDNS_LOG_TAIL'] = _ddns_log_tail()
tokens['DDNS_LOG_TAIL'], tokens['DDNS_LOG_SUMMARY'] = _ddns_log_tail()
tokens['STAT_UPTIME'] = _run('uptime -p') or '-'
tokens['STAT_NFTABLES_STATUS'] = 'Active' if _run('nft list tables 2>/dev/null').strip() else 'Inactive'

View file

@ -456,6 +456,14 @@
"label": "DDNS Log",
"client_requirement": "client_is_administrator+",
"items": [
{
"type": "pre_block",
"text": "%DDNS_LOG_TAIL%"
},
{
"type": "raw_html",
"html": "%DDNS_LOG_SUMMARY%"
},
{
"type": "button_row",
"items": [
@ -466,10 +474,6 @@
"text": "Clear Log"
}
]
},
{
"type": "pre_block",
"text": "%DDNS_LOG_TAIL%"
}
]
}