2022-01-16 18:22:00 +00:00
|
|
|
from flask import render_template, Blueprint, request, url_for
|
2022-03-13 02:09:35 +00:00
|
|
|
from flask_user import login_required
|
2022-02-12 21:30:43 +00:00
|
|
|
from app.models import CommandLog, ActivityLog, db, Account, CharacterInfo, AuditLog
|
2022-01-16 18:22:00 +00:00
|
|
|
from datatables import ColumnDT, DataTables
|
|
|
|
import time
|
|
|
|
from app import gm_level
|
|
|
|
|
|
|
|
log_blueprint = Blueprint('log', __name__)
|
|
|
|
|
2022-03-13 02:09:35 +00:00
|
|
|
|
2022-01-16 18:22:00 +00:00
|
|
|
@log_blueprint.route('/activities', methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
@gm_level(8)
|
|
|
|
def activity():
|
|
|
|
return render_template('logs/activity.html.j2')
|
|
|
|
|
|
|
|
|
|
|
|
@log_blueprint.route('/commands', methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
@gm_level(8)
|
|
|
|
def command():
|
|
|
|
return render_template('logs/command.html.j2')
|
|
|
|
|
|
|
|
|
2022-02-25 17:46:13 +00:00
|
|
|
@log_blueprint.route('/system')
|
2022-02-12 21:30:43 +00:00
|
|
|
@gm_level(8)
|
2022-02-25 17:46:13 +00:00
|
|
|
def system():
|
2022-02-12 21:30:43 +00:00
|
|
|
with open('nexus_dashboard.log', 'r') as file:
|
|
|
|
logs = '</br>'.join(file.read().split('\n')[-100:])
|
2022-02-25 17:46:13 +00:00
|
|
|
return render_template('logs/system.html.j2', logs=logs)
|
2022-02-12 21:30:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
@log_blueprint.route('/audits')
|
|
|
|
@gm_level(8)
|
|
|
|
def audit():
|
|
|
|
return render_template('logs/audit.html.j2')
|
|
|
|
|
|
|
|
|
2022-01-16 18:22:00 +00:00
|
|
|
@log_blueprint.route('/get_activities', methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
@gm_level(8)
|
|
|
|
def get_activities():
|
|
|
|
columns = [
|
2022-03-13 02:09:35 +00:00
|
|
|
ColumnDT(ActivityLog.id), # 0
|
|
|
|
ColumnDT(ActivityLog.character_id), # 1
|
|
|
|
ColumnDT(ActivityLog.activity), # 2
|
|
|
|
ColumnDT(ActivityLog.time), # 3
|
|
|
|
ColumnDT(ActivityLog.map_id), # 4
|
2022-01-16 18:22:00 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
query = db.session.query().select_from(ActivityLog)
|
|
|
|
|
|
|
|
params = request.args.to_dict()
|
|
|
|
|
|
|
|
rowTable = DataTables(params, query, columns)
|
|
|
|
|
|
|
|
data = rowTable.output_result()
|
|
|
|
for activity in data["data"]:
|
|
|
|
char_id = activity["1"]
|
|
|
|
activity["1"] = f"""
|
|
|
|
<a role="button" class="btn btn-primary btn btn-block"
|
|
|
|
href='{url_for('characters.view', id=char_id)}'>
|
|
|
|
View Character: {CharacterInfo.query.filter(CharacterInfo.id==char_id).first().name}
|
|
|
|
</a>
|
|
|
|
<a role="button" class="btn btn-primary btn btn-block"
|
|
|
|
href='{url_for('accounts.view', id=CharacterInfo.query.filter(CharacterInfo.id==char_id).first().account_id)}'>
|
|
|
|
View Account: {Account.query.filter(Account.id==CharacterInfo.query.filter(CharacterInfo.id==char_id).first().account_id).first().username}
|
|
|
|
</a>
|
|
|
|
"""
|
|
|
|
|
|
|
|
if activity["2"] == 0:
|
|
|
|
activity["2"] = "Entered World"
|
|
|
|
elif activity["2"] == 1:
|
|
|
|
activity["2"] = "Left World"
|
|
|
|
|
|
|
|
activity["3"] = time.ctime(activity["3"])
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
@log_blueprint.route('/get_commands', methods=['GET'])
|
|
|
|
@login_required
|
|
|
|
@gm_level(8)
|
|
|
|
def get_commands():
|
|
|
|
columns = [
|
2022-03-13 02:09:35 +00:00
|
|
|
ColumnDT(CommandLog.id), # 0
|
|
|
|
ColumnDT(CommandLog.character_id), # 1
|
|
|
|
ColumnDT(CommandLog.command), # 2
|
2022-01-16 18:22:00 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
query = db.session.query().select_from(CommandLog)
|
|
|
|
|
|
|
|
params = request.args.to_dict()
|
|
|
|
|
|
|
|
rowTable = DataTables(params, query, columns)
|
|
|
|
|
|
|
|
data = rowTable.output_result()
|
|
|
|
for command in data["data"]:
|
|
|
|
char_id = command["1"]
|
|
|
|
command["1"] = f"""
|
|
|
|
<a role="button" class="btn btn-primary btn btn-block"
|
|
|
|
href='{url_for('characters.view', id=char_id)}'>
|
|
|
|
View Character: {CharacterInfo.query.filter(CharacterInfo.id==command['1']).first().name}
|
|
|
|
</a>
|
|
|
|
"""
|
|
|
|
command["1"] += f"""
|
|
|
|
<a role="button" class="btn btn-primary btn btn-block"
|
|
|
|
href='{url_for('accounts.view', id=CharacterInfo.query.filter(CharacterInfo.id==char_id).first().account_id)}'>
|
|
|
|
View Account: {Account.query.filter(Account.id==CharacterInfo.query.filter(CharacterInfo.id==char_id).first().account_id).first().username}
|
|
|
|
</a>
|
|
|
|
"""
|
|
|
|
|
|
|
|
return data
|
2022-02-12 21:30:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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"""
|
|
|
|
<a role="button" class="btn btn-primary btn btn-block"
|
|
|
|
href='{url_for('accounts.view', id=char_id)}'>
|
|
|
|
{Account.query.filter(Account.id==audit['1']).first().username}
|
|
|
|
</a>
|
|
|
|
"""
|
|
|
|
|
|
|
|
return data
|