Dieser Commit ist enthalten in:
2025-06-07 16:33:05 +02:00
Ursprung 2743f3ff9b
Commit b3dc80a38a
15 geänderte Dateien mit 877 neuen und 4 gelöschten Zeilen

Datei anzeigen

@@ -11,7 +11,9 @@
"Bash(docker exec:*)", "Bash(docker exec:*)",
"Bash(python3:*)", "Bash(python3:*)",
"Bash(docker-compose restart:*)", "Bash(docker-compose restart:*)",
"Bash(docker-compose build:*)" "Bash(docker-compose build:*)",
"Bash(docker restart:*)",
"Bash(docker network inspect:*)"
], ],
"deny": [] "deny": []
} }

Datei anzeigen

@@ -330,3 +330,29 @@ Die Session-Daten werden erst gefüllt, wenn der License Server API implementier
- CSV mit Semikolon-Trennung für deutsche Excel-Kompatibilität - CSV mit Semikolon-Trennung für deutsche Excel-Kompatibilität
- Automatische Spaltenbreite in Excel - Automatische Spaltenbreite in Excel
- BOM für UTF-8 CSV (Excel-Kompatibilität) - BOM für UTF-8 CSV (Excel-Kompatibilität)
### 2025-01-06 - Audit-Log implementiert
- Vollständiges Änderungsprotokoll für alle Aktionen
- Filterbare Übersicht mit Pagination
- Detaillierte Anzeige von Änderungen
**Neue Features:**
- **Audit-Log-Tabelle**: Speichert alle Änderungen mit Zeitstempel, Benutzer, IP
- **Protokollierte Aktionen**: CREATE, UPDATE, DELETE, LOGIN, LOGOUT, EXPORT
- **JSON-Speicherung**: Alte und neue Werte als JSONB für flexible Abfragen
- **Filter-Optionen**: Nach Benutzer, Aktion und Entität
- **Detail-Anzeige**: Aufklappbare Änderungsdetails
- **Navigation**: Audit-Link in allen Templates
**Geänderte/Neue Dateien:**
- v2_adminpanel/init.sql (audit_log Tabelle mit Indizes)
- v2_adminpanel/app.py (log_audit() Funktion und audit_log() Route)
- v2_adminpanel/templates/audit_log.html (neu erstellt)
- Alle Templates (Audit-Navigation hinzugefügt)
**Technische Details:**
- JSONB für strukturierte Datenspeicherung
- Performance-Indizes auf timestamp, username und entity
- Farbcodierung für verschiedene Aktionen
- 50 Einträge pro Seite mit Pagination
- IP-Adresse und User-Agent Tracking

5
v2/cookies.txt Normale Datei
Datei anzeigen

@@ -0,0 +1,5 @@
# Netscape HTTP Cookie File
# https://curl.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
#HttpOnly_localhost FALSE / FALSE 1751984506 session NYjsxmcb81rBYjc17nkaARMbfQAgYxkTegLkLrxWfmM

Datei anzeigen

