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
64 function dhcp_leases()
65 return dhcp_leases_common(4)
68 function dhcp6_leases()
69 if luci.sys.call("dnsmasq --version 2>/dev/null | grep -q ' DHCPv6 '") == 0 then
70 return dhcp_leases_common(6)
76 function wifi_networks()
78 local ntm = require "luci.model.network".init()
81 for _, dev in ipairs(ntm:get_wifidevs()) do
85 name = dev:get_i18n(),
90 for _, net in ipairs(dev:get_wifinets()) do
91 rd.networks[#rd.networks+1] = {
92 name = net:shortname(),
93 link = net:adminlink(),
95 mode = net:active_mode(),
96 ssid = net:active_ssid(),
97 bssid = net:active_bssid(),
98 encryption = net:active_encryption(),
99 frequency = net:frequency(),
100 channel = net:channel(),
101 signal = net:signal(),
102 quality = net:signal_percent(),
104 bitrate = net:bitrate(),
105 ifname = net:ifname(),
106 assoclist = net:assoclist(),
107 country = net:country(),
108 txpower = net:txpower(),
109 txpoweroff = net:txpower_offset()
119 function wifi_network(id)
120 local ntm = require "luci.model.network".init()
121 local net = ntm:get_wifinet(id)
123 local dev = net:get_device()
127 name = net:shortname(),
128 link = net:adminlink(),
130 mode = net:active_mode(),
131 ssid = net:active_ssid(),
132 bssid = net:active_bssid(),
133 encryption = net:active_encryption(),
134 frequency = net:frequency(),
135 channel = net:channel(),
136 signal = net:signal(),
137 quality = net:signal_percent(),
139 bitrate = net:bitrate(),
140 ifname = net:ifname(),
141 assoclist = net:assoclist(),
142 country = net:country(),
143 txpower = net:txpower(),
144 txpoweroff = net:txpower_offset(),
148 name = dev:get_i18n()
156 function switch_status(devs)
159 for dev in devs:gmatch("[^%s,]+") do
161 local swc = io.popen("swconfig dev %q show" % dev, "r")
167 local port, up = l:match("port:(%d+) link:(%w+)")
169 local speed = l:match(" speed:(%d+)")
170 local duplex = l:match(" (%w+)-duplex")
171 local txflow = l:match(" (txflow)")
172 local rxflow = l:match(" (rxflow)")
173 local auto = l:match(" (auto)")
176 port = tonumber(port) or 0,
177 speed = tonumber(speed) or 0,
179 duplex = (duplex == "full"),
180 rxflow = (not not rxflow),
181 txflow = (not not txflow),
182 auto = (not not auto)
189 switches[dev] = ports