diff --git a/docs/FILE_PERMISSIONS.md b/docs/FILE_PERMISSIONS.md index 51de6fb7..dd8c0f80 100755 --- a/docs/FILE_PERMISSIONS.md +++ b/docs/FILE_PERMISSIONS.md @@ -1,5 +1,13 @@ # Managing File Permissions for NetAlertX on Nginx with Docker +> [!TIP] +> If you are facing permission issues, try to start the container without mapping your volumes. If that works, then the issue is permission related. You can try e.g., the following command: +> ``` +> docker run -d --rm --network=host \ +> -e TZ=Europe/Berlin \ +> -e PORT=20211 \ +> jokobsk/netalertx:latest +> ``` NetAlertX runs on an Nginx web server. On Alpine Linux, Nginx operates as the `nginx` user (user ID 101, group ID 82 - `www-data`). Consequently, files accessed or written by the NetAlertX application are owned by `nginx:www-data`. Upon starting, NetAlertX changes the ownership of files on the host system mapped to `/app/config` and `/app/db` in the container to `nginx:www-data`. This ensures that Nginx can access and write to these files. Since the user in the Docker container is mapped to a user on the host system by ID:GID, the files in `/app/config` and `/app/db` on the host system are owned by a user with the same ID and GID (ID 101 and GID 82). On different systems, this ID:GID may belong to different users (on Debian, the user with ID 82 is `uuidd`), or there may not be a user with ID 82 at all. diff --git a/server/device.py b/server/device.py index a0f8d648..0f06ed81 100755 --- a/server/device.py +++ b/server/device.py @@ -267,7 +267,7 @@ def update_devices_data_from_scan (db): WHERE dev_MAC = cur_MAC) """) # Update only devices with empty or NULL vendors - mylog('debug', '[Update Devices] - 3 Vendor') + mylog('debug', '[Update Devices] - 3 cur_Vendor -> dev_Vendor') sql.execute("""UPDATE Devices SET dev_Vendor = ( SELECT cur_Vendor @@ -282,6 +282,86 @@ def update_devices_data_from_scan (db): WHERE dev_MAC = cur_MAC )""") + # Update only devices with empty or NULL dev_Network_Node_port + mylog('debug', '[Update Devices] - 3 cur_Port -> dev_Network_Node_port') + sql.execute("""UPDATE Devices + SET dev_Network_Node_port = ( + SELECT cur_Port + FROM CurrentScan + WHERE dev_MAC = cur_MAC + ) + WHERE + (dev_Network_Node_port = "" OR dev_Network_Node_port IS NULL) + AND EXISTS ( + SELECT 1 + FROM CurrentScan + WHERE dev_MAC = cur_MAC + )""") + + # Update only devices with empty or NULL dev_Network_Node_MAC_ADDR + mylog('debug', '[Update Devices] - 3 cur_NetworkNodeMAC -> dev_Network_Node_MAC_ADDR') + sql.execute("""UPDATE Devices + SET dev_Network_Node_MAC_ADDR = ( + SELECT cur_NetworkNodeMAC + FROM CurrentScan + WHERE dev_MAC = cur_MAC + ) + WHERE + (dev_Network_Node_MAC_ADDR = "" OR dev_Network_Node_MAC_ADDR IS NULL) + AND EXISTS ( + SELECT 1 + FROM CurrentScan + WHERE dev_MAC = cur_MAC + )""") + + # Update only devices with empty or NULL dev_Network_Node_MAC_ADDR + mylog('debug', '[Update Devices] - 3 cur_NetworkSite -> dev_NetworkSite') + sql.execute("""UPDATE Devices + SET dev_NetworkSite = ( + SELECT cur_NetworkSite + FROM CurrentScan + WHERE dev_MAC = cur_MAC + ) + WHERE + (dev_NetworkSite = "" OR dev_NetworkSite IS NULL) + AND EXISTS ( + SELECT 1 + FROM CurrentScan + WHERE dev_MAC = cur_MAC + )""") + + # Update only devices with empty or NULL dev_SSID + mylog('debug', '[Update Devices] - 3 cur_SSID -> dev_SSID') + sql.execute("""UPDATE Devices + SET dev_SSID = ( + SELECT cur_SSID + FROM CurrentScan + WHERE dev_MAC = cur_MAC + ) + WHERE + (dev_SSID = "" OR dev_SSID IS NULL) + AND EXISTS ( + SELECT 1 + FROM CurrentScan + WHERE dev_MAC = cur_MAC + )""") + + # Update only devices with empty or NULL dev_DeviceType + mylog('debug', '[Update Devices] - 3 cur_Type -> dev_DeviceType') + sql.execute("""UPDATE Devices + SET dev_DeviceType = ( + SELECT cur_Type + FROM CurrentScan + WHERE dev_MAC = cur_MAC + ) + WHERE + (dev_DeviceType = "" OR dev_DeviceType IS NULL) + AND EXISTS ( + SELECT 1 + FROM CurrentScan + WHERE dev_MAC = cur_MAC + )""") + # Update (unknown) or (name not found) Names if available mylog('debug','[Update Devices] - 4 Unknown Name') sql.execute (""" UPDATE Devices