From d77eaf16d169c68b7b8ef1109ed8451209035783 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sat, 12 Feb 2022 15:30:43 -0600 Subject: [PATCH] Audit log view move error logs to logs Add links for new logs in header --- app/log.py | 46 ++++++++++++++++++- app/main.py | 8 ---- app/templates/header.html.j2 | 26 ++++++----- app/templates/logs/audit.html.j2 | 46 +++++++++++++++++++ .../{main/logs.html.j2 => logs/error.html.j2} | 8 ++-- 5 files changed, 110 insertions(+), 24 deletions(-) create mode 100644 app/templates/logs/audit.html.j2 rename app/templates/{main/logs.html.j2 => logs/error.html.j2} (66%) diff --git a/app/log.py b/app/log.py index f5a5426..5fb5ce8 100644 --- a/app/log.py +++ b/app/log.py @@ -1,6 +1,6 @@ from flask import render_template, Blueprint, request, url_for from flask_user import login_required, current_user -from app.models import CommandLog, ActivityLog, db, Account, CharacterInfo +from app.models import CommandLog, ActivityLog, db, Account, CharacterInfo, AuditLog from datatables import ColumnDT, DataTables import time from app import gm_level @@ -21,6 +21,20 @@ def command(): return render_template('logs/command.html.j2') +@log_blueprint.route('/errors') +@gm_level(8) +def error(): + with open('nexus_dashboard.log', 'r') as file: + logs = '
'.join(file.read().split('\n')[-100:]) + return render_template('logs/error.html.j2', logs=logs) + + +@log_blueprint.route('/audits') +@gm_level(8) +def audit(): + return render_template('logs/audit.html.j2') + + @log_blueprint.route('/get_activities', methods=['GET']) @login_required @gm_level(8) @@ -96,3 +110,33 @@ def get_commands(): """ return data + + +@log_blueprint.route('/get_audits', methods=['GET']) +@login_required +@gm_level(8) +def get_audits(): + columns = [ + ColumnDT(AuditLog.id), # 0 + ColumnDT(AuditLog.account_id), # 1 + ColumnDT(AuditLog.action), # 2 + ColumnDT(AuditLog.date), # 2 + ] + + query = db.session.query().select_from(AuditLog) + + params = request.args.to_dict() + + rowTable = DataTables(params, query, columns) + + data = rowTable.output_result() + for audit in data["data"]: + char_id = audit["1"] + audit["1"] = f""" + + {Account.query.filter(Account.id==audit['1']).first().username} + + """ + + return data diff --git a/app/main.py b/app/main.py index 95b8f33..4da900a 100644 --- a/app/main.py +++ b/app/main.py @@ -40,11 +40,3 @@ def favicon(): 'favicon.ico', mimetype='image/vnd.microsoft.icon' ) - -@main_blueprint.route('/logs') -@gm_level(9) -def logs(): - with open('nexus_dashboard.log', 'r') as file: - logs = '
'.join(file.read().split('\n')[-100:]) - return render_template('main/logs.html.j2', logs=logs) - return '
'.join(all_read_text.splitlines()[-total_lines_wanted:]) diff --git a/app/templates/header.html.j2 b/app/templates/header.html.j2 index fe1bb93..0e35694 100644 --- a/app/templates/header.html.j2 +++ b/app/templates/header.html.j2 @@ -52,22 +52,24 @@ diff --git a/app/templates/logs/audit.html.j2 b/app/templates/logs/audit.html.j2 new file mode 100644 index 0000000..2ea8d72 --- /dev/null +++ b/app/templates/logs/audit.html.j2 @@ -0,0 +1,46 @@ +{% extends 'base.html.j2' %} + +{% block title %} + Audit Log +{% endblock title %} + +{% block content_before %} + Audit Log +{% endblock content_before %} + +{% block content %} + {% if message %} +
+
+

{{ message }}

+
+
+
+ {% endif %} + + + + + + + + + + +
IDAccountCommandDate
+{% endblock %} + + +{% block js %} + {{ super () }} + +{% endblock %} diff --git a/app/templates/main/logs.html.j2 b/app/templates/logs/error.html.j2 similarity index 66% rename from app/templates/main/logs.html.j2 rename to app/templates/logs/error.html.j2 index 8880ccc..031353b 100644 --- a/app/templates/main/logs.html.j2 +++ b/app/templates/logs/error.html.j2 @@ -7,7 +7,9 @@ {% endblock %} {% block content_override %} - - {{ logs }} - +
+ + {{ logs }} + +
{% endblock %}