modules/admin-full: fix status reporting of inactive virtual interfaces
[project/luci.git] / modules / admin-full / luasrc / view / admin_network / iface_status.htm
index c554df8..428c42f 100644 (file)
 <%+cbi/valueheader%>
 
 <script type="text/javascript">//<![CDATA[
-       var iwxhr = new XHR();
-
-       function iface_shutdown(id, reconnect) {
-               if (!reconnect && !confirm(String.format('<%_Really shutdown network ?\nYou might loose access to this router if you are connected via this interface.%>', id)))
-                       return;
-
-               var a = document.getElementById(id + '-ifc-addrs');
-               if (a)
-               {
-                       a.innerHTML = reconnect
-                               ? '<em><%:Interface is reconnecting...%></em>'
-                               : '<em><%:Interface is shutting down...%></em>';
-               }
-
-               var s = document.getElementById('ifc-rc-status');
-               if (s)
+       XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "network", "iface_status", self.network)%>', null,
+               function(x, ifc)
                {
-                       s.parentNode.style.display = 'block';
-                       s.innerHTML = '<%:Waiting for router...%>';
-               }
-
-               var rcxhr = new XHR();
-               rcxhr.get('<%=luci.dispatcher.build_url("admin", "network")%>/iface_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null,
-                       function(x)
+                       if (ifc && (ifc = ifc[0]))
                        {
-                               if (s)
-                               {
-                                       s.innerHTML = reconnect
-                                               ? '<%:Interface reconnected%>'
-                                               : '<%:Interface shut down%>';
+                               var html = '';
 
-                                       window.setTimeout(function() {
-                                               s.parentNode.style.display = 'none';
-                                       }, 1000);
-                               }
-                       }
-               );
-       }
-
-
-       (function() {
-               var func = arguments.callee;
-
-               iwxhr.get('<%=luci.dispatcher.build_url("admin", "network", "iface_status", self.network)%>', null,
-                       function(x, ifc)
-                       {
-                               if (ifc && (ifc = ifc[0]))
+                               var s = document.getElementById('<%=self.option%>-ifc-signal');
+                               if (s)
+                                       s.innerHTML = String.format(
+                                               '<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px" />' +
+                                               '<br /><small>%s</small>',
+                                                       ifc.type, ifc.is_up ? '' : '_disabled',
+                                                       ifc.name
+                                       );
+
+                               var d = document.getElementById('<%=self.option%>-ifc-description');
+                               if (d && ifc.ifname)
                                {
-                                       var rxb = ifc.rx_bytes || 0;
-                                       var txb = ifc.tx_bytes || 0;
-                                       var rxp = ifc.rx_packets || 0;
-                                       var txp = ifc.tx_packets || 0;
-                                       var mac = ifc.macaddr;
-
-                                       var html = '';
-                                       var upt, icon;
-
                                        if (ifc.is_up)
                                        {
-                                               if (ifc.uptime)
-                                                       upt = String.format('%t', ifc.uptime);
-
-                                               icon = "<%=resource%>/icons/%s.png";
+                                               html += String.format('<strong><%:Uptime%>:</strong> %t<br />', ifc.uptime);
                                        }
-                                       else
+
+                                       if (ifc.type != 'tunnel')
                                        {
-                                               icon = "<%=resource%>/icons/%s_disabled.png";
+                                               html += String.format('<strong><%:MAC Address%>:</strong> %s<br />', ifc.macaddr);
                                        }
 
-                                       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>',
-                                                               String.format(icon, ifc.type),
-                                                               ifc.ifname ? ifc.ifname : '?'
-                                               );
+                                       html += String.format(
+                                               '<strong><%:RX%></strong>: %.2mB (%d <%:Pkts.%>)<br />' +
+                                               '<strong><%:TX%></strong>: %.2mB (%d <%:Pkts.%>)<br />',
+                                                       ifc.rx_bytes, ifc.rx_packets,
+                                                       ifc.tx_bytes, ifc.tx_packets
+                                       );
 
-                                       var d = document.getElementById('<%=self.option%>-ifc-description');
-                                       if (d && ifc.ifname && mac != '00:00:00:00:00:00')
+                                       if (ifc.ipaddrs && ifc.ipaddrs.length)
                                        {
-                                               if (upt)
-                                               {
-                                                       html += String.format('<strong><%:Uptime%>:</strong> %s<br />', upt);
-                                               }
-
-                                               if (ifc.type != 'tunnel')
-                                               {
-                                                       html += String.format('<strong><%:MAC Address%>:</strong> %s<br />', mac);
-                                               }
+                                               html += '<strong><%:IPv4%>: </strong>';
 
-                                               html += String.format(
-                                                       '<strong><%:RX%></strong>: %.2mB (%d <%:Pkts.%>)<br />' +
-                                                       '<strong><%:TX%></strong>: %.2mB (%d <%:Pkts.%>)<br />',
-                                                               rxb, rxp, txb, txp
-                                               );
+                                               for (var i = 0; i < ifc.ipaddrs.length; i++)
+                                                       html += String.format(
+                                                               '%s%s/%d',
+                                                               i ? ', ' : '',
+                                                               ifc.ipaddrs[i].addr,
+                                                               ifc.ipaddrs[i].prefix
+                                                       );
 
-                                               if (ifc.ipaddrs && ifc.ipaddrs.length)
-                                               {
-                                                       html += '<strong><%:IPv4%>: </strong>';
-
-                                                       for (var i = 0; i < ifc.ipaddrs.length; i++)
-                                                               html += String.format(
-                                                                       '%s%s/%d',
-                                                                       i ? ', ' : '',
-                                                                       ifc.ipaddrs[i].addr,
-                                                                       ifc.ipaddrs[i].prefix
-                                                               );
-
-                                                       html += '<br />';
-                                               }
-
-                                               if (ifc.ip6addrs && ifc.ip6addrs.length)
-                                               {
-                                                       html += '<strong><%:IPv6%>: </strong>';
+                                               html += '<br />';
+                                       }
 
-                                                       for (var i = 0; i < ifc.ip6addrs.length; i++)
-                                                               html += String.format(
-                                                                       '%s%s/%d',
-                                                                       i ? ', ' : '',
-                                                                       ifc.ip6addrs[i].addr.toUpperCase(),
-                                                                       ifc.ip6addrs[i].prefix
-                                                               );
+                                       if (ifc.ip6addrs && ifc.ip6addrs.length)
+                                       {
+                                               html += '<strong><%:IPv6%>: </strong>';
 
-                                                       html += '<br />';
-                                               }
+                                               for (var i = 0; i < ifc.ip6addrs.length; i++)
+                                                       html += String.format(
+                                                               '%s%s/%d',
+                                                               i ? ', ' : '',
+                                                               ifc.ip6addrs[i].addr.toUpperCase(),
+                                                               ifc.ip6addrs[i].prefix
+                                                       );
 
-                                               d.innerHTML = html;
-                                       }
-                                       else if (d)
-                                       {
-                                               d.innerHTML = '<em><%:Interface not present or not connected yet.%></em>';
+                                               html += '<br />';
                                        }
-                               }
 
-                               window.setTimeout(func, 5000);
+                                       d.innerHTML = html;
+                               }
+                               else if (d)
+                               {
+                                       d.innerHTML = '<em><%:Interface not present or not connected yet.%></em>';
+                               }
                        }
-               )
-       })();
+               }
+       );
 //]]></script>
 
 <table>