Bläddra i källkod

Fix: Move is_valid_mac function to top (before load_state uses it)

Gogs 2 månader sedan
förälder
incheckning
31f12bd580
1 ändrade filer med 18 tillägg och 18 borttagningar
  1. 18 18
      package/src/client2server-minimal.lua

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

@@ -18,6 +18,24 @@ local function http_post(event_type, data)
     local f = io.popen("curl -s -X POST '" .. cfg.server_url .. "/api/events' -H 'Content-Type: application/json' -d '" .. json .. "'", "r")
     local result = f:read("*a")
     f:close()
+end
+
+-- Validate MAC address (proper format with valid hex)
+local function is_valid_mac(mac)
+    if not mac or #mac ~= 17 then return false end
+    local parts = {}
+    for part in mac:gmatch("[a-fA-F0-9][a-fA-F0-9]") do
+        table.insert(parts, part)
+    end
+    if #parts ~= 6 then return false end
+    -- First byte: not 00 or FF
+    local first = tonumber(parts[1], 16)
+    if first == 0 or first == 255 then return false end
+    -- Second byte: not FF (multicast)
+    local second = tonumber(parts[2], 16)
+    if second == 255 then return false end
+    return true
+end
     return result
 end
 
@@ -165,24 +183,6 @@ end
 
 -- Get clients from ALL interfaces WITH their SSID
 -- Validate MAC address (proper format with valid hex)
-local function is_valid_mac(mac)
-    if not mac or #mac ~= 17 then return false end
-    -- Check format XX:XX:XX:XX:XX:XX
-    local parts = {}
-    for part in mac:gmatch("[a-fA-F0-9][a-fA-F0-9]") do
-        table.insert(parts, part)
-    end
-    -- Must have exactly 6 parts
-    if #parts ~= 6 then return false end
-    -- First byte must not be 00 or FF (invalid/broadcast)
-    local first = tonumber(parts[1], 16)
-    if first == 0 or first == 255 then return false end
-    -- Second byte must not be FF (multicast/broadcast address)
-    local second = tonumber(parts[2], 16)
-    if second == 255 then return false end
-    return true
-end
-
 local function get_wifi_clients()
     local clients = {}
     local interfaces = get_hostapd_interfaces()