Add latest changes

Dieser Commit ist enthalten in:
2025-07-03 20:38:33 +00:00
Ursprung 63f3d92724
Commit 6f6cde65db
129 geänderte Dateien mit 3998 neuen und 1199 gelöschten Zeilen

Datei anzeigen

@@ -193,29 +193,27 @@ def get_license_devices(license_id):
cur.execute("""
SELECT
dr.id,
dr.hardware_id,
dr.hardware_fingerprint,
dr.device_name,
dr.device_type,
dr.first_seen as registration_date,
dr.last_seen,
dr.first_activated_at as registration_date,
dr.last_seen_at,
dr.is_active,
dr.operating_system,
dr.ip_address,
(SELECT COUNT(*) FROM sessions s
WHERE s.license_key = l.license_key
AND s.hardware_id = dr.hardware_id
AND s.is_active = true) as active_sessions
(SELECT COUNT(*) FROM license_sessions ls
WHERE ls.device_registration_id = dr.id
AND ls.ended_at IS NULL) as active_sessions
FROM device_registrations dr
JOIN licenses l ON dr.license_id = l.id
WHERE l.license_key = %s
ORDER BY dr.first_seen DESC
""", (license_data['license_key'],))
WHERE dr.license_id = %s
ORDER BY dr.last_seen_at DESC
""", (license_id,))
devices = []
for row in cur.fetchall():
devices.append({
'id': row[0],
'hardware_id': row[1],
'hardware_fingerprint': row[1],
'device_name': row[2],
'device_type': row[3],
'registration_date': row[4].isoformat() if row[4] else None,
@@ -268,22 +266,20 @@ def register_device(license_id):
# Prüfe Gerätelimit
cur.execute("""
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'],))
SELECT COUNT(*) FROM device_registrations
WHERE license_id = %s AND is_active = true
""", (license_id,))
active_device_count = cur.fetchone()[0]
if active_device_count >= license_data['device_limit']:
if active_device_count >= license_data.get('device_limit', 3):
return jsonify({'error': 'Gerätelimit erreicht'}), 400
# Prüfe ob Gerät bereits registriert
cur.execute("""
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))
SELECT id, is_active FROM device_registrations
WHERE license_id = %s AND hardware_fingerprint = %s
""", (license_id, hardware_id))
existing = cur.fetchone()
@@ -294,16 +290,18 @@ def register_device(license_id):
# Reaktiviere Gerät
cur.execute("""
UPDATE device_registrations
SET is_active = true, last_seen = CURRENT_TIMESTAMP
SET is_active = true, last_seen_at = CURRENT_TIMESTAMP
WHERE id = %s
""", (existing[0],))
else:
# Registriere neues Gerät
cur.execute("""
INSERT INTO device_registrations
(license_id, hardware_id, device_name, device_type, is_active)
VALUES (%s, %s, %s, %s, true)
""", (license_id, hardware_id, device_name, device_type))
(license_id, hardware_fingerprint, device_name, device_type, is_active,
first_activated_at, last_seen_at, operating_system, app_version)
VALUES (%s, %s, %s, %s, true, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, %s, %s)
""", (license_id, hardware_id, device_name, device_type,
data.get('operating_system', 'unknown'), data.get('app_version')))
conn.commit()
@@ -332,7 +330,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.hardware_id, l.license_key
SELECT dr.device_name, dr.hardware_fingerprint, l.license_key
FROM device_registrations dr
JOIN licenses l ON dr.license_id = l.id
WHERE dr.id = %s AND l.id = %s
@@ -345,15 +343,15 @@ def deactivate_device(license_id, device_id):
# Deaktiviere Gerät
cur.execute("""
UPDATE device_registrations
SET is_active = false
SET is_active = false, deactivated_at = CURRENT_TIMESTAMP, deactivated_by = %s
WHERE id = %s
""", (device_id,))
""", (session.get('username'), device_id))
# Beende aktive Sessions
cur.execute("""
UPDATE sessions
SET is_active = false, ended_at = CURRENT_TIMESTAMP
WHERE license_key = %s AND hardware_id = %s AND is_active = true
WHERE license_key = %s AND hardware_fingerprint = %s AND is_active = true
""", (device[2], device[1]))
conn.commit()
@@ -440,7 +438,7 @@ def bulk_delete_licenses():
try:
cur.execute("""
SELECT COUNT(*)
FROM activations
FROM device_registrations
WHERE license_id = %s
AND is_active = true
""", (license_id,))
@@ -451,7 +449,7 @@ def bulk_delete_licenses():
skipped_licenses.append(license_id)
continue
except:
# If activations table doesn't exist, continue
# If device_registrations table doesn't exist, continue
pass
# Delete associated data
@@ -468,7 +466,7 @@ def bulk_delete_licenses():
pass
try:
cur.execute("DELETE FROM activations WHERE license_id = %s", (license_id,))
cur.execute("DELETE FROM license_sessions WHERE license_id = %s", (license_id,))
except:
pass
@@ -946,9 +944,9 @@ def global_search():
# Suche in Sessions
cur.execute("""
SELECT id, license_key, username, hardware_id, is_active
SELECT id, license_key, username, hardware_fingerprint as hardware_id, is_active
FROM sessions
WHERE username ILIKE %s OR hardware_id ILIKE %s
WHERE username ILIKE %s OR hardware_fingerprint ILIKE %s
ORDER BY started_at DESC
LIMIT 10
""", (f'%{query}%', f'%{query}%'))