Development
This commit is contained in:
parent
4f5f2a8071
commit
0d096a0d99
6 changed files with 175 additions and 33 deletions
|
|
@ -502,7 +502,36 @@ def _blocklist_stats_html(cfg):
|
|||
)
|
||||
|
||||
|
||||
DDNS_LOG_MAX = 50
|
||||
DDNS_LOG_MAX = 50
|
||||
RADIUS_LOG_MAX = 50
|
||||
RADIUS_LOG_FILE = '/var/log/freeradius/radius.log'
|
||||
|
||||
def _radius_log_tail():
|
||||
try:
|
||||
cfg = load_config()
|
||||
log_max_kb = cfg.get('free_radius', {}).get('general', {}).get('log_max_kb', 1024)
|
||||
size_kb = os.path.getsize(RADIUS_LOG_FILE) / 1024
|
||||
with open(RADIUS_LOG_FILE) as f:
|
||||
lines = f.readlines()
|
||||
if not lines:
|
||||
return '(log is empty)', ''
|
||||
total = len(lines)
|
||||
tail = lines[-RADIUS_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 _ddns_log_tail():
|
||||
log_path = f'{CONFIGS_DIR}/ddns.log'
|
||||
|
|
@ -819,10 +848,14 @@ def collect_tokens():
|
|||
tokens['RADIUS_SECRET'] = open(f'{CONFIGS_DIR}/.radius-secret').read().strip()
|
||||
except OSError:
|
||||
tokens['RADIUS_SECRET'] = '(Generation is pending - visit Actions to apply generation command)'
|
||||
_radius_opts = cfg.get('radius_options', {})
|
||||
tokens['RADIUS_MAC_FORMAT'] = _radius_opts.get('mac_format', 'aabbccddeeff')
|
||||
tokens['RADIUS_APPLY_TO'] = _radius_opts.get('apply_to', 'all')
|
||||
tokens['RADIUS_LOGGING'] = 'true' if _radius_opts.get('logging', False) else ''
|
||||
_fr = cfg.get('free_radius', {})
|
||||
_fr_opts = _fr.get('options', {})
|
||||
_fr_gen = _fr.get('general', {})
|
||||
tokens['RADIUS_MAC_FORMAT'] = _fr_opts.get('mac_format', 'aabbccddeeff')
|
||||
tokens['RADIUS_APPLY_TO'] = _fr_opts.get('apply_to', 'all')
|
||||
tokens['RADIUS_LOGGING'] = 'true' if _fr_gen.get('logging', False) else ''
|
||||
tokens['RADIUS_GEN_LOG_MAX_KB'] = str(_fr_gen.get('log_max_kb', 1024))
|
||||
tokens['RADIUS_LOG_TAIL'], tokens['RADIUS_LOG_SUMMARY'] = _radius_log_tail()
|
||||
tokens['STAT_BANNED_IP_COUNT'] = str(sum(1 for b in cfg.get('banned_ips', []) if b.get('enabled', True)))
|
||||
tokens['STAT_BLOCKLIST_COUNT'] = str(len(cfg.get('dns_blocking', {}).get('blocklists', [])))
|
||||
tokens['BLOCKLIST_STATS_HTML'] = _blocklist_stats_html(cfg)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue