local uci = require "luci.model.uci".cursor()
-function dhcp_leases()
+local function dhcp_leases_common(family)
local rv = { }
local nfs = require "nixio.fs"
local leasefile = "/var/dhcp.leases"
if not ln then
break
else
- local ts, mac, ip, name = ln:match("^(%d+) (%S+) (%S+) (%S+)")
- if ts and mac and ip and name then
- rv[#rv+1] = {
- expires = os.difftime(tonumber(ts) or 0, os.time()),
- macaddr = mac,
- ipaddr = ip,
- hostname = (name ~= "*") and name
- }
+ local ts, mac, ip, name, duid = ln:match("^(%d+) (%S+) (%S+) (%S+) (%S+)")
+ 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,
+ 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()),
+ ip6addr = ip,
+ duid = (duid ~= "*") and duid,
+ hostname = (name ~= "*") and name
+ }
+ end
end
end
end
return rv
end
+function dhcp_leases()
+ return dhcp_leases_common(4)
+end
+
+function dhcp6_leases()
+ if luci.sys.call("dnsmasq --version 2>/dev/null | grep -q ' DHCPv6 '") == 0 then
+ return dhcp_leases_common(6)
+ else
+ return nil
+ end
+end
+
function wifi_networks()
local rv = { }
local ntm = require "luci.model.network".init()
noise = net:noise(),
bitrate = net:bitrate(),
ifname = net:ifname(),
- assoclist = net:assoclist()
+ assoclist = net:assoclist(),
+ country = net:country(),
+ txpower = net:txpower(),
+ txpoweroff = net:txpower_offset()
}
end
return rv
end
+
+function wifi_network(id)
+ local ntm = require "luci.model.network".init()
+ local net = ntm:get_wifinet(id)
+ if net then
+ local dev = net:get_device()
+ if dev then
+ return {
+ id = id,
+ name = net:shortname(),
+ link = net:adminlink(),
+ up = net:is_up(),
+ mode = net:active_mode(),
+ ssid = net:active_ssid(),
+ bssid = net:active_bssid(),
+ encryption = net:active_encryption(),
+ frequency = net:frequency(),
+ channel = net:channel(),
+ signal = net:signal(),
+ quality = net:signal_percent(),
+ noise = net:noise(),
+ bitrate = net:bitrate(),
+ ifname = net:ifname(),
+ assoclist = net:assoclist(),
+ country = net:country(),
+ txpower = net:txpower(),
+ txpoweroff = net:txpower_offset(),
+ device = {
+ up = dev:is_up(),
+ device = dev:name(),
+ name = dev:get_i18n()
+ }
+ }
+ end
+ end
+ return { }
+end