X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=modules%2Fluci-base%2Fluasrc%2Fsys.lua;h=84c747f2bd3bf1e864cbe08046f20d72ac2a3bad;hp=99f3ee291972f94cad34a6079560cbb630204c59;hb=a441721d32d06d18368bf236ad127ffccad0bef8;hpb=52a0787c3fd6ad066e98f3d81849c413d8ea3bd4 diff --git a/modules/luci-base/luasrc/sys.lua b/modules/luci-base/luasrc/sys.lua index 99f3ee291..84c747f2b 100644 --- a/modules/luci-base/luasrc/sys.lua +++ b/modules/luci-base/luasrc/sys.lua @@ -7,6 +7,7 @@ local table = require "table" local nixio = require "nixio" local fs = require "nixio.fs" local uci = require "luci.model.uci" +local ntm = require "luci.model.network" local luci = {} luci.util = require "luci.util" @@ -348,8 +349,10 @@ end function net.devices() local devs = {} + local seen = {} for k, v in ipairs(nixio.getifaddrs()) do - if v.family == "packet" then + if v.name and not seen[v.name] then + seen[v.name] = true devs[#devs+1] = v.name end end @@ -449,37 +452,19 @@ end wifi = {} function wifi.getiwinfo(ifname) - local stat, iwinfo = pcall(require, "iwinfo") - - if ifname then - local d, n = ifname:match("^(%w+)%.network(%d+)") - local wstate = luci.util.ubus("network.wireless", "status") or { } - - d = d or ifname - n = n and tonumber(n) or 1 - - if type(wstate[d]) == "table" and - type(wstate[d].interfaces) == "table" and - type(wstate[d].interfaces[n]) == "table" and - type(wstate[d].interfaces[n].ifname) == "string" - then - ifname = wstate[d].interfaces[n].ifname - else - ifname = d - end + ntm.init() - local t = stat and iwinfo.type(ifname) - local x = t and iwinfo[t] or { } - return setmetatable({}, { - __index = function(t, k) - if k == "ifname" then - return ifname - elseif x[k] then - return x[k](ifname) - end - end - }) + local wnet = ntm:get_wifinet(ifname) + if wnet and wnet.iwinfo then + return wnet.iwinfo end + + local wdev = ntm:get_wifidev(ifname) + if wdev and wdev.iwinfo then + return wdev.iwinfo + end + + return { ifname = ifname } end