added option to view the NFC logfile as super admin

This commit is contained in:
Simon Pirkelmann 2021-04-10 17:25:27 +02:00
parent c02d5465ea
commit f48f78997c
4 changed files with 42 additions and 1 deletions

View File

@ -10,7 +10,8 @@ parser.add_argument("--nfc_socket", default="/tmp/nfc.sock", help="socket for ha
parser.add_argument("--template_folder", default="templates", help="path to Flask templates folder")
parser.add_argument("--static_folder", default="static", help="path to Flask static folder")
parser.add_argument("--admin_file", help="Path to file for creating super admin users")
parser.add_argument("--log_file", default="/var/log/webinterface.log", help="Path to log file")
parser.add_argument("--log_file", default="/var/log/webinterface.log", help="Path to flask log file")
parser.add_argument("--nfc_log", default="/var/log/nfc.log", help="Path to nfc log file")
parser.add_argument("--ldap_url", default="ldaps://ldap.imaginaerraum.de",
help="URL for LDAP server for alternative user authorization")
parser.add_argument("--mqtt_host", default="10.10.21.2", help="IP address of MQTT broker")

View File

@ -31,6 +31,9 @@
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ url_for('register') }}">Token Registrierung</a>
<a class="dropdown-item" href="{{ url_for('list_tokens') }}">Token Übersicht</a>
{% if current_user.has_role('super_admin') %}
<a class="dropdown-item" href="{{ url_for('token_log') }}">Token Log</a>
{% endif %}
</div>
</li>
{% endif %}

View File

@ -0,0 +1,23 @@
{% extends 'base.html' %}
{% block header %}
{% block title %}<h1>Token Log</h1>{% endblock %}
{% endblock %}
{% block content %}
<table class="table">
<thead>
<td>Date</td>
<td>Timestamp</td>
<td>Message</td>
</thead>
<tbody>
{% for line in log %}
<tr>
<td>{{ line[0] }}</td>
<td>{{ line[1] }}</td>
<td>{{ line[2] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

View File

@ -458,6 +458,20 @@ def create_application(config):
inactive_tokens = {t: data for t, data in tokens.items() if data['inactive']}
return render_template('tokens.html', assigned_tokens=assigned_tokens, inactive_tokens=inactive_tokens)
@app.route('/token-log')
@roles_required('super_admin')
def token_log():
log = []
try:
with open(config.nfc_log) as f:
log += f.readlines()
log.reverse()
log = map(lambda l: l.split(' ', 2), log)
return render_template('token_log.html', log=log)
except Exception as e:
flash(f"NFC logfile {Path(config.nfc_log).absolute()} konnte nicht gelesen werden. Exception: {e}")
return redirect('/')
# routes for registering, editing and deleting tokens
@app.route('/register-token', methods=['GET', 'POST'])
@roles_required('admin')