diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2014-12-03 15:17:05 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2015-01-08 16:26:20 +0100 |
commit | 1bb4822dca6113f73e3bc89e2acf15935e6f8e92 (patch) | |
tree | 35e16f100466e4e00657199b38bb3d87d52bf73f /modules/luci-mod-admin-full/luasrc/view/admin_status | |
parent | 9edd0e46c3f880727738ce8ca6ff1c8b85f99ef4 (diff) |
Rework LuCI build system
* Rename subdirectories to their repective OpenWrt package names
* Make each LuCI module its own standalone package
* Deploy a shared luci.mk which is used by each module Makefile
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'modules/luci-mod-admin-full/luasrc/view/admin_status')
9 files changed, 2381 insertions, 0 deletions
diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_status/bandwidth.htm b/modules/luci-mod-admin-full/luasrc/view/admin_status/bandwidth.htm new file mode 100644 index 0000000000..0c53c95bed --- /dev/null +++ b/modules/luci-mod-admin-full/luasrc/view/admin_status/bandwidth.htm @@ -0,0 +1,311 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2010 Jo-Philipp Wich <xm@subsignal.org> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ + +-%> + +<%- + local ntm = require "luci.model.network".init() + + local dev + local devices = { } + for _, dev in luci.util.vspairs(luci.sys.net.devices()) do + if dev ~= "lo" and not ntm:ignore_interface(dev) then + devices[#devices+1] = dev + end + end + + local curdev = luci.dispatcher.context.requestpath + curdev = curdev[#curdev] ~= "bandwidth" and curdev[#curdev] or devices[1] +-%> + +<%+header%> + +<script type="text/javascript" src="<%=resource%>/cbi.js"></script> +<script type="text/javascript">//<![CDATA[ + var bwxhr = new XHR(); + + var G; + var TIME = 0; + var RXB = 1; + var RXP = 2; + var TXB = 3; + var TXP = 4; + + var width = 760; + var height = 300; + var step = 5; + + var data_wanted = Math.floor(width / step); + var data_fill = 0; + var data_stamp = 0; + + var data_rx = [ ]; + var data_tx = [ ]; + + var line_rx; + var line_tx; + + var label_25; + var label_50; + var label_75; + + var label_rx_cur; + var label_rx_avg; + var label_rx_peak; + + var label_tx_cur; + var label_tx_avg; + var label_tx_peak; + + var label_scale; + + + function bandwidth_label(bytes, br) + { + var uby = '<%:kB/s%>'; + var kby = (bytes / 1024); + + if (kby >= 1024) + { + uby = '<%:MB/s%>'; + kby = kby / 1024; + } + + var ubi = '<%:kbit/s%>'; + var kbi = (bytes * 8 / 1024); + + if (kbi >= 1024) + { + ubi = '<%:Mbit/s%>'; + kbi = kbi / 1024; + } + + return String.format("%f %s%s(%f %s)", + kbi.toFixed(2), ubi, + br ? '<br />' : ' ', + kby.toFixed(2), uby + ); + } + + /* wait for SVG */ + window.setTimeout( + function() { + var svg = document.getElementById('bwsvg'); + + try { + G = svg.getSVGDocument + ? svg.getSVGDocument() : svg.contentDocument; + } + catch(e) { + G = document.embeds['bwsvg'].getSVGDocument(); + } + + if (!G) + { + window.setTimeout(arguments.callee, 1000); + } + else + { + /* find sizes */ + width = svg.offsetWidth - 2; + height = svg.offsetHeight - 2; + data_wanted = Math.ceil(width / step); + + /* prefill datasets */ + for (var i = 0; i < data_wanted; i++) + { + data_rx[i] = 0; + data_tx[i] = 0; + } + + /* find svg elements */ + line_rx = G.getElementById('rx'); + line_tx = G.getElementById('tx'); + + label_25 = G.getElementById('label_25'); + label_50 = G.getElementById('label_50'); + label_75 = G.getElementById('label_75'); + + label_rx_cur = document.getElementById('rx_bw_cur'); + label_rx_avg = document.getElementById('rx_bw_avg'); + label_rx_peak = document.getElementById('rx_bw_peak'); + + label_tx_cur = document.getElementById('tx_bw_cur'); + label_tx_avg = document.getElementById('tx_bw_avg'); + label_tx_peak = document.getElementById('tx_bw_peak'); + + label_scale = document.getElementById('scale'); + + + /* plot horizontal time interval lines */ + for (var i = width % (step * 60); i < width; i += step * 60) + { + var line = G.createElementNS('http://www.w3.org/2000/svg', 'line'); + line.setAttribute('x1', i); + line.setAttribute('y1', 0); + line.setAttribute('x2', i); + line.setAttribute('y2', '100%'); + line.setAttribute('style', 'stroke:black;stroke-width:0.1'); + + var text = G.createElementNS('http://www.w3.org/2000/svg', 'text'); + text.setAttribute('x', i + 5); + text.setAttribute('y', 15); + text.setAttribute('style', 'fill:#999999; font-size:9pt'); + text.appendChild(G.createTextNode(Math.round((width - i) / step / 60) + 'm')); + + label_25.parentNode.appendChild(line); + label_25.parentNode.appendChild(text); + } + + label_scale.innerHTML = String.format('<%:(%d minute window, %d second interval)%>', data_wanted / 60, 3); + + /* render datasets, start update interval */ + XHR.poll(3, '<%=build_url("admin/status/realtime/bandwidth_status", curdev)%>', null, + function(x, data) + { + var data_max = 0; + var data_scale = 0; + + var data_rx_avg = 0; + var data_tx_avg = 0; + + var data_rx_peak = 0; + var data_tx_peak = 0; + + for (var i = data_stamp ? 0 : 1; i < data.length; i++) + { + /* skip overlapping entries */ + if (data[i][TIME] <= data_stamp) + continue; + + /* normalize difference against time interval */ + if (i > 0) + { + var time_delta = data[i][TIME] - data[i-1][TIME]; + if (time_delta) + { + data_rx.push((data[i][RXB] - data[i-1][RXB]) / time_delta); + data_tx.push((data[i][TXB] - data[i-1][TXB]) / time_delta); + } + } + } + + /* cut off outdated entries */ + data_rx = data_rx.slice(data_rx.length - data_wanted, data_rx.length); + data_tx = data_tx.slice(data_tx.length - data_wanted, data_tx.length); + + /* find peak */ + for (var i = 0; i < data_rx.length; i++) + { + data_max = Math.max(data_max, data_rx[i]); + data_max = Math.max(data_max, data_tx[i]); + + data_rx_peak = Math.max(data_rx_peak, data_rx[i]); + data_tx_peak = Math.max(data_tx_peak, data_tx[i]); + + if (i > 0) + { + data_rx_avg = (data_rx_avg + data_rx[i]) / 2; + data_tx_avg = (data_tx_avg + data_tx[i]) / 2; + } + else + { + data_rx_avg = data_rx[i]; + data_tx_avg = data_tx[i]; + } + } + + /* remember current timestamp, calculate horizontal scale */ + data_stamp = data[data.length-1][TIME]; + data_scale = height / (data_max * 1.1); + + + /* plot data */ + var pt_rx = '0,' + height; + var pt_tx = '0,' + height; + + var y_rx = 0; + var y_tx = 0; + + for (var i = 0; i < data_rx.length; i++) + { + var x = i * step; + + y_rx = height - Math.floor(data_rx[i] * data_scale); + y_tx = height - Math.floor(data_tx[i] * data_scale); + + pt_rx += ' ' + x + ',' + y_rx; + pt_tx += ' ' + x + ',' + y_tx; + } + + pt_rx += ' ' + width + ',' + y_rx + ' ' + width + ',' + height; + pt_tx += ' ' + width + ',' + y_tx + ' ' + width + ',' + height; + + + line_rx.setAttribute('points', pt_rx); + line_tx.setAttribute('points', pt_tx); + + label_25.firstChild.data = bandwidth_label(1.1 * 0.25 * data_max); + label_50.firstChild.data = bandwidth_label(1.1 * 0.50 * data_max); + label_75.firstChild.data = bandwidth_label(1.1 * 0.75 * data_max); + + label_rx_cur.innerHTML = bandwidth_label(data_rx[data_rx.length-1], true); + label_tx_cur.innerHTML = bandwidth_label(data_tx[data_tx.length-1], true); + + label_rx_avg.innerHTML = bandwidth_label(data_rx_avg, true); + label_tx_avg.innerHTML = bandwidth_label(data_tx_avg, true); + + label_rx_peak.innerHTML = bandwidth_label(data_rx_peak, true); + label_tx_peak.innerHTML = bandwidth_label(data_tx_peak, true); + } + ); + } + }, 1000 + ); +//]]></script> + +<h2><a id="content" name="content"><%:Realtime Traffic%></a></h2> + +<ul class="cbi-tabmenu"> + <% for _, dev in ipairs(devices) do %> + <li class="cbi-tab<%= dev == curdev and "" or "-disabled" %>"><a href="<%=pcdata(dev)%>"><%=pcdata(dev)%></a></li> + <% end %> +</ul> + +<embed id="bwsvg" style="width:100%; height:300px; border:1px solid #000000; background-color:#FFFFFF" src="<%=resource%>/bandwidth.svg" /> +<div style="text-align:right"><small id="scale">-</small></div> +<br /> + +<table style="width:100%; table-layout:fixed" cellspacing="5"> + <tr> + <td style="text-align:right; vertical-align:top"><strong style="border-bottom:2px solid blue"><%:Inbound:%></strong></td> + <td id="rx_bw_cur">0 <%:kbit/s%><br />(0 <%:kB/s%>)</td> + + <td style="text-align:right; vertical-align:top"><strong><%:Average:%></strong></td> + <td id="rx_bw_avg">0 <%:kbit/s%><br />(0 <%:kB/s%>)</td> + + <td style="text-align:right; vertical-align:top"><strong><%:Peak:%></strong></td> + <td id="rx_bw_peak">0 <%:kbit/s%><br />(0 <%:kB/s%>)</td> + </tr> + <tr> + <td style="text-align:right; vertical-align:top"><strong style="border-bottom:2px solid green"><%:Outbound:%></strong></td> + <td id="tx_bw_cur">0 <%:kbit/s%><br />(0 <%:kB/s%>)</td> + + <td style="text-align:right; vertical-align:top"><strong><%:Average:%></strong></td> + <td id="tx_bw_avg">0 <%:kbit/s%><br />(0 <%:kB/s%>)</td> + + <td style="text-align:right; vertical-align:top"><strong><%:Peak:%></strong></td> + <td id="tx_bw_peak">0 <%:kbit/s%><br />(0 <%:kB/s%>)</td> + </tr> +</table> + +<%+footer%> diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_status/connections.htm b/modules/luci-mod-admin-full/luasrc/view/admin_status/connections.htm new file mode 100644 index 0000000000..80c8b70e3c --- /dev/null +++ b/modules/luci-mod-admin-full/luasrc/view/admin_status/connections.htm @@ -0,0 +1,382 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2010 Jo-Philipp Wich <xm@subsignal.org> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +-%> + +<%+header%> + +<script type="text/javascript" src="<%=resource%>/cbi.js"></script> +<script type="text/javascript">//<![CDATA[ + var bwxhr = new XHR(); + + var G; + var TIME = 0; + var UDP = 1; + var TCP = 2; + var OTHER = 3; + + var width = 760; + var height = 300; + var step = 5; + + var data_wanted = Math.floor(width / step); + var data_fill = 0; + var data_stamp = 0; + + var data_udp = [ ]; + var data_tcp = [ ]; + var data_otr = [ ]; + + var line_udp; + var line_tcp; + + var label_25; + var label_50; + var label_75; + + var label_udp_cur; + var label_udp_avg; + var label_udp_peak; + + var label_tcp_cur; + var label_tcp_avg; + var label_tcp_peak; + + var label_otr_cur; + var label_otr_avg; + var label_otr_peak; + + var label_scale; + + var conn_table; + + var dns_cache = { }; + + + /* wait for SVG */ + window.setTimeout( + function() { + var svg = document.getElementById('bwsvg'); + + try { + G = svg.getSVGDocument + ? svg.getSVGDocument() : svg.contentDocument; + } + catch(e) { + G = document.embeds['bwsvg'].getSVGDocument(); + } + + if (!G) + { + window.setTimeout(arguments.callee, 1000); + } + else + { + /* find sizes */ + width = svg.offsetWidth - 2; + height = svg.offsetHeight - 2; + data_wanted = Math.ceil(width / step); + + /* prefill datasets */ + for (var i = 0; i < data_wanted; i++) + { + data_udp[i] = 0; + data_tcp[i] = 0; + data_otr[i] = 0; + } + + /* find svg elements */ + line_udp = G.getElementById('udp'); + line_tcp = G.getElementById('tcp'); + line_otr = G.getElementById('other'); + + label_25 = G.getElementById('label_25'); + label_50 = G.getElementById('label_50'); + label_75 = G.getElementById('label_75'); + + label_udp_cur = document.getElementById('lb_udp_cur'); + label_udp_avg = document.getElementById('lb_udp_avg'); + label_udp_peak = document.getElementById('lb_udp_peak'); + + label_tcp_cur = document.getElementById('lb_tcp_cur'); + label_tcp_avg = document.getElementById('lb_tcp_avg'); + label_tcp_peak = document.getElementById('lb_tcp_peak'); + + label_otr_cur = document.getElementById('lb_otr_cur'); + label_otr_avg = document.getElementById('lb_otr_avg'); + label_otr_peak = document.getElementById('lb_otr_peak'); + + label_scale = document.getElementById('scale'); + + conn_table = document.getElementById('connections'); + + + /* plot horizontal time interval lines */ + for (var i = width % (step * 60); i < width; i += step * 60) + { + var line = G.createElementNS('http://www.w3.org/2000/svg', 'line'); + line.setAttribute('x1', i); + line.setAttribute('y1', 0); + line.setAttribute('x2', i); + line.setAttribute('y2', '100%'); + line.setAttribute('style', 'stroke:black;stroke-width:0.1'); + + var text = G.createElementNS('http://www.w3.org/2000/svg', 'text'); + text.setAttribute('x', i + 5); + text.setAttribute('y', 15); + text.setAttribute('style', 'fill:#999999; font-size:9pt'); + text.appendChild(G.createTextNode(Math.round((width - i) / step / 60) + 'm')); + + label_25.parentNode.appendChild(line); + label_25.parentNode.appendChild(text); + } + + label_scale.innerHTML = String.format('<%:(%d minute window, %d second interval)%>', data_wanted / 60, 3); + + /* render datasets, start update interval */ + XHR.poll(3, '<%=build_url("admin/status/realtime/connections_status")%>', null, + function(x, json) + { + var conn = json.connections; + + while (conn_table.rows.length > 1) + conn_table.rows[0].parentNode.deleteRow(-1); + + + var lookup_queue = [ ]; + + conn.sort(function(a, b) { + return b.bytes - a.bytes; + }); + + for (var i = 0; i < conn.length; i++) + { + var c = conn[i]; + + if (c.src == '127.0.0.1' && c.dst == '127.0.0.1') + continue; + + var tr = conn_table.rows[0].parentNode.insertRow(-1); + tr.className = 'cbi-section-table-row cbi-rowstyle-' + (1 + (i % 2)); + + if (!dns_cache[c.src]) + lookup_queue.push(c.src); + + if (!dns_cache[c.dst]) + lookup_queue.push(c.dst); + + var src = dns_cache[c.src] || (c.layer3 == 'ipv6' ? '[' + c.src + ']' : c.src); + var dst = dns_cache[c.dst] || (c.layer3 == 'ipv6' ? '[' + c.dst + ']' : c.dst); + + tr.insertCell(-1).innerHTML = c.layer3.toUpperCase(); + tr.insertCell(-1).innerHTML = c.layer4.toUpperCase(); + tr.insertCell(-1).innerHTML = String.format('%s:%d', src, c.sport); + tr.insertCell(-1).innerHTML = String.format('%s:%d', dst, c.dport); + + var traf = tr.insertCell(-1); + traf.style.whiteSpace = 'nowrap'; + traf.innerHTML = String.format('%1024.2mB (%d <%:Pkts.%>)', c.bytes, c.packets); + } + + if (lookup_queue.length > 0) + XHR.get('<%=build_url("admin/status/nameinfo")%>/' + lookup_queue.slice(0, 100).join('/'), null, + function(x, json) + { + for (var addr in json) + dns_cache[addr] = json[addr]; + } + ); + + + var data = json.statistics; + + var data_max = 0; + var data_scale = 0; + + var data_udp_avg = 0; + var data_tcp_avg = 0; + var data_otr_avg = 0; + + var data_udp_peak = 0; + var data_tcp_peak = 0; + var data_otr_peak = 0; + + for (var i = data_stamp ? 0 : 1; i < data.length; i++) + { + /* skip overlapping entries */ + if (data[i][TIME] <= data_stamp) + continue; + + data_udp.push(data[i][UDP]); + data_tcp.push(data[i][TCP]); + data_otr.push(data[i][OTHER]); + } + + /* cut off outdated entries */ + data_udp = data_udp.slice(data_udp.length - data_wanted, data_udp.length); + data_tcp = data_tcp.slice(data_tcp.length - data_wanted, data_tcp.length); + data_otr = data_otr.slice(data_otr.length - data_wanted, data_otr.length); + + /* find peak */ + for (var i = 0; i < data_udp.length; i++) + { + data_max = Math.max(data_max, data_udp[i]); + data_max = Math.max(data_max, data_tcp[i]); + data_max = Math.max(data_max, data_otr[i]); + + data_udp_peak = Math.max(data_udp_peak, data_udp[i]); + data_tcp_peak = Math.max(data_tcp_peak, data_tcp[i]); + data_otr_peak = Math.max(data_otr_peak, data_otr[i]); + + if (i > 0) + { + data_udp_avg = (data_udp_avg + data_udp[i]) / 2; + data_tcp_avg = (data_tcp_avg + data_tcp[i]) / 2; + data_otr_avg = (data_otr_avg + data_otr[i]) / 2; + } + else + { + data_udp_avg = data_udp[i]; + data_tcp_avg = data_tcp[i]; + data_otr_avg = data_otr[i]; + } + } + + /* remember current timestamp, calculate horizontal scale */ + data_stamp = data[data.length-1][TIME]; + data_scale = height / (data_max * 1.1); + + + /* plot data */ + var pt_udp = '0,' + height; + var pt_tcp = '0,' + height; + var pt_otr = '0,' + height; + + var y_udp = 0; + var y_tcp = 0; + var y_otr = 0; + + for (var i = 0; i < data_udp.length; i++) + { + var x = i * step; + + y_udp = height - Math.floor(data_udp[i] * data_scale); + y_tcp = height - Math.floor(data_tcp[i] * data_scale); + y_otr = height - Math.floor(data_otr[i] * data_scale); + + pt_udp += ' ' + x + ',' + y_udp; + pt_tcp += ' ' + x + ',' + y_tcp; + pt_otr += ' ' + x + ',' + y_otr; + } + + pt_udp += ' ' + width + ',' + y_udp + ' ' + width + ',' + height; + pt_tcp += ' ' + width + ',' + y_tcp + ' ' + width + ',' + height; + pt_otr += ' ' + width + ',' + y_otr + ' ' + width + ',' + height; + + + var order = [ + [ line_udp, data_udp[data_udp.length-1] ], + [ line_tcp, data_tcp[data_tcp.length-1] ], + [ line_otr, data_otr[data_otr.length-1] ] + ]; + + order.sort(function(a, b) { return b[1] - a[1] }); + + for (var i = 0; i < order.length; i++) + order[i][0].parentNode.appendChild(order[i][0]); + + + line_udp.setAttribute('points', pt_udp); + line_tcp.setAttribute('points', pt_tcp); + line_otr.setAttribute('points', pt_otr); + + label_25.firstChild.data = Math.floor(1.1 * 0.25 * data_max); + label_50.firstChild.data = Math.floor(1.1 * 0.50 * data_max); + label_75.firstChild.data = Math.floor(1.1 * 0.75 * data_max); + + label_udp_cur.innerHTML = Math.floor(data_udp[data_udp.length-1]); + label_tcp_cur.innerHTML = Math.floor(data_tcp[data_tcp.length-1]); + label_otr_cur.innerHTML = Math.floor(data_otr[data_otr.length-1]); + + label_udp_avg.innerHTML = Math.floor(data_udp_avg); + label_tcp_avg.innerHTML = Math.floor(data_tcp_avg); + label_otr_avg.innerHTML = Math.floor(data_otr_avg); + + label_udp_peak.innerHTML = Math.floor(data_udp_peak); + label_tcp_peak.innerHTML = Math.floor(data_tcp_peak); + label_otr_peak.innerHTML = Math.floor(data_otr_peak); + } + ); + } + }, 1000 + ); +//]]></script> + +<h2><a id="content" name="content"><%:Realtime Connections%></a></h2> + +<div class="cbi-map-descr"><%:This page gives an overview over currently active network connections.%></div> + +<fieldset class="cbi-section" id="cbi-table-table"> + <legend><%:Active Connections%></legend> + + <embed id="bwsvg" style="width:100%; height:300px; border:1px solid #000000; background-color:#FFFFFF" src="<%=resource%>/connections.svg" /> + <div style="text-align:right"><small id="scale">-</small></div> + <br /> + + <table style="width:100%; table-layout:fixed" cellspacing="5"> + <tr> + <td style="text-align:right; vertical-align:top"><strong style="border-bottom:2px solid blue"><%:UDP:%></strong></td> + <td id="lb_udp_cur">0</td> + + <td style="text-align:right; vertical-align:top"><strong><%:Average:%></strong></td> + <td id="lb_udp_avg">0</td> + + <td style="text-align:right; vertical-align:top"><strong><%:Peak:%></strong></td> + <td id="lb_udp_peak">0</td> + </tr> + <tr> + <td style="text-align:right; vertical-align:top"><strong style="border-bottom:2px solid green"><%:TCP:%></strong></td> + <td id="lb_tcp_cur">0</td> + + <td style="text-align:right; vertical-align:top"><strong><%:Average:%></strong></td> + <td id="lb_tcp_avg">0</td> + + <td style="text-align:right; vertical-align:top"><strong><%:Peak:%></strong></td> + <td id="lb_tcp_peak">0</td> + </tr> + <tr> + <td style="text-align:right; vertical-align:top"><strong style="border-bottom:2px solid red"><%:Other:%></strong></td> + <td id="lb_otr_cur">0</td> + + <td style="text-align:right; vertical-align:top"><strong><%:Average:%></strong></td> + <td id="lb_otr_avg">0</td> + + <td style="text-align:right; vertical-align:top"><strong><%:Peak:%></strong></td> + <td id="lb_otr_peak">0</td> + </tr> + </table> + <br /> + + <div class="cbi-section-node"> + <table class="cbi-section-table" id="connections"> + <tr class="cbi-section-table-titles"> + <th class="cbi-section-table-cell"><%:Network%></th> + <th class="cbi-section-table-cell"><%:Protocol%></th> + <th class="cbi-section-table-cell"><%:Source%></th> + <th class="cbi-section-table-cell"><%:Destination%></th> + <th class="cbi-section-table-cell"><%:Transfer%></th> + </tr> + + <tr><td colspan="5"><em><%:Collecting data...%></em></td></tr> + </table> + </div> +</fieldset> + +<%+footer%> diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_status/dmesg.htm b/modules/luci-mod-admin-full/luasrc/view/admin_status/dmesg.htm new file mode 100644 index 0000000000..7757460a05 --- /dev/null +++ b/modules/luci-mod-admin-full/luasrc/view/admin_status/dmesg.htm @@ -0,0 +1,20 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2008 Steven Barth <steven@midlink.org> +Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id: syslog.htm 3622 2008-10-23 16:05:55Z jow $ + +-%> +<%+header%> +<h2><a id="content" name="content"><%:Kernel Log%></a></h2> +<div id="content_syslog"> +<textarea readonly="readonly" wrap="off" rows="<%=dmesg:cmatch("\n")+2%>" id="syslog"><%=dmesg:pcdata()%></textarea> +</div> +<%+footer%> diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm b/modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm new file mode 100644 index 0000000000..cfeb91ac7a --- /dev/null +++ b/modules/luci-mod-admin-full/luasrc/view/admin_status/index.htm @@ -0,0 +1,713 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2008 Steven Barth <steven@midlink.org> +Copyright 2008-2011 Jo-Philipp Wich <xm@subsignal.org> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +-%> + +<% + require "luci.fs" + require "luci.tools.status" + + local has_ipv6 = luci.fs.access("/proc/net/ipv6_route") + local has_dhcp = luci.fs.access("/etc/config/dhcp") + local has_wifi = luci.fs.stat("/etc/config/wireless") + has_wifi = has_wifi and has_wifi.size > 0 + local _, _, memtotal, memcached, membuffers, memfree, _, swaptotal, swapcached, swapfree = luci.sys.sysinfo() + local has_swap + if swaptotal > 0 then + has_swap = 1 + end + local has_dsl = luci.fs.stat("/etc/init.d/dsl_control") + + if luci.http.formvalue("status") == "1" then + local ntm = require "luci.model.network".init() + local wan = ntm:get_wannet() + local wan6 = ntm:get_wan6net() + + local conn_count = tonumber(( + luci.sys.exec("wc -l /proc/net/nf_conntrack") or + luci.sys.exec("wc -l /proc/net/ip_conntrack") or + ""):match("%d+")) or 0 + + local conn_max = tonumber(( + luci.sys.exec("sysctl net.nf_conntrack_max") or + luci.sys.exec("sysctl net.ipv4.netfilter.ip_conntrack_max") or + ""):match("%d+")) or 4096 + + local rv = { + uptime = luci.sys.uptime(), + localtime = os.date(), + loadavg = { luci.sys.loadavg() }, + memtotal = memtotal, + memcached = memcached, + membuffers = membuffers, + memfree = memfree, + swaptotal = swaptotal, + swapcached = swapcached, + swapfree = swapfree, + connmax = conn_max, + conncount = conn_count, + leases = luci.tools.status.dhcp_leases(), + leases6 = luci.tools.status.dhcp6_leases(), + wifinets = luci.tools.status.wifi_networks() + } + + if wan then + rv.wan = { + ipaddr = wan:ipaddr(), + gwaddr = wan:gwaddr(), + netmask = wan:netmask(), + dns = wan:dnsaddrs(), + expires = wan:expires(), + uptime = wan:uptime(), + proto = wan:proto(), + ifname = wan:ifname(), + link = wan:adminlink() + } + end + + if wan6 then + rv.wan6 = { + ip6addr = wan6:ip6addr(), + gw6addr = wan6:gw6addr(), + dns = wan6:dns6addrs(), + uptime = wan6:uptime(), + ifname = wan6:ifname(), + link = wan6:adminlink() + } + end + + if has_dsl then + local dsl_stat = luci.sys.exec("/etc/init.d/dsl_control lucistat") + local dsl_func = loadstring(dsl_stat) + rv.dsl = dsl_func() + end + + luci.http.prepare_content("application/json") + luci.http.write_json(rv) + + return + end + + local system, model = luci.sys.sysinfo() +-%> + +<%+header%> + +<script type="text/javascript" src="<%=resource%>/cbi.js"></script> +<script type="text/javascript">//<![CDATA[ + function progressbar(v, m) + { + var vn = parseInt(v) || 0; + var mn = parseInt(m) || 100; + var pc = Math.floor((100 / mn) * vn); + + return String.format( + '<div style="width:200px; position:relative; border:1px solid #999999">' + + '<div style="background-color:#CCCCCC; width:%d%%; height:15px">' + + '<div style="position:absolute; left:0; top:0; text-align:center; width:100%%; color:#000000">' + + '<small>%s / %s (%d%%)</small>' + + '</div>' + + '</div>' + + '</div>', pc, v, m, pc + ); + } + + var wifidevs = <%=luci.http.write_json(netdevs)%>; + var arptable = <%=luci.http.write_json(arpcache)%>; + + XHR.poll(5, '<%=REQUEST_URI%>', { status: 1 }, + function(x, info) + { + var si = document.getElementById('wan4_i'); + var ss = document.getElementById('wan4_s'); + var ifc = info.wan; + + if (ifc && ifc.ifname && ifc.proto != 'none') + { + var s = String.format( + '<strong><%:Type%>: </strong>%s<br />' + + '<strong><%:Address%>: </strong>%s<br />' + + '<strong><%:Netmask%>: </strong>%s<br />' + + '<strong><%:Gateway%>: </strong>%s<br />', + ifc.proto, + (ifc.ipaddr) ? ifc.ipaddr : '0.0.0.0', + (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '255.255.255.255', + (ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0' + ); + + for (var i = 0; i < ifc.dns.length; i++) + { + s += String.format( + '<strong><%:DNS%> %d: </strong>%s<br />', + i + 1, ifc.dns[i] + ); + } + + if (ifc.expires > -1) + { + s += String.format( + '<strong><%:Expires%>: </strong>%t<br />', + ifc.expires + ); + } + + if (ifc.uptime > 0) + { + s += String.format( + '<strong><%:Connected%>: </strong>%t<br />', + ifc.uptime + ); + } + + ss.innerHTML = String.format('<small>%s</small>', s); + si.innerHTML = String.format( + '<img src="<%=resource%>/icons/ethernet.png" />' + + '<br /><small><a href="%s">%s</a></small>', + ifc.link, ifc.ifname + ); + } + else + { + si.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>'; + ss.innerHTML = '<em><%:Not connected%></em>'; + } + + <% if has_ipv6 then %> + var si6 = document.getElementById('wan6_i'); + var ss6 = document.getElementById('wan6_s'); + var ifc6 = info.wan6; + + if (ifc6 && ifc6.ifname && ifc6.proto != 'none') + { + var s = String.format( + '<strong><%:Address%>: </strong>%s<br />' + + '<strong><%:Gateway%>: </strong>%s<br />', + (ifc6.ip6addr) ? ifc6.ip6addr : '::', + (ifc6.gw6addr) ? ifc6.gw6addr : '::' + ); + + for (var i = 0; i < ifc6.dns.length; i++) + { + s += String.format( + '<strong><%:DNS%> %d: </strong>%s<br />', + i + 1, ifc6.dns[i] + ); + } + + if (ifc6.uptime > 0) + { + s += String.format( + '<strong><%:Connected%>: </strong>%t<br />', + ifc6.uptime + ); + } + + ss6.innerHTML = String.format('<small>%s</small>', s); + si6.innerHTML = String.format( + '<img src="<%=resource%>/icons/ethernet.png" />' + + '<br /><small><a href="%s">%s</a></small>', + ifc6.link, ifc6.ifname + ); + } + else + { + si6.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>'; + ss6.innerHTML = '<em><%:Not connected%></em>'; + } + <% end %> + + <% if has_dsl then %> + var dsl_i = document.getElementById('dsl_i'); + var dsl_s = document.getElementById('dsl_s'); + + var s = String.format( + '<strong><%:Status%>: </strong>%s<br />' + + '<strong><%:Line State%>: </strong>%s [0x%x]<br />' + + '<strong><%:Line Speed%>: </strong>%s/s / %s/s<br />' + + '<strong><%:Line Attenuation%>: </strong>%s dB / %s dB<br />' + + '<strong><%:Noise Margin%>: </strong>%s dB / %s dB<br />', + info.dsl.line_state, info.dsl.line_state_detail, + info.dsl.line_state_num, + info.dsl.data_rate_down_s, info.dsl.data_rate_up_s, + info.dsl.line_attenuation_down, info.dsl.line_attenuation_up, + info.dsl.noise_margin_down, info.dsl.noise_margin_up + ); + + dsl_s.innerHTML = String.format('<small>%s</small>', s); + dsl_i.innerHTML = String.format( + '<img src="<%=resource%>/icons/ethernet.png" />' + + '<br /><small>ADSL</small>' + ); + <% end %> + + <% if has_dhcp then %> + var ls = document.getElementById('lease_status_table'); + if (ls) + { + /* clear all rows */ + while( ls.rows.length > 1 ) + ls.rows[0].parentNode.deleteRow(1); + + for( var i = 0; i < info.leases.length; i++ ) + { + var timestr; + + if (info.leases[i].expires <= 0) + timestr = '<em><%:expired%></em>'; + else + timestr = String.format('%t', info.leases[i].expires); + + var tr = ls.rows[0].parentNode.insertRow(-1); + tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1); + + tr.insertCell(-1).innerHTML = info.leases[i].hostname ? info.leases[i].hostname : '?'; + tr.insertCell(-1).innerHTML = info.leases[i].ipaddr; + tr.insertCell(-1).innerHTML = info.leases[i].macaddr; + tr.insertCell(-1).innerHTML = timestr; + } + + if( ls.rows.length == 1 ) + { + var tr = ls.rows[0].parentNode.insertRow(-1); + tr.className = 'cbi-section-table-row'; + + var td = tr.insertCell(-1); + td.colSpan = 4; + td.innerHTML = '<em><br /><%:There are no active leases.%></em>'; + } + } + + var ls6 = document.getElementById('lease6_status_table'); + if (ls6 && info.leases6) + { + ls6.parentNode.style.display = 'block'; + + /* clear all rows */ + while( ls6.rows.length > 1 ) + ls6.rows[0].parentNode.deleteRow(1); + + for( var i = 0; i < info.leases6.length; i++ ) + { + var timestr; + + if (info.leases6[i].expires <= 0) + timestr = '<em><%:expired%></em>'; + else + timestr = String.format('%t', info.leases6[i].expires); + + var tr = ls6.rows[0].parentNode.insertRow(-1); + tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1); + + tr.insertCell(-1).innerHTML = info.leases6[i].hostname ? info.leases6[i].hostname : '?'; + tr.insertCell(-1).innerHTML = info.leases6[i].ip6addr; + tr.insertCell(-1).innerHTML = info.leases6[i].duid; + tr.insertCell(-1).innerHTML = timestr; + } + + if( ls6.rows.length == 1 ) + { + var tr = ls6.rows[0].parentNode.insertRow(-1); + tr.className = 'cbi-section-table-row'; + + var td = tr.insertCell(-1); + td.colSpan = 4; + td.innerHTML = '<em><br /><%:There are no active leases.%></em>'; + } + } + <% end %> + + <% if has_wifi then %> + var assoclist = [ ]; + + var ws = document.getElementById('wifi_status_table'); + if (ws) + { + var wsbody = ws.rows[0].parentNode; + while (ws.rows.length > 0) + wsbody.deleteRow(0); + + for (var didx = 0; didx < info.wifinets.length; didx++) + { + var dev = info.wifinets[didx]; + + var tr = wsbody.insertRow(-1); + var td; + + td = tr.insertCell(-1); + td.width = "33%"; + td.innerHTML = dev.name; + td.style.verticalAlign = "top"; + + td = tr.insertCell(-1); + + var s = ''; + + for (var nidx = 0; nidx < dev.networks.length; nidx++) + { + var net = dev.networks[nidx]; + var is_assoc = (net.bssid != '00:00:00:00:00:00' && net.channel); + + var icon; + if (!is_assoc) + icon = "<%=resource%>/icons/signal-none.png"; + else if (net.quality == 0) + icon = "<%=resource%>/icons/signal-0.png"; + else if (net.quality < 25) + icon = "<%=resource%>/icons/signal-0-25.png"; + else if (net.quality < 50) + icon = "<%=resource%>/icons/signal-25-50.png"; + else if (net.quality < 75) + icon = "<%=resource%>/icons/signal-50-75.png"; + else + icon = "<%=resource%>/icons/signal-75-100.png"; + + s += String.format( + '<table><tr><td style="text-align:center; width:32px; padding:3px">' + + '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />' + + '<br /><small>%d%%</small>' + + '</td><td style="text-align:left; padding:3px"><small>' + + '<strong><%:SSID%>:</strong> <a href="%s">%h</a><br />' + + '<strong><%:Mode%>:</strong> %s<br />' + + '<strong><%:Channel%>:</strong> %d (%.3f <%:GHz%>)<br />' + + '<strong><%:Bitrate%>:</strong> %s <%:Mbit/s%><br />', + icon, net.signal, net.noise, + net.quality, + net.link, net.ssid, + net.mode, + net.channel, net.frequency, + net.bitrate || '?' + ); + + if (is_assoc) + { + s += String.format( + '<strong><%:BSSID%>:</strong> %s<br />' + + '<strong><%:Encryption%>:</strong> %s', + net.bssid, + net.encryption + ); + } + else + { + s += '<em><%:Wireless is disabled or not associated%></em>'; + } + + s += '</small></td></tr></table>'; + + for (var bssid in net.assoclist) + { + assoclist.push({ + bssid: bssid, + signal: net.assoclist[bssid].signal, + noise: net.assoclist[bssid].noise, + rx_rate: net.assoclist[bssid].rx_rate, + rx_mcs: net.assoclist[bssid].rx_mcs, + rx_40mhz: net.assoclist[bssid].rx_40mhz, + tx_rate: net.assoclist[bssid].tx_rate, + tx_mcs: net.assoclist[bssid].tx_mcs, + tx_40mhz: net.assoclist[bssid].tx_40mhz, + link: net.link, + name: net.name + }); + } + } + + if (!s) + s = '<em><%:No information available%></em>'; + + td.innerHTML = s; + } + } + + var ac = document.getElementById('wifi_assoc_table'); + if (ac) + { + /* clear all rows */ + while( ac.rows.length > 1 ) + ac.rows[0].parentNode.deleteRow(1); + + assoclist.sort(function(a, b) { + return (a.name == b.name) + ? (a.bssid < b.bssid) + : (a.name > b.name ) + ; + }); + + for( var i = 0; i < assoclist.length; i++ ) + { + var tr = ac.rows[0].parentNode.insertRow(-1); + tr.className = 'cbi-section-table-row cbi-rowstyle-' + (1 + (i % 2)); + + var icon; + var q = (-1 * (assoclist[i].noise - assoclist[i].signal)) / 5; + if (q < 1) + icon = "<%=resource%>/icons/signal-0.png"; + else if (q < 2) + icon = "<%=resource%>/icons/signal-0-25.png"; + else if (q < 3) + icon = "<%=resource%>/icons/signal-25-50.png"; + else if (q < 4) + icon = "<%=resource%>/icons/signal-50-75.png"; + else + icon = "<%=resource%>/icons/signal-75-100.png"; + + tr.insertCell(-1).innerHTML = String.format( + '<img src="%s" title="<%:Signal%>: %d <%:dBm%> / <%:Noise%>: %d <%:dBm%>" />', + icon, assoclist[i].signal, assoclist[i].noise + ); + + tr.insertCell(-1).innerHTML = assoclist[i].bssid; + + tr.insertCell(-1).innerHTML = String.format( + '<a href="%s">%s</a>', + assoclist[i].link, + '%h'.format(assoclist[i].name).nobr() + ); + + tr.insertCell(-1).innerHTML = String.format('%d <%:dBm%>', assoclist[i].signal).nobr(); + tr.insertCell(-1).innerHTML = String.format('%d <%:dBm%>', assoclist[i].noise).nobr(); + + tr.insertCell(-1).innerHTML = (assoclist[i].rx_mcs > -1) + ? String.format('%.1f <%:Mbit/s%>, MCS %d, %d<%:MHz%>', assoclist[i].rx_rate / 1000, assoclist[i].rx_mcs, assoclist[i].rx_40mhz ? 40 : 20).nobr() + : String.format('%.1f <%:Mbit/s%>', assoclist[i].rx_rate / 1000).nobr() + ; + + tr.insertCell(-1).innerHTML = (assoclist[i].tx_mcs > -1) + ? String.format('%.1f <%:Mbit/s%>, MCS %d, %d<%:MHz%>', assoclist[i].tx_rate / 1000, assoclist[i].tx_mcs, assoclist[i].tx_40mhz ? 40 : 20).nobr() + : String.format('%.1f <%:Mbit/s%>', assoclist[i].tx_rate / 1000).nobr() + ; + } + + if (ac.rows.length == 1) + { + var tr = ac.rows[0].parentNode.insertRow(-1); + tr.className = 'cbi-section-table-row'; + + var td = tr.insertCell(-1); + td.colSpan = 7; + td.innerHTML = '<br /><em><%:No information available%></em>'; + } + } + <% end %> + + var e; + + if (e = document.getElementById('localtime')) + e.innerHTML = info.localtime; + + if (e = document.getElementById('uptime')) + e.innerHTML = String.format('%t', info.uptime); + + if (e = document.getElementById('loadavg')) + e.innerHTML = String.format('%.02f, %.02f, %.02f', + info.loadavg[0], info.loadavg[1], info.loadavg[2]); + + if (e = document.getElementById('memtotal')) + e.innerHTML = progressbar( + (info.memfree + info.membuffers + info.memcached) + " <%:kB%>", + info.memtotal + " <%:kB%>" + ); + + if (e = document.getElementById('memfree')) + e.innerHTML = progressbar( + info.memfree + " <%:kB%>", info.memtotal + " <%:kB%>" + ); + + if (e = document.getElementById('memcache')) + e.innerHTML = progressbar( + info.memcached + " <%:kB%>", info.memtotal + " <%:kB%>" + ); + + if (e = document.getElementById('membuff')) + e.innerHTML = progressbar( + info.membuffers + " <%:kB%>", info.memtotal + " <%:kB%>" + ); + + if (e = document.getElementById('swapcache')) + e.innerHTML = progressbar( + info.swapcached + " <%:kB%>", info.swaptotal + " <%:kB%>" + ); + + if (e = document.getElementById('swaptotal')) + e.innerHTML = progressbar( + (info.swapfree + info.swapcached) + " <%:kB%>", + info.swaptotal + " <%:kB%>" + ); + + if (e = document.getElementById('swapfree')) + e.innerHTML = progressbar( + info.swapfree + " <%:kB%>", info.swaptotal + " <%:kB%>" + ); + + if (e = document.getElementById('conns')) + e.innerHTML = progressbar(info.conncount, info.connmax); + + } + ); +//]]></script> + +<h2><a id="content" name="content"><%:Status%></a></h2> + +<fieldset class="cbi-section"> + <legend><%:System%></legend> + + <table width="100%" cellspacing="10"> + <tr><td width="33%"><%:Hostname%></td><td><%=luci.sys.hostname() or "?"%></td></tr> + <tr><td width="33%"><%:Model%></td><td><%=pcdata(model or "?")%></td></tr> + <tr><td width="33%"><%:Firmware Version%></td><td> + <%=pcdata(luci.version.distname)%> <%=pcdata(luci.version.distversion)%> / + <%=pcdata(luci.version.luciname)%> (<%=pcdata(luci.version.luciversion)%>) + </td></tr> + <tr><td width="33%"><%:Kernel Version%></td><td><%=luci.sys.exec("uname -r")%></td></tr> + <tr><td width="33%"><%:Local Time%></td><td id="localtime">-</td></tr> + <tr><td width="33%"><%:Uptime%></td><td id="uptime">-</td></tr> + <tr><td width="33%"><%:Load Average%></td><td id="loadavg">-</td></tr> + </table> +</fieldset> + +<fieldset class="cbi-section"> + <legend><%:Memory%></legend> + + <table width="100%" cellspacing="10"> + <tr><td width="33%"><%:Total Available%></td><td id="memtotal">-</td></tr> + <tr><td width="33%"><%:Free%></td><td id="memfree">-</td></tr> + <tr><td width="33%"><%:Cached%></td><td id="memcache">-</td></tr> + <tr><td width="33%"><%:Buffered%></td><td id="membuff">-</td></tr> + </table> +</fieldset> + +<% if has_swap then %> +<fieldset class="cbi-section"> + <legend><%:Swap%></legend> + + <table width="100%" cellspacing="10"> + <tr><td width="33%"><%:Total Available%></td><td id="swaptotal">-</td></tr> + <tr><td width="33%"><%:Free%></td><td id="swapfree">-</td></tr> + <tr><td width="33%"><%:Cached%></td><td id="swapcache">-</td></tr> + </table> +</fieldset> +<% end %> + +<fieldset class="cbi-section"> + <legend><%:Network%></legend> + + <table width="100%" cellspacing="10"> + <tr><td width="33%" style="vertical-align:top"><%:IPv4 WAN Status%></td><td> + <table><tr> + <td id="wan4_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td> + <td id="wan4_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td> + </tr></table> + </td></tr> + <% if has_ipv6 then %> + <tr><td width="33%" style="vertical-align:top"><%:IPv6 WAN Status%></td><td> + <table><tr> + <td id="wan6_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td> + <td id="wan6_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td> + </tr></table> + </td></tr> + <% end %> + <tr><td width="33%"><%:Active Connections%></td><td id="conns">-</td></tr> + </table> +</fieldset> + +<% if has_dhcp then %> +<fieldset class="cbi-section"> + <legend><%:DHCP Leases%></legend> + + <table class="cbi-section-table" id="lease_status_table"> + <tr class="cbi-section-table-titles"> + <th class="cbi-section-table-cell"><%:Hostname%></th> + <th class="cbi-section-table-cell"><%:IPv4-Address%></th> + <th class="cbi-section-table-cell"><%:MAC-Address%></th> + <th class="cbi-section-table-cell"><%:Leasetime remaining%></th> + </tr> + <tr class="cbi-section-table-row"> + <td colspan="4"><em><br /><%:Collecting data...%></em></td> + </tr> + </table> +</fieldset> + +<fieldset class="cbi-section" style="display:none"> + <legend><%:DHCPv6 Leases%></legend> + + <table class="cbi-section-table" id="lease6_status_table"> + <tr class="cbi-section-table-titles"> + <th class="cbi-section-table-cell"><%:Hostname%></th> + <th class="cbi-section-table-cell"><%:IPv6-Address%></th> + <th class="cbi-section-table-cell"><%:DUID%></th> + <th class="cbi-section-table-cell"><%:Leasetime remaining%></th> + </tr> + <tr class="cbi-section-table-row"> + <td colspan="4"><em><br /><%:Collecting data...%></em></td> + </tr> + </table> +</fieldset> +<% end %> + +<% if has_dsl then %> +<fieldset class="cbi-section"> + <legend><%:ADSL%></legend> + <table width="100%" cellspacing="10"> + <tr><td width="33%" style="vertical-align:top"><%:ADSL Status%></td><td> + <table><tr> + <td id="dsl_i" style="width:16px; text-align:center; padding:3px"><img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small></td> + <td id="dsl_s" style="vertical-align:middle; padding: 3px"><em><%:Collecting data...%></em></td> + </tr></table> + </td></tr> + </table> +</fieldset> +<% end %> + +<% if has_wifi then %> +<fieldset class="cbi-section"> + <legend><%:Wireless%></legend> + + <table id="wifi_status_table" width="100%" cellspacing="10"> + <tr><td><em><%:Collecting data...%></em></td></tr> + </table> +</fieldset> + +<fieldset class="cbi-section"> + <legend><%:Associated Stations%></legend> + + <table class="cbi-section-table" id="wifi_assoc_table"> + <tr class="cbi-section-table-titles"> + <th class="cbi-section-table-cell"> </th> + <th class="cbi-section-table-cell"><%:MAC-Address%></th> + <th class="cbi-section-table-cell"><%:Network%></th> + <th class="cbi-section-table-cell"><%:Signal%></th> + <th class="cbi-section-table-cell"><%:Noise%></th> + <th class="cbi-section-table-cell"><%:RX Rate%></th> + <th class="cbi-section-table-cell"><%:TX Rate%></th> + </tr> + <tr class="cbi-section-table-row"> + <td colspan="7"><em><br /><%:Collecting data...%></em></td> + </tr> + </table> +</fieldset> +<% end %> + +<%- + require "luci.util" + require "nixio.fs" + + local plugins = nixio.fs.dir(luci.util.libpath() .. "/view/admin_status/index") + if plugins then + local inc + for inc in plugins do + if inc:match("%.htm$") then + include("admin_status/index/" .. inc:gsub("%.htm$", "")) + end + end + end +-%> + +<%+footer%> diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_status/iptables.htm b/modules/luci-mod-admin-full/luasrc/view/admin_status/iptables.htm new file mode 100644 index 0000000000..957604e8af --- /dev/null +++ b/modules/luci-mod-admin-full/luasrc/view/admin_status/iptables.htm @@ -0,0 +1,159 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2008-2009 Steven Barth <steven@midlink.org> +Copyright 2008-2011 Jo-Philipp Wich <xm@subsignal.org> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ + +-%> + +<%- + + require "luci.sys.iptparser" + require "luci.tools.webadmin" + require "luci.fs" + + local has_ip6tables = luci.fs.access("/usr/sbin/ip6tables") + local mode = 4 + + if has_ip6tables then + mode = luci.dispatcher.context.requestpath + mode = tonumber(mode[#mode] ~= "iptables" and mode[#mode]) or 4 + end + + local ipt = luci.sys.iptparser.IptParser(mode) + local wba = luci.tools.webadmin + + local rowcnt = 1 + function rowstyle() + rowcnt = rowcnt + 1 + return (rowcnt % 2) + 1 + end + + function link_target(t,c) + if ipt:is_custom_target(c) then + return '<a href="#rule_%s_%s">%s</a>' %{ t:lower(), c, c } + end + return c + end + + function link_iface(i) + local net = wba.iface_get_network(i) + if net and i ~= "lo" then + return '<a href="%s">%s</a>' %{ + luci.dispatcher.build_url("admin", "network", "network", net), i + } + + end + return i + end + + local tables = { "Filter", "NAT", "Mangle", "Raw" } + if mode == 6 then + tables = { "Filter", "Mangle", "Raw" } + end +-%> + +<%+header%> + +<style type="text/css"> + span:target { + color: blue; + text-decoration: underline; + } +</style> + +<h2><a id="content" name="content"><%:Firewall Status%></a></h2> + +<% if has_ip6tables then %> +<ul class="cbi-tabmenu"> + <li class="cbi-tab<%= mode ~= 4 and "-disabled" %>"><a href="<%=luci.dispatcher.build_url("admin/status/iptables/4")%>"><%:IPv4 Firewall%></a></li> + <li class="cbi-tab<%= mode ~= 6 and "-disabled" %>"><a href="<%=luci.dispatcher.build_url("admin/status/iptables/6")%>"><%:IPv6 Firewall%></a></li> +</ul> +<% end %> + +<form method="post" action="<%=REQUEST_URI%>"> + <div class="cbi-map"> + <fieldset class="cbi-section"> + <h3><%:Actions%></h3> + <ul> + <li><a href="<%=REQUEST_URI%>?zero=<%=mode%>"><%:Reset Counters%></a></li> + <li><a href="<%=REQUEST_URI%>?restart=1"><%:Restart Firewall%></a></li> + </ul> + <br /><br /> + + <% for _, tbl in ipairs(tables) do chaincnt = 0 %> + <h3><%:Table%>: <%=tbl%></h3> + <table class="cbi-section-table" style="font-size:90%"> + <% for _, chain in ipairs(ipt:chains(tbl)) do + rowcnt = 0 + chaincnt = chaincnt + 1 + chaininfo = ipt:chain(tbl, chain) + %> + <tr class="cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>"> + <th class="cbi-section-table-cell" style="text-align:left" colspan="11"> + <br /><span id="rule_<%=tbl:lower()%>_<%=chain%>"> + <%:Chain%> <em><%=chain%></em> + (<%- if chaininfo.policy then -%> + <%:Policy%>: <em><%=chaininfo.policy%></em>, <%:Packets%>: <%=chaininfo.packets%>, <%:Traffic%>: <%=wba.byte_format(chaininfo.bytes)-%> + <%- else -%> + <%:References%>: <%=chaininfo.references-%> + <%- end -%>)</span> + </th> + </tr> + <tr class="cbi-section-table-descr"> + <th class="cbi-section-table-cell"><%:Rule #%></th> + <th class="cbi-section-table-cell"><%:Pkts.%></th> + <th class="cbi-section-table-cell"><%:Traffic%></th> + <th class="cbi-section-table-cell"><%:Target%></th> + <th class="cbi-section-table-cell"><%:Prot.%></th> + <th class="cbi-section-table-cell"><%:Flags%></th> + <th class="cbi-section-table-cell"><%:In%></th> + <th class="cbi-section-table-cell"><%:Out%></th> + <th class="cbi-section-table-cell"><%:Source%></th> + <th class="cbi-section-table-cell"><%:Destination%></th> + <th class="cbi-section-table-cell" style="width:30%"><%:Options%></th> + </tr> + + <% for _, rule in ipairs(ipt:find({table=tbl, chain=chain})) do %> + <tr class="cbi-section-table-row cbi-rowstyle-<%=rowstyle()%>"> + <td><%=rule.index%></td> + <td><%=rule.packets%></td> + <td><%=wba.byte_format(rule.bytes)%></td> + <td><%=rule.target and link_target(tbl, rule.target) or "-"%></td> + <td><%=rule.protocol%></td> + <td><%=rule.flags%></td> + <td><%=link_iface(rule.inputif)%></td> + <td><%=link_iface(rule.outputif)%></td> + <td><%=rule.source%></td> + <td><%=rule.destination%></td> + <td style="width:30%"><small><%=#rule.options > 0 and luci.util.pcdata(table.concat(rule.options, " ")) or "-"%></small></td> + </tr> + <% end %> + + <% if rowcnt == 1 then %> + <tr class="cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>"> + <td colspan="11"><em><%:No rules in this chain%></em></td> + </tr> + <% end %> + <% end %> + + <% if chaincnt == 0 then %> + <tr class="cbi-section-table-titles cbi-rowstyle-<%=rowstyle()%>"> + <td colspan="11"><em><%:No chains in this table%></em></td> + </tr> + <% end %> + </table> + <br /><br /> + <% end %> + </fieldset> + </div> +</form> + +<%+footer%> diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_status/load.htm b/modules/luci-mod-admin-full/luasrc/view/admin_status/load.htm new file mode 100644 index 0000000000..a002715ec8 --- /dev/null +++ b/modules/luci-mod-admin-full/luasrc/view/admin_status/load.htm @@ -0,0 +1,291 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2010 Jo-Philipp Wich <xm@subsignal.org> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +-%> + +<%+header%> + +<script type="text/javascript" src="<%=resource%>/cbi.js"></script> +<script type="text/javascript">//<![CDATA[ + var bwxhr = new XHR(); + + var G; + var TIME = 0; + var L01 = 1; + var L05 = 2; + var L15 = 3; + + var width = 760; + var height = 300; + var step = 5; + + var data_wanted = Math.floor(width / step); + var data_fill = 0; + var data_stamp = 0; + + var data_01 = [ ]; + var data_05 = [ ]; + var data_15 = [ ]; + + var line_01; + var line_05; + var line_15; + + var label_25; + var label_050; + var label_75; + + var label_01_cur; + var label_01_avg; + var label_01_peak; + + var label_05_cur; + var label_05_avg; + var label_05_peak; + + var label_15_cur; + var label_15_avg; + var label_15_peak; + + var label_scale; + + + /* wait for SVG */ + window.setTimeout( + function() { + var svg = document.getElementById('bwsvg'); + + try { + G = svg.getSVGDocument + ? svg.getSVGDocument() : svg.contentDocument; + } + catch(e) { + G = document.embeds['bwsvg'].getSVGDocument(); + } + + if (!G) + { + window.setTimeout(arguments.callee, 1000); + } + else + { + /* find sizes */ + width = svg.offsetWidth - 2; + height = svg.offsetHeight - 2; + data_wanted = Math.ceil(width / step); + + /* prefill datasets */ + for (var i = 0; i < data_wanted; i++) + { + data_01[i] = 0; + data_05[i] = 0; + data_15[i] = 0; + } + + /* find svg elements */ + line_01 = G.getElementById('load01'); + line_05 = G.getElementById('load05'); + line_15 = G.getElementById('load15'); + + label_25 = G.getElementById('label_25'); + label_50 = G.getElementById('label_50'); + label_75 = G.getElementById('label_75'); + + label_01_cur = document.getElementById('lb_load01_cur'); + label_01_avg = document.getElementById('lb_load01_avg'); + label_01_peak = document.getElementById('lb_load01_peak'); + + label_05_cur = document.getElementById('lb_load05_cur'); + label_05_avg = document.getElementById('lb_load05_avg'); + label_05_peak = document.getElementById('lb_load05_peak'); + + label_15_cur = document.getElementById('lb_load15_cur'); + label_15_avg = document.getElementById('lb_load15_avg'); + label_15_peak = document.getElementById('lb_load15_peak'); + + label_scale = document.getElementById('scale'); + + + /* plot horizontal time interval lines */ + for (var i = width % (step * 60); i < width; i += step * 60) + { + var line = G.createElementNS('http://www.w3.org/2000/svg', 'line'); + line.setAttribute('x1', i); + line.setAttribute('y1', 0); + line.setAttribute('x2', i); + line.setAttribute('y2', '100%'); + line.setAttribute('style', 'stroke:black;stroke-width:0.1'); + + var text = G.createElementNS('http://www.w3.org/2000/svg', 'text'); + text.setAttribute('x', i + 5); + text.setAttribute('y', 15); + text.setAttribute('style', 'fill:#999999; font-size:9pt'); + text.appendChild(G.createTextNode(Math.round((width - i) / step / 60) + 'm')); + + label_25.parentNode.appendChild(line); + label_25.parentNode.appendChild(text); + } + + label_scale.innerHTML = String.format('<%:(%d minute window, %d second interval)%>', data_wanted / 60, 3); + + /* render datasets, start update interval */ + XHR.poll(3, '<%=build_url("admin/status/realtime/load_status")%>', null, + function(x, data) + { + var data_max = 0; + var data_scale = 0; + + var data_01_avg = 0; + var data_05_avg = 0; + var data_15_avg = 0; + + var data_01_peak = 0; + var data_05_peak = 0; + var data_15_peak = 0; + + for (var i = data_stamp ? 0 : 1; i < data.length; i++) + { + /* skip overlapping entries */ + if (data[i][TIME] <= data_stamp) + continue; + + data_01.push(data[i][L01]); + data_05.push(data[i][L05]); + data_15.push(data[i][L15]); + } + + /* cut off outdated entries */ + data_01 = data_01.slice(data_01.length - data_wanted, data_01.length); + data_05 = data_05.slice(data_05.length - data_wanted, data_05.length); + data_15 = data_15.slice(data_15.length - data_wanted, data_15.length); + + /* find peak */ + for (var i = 0; i < data_01.length; i++) + { + data_max = Math.max(data_max, data_01[i]); + data_max = Math.max(data_max, data_05[i]); + data_max = Math.max(data_max, data_15[i]); + + data_01_peak = Math.max(data_01_peak, data_01[i]); + data_05_peak = Math.max(data_05_peak, data_05[i]); + data_15_peak = Math.max(data_15_peak, data_15[i]); + + if (i > 0) + { + data_01_avg = (data_01_avg + data_01[i]) / 2; + data_05_avg = (data_05_avg + data_05[i]) / 2; + data_15_avg = (data_15_avg + data_15[i]) / 2; + } + else + { + data_01_avg = data_01[i]; + data_05_avg = data_05[i]; + data_15_avg = data_15[i]; + } + } + + /* remember current timestamp, calculate horizontal scale */ + data_stamp = data[data.length-1][TIME]; + data_scale = height / (data_max * 1.1); + + + /* plot data */ + var pt_01 = '0,' + height; + var pt_05 = '0,' + height; + var pt_15 = '0,' + height; + + var y_01 = 0; + var y_05 = 0; + var y_15 = 0; + + for (var i = 0; i < data_01.length; i++) + { + var x = i * step; + + y_01 = height - Math.floor(data_01[i] * data_scale); + y_05 = height - Math.floor(data_05[i] * data_scale); + y_15 = height - Math.floor(data_15[i] * data_scale); + + pt_01 += ' ' + x + ',' + y_01; + pt_05 += ' ' + x + ',' + y_05; + pt_15 += ' ' + x + ',' + y_15; + } + + pt_01 += ' ' + width + ',' + y_01 + ' ' + width + ',' + height; + pt_05 += ' ' + width + ',' + y_05 + ' ' + width + ',' + height; + pt_15 += ' ' + width + ',' + y_15 + ' ' + width + ',' + height; + + + line_01.setAttribute('points', pt_01); + line_05.setAttribute('points', pt_05); + line_15.setAttribute('points', pt_15); + + label_25.firstChild.data = (1.1 * 0.25 * data_max / 100).toFixed(2); + label_50.firstChild.data = (1.1 * 0.50 * data_max / 100).toFixed(2); + label_75.firstChild.data = (1.1 * 0.75 * data_max / 100).toFixed(2); + + label_01_cur.innerHTML = (data_01[data_01.length-1] / 100).toFixed(2); + label_05_cur.innerHTML = (data_05[data_05.length-1] / 100).toFixed(2); + label_15_cur.innerHTML = (data_15[data_15.length-1] / 100).toFixed(2); + + label_01_avg.innerHTML = (data_01_avg / 100).toFixed(2); + label_05_avg.innerHTML = (data_05_avg / 100).toFixed(2); + label_15_avg.innerHTML = (data_15_avg / 100).toFixed(2); + + label_01_peak.innerHTML = (data_01_peak / 100).toFixed(2); + label_05_peak.innerHTML = (data_05_peak / 100).toFixed(2); + label_15_peak.innerHTML = (data_15_peak / 100).toFixed(2); + } + ); + } + }, 1000 + ); +//]]></script> + +<h2><a id="content" name="content"><%:Realtime Load%></a></h2> + +<embed id="bwsvg" style="width:100%; height:300px; border:1px solid #000000; background-color:#FFFFFF" src="<%=resource%>/load.svg" /> +<div style="text-align:right"><small id="scale">-</small></div> +<br /> + +<table style="width:100%; table-layout:fixed" cellspacing="5"> + <tr> + <td style="text-align:right; vertical-align:top"><strong style="border-bottom:2px solid #ff0000; white-space:nowrap"><%:1 Minute Load:%></strong></td> + <td id="lb_load01_cur">0</td> + + <td style="text-align:right; vertical-align:top"><strong><%:Average:%></strong></td> + <td id="lb_load01_avg">0</td> + + <td style="text-align:right; vertical-align:top"><strong><%:Peak:%></strong></td> + <td id="lb_load01_peak">0</td> + </tr> + <tr> + <td style="text-align:right; vertical-align:top"><strong style="border-bottom:2px solid #ff6600; white-space:nowrap"><%:5 Minute Load:%></strong></td> + <td id="lb_load05_cur">0</td> + + <td style="text-align:right; vertical-align:top"><strong><%:Average:%></strong></td> + <td id="lb_load05_avg">0</td> + + <td style="text-align:right; vertical-align:top"><strong><%:Peak:%></strong></td> + <td id="lb_load05_peak">0</td> + </tr> + <tr> + <td style="text-align:right; vertical-align:top"><strong style="border-bottom:2px solid #ffaa00; white-space:nowrap"><%:15 Minute Load:%></strong></td> + <td id="lb_load15_cur">0</td> + + <td style="text-align:right; vertical-align:top"><strong><%:Average:%></strong></td> + <td id="lb_load15_avg">0</td> + + <td style="text-align:right; vertical-align:top"><strong><%:Peak:%></strong></td> + <td id="lb_load15_peak">0</td> + </tr> +</table> + +<%+footer%> diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_status/routes.htm b/modules/luci-mod-admin-full/luasrc/view/admin_status/routes.htm new file mode 100644 index 0000000000..4e7287b705 --- /dev/null +++ b/modules/luci-mod-admin-full/luasrc/view/admin_status/routes.htm @@ -0,0 +1,107 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2008-2009 Steven Barth <steven@midlink.org> +Copyright 2008-2009 Jo-Philipp Wich <xm@subsignal.org> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ + +-%> + +<%- + require "bit" + require "luci.sys" + require "luci.tools.webadmin" + require "nixio.fs" + + local style = true +-%> + +<%+header%> + +<div class="cbi-map" id="cbi-network"> + <h2><a id="content" name="content"><%:Routes%></a></h2> + <div class="cbi-map-descr"><%:The following rules are currently active on this system.%></div> + + <fieldset class="cbi-section" id="cbi-table-table"> + <legend>ARP</legend> + <div class="cbi-section-node"> + <table class="cbi-section-table"> + <tr class="cbi-section-table-titles"> + <th class="cbi-section-table-cell"><%_<abbr title="Internet Protocol Version 4">IPv4</abbr>-Address%></th> + <th class="cbi-section-table-cell"><%_<abbr title="Media Access Control">MAC</abbr>-Address%></th> + <th class="cbi-section-table-cell"><%:Interface%></th> + </tr> + + <% luci.sys.net.arptable(function(e) %> + <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>"> + <td class="cbi-value-field"><%=e["IP address"]%></td> + <td class="cbi-value-field"><%=e["HW address"]%></td> + <td class="cbi-value-field"><%=e["Device"]%></td> + </tr> + <% style = not style; end) %> + </table> + </div> + </fieldset> + <br /> + + <fieldset class="cbi-section" id="cbi-table-table"> + <legend><%_Active <abbr title="Internet Protocol Version 4">IPv4</abbr>-Routes%></legend> + + <div class="cbi-section-node"> + <table class="cbi-section-table"> + <tr class="cbi-section-table-titles"> + <th class="cbi-section-table-cell"><%:Network%></th> + <th class="cbi-section-table-cell"><%:Target%></th> + <th class="cbi-section-table-cell"><%_<abbr title="Internet Protocol Version 4">IPv4</abbr>-Gateway%></th> + <th class="cbi-section-table-cell"><%:Metric%></th> + </tr> + <% luci.sys.net.routes(function(rt) %> + <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>"> + <td class="cbi-value-field"><%=luci.tools.webadmin.iface_get_network(rt.device) or rt.device%></td> + <td class="cbi-value-field"><%=rt.dest:string()%></td> + <td class="cbi-value-field"><%=rt.gateway:string()%></td> + <td class="cbi-value-field"><%=rt.metric%></td> + </tr> + <% style = not style; end) %> + </table> + </div> + </fieldset> + <br /> + + <% if nixio.fs.access("/proc/net/ipv6_route") then + style = true + fe80 = luci.ip.IPv6("fe80::/10") + %> + <fieldset class="cbi-section" id="cbi-table-table"> + <legend><%_Active <abbr title="Internet Protocol Version 6">IPv6</abbr>-Routes%></legend> + + <div class="cbi-section-node"> + <table class="cbi-section-table"> + <tr class="cbi-section-table-titles"> + <th class="cbi-section-table-cell"><%:Network%></th> + <th class="cbi-section-table-cell"><%:Target%></th> + <th class="cbi-section-table-cell"><%_<abbr title="Internet Protocol Version 6">IPv6</abbr>-Gateway%></th> + <th class="cbi-section-table-cell"><%:Metric%></th> + </tr> + <% luci.sys.net.routes6(function(rt) if fe80:contains(rt.dest) then return end %> + <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>"> + <td class="cbi-value-field"><%=luci.tools.webadmin.iface_get_network(rt.device) or '(' .. rt.device .. ')'%></td> + <td class="cbi-value-field"><%=rt.dest:string()%></td> + <td class="cbi-value-field"><%=rt.source:string()%></td> + <td class="cbi-value-field"><%=rt.metric_raw:upper()%></td> + </tr> + <% style = not style; end) %> + </table> + </div> + </fieldset> + <br /> + <% end %> +</div> + +<%+footer%> diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_status/syslog.htm b/modules/luci-mod-admin-full/luasrc/view/admin_status/syslog.htm new file mode 100644 index 0000000000..06aeeb01a6 --- /dev/null +++ b/modules/luci-mod-admin-full/luasrc/view/admin_status/syslog.htm @@ -0,0 +1,20 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2008 Steven Barth <steven@midlink.org> +Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ + +-%> +<%+header%> +<h2><a id="content" name="content"><%:System Log%></a></h2> +<div id="content_syslog"> +<textarea readonly="readonly" wrap="off" rows="<%=syslog:cmatch("\n")+2%>" id="syslog"><%=syslog:pcdata()%></textarea> +</div> +<%+footer%> diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_status/wireless.htm b/modules/luci-mod-admin-full/luasrc/view/admin_status/wireless.htm new file mode 100644 index 0000000000..465143ebce --- /dev/null +++ b/modules/luci-mod-admin-full/luasrc/view/admin_status/wireless.htm @@ -0,0 +1,378 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2011 Jo-Philipp Wich <xm@subsignal.org> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +-%> + +<%- + local ntm = require "luci.model.network".init() + + local dev + local devices = { } + for _, dev in luci.util.vspairs(luci.sys.net.devices()) do + if dev:match("^wlan%d") or dev:match("^ath%d") or dev:match("^wl%d") then + devices[#devices+1] = dev + end + end + + local curdev = luci.dispatcher.context.requestpath + curdev = curdev[#curdev] ~= "wireless" and curdev[#curdev] or devices[1] +-%> + +<%+header%> + +<script type="text/javascript" src="<%=resource%>/cbi.js"></script> +<script type="text/javascript">//<![CDATA[ + var bwxhr = new XHR(); + + var G, G2; + var TIME = 0; + var RATE = 1; + var RSSI = 2; + var NOISE = 3; + + var width = 760; + var height = 300; + var step = 5; + + var data_wanted = Math.floor(width / step); + var data_fill = 0; + var data_stamp = 0; + + var data_rssi = [ ]; + var data_noise = [ ]; + var data_rate = [ ]; + + var line_rssi; + var line_noise; + var line_rate; + + var label_25, label_25_2; + var label_50, label_50_2; + var label_75, label_75_2; + + var label_rssi_cur; + var label_rssi_avg; + var label_rssi_peak; + + var label_noise_cur; + var label_noise_avg; + var label_noise_peak; + + var label_rate_cur; + var label_rate_avg; + var label_rate_peak; + + var label_scale; + + + /* wait for SVG */ + window.setTimeout( + function() { + var svg = document.getElementById('iwsvg'); + var svg2 = document.getElementById('iwsvg2'); + + try { + G = svg.getSVGDocument + ? svg.getSVGDocument() : svg.contentDocument; + G2 = svg2.getSVGDocument + ? svg2.getSVGDocument() : svg2.contentDocument; + } + catch(e) { + G = document.embeds['iwsvg'].getSVGDocument(); + G2 = document.embeds['iwsvg2'].getSVGDocument(); + } + + if (!G || !G2) + { + window.setTimeout(arguments.callee, 1000); + } + else + { + /* find sizes */ + width = svg.offsetWidth - 2; + height = svg.offsetHeight - 2; + data_wanted = Math.ceil(width / step); + + /* prefill datasets */ + for (var i = 0; i < data_wanted; i++) + { + data_rssi[i] = 0; + data_noise[i] = 0; + data_rate[i] = 0; + } + + /* find svg elements */ + line_rssi = G.getElementById('rssi'); + line_noise = G.getElementById('noise'); + line_rate = G2.getElementById('rate'); + + label_25 = G.getElementById('label_25'); + label_50 = G.getElementById('label_50'); + label_75 = G.getElementById('label_75'); + label_25_2 = G2.getElementById('label_25'); + label_50_2 = G2.getElementById('label_50'); + label_75_2 = G2.getElementById('label_75'); + + label_rssi_cur = document.getElementById('rssi_bw_cur'); + label_rssi_avg = document.getElementById('rssi_bw_avg'); + label_rssi_peak = document.getElementById('rssi_bw_peak'); + + label_noise_cur = document.getElementById('noise_bw_cur'); + label_noise_avg = document.getElementById('noise_bw_avg'); + label_noise_peak = document.getElementById('noise_bw_peak'); + + label_rate_cur = document.getElementById('rate_bw_cur'); + label_rate_avg = document.getElementById('rate_bw_avg'); + label_rate_peak = document.getElementById('rate_bw_peak'); + + label_scale = document.getElementById('scale'); + label_scale_2 = document.getElementById('scale2'); + + + /* plot horizontal time interval lines */ + for (var i = width % (step * 60); i < width; i += step * 60) + { + var line = G.createElementNS('http://www.w3.org/2000/svg', 'line'); + line.setAttribute('x1', i); + line.setAttribute('y1', 0); + line.setAttribute('x2', i); + line.setAttribute('y2', '100%'); + line.setAttribute('style', 'stroke:black;stroke-width:0.1'); + + var text = G.createElementNS('http://www.w3.org/2000/svg', 'text'); + text.setAttribute('x', i + 5); + text.setAttribute('y', 15); + text.setAttribute('style', 'fill:#999999; font-size:9pt'); + text.appendChild(G.createTextNode(Math.round((width - i) / step / 60) + 'm')); + + label_25.parentNode.appendChild(line); + label_25.parentNode.appendChild(text); + + + var line2 = G2.createElementNS('http://www.w3.org/2000/svg', 'line'); + line2.setAttribute('x1', i); + line2.setAttribute('y1', 0); + line2.setAttribute('x2', i); + line2.setAttribute('y2', '100%'); + line2.setAttribute('style', 'stroke:black;stroke-width:0.1'); + + var text2 = G2.createElementNS('http://www.w3.org/2000/svg', 'text'); + text2.setAttribute('x', i + 5); + text2.setAttribute('y', 15); + text2.setAttribute('style', 'fill:#999999; font-size:9pt'); + text2.appendChild(G.createTextNode(Math.round((width - i) / step / 60) + 'm')); + + label_25_2.parentNode.appendChild(line2); + label_25_2.parentNode.appendChild(text2); + } + + label_scale.innerHTML = String.format('<%:(%d minute window, %d second interval)%>', data_wanted / 60, 3); + label_scale_2.innerHTML = String.format('<%:(%d minute window, %d second interval)%>', data_wanted / 60, 3); + + /* render datasets, start update interval */ + XHR.poll(3, '<%=build_url("admin/status/realtime/wireless_status", curdev)%>', null, + function(x, data) + { + var noise_floor = 255; + var rate_floor = 60000; + + for (var i = 0; i < data.length; i++) { + noise_floor = Math.min(noise_floor, data[i][NOISE]); + rate_floor = Math.min(rate_floor, data[i][RATE]); + } + + noise_floor -= 5; + + var data_max = 0; + var data_scale = 0; + var data_max_2 = 0; + var data_scale_2 = 0; + + var data_rssi_avg = 0; + var data_noise_avg = 0; + var data_rate_avg = 0; + + var data_rssi_peak = 0; + var data_noise_peak = 0; + var data_rate_peak = 0; + + for (var i = data_stamp ? 0 : 1; i < data.length; i++) + { + /* skip overlapping entries */ + if (data[i][TIME] <= data_stamp) + continue; + + data_rssi.push(data[i][RSSI] - noise_floor); + data_noise.push(data[i][NOISE] - noise_floor); + data_rate.push(Math.floor(data[i][RATE] / 1000)); + } + + /* cut off outdated entries */ + data_rssi = data_rssi.slice(data_rssi.length - data_wanted, data_rssi.length); + data_noise = data_noise.slice(data_noise.length - data_wanted, data_noise.length); + data_rate = data_rate.slice(data_rate.length - data_wanted, data_rate.length); + + /* find peak */ + for (var i = 0; i < data_rssi.length; i++) + { + data_max = Math.max(data_max, data_rssi[i]); + data_max_2 = Math.max(data_max_2, data_rate[i]); + + data_rssi_peak = Math.max(data_rssi_peak, data_rssi[i]); + data_noise_peak = Math.max(data_noise_peak, data_noise[i]); + data_rate_peak = Math.max(data_rate_peak, data_rate[i]); + + if (i > 0) + { + data_rssi_avg = (data_rssi_avg + data_rssi[i]) / 2; + data_noise_avg = (data_noise_avg + data_noise[i]) / 2; + data_rate_avg = (data_rate_avg + data_rate[i]) / 2; + } + else + { + data_rssi_avg = data_rssi[i]; + data_noise_avg = data_noise[i]; + data_rate_avg = data_rate[i]; + } + } + + /* remember current timestamp, calculate horizontal scale */ + data_stamp = data[data.length-1][TIME]; + data_scale = (height / (data_max * 1.1)).toFixed(1); + data_scale_2 = (height / (data_max_2 * 1.1)).toFixed(1); + + /* plot data */ + var pt_rssi = '0,' + height; + var pt_noise = '0,' + height; + var pt_rate = '0,' + height; + + var y_rssi = 0; + var y_noise = 0; + var y_rate = 0; + + for (var i = 0; i < data_rssi.length; i++) + { + var x = i * step; + + y_rssi = height - Math.floor(data_rssi[i] * data_scale); + y_noise = height - Math.floor(data_noise[i] * data_scale); + y_rate = height - Math.floor(data_rate[i] * data_scale_2); + + y_rssi -= Math.floor(y_rssi % (1/data_scale)); + y_noise -= Math.floor(y_noise % (1/data_scale)); + + pt_rssi += ' ' + x + ',' + y_rssi; + pt_noise += ' ' + x + ',' + y_noise; + pt_rate += ' ' + x + ',' + y_rate; + } + + pt_rssi += ' ' + width + ',' + y_rssi + ' ' + width + ',' + height; + pt_noise += ' ' + width + ',' + y_noise + ' ' + width + ',' + height; + pt_rate += ' ' + width + ',' + y_rate + ' ' + width + ',' + height; + + line_rssi.setAttribute('points', pt_rssi); + line_noise.setAttribute('points', pt_noise); + line_rate.setAttribute('points', pt_rate); + + function wireless_label(dbm, noise) + { + if (noise) + return String.format("%d <%:dBm%> (SNR %d <%:dBm%>)", noise_floor + dbm - 255, dbm - noise); + else + return String.format("%d <%:dBm%>", noise_floor + dbm - 255); + } + + function rate_label(mbit) + { + return String.format("%d <%:Mbit/s%>", mbit); + } + + label_25.firstChild.data = wireless_label(1.1 * 0.25 * data_max); + label_50.firstChild.data = wireless_label(1.1 * 0.50 * data_max); + label_75.firstChild.data = wireless_label(1.1 * 0.75 * data_max); + + label_25_2.firstChild.data = rate_label(1.1 * 0.25 * data_max_2); + label_50_2.firstChild.data = rate_label(1.1 * 0.50 * data_max_2); + label_75_2.firstChild.data = rate_label(1.1 * 0.75 * data_max_2); + + label_rssi_cur.innerHTML = wireless_label(data_rssi[data_rssi.length-1], data_noise[data_noise.length-1]).nobr(); + label_noise_cur.innerHTML = wireless_label(data_noise[data_noise.length-1]).nobr(); + + label_rssi_avg.innerHTML = wireless_label(data_rssi_avg, data_noise_avg).nobr(); + label_noise_avg.innerHTML = wireless_label(data_noise_avg).nobr(); + + label_rssi_peak.innerHTML = wireless_label(data_rssi_peak, data_noise_peak).nobr(); + label_noise_peak.innerHTML = wireless_label(data_noise_peak).nobr(); + + label_rate_cur.innerHTML = rate_label(data_rate[data_rate.length-1]); + label_rate_avg.innerHTML = rate_label(data_rate_avg); + label_rate_peak.innerHTML = rate_label(data_rate_peak); + } + ); + } + }, 1000 + ); +//]]></script> + +<h2><a id="content" name="content"><%:Realtime Wireless%></a></h2> + +<ul class="cbi-tabmenu"> + <% for _, dev in ipairs(devices) do %> + <li class="cbi-tab<%= dev == curdev and "" or "-disabled" %>"><a href="<%=pcdata(dev)%>"><%=pcdata(dev)%></a></li> + <% end %> +</ul> + +<embed id="iwsvg" style="width:100%; height:300px; border:1px solid #000000; background-color:#FFFFFF" src="<%=resource%>/wireless.svg" /> +<div style="text-align:right"><small id="scale">-</small></div> +<br /> + +<table style="width:100%; table-layout:fixed" cellspacing="5"> + <tr> + <td style="text-align:right; vertical-align:top"><strong style="border-bottom:2px solid blue"><%:Signal:%></strong></td> + <td id="rssi_bw_cur">0 <%:dBm%></td> + + <td style="text-align:right; vertical-align:top"><strong><%:Average:%></strong></td> + <td id="rssi_bw_avg">0 <%:dBm%></td> + + <td style="text-align:right; vertical-align:top"><strong><%:Peak:%></strong></td> + <td id="rssi_bw_peak">0 <%:dBm%></td> + </tr> + <tr> + <td style="text-align:right; vertical-align:top"><strong style="border-bottom:2px solid red"><%:Noise:%></strong></td> + <td id="noise_bw_cur">0 <%:dBm%></td> + + <td style="text-align:right; vertical-align:top"><strong><%:Average:%></strong></td> + <td id="noise_bw_avg">0 <%:dBm%></td> + + <td style="text-align:right; vertical-align:top"><strong><%:Peak:%></strong></td> + <td id="noise_bw_peak">0 <%:dBm%></td> + </tr> +</table> + +<br /> + +<embed id="iwsvg2" style="width:100%; height:300px; border:1px solid #000000; background-color:#FFFFFF" src="<%=resource%>/wifirate.svg" /> +<div style="text-align:right"><small id="scale2">-</small></div> +<br /> + +<table style="width:100%; table-layout:fixed" cellspacing="5"> + <tr> + <td style="text-align:right; vertical-align:top"><strong style="border-bottom:2px solid green"><%:Phy Rate:%></strong></td> + <td id="rate_bw_cur">0 MBit/s</td> + + <td style="text-align:right; vertical-align:top"><strong><%:Average:%></strong></td> + <td id="rate_bw_avg">0 MBit/s</td> + + <td style="text-align:right; vertical-align:top"><strong><%:Peak:%></strong></td> + <td id="rate_bw_peak">0 MBit/s</td> + </tr> +</table> + +<%+footer%> |