瀏覽代碼

Fix: More precise client detection per interface

- Query each interface separately
- Only detect clients if interface actually has clients
- First interface wins for duplicate MACs
Gogs 2 月之前
父節點
當前提交
d2442bcc0e
共有 1 個文件被更改,包括 18 次插入3 次删除
  1. 18 3
      package/src/client2server-minimal.lua

+ 18 - 3
package/src/client2server-minimal.lua

@@ -165,17 +165,32 @@ end
 local function get_wifi_clients()
     local clients = {}
     local interfaces = get_hostapd_interfaces()
+    
+    -- Get SSID mapping first
+    local ssid_map = {}
+    for _, iface in ipairs(interfaces) do
+        ssid_map[iface] = get_ssid_name(iface)
+    end
+    
+    -- Query each interface separately
     for _, iface in ipairs(interfaces) do
-        local ssid = get_ssid_name(iface)
         local f = io.popen("ubus call " .. iface .. " get_clients 2>/dev/null")
         if f then
             local result = f:read("*a")
             f:close()
-            for mac in result:gmatch('"([a-fA-F0-9:]+)"') do
-                clients[mac] = { iface = iface, ssid = ssid }
+            -- Check if there are actually clients (result contains "clients": {})
+            if result:find('"clients"') and not result:find('"clients":%s*{}') then
+                -- Extract MAC addresses - match pattern for valid MACs
+                for mac in result:gmatch('([a-fA-F0-9][a-fA-F0-9]:[a-fA-F0-9][a-fA-F0-9]:[a-fA-F0-9][a-fA-F0-9]:[a-fA-F0-9][a-fA-F0-9]:[a-fA-F0-9][a-fA-F0-9]:[a-fA-F0-9][a-fA-F0-9])') do
+                    -- Only add if not already tracked (first interface wins)
+                    if not clients[mac] then
+                        clients[mac] = { iface = iface, ssid = ssid_map[iface] }
+                    end
+                end
             end
         end
     end
+    
     return clients
 end