2 local utl = require "luci.util"
3 local sys = require "luci.sys"
4 local twa = require "luci.tools.webadmin"
5 local ip = require "luci.ip"
9 local sysinfo = utl.ubus("system", "info") or { }
10 local boardinfo = utl.ubus("system", "board") or { }
12 local loads = sysinfo.load or { 0, 0, 0 }
13 local meminfo = sysinfo.memory or {
20 local uptime = twa.date_format(sysinfo.uptime or 0)
21 local time = os.date("%a, %d %b %Y, %H:%M:%S")
22 local load = string.format("%.2f, %.2f, %.2f", loads[1] / 65535.0, loads[2] / 65535.0, loads[3] / 65535.0)
24 local mem = string.format(
25 "%.2f MB (%.2f %s, %.2f %s, %.2f %s)",
26 meminfo.total / 1024 / 1024,
27 (meminfo.total - meminfo.free) / 1024 / 1024,
28 tostring(i18n.translate("used")),
29 meminfo.free / 1024 / 1024,
30 tostring(i18n.translate("free")),
31 meminfo.buffered / 1024 / 1024,
32 tostring(i18n.translate("buffered"))
38 local ntm = require "luci.model.network".init()
39 local devices = ntm:get_wifidevs()
43 for _, dev in ipairs(devices) do
45 for _, net in ipairs(dev:get_wifinets()) do
46 netlist[#netlist+1] = net:ifname()
47 netdevs[net:ifname()] = dev:name()
50 local has_iwinfo = pcall(require, "iwinfo")
52 if luci.http.formvalue("status") == "1" then
54 for dev in pairs(netdevs) do
55 local j = { id = dev }
56 local iw = luci.sys.wifi.getiwinfo(dev)
60 "channel", "txpower", "bitrate", "signal", "noise",
61 "quality", "quality_max", "mode", "ssid", "bssid", "encryption", "ifname"
70 -- Find default routes
72 local _, r, def4, def6
74 for _, r in ipairs(ip.routes({ type = 1, dest_exact = "0.0.0.0/0" })) do
76 gateway = r.gw:string(),
77 dest = r.dest:string(),
84 for _, r in ipairs(ip.routes({ type = 1, dest_exact = "::/0" })) do
86 gateway = r.gw:string(),
87 dest = r.dest:string(),
103 luci.http.prepare_content("application/json")
104 luci.http.write_json(rv)
111 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
113 <script type="text/javascript">//<![CDATA[
114 XHR.poll(<%=interval%> , '<%=REQUEST_URI%>', { status: 1 },
119 for( var i = 0; i < st.length; i++ )
122 var is_assoc = (iw.bssid && iw.channel);
123 var p = (100 / iw.quality_max * iw.quality);
124 var q = is_assoc ? p : -1;
128 icon = "<%=resource%>/icons/signal-none.png";
130 icon = "<%=resource%>/icons/signal-0.png";
132 icon = "<%=resource%>/icons/signal-0-25.png";
134 icon = "<%=resource%>/icons/signal-25-50.png";
136 icon = "<%=resource%>/icons/signal-50-75.png";
138 icon = "<%=resource%>/icons/signal-75-100.png";
140 var power = document.getElementById(iw.id + '-txpower');
142 power.innerHTML = String.format('%s dbm', iw.txpower);
144 var signal = document.getElementById(iw.id + '-signal');
146 signal.innerHTML = String.format(
147 '<img src="%s" title="Signal: %s db / Noise: %s db" alt="Signal Quality" />',
148 icon, iw.signal, iw.noise
151 var bitrate = document.getElementById(iw.id + '-bitrate');
153 bitrate.innerHTML = String.format('%s Mb/s', iw.bitrate ? iw.bitrate / 1000 : '?');
155 var ssid = document.getElementById(iw.id + '-ssid');
157 ssid.innerHTML = iw.ssid;
159 var bssid = document.getElementById(iw.id + '-bssid');
161 bssid.innerHTML = iw.bssid;
163 var channel = document.getElementById(iw.id + '-channel');
165 channel.innerHTML = iw.channel;
167 var mode = document.getElementById(iw.id + '-mode');
169 mode.innerHTML = iw.mode;
175 if (u = document.getElementById('dynuptime'))
176 u.innerHTML = st[i].uptime;
178 if (u = document.getElementById('dynload'))
179 u.innerHTML = st[i].load;
181 if (u = document.getElementById('dynmem'))
182 u.innerHTML = st[i].mem;
184 if (u = document.getElementById('dyntime'))
185 u.innerHTML = st[i].time;
187 if (st[i].defroutev4)
189 if (u = document.getElementById('v4dst'))
190 u.innerHTML = st[i].defroutev4.dest;
192 if (u = document.getElementById('v4gw'))
193 u.innerHTML = st[i].defroutev4.gateway;
195 if (u = document.getElementById('v4dev'))
196 u.innerHTML = st[i].defroutev4.dev;
198 if (u = document.getElementById('v4metr'))
199 u.innerHTML = st[i].defroutev4.metr;
202 if (st[i].defroutev6)
204 if (u = document.getElementById('v6dst'))
205 u.innerHTML = st[i].defroutev6.dest;
207 if (u = document.getElementById('v6gw'))
208 u.innerHTML = st[i].defroutev6.gateway;
210 if (u = document.getElementById('v6dev'))
211 u.innerHTML = st[i].defroutev6.dev;
213 if (u = document.getElementById('v6metr'))
214 u.innerHTML = st[i].defroutev6.metr;
221 <div class="cbi-map">
223 <div class="cbi-section-node">
224 <div class="cbi-value"><label class="cbi-value-title"><%:System%></label><div class="cbi-value-field"><%=boardinfo.system or "?"%></div></div>
225 <div class="cbi-value"><label class="cbi-value-title"><%:Model%></label><div class="cbi-value-field"><%=boardinfo.model or "?"%></div></div>
226 <div class="cbi-value"><label class="cbi-value-title"><%:Load%></label><div class="cbi-value-field" id="dynload"><%=load%></div></div>
227 <div class="cbi-value"><label class="cbi-value-title"><%:Memory%></label><div class="cbi-value-field" id="dynmem"><%=mem%></div></div>
228 <div class="cbi-value"><label class="cbi-value-title"><%:Local Time%></label><div class="cbi-value-field" id="dyntime"><%=time%></div></div>
229 <div class="cbi-value"><label class="cbi-value-title"><%:Uptime%></label><div class="cbi-value-field" id="dynuptime"><%=uptime%></div></div>
233 <% if devices[1] then %>
235 <div class="cbi-map">
236 <h2><%:Wireless Overview%></h2>
238 <% if not has_iwinfo then %>
239 <div class="errorbox">
240 <strong><%:Package libiwinfo required!%></strong><br />
241 <%_The <em>libiwinfo</em> package is not installed. You must install this component for working wireless configuration!%>
245 <div class="cbi-section">
246 <div class="cbi-section-node">
247 <table class="cbi-section-table">
248 <tr class="cbi-section-table-titles">
249 <th class="cbi-section-table-cell"><%:Signal%></th>
250 <th class="cbi-section-table-cell"><%:Bitrate%></th>
251 <th class="cbi-section-table-cell"><%:SSID%></th>
252 <th class="cbi-section-table-cell"><%:BSSID%></th>
253 <th class="cbi-section-table-cell"><%:Channel%></th>
254 <th class="cbi-section-table-cell"><%:Mode%></th>
255 <th class="cbi-section-table-cell"><%:TX%>-<%:Power%></th>
256 <th class="cbi-section-table-cell"><%:Interface%></th>
259 for _, dev in ipairs(devices) do
261 for _, net in ipairs(dev:get_wifinets()) do
262 netlist[#netlist+1] = net:ifname()
263 netdevs[net:ifname()] = dev:name()
265 if net.iwdata.device then
266 local signal = net.iwinfo.signal or "N/A"
267 local noise = net.iwinfo.noise or "N/A"
268 local q = net.iwinfo.quality or "0"
269 local qmax = net.iwinfo.quality_max or "100"
270 local qperc = q / qmax * 100
273 icon = "signal-none.png"
274 elseif qperc < 26 then
275 icon = "signal-0-25.png"
276 elseif qperc < 51 then
277 icon = "signal-25-50.png"
278 elseif qperc < 76 then
279 icon = "signal-50-75.png"
280 elseif qperc < 100 then
281 icon = "signal-75-100.png"
283 icon = "signal-0.png"
286 signal_string = "<img src='"..resource.."/icons/"..icon.."' title='Signal: "..signal.." db / Noise: "..noise.." db' alt='Signal Quality'></img>"
288 local ssid = net.iwinfo.ssid or "N/A"
289 local bssid = net.iwinfo.bssid or "N/A"
290 local chan = net.iwinfo.channel or "N/A"
291 local mode = net.iwinfo.mode or "N/A"
292 local txpwr = net.iwinfo.txpower or "N/A"
293 if txpwr ~= "N/A" then
294 txpwr = txpwr.." dbm"
296 local bitrate = net.iwinfo.bitrate or "N/A"
297 if bitrate ~= "N/A" then
298 bitrate = ( bitrate / 1000 ).."Mb/s"
300 local interface = net.iwdata.ifname or "N/A"
302 <tr class="cbi-section-table-row cbi-rowstyle-1">
303 <td class="cbi-value-field" id="<%=net:ifname()%>-signal"><%=signal_string%></td>
304 <td class="cbi-value-field" id="<%=net:ifname()%>-bitrate"><%=bitrate%></td>
305 <td class="cbi-value-field" id="<%=net:ifname()%>-ssid"><%=ssid%></td>
306 <td class="cbi-value-field" id="<%=net:ifname()%>-bssid"><%=bssid%></td>
307 <td class="cbi-value-field" id="<%=net:ifname()%>-channel"><%=chan%></td>
308 <td class="cbi-value-field" id="<%=net:ifname()%>-mode"><%=mode%></td>
309 <td class="cbi-value-field" id="<%=net:ifname()%>-txpower"><%=txpwr%></td>
310 <td class="cbi-value-field"><%=interface%></td>
321 <div class="cbi-map">
322 <h2><%:Default routes%></h2>
323 <div class="cbi-section">
324 <div class="cbi-section-node">
326 <% if not defroutev4 and not defroutev6 then %>
327 <%:No default routes known.%>
329 <table class="cbi-section-table">
330 <tr class="cbi-section-table-titles">
331 <th class="cbi-section-table-cell"><%:Network%></th>
332 <th class="cbi-section-table-cell"><%:Interface%></th>
333 <th class="cbi-section-table-cell"><%:Gateway%></th>
334 <th class="cbi-section-table-cell"><%:Metric%></th>
337 <% if defroutev4 then %>
339 <tr class="cbi-section-table-row cbi-rowstyle-1">
340 <td class="cbi-value-field" id="v4dst"><%=defroutev4.dest%></td>
341 <td class="cbi-value-field" id="v4dev"><%=defroutev4.device%></td>
342 <td class="cbi-value-field" id="v4gw"><%=defroutev4.gateway%></td>
343 <td class="cbi-value-field" id="v4metr"><%=defroutev4.metric%></td>
347 if defroutev6 then %>
349 <tr class="cbi-section-table-row cbi-rowstyle-2">
350 <td class="cbi-value-field" id="v6dst"><%=defroutev6.dest%></td>
351 <td class="cbi-value-field" id="v6dev"><%=defroutev6.device%></td>
352 <td class="cbi-value-field" id="v6gw"><%=defroutev6.nexthop%></td>
353 <td class="cbi-value-field" id="v6metr"><%=defroutev6.metric%></td>