Development
This commit is contained in:
parent
6d9aac0460
commit
59ac3c5973
20 changed files with 1466 additions and 1 deletions
48
docker/routlin-dash/app/pages/radius/view.py
Normal file
48
docker/routlin-dash/app/pages/radius/view.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import os
|
||||
from view_common import CONFIGS_DIR
|
||||
|
||||
RADIUS_LOG_MAX = 50
|
||||
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()
|
||||
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 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)', ''
|
||||
|
||||
|
||||
def collect_tokens(cfg):
|
||||
tokens = {}
|
||||
try:
|
||||
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)'
|
||||
fr = cfg.get('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(cfg)
|
||||
return tokens
|
||||
Loading…
Add table
Add a link
Reference in a new issue