2 local utl = require "luci.util"
3 local sys = require "luci.sys"
4 local twa = require "luci.tools.webadmin"
8 local sysinfo = utl.ubus("system", "info") or { }
9 local boardinfo = utl.ubus("system", "board") or { }
11 local loads = sysinfo.load or { 0, 0, 0 }
12 local meminfo = sysinfo.memory or {
19 local uptime = twa.date_format(sysinfo.uptime or 0)
20 local time = os.date("%a, %d %b %Y, %H:%M:%S")
21 local load = string.format("%.2f, %.2f, %.2f", loads[1] / 65535.0, loads[2] / 65535.0, loads[3] / 65535.0)
23 local mem = string.format(
24 "%.2f MB (%.2f %s, %.2f %s, %.2f %s)",
25 memory.total / 1024 / 1024,
26 (memory.total - memory.free) / 1024 / 1024,
27 tostring(i18n.translate("used")),
28 memory.free / 1024 / 1024,
29 tostring(i18n.translate("free")),
30 memory.buffered / 1024 / 1024,
31 tostring(i18n.translate("buffered"))
37 local ntm = require "luci.model.network".init()
38 local devices = ntm:get_wifidevs()
42 for _, dev in ipairs(devices) do
44 for _, net in ipairs(dev:get_wifinets()) do
45 netlist[#netlist+1] = net:ifname()
46 netdevs[net:ifname()] = dev:name()
49 local has_iwinfo = pcall(require, "iwinfo")
52 local defroutev4 = sys.net.defaultroute()
53 local defroutev6 = sys.net.defaultroute6()
56 defroutev4.dest = defroutev4.dest:string()
57 defroutev4.gateway = defroutev4.gateway:string()
59 -- probably policy routing activated, try olsr-default table
60 local dr4 = sys.exec("ip r s t olsr-default")
63 defroutev4.dest, defroutev4.gateway, defroutev4.device, defroutev4.metric = dr4:match("^(%w+) via (%d+.%d+.%d+.%d+) dev ([%w-]+) +metric (%d+)")
68 defroutev6.dest = defroutev6.dest:string()
69 defroutev6.nexthop = defroutev6.nexthop:string()
72 if luci.http.formvalue("status") == "1" then
74 for dev in pairs(netdevs) do
75 local j = { id = dev }
76 local iw = luci.sys.wifi.getiwinfo(dev)
80 "channel", "txpower", "bitrate", "signal", "noise",
81 "quality", "quality_max", "mode", "ssid", "bssid", "encryption", "ifname"
91 gateway = defroutev6.nexthop,
92 dest = defroutev6.dest,
93 dev = defroutev6.device,
94 metr = defroutev6.metric
100 gateway = defroutev4.gateway,
101 dest = defroutev4.dest,
102 dev = defroutev4.device,
103 metr = defroutev4.metric
116 luci.http.prepare_content("application/json")
117 luci.http.write_json(rv)
124 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
126 <script type="text/javascript">//<![CDATA[
127 XHR.poll(<%=interval%> , '<%=REQUEST_URI%>', { status: 1 },
132 for( var i = 0; i < st.length; i++ )
135 var is_assoc = (iw.bssid && iw.channel);
136 var p = (100 / iw.quality_max * iw.quality);
137 var q = is_assoc ? p : -1;
141 icon = "<%=resource%>/icons/signal-none.png";
143 icon = "<%=resource%>/icons/signal-0.png";
145 icon = "<%=resource%>/icons/signal-0-25.png";
147 icon = "<%=resource%>/icons/signal-25-50.png";
149 icon = "<%=resource%>/icons/signal-50-75.png";
151 icon = "<%=resource%>/icons/signal-75-100.png";
153 var power = document.getElementById(iw.id + '-txpower');
155 power.innerHTML = String.format('%s dbm', iw.txpower);
157 var signal = document.getElementById(iw.id + '-signal');
159 signal.innerHTML = String.format(
160 '<img src="%s" title="Signal: %s db / Noise: %s db" alt="Signal Quality" />',
161 icon, iw.signal, iw.noise
164 var bitrate = document.getElementById(iw.id + '-bitrate');
166 bitrate.innerHTML = String.format('%s Mb/s', iw.bitrate ? iw.bitrate / 1000 : '?');
168 var ssid = document.getElementById(iw.id + '-ssid');
170 ssid.innerHTML = iw.ssid;
172 var bssid = document.getElementById(iw.id + '-bssid');
174 bssid.innerHTML = iw.bssid;
176 var channel = document.getElementById(iw.id + '-channel');
178 channel.innerHTML = iw.channel;
180 var mode = document.getElementById(iw.id + '-mode');
182 mode.innerHTML = iw.mode;
188 if (u = document.getElementById('dynuptime'))
189 u.innerHTML = st[i].uptime;
191 if (u = document.getElementById('dynload'))
192 u.innerHTML = st[i].load;
194 if (u = document.getElementById('dynmem'))
195 u.innerHTML = st[i].mem;
197 if (u = document.getElementById('dyntime'))
198 u.innerHTML = st[i].time;
200 if (st[i].defroutev4)
202 if (u = document.getElementById('v4dst'))
203 u.innerHTML = st[i].defroutev4.dest;
205 if (u = document.getElementById('v4gw'))
206 u.innerHTML = st[i].defroutev4.gateway;
208 if (u = document.getElementById('v4dev'))
209 u.innerHTML = st[i].defroutev4.dev;
211 if (u = document.getElementById('v4metr'))
212 u.innerHTML = st[i].defroutev4.metr;
215 if (st[i].defroutev6)
217 if (u = document.getElementById('v6dst'))
218 u.innerHTML = st[i].defroutev6.dest;
220 if (u = document.getElementById('v6gw'))
221 u.innerHTML = st[i].defroutev6.gateway;
223 if (u = document.getElementById('v6dev'))
224 u.innerHTML = st[i].defroutev6.dev;
226 if (u = document.getElementById('v6metr'))
227 u.innerHTML = st[i].defroutev6.metr;
234 <div class="cbi-map">
236 <div class="cbi-section-node">
237 <div class="cbi-value"><label class="cbi-value-title"><%:System%></label><div class="cbi-value-field"><%=boardinfo.system or "?"%></div></div>
238 <div class="cbi-value"><label class="cbi-value-title"><%:Model%></label><div class="cbi-value-field"><%=boardinfo.model or "?"%></div></div>
239 <div class="cbi-value"><label class="cbi-value-title"><%:Load%></label><div class="cbi-value-field" id="dynload"><%=load%></div></div>
240 <div class="cbi-value"><label class="cbi-value-title"><%:Memory%></label><div class="cbi-value-field" id="dynmem"><%=mem%></div></div>
241 <div class="cbi-value"><label class="cbi-value-title"><%:Local Time%></label><div class="cbi-value-field" id="dyntime"><%=time%></div></div>
242 <div class="cbi-value"><label class="cbi-value-title"><%:Uptime%></label><div class="cbi-value-field" id="dynuptime"><%=uptime%></div></div>
246 <% if devices[1] then %>
248 <div class="cbi-map">
249 <h2><%:Wireless Overview%></h2>
251 <% if not has_iwinfo then %>
252 <div class="errorbox">
253 <strong><%:Package libiwinfo required!%></strong><br />
254 <%_The <em>libiwinfo</em> package is not installed. You must install this component for working wireless configuration!%>
258 <div class="cbi-section">
259 <div class="cbi-section-node">
260 <table class="cbi-section-table">
261 <tr class="cbi-section-table-titles">
262 <th class="cbi-section-table-cell"><%:Signal%></th>
263 <th class="cbi-section-table-cell"><%:Bitrate%></th>
264 <th class="cbi-section-table-cell"><%:SSID%></th>
265 <th class="cbi-section-table-cell"><%:BSSID%></th>
266 <th class="cbi-section-table-cell"><%:Channel%></th>
267 <th class="cbi-section-table-cell"><%:Mode%></th>
268 <th class="cbi-section-table-cell"><%:TX%>-<%:Power%></th>
269 <th class="cbi-section-table-cell"><%:Interface%></th>
272 for _, dev in ipairs(devices) do
274 for _, net in ipairs(dev:get_wifinets()) do
275 netlist[#netlist+1] = net:ifname()
276 netdevs[net:ifname()] = dev:name()
278 if net.iwdata.device then
279 local signal = net.iwinfo.signal or "N/A"
280 local noise = net.iwinfo.noise or "N/A"
281 local q = net.iwinfo.quality or "0"
282 local qmax = net.iwinfo.quality_max or "100"
283 local qperc = q / qmax * 100
286 icon = "signal-none.png"
287 elseif qperc < 26 then
288 icon = "signal-0-25.png"
289 elseif qperc < 51 then
290 icon = "signal-25-50.png"
291 elseif qperc < 76 then
292 icon = "signal-50-75.png"
293 elseif qperc < 100 then
294 icon = "signal-75-100.png"
296 icon = "signal-0.png"
299 signal_string = "<img src='"..resource.."/icons/"..icon.."' title='Signal: "..signal.." db / Noise: "..noise.." db' alt='Signal Quality'></img>"
301 local ssid = net.iwinfo.ssid or "N/A"
302 local bssid = net.iwinfo.bssid or "N/A"
303 local chan = net.iwinfo.channel or "N/A"
304 local mode = net.iwinfo.mode or "N/A"
305 local txpwr = net.iwinfo.txpower or "N/A"
306 if txpwr ~= "N/A" then
307 txpwr = txpwr.." dbm"
309 local bitrate = net.iwinfo.bitrate or "N/A"
310 if bitrate ~= "N/A" then
311 bitrate = ( bitrate / 1000 ).."Mb/s"
313 local interface = net.iwdata.ifname or "N/A"
315 <tr class="cbi-section-table-row cbi-rowstyle-1">
316 <td class="cbi-value-field" id="<%=net:ifname()%>-signal"><%=signal_string%></td>
317 <td class="cbi-value-field" id="<%=net:ifname()%>-bitrate"><%=bitrate%></td>
318 <td class="cbi-value-field" id="<%=net:ifname()%>-ssid"><%=ssid%></td>
319 <td class="cbi-value-field" id="<%=net:ifname()%>-bssid"><%=bssid%></td>
320 <td class="cbi-value-field" id="<%=net:ifname()%>-channel"><%=chan%></td>
321 <td class="cbi-value-field" id="<%=net:ifname()%>-mode"><%=mode%></td>
322 <td class="cbi-value-field" id="<%=net:ifname()%>-txpower"><%=txpwr%></td>
323 <td class="cbi-value-field"><%=interface%></td>
334 <div class="cbi-map">
335 <h2><%:Default routes%></h2>
336 <div class="cbi-section">
337 <div class="cbi-section-node">
339 <% if not defroutev4 and not defroutev6 then %>
340 <%:No default routes known.%>
342 <table class="cbi-section-table">
343 <tr class="cbi-section-table-titles">
344 <th class="cbi-section-table-cell"><%:Network%></th>
345 <th class="cbi-section-table-cell"><%:Interface%></th>
346 <th class="cbi-section-table-cell"><%:Gateway%></th>
347 <th class="cbi-section-table-cell"><%:Metric%></th>
350 <% if defroutev4 then %>
352 <tr class="cbi-section-table-row cbi-rowstyle-1">
353 <td class="cbi-value-field" id="v4dst"><%=defroutev4.dest%></td>
354 <td class="cbi-value-field" id="v4dev"><%=defroutev4.device%></td>
355 <td class="cbi-value-field" id="v4gw"><%=defroutev4.gateway%></td>
356 <td class="cbi-value-field" id="v4metr"><%=defroutev4.metric%></td>
360 if defroutev6 then %>
362 <tr class="cbi-section-table-row cbi-rowstyle-2">
363 <td class="cbi-value-field" id="v6dst"><%=defroutev6.dest%></td>
364 <td class="cbi-value-field" id="v6dev"><%=defroutev6.device%></td>
365 <td class="cbi-value-field" id="v6gw"><%=defroutev6.nexthop%></td>
366 <td class="cbi-value-field" id="v6metr"><%=defroutev6.metric%></td>