summaryrefslogtreecommitdiffhomepage
path: root/modules/freifunk/luasrc/view
diff options
context:
space:
mode:
authorManuel Munz <freifunk@somakoma.de>2010-11-26 11:01:08 +0000
committerManuel Munz <freifunk@somakoma.de>2010-11-26 11:01:08 +0000
commitf71776c1cda35263e70659c5ea54a8d5822dba97 (patch)
tree4ec6eebc08f6a087b15c05ba8471cdf0604eacd8 /modules/freifunk/luasrc/view
parentf1c6b2974b390ded27dda7b6d3165111a1387cea (diff)
modules/freifunk: Rewrite status as view and use iwinfo
Diffstat (limited to 'modules/freifunk/luasrc/view')
-rw-r--r--modules/freifunk/luasrc/view/freifunk/public_status.htm173
1 files changed, 173 insertions, 0 deletions
diff --git a/modules/freifunk/luasrc/view/freifunk/public_status.htm b/modules/freifunk/luasrc/view/freifunk/public_status.htm
new file mode 100644
index 0000000000..efeb40566d
--- /dev/null
+++ b/modules/freifunk/luasrc/view/freifunk/public_status.htm
@@ -0,0 +1,173 @@
+<%
+local sys = require "luci.sys"
+local twa = require "luci.tools.webadmin"
+
+-- System
+local system, model, memtotal, memcached, membuffers, memfree = sys.sysinfo()
+local uptime = twa.date_format(tonumber(sys.uptime()))
+local_time = os.date("%c")
+local load1, load5, load15 = sys.loadavg()
+local load = string.format("%.2f, %.2f, %.2f", load1, load5, load15)
+local memory = string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)",
+ tonumber(memtotal) / 1024,
+ 100 * memcached / memtotal,
+ tostring(translate("cached")),
+ 100 * membuffers / memtotal,
+ tostring(translate("buffered")),
+ 100 * memfree / memtotal,
+ tostring(translate("free"))
+)
+
+-- wireless
+local uci = require "luci.model.uci".cursor()
+local ntm = require "luci.model.network"
+ntm.init(uci)
+local devices = ntm:get_wifidevs()
+local netlist = { }
+local netdevs = { }
+local dev
+
+-- Routes
+local defroutev4 = sys.net.defaultroute()
+local defroutev6 = sys.net.defaultroute6 ()
+
+%>
+<%+header%>
+
+<div class="cbi-map">
+ <h2><%:System%></h2>
+ <div class="cbi-section-node">
+ <div class="cbi-value"><label class="cbi-value-title"><%:System%></label><div class="cbi-value-field"><%=system%></div></div>
+ <div class="cbi-value"><label class="cbi-value-title"><%:Processor%></label><div class="cbi-value-field"><%=model%></div></div>
+ <div class="cbi-value"><label class="cbi-value-title"><%:Load%></label><div class="cbi-value-field"><%=load%></div></div>
+ <div class="cbi-value"><label class="cbi-value-title"><%:Memory%></label><div class="cbi-value-field"><%=memory%></div></div>
+ <div class="cbi-value"><label class="cbi-value-title"><%:Local Time%></label><div class="cbi-value-field"><%=local_time%></div></div>
+ <div class="cbi-value"><label class="cbi-value-title"><%:Uptime%></label><div class="cbi-value-field"><%=uptime%></div></div>
+ </div>
+</div>
+
+<% if devices[1] then %>
+
+<div class="cbi-map">
+ <h2><%:Wireless Overview%></h2>
+ <div class="cbi-section">
+ <div class="cbi-section-node">
+ <table class="cbi-section-table">
+ <tr class="cbi-section-table-titles">
+ <th class="cbi-section-table-cell"><%:Signal%></th>
+ <th class="cbi-section-table-cell"><%:Bitrate%></th>
+ <th class="cbi-section-table-cell"><%:SSID%></th>
+ <th class="cbi-section-table-cell"><%:BSSID%></th>
+ <th class="cbi-section-table-cell"><%:Channel%></th>
+ <th class="cbi-section-table-cell"><%:Mode%></th>
+ <th class="cbi-section-table-cell"><%:TX%>-<%:Power%></th>
+ <th class="cbi-section-table-cell"><%:Interface%></th>
+ </tr>
+ <%
+ for _, dev in ipairs(devices) do
+ local net
+ for _, net in ipairs(dev:get_wifinets()) do
+ netlist[#netlist+1] = net:ifname()
+ netdevs[net:ifname()] = dev:name()
+
+ if net.iwdata.ifname then
+ local signal = net.iwinfo.signal or "N/A"
+ local noise = net.iwinfo.noise or "N/A"
+ local q = net.iwinfo.quality or "0"
+ local qmax = net.iwinfo.quality_max or "100"
+ local qperc = q / qmax * 100
+
+ if qperc == 0 then
+ icon = "signal-none.png"
+ elseif qperc < 26 then
+ icon = "signal-0-25.png"
+ elseif qperc < 51 then
+ icon = "signal-25-50.png"
+ elseif qperc < 76 then
+ icon = "signal-50-75.png"
+ elseif qperc < 100 then
+ icon = "signal-75-100.png"
+ else
+ icon = "signal-0.png"
+ end
+
+ signal_string = "<img src='"..resource.."/icons/"..icon.."' title='Signal: "..signal.." db / Noise: "..noise.." db' alt='Signal Quality'></img>"
+
+ local ssid = net.iwinfo.ssid or "N/A"
+ local bssid = net.iwinfo.bssid or "N/A"
+ local chan = net.iwinfo.channel or "N/A"
+ local mode = net.iwinfo.mode or "N/A"
+ local txpwr = net.iwinfo.txpower or "N/A"
+ if txpwr ~= "N/A" then
+ txpwr = txpwr.." dbm"
+ end
+ local bitrate = net.iwinfo.bitrate or "N/A"
+ if bitrate ~= "N/A" then
+ bitrate = ( bitrate / 1000 ).."Mb/s"
+ end
+ local interface = net.iwdata.ifname or "N/A"
+ %>
+ <tr class="cbi-section-table-row cbi-rowstyle-1">
+ <td class="cbi-value-field"><%=signal_string%></td>
+ <td class="cbi-value-field"><%=bitrate%></td>
+ <td class="cbi-value-field"><%=ssid%></td>
+ <td class="cbi-value-field"><%=bssid%></td>
+ <td class="cbi-value-field"><%=chan%></td>
+ <td class="cbi-value-field"><%=mode%></td>
+ <td class="cbi-value-field"><%=txpwr%></td>
+ <td class="cbi-value-field"><%=interface%></td>
+ </tr>
+ <% end
+ end
+ end %>
+ </table>
+ </div>
+ </div>
+</div>
+<% end %>
+
+<div class="cbi-map">
+ <h2><%:Default routes%></h2>
+ <div class="cbi-section">
+ <div class="cbi-section-node">
+ <table class="cbi-section-table">
+
+<% if not defroutev4 and not defroutev6 then %>
+ <%:No defaultroutes known.%>
+<%else%>
+ <tr class="cbi-section-table-titles">
+ <th class="cbi-section-table-cell"><%:Network%></th>
+ <th class="cbi-section-table-cell"><%:Interface%></th>
+ <th class="cbi-section-table-cell"><%:Gateway%></th>
+ <th class="cbi-section-table-cell"><%:Metric%></th>
+ </tr>
+
+ <% if defroutev4 then %>
+
+ <tr class="cbi-section-table-row cbi-rowstyle-1">
+ <td class="cbi-value-field"><%=defroutev4.dest:string()%></td>
+ <td class="cbi-value-field"><%=defroutev4.device%></td>
+ <td class="cbi-value-field"><%=defroutev4.gateway:string()%></td>
+ <td class="cbi-value-field"><%=defroutev4.metric%></td>
+ </tr>
+
+ <% end
+ if defroutev6 then %>
+
+ <tr class="cbi-section-table-row cbi-rowstyle-2">
+ <td class="cbi-value-field"><%=defroutev6.dest:string()%></td>
+ <td class="cbi-value-field"><%=defroutev6.device%></td>
+ <td class="cbi-value-field"><%=defroutev6.nexthop:string()%></td>
+ <td class="cbi-value-field"><%=defroutev6.metric%></td>
+ </tr>
+
+ <% end %>
+
+ </table>
+ </div>
+ </div>
+</div>
+<% end %>
+
+<%+footer%>
+