Переглянути джерело

Use UCI for SSID names instead of ubus

- UCI get wireless.*.ssid works on this OpenWRT version
- Parse all SSIDs from uci show wireless
- Map hostapd.wlan0-1 -> first SSID, hostapd.wlan0-2 -> second SSID
Gogs 2 місяців тому
батько
коміт
6551fbc419
1 змінених файлів з 36 додано та 9 видалено
  1. 36 9
      package/src/client2server-minimal.lua

+ 36 - 9
package/src/client2server-minimal.lua

@@ -89,31 +89,58 @@ local function get_hostapd_interfaces()
     return interfaces
 end
 
--- Get SSID name for an interface
+-- Get SSID name for an interface via UCI
 local function get_ssid_name(iface)
-    local f = io.popen("ubus call " .. iface .. " get_status 2>/dev/null")
+    -- Parse all SSIDs from UCI and pick one based on interface
+    local f = io.popen("uci show wireless 2>/dev/null")
     if f then
         local result = f:read("*a")
         f:close()
-        local ssid = result:match('"ssid":"([^"]+)"')
-        return ssid or iface
+        -- Extract all ssid values
+        local ssids = {}
+        for ssid in result:gmatch("ssid='([^']+)'") do
+            if ssid and ssid ~= "" then
+                table.insert(ssids, ssid)
+            end
+        end
+        -- Map interface index to SSID
+        if iface == "hostapd.wlan0-1" and ssids[1] then
+            return ssids[1]
+        elseif iface == "hostapd.wlan0-2" and ssids[2] then
+            return ssids[2]
+        elseif ssids[1] then
+            return ssids[1]
+        end
     end
     return iface
 end
 
--- Get all SSID statuses
+-- Get all SSIDs mapped to interfaces
 local function get_all_ssids()
     local ssids = {}
     local interfaces = get_hostapd_interfaces()
     for _, iface in ipairs(interfaces) do
-        local f = io.popen("ubus call " .. iface .. " get_status 2>/dev/null")
+        local ssid = get_ssid_name(iface)
+        ssids[iface] = { ssid = ssid }
+    end
+    return ssids
+end
+
+-- Get all SSID statuses via UCI
+local function get_all_ssids()
+    local ssids = {}
+    local interfaces = get_hostapd_interfaces()
+    for _, iface in ipairs(interfaces) do
+        local ssid = get_ssid_name(iface)
+        -- Check if enabled via UCI
+        local f = io.popen("uci get wireless." .. iface .. ".disabled 2>/dev/null")
+        local enabled = true
         if f then
             local result = f:read("*a")
             f:close()
-            local enabled = result:match('"enabled":%s*(%a+)')
-            local ssid = result:match('"ssid":"([^"]+)"') or iface
-            ssids[iface] = { enabled = (enabled == "true"), ssid = ssid }
+            enabled = (result:gsub("%s+$", "") ~= "1")
         end
+        ssids[iface] = { enabled = enabled, ssid = ssid }
     end
     return ssids
 end