diff --git a/docker/routlin-dash/app/pages/radius/action.py b/docker/routlin-dash/app/pages/radius/action.py index 9e6ec88..93ac008 100644 --- a/docker/routlin-dash/app/pages/radius/action.py +++ b/docker/routlin-dash/app/pages/radius/action.py @@ -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': ''}) diff --git a/docker/routlin-dash/app/pages/radius/content.json b/docker/routlin-dash/app/pages/radius/content.json index ab38068..2bf621d 100644 --- a/docker/routlin-dash/app/pages/radius/content.json +++ b/docker/routlin-dash/app/pages/radius/content.json @@ -128,23 +128,6 @@ "type": "raw_html", "html": "%RADIUS_LOG_SUMMARY%" }, - { - "type": "button_row", - "justify": "space-between", - "items": [ - { - "type": "button_ghost", - "action": "/action/radius/logging_download", - "text": "Download Log" - }, - { - "type": "button_danger", - "action": "/action/radius/logging_clear", - "method": "post", - "text": "Clear Log" - } - ] - }, { "type": "hr" }, @@ -163,8 +146,6 @@ "items": [ { "type": "button_primary", - "action": "/action/radius/logging_save", - "method": "post", "text": "Save" }, { @@ -174,6 +155,23 @@ ] } ] + }, + { + "type": "button_row", + "justify": "space-between", + "items": [ + { + "type": "button_ghost", + "action": "/action/radius/logging_download", + "text": "Download Log" + }, + { + "type": "button_danger", + "action": "/action/radius/logging_clear", + "method": "post", + "text": "Clear Log" + } + ] } ] } diff --git a/docker/routlin-dash/app/view_page.py b/docker/routlin-dash/app/view_page.py index 2af4fbe..dfeb0e7 100644 --- a/docker/routlin-dash/app/view_page.py +++ b/docker/routlin-dash/app/view_page.py @@ -523,7 +523,7 @@ def _radius_log_tail(): 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 = ( - '
' + '
' f'{left}{right}
' ) return ''.join(tail).strip(), summary