@@ -1,5 +1,6 @@
import os import os
import psycopg2 import psycopg2
from psycopg2.extras import Json
from flask import Flask, render_template, request, redirect, session, url_for, send_file from flask import Flask, render_template, request, redirect, session, url_for, send_file
from flask_session import Session from flask_session import Session
from functools import wraps from functools import wraps
@@ -7,6 +8,7 @@ from dotenv import load_dotenv
import pandas as pd import pandas as pd
from datetime import datetime from datetime import datetime
import io import io
import json
load_dotenv() load_dotenv()
@@ -39,6 +41,37 @@ def get_connection():
conn.set_client_encoding('UTF8') conn.set_client_encoding('UTF8')
return conn return conn
# Audit-Log-Funktion
def log_audit(action, entity_type, entity_id=None, old_values=None, new_values=None, additional_info=None):
"""Protokolliert Änderungen im Audit-Log"""
conn = get_connection()
cur = conn.cursor()
try:
username = session.get('username', 'system')
ip_address = request.remote_addr if request else None
user_agent = request.headers.get('User-Agent') if request else None
# Konvertiere Dictionaries zu JSONB
old_json = Json(old_values) if old_values else None
new_json = Json(new_values) if new_values else None
cur.execute("""
INSERT INTO audit_log
(username, action, entity_type, entity_id, old_values, new_values,
ip_address, user_agent, additional_info)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
""", (username, action, entity_type, entity_id, old_json, new_json,
ip_address, user_agent, additional_info))
conn.commit()
except Exception as e:
print(f"Audit log error: {e}")
conn.rollback()
finally:
cur.close()
conn.close()
@app.route("/login", methods=["GET", "POST"]) @app.route("/login", methods=["GET", "POST"])
def login(): def login():
if request.method == "POST": if request.method == "POST":
@@ -55,6 +88,7 @@ def login():
(username == admin2_user and password == admin2_pass)): (username == admin2_user and password == admin2_pass)):
session['logged_in'] = True session['logged_in'] = True
session['username'] = username session['username'] = username
log_audit('LOGIN', 'user', additional_info=f"Erfolgreiche Anmeldung")
return redirect(url_for('dashboard')) return redirect(url_for('dashboard'))
else: else:
return render_template("login.html", error="Ungültige Anmeldedaten") return render_template("login.html", error="Ungültige Anmeldedaten")
@@ -63,6 +97,8 @@ def login():
@app.route("/logout") @app.route("/logout")
def logout(): def logout():
username = session.get('username', 'unknown')
log_audit('LOGOUT', 'user', additional_info=f"Abmeldung")
session.pop('logged_in', None) session.pop('logged_in', None)
session.pop('username', None) session.pop('username', None)
return redirect(url_for('login')) return redirect(url_for('login'))
@@ -190,9 +226,22 @@ def create_license():
cur.execute(""" cur.execute("""
INSERT INTO licenses (license_key, customer_id, license_type, valid_from, valid_until, is_active) INSERT INTO licenses (license_key, customer_id, license_type, valid_from, valid_until, is_active)
VALUES (%s, %s, %s, %s, %s, TRUE) VALUES (%s, %s, %s, %s, %s, TRUE)
RETURNING id
""", (license_key, customer_id, license_type, valid_from, valid_until)) """, (license_key, customer_id, license_type, valid_from, valid_until))
license_id = cur.fetchone()[0]
conn.commit() conn.commit()
# Audit-Log
log_audit('CREATE', 'license', license_id,
new_values={
'license_key': license_key,
'customer_name': name,
'customer_email': email,
'license_type': license_type,
'valid_from': valid_from,
'valid_until': valid_until
})
cur.close() cur.close()
conn.close() conn.close()
@@ -290,6 +339,13 @@ def edit_license(license_id):
cur = conn.cursor() cur = conn.cursor()
if request.method == "POST": if request.method == "POST":
# Alte Werte für Audit-Log abrufen
cur.execute("""
SELECT license_key, license_type, valid_from, valid_until, is_active
FROM licenses WHERE id = %s
""", (license_id,))
old_license = cur.fetchone()
# Update license # Update license
license_key = request.form["license_key"] license_key = request.form["license_key"]
license_type = request.form["license_type"] license_type = request.form["license_type"]
@@ -305,6 +361,24 @@ def edit_license(license_id):
""", (license_key, license_type, valid_from, valid_until, is_active, license_id)) """, (license_key, license_type, valid_from, valid_until, is_active, license_id))
conn.commit() conn.commit()
# Audit-Log
log_audit('UPDATE', 'license', license_id,
old_values={
'license_key': old_license[0],
'license_type': old_license[1],
'valid_from': str(old_license[2]),
'valid_until': str(old_license[3]),
'is_active': old_license[4]
},
new_values={
'license_key': license_key,
'license_type': license_type,
'valid_from': valid_from,
'valid_until': valid_until,
'is_active': is_active
})
cur.close() cur.close()
conn.close() conn.close()
@@ -334,9 +408,28 @@ def delete_license(license_id):
conn = get_connection() conn = get_connection()
cur = conn.cursor() cur = conn.cursor()
# Lizenzdetails für Audit-Log abrufen
cur.execute("""
SELECT l.license_key, c.name, l.license_type
FROM licenses l
JOIN customers c ON l.customer_id = c.id
WHERE l.id = %s
""", (license_id,))
license_info = cur.fetchone()
cur.execute("DELETE FROM licenses WHERE id = %s", (license_id,)) cur.execute("DELETE FROM licenses WHERE id = %s", (license_id,))
conn.commit() conn.commit()
# Audit-Log
if license_info:
log_audit('DELETE', 'license', license_id,
old_values={
'license_key': license_info[0],
'customer_name': license_info[1],
'license_type': license_info[2]
})
cur.close() cur.close()
conn.close() conn.close()
@@ -418,6 +511,10 @@ def edit_customer(customer_id):
cur = conn.cursor() cur = conn.cursor()
if request.method == "POST": if request.method == "POST":
# Alte Werte für Audit-Log abrufen
cur.execute("SELECT name, email FROM customers WHERE id = %s", (customer_id,))
old_customer = cur.fetchone()
# Update customer # Update customer
name = request.form["name"] name = request.form["name"]
email = request.form["email"] email = request.form["email"]
@@ -429,6 +526,18 @@ def edit_customer(customer_id):
""", (name, email, customer_id)) """, (name, email, customer_id))
conn.commit() conn.commit()
# Audit-Log
log_audit('UPDATE', 'customer', customer_id,
old_values={
'name': old_customer[0],
'email': old_customer[1]
},
new_values={
'name': name,
'email': email
})
cur.close() cur.close()
conn.close() conn.close()
@@ -477,10 +586,23 @@ def delete_customer(customer_id):
conn.close() conn.close()
return redirect("/customers") return redirect("/customers")
# Kundendetails für Audit-Log abrufen
cur.execute("SELECT name, email FROM customers WHERE id = %s", (customer_id,))
customer_info = cur.fetchone()
# Kunde löschen wenn keine Lizenzen vorhanden # Kunde löschen wenn keine Lizenzen vorhanden
cur.execute("DELETE FROM customers WHERE id = %s", (customer_id,)) cur.execute("DELETE FROM customers WHERE id = %s", (customer_id,))
conn.commit() conn.commit()
# Audit-Log
if customer_info:
log_audit('DELETE', 'customer', customer_id,
old_values={
'name': customer_info[0],
'email': customer_info[1]
})
cur.close() cur.close()
conn.close() conn.close()
@@ -588,6 +710,10 @@ def export_licenses():
# Export Format # Export Format
export_format = request.args.get('format', 'excel') export_format = request.args.get('format', 'excel')
# Audit-Log
log_audit('EXPORT', 'license',
additional_info=f"Export aller Lizenzen als {export_format.upper()}")
filename = f'lizenzen_export_{datetime.now().strftime("%Y%m%d_%H%M%S")}' filename = f'lizenzen_export_{datetime.now().strftime("%Y%m%d_%H%M%S")}'
if export_format == 'csv': if export_format == 'csv':
@@ -665,6 +791,10 @@ def export_customers():
# Export Format # Export Format
export_format = request.args.get('format', 'excel') export_format = request.args.get('format', 'excel')
# Audit-Log
log_audit('EXPORT', 'customer',
additional_info=f"Export aller Kunden als {export_format.upper()}")
filename = f'kunden_export_{datetime.now().strftime("%Y%m%d_%H%M%S")}' filename = f'kunden_export_{datetime.now().strftime("%Y%m%d_%H%M%S")}'
if export_format == 'csv': if export_format == 'csv':
@@ -708,5 +838,78 @@ def export_customers():
download_name=f'{filename}.xlsx' download_name=f'{filename}.xlsx'
) )
@app.route("/audit")
@login_required
def audit_log():
conn = get_connection()
cur = conn.cursor()
# Parameter
filter_user = request.args.get('user', '').strip()
filter_action = request.args.get('action', '').strip()
filter_entity = request.args.get('entity', '').strip()
page = request.args.get('page', 1, type=int)
per_page = 50
# SQL Query mit optionalen Filtern
query = """
SELECT id, timestamp, username, action, entity_type, entity_id,
old_values, new_values, ip_address, user_agent, additional_info
FROM audit_log
WHERE 1=1
"""
params = []
# Filter
if filter_user:
query += " AND LOWER(username) LIKE LOWER(%s)"
params.append(f'%{filter_user}%')
if filter_action:
query += " AND action = %s"
params.append(filter_action)
if filter_entity:
query += " AND entity_type = %s"
params.append(filter_entity)
# Gesamtanzahl für Pagination
count_query = "SELECT COUNT(*) FROM (" + query + ") as count_table"
cur.execute(count_query, params)
total = cur.fetchone()[0]
# Pagination
offset = (page - 1) * per_page
query += " ORDER BY timestamp DESC LIMIT %s OFFSET %s"
params.extend([per_page, offset])
cur.execute(query, params)
logs = cur.fetchall()
# JSON-Werte parsen
parsed_logs = []
for log in logs:
parsed_log = list(log)
# old_values und new_values sind bereits Dictionaries (JSONB)
# Keine Konvertierung nötig
parsed_logs.append(parsed_log)
# Pagination Info
total_pages = (total + per_page - 1) // per_page
cur.close()
conn.close()
return render_template("audit_log.html",
logs=parsed_logs,
filter_user=filter_user,
filter_action=filter_action,
filter_entity=filter_entity,
page=page,
total_pages=total_pages,
total=total,
username=session.get('username'))
if __name__ == "__main__": if __name__ == "__main__":
app.run(host="0.0.0.0", port=443, ssl_context='adhoc') app.run(host="0.0.0.0", port=443, ssl_context='adhoc')

