Development

This commit is contained in:
Matthew Grotke 2026-06-03 00:45:04 -04:00
parent 4a9110cc4c
commit 094847966a
6 changed files with 197 additions and 57 deletions

View file

@ -8,25 +8,48 @@ RADIUS_LOG_FILE = '/var/log/freeradius/radius.log'
def radius_log_tail(cfg):
try:
log_max_kb = cfg.get('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()
current = []
try:
with open(RADIUS_LOG_FILE) as f:
current = f.readlines()
except FileNotFoundError:
pass
prev = []
if len(current) < RADIUS_LOG_MAX:
try:
with open(RADIUS_LOG_FILE + '.1') as f:
prev = f.readlines()
except FileNotFoundError:
pass
need = max(0, RADIUS_LOG_MAX - len(current))
lines = (prev[-need:] if need and prev else []) + current
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)'
log_dir = os.path.dirname(RADIUS_LOG_FILE)
try:
size_kb = sum(
os.path.getsize(os.path.join(log_dir, f))
for f in os.listdir(log_dir)
if os.path.isfile(os.path.join(log_dir, f))
) / 1024
except OSError:
size_kb = 0.0
tail = lines[-RADIUS_LOG_MAX:]
pct = min(100, round(size_kb / log_max_kb * 100)) if log_max_kb else 0
note = ' (includes rotated log)' if (prev and need) else ''
left = f'Showing {len(tail)} lines{note}'
right = f'Total log size: {size_kb:.1f} KB ({pct}% of max)'
summary = (
'<div id="radius-log-summary" 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)', ''