Merge pull request #965 from cshore-firmware/pull-request-odhcpd-mac
authorDaniel Dickinson <cshoredaniel@users.noreply.github.com>
Tue, 7 Feb 2017 21:00:09 +0000 (16:00 -0500)
committerGitHub <noreply@github.com>
Tue, 7 Feb 2017 21:00:09 +0000 (16:00 -0500)
base: status: For odhpcd leases display MAC formatted with colons

1  2 
modules/luci-base/luasrc/tools/status.lua

@@@ -26,18 -26,17 +26,18 @@@ local function dhcp_leases_common(famil
                                break
                        else
                                local ts, mac, ip, name, duid = ln:match("^(%d+) (%S+) (%S+) (%S+) (%S+)")
 +                              local expire = tonumber(ts) or 0
                                if ts and mac and ip and name and duid then
                                        if family == 4 and not ip:match(":") then
                                                rv[#rv+1] = {
 -                                                      expires  = os.difftime(tonumber(ts) or 0, os.time()),
 +                                                      expires  = (expire ~= 0) and os.difftime(expire, os.time()),
                                                        macaddr  = mac,
                                                        ipaddr   = ip,
                                                        hostname = (name ~= "*") and name
                                                }
                                        elseif family == 6 and ip:match(":") then
                                                rv[#rv+1] = {
 -                                                      expires  = os.difftime(tonumber(ts) or 0, os.time()),
 +                                                      expires  = (expire ~= 0) and os.difftime(expire, os.time()),
                                                        ip6addr  = ip,
                                                        duid     = (duid ~= "*") and duid,
                                                        hostname = (name ~= "*") and name
                                                hostname = (name ~= "-") and name
                                        }
                                elseif ip and iaid == "ipv4" and family == 4 then
+                                       local mac, mac1, mac2, mac3, mac4, mac5, mac6
+                                       if duid and type(duid) == "string" then
+                                                mac1, mac2, mac3, mac4, mac5, mac6 = duid:match("^(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)(%x%x)$")
+                                       end
+                                       if not (mac1 and mac2 and mac3 and mac4 and mac5 and mac6) then
+                                               mac = "FF:FF:FF:FF:FF:FF"
+                                       else
+                                               mac = mac1..":"..mac2..":"..mac3..":"..mac4..":"..mac5..":"..mac6
+                                       end
                                        rv[#rv+1] = {
                                                expires  = (expire >= 0) and os.difftime(expire, os.time()),
                                                macaddr  = duid,
+                                               macaddr  = mac:lower(),
                                                ipaddr   = ip,
                                                hostname = (name ~= "-") and name
                                        }