Development

This commit is contained in:
Matthew Grotke 2026-06-08 00:28:33 -04:00
parent 1a473296b7
commit 43c4cf380d
5 changed files with 71 additions and 62 deletions

View file

@ -1,7 +1,6 @@
import json
import sqlite3
import time
import datetime
import config_utils
import factory
@ -27,7 +26,8 @@ def _load_credentials():
vlan TEXT NOT NULL DEFAULT '',
enabled INTEGER NOT NULL DEFAULT 1,
date_set INTEGER NOT NULL,
valid_for INTEGER DEFAULT NULL
session_seconds INTEGER NOT NULL DEFAULT 0,
expires_seconds INTEGER NOT NULL DEFAULT 0
)
""")
conn.execute("""
@ -48,15 +48,14 @@ def _load_credentials():
return []
def _format_expiry(date_set, valid_for):
if valid_for is None:
return 'Never'
expires_ts = date_set + valid_for
now = int(time.time())
if expires_ts <= now:
return 'Expired'
dt = datetime.datetime.fromtimestamp(expires_ts)
return dt.strftime('%Y-%m-%d %H:%M')
def _format_session(session_seconds):
if not session_seconds:
return 'No limit'
if session_seconds % 86400 == 0:
n = session_seconds // 86400
return f"{n} day{'s' if n != 1 else ''}"
hours = session_seconds / 3600
return f"{hours:g} h"
def collect_tokens(cfg):
@ -100,7 +99,7 @@ def collect_tokens(cfg):
r = dict(row)
r.pop('password', None)
r['user_type_label'] = USER_TYPE_LABELS.get(r.get('user_type'), str(r.get('user_type', '')))
r['expires_label'] = _format_expiry(r.get('date_set', 0), r.get('valid_for'))
r['expires_label'] = _format_session(r.get('session_seconds', 0))
display_rows.append(r)
content = factory.load_json(f'{factory.PAGES_DIR}/clientcredentials/content.json')