2 local sys = require "luci.sys"
3 local twa = require "luci.tools.webadmin"
6 local model, system, memtotal, memcached, membuffers, memfree, bogomips = sys.sysinfo()
7 local uptime = twa.date_format(tonumber(sys.uptime()))
8 local time = os.date("%a, %d %b %Y, %H:%M:%S")
9 local load1, load5, load15 = sys.loadavg()
10 local load = string.format("%.2f, %.2f, %.2f", load1, load5, load15)
12 local mem = string.format(
13 "%.2f MB (%.2f %s, %.2f %s, %.2f %s, %.2f %s)",
14 tonumber(memtotal) / 1024,
15 tonumber(memtotal - memfree) / 1024,
16 tostring(i18n.translate("used")),
18 tostring(i18n.translate("free")),
20 tostring(i18n.translate("cached")),
22 tostring(i18n.translate("buffered"))
26 local bogomips = bogomips or 100
28 if bogomips > 350 then
33 local ntm = require "luci.model.network".init()
34 local devices = ntm:get_wifidevs()
38 for _, dev in ipairs(devices) do
40 for _, net in ipairs(dev:get_wifinets()) do
41 netlist[#netlist+1] = net:ifname()
42 netdevs[net:ifname()] = dev:name()
45 local has_iwinfo = pcall(require, "iwinfo")
48 local defroutev4 = sys.net.defaultroute()
49 local defroutev6 = sys.net.defaultroute6()
52 defroutev4.dest = defroutev4.dest:string()
53 defroutev4.gateway = defroutev4.gateway:string()
55 -- probably policy routing activated, try olsr-default table
56 local dr4 = sys.exec("ip r s t olsr-default")
59 defroutev4.dest, defroutev4.gateway, defroutev4.device, defroutev4.metric = dr4:match("^(%w+) via (%d+.%d+.%d+.%d+) dev ([%w-]+) +metric (%d+)")
64 defroutev6.dest = defroutev6.dest:string()
65 defroutev6.nexthop = defroutev6.nexthop:string()
68 if luci.http.formvalue("status") == "1" then
70 for dev in pairs(netdevs) do
71 local j = { id = dev }
72 local iw = luci.sys.wifi.getiwinfo(dev)
76 "channel", "txpower", "bitrate", "signal", "noise",
77 "quality", "quality_max", "mode", "ssid", "bssid", "encryption", "ifname"
87 gateway = defroutev6.nexthop,
88 dest = defroutev6.dest,
89 dev = defroutev6.device,
90 metr = defroutev6.metric
96 gateway = defroutev4.gateway,
97 dest = defroutev4.dest,
98 dev = defroutev4.device,
99 metr = defroutev4.metric
112 luci.http.prepare_content("application/json")
113 luci.http.write_json(rv)
120 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
122 <script type="text/javascript">//<![CDATA[
123 XHR.poll(<%=interval%> , '<%=REQUEST_URI%>', { status: 1 },
128 for( var i = 0; i < st.length; i++ )
131 var is_assoc = (iw.bssid && iw.channel);
132 var p = (100 / iw.quality_max * iw.quality);
133 var q = is_assoc ? p : -1;
137 icon = "<%=resource%>/icons/signal-none.png";
139 icon = "<%=resource%>/icons/signal-0.png";
141 icon = "<%=resource%>/icons/signal-0-25.png";
143 icon = "<%=resource%>/icons/signal-25-50.png";
145 icon = "<%=resource%>/icons/signal-50-75.png";
147 icon = "<%=resource%>/icons/signal-75-100.png";
149 var power = document.getElementById(iw.id + '-txpower');
151 power.innerHTML = String.format('%s dbm', iw.txpower);
153 var signal = document.getElementById(iw.id + '-signal');
155 signal.innerHTML = String.format(
156 '<img src="%s" title="Signal: %s db / Noise: %s db" alt="Signal Quality" />',
157 icon, iw.signal, iw.noise
160 var bitrate = document.getElementById(iw.id + '-bitrate');
162 bitrate.innerHTML = String.format('%s Mb/s', iw.bitrate ? iw.bitrate / 1000 : '?');
164 var ssid = document.getElementById(iw.id + '-ssid');
166 ssid.innerHTML = iw.ssid;
168 var bssid = document.getElementById(iw.id + '-bssid');
170 bssid.innerHTML = iw.bssid;
172 var channel = document.getElementById(iw.id + '-channel');
174 channel.innerHTML = iw.channel;
176 var mode = document.getElementById(iw.id + '-mode');
178 mode.innerHTML = iw.mode;
184 if (u = document.getElementById('dynuptime'))
185 u.innerHTML = st[i].uptime;
187 if (u = document.getElementById('dynload'))
188 u.innerHTML = st[i].load;
190 if (u = document.getElementById('dynmem'))
191 u.innerHTML = st[i].mem;
193 if (u = document.getElementById('dyntime'))
194 u.innerHTML = st[i].time;
196 if (st[i].defroutev4)
198 if (u = document.getElementById('v4dst'))
199 u.innerHTML = st[i].defroutev4.dest;
201 if (u = document.getElementById('v4gw'))
202 u.innerHTML = st[i].defroutev4.gateway;
204 if (u = document.getElementById('v4dev'))
205 u.innerHTML = st[i].defroutev4.dev;
207 if (u = document.getElementById('v4metr'))
208 u.innerHTML = st[i].defroutev4.metr;
211 if (st[i].defroutev6)
213 if (u = document.getElementById('v6dst'))
214 u.innerHTML = st[i].defroutev6.dest;
216 if (u = document.getElementById('v6gw'))
217 u.innerHTML = st[i].defroutev6.gateway;
219 if (u = document.getElementById('v6dev'))
220 u.innerHTML = st[i].defroutev6.dev;
222 if (u = document.getElementById('v6metr'))
223 u.innerHTML = st[i].defroutev6.metr;
230 <div class="cbi-map">
232 <div class="cbi-section-node">
233 <div class="cbi-value"><label class="cbi-value-title"><%:System%></label><div class="cbi-value-field"><%=system%></div></div>
234 <div class="cbi-value"><label class="cbi-value-title"><%:Processor%></label><div class="cbi-value-field"><%=model%></div></div>
235 <div class="cbi-value"><label class="cbi-value-title"><%:Load%></label><div class="cbi-value-field" id="dynload"><%=load%></div></div>
236 <div class="cbi-value"><label class="cbi-value-title"><%:Memory%></label><div class="cbi-value-field" id="dynmem"><%=mem%></div></div>
237 <div class="cbi-value"><label class="cbi-value-title"><%:Local Time%></label><div class="cbi-value-field" id="dyntime"><%=time%></div></div>
238 <div class="cbi-value"><label class="cbi-value-title"><%:Uptime%></label><div class="cbi-value-field" id="dynuptime"><%=uptime%></div></div>
242 <% if devices[1] then %>
244 <div class="cbi-map">
245 <h2><%:Wireless Overview%></h2>
247 <% if not has_iwinfo then %>
248 <div class="errorbox">
249 <strong><%:Package libiwinfo required!%></strong><br />
250 <%_The <em>libiwinfo</em> package is not installed. You must install this component for working wireless configuration!%>
254 <div class="cbi-section">
255 <div class="cbi-section-node">
256 <table class="cbi-section-table">
257 <tr class="cbi-section-table-titles">
258 <th class="cbi-section-table-cell"><%:Signal%></th>
259 <th class="cbi-section-table-cell"><%:Bitrate%></th>
260 <th class="cbi-section-table-cell"><%:SSID%></th>
261 <th class="cbi-section-table-cell"><%:BSSID%></th>
262 <th class="cbi-section-table-cell"><%:Channel%></th>
263 <th class="cbi-section-table-cell"><%:Mode%></th>
264 <th class="cbi-section-table-cell"><%:TX%>-<%:Power%></th>
265 <th class="cbi-section-table-cell"><%:Interface%></th>
268 for _, dev in ipairs(devices) do
270 for _, net in ipairs(dev:get_wifinets()) do
271 netlist[#netlist+1] = net:ifname()
272 netdevs[net:ifname()] = dev:name()
274 if net.iwdata.device then
275 local signal = net.iwinfo.signal or "N/A"
276 local noise = net.iwinfo.noise or "N/A"
277 local q = net.iwinfo.quality or "0"
278 local qmax = net.iwinfo.quality_max or "100"
279 local qperc = q / qmax * 100
282 icon = "signal-none.png"
283 elseif qperc < 26 then
284 icon = "signal-0-25.png"
285 elseif qperc < 51 then
286 icon = "signal-25-50.png"
287 elseif qperc < 76 then
288 icon = "signal-50-75.png"
289 elseif qperc < 100 then
290 icon = "signal-75-100.png"
292 icon = "signal-0.png"
295 signal_string = "<img src='"..resource.."/icons/"..icon.."' title='Signal: "..signal.." db / Noise: "..noise.." db' alt='Signal Quality'></img>"
297 local ssid = net.iwinfo.ssid or "N/A"
298 local bssid = net.iwinfo.bssid or "N/A"
299 local chan = net.iwinfo.channel or "N/A"
300 local mode = net.iwinfo.mode or "N/A"
301 local txpwr = net.iwinfo.txpower or "N/A"
302 if txpwr ~= "N/A" then
303 txpwr = txpwr.." dbm"
305 local bitrate = net.iwinfo.bitrate or "N/A"
306 if bitrate ~= "N/A" then
307 bitrate = ( bitrate / 1000 ).."Mb/s"
309 local interface = net.iwdata.ifname or "N/A"
311 <tr class="cbi-section-table-row cbi-rowstyle-1">
312 <td class="cbi-value-field" id="<%=net:ifname()%>-signal"><%=signal_string%></td>
313 <td class="cbi-value-field" id="<%=net:ifname()%>-bitrate"><%=bitrate%></td>
314 <td class="cbi-value-field" id="<%=net:ifname()%>-ssid"><%=ssid%></td>
315 <td class="cbi-value-field" id="<%=net:ifname()%>-bssid"><%=bssid%></td>
316 <td class="cbi-value-field" id="<%=net:ifname()%>-channel"><%=chan%></td>
317 <td class="cbi-value-field" id="<%=net:ifname()%>-mode"><%=mode%></td>
318 <td class="cbi-value-field" id="<%=net:ifname()%>-txpower"><%=txpwr%></td>
319 <td class="cbi-value-field"><%=interface%></td>
330 <div class="cbi-map">
331 <h2><%:Default routes%></h2>
332 <div class="cbi-section">
333 <div class="cbi-section-node">
335 <% if not defroutev4 and not defroutev6 then %>
336 <%:No default routes known.%>
338 <table class="cbi-section-table">
339 <tr class="cbi-section-table-titles">
340 <th class="cbi-section-table-cell"><%:Network%></th>
341 <th class="cbi-section-table-cell"><%:Interface%></th>
342 <th class="cbi-section-table-cell"><%:Gateway%></th>
343 <th class="cbi-section-table-cell"><%:Metric%></th>
346 <% if defroutev4 then %>
348 <tr class="cbi-section-table-row cbi-rowstyle-1">
349 <td class="cbi-value-field" id="v4dst"><%=defroutev4.dest%></td>
350 <td class="cbi-value-field" id="v4dev"><%=defroutev4.device%></td>
351 <td class="cbi-value-field" id="v4gw"><%=defroutev4.gateway%></td>
352 <td class="cbi-value-field" id="v4metr"><%=defroutev4.metric%></td>
356 if defroutev6 then %>
358 <tr class="cbi-section-table-row cbi-rowstyle-2">
359 <td class="cbi-value-field" id="v6dst"><%=defroutev6.dest%></td>
360 <td class="cbi-value-field" id="v6dev"><%=defroutev6.device%></td>
361 <td class="cbi-value-field" id="v6gw"><%=defroutev6.nexthop%></td>
362 <td class="cbi-value-field" id="v6metr"><%=defroutev6.metric%></td>