Development

This commit is contained in:
Matthew Grotke 2026-06-01 13:51:12 -04:00
parent 8ba730f92f
commit 9f1b4a9119
3 changed files with 44 additions and 21 deletions

View file

@ -1,7 +1,7 @@
import copy
import os
from pathlib import Path
from flask import Blueprint, request, redirect, flash, send_file, abort
from flask import Blueprint, request, redirect, flash, send_file, abort, jsonify
from auth import require_level
from config_utils import CONFIGS_DIR, load_config, record_group, diff_fields
import validation as validate
@ -90,3 +90,28 @@ def logging_download():
if not os.path.isfile(RADIUS_LOG_FILE):
abort(404)
return send_file(RADIUS_LOG_FILE, as_attachment=True, download_name='radius.log', mimetype='text/plain')
@bp.route('/api/radius/log-tail', methods=['GET'])
@require_level('administrator')
def api_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 jsonify({'log': '(log is empty)', 'summary': ''})
total = len(lines)
tail = lines[-50:]
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)'
return jsonify({'log': ''.join(tail).strip(), 'left': left, 'right': right})
except FileNotFoundError:
return jsonify({'log': '(log file not found)', 'left': '', 'right': ''})
except Exception:
return jsonify({'log': '(error reading log)', 'left': '', 'right': ''})