From 06bfdfaf2a4da785b531512b28e17fea98e840ca Mon Sep 17 00:00:00 2001 From: UserIsMH Date: Mon, 9 Jun 2025 22:50:04 +0200 Subject: [PATCH] Testdaten Checkbox --- v2_adminpanel/app.py | 41 ++++++++++++++-------- v2_adminpanel/mark_resources_as_test.sql | 5 +++ v2_adminpanel/templates/add_resources.html | 14 ++++++-- v2_adminpanel/templates/dashboard.html | 4 +-- v2_adminpanel/templates/resources.html | 41 +++++++++++++++++----- 5 files changed, 76 insertions(+), 29 deletions(-) create mode 100644 v2_adminpanel/mark_resources_as_test.sql diff --git a/v2_adminpanel/app.py b/v2_adminpanel/app.py index a3f7a4e..9dec360 100644 --- a/v2_adminpanel/app.py +++ b/v2_adminpanel/app.py @@ -1360,7 +1360,7 @@ def dashboard(): security_level = 'success' security_level_text = 'NORMAL' - # Resource Pool Statistiken + # Resource Pool Statistiken (nur Live-Daten, keine Testdaten) cur.execute(""" SELECT resource_type, @@ -1369,6 +1369,7 @@ def dashboard(): COUNT(*) FILTER (WHERE status = 'quarantine') as quarantine, COUNT(*) as total FROM resource_pools + WHERE is_test = FALSE GROUP BY resource_type """) @@ -3163,6 +3164,9 @@ def resources(): conn = get_connection() cur = conn.cursor() + # Prüfe ob Testdaten angezeigt werden sollen (gleiche Logik wie bei Kunden) + show_test = request.args.get('show_test', 'false').lower() == 'true' + # Statistiken abrufen cur.execute(""" SELECT @@ -3172,8 +3176,9 @@ def resources(): COUNT(*) FILTER (WHERE status = 'quarantine') as quarantine, COUNT(*) as total FROM resource_pools + WHERE is_test = %s GROUP BY resource_type - """) + """, (show_test,)) stats = {} for row in cur.fetchall(): @@ -3185,7 +3190,7 @@ def resources(): 'available_percent': round((row[1] / row[4] * 100) if row[4] > 0 else 0, 1) } - # Letzte Aktivitäten + # Letzte Aktivitäten (gefiltert nach Test/Live) cur.execute(""" SELECT rh.action, @@ -3196,9 +3201,10 @@ def resources(): rh.details FROM resource_history rh JOIN resource_pools rp ON rh.resource_id = rp.id + WHERE rp.is_test = %s ORDER BY rh.action_at DESC LIMIT 10 - """) + """, (show_test,)) recent_activities = cur.fetchall() # Ressourcen-Liste mit Pagination @@ -3226,9 +3232,9 @@ def resources(): FROM resource_pools rp LEFT JOIN licenses l ON rp.allocated_to_license = l.id LEFT JOIN customers c ON l.customer_id = c.id - WHERE 1=1 + WHERE rp.is_test = %s """ - params = [] + params = [show_test] if resource_type: query += " AND rp.resource_type = %s" @@ -3268,6 +3274,7 @@ def resources(): resource_type=resource_type, status_filter=status_filter, search=search, + show_test=show_test, datetime=datetime, timedelta=timedelta) @@ -3275,16 +3282,20 @@ def resources(): @login_required def add_resources(): """Ressourcen zum Pool hinzufügen""" + # Hole show_test Parameter für die Anzeige + show_test = request.args.get('show_test', 'false').lower() == 'true' + if request.method == 'POST': resource_type = request.form.get('resource_type') resources_text = request.form.get('resources_text', '') + is_test = request.form.get('is_test') == 'on' # Checkbox für Testdaten # Parse resources (one per line) resources = [r.strip() for r in resources_text.split('\n') if r.strip()] if not resources: flash('Keine Ressourcen angegeben', 'error') - return redirect(url_for('add_resources')) + return redirect(url_for('add_resources', show_test=show_test)) conn = get_connection() cur = conn.cursor() @@ -3295,10 +3306,10 @@ def add_resources(): for resource_value in resources: try: cur.execute(""" - INSERT INTO resource_pools (resource_type, resource_value, status_changed_by) - VALUES (%s, %s, %s) + INSERT INTO resource_pools (resource_type, resource_value, status_changed_by, is_test) + VALUES (%s, %s, %s, %s) ON CONFLICT (resource_type, resource_value) DO NOTHING - """, (resource_type, resource_value, session['username'])) + """, (resource_type, resource_value, session['username'], is_test)) if cur.rowcount > 0: added += 1 @@ -3323,13 +3334,13 @@ def add_resources(): conn.close() log_audit('CREATE', 'resource_pool', None, - new_values={'type': resource_type, 'added': added, 'duplicates': duplicates}, - additional_info=f"{added} Ressourcen hinzugefügt, {duplicates} Duplikate übersprungen") + new_values={'type': resource_type, 'added': added, 'duplicates': duplicates, 'is_test': is_test}, + additional_info=f"{added} {'Test-' if is_test else ''}Ressourcen hinzugefügt, {duplicates} Duplikate übersprungen") - flash(f'{added} Ressourcen hinzugefügt, {duplicates} Duplikate übersprungen', 'success') - return redirect(url_for('resources')) + flash(f'{added} {"Test-" if is_test else ""}Ressourcen hinzugefügt, {duplicates} Duplikate übersprungen', 'success') + return redirect(url_for('resources', show_test=show_test)) - return render_template('add_resources.html') + return render_template('add_resources.html', show_test=show_test) @app.route('/resources/quarantine/', methods=['POST']) @login_required diff --git a/v2_adminpanel/mark_resources_as_test.sql b/v2_adminpanel/mark_resources_as_test.sql new file mode 100644 index 0000000..2377e7a --- /dev/null +++ b/v2_adminpanel/mark_resources_as_test.sql @@ -0,0 +1,5 @@ +-- Markiere alle existierenden Ressourcen als Testdaten +UPDATE resource_pools SET is_test = TRUE WHERE is_test = FALSE OR is_test IS NULL; + +-- Zeige Anzahl der aktualisierten Ressourcen +SELECT COUNT(*) as updated_resources FROM resource_pools WHERE is_test = TRUE; \ No newline at end of file diff --git a/v2_adminpanel/templates/add_resources.html b/v2_adminpanel/templates/add_resources.html index 098857a..66cafcc 100644 --- a/v2_adminpanel/templates/add_resources.html +++ b/v2_adminpanel/templates/add_resources.html @@ -115,12 +115,12 @@

Ressourcen hinzufügen

Fügen Sie neue Domains, IPs oder Telefonnummern zum Pool hinzu

- + ← Zurück zur Übersicht -
+
@@ -265,12 +265,20 @@ my-website.io
+ + +
+ + +
-
+ +
+
+
+ + +
+
+
+
{% for type, data in stats.items() %} @@ -246,6 +260,7 @@
+
@@ -272,7 +287,7 @@
@@ -417,13 +432,13 @@