add basic event log viewer
This commit is contained in:
parent
4ee4c26f5e
commit
e66ae91740
@ -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:
|
||||
|
@ -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")
|
||||
|
@ -51,6 +51,9 @@
|
||||
<button type="submit" class="btn btn-primary">Search</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-sm-6" style="max-width: 25%;">
|
||||
<a href="/sys/logs"><button class="btn btn-primary">Event Logs</button></a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="row" id="rowResult" style="margin: 10px;">
|
||||
|
176
core/templates/sys/logs.jinja
Normal file
176
core/templates/sys/logs.jinja
Normal file
@ -0,0 +1,176 @@
|
||||
{% extends "core/templates/index.jinja" %}
|
||||
{% block content %}
|
||||
<h1>Event Logs</h1>
|
||||
<table class="table table-dark table-striped-columns" id="tbl_events">
|
||||
<caption>Viewing last 100 logs</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Severity</th>
|
||||
<th>System</th>
|
||||
<th>Name</th>
|
||||
<th>User</th>
|
||||
<th>Arcade</th>
|
||||
<th>Machine</th>
|
||||
<th>Game</th>
|
||||
<th>Version</th>
|
||||
<th>Message</th>
|
||||
<th>Params</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
<div id="div_tbl_ctrl">
|
||||
<select id="sel_per_page" onchange="update_tbl()">
|
||||
<option value="10" selected>10</option>
|
||||
<option value="25">25</option>
|
||||
<option value="50">50</option>
|
||||
<option value="100">100</option>
|
||||
</select>
|
||||
|
||||
<button class="btn btn-primary" id="btn_prev" disabled onclick="chg_page(-1)"><<</button>
|
||||
<button class="btn btn-primary" id="btn_next" onclick="chg_page(1)">>></button>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
{% if events is defined %}
|
||||
const TBL_DATA = {{events}};
|
||||
{% else %}
|
||||
const TBL_DATA = [];
|
||||
{% endif %}
|
||||
|
||||
var per_page = 0;
|
||||
var page = 0;
|
||||
|
||||
function update_tbl() {
|
||||
var tbl = document.getElementById("tbl_events");
|
||||
|
||||
for (var i = 0; i < per_page; i++) {
|
||||
try{
|
||||
tbl.deleteRow(1);
|
||||
} catch {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
per_page = document.getElementById("sel_per_page").value;
|
||||
|
||||
if (per_page >= TBL_DATA.length) {
|
||||
page = 0;
|
||||
document.getElementById("btn_next").disabled = true;
|
||||
document.getElementById("btn_prev").disabled = true;
|
||||
}
|
||||
|
||||
for (var i = 0; i < per_page; i++) {
|
||||
let off = (page * per_page) + i;
|
||||
if (off >= TBL_DATA.length ) {
|
||||
break;
|
||||
}
|
||||
|
||||
var data = TBL_DATA[off];
|
||||
var row = tbl.insertRow(i + 1);
|
||||
var cell_severity = row.insertCell(0);
|
||||
switch (data.severity) {
|
||||
case 10:
|
||||
cell_severity.innerHTML = "DEBUG";
|
||||
row.classList.add("table-success");
|
||||
break;
|
||||
case 20:
|
||||
cell_severity.innerHTML = "INFO";
|
||||
row.classList.add("table-info");
|
||||
break;
|
||||
case 30:
|
||||
cell_severity.innerHTML = "WARN";
|
||||
row.classList.add("table-warning");
|
||||
break;
|
||||
case 40:
|
||||
cell_severity.innerHTML = "ERROR";
|
||||
row.classList.add("table-danger");
|
||||
break;
|
||||
case 50:
|
||||
cell_severity.innerHTML = "CRITICAL";
|
||||
row.classList.add("table-danger");
|
||||
break;
|
||||
default:
|
||||
cell_severity.innerHTML = "---";
|
||||
row.classList.add("table-primary");
|
||||
break;
|
||||
}
|
||||
|
||||
var cell_mod = row.insertCell(1);
|
||||
cell_mod.innerHTML = data.system;
|
||||
|
||||
var cell_name = row.insertCell(2);
|
||||
cell_name.innerHTML = data.type;
|
||||
|
||||
var cell_usr = row.insertCell(3);
|
||||
if (data.user == 'NONE') {
|
||||
cell_usr.innerHTML = "---";
|
||||
} else {
|
||||
cell_usr.innerHTML = "<a href=\"/user/" + data.user + "\">" + data.user + "</a>";
|
||||
}
|
||||
|
||||
var cell_arcade = row.insertCell(4);
|
||||
if (data.arcade == 'NONE') {
|
||||
cell_arcade.innerHTML = "---";
|
||||
} else {
|
||||
cell_arcade.innerHTML = "<a href=\"/shop/" + data.arcade + "\">" + data.arcade + "</a>";
|
||||
}
|
||||
|
||||
var cell_machine = row.insertCell(5);
|
||||
if (data.arcade == 'NONE') {
|
||||
cell_machine.innerHTML = "---";
|
||||
} else {
|
||||
cell_machine.innerHTML = "<a href=\"/cab/" + data.machine + "\">" + data.machine + "</a>";
|
||||
}
|
||||
|
||||
var cell_game = row.insertCell(6);
|
||||
if (data.game == 'NONE') {
|
||||
cell_game.innerHTML = "---";
|
||||
} else {
|
||||
cell_game.innerHTML = data.game;
|
||||
}
|
||||
|
||||
var cell_version = row.insertCell(7);
|
||||
if (data.version == 'NONE') {
|
||||
cell_version.innerHTML = "---";
|
||||
} else {
|
||||
cell_version.innerHTML = data.version;
|
||||
}
|
||||
|
||||
var cell_msg = row.insertCell(8);
|
||||
if (data.message == '') {
|
||||
cell_msg.innerHTML = "---";
|
||||
} else {
|
||||
cell_msg.innerHTML = data.message;
|
||||
}
|
||||
|
||||
var cell_deets = row.insertCell(9);
|
||||
if (data.details == '{}') {
|
||||
cell_deets.innerHTML = "---";
|
||||
} else {
|
||||
cell_deets.innerHTML = data.details;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function chg_page(num) {
|
||||
var max_page = TBL_DATA.length / per_page;
|
||||
page = page + num;
|
||||
|
||||
if (page > max_page) {
|
||||
page = max_page;
|
||||
document.getElementById("btn_next").disabled = true;
|
||||
document.getElementById("btn_prev").disabled = false;
|
||||
return;
|
||||
} else if (page < 0) {
|
||||
page = 0;
|
||||
document.getElementById("btn_next").disabled = false;
|
||||
document.getElementById("btn_prev").disabled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
update_tbl();
|
||||
}
|
||||
|
||||
update_tbl();
|
||||
</script>
|
||||
{% endblock content %}
|
@ -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 %}
|
||||
|
Loading…
Reference in New Issue
Block a user