✨feature: Add editable hostname and operating system
Release / Build and Push Docker Image (push) Successful in 4m56s
Release / Build and Push Docker Image (push) Successful in 4m56s
This commit is contained in:
+33
-2
@@ -238,7 +238,12 @@ def fetch_devices() -> list[dict]:
|
||||
with get_conn() as conn:
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT id, ip, hostname, os_name, mac, vendor, is_active, first_seen, last_seen
|
||||
SELECT id, ip,
|
||||
COALESCE(custom_hostname, hostname) AS hostname,
|
||||
COALESCE(custom_os_name, os_name) AS os_name,
|
||||
custom_hostname,
|
||||
custom_os_name,
|
||||
mac, vendor, is_active, first_seen, last_seen
|
||||
FROM devices
|
||||
ORDER BY is_active DESC, ip ASC
|
||||
"""
|
||||
@@ -250,7 +255,14 @@ def fetch_device(device_id: int) -> dict | None:
|
||||
with get_conn() as conn:
|
||||
device = conn.execute(
|
||||
"""
|
||||
SELECT id, ip, hostname, os_name, mac, vendor, is_active, first_seen, last_seen
|
||||
SELECT id, ip,
|
||||
COALESCE(custom_hostname, hostname) AS hostname,
|
||||
COALESCE(custom_os_name, os_name) AS os_name,
|
||||
custom_hostname,
|
||||
custom_os_name,
|
||||
hostname AS detected_hostname,
|
||||
os_name AS detected_os_name,
|
||||
mac, vendor, is_active, first_seen, last_seen
|
||||
FROM devices
|
||||
WHERE id = ?
|
||||
""",
|
||||
@@ -282,6 +294,25 @@ def fetch_device(device_id: int) -> dict | None:
|
||||
return result
|
||||
|
||||
|
||||
def update_device_identity(device_id: int, hostname: str | None, os_name: str | None) -> dict | None:
|
||||
normalized_hostname = (hostname or "").strip() or None
|
||||
normalized_os_name = (os_name or "").strip() or None
|
||||
|
||||
with get_conn() as conn:
|
||||
updated = conn.execute(
|
||||
"""
|
||||
UPDATE devices
|
||||
SET custom_hostname = ?, custom_os_name = ?
|
||||
WHERE id = ?
|
||||
""",
|
||||
(normalized_hostname, normalized_os_name, device_id),
|
||||
)
|
||||
if updated.rowcount == 0:
|
||||
return None
|
||||
|
||||
return fetch_device(device_id)
|
||||
|
||||
|
||||
def fetch_scans(limit: int = 20) -> list[dict]:
|
||||
with get_conn() as conn:
|
||||
rows = conn.execute(
|
||||
|
||||
Reference in New Issue
Block a user