Development
This commit is contained in:
parent
4a9110cc4c
commit
094847966a
6 changed files with 197 additions and 57 deletions
|
|
@ -1,9 +1,38 @@
|
|||
import json
|
||||
import os
|
||||
from datetime import datetime, timezone
|
||||
from config_utils import collect_layout_tokens, load_datasource, fmt_bytes, relative_time, BLOCKLISTS_DIR
|
||||
from config_utils import collect_layout_tokens, load_datasource, fmt_bytes, relative_time, BLOCKLISTS_DIR, CONFIGS_DIR
|
||||
from factory import e, load_json, build_table, table_token_key, iter_table_items, PAGES_DIR
|
||||
|
||||
DNS_LOG_FILE = f'{CONFIGS_DIR}/dns-blocklists.log'
|
||||
DNS_LOG_MAX = 50
|
||||
|
||||
|
||||
def _dnsblocking_log_tail(cfg):
|
||||
try:
|
||||
log_max_kb = cfg.get('dns_blocking', {}).get('general', {}).get('log_max_kb', 1024)
|
||||
size_kb = os.path.getsize(DNS_LOG_FILE) / 1024
|
||||
with open(DNS_LOG_FILE) as f:
|
||||
lines = f.readlines()
|
||||
if not lines:
|
||||
return '(log is empty)', ''
|
||||
total = len(lines)
|
||||
tail = lines[-DNS_LOG_MAX:]
|
||||
shown = len(tail)
|
||||
hidden = total - shown
|
||||
pct = min(100, round(size_kb / log_max_kb * 100)) if log_max_kb else 0
|
||||
left = f'Showing {shown} of {total} lines ({hidden} not shown)' if hidden > 0 else f'Showing {shown} of {total} lines'
|
||||
right = f'Log file size: {size_kb:.1f} KB ({pct}% of max)'
|
||||
summary = (
|
||||
'<div class="text-muted" style="display:flex;justify-content:space-between;margin-top:0.5em;">'
|
||||
f'<span>{left}</span><span>{right}</span></div>'
|
||||
)
|
||||
return ''.join(tail).strip(), summary
|
||||
except FileNotFoundError:
|
||||
return '(log file not found)', ''
|
||||
except Exception:
|
||||
return '(error reading log)', ''
|
||||
|
||||
|
||||
def blocklist_stats_html(cfg):
|
||||
rows = ''
|
||||
|
|
@ -50,6 +79,7 @@ def collect_tokens(cfg):
|
|||
tokens['GENERAL_LOG_ERRORS_ONLY'] = 'true' if dns_blk_gen.get('log_errors_only') else 'false'
|
||||
tokens['GENERAL_DAILY_EXECUTE_TIME'] = str(dns_blk_gen.get('daily_execute_time_24hr_local', '-'))
|
||||
tokens['BLOCKLIST_STATS_HTML'] = blocklist_stats_html(cfg)
|
||||
tokens['DNS_LOG_TAIL'], tokens['DNS_LOG_SUMMARY'] = _dnsblocking_log_tail(cfg)
|
||||
tokens['BLOCKLIST_FORMAT_OPTIONS'] = json.dumps([
|
||||
{'value': 'hosts', 'label': 'hosts (hosts file format)'},
|
||||
{'value': 'dnsmasq', 'label': 'dnsmasq (local=/ syntax)'},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue