summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/luasrc
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2018-06-25 09:01:33 +0200
committerJo-Philipp Wich <jo@mein.io>2018-06-25 09:01:33 +0200
commite5ba594d77eed77d31d4b9b8c0e86026eb5a5fac (patch)
tree024000a15cab5bec318352d76b15ed9a0ff91072 /modules/luci-base/luasrc
parent86c6c60a0d3aded629efbf4bd5e4145dc077a29d (diff)
luci-base, luci-mod-admin-full: unify wifi assoclist code
Merge the assoclist code of the status overview and wireless overview pages into a single shared partial template. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/luasrc')
-rw-r--r--modules/luci-base/luasrc/tools/status.lua54
1 files changed, 52 insertions, 2 deletions
diff --git a/modules/luci-base/luasrc/tools/status.lua b/modules/luci-base/luasrc/tools/status.lua
index 06a9ad415..0059ccceb 100644
--- a/modules/luci-base/luasrc/tools/status.lua
+++ b/modules/luci-base/luasrc/tools/status.lua
@@ -113,6 +113,11 @@ function wifi_networks()
local net
for _, net in ipairs(dev:get_wifinets()) do
+ local a, an = nil, 0
+ for _, a in pairs(net:assoclist() or {}) do
+ an = an + 1
+ end
+
rd.networks[#rd.networks+1] = {
name = net:shortname(),
link = net:adminlink(),
@@ -128,10 +133,10 @@ function wifi_networks()
noise = net:noise(),
bitrate = net:bitrate(),
ifname = net:ifname(),
- assoclist = net:assoclist(),
country = net:country(),
txpower = net:txpower(),
txpoweroff = net:txpower_offset(),
+ num_assoc = an,
disabled = (dev:get("disabled") == "1" or
net:get("disabled") == "1")
}
@@ -165,7 +170,6 @@ function wifi_network(id)
noise = net:noise(),
bitrate = net:bitrate(),
ifname = net:ifname(),
- assoclist = net:assoclist(),
country = net:country(),
txpower = net:txpower(),
txpoweroff = net:txpower_offset(),
@@ -182,6 +186,52 @@ function wifi_network(id)
return { }
end
+function wifi_assoclist()
+ local sys = require "luci.sys"
+ local ntm = require "luci.model.network".init()
+ local hosts = sys.net.host_hints()
+
+ local assoc = {}
+ local _, dev, net, bss
+
+ for _, dev in ipairs(ntm:get_wifidevs()) do
+ local radioname = dev:get_i18n()
+
+ for _, net in ipairs(dev:get_wifinets()) do
+ local netname = net:shortname()
+ local netlink = net:adminlink()
+ local ifname = net:ifname()
+
+ for _, bss in pairs(net:assoclist() or {}) do
+ local host = hosts[_]
+
+ bss.bssid = _
+ bss.ifname = ifname
+ bss.radio = radioname
+ bss.name = netname
+ bss.link = netlink
+
+ bss.host_name = (host) and (host.name or host.ipv4 or host.ipv6)
+ bss.host_hint = (host and host.name and (host.ipv4 or host.ipv6)) and (host.ipv4 or host.ipv6)
+
+ assoc[#assoc+1] = bss
+ end
+ end
+ end
+
+ table.sort(assoc, function(a, b)
+ if a.radio ~= b.radio then
+ return a.radio < b.radio
+ elseif a.ifname ~= b.ifname then
+ return a.ifname < b.ifname
+ else
+ return a.bssid < b.bssid
+ end
+ end)
+
+ return assoc
+end
+
function switch_status(devs)
local dev
local switches = { }