modules/admin-full: utilize luci.model.network, add uptime in iface_status action
This commit is contained in:
parent
9d83aafb78
commit
a493e28e91
1 changed files with 34 additions and 42 deletions
|
@ -189,25 +189,16 @@ end
|
||||||
|
|
||||||
function iface_status()
|
function iface_status()
|
||||||
local path = luci.dispatcher.context.requestpath
|
local path = luci.dispatcher.context.requestpath
|
||||||
local x = luci.model.uci.cursor_state()
|
local netm = require "luci.model.network".init()
|
||||||
local rv = { }
|
local rv = { }
|
||||||
|
|
||||||
local iface
|
local iface
|
||||||
for iface in path[#path]:gmatch("[%w%.%-]+") do
|
for iface in path[#path]:gmatch("[%w%.%-]+") do
|
||||||
local dev
|
local net = netm:get_network(iface)
|
||||||
if x:get("network", iface, "type") == "bridge" then
|
if net then
|
||||||
dev = "br-" .. iface
|
|
||||||
else
|
|
||||||
dev = x:get("network", iface, "device") or ""
|
|
||||||
end
|
|
||||||
|
|
||||||
if #dev == 0 or dev:match("^%d") or dev:match("%W") then
|
|
||||||
dev = x:get("network", iface, "ifname") or ""
|
|
||||||
dev = dev:match("%S+")
|
|
||||||
end
|
|
||||||
|
|
||||||
local info
|
local info
|
||||||
local data = { id = iface }
|
local dev = net:ifname()
|
||||||
|
local data = { id = iface, uptime = net:uptime() }
|
||||||
for _, info in ipairs(nixio.getifaddrs()) do
|
for _, info in ipairs(nixio.getifaddrs()) do
|
||||||
local name = info.name:match("[^:]+")
|
local name = info.name:match("[^:]+")
|
||||||
if name == dev then
|
if name == dev then
|
||||||
|
@ -240,6 +231,7 @@ function iface_status()
|
||||||
rv[#rv+1] = data
|
rv[#rv+1] = data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if #rv > 0 then
|
if #rv > 0 then
|
||||||
luci.http.prepare_content("application/json")
|
luci.http.prepare_content("application/json")
|
||||||
|
|
Loading…
Reference in a new issue