bug fix - route probleme

Dieser Commit ist enthalten in:
2025-06-18 19:40:14 +02:00
Ursprung 4bfe1983a3
Commit 55e8a66f9f
21 geänderte Dateien mit 3847 neuen und 97 gelöschten Zeilen

Datei anzeigen

@@ -55,7 +55,7 @@ def api_customers():
@api_bp.route("/license/<int:license_id>/toggle", methods=["POST"])
@login_required
def toggle_license(license_id):
"""Toggle license active status"""
"""Toggle license is_active status"""
conn = get_connection()
cur = conn.cursor()
@@ -192,32 +192,38 @@ def get_license_devices(license_id):
cur.execute("""
SELECT
dr.id,
dr.device_id,
dr.hardware_id,
dr.device_name,
dr.device_type,
dr.registration_date,
dr.first_seen as registration_date,
dr.last_seen,
dr.is_active,
dr.operating_system,
dr.ip_address,
(SELECT COUNT(*) FROM sessions s
WHERE s.license_key = dr.license_key
AND s.device_id = dr.device_id
AND s.active = true) as active_sessions
WHERE s.license_key = l.license_key
AND s.hardware_id = dr.hardware_id
AND s.is_active = true) as active_sessions
FROM device_registrations dr
WHERE dr.license_key = %s
ORDER BY dr.registration_date DESC
JOIN licenses l ON dr.license_id = l.id
WHERE l.license_key = %s
ORDER BY dr.first_seen DESC
""", (license_data['license_key'],))
devices = []
for row in cur.fetchall():
devices.append({
'id': row[0],
'device_id': row[1],
'hardware_id': row[1],
'device_name': row[2],
'device_type': row[3],
'registration_date': row[4].isoformat() if row[4] else None,
'last_seen': row[5].isoformat() if row[5] else None,
'is_active': row[6],
'active_sessions': row[7]
'operating_system': row[7] or 'Unknown',
'ip_address': row[8] or 'Unknown',
'active_sessions': row[9],
'first_seen': row[4].isoformat() if row[4] else None
})
return jsonify({
@@ -241,11 +247,11 @@ def register_device(license_id):
"""Registriere ein neues Gerät für eine Lizenz"""
data = request.get_json()
device_id = data.get('device_id')
hardware_id = data.get('hardware_id')
device_name = data.get('device_name')
device_type = data.get('device_type', 'unknown')
if not device_id or not device_name:
if not hardware_id or not device_name:
return jsonify({'error': 'Geräte-ID und Name erforderlich'}), 400
conn = get_connection()
@@ -259,8 +265,9 @@ def register_device(license_id):
# Prüfe Gerätelimit
cur.execute("""
SELECT COUNT(*) FROM device_registrations
WHERE license_key = %s AND is_active = true
SELECT COUNT(*) FROM device_registrations dr
JOIN licenses l ON dr.license_id = l.id
WHERE l.license_key = %s AND dr.is_active = true
""", (license_data['license_key'],))
active_device_count = cur.fetchone()[0]
@@ -270,9 +277,10 @@ def register_device(license_id):
# Prüfe ob Gerät bereits registriert
cur.execute("""
SELECT id, is_active FROM device_registrations
WHERE license_key = %s AND device_id = %s
""", (license_data['license_key'], device_id))
SELECT dr.id, dr.is_active FROM device_registrations dr
JOIN licenses l ON dr.license_id = l.id
WHERE l.license_key = %s AND dr.hardware_id = %s
""", (license_data['license_key'], hardware_id))
existing = cur.fetchone()
@@ -290,15 +298,15 @@ def register_device(license_id):
# Registriere neues Gerät
cur.execute("""
INSERT INTO device_registrations
(license_key, device_id, device_name, device_type, is_active)
(license_id, hardware_id, device_name, device_type, is_active)
VALUES (%s, %s, %s, %s, true)
""", (license_data['license_key'], device_id, device_name, device_type))
""", (license_id, hardware_id, device_name, device_type))
conn.commit()
# Audit-Log
log_audit('DEVICE_REGISTER', 'license', license_id,
additional_info=f"Gerät {device_name} ({device_id}) registriert")
additional_info=f"Gerät {device_name} ({hardware_id}) registriert")
return jsonify({'success': True})
@@ -321,7 +329,7 @@ def deactivate_device(license_id, device_id):
try:
# Prüfe ob Gerät zur Lizenz gehört
cur.execute("""
SELECT dr.device_name, dr.device_id, l.license_key
SELECT dr.device_name, dr.hardware_id, l.license_key
FROM device_registrations dr
JOIN licenses l ON dr.license_key = l.license_key
WHERE dr.id = %s AND l.id = %s
@@ -341,8 +349,8 @@ def deactivate_device(license_id, device_id):
# Beende aktive Sessions
cur.execute("""
UPDATE sessions
SET active = false, logout_time = CURRENT_TIMESTAMP
WHERE license_key = %s AND device_id = %s AND active = true
SET is_active = false, ended_at = CURRENT_TIMESTAMP
WHERE license_key = %s AND hardware_id = %s AND is_active = true
""", (device[2], device[1]))
conn.commit()
@@ -450,11 +458,11 @@ def quick_edit_license(license_id):
old_values['valid_until'] = str(current_license['valid_until'])
new_values['valid_until'] = data['valid_until']
if 'active' in data:
if 'is_active' in data:
updates.append("is_active = %s")
params.append(bool(data['active']))
params.append(bool(data['is_active']))
old_values['is_active'] = current_license['is_active']
new_values['is_active'] = bool(data['active'])
new_values['is_active'] = bool(data['is_active'])
if not updates:
return jsonify({'error': 'Keine Änderungen angegeben'}), 400
@@ -846,10 +854,10 @@ def global_search():
# Suche in Sessions
cur.execute("""
SELECT id, license_key, username, device_id, active
SELECT id, license_key, username, hardware_id, is_active
FROM sessions
WHERE username ILIKE %s OR device_id ILIKE %s
ORDER BY login_time DESC
WHERE username ILIKE %s OR hardware_id ILIKE %s
ORDER BY started_at DESC
LIMIT 10
""", (f'%{query}%', f'%{query}%'))
@@ -858,8 +866,8 @@ def global_search():
'id': row[0],
'license_key': row[1],
'username': row[2],
'device_id': row[3],
'active': row[4]
'hardware_id': row[3],
'is_active': row[4]
})
return jsonify(results)