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

@@ -39,14 +39,16 @@ def get_licenses(show_fake=False):
with get_db_cursor(conn) as cur:
if show_fake:
cur.execute("""
SELECT l.*, c.name as customer_name
SELECT l.*, c.name as customer_name,
(SELECT COUNT(*) FROM license_sessions ls WHERE ls.license_id = l.id) as active_sessions
FROM licenses l
LEFT JOIN customers c ON l.customer_id = c.id
ORDER BY l.created_at DESC
""")
else:
cur.execute("""
SELECT l.*, c.name as customer_name
SELECT l.*, c.name as customer_name,
(SELECT COUNT(*) FROM license_sessions ls WHERE ls.license_id = l.id) as active_sessions
FROM licenses l
LEFT JOIN customers c ON l.customer_id = c.id
WHERE l.is_fake = false
@@ -70,7 +72,8 @@ def get_license_by_id(license_id):
with get_db_connection() as conn:
with get_db_cursor(conn) as cur:
cur.execute("""
SELECT l.*, c.name as customer_name
SELECT l.*, c.name as customer_name,
(SELECT COUNT(*) FROM license_sessions ls WHERE ls.license_id = l.id) as active_sessions
FROM licenses l
LEFT JOIN customers c ON l.customer_id = c.id
WHERE l.id = %s
@@ -86,6 +89,37 @@ def get_license_by_id(license_id):
return None
def get_license_session_stats(license_id):
"""Get session statistics for a specific license"""
try:
with get_db_connection() as conn:
with get_db_cursor(conn) as cur:
cur.execute("""
SELECT
l.device_limit,
l.concurrent_sessions_limit,
(SELECT COUNT(*) FROM device_registrations dr WHERE dr.license_id = l.id AND dr.is_active = true) as registered_devices,
(SELECT COUNT(*) FROM license_sessions ls WHERE ls.license_id = l.id) as active_sessions,
l.concurrent_sessions_limit - (SELECT COUNT(*) FROM license_sessions ls WHERE ls.license_id = l.id) as available_sessions
FROM licenses l
WHERE l.id = %s
""", (license_id,))
row = cur.fetchone()
if row:
return {
'device_limit': row[0],
'concurrent_sessions_limit': row[1],
'registered_devices': row[2],
'active_sessions': row[3],
'available_sessions': row[4]
}
return None
except Exception as e:
logger.error(f"Error fetching session stats for license {license_id}: {str(e)}")
return None
def get_customers(show_fake=False, search=None):
"""Get all customers from database"""
try:
@@ -175,4 +209,67 @@ def get_active_sessions():
return sessions
except Exception as e:
logger.error(f"Error fetching is_active sessions: {str(e)}")
return []
return []
def get_devices_for_license(license_id):
"""Get all registered devices for a specific license"""
try:
with get_db_connection() as conn:
with get_db_cursor(conn) as cur:
cur.execute("""
SELECT
id,
hardware_fingerprint,
device_name,
device_type,
operating_system,
app_version,
first_activated_at,
last_seen_at,
is_active,
ip_address,
(SELECT COUNT(*) FROM license_sessions ls
WHERE ls.device_registration_id = dr.id) as active_sessions
FROM device_registrations dr
WHERE dr.license_id = %s
ORDER BY dr.last_seen_at DESC
""", (license_id,))
columns = [desc[0] for desc in cur.description]
devices = []
for row in cur.fetchall():
device_dict = dict(zip(columns, row))
devices.append(device_dict)
return devices
except Exception as e:
logger.error(f"Error fetching devices for license {license_id}: {str(e)}")
return []
def check_device_limit(license_id):
"""Check if license has reached its device limit"""
try:
with get_db_connection() as conn:
with get_db_cursor(conn) as cur:
cur.execute("""
SELECT
l.device_limit,
COUNT(dr.id) as active_devices
FROM licenses l
LEFT JOIN device_registrations dr ON l.id = dr.license_id AND dr.is_active = true
WHERE l.id = %s
GROUP BY l.device_limit
""", (license_id,))
row = cur.fetchone()
if row:
return {
'device_limit': row[0],
'active_devices': row[1],
'limit_reached': row[1] >= row[0]
}
return None
except Exception as e:
logger.error(f"Error checking device limit for license {license_id}: {str(e)}")
return None