diff --git a/core/data/schema/base.py b/core/data/schema/base.py index a6fd68d..e315964 100644 --- a/core/data/schema/base.py +++ b/core/data/schema/base.py @@ -108,8 +108,8 @@ class BaseData: return result.lastrowid - async def get_event_log(self, entries: int = 100) -> Optional[List[Dict]]: - sql = event_log.select().limit(entries).all() + async def get_event_log(self, entries: int = 100) -> Optional[List[Row]]: + sql = event_log.select().limit(entries) result = await self.execute(sql) if result is None: diff --git a/core/frontend.py b/core/frontend.py index 382a082..bb3e9aa 100644 --- a/core/frontend.py +++ b/core/frontend.py @@ -133,6 +133,7 @@ class FrontendServlet(): ]), Mount("/sys", routes=[ Route("/", self.system.render_GET, methods=['GET']), + Route("/logs", self.system.render_logs, methods=['GET']), Route("/lookup.user", self.system.lookup_user, methods=['GET']), Route("/lookup.shop", self.system.lookup_shop, methods=['GET']), Route("/add.user", self.system.add_user, methods=['POST']), @@ -783,6 +784,35 @@ class FE_System(FE_Base): cabadd={"id": cab_id, "serial": serial}, ), media_type="text/html; charset=utf-8") + async def render_logs(self, request: Request): + template = self.environment.get_template("core/templates/sys/logs.jinja") + events = [] + + usr_sesh = self.validate_session(request) + if not usr_sesh or not self.test_perm(usr_sesh.permissions, PermissionOffset.SYSADMIN): + return RedirectResponse("/sys/?e=11", 303) + + logs = await self.data.base.get_event_log() + if not logs: + logs = [] + + for log in logs: + evt = log._asdict() + if not evt['user']: evt["user"] = "NONE" + if not evt['arcade']: evt["arcade"] = "NONE" + if not evt['machine']: evt["machine"] = "NONE" + if not evt['ip']: evt["ip"] = "NONE" + if not evt['game']: evt["game"] = "NONE" + if not evt['version']: evt["version"] = "NONE" + evt['when_logged'] = evt['when_logged'].strftime("%x %X") + events.append(evt) + + return Response(template.render( + title=f"{self.core_config.server.name} | Event Logs", + sesh=vars(usr_sesh), + events=events + ), media_type="text/html; charset=utf-8") + class FE_Arcade(FE_Base): async def render_GET(self, request: Request): template = self.environment.get_template("core/templates/arcade/index.jinja") diff --git a/core/templates/sys/index.jinja b/core/templates/sys/index.jinja index b589d90..637b8c9 100644 --- a/core/templates/sys/index.jinja +++ b/core/templates/sys/index.jinja @@ -51,6 +51,9 @@ +
{% endif %}Severity | +System | +Name | +User | +Arcade | +Machine | +Game | +Version | +Message | +Params | +
---|