3 local sys = require "luci.sys"
4 local twa = require "luci.tools.webadmin"
7 local model, system, memtotal, memcached, membuffers, memfree, bogomips = sys.sysinfo()
8 local uptime = twa.date_format(tonumber(sys.uptime()))
9 local_time = os.date("%a, %d %b %Y, %H:%M:%S")
10 local load1, load5, load15 = sys.loadavg()
11 local load = string.format("%.2f, %.2f, %.2f", load1, load5, load15)
13 local mem = string.format(
14 "%.2f MB (%.2f %s, %.2f %s, %.2f %s, %.2f %s)",
15 tonumber(memtotal) / 1024,
16 tonumber(memtotal - memfree) / 1024,
17 tostring(i18n.translate("used")),
19 tostring(i18n.translate("free")),
21 tostring(i18n.translate("cached")),
23 tostring(i18n.translate("buffered"))
27 local bogomips = bogomips or 100
29 if bogomips > 350 then
34 local ntm = require "luci.model.network".init()
35 local devices = ntm:get_wifidevs()
39 for _, dev in ipairs(devices) do
41 for _, net in ipairs(dev:get_wifinets()) do
42 netlist[#netlist+1] = net:ifname()
43 netdevs[net:ifname()] = dev:name()
46 local has_iwinfo = pcall(require, "iwinfo")
49 local defroutev4 = sys.net.defaultroute()
50 local defroutev6 = sys.net.defaultroute6()
53 defroutev4.dest = defroutev4.dest:string()
54 defroutev4.gateway = defroutev4.gateway:string()
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+)")
69 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
71 <script type="text/javascript">//<![CDATA[
72 XHR.poll(<%=interval%>, '<%=luci.dispatcher.build_url("freifunk", "status", "public_status_json", table.concat(netlist, ","))%>', null,
77 for( var i = 0; i < st.length; i++ )
80 var is_assoc = (iw.bssid && iw.channel);
81 var p = (100 / iw.quality_max * iw.quality);
82 var q = is_assoc ? p : -1;
86 icon = "<%=resource%>/icons/signal-none.png";
88 icon = "<%=resource%>/icons/signal-0.png";
90 icon = "<%=resource%>/icons/signal-0-25.png";
92 icon = "<%=resource%>/icons/signal-25-50.png";
94 icon = "<%=resource%>/icons/signal-50-75.png";
96 icon = "<%=resource%>/icons/signal-75-100.png";
98 var power = document.getElementById(iw.id + '-txpower');
100 power.innerHTML = String.format('%s dbm', iw.txpower);
102 var signal = document.getElementById(iw.id + '-signal');
104 signal.innerHTML = String.format(
105 '<img src="%s" title="Signal: %s db / Noise: %s db" alt="Signal Quality" />',
106 icon, iw.signal, iw.noise
109 var bitrate = document.getElementById(iw.id + '-bitrate');
111 bitrate.innerHTML = String.format('%s Mb/s', iw.bitrate ? iw.bitrate / 1000 : '?');
113 var ssid = document.getElementById(iw.id + '-ssid');
115 ssid.innerHTML = iw.ssid;
117 var bssid = document.getElementById(iw.id + '-bssid');
119 bssid.innerHTML = iw.bssid;
121 var channel = document.getElementById(iw.id + '-channel');
123 channel.innerHTML = iw.channel;
125 var mode = document.getElementById(iw.id + '-mode');
127 mode.innerHTML = iw.mode;
133 if (u = document.getElementById('dynuptime'))
134 u.innerHTML = st[i].uptime;
136 if (u = document.getElementById('dynload'))
137 u.innerHTML = st[i].load;
139 if (u = document.getElementById('dynmem'))
140 u.innerHTML = st[i].mem;
142 if (u = document.getElementById('dyntime'))
143 u.innerHTML = st[i].time;
145 if (st[i].defroutev4)
147 if (u = document.getElementById('v4dst'))
148 u.innerHTML = st[i].defroutev4.dest;
150 if (u = document.getElementById('v4gw'))
151 u.innerHTML = st[i].defroutev4.gateway;
153 if (u = document.getElementById('v4dev'))
154 u.innerHTML = st[i].defroutev4.dev;
156 if (u = document.getElementById('v4metr'))
157 u.innerHTML = st[i].defroutev4.metr;
160 if (st[i].defroutev6)
162 if (u = document.getElementById('v6dst'))
163 u.innerHTML = st[i].defroutev6.dest;
165 if (u = document.getElementById('v6gw'))
166 u.innerHTML = st[i].defroutev6.gateway;
168 if (u = document.getElementById('v6dev'))
169 u.innerHTML = st[i].defroutev6.dev;
171 if (u = document.getElementById('v6metr'))
172 u.innerHTML = st[i].defroutev6.metr;
179 <div class="cbi-map">
181 <div class="cbi-section-node">
182 <div class="cbi-value"><label class="cbi-value-title"><%:System%></label><div class="cbi-value-field"><%=system%></div></div>
183 <div class="cbi-value"><label class="cbi-value-title"><%:Processor%></label><div class="cbi-value-field"><%=model%></div></div>
184 <div class="cbi-value"><label class="cbi-value-title"><%:Load%></label><div class="cbi-value-field" id="dynload"><%=load%></div></div>
185 <div class="cbi-value"><label class="cbi-value-title"><%:Memory%></label><div class="cbi-value-field" id="dynmem"><%=mem%></div></div>
186 <div class="cbi-value"><label class="cbi-value-title"><%:Local Time%></label><div class="cbi-value-field" id="dyntime"><%=local_time%></div></div>
187 <div class="cbi-value"><label class="cbi-value-title"><%:Uptime%></label><div class="cbi-value-field" id="dynuptime"><%=uptime%></div></div>
191 <% if devices[1] then %>
193 <div class="cbi-map">
194 <h2><%:Wireless Overview%></h2>
196 <% if not has_iwinfo then %>
197 <div class="errorbox">
198 <strong><%:Package libiwinfo required!%></strong><br />
199 <%_The <em>libiwinfo</em> package is not installed. You must install this component for working wireless configuration!%>
203 <div class="cbi-section">
204 <div class="cbi-section-node">
205 <table class="cbi-section-table">
206 <tr class="cbi-section-table-titles">
207 <th class="cbi-section-table-cell"><%:Signal%></th>
208 <th class="cbi-section-table-cell"><%:Bitrate%></th>
209 <th class="cbi-section-table-cell"><%:SSID%></th>
210 <th class="cbi-section-table-cell"><%:BSSID%></th>
211 <th class="cbi-section-table-cell"><%:Channel%></th>
212 <th class="cbi-section-table-cell"><%:Mode%></th>
213 <th class="cbi-section-table-cell"><%:TX%>-<%:Power%></th>
214 <th class="cbi-section-table-cell"><%:Interface%></th>
217 for _, dev in ipairs(devices) do
219 for _, net in ipairs(dev:get_wifinets()) do
220 netlist[#netlist+1] = net:ifname()
221 netdevs[net:ifname()] = dev:name()
223 if net.iwdata.ifname then
224 local signal = net.iwinfo.signal or "N/A"
225 local noise = net.iwinfo.noise or "N/A"
226 local q = net.iwinfo.quality or "0"
227 local qmax = net.iwinfo.quality_max or "100"
228 local qperc = q / qmax * 100
231 icon = "signal-none.png"
232 elseif qperc < 26 then
233 icon = "signal-0-25.png"
234 elseif qperc < 51 then
235 icon = "signal-25-50.png"
236 elseif qperc < 76 then
237 icon = "signal-50-75.png"
238 elseif qperc < 100 then
239 icon = "signal-75-100.png"
241 icon = "signal-0.png"
244 signal_string = "<img src='"..resource.."/icons/"..icon.."' title='Signal: "..signal.." db / Noise: "..noise.." db' alt='Signal Quality'></img>"
246 local ssid = net.iwinfo.ssid or "N/A"
247 local bssid = net.iwinfo.bssid or "N/A"
248 local chan = net.iwinfo.channel or "N/A"
249 local mode = net.iwinfo.mode or "N/A"
250 local txpwr = net.iwinfo.txpower or "N/A"
251 if txpwr ~= "N/A" then
252 txpwr = txpwr.." dbm"
254 local bitrate = net.iwinfo.bitrate or "N/A"
255 if bitrate ~= "N/A" then
256 bitrate = ( bitrate / 1000 ).."Mb/s"
258 local interface = net.iwdata.ifname or "N/A"
260 <tr class="cbi-section-table-row cbi-rowstyle-1">
261 <td class="cbi-value-field" id="<%=net:ifname()%>-signal"><%=signal_string%></td>
262 <td class="cbi-value-field" id="<%=net:ifname()%>-bitrate"><%=bitrate%></td>
263 <td class="cbi-value-field" id="<%=net:ifname()%>-ssid"><%=ssid%></td>
264 <td class="cbi-value-field" id="<%=net:ifname()%>-bssid"><%=bssid%></td>
265 <td class="cbi-value-field" id="<%=net:ifname()%>-channel"><%=chan%></td>
266 <td class="cbi-value-field" id="<%=net:ifname()%>-mode"><%=mode%></td>
267 <td class="cbi-value-field" id="<%=net:ifname()%>-txpower"><%=txpwr%></td>
268 <td class="cbi-value-field"><%=interface%></td>
279 <div class="cbi-map">
280 <h2><%:Default routes%></h2>
281 <div class="cbi-section">
282 <div class="cbi-section-node">
284 <% if not defroutev4 and not defroutev6 then %>
285 <%:No default routes known.%>
287 <table class="cbi-section-table">
288 <tr class="cbi-section-table-titles">
289 <th class="cbi-section-table-cell"><%:Network%></th>
290 <th class="cbi-section-table-cell"><%:Interface%></th>
291 <th class="cbi-section-table-cell"><%:Gateway%></th>
292 <th class="cbi-section-table-cell"><%:Metric%></th>
295 <% if defroutev4 then %>
297 <tr class="cbi-section-table-row cbi-rowstyle-1">
298 <td class="cbi-value-field" id="v4dst"><%=defroutev4.dest%></td>
299 <td class="cbi-value-field" id="v4dev"><%=defroutev4.device%></td>
300 <td class="cbi-value-field" id="v4gw"><%=defroutev4.gateway%></td>
301 <td class="cbi-value-field" id="v4metr"><%=defroutev4.metric%></td>
305 if defroutev6 then %>
307 <tr class="cbi-section-table-row cbi-rowstyle-2">
308 <td class="cbi-value-field" id="v6dst"><%=defroutev6.dest:string()%></td>
309 <td class="cbi-value-field" id="v6dev"><%=defroutev6.device%></td>
310 <td class="cbi-value-field" id="v6gw"><%=defroutev6.nexthop:string()%></td>
311 <td class="cbi-value-field" id="v6metr"><%=defroutev6.metric%></td>