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")
53 -- Find default routes
55 local _, r, def4, def6
57 for _, r in ipairs(ip.routes({ type =
1, dest_exact =
"0.0.0.0/0" })) do
59 gateway = r.gw:string(),
60 dest = r.dest:string(),
67 for _, r in ipairs(ip.routes({ type =
1, dest_exact =
"::/0" })) do
69 gateway = r.gw:string(),
70 dest = r.dest:string(),
78 if luci.http.formvalue(
"status") ==
"1" then
80 for dev in pairs(netdevs) do
81 local j = { id = dev }
82 local iw = luci.sys.wifi.getiwinfo(dev)
86 "channel",
"txpower",
"bitrate",
"signal",
"noise",
87 "quality",
"quality_max",
"mode",
"ssid",
"bssid",
"encryption",
"ifname"
105 luci.http.prepare_content(
"application/json")
106 luci.http.write_json(rv)
113 <script type=
"text/javascript" src=
"<%=resource%>/cbi.js"></script>
115 <script type=
"text/javascript">//<![CDATA[
116 XHR.poll(<%=interval%
> , '<%=REQUEST_URI%
>', { status:
1 },
121 for( var i =
0; i < st.length; i++ )
124 var is_assoc = (iw.bssid && iw.channel);
125 var p = (
100 / iw.quality_max * iw.quality);
126 var q = is_assoc ? p : -
1;
130 icon =
"<%=resource%>/icons/signal-none.png";
132 icon =
"<%=resource%>/icons/signal-0.png";
134 icon =
"<%=resource%>/icons/signal-0-25.png";
136 icon =
"<%=resource%>/icons/signal-25-50.png";
138 icon =
"<%=resource%>/icons/signal-50-75.png";
140 icon =
"<%=resource%>/icons/signal-75-100.png";
142 var power = document.getElementById(iw.id + '-txpower');
144 power.innerHTML = String.format('%s dbm', iw.txpower);
146 var signal = document.getElementById(iw.id + '-signal');
148 signal.innerHTML = String.format(
149 '
<img src=
"%s" title=
"Signal: %s db / Noise: %s db" alt=
"Signal Quality" />',
150 icon, iw.signal, iw.noise
153 var bitrate = document.getElementById(iw.id + '-bitrate');
155 bitrate.innerHTML = String.format('%s Mb/s', iw.bitrate ? iw.bitrate /
1000 : '?');
157 var ssid = document.getElementById(iw.id + '-ssid');
159 ssid.innerHTML = iw.ssid;
161 var bssid = document.getElementById(iw.id + '-bssid');
163 bssid.innerHTML = iw.bssid;
165 var channel = document.getElementById(iw.id + '-channel');
167 channel.innerHTML = iw.channel;
169 var mode = document.getElementById(iw.id + '-mode');
171 mode.innerHTML = iw.mode;
177 if (u = document.getElementById('dynuptime'))
178 u.innerHTML = st[i].uptime;
180 if (u = document.getElementById('dynload'))
181 u.innerHTML = st[i].load;
183 if (u = document.getElementById('dynmem'))
184 u.innerHTML = st[i].mem;
186 if (u = document.getElementById('dyntime'))
187 u.innerHTML = st[i].time;
189 if (st[i].defroutev4)
191 if (u = document.getElementById('v4dst'))
192 u.innerHTML = st[i].defroutev4.dest;
194 if (u = document.getElementById('v4gw'))
195 u.innerHTML = st[i].defroutev4.gateway;
197 if (u = document.getElementById('v4dev'))
198 u.innerHTML = st[i].defroutev4.dev;
200 if (u = document.getElementById('v4metr'))
201 u.innerHTML = st[i].defroutev4.metr;
204 if (st[i].defroutev6)
206 if (u = document.getElementById('v6dst'))
207 u.innerHTML = st[i].defroutev6.dest;
209 if (u = document.getElementById('v6gw'))
210 u.innerHTML = st[i].defroutev6.gateway;
212 if (u = document.getElementById('v6dev'))
213 u.innerHTML = st[i].defroutev6.dev;
215 if (u = document.getElementById('v6metr'))
216 u.innerHTML = st[i].defroutev6.metr;
223 <div class=
"cbi-map">
225 <div class=
"cbi-section-node">
226 <div class=
"cbi-value"><label class=
"cbi-value-title"><%:System%
></label><div class=
"cbi-value-field"><%=boardinfo.system or
"?"%
></div></div>
227 <div class=
"cbi-value"><label class=
"cbi-value-title"><%:Model%
></label><div class=
"cbi-value-field"><%=boardinfo.model or
"?"%
></div></div>
228 <div class=
"cbi-value"><label class=
"cbi-value-title"><%:Load%
></label><div class=
"cbi-value-field" id=
"dynload"><%=load%
></div></div>
229 <div class=
"cbi-value"><label class=
"cbi-value-title"><%:Memory%
></label><div class=
"cbi-value-field" id=
"dynmem"><%=mem%
></div></div>
230 <div class=
"cbi-value"><label class=
"cbi-value-title"><%:Local Time%
></label><div class=
"cbi-value-field" id=
"dyntime"><%=time%
></div></div>
231 <div class=
"cbi-value"><label class=
"cbi-value-title"><%:Uptime%
></label><div class=
"cbi-value-field" id=
"dynuptime"><%=uptime%
></div></div>
235 <% if devices[
1] then %
>
237 <div class=
"cbi-map">
238 <h2><%:Wireless Overview%
></h2>
240 <% if not has_iwinfo then %
>
241 <div class=
"errorbox">
242 <strong><%:Package libiwinfo required!%
></strong><br />
243 <%_The
<em>libiwinfo
</em> package is not installed. You must install this component for working wireless configuration!%
>
247 <div class=
"cbi-section">
248 <div class=
"cbi-section-node">
249 <table class=
"cbi-section-table">
250 <tr class=
"cbi-section-table-titles">
251 <th class=
"cbi-section-table-cell"><%:Signal%
></th>
252 <th class=
"cbi-section-table-cell"><%:Bitrate%
></th>
253 <th class=
"cbi-section-table-cell"><%:SSID%
></th>
254 <th class=
"cbi-section-table-cell"><%:BSSID%
></th>
255 <th class=
"cbi-section-table-cell"><%:Channel%
></th>
256 <th class=
"cbi-section-table-cell"><%:Mode%
></th>
257 <th class=
"cbi-section-table-cell"><%:TX%
>-<%:Power%
></th>
258 <th class=
"cbi-section-table-cell"><%:Interface%
></th>
261 for _, dev in ipairs(devices) do
263 for _, net in ipairs(dev:get_wifinets()) do
264 netlist[#netlist+
1] = net:ifname()
265 netdevs[net:ifname()] = dev:name()
267 if net.iwdata.device then
268 local signal = net.iwinfo.signal or
"N/A"
269 local noise = net.iwinfo.noise or
"N/A"
270 local q = net.iwinfo.quality or
"0"
271 local qmax = net.iwinfo.quality_max or
"100"
272 local qperc = q / qmax *
100
275 icon =
"signal-none.png"
276 elseif qperc <
26 then
277 icon =
"signal-0-25.png"
278 elseif qperc <
51 then
279 icon =
"signal-25-50.png"
280 elseif qperc <
76 then
281 icon =
"signal-50-75.png"
282 elseif qperc <
100 then
283 icon =
"signal-75-100.png"
285 icon =
"signal-0.png"
288 signal_string =
"<img src='"..resource..
"/icons/"..icon..
"' title='Signal: "..signal..
" db / Noise: "..noise..
" db' alt='Signal Quality'></img>"
290 local ssid = net.iwinfo.ssid or
"N/A"
291 local bssid = net.iwinfo.bssid or
"N/A"
292 local chan = net.iwinfo.channel or
"N/A"
293 local mode = net.iwinfo.mode or
"N/A"
294 local txpwr = net.iwinfo.txpower or
"N/A"
295 if txpwr ~=
"N/A" then
296 txpwr = txpwr..
" dbm"
298 local bitrate = net.iwinfo.bitrate or
"N/A"
299 if bitrate ~=
"N/A" then
300 bitrate = ( bitrate /
1000 )..
"Mb/s"
302 local interface = net.iwinfo.ifname or
"N/A"
304 <tr class=
"cbi-section-table-row cbi-rowstyle-1">
305 <td class=
"cbi-value-field" id=
"<%=net:ifname()%>-signal"><%=signal_string%
></td>
306 <td class=
"cbi-value-field" id=
"<%=net:ifname()%>-bitrate"><%=bitrate%
></td>
307 <td class=
"cbi-value-field" id=
"<%=net:ifname()%>-ssid"><%=ssid%
></td>
308 <td class=
"cbi-value-field" id=
"<%=net:ifname()%>-bssid"><%=bssid%
></td>
309 <td class=
"cbi-value-field" id=
"<%=net:ifname()%>-channel"><%=chan%
></td>
310 <td class=
"cbi-value-field" id=
"<%=net:ifname()%>-mode"><%=mode%
></td>
311 <td class=
"cbi-value-field" id=
"<%=net:ifname()%>-txpower"><%=txpwr%
></td>
312 <td class=
"cbi-value-field"><%=interface%
></td>
323 <div class=
"cbi-map">
324 <h2><%:Default routes%
></h2>
325 <div class=
"cbi-section">
326 <div class=
"cbi-section-node">
328 <% if not def4 and not def6 then %
>
329 <%:No default routes known.%
>
331 <table class=
"cbi-section-table">
332 <tr class=
"cbi-section-table-titles">
333 <th class=
"cbi-section-table-cell"><%:Network%
></th>
334 <th class=
"cbi-section-table-cell"><%:Interface%
></th>
335 <th class=
"cbi-section-table-cell"><%:Gateway%
></th>
336 <th class=
"cbi-section-table-cell"><%:Metric%
></th>
340 <tr class=
"cbi-section-table-row cbi-rowstyle-1">
341 <td class=
"cbi-value-field" id=
"v4dst"><%=def4.dest%
></td>
342 <td class=
"cbi-value-field" id=
"v4dev"><%=def4.dev%
></td>
343 <td class=
"cbi-value-field" id=
"v4gw"><%=def4.gateway%
></td>
344 <td class=
"cbi-value-field" id=
"v4metr"><%=def4.metr%
></td>
350 <tr class=
"cbi-section-table-row cbi-rowstyle-2">
351 <td class=
"cbi-value-field" id=
"v6dst"><%=def6.dest%
></td>
352 <td class=
"cbi-value-field" id=
"v6dev"><%=def6.dev%
></td>
353 <td class=
"cbi-value-field" id=
"v6gw"><%=def6.gateway%
></td>
354 <td class=
"cbi-value-field" id=
"v6metr"><%=def6.metr%
></td>