Merge pull request #1735 from sumpfralle/olsr-jsoninfo-parser-handle-empty-result
[oweals/luci.git] / modules / luci-base / luasrc / tools / status.lua
index 635995310f640b758fa5d5afd79a0647c66c50ec..dc30c064c04bd73438e305debca54c2fc3436d8c 100644 (file)
@@ -6,21 +6,6 @@ module("luci.tools.status", package.seeall)
 local uci = require "luci.model.uci".cursor()
 local ipc = require "luci.ip"
 
-local function duid_to_mac(duid)
-       local b1, b2, b3, b4, b5, b6
-
-       -- DUID-LLT / Ethernet
-       if type(duid) == "string" and #duid == 28 then
-               b1, b2, b3, b4, b5, b6 = duid:match("^00010001(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)%x%x%x%x%x%x%x%x$")
-
-       -- DUID-LL / Ethernet
-       elseif type(duid) == "string" and #duid == 20 then
-               b1, b2, b3, b4, b5, b6 = duid:match("^00030001(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)$")
-       end
-
-       return b1 and ipc.checkmac(table.concat({ b1, b2, b3, b4, b5, b6 }, ":"))
-end
-
 local function dhcp_leases_common(family)
        local rv = { }
        local nfs = require "nixio.fs"
@@ -93,7 +78,7 @@ local function dhcp_leases_common(family)
                                elseif ip and iaid == "ipv4" and family == 4 then
                                        rv[#rv+1] = {
                                                expires  = (expire >= 0) and os.difftime(expire, os.time()),
-                                               macaddr  = ipc.checkmac(duid:gsub("^(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)$", "%1:%2:%3:%4:%5:%6")) or "00:00:00:00:00:00",
+                                               macaddr  = sys.net.duid_to_mac(duid) or "00:00:00:00:00:00",
                                                ipaddr   = ip,
                                                hostname = (name ~= "-") and name
                                        }
@@ -107,7 +92,7 @@ local function dhcp_leases_common(family)
                local _, lease
                local hosts = sys.net.host_hints()
                for _, lease in ipairs(rv) do
-                       local mac = duid_to_mac(lease.duid)
+                       local mac = sys.net.duid_to_mac(lease.duid)
                        local host = mac and hosts[mac]
                        if host then
                                if not lease.name then
@@ -263,43 +248,3 @@ function wifi_assoclist()
 
        return assoc
 end
-
-function switch_status(devs)
-       local dev
-       local switches = { }
-       for dev in devs:gmatch("[^%s,]+") do
-               local ports = { }
-               local swc = io.popen("swconfig dev %s show"
-                       % luci.util.shellquote(dev), "r")
-
-               if swc then
-                       local l
-                       repeat
-                               l = swc:read("*l")
-                               if l then
-                                       local port, up = l:match("port:(%d+) link:(%w+)")
-                                       if port then
-                                               local speed  = l:match(" speed:(%d+)")
-                                               local duplex = l:match(" (%w+)-duplex")
-                                               local txflow = l:match(" (txflow)")
-                                               local rxflow = l:match(" (rxflow)")
-                                               local auto   = l:match(" (auto)")
-
-                                               ports[#ports+1] = {
-                                                       port   = tonumber(port) or 0,
-                                                       speed  = tonumber(speed) or 0,
-                                                       link   = (up == "up"),
-                                                       duplex = (duplex == "full"),
-                                                       rxflow = (not not rxflow),
-                                                       txflow = (not not txflow),
-                                                       auto   = (not not auto)
-                                               }
-                                       end
-                               end
-                       until not l
-                       swc:close()
-               end
-               switches[dev] = ports
-       end
-       return switches
-end