2 LuCI - Lua Configuration Interface
4 Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
15 module("luci.tools.status", package.seeall)
17 local uci = require "luci.model.uci".cursor()
19 local function dhcp_leases_common(family)
21 local nfs = require "nixio.fs"
22 local leasefile = "/var/dhcp.leases"
24 uci:foreach("dhcp", "dnsmasq",
26 if s.leasefile and nfs.access(s.leasefile) then
27 leasefile = s.leasefile
32 local fd = io.open(leasefile, "r")
35 local ln = fd:read("*l")
39 local ts, mac, ip, name, duid = ln:match("^(%d+) (%S+) (%S+) (%S+) (%S+)")
40 if ts and mac and ip and name and duid then
41 if family == 4 and not ip:match(":") then
43 expires = os.difftime(tonumber(ts) or 0, os.time()),
46 hostname = (name ~= "*") and name
48 elseif family == 6 and ip:match(":") then
50 expires = os.difftime(tonumber(ts) or 0, os.time()),
52 duid = (duid ~= "*") and duid,
53 hostname = (name ~= "*") and name
65 function dhcp_leases()
66 return dhcp_leases_common(4)
69 function dhcp6_leases()
70 if luci.sys.call("dnsmasq --version 2>/dev/null | grep -q ' DHCPv6 '") == 0 then
71 return dhcp_leases_common(6)
77 function wifi_networks()
79 local ntm = require "luci.model.network".init()
82 for _, dev in ipairs(ntm:get_wifidevs()) do
86 name = dev:get_i18n(),
91 for _, net in ipairs(dev:get_wifinets()) do
92 rd.networks[#rd.networks+1] = {
93 name = net:shortname(),
94 link = net:adminlink(),
96 mode = net:active_mode(),
97 ssid = net:active_ssid(),
98 bssid = net:active_bssid(),
99 encryption = net:active_encryption(),
100 frequency = net:frequency(),
101 channel = net:channel(),
102 signal = net:signal(),
103 quality = net:signal_percent(),
105 bitrate = net:bitrate(),
106 ifname = net:ifname(),
107 assoclist = net:assoclist(),
108 country = net:country(),
109 txpower = net:txpower(),
110 txpoweroff = net:txpower_offset()
120 function wifi_network(id)
121 local ntm = require "luci.model.network".init()
122 local net = ntm:get_wifinet(id)
124 local dev = net:get_device()
128 name = net:shortname(),
129 link = net:adminlink(),
131 mode = net:active_mode(),
132 ssid = net:active_ssid(),
133 bssid = net:active_bssid(),
134 encryption = net:active_encryption(),
135 frequency = net:frequency(),
136 channel = net:channel(),
137 signal = net:signal(),
138 quality = net:signal_percent(),
140 bitrate = net:bitrate(),
141 ifname = net:ifname(),
142 assoclist = net:assoclist(),
143 country = net:country(),
144 txpower = net:txpower(),
145 txpoweroff = net:txpower_offset(),
149 name = dev:get_i18n()