Datei anzeigen

@@ -29,3 +29,23 @@ CREATE TABLE IF NOT EXISTS sessions (
ended_at TIMESTAMP, ended_at TIMESTAMP,
is_active BOOLEAN DEFAULT TRUE is_active BOOLEAN DEFAULT TRUE
); );
-- Audit-Log-Tabelle für Änderungsprotokolle
CREATE TABLE IF NOT EXISTS audit_log (
id SERIAL PRIMARY KEY,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
username TEXT NOT NULL,
action TEXT NOT NULL,
entity_type TEXT NOT NULL,
entity_id INTEGER,
old_values JSONB,
new_values JSONB,
ip_address TEXT,
user_agent TEXT,
additional_info TEXT
);
-- Index für bessere Performance bei Abfragen
CREATE INDEX idx_audit_log_timestamp ON audit_log(timestamp DESC);
CREATE INDEX idx_audit_log_username ON audit_log(username);
CREATE INDEX idx_audit_log_entity ON audit_log(entity_type, entity_id);

Datei anzeigen

@@ -0,0 +1,235 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Audit-Log - Admin Panel</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
.audit-details {
font-size: 0.85em;
max-width: 300px;
overflow: hidden;
text-overflow: ellipsis;
}
.json-display {
background-color: #f8f9fa;
padding: 5px;
border-radius: 3px;
font-family: monospace;
font-size: 0.8em;
max-height: 100px;
overflow-y: auto;
}
.action-CREATE { color: #28a745; }
.action-UPDATE { color: #007bff; }
.action-DELETE { color: #dc3545; }
.action-LOGIN { color: #17a2b8; }
.action-LOGOUT { color: #6c757d; }
.action-EXPORT { color: #ffc107; }
</style>
</head>
<body class="bg-light">
<nav class="navbar navbar-dark bg-dark">
<div class="container">
<span class="navbar-brand">🎛️ Lizenzverwaltung</span>
<div class="d-flex align-items-center">
<span class="text-white me-3">Angemeldet als: {{ username }}</span>
<a href="/logout" class="btn btn-outline-light btn-sm">Abmelden</a>
</div>
</div>
</nav>
<div class="container py-5">
<div class="d-flex justify-content-between align-items-center mb-4">
<h2>📋 Audit-Log</h2>
<div>
<a href="/" class="btn btn-secondary">📊 Dashboard</a>
<a href="/licenses" class="btn btn-secondary">📋 Lizenzen</a>
<a href="/customers" class="btn btn-secondary">👥 Kunden</a>
<a href="/sessions" class="btn btn-secondary">🟢 Sessions</a>
</div>
</div>
<!-- Filter -->
<div class="card mb-3">
<div class="card-body">
<form method="get" action="/audit">
<div class="row g-3 align-items-end">
<div class="col-md-3">
<label for="user" class="form-label">Benutzer</label>
<input type="text" class="form-control" id="user" name="user"
placeholder="Benutzername..." value="{{ filter_user }}">
</div>
<div class="col-md-3">
<label for="action" class="form-label">Aktion</label>
<select class="form-select" id="action" name="action">
<option value="">Alle Aktionen</option>
<option value="CREATE" {% if filter_action == 'CREATE' %}selected{% endif %}> Erstellt</option>
<option value="UPDATE" {% if filter_action == 'UPDATE' %}selected{% endif %}>✏️ Bearbeitet</option>
<option value="DELETE" {% if filter_action == 'DELETE' %}selected{% endif %}>🗑️ Gelöscht</option>
<option value="LOGIN" {% if filter_action == 'LOGIN' %}selected{% endif %}>🔑 Anmeldung</option>
<option value="LOGOUT" {% if filter_action == 'LOGOUT' %}selected{% endif %}>🚪 Abmeldung</option>
<option value="EXPORT" {% if filter_action == 'EXPORT' %}selected{% endif %}>📥 Export</option>
</select>
</div>
<div class="col-md-3">
<label for="entity" class="form-label">Entität</label>
<select class="form-select" id="entity" name="entity">
<option value="">Alle Entitäten</option>
<option value="license" {% if filter_entity == 'license' %}selected{% endif %}>Lizenz</option>
<option value="customer" {% if filter_entity == 'customer' %}selected{% endif %}>Kunde</option>
<option value="user" {% if filter_entity == 'user' %}selected{% endif %}>Benutzer</option>
<option value="session" {% if filter_entity == 'session' %}selected{% endif %}>Session</option>
</select>
</div>
<div class="col-md-3">
<button type="submit" class="btn btn-primary">Filter anwenden</button>
<a href="/audit" class="btn btn-outline-secondary">Zurücksetzen</a>
</div>
</div>
</form>
</div>
</div>
<!-- Audit Log Tabelle -->
<div class="card">
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Zeitstempel</th>
<th>Benutzer</th>
<th>Aktion</th>
<th>Entität</th>
<th>Details</th>
<th>IP-Adresse</th>
</tr>
</thead>
<tbody>
{% for log in logs %}
<tr>
<td>{{ log[1].strftime('%d.%m.%Y %H:%M:%S') }}</td>
<td><strong>{{ log[2] }}</strong></td>
<td>
<span class="action-{{ log[3] }}">
{% if log[3] == 'CREATE' %} Erstellt
{% elif log[3] == 'UPDATE' %}✏️ Bearbeitet
{% elif log[3] == 'DELETE' %}🗑️ Gelöscht
{% elif log[3] == 'LOGIN' %}🔑 Anmeldung
{% elif log[3] == 'LOGOUT' %}🚪 Abmeldung
{% elif log[3] == 'EXPORT' %}📥 Export
{% else %}{{ log[3] }}
{% endif %}
</span>
</td>
<td>
{{ log[4] }}
{% if log[5] %}
<small class="text-muted">#{{ log[5] }}</small>
{% endif %}
</td>
<td class="audit-details">
{% if log[10] %}
<div class="mb-1"><small class="text-muted">{{ log[10] }}</small></div>
{% endif %}
{% if log[6] and log[3] == 'DELETE' %}
<details>
<summary>Gelöschte Werte</summary>
<div class="json-display">
{% for key, value in log[6].items() %}
<strong>{{ key }}:</strong> {{ value }}<br>
{% endfor %}
</div>
</details>
{% elif log[6] and log[7] and log[3] == 'UPDATE' %}
<details>
<summary>Änderungen anzeigen</summary>
<div class="json-display">
<strong>Vorher:</strong><br>
{% for key, value in log[6].items() %}
{% if log[7][key] != value %}
{{ key }}: {{ value }}<br>
{% endif %}
{% endfor %}
<hr class="my-1">
<strong>Nachher:</strong><br>
{% for key, value in log[7].items() %}
{% if log[6][key] != value %}
{{ key }}: {{ value }}<br>
{% endif %}
{% endfor %}
</div>
</details>
{% elif log[7] and log[3] == 'CREATE' %}
<details>
<summary>Erstellte Werte</summary>
<div class="json-display">
{% for key, value in log[7].items() %}
<strong>{{ key }}:</strong> {{ value }}<br>
{% endfor %}
</div>
</details>
{% endif %}
</td>
<td>
<small class="text-muted">{{ log[8] or '-' }}</small>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if not logs %}
<div class="text-center py-5">
<p class="text-muted">Keine Audit-Log-Einträge gefunden.</p>
</div>
{% endif %}
</div>
<!-- Pagination -->
{% if total_pages > 1 %}
<nav aria-label="Seitennavigation" class="mt-3">
<ul class="pagination justify-content-center">
<!-- Erste Seite -->
<li class="page-item {% if page == 1 %}disabled{% endif %}">
<a class="page-link" href="{{ url_for('audit_log', page=1, user=filter_user, action=filter_action, entity=filter_entity) }}">Erste</a>
</li>
<!-- Vorherige Seite -->
<li class="page-item {% if page == 1 %}disabled{% endif %}">
<a class="page-link" href="{{ url_for('audit_log', page=page-1, user=filter_user, action=filter_action, entity=filter_entity) }}"></a>
</li>
<!-- Seitenzahlen -->
{% for p in range(1, total_pages + 1) %}
{% if p >= page - 2 and p <= page + 2 %}
<li class="page-item {% if p == page %}active{% endif %}">
<a class="page-link" href="{{ url_for('audit_log', page=p, user=filter_user, action=filter_action, entity=filter_entity) }}">{{ p }}</a>
</li>
{% endif %}
{% endfor %}
<!-- Nächste Seite -->
<li class="page-item {% if page == total_pages %}disabled{% endif %}">
<a class="page-link" href="{{ url_for('audit_log', page=page+1, user=filter_user, action=filter_action, entity=filter_entity) }}"></a>
</li>
<!-- Letzte Seite -->
<li class="page-item {% if page == total_pages %}disabled{% endif %}">
<a class="page-link" href="{{ url_for('audit_log', page=total_pages, user=filter_user, action=filter_action, entity=filter_entity) }}">Letzte</a>
</li>
</ul>
<p class="text-center text-muted">
Seite {{ page }} von {{ total_pages }} | Gesamt: {{ total }} Einträge
</p>
</nav>
{% endif %}
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

Datei anzeigen

@@ -24,6 +24,7 @@
<a href="/create" class="btn btn-primary"> Neue Lizenz</a> <a href="/create" class="btn btn-primary"> Neue Lizenz</a>
<a href="/licenses" class="btn btn-secondary">📋 Lizenzen</a> <a href="/licenses" class="btn btn-secondary">📋 Lizenzen</a>
<a href="/sessions" class="btn btn-secondary">🟢 Sessions</a> <a href="/sessions" class="btn btn-secondary">🟢 Sessions</a>
<a href="/audit" class="btn btn-secondary">📋 Audit</a>
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn btn-info dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"> <button type="button" class="btn btn-info dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
📥 Export 📥 Export

Datei anzeigen

@@ -35,6 +35,7 @@
<a href="/licenses" class="btn btn-secondary">📋 Lizenzen</a> <a href="/licenses" class="btn btn-secondary">📋 Lizenzen</a>
<a href="/customers" class="btn btn-secondary">👥 Kunden</a> <a href="/customers" class="btn btn-secondary">👥 Kunden</a>
<a href="/sessions" class="btn btn-secondary">🟢 Sessions</a> <a href="/sessions" class="btn btn-secondary">🟢 Sessions</a>
<a href="/audit" class="btn btn-secondary">📋 Audit</a>
</div> </div>
</div> </div>

Datei anzeigen

@@ -19,7 +19,14 @@
<div class="container py-5"> <div class="container py-5">
<div class="d-flex justify-content-between align-items-center mb-4"> <div class="d-flex justify-content-between align-items-center mb-4">
<h2>Kunde bearbeiten</h2> <h2>Kunde bearbeiten</h2>
<a href="/customers" class="btn btn-secondary">← Zurück zur Übersicht</a> <div>
<a href="/" class="btn btn-secondary">📈 Dashboard</a>
<a href="/create" class="btn btn-primary"> Neue Lizenz</a>
<a href="/licenses" class="btn btn-secondary">📋 Lizenzen</a>
<a href="/customers" class="btn btn-secondary">👥 Kunden</a>
<a href="/sessions" class="btn btn-secondary">🟢 Sessions</a>
<a href="/audit" class="btn btn-secondary">📋 Audit</a>
</div>
</div> </div>
<div class="card mb-4"> <div class="card mb-4">

Datei anzeigen

@@ -19,7 +19,14 @@
<div class="container py-5"> <div class="container py-5">
<div class="d-flex justify-content-between align-items-center mb-4"> <div class="d-flex justify-content-between align-items-center mb-4">
<h2>Lizenz bearbeiten</h2> <h2>Lizenz bearbeiten</h2>
<a href="/licenses" class="btn btn-secondary">← Zurück zur Übersicht</a> <div>
<a href="/" class="btn btn-secondary">📈 Dashboard</a>
<a href="/create" class="btn btn-primary"> Neue Lizenz</a>
<a href="/licenses" class="btn btn-secondary">📋 Lizenzen</a>
<a href="/customers" class="btn btn-secondary">👥 Kunden</a>
<a href="/sessions" class="btn btn-secondary">🟢 Sessions</a>
<a href="/audit" class="btn btn-secondary">📋 Audit</a>
</div>
</div> </div>
<div class="card"> <div class="card">

Datei anzeigen

@@ -24,6 +24,7 @@
<a href="/licenses" class="btn btn-secondary">📋 Lizenzen</a> <a href="/licenses" class="btn btn-secondary">📋 Lizenzen</a>
<a href="/customers" class="btn btn-secondary">👥 Kunden</a> <a href="/customers" class="btn btn-secondary">👥 Kunden</a>
<a href="/sessions" class="btn btn-secondary">🟢 Sessions</a> <a href="/sessions" class="btn btn-secondary">🟢 Sessions</a>
<a href="/audit" class="btn btn-secondary">📋 Audit</a>
</div> </div>
</div> </div>

Datei anzeigen

@@ -29,6 +29,7 @@
<a href="/create" class="btn btn-primary"> Neue Lizenz</a> <a href="/create" class="btn btn-primary"> Neue Lizenz</a>
<a href="/customers" class="btn btn-secondary">👥 Kunden</a> <a href="/customers" class="btn btn-secondary">👥 Kunden</a>
<a href="/sessions" class="btn btn-secondary">🟢 Sessions</a> <a href="/sessions" class="btn btn-secondary">🟢 Sessions</a>
<a href="/audit" class="btn btn-secondary">📋 Audit</a>
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn btn-info dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"> <button type="button" class="btn btn-info dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
📥 Export 📥 Export

Datei anzeigen

@@ -28,6 +28,7 @@
<a href="/" class="btn btn-secondary">📊 Dashboard</a> <a href="/" class="btn btn-secondary">📊 Dashboard</a>
<a href="/licenses" class="btn btn-secondary">📋 Lizenzen</a> <a href="/licenses" class="btn btn-secondary">📋 Lizenzen</a>
<a href="/customers" class="btn btn-secondary">👥 Kunden</a> <a href="/customers" class="btn btn-secondary">👥 Kunden</a>
<a href="/audit" class="btn btn-secondary">📋 Audit</a>
</div> </div>
</div> </div>

125
v2_testing/test_audit_json.py Normale Datei
Datei anzeigen

@@ -0,0 +1,125 @@
#!/usr/bin/env python3
import requests
import urllib3
import subprocess
import json
# Disable SSL warnings
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
base_url = "https://localhost:443"
admin_user = {"username": "rac00n", "password": "1248163264"}
def login(session):
"""Login to admin panel"""
login_data = {
"username": admin_user["username"],
"password": admin_user["password"]
}
response = session.post(f"{base_url}/login", data=login_data, verify=False, allow_redirects=False)
return response.status_code == 302
def test_json_logging():
"""Test JSON value logging in audit log"""
session = requests.Session()
login(session)
print("Testing JSON Value Storage in Audit Log")
print("=" * 50)
# 1. Create a license (should log new_values as JSON)
print("\n1. Creating license to test JSON logging...")
license_data = {
"customer_name": "JSON Test GmbH",
"email": "json@test.de",
"license_key": "JSON-TEST-KEY",
"license_type": "full",
"valid_from": "2025-01-01",
"valid_until": "2025-12-31"
}
response = session.post(f"{base_url}/create", data=license_data, verify=False, allow_redirects=False)
print("✓ License created")
# 2. Get the license ID
result = subprocess.run([
"docker", "exec", "db", "psql", "-U", "adminuser", "-d", "meinedatenbank", "-t",
"-c", "SELECT id FROM licenses WHERE license_key = 'JSON-TEST-KEY';"
], capture_output=True, text=True)
license_id = result.stdout.strip()
if license_id:
# 3. Edit the license (should log both old_values and new_values)
print("\n2. Editing license to test old/new JSON values...")
# First get the edit page to ensure we have the right form
response = session.get(f"{base_url}/license/edit/{license_id}", verify=False)
# Now update
updated_data = {
"license_key": "JSON-TEST-UPDATED",
"license_type": "test",
"valid_from": "2025-01-01",
"valid_until": "2025-06-30",
"is_active": "on"
}
response = session.post(f"{base_url}/license/edit/{license_id}",
data=updated_data,
verify=False,
allow_redirects=False)
print("✓ License updated")
# 4. Check the audit log for JSON values
print("\n3. Checking audit log for JSON values...")
result = subprocess.run([
"docker", "exec", "db", "psql", "-U", "adminuser", "-d", "meinedatenbank",
"-c", """SELECT action, entity_type,
CASE WHEN old_values IS NULL THEN 'NULL'
ELSE jsonb_pretty(old_values) END as old_vals,
CASE WHEN new_values IS NULL THEN 'NULL'
ELSE jsonb_pretty(new_values) END as new_vals
FROM audit_log
WHERE entity_type IN ('license', 'customer')
AND (old_values IS NOT NULL OR new_values IS NOT NULL)
ORDER BY timestamp DESC
LIMIT 5;"""
], capture_output=True, text=True)
print(result.stdout)
# 5. Test specific JSON queries
print("\n4. Testing JSON queries...")
# Query for specific license key in new_values
result = subprocess.run([
"docker", "exec", "db", "psql", "-U", "adminuser", "-d", "meinedatenbank", "-t",
"-c", """SELECT COUNT(*)
FROM audit_log
WHERE new_values->>'license_key' LIKE 'JSON%';"""
], capture_output=True, text=True)
count = int(result.stdout.strip())
if count > 0:
print(f"✓ Found {count} entries with JSON license keys")
# Query for updates (where both old and new values exist)
result = subprocess.run([
"docker", "exec", "db", "psql", "-U", "adminuser", "-d", "meinedatenbank", "-t",
"-c", """SELECT COUNT(*)
FROM audit_log
WHERE old_values IS NOT NULL
AND new_values IS NOT NULL;"""
], capture_output=True, text=True)
update_count = int(result.stdout.strip())
print(f"✓ Found {update_count} UPDATE entries with both old and new values")
# 6. Clean up test data
print("\n5. Cleaning up test data...")
subprocess.run([
"docker", "exec", "db", "psql", "-U", "adminuser", "-d", "meinedatenbank",
"-c", "DELETE FROM licenses WHERE license_key LIKE 'JSON%';"
], capture_output=True)
print("✓ Test data cleaned up")
# Run the test
test_json_logging()

238
v2_testing/test_audit_log.py Normale Datei
Datei anzeigen

@@ -0,0 +1,238 @@
#!/usr/bin/env python3
import requests
import urllib3
import subprocess
import time
import json
# Disable SSL warnings
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
base_url = "https://localhost:443"
admin_user = {"username": "rac00n", "password": "1248163264"}
def login(session):
"""Login to admin panel"""
login_data = {
"username": admin_user["username"],
"password": admin_user["password"]
}
response = session.post(f"{base_url}/login", data=login_data, verify=False, allow_redirects=False)
return response.status_code == 302
def test_audit_table():
"""Test if audit_log table exists"""
print("1. Checking Audit Log Table:")
print("-" * 40)
result = subprocess.run([
"docker", "exec", "db", "psql", "-U", "adminuser", "-d", "meinedatenbank",
"-c", "\\d audit_log"
], capture_output=True, text=True)
if "Table \"public.audit_log\"" in result.stdout:
print("✓ Audit log table exists")
print("\nTable structure:")
print(result.stdout)
return True
else:
print("✗ Audit log table not found - creating it")
# Create table
subprocess.run([
"docker", "exec", "db", "psql", "-U", "adminuser", "-d", "meinedatenbank",
"-f", "/docker-entrypoint-initdb.d/init.sql"
], capture_output=True)
return False
def test_audit_logging():
"""Test various actions to generate audit logs"""
session = requests.Session()
print("\n2. Testing Audit Log Generation:")
print("-" * 40)
# Test 1: Login
print("Testing LOGIN audit...")
login(session)
print("✓ Login performed")
# Test 2: Create license
print("\nTesting CREATE audit...")
license_data = {
"customer_name": "Audit Test GmbH",
"email": "audit@test.de",
"license_key": "AUDIT-TEST-001",
"license_type": "test",
"valid_from": "2025-01-01",
"valid_until": "2025-12-31"
}
response = session.post(f"{base_url}/create", data=license_data, verify=False, allow_redirects=False)
if response.status_code == 302:
print("✓ License created")
# Test 3: Export
print("\nTesting EXPORT audit...")
response = session.get(f"{base_url}/export/licenses?format=csv", verify=False)
if response.status_code == 200:
print("✓ Export performed")
# Test 4: Logout
print("\nTesting LOGOUT audit...")
response = session.get(f"{base_url}/logout", verify=False, allow_redirects=False)
if response.status_code == 302:
print("✓ Logout performed")
# Wait for logs to be written
time.sleep(1)
def test_audit_page():
"""Test the audit log page"""
session = requests.Session()
login(session)
print("\n3. Testing Audit Log Page:")
print("-" * 40)
response = session.get(f"{base_url}/audit", verify=False)
if response.status_code == 200:
print("✓ Audit log page accessible")
content = response.text
# Check for expected elements
checks = [
("Audit-Log", "Page title"),
("Zeitstempel", "Timestamp column"),
("Benutzer", "User column"),
("Aktion", "Action column"),
("Entität", "Entity column"),
("IP-Adresse", "IP address column"),
("LOGIN", "Login action"),
("LOGOUT", "Logout action"),
("CREATE", "Create action"),
("EXPORT", "Export action")
]
found = 0
for check_text, description in checks:
if check_text in content:
found += 1
print(f"✓ Found {found}/{len(checks)} expected elements")
# Check filters
if '<select' in content and 'filter' in content.lower():
print("✓ Filter options available")
else:
print(f"✗ Failed to access audit log page: Status {response.status_code}")
def check_audit_logs_db():
"""Check audit logs directly in database"""
print("\n4. Database Audit Log Check:")
print("-" * 40)
result = subprocess.run([
"docker", "exec", "db", "psql", "-U", "adminuser", "-d", "meinedatenbank",
"-c", """SELECT action, entity_type, username,
CASE WHEN old_values IS NULL THEN 'NULL' ELSE 'JSON' END as old_v,
CASE WHEN new_values IS NULL THEN 'NULL' ELSE 'JSON' END as new_v,
additional_info
FROM audit_log
ORDER BY timestamp DESC
LIMIT 10;"""
], capture_output=True, text=True)
print(result.stdout)
# Count total logs
result = subprocess.run([
"docker", "exec", "db", "psql", "-U", "adminuser", "-d", "meinedatenbank", "-t",
"-c", "SELECT COUNT(*) FROM audit_log;"
], capture_output=True, text=True)
count = int(result.stdout.strip())
print(f"\nTotal audit log entries: {count}")
def test_audit_filters():
"""Test audit log filters"""
session = requests.Session()
login(session)
print("\n5. Testing Audit Log Filters:")
print("-" * 40)
# Test different filters
filters = [
("?action=LOGIN", "Filter by LOGIN action"),
("?user=rac00n", "Filter by username"),
("?entity=license", "Filter by entity type"),
("?page=2", "Pagination test")
]
for filter_param, description in filters:
response = session.get(f"{base_url}/audit{filter_param}", verify=False)
if response.status_code == 200:
print(f"{description}: Working")
else:
print(f"{description}: Failed")
def test_json_values():
"""Test JSON storage of old/new values"""
print("\n6. Testing JSON Value Storage:")
print("-" * 40)
# Get a recent update log with JSON values
result = subprocess.run([
"docker", "exec", "db", "psql", "-U", "adminuser", "-d", "meinedatenbank", "-t",
"-c", """SELECT new_values::text
FROM audit_log
WHERE action = 'CREATE'
AND new_values IS NOT NULL
LIMIT 1;"""
], capture_output=True, text=True)
if result.stdout.strip():
try:
json_data = json.loads(result.stdout.strip())
print("✓ JSON values stored correctly")
print(f"Sample JSON keys: {list(json_data.keys())}")
except:
print("✗ Invalid JSON format")
else:
print("✗ No JSON values found")
# Main execution
print("Testing Audit Log Functionality")
print("=" * 50)
# Ensure table exists
if not test_audit_table():
print("\nRestarting containers to create audit_log table...")
subprocess.run(["docker-compose", "down"], capture_output=True)
subprocess.run(["docker-compose", "up", "-d"], capture_output=True)
subprocess.run(["sleep", "7"], capture_output=True)
test_audit_table()
# Generate test data
test_audit_logging()
# Check results
test_audit_page()
check_audit_logs_db()
test_audit_filters()
test_json_values()
print("\n" + "=" * 50)
print("Audit Log Summary:")
print("-" * 40)
# Summary statistics
result = subprocess.run([
"docker", "exec", "db", "psql", "-U", "adminuser", "-d", "meinedatenbank",
"-c", """SELECT action, COUNT(*) as count
FROM audit_log
GROUP BY action
ORDER BY count DESC;"""
], capture_output=True, text=True)
print(result.stdout)