Löschen Lizenz Schutz

Dieser Commit ist enthalten in:
2025-06-21 16:41:08 +02:00
Ursprung 1451a23ff3
Commit fec588ba06
3 geänderte Dateien mit 177 neuen und 22 gelöschten Zeilen

Datei anzeigen

@@ -175,6 +175,9 @@ def edit_license(license_id):
@license_bp.route("/license/delete/<int:license_id>", methods=["POST"])
@login_required
def delete_license(license_id):
# Check for force parameter
force_delete = request.form.get('force', 'false').lower() == 'true'
conn = get_connection()
cur = conn.cursor()
@@ -185,21 +188,77 @@ def delete_license(license_id):
flash('Lizenz nicht gefunden!', 'error')
return redirect(url_for('licenses.licenses'))
# Safety check: Don't delete active licenses unless forced
if license_data.get('is_active') and not force_delete:
flash(f'Lizenz {license_data["license_key"]} ist noch aktiv! Bitte deaktivieren Sie die Lizenz zuerst oder nutzen Sie "Erzwungenes Löschen".', 'warning')
return redirect(url_for('licenses.licenses'))
# Check for recent activity (heartbeats in last 24 hours)
try:
cur.execute("""
SELECT COUNT(*)
FROM license_heartbeats
WHERE license_id = %s
AND timestamp > NOW() - INTERVAL '24 hours'
""", (license_id,))
recent_heartbeats = cur.fetchone()[0]
if recent_heartbeats > 0 and not force_delete:
flash(f'Lizenz {license_data["license_key"]} hatte in den letzten 24 Stunden {recent_heartbeats} Aktivitäten! '
f'Die Lizenz wird möglicherweise noch aktiv genutzt. Bitte prüfen Sie dies vor dem Löschen.', 'danger')
return redirect(url_for('licenses.licenses'))
except Exception as e:
# If heartbeats table doesn't exist, continue
logging.warning(f"Could not check heartbeats: {str(e)}")
# Check for active devices/activations
try:
cur.execute("""
SELECT COUNT(*)
FROM activations
WHERE license_id = %s
AND is_active = true
""", (license_id,))
active_devices = cur.fetchone()[0]
if active_devices > 0 and not force_delete:
flash(f'Lizenz {license_data["license_key"]} hat {active_devices} aktive Geräte! '
f'Bitte deaktivieren Sie alle Geräte vor dem Löschen.', 'danger')
return redirect(url_for('licenses.licenses'))
except Exception as e:
# If activations table doesn't exist, continue
logging.warning(f"Could not check activations: {str(e)}")
# Delete from sessions first
cur.execute("DELETE FROM sessions WHERE license_key = %s", (license_data['license_key'],))
# Delete from license_heartbeats if exists
try:
cur.execute("DELETE FROM license_heartbeats WHERE license_id = %s", (license_id,))
except:
pass
# Delete from activations if exists
try:
cur.execute("DELETE FROM activations WHERE license_id = %s", (license_id,))
except:
pass
# Delete the license
cur.execute("DELETE FROM licenses WHERE id = %s", (license_id,))
conn.commit()
# Log deletion
# Log deletion with force flag
log_audit('DELETE', 'license', license_id,
old_values={
'license_key': license_data['license_key'],
'customer_name': license_data['customer_name'],
'customer_email': license_data['customer_email']
})
'customer_email': license_data['customer_email'],
'was_active': license_data.get('is_active'),
'forced': force_delete
},
additional_info=f"{'Forced deletion' if force_delete else 'Normal deletion'}")
flash(f'Lizenz {license_data["license_key"]} erfolgreich gelöscht!', 'success')