X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=modules%2Fluci-base%2Fluasrc%2Ftools%2Fstatus.lua;h=1c4038735faf4a04da415d33cd6355ba9436e74d;hp=0efc51be23a5145f5586074f1ce4fbf6ef214421;hb=9db5fa93afdbb4667e523cba0e6bde4e73a01150;hpb=1bb4822dca6113f73e3bc89e2acf15935e6f8e92 diff --git a/modules/luci-base/luasrc/tools/status.lua b/modules/luci-base/luasrc/tools/status.lua index 0efc51be2..1c4038735 100644 --- a/modules/luci-base/luasrc/tools/status.lua +++ b/modules/luci-base/luasrc/tools/status.lua @@ -1,24 +1,15 @@ ---[[ -LuCI - Lua Configuration Interface - -Copyright 2011 Jo-Philipp Wich - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -]]-- +-- Copyright 2011 Jo-Philipp Wich +-- Licensed to the public under the Apache License 2.0. module("luci.tools.status", package.seeall) local uci = require "luci.model.uci".cursor() +local ipc = require "luci.ip" local function dhcp_leases_common(family) local rv = { } local nfs = require "nixio.fs" - local leasefile = "/var/dhcp.leases" + local leasefile = "/tmp/dhcp.leases" uci:foreach("dhcp", "dnsmasq", function(s) @@ -36,17 +27,18 @@ local function dhcp_leases_common(family) 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()), - macaddr = mac, + expires = (expire ~= 0) and os.difftime(expire, os.time()), + macaddr = ipc.checkmac(mac) or "00:00:00:00:00:00", 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 @@ -58,25 +50,34 @@ local function dhcp_leases_common(family) fd:close() end - local fd = io.open("/tmp/hosts/odhcpd", "r") + local lease6file = "/tmp/hosts/odhcpd" + uci:foreach("dhcp", "odhcpd", + function(t) + if t.leasefile and nfs.access(t.leasefile) then + lease6file = t.leasefile + return false + end + end) + local fd = io.open(lease6file, "r") if fd then while true do local ln = fd:read("*l") if not ln then break else - local iface, duid, iaid, name, ts, id, length, ip = ln:match("^# (%S+) (%S+) (%S+) (%S+) (%d+) (%S+) (%S+) (.*)") + local iface, duid, iaid, name, ts, id, length, ip = ln:match("^# (%S+) (%S+) (%S+) (%S+) (-?%d+) (%S+) (%S+) (.*)") + local expire = tonumber(ts) or 0 if ip and iaid ~= "ipv4" and family == 6 then rv[#rv+1] = { - expires = os.difftime(tonumber(ts) or 0, os.time()), + expires = (expire >= 0) and os.difftime(expire, os.time()), duid = duid, ip6addr = ip, hostname = (name ~= "-") and name } elseif ip and iaid == "ipv4" and family == 4 then rv[#rv+1] = { - expires = os.difftime(tonumber(ts) or 0, os.time()), - macaddr = duid, + 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", ipaddr = ip, hostname = (name ~= "-") and name } @@ -130,7 +131,9 @@ function wifi_networks() assoclist = net:assoclist(), country = net:country(), txpower = net:txpower(), - txpoweroff = net:txpower_offset() + txpoweroff = net:txpower_offset(), + disabled = (dev:get("disabled") == "1" or + net:get("disabled") == "1") } end @@ -184,7 +187,7 @@ function switch_status(devs) local switches = { } for dev in devs:gmatch("[^%s,]+") do local ports = { } - local swc = io.popen("swconfig dev %q show" % dev, "r") + local swc = io.popen("swconfig dev '%s' show" % dev:gsub("'", ""), "r") if swc then local l repeat