From e66ae9174055b24b404c184663ebf819408ccd4c Mon Sep 17 00:00:00 2001 From: Kevin Trocolli Date: Wed, 22 May 2024 01:36:41 -0400 Subject: [PATCH] add basic event log viewer --- core/data/schema/base.py | 4 +- core/frontend.py | 30 ++++ core/templates/sys/index.jinja | 3 + core/templates/sys/logs.jinja | 176 ++++++++++++++++++++++++ core/templates/widgets/err_banner.jinja | 2 + 5 files changed, 213 insertions(+), 2 deletions(-) create mode 100644 core/templates/sys/logs.jinja 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 %}
diff --git a/core/templates/sys/logs.jinja b/core/templates/sys/logs.jinja new file mode 100644 index 0000000..3f87fb8 --- /dev/null +++ b/core/templates/sys/logs.jinja @@ -0,0 +1,176 @@ +{% extends "core/templates/index.jinja" %} +{% block content %} +

Event Logs

+ + + + + + + + + + + + + + + + +
Viewing last 100 logs
SeveritySystemNameUserArcadeMachineGameVersionMessageParams
+
+ +  + + +
+ +{% endblock content %} \ No newline at end of file diff --git a/core/templates/widgets/err_banner.jinja b/core/templates/widgets/err_banner.jinja index eec204a..25208df 100644 --- a/core/templates/widgets/err_banner.jinja +++ b/core/templates/widgets/err_banner.jinja @@ -21,6 +21,8 @@ New Nickname too long You must be logged in to preform this action {% elif error == 10 %} Invalid serial number +{% elif error == 11 %} +Access Denied {% else %} An unknown error occoured {% endif %}