diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2010-10-25 22:26:08 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2010-10-25 22:26:08 +0000 |
commit | f6b77ef7f09fcce65f716abe683c27a9c0a11160 (patch) | |
tree | 8884be8bd669b6b26ef85b49eb0fccd9b497b75d /modules/admin-full/luasrc/view | |
parent | cd63354f7e0eb7bac4416cbb90ae70f43b4c4194 (diff) |
modules/admin-full: add realtime iface status to config page
Diffstat (limited to 'modules/admin-full/luasrc/view')
-rw-r--r-- | modules/admin-full/luasrc/view/admin_network/iface_status.htm | 95 | ||||
-rw-r--r-- | modules/admin-full/luasrc/view/admin_network/wifi_status.htm | 6 |
2 files changed, 99 insertions, 2 deletions
diff --git a/modules/admin-full/luasrc/view/admin_network/iface_status.htm b/modules/admin-full/luasrc/view/admin_network/iface_status.htm new file mode 100644 index 000000000..4deebeec1 --- /dev/null +++ b/modules/admin-full/luasrc/view/admin_network/iface_status.htm @@ -0,0 +1,95 @@ +<%+cbi/valueheader%> + +<script type="text/javascript"><![CDATA[ + var iwxhr = new XHR(); + (function() { + iwxhr.get('<%=luci.dispatcher.build_url("admin", "network", "iface_status", self.network)%>', null, + function(x) + { + var ifc = x.responseText ? eval('(' + x.responseText + ')') : { }; + if (ifc) + { + var is_up = (ifc.flags && ifc.flags.up); + var rxb = ifc.stats ? (ifc.stats["rx_bytes"] / 1024) : 0; + var txb = ifc.stats ? (ifc.stats["tx_bytes"] / 1024) : 0; + var rxp = ifc.stats ? ifc.stats["rx_packets"] : 0; + var txp = ifc.stats ? ifc.stats["tx_packets"] : 0; + var mac = ifc.macaddr ? ifc.macaddr : '00:00:00:00:00:00'; + + var icon; + if (is_up) + icon = "<%=resource%>/icons/ethernet.png"; + else + icon = "<%=resource%>/icons/ethernet_disabled.png"; + + var s = document.getElementById('<%=self.option%>-ifc-signal'); + if (s) + s.innerHTML = String.format( + '<img src="%s" style="width:16px; height:16px" /><br />' + + '<small>%s</small>', icon, ifc.ifname ? ifc.ifname : '?' + ); + + var d = document.getElementById('<%=self.option%>-ifc-description'); + if (d && ifc.ifname) + { + d.innerHTML = String.format( + '<strong><%:MAC Address%>:</strong> %s<br />' + + '<strong><%:RX%></strong>: %.2f <%:KB%> (%d <%:Pkts.%>)<br />' + + '<strong><%:TX%></strong>: %.2f <%:KB%> (%d <%:Pkts.%>)<br />', + mac, rxb, rxp, txb, txp + ); + + if (ifc.ipaddrs && ifc.ipaddrs.length) + { + d.innerHTML += '<strong><%:IPv4%>: </strong>'; + + for (var i = 0; i < ifc.ipaddrs.length; i++) + d.innerHTML += String.format( + '%s%s/%d', + i ? ', ' : '', + ifc.ipaddrs[i].addr, + ifc.ipaddrs[i].prefix + ); + + d.innerHTML += '<br />'; + } + + if (ifc.ip6addrs && ifc.ip6addrs.length) + { + d.innerHTML += '<strong><%:IPv6%>: </strong>'; + + for (var i = 0; i < ifc.ip6addrs.length; i++) + d.innerHTML += String.format( + '%s%s/%d', + i ? ', ' : '', + ifc.ip6addrs[i].addr, + ifc.ip6addrs[i].prefix + ); + + d.innerHTML += '<br />'; + } + } + else if (d) + d.innerHTML = '<%:Interface not present or not connected yet.%>'; + } + } + ) + + window.setTimeout(arguments.callee, 5000); + })(); +]]></script> + +<table> + <tr class="cbi-section-table"> + <td></td> + <td class="cbi-value-field" style="width:16px; padding:3px; text-align:center" id="<%=self.option%>-ifc-signal"> + <img src="<%=resource%>/icons/ethernet_disabled.png" style="width:16px; height:16px" /><br /> + <small>?</small> + </td> + <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px" id="<%=self.option%>-ifc-description"> + <em><%:Collecting data...%></em> + </td> + </tr> +</table> + +<%+cbi/valuefooter%> diff --git a/modules/admin-full/luasrc/view/admin_network/wifi_status.htm b/modules/admin-full/luasrc/view/admin_network/wifi_status.htm index 044549d52..fee8db498 100644 --- a/modules/admin-full/luasrc/view/admin_network/wifi_status.htm +++ b/modules/admin-full/luasrc/view/admin_network/wifi_status.htm @@ -2,7 +2,7 @@ <script type="text/javascript"><![CDATA[ var iwxhr = new XHR(); - window.setInterval(function() { + (function() { iwxhr.get('<%=luci.dispatcher.build_url("admin", "network", "wireless_status", self.ifname)%>', null, function(x) { @@ -58,7 +58,9 @@ } } ) - }, 5000); + + window.setTimeout(arguments.callee, 5000); + })(); ]]></script> <table> |