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
14 module("luci.tools.status", package.seeall)
16 local uci = require "luci.model.uci".cursor()
18 local function dhcp_leases_common(family)
20 local nfs = require "nixio.fs"
21 local leasefile = "/var/dhcp.leases"
23 uci:foreach("dhcp", "dnsmasq",
25 if s.leasefile and nfs.access(s.leasefile) then
26 leasefile = s.leasefile
31 local fd = io.open(leasefile, "r")
34 local ln = fd:read("*l")
38 local ts, mac, ip, name, duid = ln:match("^(%d+) (%S+) (%S+) (%S+) (%S+)")
39 if ts and mac and ip and name and duid then
40 if family == 4 and not ip:match(":") then
42 expires = os.difftime(tonumber(ts) or 0, os.time()),
45 hostname = (name ~= "*") and name
47 elseif family == 6 and ip:match(":") then
49 expires = os.difftime(tonumber(ts) or 0, os.time()),
51 duid = (duid ~= "*") and duid,
52 hostname = (name ~= "*") and name
61 local fd = io.open("/tmp/hosts/odhcpd", "r")
64 local ln = fd:read("*l")
68 local iface, duid, iaid, name, ts, id, length, ip = ln:match("^# (%S+) (%S+) (%S+) (%S+) (%d+) (%S+) (%S+) (.*)")
69 if ip and iaid ~= "ipv4" and family == 6 then
71 expires = os.difftime(tonumber(ts) or 0, os.time()),
74 hostname = (name ~= "-") and name
76 elseif ip and iaid == "ipv4" and family == 4 then
78 expires = os.difftime(tonumber(ts) or 0, os.time()),
81 hostname = (name ~= "-") and name
92 function dhcp_leases()
93 return dhcp_leases_common(4)
96 function dhcp6_leases()
97 return dhcp_leases_common(6)
100 function wifi_networks()
102 local ntm = require "luci.model.network".init()
105 for _, dev in ipairs(ntm:get_wifidevs()) do
109 name = dev:get_i18n(),
114 for _, net in ipairs(dev:get_wifinets()) do
115 rd.networks[#rd.networks+1] = {
116 name = net:shortname(),
117 link = net:adminlink(),
119 mode = net:active_mode(),
120 ssid = net:active_ssid(),
121 bssid = net:active_bssid(),
122 encryption = net:active_encryption(),
123 frequency = net:frequency(),
124 channel = net:channel(),
125 signal = net:signal(),
126 quality = net:signal_percent(),
128 bitrate = net:bitrate(),
129 ifname = net:ifname(),
130 assoclist = net:assoclist(),
131 country = net:country(),
132 txpower = net:txpower(),
133 txpoweroff = net:txpower_offset()
143 function wifi_network(id)
144 local ntm = require "luci.model.network".init()
145 local net = ntm:get_wifinet(id)
147 local dev = net:get_device()
151 name = net:shortname(),
152 link = net:adminlink(),
154 mode = net:active_mode(),
155 ssid = net:active_ssid(),
156 bssid = net:active_bssid(),
157 encryption = net:active_encryption(),
158 frequency = net:frequency(),
159 channel = net:channel(),
160 signal = net:signal(),
161 quality = net:signal_percent(),
163 bitrate = net:bitrate(),
164 ifname = net:ifname(),
165 assoclist = net:assoclist(),
166 country = net:country(),
167 txpower = net:txpower(),
168 txpoweroff = net:txpower_offset(),
169 disabled = (dev:get("disabled") == "1" or
170 net:get("disabled") == "1"),
174 name = dev:get_i18n()
182 function switch_status(devs)
185 for dev in devs:gmatch("[^%s,]+") do
187 local swc = io.popen("swconfig dev %q show" % dev, "r")
193 local port, up = l:match("port:(%d+) link:(%w+)")
195 local speed = l:match(" speed:(%d+)")
196 local duplex = l:match(" (%w+)-duplex")
197 local txflow = l:match(" (txflow)")
198 local rxflow = l:match(" (rxflow)")
199 local auto = l:match(" (auto)")
202 port = tonumber(port) or 0,
203 speed = tonumber(speed) or 0,
205 duplex = (duplex == "full"),
206 rxflow = (not not rxflow),
207 txflow = (not not txflow),
208 auto = (not not auto)
215 switches[dev] = ports