Merge pull request #19 from DarkflameUniverse/v1-polish
This commit is contained in:
		
							
								
								
									
										46
									
								
								app/log.py
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								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 = '</br>'.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""" | ||||
|             <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 | ||||
|   | ||||
| @@ -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 = '</br>'.join(file.read().split('\n')[-100:]) | ||||
|     return render_template('main/logs.html.j2', logs=logs) | ||||
|     return '</br>'.join(all_read_text.splitlines()[-total_lines_wanted:]) | ||||
|   | ||||
| @@ -52,22 +52,24 @@ | ||||
|             <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Tools</a> | ||||
|             <div class="dropdown-menu"> | ||||
|  | ||||
|               <a class="dropdown-item" href='{{ url_for('mail.send') }}'>Send Mail</a> | ||||
|               <a class="dropdown-item text-center" href='{{ url_for('mail.send') }}'>Send Mail</a> | ||||
|               <hr/> | ||||
|               <h6 class="text-center">Moderation</h6> | ||||
|               <a class="dropdown-item" href='{{ url_for('moderation.index', status='unapproved') }}'>View Unapproved Items</a> | ||||
|               <a class="dropdown-item" href='{{ url_for('moderation.index', status='approved') }}'>View Approved Items</a> | ||||
|               <a class="dropdown-item" href='{{ url_for('moderation.index', status='all') }}'>View All Items</a> | ||||
|               <h3 class="text-center">Moderation</h3> | ||||
|               <a class="dropdown-item text-center" href='{{ url_for('moderation.index', status='unapproved') }}'>Unapproved Items</a> | ||||
|               <a class="dropdown-item text-center" href='{{ url_for('moderation.index', status='approved') }}'>Approved Items</a> | ||||
|               <a class="dropdown-item text-center" href='{{ url_for('moderation.index', status='all') }}'>All Items</a> | ||||
|               <hr/> | ||||
|               <h6 class="text-center">Bug Reports</h6> | ||||
|               <a class="dropdown-item" href='{{ url_for('bug_reports.index', status='unresolved') }}'>View Unresolved Reports</a> | ||||
|               <a class="dropdown-item" href='{{ url_for('bug_reports.index', status='resolved') }}'>View Resolved Reports</a> | ||||
|               <a class="dropdown-item" href='{{ url_for('bug_reports.index', status='all') }}'>View All Reports</a> | ||||
|               <h3 class="text-center">Bug Reports</h3> | ||||
|               <a class="dropdown-item text-center" href='{{ url_for('bug_reports.index', status='unresolved') }}'>Unresolved Reports</a> | ||||
|               <a class="dropdown-item text-center" href='{{ url_for('bug_reports.index', status='resolved') }}'>Resolved Reports</a> | ||||
|               <a class="dropdown-item text-center" href='{{ url_for('bug_reports.index', status='all') }}'>All Reports</a> | ||||
|               {% if current_user.is_authenticated and current_user.gm_level >= 8 %} | ||||
|                 <hr/> | ||||
|                 <h6 class="text-center">Logs</h6> | ||||
|                 <a class="dropdown-item" href='{{ url_for('log.activity') }}'>Command Log</a> | ||||
|                 <a class="dropdown-item" href='{{ url_for('log.command') }}'>Activity Log</a> | ||||
|                 <h3 class="text-center">Logs</h3> | ||||
|                 <a class="dropdown-item text-center" href='{{ url_for('log.activity') }}'>Command Log</a> | ||||
|                 <a class="dropdown-item text-center" href='{{ url_for('log.command') }}'>Activity Log</a> | ||||
|                 <a class="dropdown-item text-center" href='{{ url_for('log.audit') }}'>Audit Log</a> | ||||
|                 <a class="dropdown-item text-center" href='{{ url_for('log.error') }}'>Error Log</a> | ||||
|               {% endif %} | ||||
|             </div> | ||||
|           </li> | ||||
|   | ||||
							
								
								
									
										46
									
								
								app/templates/logs/audit.html.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								app/templates/logs/audit.html.j2
									
									
									
									
									
										Normal file
									
								
							| @@ -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 %} | ||||
|     <div class="row"> | ||||
|       <div class="col text-center"> | ||||
|         <h3>{{ message }}</h3> | ||||
|       </div> | ||||
|     </div> | ||||
|     <br/> | ||||
|   {% endif %} | ||||
|   <table class="table table-dark table-striped table-bordered table-hover" id="audit_table"> | ||||
|     <thead> | ||||
|         <tr> | ||||
|             <th>ID</th> | ||||
|             <th>Account</th> | ||||
|             <th>Command</th> | ||||
|             <th>Date</th> | ||||
|         </tr> | ||||
|     </thead> | ||||
|     <tbody></tbody> | ||||
| </table> | ||||
| {% endblock  %} | ||||
|  | ||||
|  | ||||
| {% block js %} | ||||
|   {{ super () }} | ||||
|   <script> | ||||
|     $(document).ready(function(){ | ||||
|         let audit_table = $('#audit_table').DataTable({ | ||||
|             "order": [[0, "desc"]], | ||||
|             "processing": true, | ||||
|             "serverSide": true, | ||||
|             "ajax": "{{ url_for('log.get_audits') }}", | ||||
|           }); | ||||
|         }); | ||||
|   </script> | ||||
| {% endblock %} | ||||
| @@ -7,7 +7,9 @@ | ||||
| {% endblock %} | ||||
| 
 | ||||
| {% block content_override %} | ||||
|   <code> | ||||
|     {{ logs }} | ||||
|   </code> | ||||
|   <div class="bg-white mx-5 p-3 rounded"> | ||||
|     <code> | ||||
|       {{ logs }} | ||||
|     </code> | ||||
|   </div> | ||||
| {% endblock %} | ||||
		Reference in New Issue
	
	Block a user
	 Aaron Kimbrell
					Aaron Kimbrell