Development

This commit is contained in:
Matthew Grotke 2026-06-07 00:21:08 -04:00
parent 563d82daf3
commit 70ccfe2c29
48 changed files with 549 additions and 578 deletions

View file

@ -1,10 +1,10 @@
import json
import os
from datetime import datetime, timezone
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
import config_utils
import factory
DNS_LOG_FILE = f'{CONFIGS_DIR}/dns-blocklists.log'
DNS_LOG_FILE = f'{config_utils.CONFIGS_DIR}/dns-blocklists.log'
DNS_LOG_MAX = 50
@ -37,17 +37,17 @@ def _dnsblocking_log_tail(cfg):
def blocklist_stats_html(cfg):
rows = ''
for bl in cfg.get('dns_blocking', {}).get('blocklists', []):
name = e(bl.get('name', ''))
name = factory.e(bl.get('name', ''))
save_as = bl.get('save_as', '')
bl_path = f'{BLOCKLISTS_DIR}/{save_as}' if save_as else ''
bl_path = f'{config_utils.BLOCKLISTS_DIR}/{save_as}' if save_as else ''
try:
with open(bl_path) as f:
entries = sum(1 for _ in f)
mtime = int(os.path.getmtime(bl_path))
size_str = fmt_bytes(os.path.getsize(bl_path))
size_str = config_utils.fmt_bytes(os.path.getsize(bl_path))
last_refreshed = (
f'{datetime.fromtimestamp(mtime).strftime("%Y-%m-%d %H:%M")}'
f' ({relative_time(mtime, datetime.now(tz=timezone.utc).timestamp())} ago)'
f' ({config_utils.relative_time(mtime, datetime.now(tz=timezone.utc).timestamp())} ago)'
)
except Exception:
entries, size_str, last_refreshed = '-', '-', 'Never'
@ -56,7 +56,7 @@ def blocklist_stats_html(cfg):
f'<td class="table-cell">{name}</td>'
f'<td class="table-cell">{entries}</td>'
f'<td class="table-cell">{size_str}</td>'
f'<td class="table-cell">{e(last_refreshed)}</td>'
f'<td class="table-cell">{factory.e(last_refreshed)}</td>'
'</tr>'
)
if not rows:
@ -73,7 +73,7 @@ def blocklist_stats_html(cfg):
def collect_tokens(cfg):
tokens = collect_layout_tokens(cfg)
tokens = config_utils.collect_layout_tokens(cfg)
dns_blk_gen = cfg.get('dns_blocking', {}).get('general', {})
tokens['GENERAL_LOG_MAX_KB'] = str(dns_blk_gen.get('log_max_kb', '-'))
tokens['GENERAL_LOG_ERRORS_ONLY'] = 'true' if dns_blk_gen.get('log_errors_only') else 'false'
@ -84,8 +84,8 @@ def collect_tokens(cfg):
{'value': 'hosts', 'label': 'hosts (hosts file format)'},
{'value': 'dnsmasq', 'label': 'dnsmasq (local=/ syntax)'},
])
content = load_json(f'{PAGES_DIR}/dnsblocking/content.json')
for table_item in iter_table_items(content.get('items', [])):
content = factory.load_json(f'{factory.PAGES_DIR}/dnsblocking/content.json')
for table_item in factory.iter_table_items(content.get('items', [])):
ds = table_item.get('datasource', '')
tokens[table_token_key(ds)] = build_table(table_item, tokens, load_datasource(ds))
tokens[factory.table_token_key(ds)] = factory.build_table(table_item, tokens, config_utils.load_datasource(ds))
return tokens