Development
This commit is contained in:
parent
8ba730f92f
commit
9f1b4a9119
3 changed files with 44 additions and 21 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import copy
|
import copy
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
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 auth import require_level
|
||||||
from config_utils import CONFIGS_DIR, load_config, record_group, diff_fields
|
from config_utils import CONFIGS_DIR, load_config, record_group, diff_fields
|
||||||
import validation as validate
|
import validation as validate
|
||||||
|
|
@ -90,3 +90,28 @@ def logging_download():
|
||||||
if not os.path.isfile(RADIUS_LOG_FILE):
|
if not os.path.isfile(RADIUS_LOG_FILE):
|
||||||
abort(404)
|
abort(404)
|
||||||
return send_file(RADIUS_LOG_FILE, as_attachment=True, download_name='radius.log', mimetype='text/plain')
|
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': ''})
|
||||||
|
|
|
||||||
|
|
@ -128,23 +128,6 @@
|
||||||
"type": "raw_html",
|
"type": "raw_html",
|
||||||
"html": "%RADIUS_LOG_SUMMARY%"
|
"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"
|
"type": "hr"
|
||||||
},
|
},
|
||||||
|
|
@ -163,8 +146,6 @@
|
||||||
"items": [
|
"items": [
|
||||||
{
|
{
|
||||||
"type": "button_primary",
|
"type": "button_primary",
|
||||||
"action": "/action/radius/logging_save",
|
|
||||||
"method": "post",
|
|
||||||
"text": "Save"
|
"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"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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'
|
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)'
|
right = f'Log file size: {size_kb:.1f} KB ({pct}% of max)'
|
||||||
summary = (
|
summary = (
|
||||||
'<div class="text-muted" style="display:flex;justify-content:space-between;margin-top:0.5em;">'
|
'<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>'
|
f'<span>{left}</span><span>{right}</span></div>'
|
||||||
)
|
)
|
||||||
return ''.join(tail).strip(), summary
|
return ''.join(tail).strip(), summary
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue