Development
This commit is contained in:
parent
44ae8f0fe8
commit
ceb8082e0c
2 changed files with 25 additions and 9 deletions
|
|
@ -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'
|
log_path = f'{CONFIGS_DIR}/ddns.log'
|
||||||
try:
|
try:
|
||||||
with open(log_path) as f:
|
with open(log_path) as f:
|
||||||
lines = f.readlines()
|
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:
|
except FileNotFoundError:
|
||||||
return '(log file not found)'
|
return '(log file not found)', ''
|
||||||
except Exception:
|
except Exception:
|
||||||
return '(error reading log)'
|
return '(error reading log)', ''
|
||||||
|
|
||||||
def _fmt_seconds(secs):
|
def _fmt_seconds(secs):
|
||||||
secs = int(secs)
|
secs = int(secs)
|
||||||
|
|
@ -696,7 +708,7 @@ def collect_tokens():
|
||||||
tokens['STAT_PUBLIC_IP'] = ip_str
|
tokens['STAT_PUBLIC_IP'] = ip_str
|
||||||
tokens['STAT_DDNS_HOSTNAME'] = sub_str
|
tokens['STAT_DDNS_HOSTNAME'] = sub_str
|
||||||
tokens['STAT_DDNS_NEXT_INTERVAL'] = next_interval
|
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_UPTIME'] = _run('uptime -p') or '-'
|
||||||
tokens['STAT_NFTABLES_STATUS'] = 'Active' if _run('nft list tables 2>/dev/null').strip() else 'Inactive'
|
tokens['STAT_NFTABLES_STATUS'] = 'Active' if _run('nft list tables 2>/dev/null').strip() else 'Inactive'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -456,6 +456,14 @@
|
||||||
"label": "DDNS Log",
|
"label": "DDNS Log",
|
||||||
"client_requirement": "client_is_administrator+",
|
"client_requirement": "client_is_administrator+",
|
||||||
"items": [
|
"items": [
|
||||||
|
{
|
||||||
|
"type": "pre_block",
|
||||||
|
"text": "%DDNS_LOG_TAIL%"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "raw_html",
|
||||||
|
"html": "%DDNS_LOG_SUMMARY%"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "button_row",
|
"type": "button_row",
|
||||||
"items": [
|
"items": [
|
||||||
|
|
@ -466,10 +474,6 @@
|
||||||
"text": "Clear Log"
|
"text": "Clear Log"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "pre_block",
|
|
||||||
"text": "%DDNS_LOG_TAIL%"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue