Changeset 7568

Show
Ignore:
Timestamp:
09/26/11 01:24:34 (20 months ago)
Author:
jow
Message:

modules/admin-full: rework status javascript code to use XHR.poll()

Location:
luci/trunk/modules/admin-full/luasrc/view
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/modules/admin-full/luasrc/view/admin_network/iface_overview.htm

    r7564 r7568  
    4545        } 
    4646 
    47         var rcxhr = new XHR(); 
    48         rcxhr.get('<%=luci.dispatcher.build_url("admin", "network")%>/iface_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null, 
     47        XHR.get('<%=luci.dispatcher.build_url("admin", "network")%>/iface_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null, 
    4948            function(x) 
    5049            { 
     
    6867    var arptable = <%=luci.http.write_json(arpcache)%>; 
    6968 
    70     (function() { 
    71         var func = arguments.callee; 
    72         iwxhr.get('<%=luci.dispatcher.build_url("admin", "network", "iface_status", table.concat(netlist, ","))%>', null, 
    73             function(x, ifcs) 
     69    XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "network", "iface_status", table.concat(netlist, ","))%>', null, 
     70        function(x, ifcs) 
     71        { 
     72            if (ifcs) 
    7473            { 
    75                 if (ifcs) 
     74                for (var idx = 0; idx < ifcs.length; idx++) 
    7675                { 
    77                     for (var idx = 0; idx < ifcs.length; idx++) 
     76                    var ifc = ifcs[idx]; 
     77                    var html = ''; 
     78 
     79                    var s = document.getElementById(ifc.id + '-ifc-devices'); 
     80                    if (s) 
    7881                    { 
    79                         var ifc = ifcs[idx]; 
    80                         var html = ''; 
    81  
    82                         var s = document.getElementById(ifc.id + '-ifc-devices'); 
    83                         if (s) 
    84                         { 
    85                             var stat = String.format( 
    86                                 '<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" />', 
    87                                     ifc.type, 
    88                                     ifc.is_up ? '' : '_disabled' 
    89                             ); 
    90  
    91                             if (ifc.subdevices && ifc.subdevices.length) 
     82                        var stat = String.format( 
     83                            '<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" />', 
     84                                ifc.type, 
     85                                ifc.is_up ? '' : '_disabled' 
     86                        ); 
     87 
     88                        if (ifc.subdevices && ifc.subdevices.length) 
     89                        { 
     90                            stat += ' <strong>('; 
     91 
     92                            for (var j = 0; j < ifc.subdevices.length; j++) 
    9293                            { 
    93                                 stat += ' <strong>('; 
    94  
    95                                 for (var j = 0; j < ifc.subdevices.length; j++) 
    96                                 { 
    97                                     var sif = ifc.subdevices[j]; 
    98  
    99                                     stat += String.format( 
    100                                         '<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" title="%q" />', 
    101                                             sif.type, 
    102                                             sif.is_up ? '' : '_disabled', 
    103                                             sif.name 
    104                                     ); 
    105                                 } 
    106  
    107                                 stat += ')</strong>'; 
     94                                var sif = ifc.subdevices[j]; 
     95 
     96                                stat += String.format( 
     97                                    '<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px; vertical-align:middle" title="%q" />', 
     98                                        sif.type, 
     99                                        sif.is_up ? '' : '_disabled', 
     100                                        sif.name 
     101                                ); 
    108102                            } 
    109103 
    110                             stat += String.format( 
    111                                 '<br /><small>%s</small>', 
    112                                     ifc.name 
    113                             ); 
    114  
    115                             s.innerHTML = stat; 
    116                         } 
    117  
    118                         var d = document.getElementById(ifc.id + '-ifc-description'); 
    119                         if (d && ifc.ifname) 
    120                         { 
    121                             if (ifc.is_up) 
    122                             { 
    123                                 html += String.format('<strong><%:Uptime%>:</strong> %t<br />', ifc.uptime); 
    124                             } 
    125  
    126                             if (ifc.type != 'tunnel') 
    127                             { 
    128                                 html += String.format('<strong><%:MAC Address%>:</strong> %s<br />', ifc.macaddr); 
    129                             } 
    130  
    131                             html += String.format( 
    132                                 '<strong><%:RX%></strong>: %.2mB (%d <%:Pkts.%>)<br />' + 
    133                                 '<strong><%:TX%></strong>: %.2mB (%d <%:Pkts.%>)<br />', 
    134                                     ifc.rx_bytes, ifc.rx_packets, 
    135                                     ifc.tx_bytes, ifc.tx_packets 
    136                             ); 
    137  
    138                             if (ifc.ipaddrs && ifc.ipaddrs.length) 
    139                             { 
    140                                 html += '<strong><%:IPv4%>: </strong>'; 
    141  
    142                                 for (var i = 0; i < ifc.ipaddrs.length; i++) 
    143                                     html += String.format( 
    144                                         '%s%s/%d', 
    145                                         i ? ', ' : '', 
    146                                         ifc.ipaddrs[i].addr, 
    147                                         ifc.ipaddrs[i].prefix 
    148                                     ); 
    149  
    150                                 html += '<br />'; 
    151                             } 
    152  
    153                             if (ifc.ip6addrs && ifc.ip6addrs.length) 
    154                             { 
    155                                 html += '<strong><%:IPv6%>: </strong>'; 
    156  
    157                                 for (var i = 0; i < ifc.ip6addrs.length; i++) 
    158                                     html += String.format( 
    159                                         '%s%s/%d', 
    160                                         i ? ', ' : '', 
    161                                         ifc.ip6addrs[i].addr.toUpperCase(), 
    162                                         ifc.ip6addrs[i].prefix 
    163                                     ); 
    164  
    165                                 html += '<br />'; 
    166                             } 
    167  
    168                             d.innerHTML = html; 
    169                         } 
    170                         else if (d) 
    171                         { 
    172                             d.innerHTML = '<em><%:Interface not present or not connected yet.%></em>'; 
    173                         } 
     104                            stat += ')</strong>'; 
     105                        } 
     106 
     107                        stat += String.format( 
     108                            '<br /><small>%s</small>', 
     109                                ifc.name 
     110                        ); 
     111 
     112                        s.innerHTML = stat; 
     113                    } 
     114 
     115                    var d = document.getElementById(ifc.id + '-ifc-description'); 
     116                    if (d && ifc.ifname) 
     117                    { 
     118                        if (ifc.is_up) 
     119                        { 
     120                            html += String.format('<strong><%:Uptime%>:</strong> %t<br />', ifc.uptime); 
     121                        } 
     122 
     123                        if (ifc.type != 'tunnel') 
     124                        { 
     125                            html += String.format('<strong><%:MAC Address%>:</strong> %s<br />', ifc.macaddr); 
     126                        } 
     127 
     128                        html += String.format( 
     129                            '<strong><%:RX%></strong>: %.2mB (%d <%:Pkts.%>)<br />' + 
     130                            '<strong><%:TX%></strong>: %.2mB (%d <%:Pkts.%>)<br />', 
     131                                ifc.rx_bytes, ifc.rx_packets, 
     132                                ifc.tx_bytes, ifc.tx_packets 
     133                        ); 
     134 
     135                        if (ifc.ipaddrs && ifc.ipaddrs.length) 
     136                        { 
     137                            html += '<strong><%:IPv4%>: </strong>'; 
     138 
     139                            for (var i = 0; i < ifc.ipaddrs.length; i++) 
     140                                html += String.format( 
     141                                    '%s%s/%d', 
     142                                    i ? ', ' : '', 
     143                                    ifc.ipaddrs[i].addr, 
     144                                    ifc.ipaddrs[i].prefix 
     145                                ); 
     146 
     147                            html += '<br />'; 
     148                        } 
     149 
     150                        if (ifc.ip6addrs && ifc.ip6addrs.length) 
     151                        { 
     152                            html += '<strong><%:IPv6%>: </strong>'; 
     153 
     154                            for (var i = 0; i < ifc.ip6addrs.length; i++) 
     155                                html += String.format( 
     156                                    '%s%s/%d', 
     157                                    i ? ', ' : '', 
     158                                    ifc.ip6addrs[i].addr.toUpperCase(), 
     159                                    ifc.ip6addrs[i].prefix 
     160                                ); 
     161 
     162                            html += '<br />'; 
     163                        } 
     164 
     165                        d.innerHTML = html; 
     166                    } 
     167                    else if (d) 
     168                    { 
     169                        d.innerHTML = '<em><%:Interface not present or not connected yet.%></em>'; 
    174170                    } 
    175171                } 
    176  
    177                 window.setTimeout(func, 5000); 
    178172            } 
    179         ) 
    180     })(); 
     173        } 
     174    ); 
    181175//]]></script> 
    182176 
  • luci/trunk/modules/admin-full/luasrc/view/admin_network/iface_status.htm

    r7559 r7568  
    22 
    33<script type="text/javascript">//<![CDATA[ 
    4     var iwxhr = new XHR(); 
     4    XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "network", "iface_status", self.network)%>', null, 
     5        function(x, ifc) 
     6        { 
     7            if (ifc && (ifc = ifc[0])) 
     8            { 
     9                var html = ''; 
    510 
    6     (function() { 
    7         var func = arguments.callee; 
     11                var s = document.getElementById('<%=self.option%>-ifc-signal'); 
     12                if (s) 
     13                    s.innerHTML = String.format( 
     14                        '<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px" />' + 
     15                        '<br /><small>%s</small>', 
     16                            ifc.type, ifc.is_up ? '' : '_disabled', 
     17                            ifc.is_up ? ifc.ifname : '?' 
     18                    ); 
    819 
    9         iwxhr.get('<%=luci.dispatcher.build_url("admin", "network", "iface_status", self.network)%>', null, 
    10             function(x, ifc) 
    11             { 
    12                 if (ifc && (ifc = ifc[0])) 
     20                var d = document.getElementById('<%=self.option%>-ifc-description'); 
     21                if (d && ifc.ifname && ifc.macaddr != '00:00:00:00:00:00') 
    1322                { 
    14                     var html = ''; 
     23                    if (ifc.is_up) 
     24                    { 
     25                        html += String.format('<strong><%:Uptime%>:</strong> %t<br />', ifc.uptime); 
     26                    } 
    1527 
    16                     var s = document.getElementById('<%=self.option%>-ifc-signal'); 
    17                     if (s) 
    18                         s.innerHTML = String.format( 
    19                             '<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px" />' + 
    20                             '<br /><small>%s</small>', 
    21                                 ifc.type, ifc.is_up ? '' : '_disabled', 
    22                                 ifc.is_up ? ifc.ifname : '?' 
    23                         ); 
     28                    if (ifc.type != 'tunnel') 
     29                    { 
     30                        html += String.format('<strong><%:MAC Address%>:</strong> %s<br />', ifc.macaddr); 
     31                    } 
    2432 
    25                     var d = document.getElementById('<%=self.option%>-ifc-description'); 
    26                     if (d && ifc.ifname && ifc.macaddr != '00:00:00:00:00:00') 
     33                    html += String.format( 
     34                        '<strong><%:RX%></strong>: %.2mB (%d <%:Pkts.%>)<br />' + 
     35                        '<strong><%:TX%></strong>: %.2mB (%d <%:Pkts.%>)<br />', 
     36                            ifc.rx_bytes, ifc.rx_packets, 
     37                            ifc.tx_bytes, ifc.tx_packets 
     38                    ); 
     39 
     40                    if (ifc.ipaddrs && ifc.ipaddrs.length) 
    2741                    { 
    28                         if (ifc.is_up) 
    29                         { 
    30                             html += String.format('<strong><%:Uptime%>:</strong> %t<br />', ifc.uptime); 
    31                         } 
     42                        html += '<strong><%:IPv4%>: </strong>'; 
    3243 
    33                         if (ifc.type != 'tunnel') 
    34                         { 
    35                             html += String.format('<strong><%:MAC Address%>:</strong> %s<br />', ifc.macaddr); 
    36                         } 
     44                        for (var i = 0; i < ifc.ipaddrs.length; i++) 
     45                            html += String.format( 
     46                                '%s%s/%d', 
     47                                i ? ', ' : '', 
     48                                ifc.ipaddrs[i].addr, 
     49                                ifc.ipaddrs[i].prefix 
     50                            ); 
    3751 
    38                         html += String.format( 
    39                             '<strong><%:RX%></strong>: %.2mB (%d <%:Pkts.%>)<br />' + 
    40                             '<strong><%:TX%></strong>: %.2mB (%d <%:Pkts.%>)<br />', 
    41                                 ifc.rx_bytes, ifc.rx_packets, 
    42                                 ifc.tx_bytes, ifc.tx_packets 
    43                         ); 
     52                        html += '<br />'; 
     53                    } 
    4454 
    45                         if (ifc.ipaddrs && ifc.ipaddrs.length) 
    46                         { 
    47                             html += '<strong><%:IPv4%>: </strong>'; 
     55                    if (ifc.ip6addrs && ifc.ip6addrs.length) 
     56                    { 
     57                        html += '<strong><%:IPv6%>: </strong>'; 
    4858 
    49                             for (var i = 0; i < ifc.ipaddrs.length; i++) 
    50                                 html += String.format( 
    51                                     '%s%s/%d', 
    52                                     i ? ', ' : '', 
    53                                     ifc.ipaddrs[i].addr, 
    54                                     ifc.ipaddrs[i].prefix 
    55                                 ); 
     59                        for (var i = 0; i < ifc.ip6addrs.length; i++) 
     60                            html += String.format( 
     61                                '%s%s/%d', 
     62                                i ? ', ' : '', 
     63                                ifc.ip6addrs[i].addr.toUpperCase(), 
     64                                ifc.ip6addrs[i].prefix 
     65                            ); 
    5666 
    57                             html += '<br />'; 
    58                         } 
     67                        html += '<br />'; 
     68                    } 
    5969 
    60                         if (ifc.ip6addrs && ifc.ip6addrs.length) 
    61                         { 
    62                             html += '<strong><%:IPv6%>: </strong>'; 
    63  
    64                             for (var i = 0; i < ifc.ip6addrs.length; i++) 
    65                                 html += String.format( 
    66                                     '%s%s/%d', 
    67                                     i ? ', ' : '', 
    68                                     ifc.ip6addrs[i].addr.toUpperCase(), 
    69                                     ifc.ip6addrs[i].prefix 
    70                                 ); 
    71  
    72                             html += '<br />'; 
    73                         } 
    74  
    75                         d.innerHTML = html; 
    76                     } 
    77                     else if (d) 
    78                     { 
    79                         d.innerHTML = '<em><%:Interface not present or not connected yet.%></em>'; 
    80                     } 
     70                    d.innerHTML = html; 
    8171                } 
    82  
    83                 window.setTimeout(func, 5000); 
     72                else if (d) 
     73                { 
     74                    d.innerHTML = '<em><%:Interface not present or not connected yet.%></em>'; 
     75                } 
    8476            } 
    85         ) 
    86     })(); 
     77        } 
     78    ); 
    8779//]]></script> 
    8880 
  • luci/trunk/modules/admin-full/luasrc/view/admin_network/lease_status.htm

    r7562 r7568  
    11<script type="text/javascript">//<![CDATA[ 
    2     var stxhr = new XHR(); 
     2    XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "network", "dhcplease_status")%>', null, 
     3        function(x, st) 
     4        { 
     5            var tb = document.getElementById('lease_status_table'); 
     6            if (st && tb) 
     7            { 
     8                /* clear all rows */ 
     9                while( tb.rows.length > 1 ) 
     10                    tb.deleteRow(1); 
    311 
    4     (function() { 
    5         var func = arguments.callee; 
     12                for( var i = 0; i < st.length; i++ ) 
     13                { 
     14                    var timestr; 
    615 
    7         stxhr.get('<%=luci.dispatcher.build_url("admin", "network", "dhcplease_status")%>', null, 
    8             function(x, st) 
    9             { 
    10                 var tb = document.getElementById('lease_status_table'); 
    11                 if (st && tb) 
    12                 { 
    13                     /* clear all rows */ 
    14                     while( tb.rows.length > 1 ) 
    15                         tb.deleteRow(1); 
    16  
    17                     for( var i = 0; i < st.length; i++ ) 
     16                    if (st[i].expires <= 0) 
    1817                    { 
    19                         var timestr; 
    20  
    21                         if (st[i].expires <= 0) 
    22                         { 
    23                             timestr = '<em><%:expired%></em>'; 
    24                         } 
    25                         else 
    26                         { 
    27                             timestr = String.format('%t', st[i].expires); 
    28                         } 
    29  
    30                         var tr = tb.insertRow(-1); 
    31                             tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1); 
    32  
    33                         tr.insertCell(-1).innerHTML = st[i].hostname ? st[i].hostname : '?'; 
    34                         tr.insertCell(-1).innerHTML = st[i].ipaddr; 
    35                         tr.insertCell(-1).innerHTML = st[i].macaddr; 
    36                         tr.insertCell(-1).innerHTML = timestr; 
     18                        timestr = '<em><%:expired%></em>'; 
     19                    } 
     20                    else 
     21                    { 
     22                        timestr = String.format('%t', st[i].expires); 
    3723                    } 
    3824 
    39                     if( tb.rows.length == 1 ) 
    40                     { 
    41                         var tr = tb.insertRow(-1); 
    42                             tr.className = 'cbi-section-table-row'; 
     25                    var tr = tb.insertRow(-1); 
     26                        tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1); 
    4327 
    44                         var td = tr.insertCell(-1); 
    45                             td.colSpan = 4; 
    46                             td.innerHTML = '<em><br /><%:There are no active leases.%></em>'; 
    47                     } 
     28                    tr.insertCell(-1).innerHTML = st[i].hostname ? st[i].hostname : '?'; 
     29                    tr.insertCell(-1).innerHTML = st[i].ipaddr; 
     30                    tr.insertCell(-1).innerHTML = st[i].macaddr; 
     31                    tr.insertCell(-1).innerHTML = timestr; 
    4832                } 
    4933 
    50                 window.setTimeout(func, 5000); 
     34                if( tb.rows.length == 1 ) 
     35                { 
     36                    var tr = tb.insertRow(-1); 
     37                        tr.className = 'cbi-section-table-row'; 
     38 
     39                    var td = tr.insertCell(-1); 
     40                        td.colSpan = 4; 
     41                        td.innerHTML = '<em><br /><%:There are no active leases.%></em>'; 
     42                } 
    5143            } 
    52         ) 
    53     })(); 
     44        } 
     45    ); 
    5446//]]></script> 
    5547 
  • luci/trunk/modules/admin-full/luasrc/view/admin_network/wifi_overview.htm

    r7563 r7568  
    120120<script type="text/javascript" src="<%=resource%>/cbi.js"></script> 
    121121<script type="text/javascript">//<![CDATA[ 
    122     var iwxhr = new XHR(); 
    123122    var wifidevs = <%=luci.http.write_json(netdevs)%>; 
    124123    var arptable = <%=luci.http.write_json(arpcache)%>; 
     
    148147        } 
    149148 
    150         var rcxhr = new XHR(); 
    151         rcxhr.get('<%=luci.dispatcher.build_url("admin", "network")%>/wireless_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null, 
     149        XHR.get('<%=luci.dispatcher.build_url("admin", "network")%>/wireless_' + (reconnect ? 'reconnect' : 'shutdown') + '/' + id, null, 
    152150            function(x) 
    153151            { 
     
    167165    } 
    168166 
    169     (function() { 
    170         var func = arguments.callee; 
    171  
    172         iwxhr.get('<%=luci.dispatcher.build_url("admin", "network", "wireless_status", table.concat(netlist, ","))%>', null, 
    173             function(x, st) 
     167    XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "network", "wireless_status", table.concat(netlist, ","))%>', null, 
     168        function(x, st) 
     169        { 
     170            if (st) 
    174171            { 
    175                 if (st) 
     172                var assoctable = document.getElementById('iw-assoclist'); 
     173                if (assoctable) 
     174                    while (assoctable.rows.length > 1) 
     175                        assoctable.rows[1].parentNode.removeChild(assoctable.rows[1]); 
     176 
     177                var devup = { }; 
     178                var rowstyle = 1; 
     179 
     180                for( var i = 0; i < st.length; i++ ) 
    176181                { 
    177                     var assoctable = document.getElementById('iw-assoclist'); 
     182                    var iw = st[i]; 
     183                    var is_assoc = (iw.bssid && iw.bssid != '00:00:00:00:00:00' && iw.channel); 
     184                    var p = iw.quality; 
     185                    var q = is_assoc ? p : -1; 
     186 
     187                    var icon; 
     188                    if (q < 0) 
     189                        icon = "<%=resource%>/icons/signal-none.png"; 
     190                    else if (q == 0) 
     191                        icon = "<%=resource%>/icons/signal-0.png"; 
     192                    else if (q < 25) 
     193                        icon = "<%=resource%>/icons/signal-0-25.png"; 
     194                    else if (q < 50) 
     195                        icon = "<%=resource%>/icons/signal-25-50.png"; 
     196                    else if (q < 75) 
     197                        icon = "<%=resource%>/icons/signal-50-75.png"; 
     198                    else 
     199                        icon = "<%=resource%>/icons/signal-75-100.png"; 
     200 
     201                    if (!devup[wifidevs[iw.id]]) 
     202                        devup[wifidevs[iw.id]] = is_assoc; 
     203 
     204                    var sig = document.getElementById(iw.id + '-iw-signal'); 
     205                    if (sig) 
     206                        sig.innerHTML = String.format( 
     207                            '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" /><br />' + 
     208                            '<small>%d%%</small>', icon, iw.signal, iw.noise, p 
     209                        ); 
     210 
     211                    var toggle = document.getElementById(iw.id + '-iw-toggle'); 
     212                    if (toggle) 
     213                    { 
     214                        if (is_assoc) 
     215                        { 
     216                            toggle.style.backgroundImage = 'url(<%=resource%>/cbi/reset.gif)'; 
     217                            toggle.value = '<%:Disable%>'; 
     218                            toggle.title = '<%:Shutdown this network%>'; 
     219                        } 
     220                        else 
     221                        { 
     222                            toggle.style.backgroundImage = 'url(<%=resource%>/cbi/reload.gif)'; 
     223                            toggle.value = '<%:Enable%>'; 
     224                            toggle.title = '<%:Activate this network%>'; 
     225                        } 
     226 
     227                        toggle.setAttribute('active', is_assoc); 
     228                    } 
     229 
     230                    var info = document.getElementById(iw.id + '-iw-status'); 
     231                    if (info) 
     232                    { 
     233                        if (is_assoc) 
     234                            info.innerHTML = String.format( 
     235                                '<strong><%:SSID%>:</strong> %h | ' + 
     236                                '<strong><%:Mode%>:</strong> %s<br />' + 
     237                                '<strong><%:BSSID%>:</strong> %s | ' + 
     238                                '<strong><%:Encryption%>:</strong> %s', 
     239                                    iw.ssid, iw.mode, iw.bssid, 
     240                                    iw.encryption ? iw.encryption : '<%:None%>' 
     241                            ); 
     242                        else 
     243                            info.innerHTML = String.format( 
     244                                '<strong><%:SSID%>:</strong> %h | ' + 
     245                                '<strong><%:Mode%>:</strong> %s<br />' + 
     246                                '<em>%s</em>', 
     247                                    iw.ssid || '?', iw.mode, 
     248                                    is_reconnecting 
     249                                        ? '<em><%:Wireless is restarting...%></em>' 
     250                                        : '<em><%:Wireless is disabled or not associated%></em>' 
     251                            ); 
     252                    } 
     253 
     254                    var dev = document.getElementById(wifidevs[iw.id] + '-iw-devinfo'); 
     255                    if (dev) 
     256                    { 
     257                        if (is_assoc) 
     258                            dev.innerHTML = String.format( 
     259                                '<strong><%:Channel%>:</strong> %s (%s GHz) | ' + 
     260                                '<strong><%:Bitrate%>:</strong> %s Mb/s', 
     261                                    iw.channel ? iw.channel : '?', 
     262                                    iw.frequency ? iw.frequency : '?', 
     263                                    iw.bitrate ? iw.bitrate : '?' 
     264                            ); 
     265                        else 
     266                            dev.innerHTML = ''; 
     267                    } 
     268 
    178269                    if (assoctable) 
    179                         while (assoctable.rows.length > 1) 
    180                             assoctable.rows[1].parentNode.removeChild(assoctable.rows[1]); 
    181  
    182                     var devup = { }; 
    183                     var rowstyle = 1; 
    184  
    185                     for( var i = 0; i < st.length; i++ ) 
    186270                    { 
    187                         var iw = st[i]; 
    188                         var is_assoc = (iw.bssid && iw.bssid != '00:00:00:00:00:00' && iw.channel); 
    189                         var p = iw.quality; 
    190                         var q = is_assoc ? p : -1; 
    191  
    192                         var icon; 
    193                         if (q < 0) 
    194                             icon = "<%=resource%>/icons/signal-none.png"; 
    195                         else if (q == 0) 
    196                             icon = "<%=resource%>/icons/signal-0.png"; 
    197                         else if (q < 25) 
    198                             icon = "<%=resource%>/icons/signal-0-25.png"; 
    199                         else if (q < 50) 
    200                             icon = "<%=resource%>/icons/signal-25-50.png"; 
    201                         else if (q < 75) 
    202                             icon = "<%=resource%>/icons/signal-50-75.png"; 
    203                         else 
    204                             icon = "<%=resource%>/icons/signal-75-100.png"; 
    205  
    206                         if (!devup[wifidevs[iw.id]]) 
    207                             devup[wifidevs[iw.id]] = is_assoc; 
    208  
    209                         var sig = document.getElementById(iw.id + '-iw-signal'); 
    210                         if (sig) 
    211                             sig.innerHTML = String.format( 
    212                                 '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" /><br />' + 
    213                                 '<small>%d%%</small>', icon, iw.signal, iw.noise, p 
     271                        var assoclist = [ ]; 
     272                        for( var bssid in iw.assoclist ) 
     273                        { 
     274                            assoclist.push(iw.assoclist[bssid]); 
     275                            assoclist[assoclist.length-1].bssid = bssid; 
     276                        } 
     277 
     278                        assoclist.sort(function(a, b) { a.bssid < b.bssid }); 
     279 
     280                        for( var j = 0; j < assoclist.length; j++ ) 
     281                        { 
     282                            var tr = assoctable.insertRow(-1); 
     283                                tr.className = 'cbi-section-table-row cbi-rowstyle-' + rowstyle; 
     284 
     285                            var icon; 
     286                            var q = (-1 * (assoclist[j].noise - assoclist[j].signal)) / 5; 
     287                            if (q < 1) 
     288                                icon = "<%=resource%>/icons/signal-0.png"; 
     289                            else if (q < 2) 
     290                                icon = "<%=resource%>/icons/signal-0-25.png"; 
     291                            else if (q < 3) 
     292                                icon = "<%=resource%>/icons/signal-25-50.png"; 
     293                            else if (q < 4) 
     294                                icon = "<%=resource%>/icons/signal-50-75.png"; 
     295                            else 
     296                                icon = "<%=resource%>/icons/signal-75-100.png"; 
     297 
     298                            tr.insertCell(-1).innerHTML = String.format( 
     299                                '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />', 
     300                                icon, assoclist[j].signal, assoclist[j].noise 
    214301                            ); 
    215302 
    216                         var toggle = document.getElementById(iw.id + '-iw-toggle'); 
    217                         if (toggle) 
    218                         { 
    219                             if (is_assoc) 
    220                             { 
    221                                 toggle.style.backgroundImage = 'url(<%=resource%>/cbi/reset.gif)'; 
    222                                 toggle.value = '<%:Disable%>'; 
    223                                 toggle.title = '<%:Shutdown this network%>'; 
    224                             } 
    225                             else 
    226                             { 
    227                                 toggle.style.backgroundImage = 'url(<%=resource%>/cbi/reload.gif)'; 
    228                                 toggle.value = '<%:Enable%>'; 
    229                                 toggle.title = '<%:Activate this network%>'; 
    230  
    231                             } 
    232  
    233                             toggle.setAttribute('active', is_assoc); 
    234                         } 
    235  
    236                         var info = document.getElementById(iw.id + '-iw-status'); 
    237                         if (info) 
    238                         { 
    239                             if (is_assoc) 
    240                                 info.innerHTML = String.format( 
    241                                     '<strong><%:SSID%>:</strong> %h | ' + 
    242                                     '<strong><%:Mode%>:</strong> %s<br />' + 
    243                                     '<strong><%:BSSID%>:</strong> %s | ' + 
    244                                     '<strong><%:Encryption%>:</strong> %s', 
    245                                         iw.ssid, iw.mode, iw.bssid, 
    246                                         iw.encryption ? iw.encryption : '<%:None%>' 
    247                                 ); 
    248                             else 
    249                                 info.innerHTML = String.format( 
    250                                     '<strong><%:SSID%>:</strong> %h | ' + 
    251                                     '<strong><%:Mode%>:</strong> %s<br />' + 
    252                                     '<em>%s</em>', 
    253                                         iw.ssid || '?', iw.mode, 
    254                                         is_reconnecting 
    255                                             ? '<em><%:Wireless is restarting...%></em>' 
    256                                             : '<em><%:Wireless is disabled or not associated%></em>' 
    257                                 ); 
    258                         } 
    259  
    260                         var dev = document.getElementById(wifidevs[iw.id] + '-iw-devinfo'); 
    261                         if (dev) 
    262                         { 
    263                             if (is_assoc) 
    264                                 dev.innerHTML = String.format( 
    265                                     '<strong><%:Channel%>:</strong> %s (%s GHz) | ' + 
    266                                     '<strong><%:Bitrate%>:</strong> %s Mb/s', 
    267                                         iw.channel ? iw.channel : '?', 
    268                                         iw.frequency ? iw.frequency : '?', 
    269                                         iw.bitrate ? iw.bitrate : '?' 
    270                                 ); 
    271                             else 
    272                                 dev.innerHTML = ''; 
    273                         } 
    274  
    275                         if (assoctable) 
    276                         { 
    277                             var assoclist = [ ]; 
    278                             for( var bssid in iw.assoclist ) 
    279                             { 
    280                                 assoclist.push(iw.assoclist[bssid]); 
    281                                 assoclist[assoclist.length-1].bssid = bssid; 
    282                             } 
    283  
    284                             assoclist.sort(function(a, b) { a.bssid < b.bssid }); 
    285  
    286                             for( var j = 0; j < assoclist.length; j++ ) 
    287                             { 
    288                                 var tr = assoctable.insertRow(-1); 
    289                                     tr.className = 'cbi-section-table-row cbi-rowstyle-' + rowstyle; 
    290  
    291                                 var icon; 
    292                                 var q = (-1 * (assoclist[j].noise - assoclist[j].signal)) / 5; 
    293                                 if (q < 1) 
    294                                     icon = "<%=resource%>/icons/signal-0.png"; 
    295                                 else if (q < 2) 
    296                                     icon = "<%=resource%>/icons/signal-0-25.png"; 
    297                                 else if (q < 3) 
    298                                     icon = "<%=resource%>/icons/signal-25-50.png"; 
    299                                 else if (q < 4) 
    300                                     icon = "<%=resource%>/icons/signal-50-75.png"; 
    301                                 else 
    302                                     icon = "<%=resource%>/icons/signal-75-100.png"; 
    303  
    304                                 tr.insertCell(-1).innerHTML = String.format( 
    305                                     '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />', 
    306                                     icon, assoclist[j].signal, assoclist[j].noise 
    307                                 ); 
    308  
    309                                 tr.insertCell(-1).innerHTML = iw.ssid ? iw.ssid : '?'; 
    310                                 tr.insertCell(-1).innerHTML = assoclist[j].bssid; 
    311  
    312                                 tr.insertCell(-1).innerHTML = arptable[assoclist[j].bssid] 
    313                                     ? arptable[assoclist[j].bssid] : '?'; 
    314  
    315                                 tr.insertCell(-1).innerHTML = String.format('%d dBm', assoclist[j].signal); 
    316                                 tr.insertCell(-1).innerHTML = String.format('%d dBm', assoclist[j].noise); 
    317  
    318                                 rowstyle = (rowstyle == 1) ? 2 : 1; 
    319                             } 
     303                            tr.insertCell(-1).innerHTML = iw.ssid ? iw.ssid : '?'; 
     304                            tr.insertCell(-1).innerHTML = assoclist[j].bssid; 
     305 
     306                            tr.insertCell(-1).innerHTML = arptable[assoclist[j].bssid] 
     307                                ? arptable[assoclist[j].bssid] : '?'; 
     308 
     309                            tr.insertCell(-1).innerHTML = String.format('%d dBm', assoclist[j].signal); 
     310                            tr.insertCell(-1).innerHTML = String.format('%d dBm', assoclist[j].noise); 
     311 
     312                            rowstyle = (rowstyle == 1) ? 2 : 1; 
    320313                        } 
    321314                    } 
    322  
    323                     if (assoctable && assoctable.rows.length == 1) 
    324                     { 
    325                         var tr = assoctable.insertRow(-1); 
    326                             tr.className = 'cbi-section-table-row'; 
    327  
    328                         var td = tr.insertCell(-1); 
    329                             td.colSpan = 6; 
    330                             td.innerHTML = '<br /><em><%:No information available%></em>'; 
    331                     } 
    332  
    333                     for (var dev in devup) 
    334                     { 
    335                         var img = document.getElementById(dev + '-iw-upstate'); 
    336                         if (img) 
    337                             img.src = '<%=resource%>/icons/wifi_big' + (devup[dev] ? '' : '_disabled') + '.png'; 
    338                     } 
    339315                } 
    340316 
    341                 window.setTimeout(func, 5000); 
     317                if (assoctable && assoctable.rows.length == 1) 
     318                { 
     319                    var tr = assoctable.insertRow(-1); 
     320                        tr.className = 'cbi-section-table-row'; 
     321 
     322                    var td = tr.insertCell(-1); 
     323                        td.colSpan = 6; 
     324                        td.innerHTML = '<br /><em><%:No information available%></em>'; 
     325                } 
     326 
     327                for (var dev in devup) 
     328                { 
     329                    var img = document.getElementById(dev + '-iw-upstate'); 
     330                    if (img) 
     331                        img.src = '<%=resource%>/icons/wifi_big' + (devup[dev] ? '' : '_disabled') + '.png'; 
     332                } 
    342333            } 
    343         ) 
    344     })(); 
     334        } 
     335    ); 
    345336//]]></script> 
    346337 
  • luci/trunk/modules/admin-full/luasrc/view/admin_network/wifi_status.htm

    r7562 r7568  
    22 
    33<script type="text/javascript">//<![CDATA[ 
    4     var iwxhr = new XHR(); 
     4    XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "network", "wireless_status", self.ifname)%>', null, 
     5        function(x, iw) 
     6        { 
     7            if (iw && (iw = iw[0])) 
     8            { 
     9                var is_assoc = (iw.bssid && iw.bssid != '00:00:00:00:00:00' && iw.channel); 
     10                var p = iw.quality; 
     11                var q = is_assoc ? p : -1; 
    512 
    6     (function() { 
    7         var func = arguments.callee; 
     13                var icon; 
     14                if (q < 0) 
     15                    icon = "<%=resource%>/icons/signal-none.png"; 
     16                else if (q == 0) 
     17                    icon = "<%=resource%>/icons/signal-0.png"; 
     18                else if (q < 25) 
     19                    icon = "<%=resource%>/icons/signal-0-25.png"; 
     20                else if (q < 50) 
     21                    icon = "<%=resource%>/icons/signal-25-50.png"; 
     22                else if (q < 75) 
     23                    icon = "<%=resource%>/icons/signal-50-75.png"; 
     24                else 
     25                    icon = "<%=resource%>/icons/signal-75-100.png"; 
    826 
    9         iwxhr.get('<%=luci.dispatcher.build_url("admin", "network", "wireless_status", self.ifname)%>', null, 
    10             function(x, iw) 
    11             { 
    12                 if (iw && (iw = iw[0])) 
    13                 { 
    14                     var is_assoc = (iw.bssid && iw.bssid != '00:00:00:00:00:00' && iw.channel); 
    15                     var p = iw.quality; 
    16                     var q = is_assoc ? p : -1; 
     27                var s = document.getElementById('<%=self.option%>-iw-signal'); 
     28                if (s) 
     29                    s.innerHTML = String.format( 
     30                        '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" /><br />' + 
     31                        '<small>%d%%</small>', icon, iw.signal, iw.noise, p 
     32                    ); 
    1733 
    18                     var icon; 
    19                     if (q < 0) 
    20                         icon = "<%=resource%>/icons/signal-none.png"; 
    21                     else if (q == 0) 
    22                         icon = "<%=resource%>/icons/signal-0.png"; 
    23                     else if (q < 25) 
    24                         icon = "<%=resource%>/icons/signal-0-25.png"; 
    25                     else if (q < 50) 
    26                         icon = "<%=resource%>/icons/signal-25-50.png"; 
    27                     else if (q < 75) 
    28                         icon = "<%=resource%>/icons/signal-50-75.png"; 
    29                     else 
    30                         icon = "<%=resource%>/icons/signal-75-100.png"; 
    31  
    32                     var s = document.getElementById('<%=self.option%>-iw-signal'); 
    33                     if (s) 
    34                         s.innerHTML = String.format( 
    35                             '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" /><br />' + 
    36                             '<small>%d%%</small>', icon, iw.signal, iw.noise, p 
    37                         ); 
    38  
    39                     var d = document.getElementById('<%=self.option%>-iw-description'); 
    40                     if (d && is_assoc) 
    41                         d.innerHTML = String.format( 
    42                             '<strong><%:Mode%>:</strong> %s | ' + 
    43                             '<strong><%:SSID%>:</strong> %h<br />' + 
    44                             '<strong><%:BSSID%>:</strong> %s | ' + 
    45                             '<strong><%:Encryption%>:</strong> %s<br />' + 
    46                             '<strong><%:Channel%>:</strong> %d (%.3f GHz) | ' + 
    47                             '<strong><%:Tx-Power%>:</strong> %d dBm<br />' + 
    48                             '<strong><%:Signal%>:</strong> %d dBm | ' + 
    49                             '<strong><%:Noise%>:</strong> %d dBm<br />' + 
    50                             '<strong><%:Bit Rate%>:</strong> %.1f MBit/s | ' + 
    51                             '<strong><%:Country%>:</strong> %s', 
    52                                 iw.mode, iw.ssid, iw.bssid, 
    53                                 iw.encryption ? iw.encryption : '<%:None%>', 
    54                                 iw.channel, iw.frequency ? iw.frequency : 0, 
    55                                 iw.txpower, iw.signal, iw.noise, 
    56                                 iw.bitrate ? iw.bitrate : 0, iw.country 
    57                         ); 
    58                     else if (d) 
    59                         d.innerHTML = String.format( 
    60                             '<strong><%:SSID%>:</strong> %h | ' + 
    61                             '<strong><%:Mode%>:</strong> %s<br />' + 
    62                             '<em><%:Wireless is disabled or not associated%></em>', 
    63                                 iw.ssid || '?', iw.mode 
    64                         ); 
    65                 } 
    66  
    67                 window.setTimeout(func, 5000); 
     34                var d = document.getElementById('<%=self.option%>-iw-description'); 
     35                if (d && is_assoc) 
     36                    d.innerHTML = String.format( 
     37                        '<strong><%:Mode%>:</strong> %s | ' + 
     38                        '<strong><%:SSID%>:</strong> %h<br />' + 
     39                        '<strong><%:BSSID%>:</strong> %s | ' + 
     40                        '<strong><%:Encryption%>:</strong> %s<br />' + 
     41                        '<strong><%:Channel%>:</strong> %d (%.3f GHz) | ' + 
     42                        '<strong><%:Tx-Power%>:</strong> %d dBm<br />' + 
     43                        '<strong><%:Signal%>:</strong> %d dBm | ' + 
     44                        '<strong><%:Noise%>:</strong> %d dBm<br />' + 
     45                        '<strong><%:Bit Rate%>:</strong> %.1f MBit/s | ' + 
     46                        '<strong><%:Country%>:</strong> %s', 
     47                            iw.mode, iw.ssid, iw.bssid, 
     48                            iw.encryption ? iw.encryption : '<%:None%>', 
     49                            iw.channel, iw.frequency ? iw.frequency : 0, 
     50                            iw.txpower, iw.signal, iw.noise, 
     51                            iw.bitrate ? iw.bitrate : 0, iw.country 
     52                    ); 
     53                else if (d) 
     54                    d.innerHTML = String.format( 
     55                        '<strong><%:SSID%>:</strong> %h | ' + 
     56                        '<strong><%:Mode%>:</strong> %s<br />' + 
     57                        '<em><%:Wireless is disabled or not associated%></em>', 
     58                            iw.ssid || '?', iw.mode 
     59                    ); 
    6860            } 
    69         ) 
    70     })(); 
     61        } 
     62    ); 
    7163//]]></script> 
    7264 
  • luci/trunk/modules/admin-full/luasrc/view/admin_status/index.htm

    r7559 r7568  
    120120    } 
    121121 
    122     var iwxhr = new XHR(); 
    123122    var wifidevs = <%=luci.http.write_json(netdevs)%>; 
    124123    var arptable = <%=luci.http.write_json(arpcache)%>; 
    125124 
    126     (function() { 
    127         var func = arguments.callee; 
    128  
    129         iwxhr.get('<%=REQUEST_URI%>', { status: 1 }, 
    130             function(x, info) 
    131             { 
    132                 var si = document.getElementById('wan4_i'); 
    133                 var ss = document.getElementById('wan4_s'); 
    134                 var ifc = info.wan; 
    135  
    136                 if (ifc && ifc.ifname && ifc.proto != 'none') 
    137                 { 
    138                     var s = String.format( 
    139                         '<strong><%:Type%>: </strong>%s<br />' + 
    140                         '<strong><%:Address%>: </strong>%s<br />' + 
    141                         '<strong><%:Netmask%>: </strong>%s<br />' + 
    142                         '<strong><%:Gateway%>: </strong>%s<br />', 
    143                             ifc.proto, 
    144                             (ifc.ipaddr) ? ifc.ipaddr : '0.0.0.0', 
    145                             (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '255.255.255.255', 
    146                             (ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0' 
    147                     ); 
    148  
    149                     for (var i = 0; i < ifc.dns.length; i++) 
     125    XHR.poll(5, '<%=REQUEST_URI%>', { status: 1 }, 
     126        function(x, info) 
     127        { 
     128            var si = document.getElementById('wan4_i'); 
     129            var ss = document.getElementById('wan4_s'); 
     130            var ifc = info.wan; 
     131 
     132            if (ifc && ifc.ifname && ifc.proto != 'none') 
     133            { 
     134                var s = String.format( 
     135                    '<strong><%:Type%>: </strong>%s<br />' + 
     136                    '<strong><%:Address%>: </strong>%s<br />' + 
     137                    '<strong><%:Netmask%>: </strong>%s<br />' + 
     138                    '<strong><%:Gateway%>: </strong>%s<br />', 
     139                        ifc.proto, 
     140                        (ifc.ipaddr) ? ifc.ipaddr : '0.0.0.0', 
     141                        (ifc.netmask && ifc.netmask != ifc.ipaddr) ? ifc.netmask : '255.255.255.255', 
     142                        (ifc.gwaddr) ? ifc.gwaddr : '0.0.0.0' 
     143                ); 
     144 
     145                for (var i = 0; i < ifc.dns.length; i++) 
     146                { 
     147                    s += String.format( 
     148                        '<strong><%:DNS%> %d: </strong>%s<br />', 
     149                        i + 1, ifc.dns[i] 
     150                    ); 
     151                } 
     152 
     153                if (ifc.expires > -1) 
     154                { 
     155                    s += String.format( 
     156                        '<strong><%:Expires%>: </strong>%t<br />', 
     157                        ifc.expires 
     158                    ); 
     159                } 
     160 
     161                if (ifc.uptime > 0) 
     162                { 
     163                    s += String.format( 
     164                        '<strong><%:Connected%>: </strong>%t<br />', 
     165                        ifc.uptime 
     166                    ); 
     167                } 
     168 
     169                ss.innerHTML = String.format('<small>%s</small>', s); 
     170                si.innerHTML = String.format( 
     171                    '<img src="<%=resource%>/icons/ethernet.png" />' + 
     172                    '<br /><small><a href="%s">%s</a></small>', 
     173                        ifc.link, ifc.ifname 
     174                ); 
     175            } 
     176            else 
     177            { 
     178                si.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>'; 
     179                ss.innerHTML = '<em>Not connected</em>'; 
     180            } 
     181 
     182            <% if has_ipv6 then %> 
     183            var si6 = document.getElementById('wan6_i'); 
     184            var ss6 = document.getElementById('wan6_s'); 
     185            var ifc6 = info.wan6; 
     186 
     187            if (ifc6 && ifc6.ifname && ifc6.proto != 'none') 
     188            { 
     189                var s = String.format( 
     190                    '<strong><%:Address%>: </strong>%s<br />' + 
     191                    '<strong><%:Gateway%>: </strong>%s<br />', 
     192                        (ifc6.ip6addr) ? ifc6.ip6addr : '::', 
     193                        (ifc6.gw6addr) ? ifc6.gw6addr : '::' 
     194                ); 
     195 
     196                for (var i = 0; i < ifc6.dns.length; i++) 
     197                { 
     198                    s += String.format( 
     199                        '<strong><%:DNS%> %d: </strong>%s<br />', 
     200                        i + 1, ifc6.dns[i] 
     201                    ); 
     202                } 
     203 
     204                if (ifc6.uptime > 0) 
     205                { 
     206                    s += String.format( 
     207                        '<strong><%:Connected%>: </strong>%t<br />', 
     208                        ifc6.uptime 
     209                    ); 
     210                } 
     211 
     212                ss6.innerHTML = String.format('<small>%s</small>', s); 
     213                si6.innerHTML = String.format( 
     214                    '<img src="<%=resource%>/icons/ethernet.png" />' + 
     215                    '<br /><small><a href="%s">%s</a></small>', 
     216                        ifc6.link, ifc6.ifname 
     217                ); 
     218            } 
     219            else 
     220            { 
     221                si6.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>'; 
     222                ss6.innerHTML = '<em>Not connected</em>'; 
     223            } 
     224            <% end %> 
     225 
     226            <% if has_dhcp then %> 
     227            var ls = document.getElementById('lease_status_table'); 
     228            if (ls) 
     229            { 
     230                /* clear all rows */ 
     231                while( ls.rows.length > 1 ) 
     232                    ls.rows[0].parentNode.deleteRow(1); 
     233 
     234                for( var i = 0; i < info.leases.length; i++ ) 
     235                { 
     236                    var timestr; 
     237 
     238                    if (info.leases[i].expires <= 0) 
     239                        timestr = '<em><%:expired%></em>'; 
     240                    else 
     241                        timestr = String.format('%t', info.leases[i].expires); 
     242 
     243                    var tr = ls.rows[0].parentNode.insertRow(-1); 
     244                        tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1); 
     245 
     246                    tr.insertCell(-1).innerHTML = info.leases[i].hostname ? info.leases[i].hostname : '?'; 
     247                    tr.insertCell(-1).innerHTML = info.leases[i].ipaddr; 
     248                    tr.insertCell(-1).innerHTML = info.leases[i].macaddr; 
     249                    tr.insertCell(-1).innerHTML = timestr; 
     250                } 
     251 
     252                if( ls.rows.length == 1 ) 
     253                { 
     254                    var tr = ls.rows[0].parentNode.insertRow(-1); 
     255                        tr.className = 'cbi-section-table-row'; 
     256 
     257                    var td = tr.insertCell(-1); 
     258                        td.colSpan = 4; 
     259                        td.innerHTML = '<em><br /><%:There are no active leases.%></em>'; 
     260                } 
     261            } 
     262            <% end %> 
     263 
     264            <% if has_wifi then %> 
     265            var assoclist = [ ]; 
     266 
     267            var ws = document.getElementById('wifi_status_table'); 
     268            if (ws) 
     269            { 
     270                var wsbody = ws.rows[0].parentNode; 
     271                while (ws.rows.length > 0) 
     272                    wsbody.deleteRow(0); 
     273 
     274                for (var didx = 0; didx < info.wifinets.length; didx++) 
     275                { 
     276                    var dev = info.wifinets[didx]; 
     277 
     278                    var tr = wsbody.insertRow(-1); 
     279                    var td; 
     280 
     281                    td = tr.insertCell(-1); 
     282                    td.width     = "33%"; 
     283                    td.innerHTML = dev.name; 
     284                    td.style.verticalAlign = "top"; 
     285 
     286                    td = tr.insertCell(-1); 
     287 
     288                    var s = ''; 
     289 
     290                    for (var nidx = 0; nidx < dev.networks.length; nidx++) 
    150291                    { 
    151                         s += String.format( 
    152                             '<strong><%:DNS%> %d: </strong>%s<br />', 
    153                             i + 1, ifc.dns[i] 
    154                         ); 
    155                     } 
    156  
    157                     if (ifc.expires > -1) 
    158                     { 
    159                         s += String.format( 
    160                             '<strong><%:Expires%>: </strong>%t<br />', 
    161                             ifc.expires 
    162                         ); 
    163                     } 
    164  
    165                     if (ifc.uptime > 0) 
    166                     { 
    167                         s += String.format( 
    168                             '<strong><%:Connected%>: </strong>%t<br />', 
    169                             ifc.uptime 
    170                         ); 
    171                     } 
    172  
    173                     ss.innerHTML = String.format('<small>%s</small>', s); 
    174                     si.innerHTML = String.format( 
    175                         '<img src="<%=resource%>/icons/ethernet.png" />' + 
    176                         '<br /><small><a href="%s">%s</a></small>', 
    177                             ifc.link, ifc.ifname 
    178                     ); 
    179                 } 
    180                 else 
    181                 { 
    182                     si.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>'; 
    183                     ss.innerHTML = '<em>Not connected</em>'; 
    184                 } 
    185  
    186                 <% if has_ipv6 then %> 
    187                 var si6 = document.getElementById('wan6_i'); 
    188                 var ss6 = document.getElementById('wan6_s'); 
    189                 var ifc6 = info.wan6; 
    190  
    191                 if (ifc6 && ifc6.ifname && ifc6.proto != 'none') 
    192                 { 
    193                     var s = String.format( 
    194                         '<strong><%:Address%>: </strong>%s<br />' + 
    195                         '<strong><%:Gateway%>: </strong>%s<br />', 
    196                             (ifc6.ip6addr) ? ifc6.ip6addr : '::', 
    197                             (ifc6.gw6addr) ? ifc6.gw6addr : '::' 
    198                     ); 
    199  
    200                     for (var i = 0; i < ifc6.dns.length; i++) 
    201                     { 
    202                         s += String.format( 
    203                             '<strong><%:DNS%> %d: </strong>%s<br />', 
    204                             i + 1, ifc6.dns[i] 
    205                         ); 
    206                     } 
    207  
    208                     if (ifc6.uptime > 0) 
    209                     { 
    210                         s += String.format( 
    211                             '<strong><%:Connected%>: </strong>%t<br />', 
    212                             ifc6.uptime 
    213                         ); 
    214                     } 
    215  
    216                     ss6.innerHTML = String.format('<small>%s</small>', s); 
    217                     si6.innerHTML = String.format( 
    218                         '<img src="<%=resource%>/icons/ethernet.png" />' + 
    219                         '<br /><small><a href="%s">%s</a></small>', 
    220                             ifc6.link, ifc6.ifname 
    221                     ); 
    222                 } 
    223                 else 
    224                 { 
    225                     si6.innerHTML = '<img src="<%=resource%>/icons/ethernet_disabled.png" /><br /><small>?</small>'; 
    226                     ss6.innerHTML = '<em>Not connected</em>'; 
    227                 } 
    228                 <% end %> 
    229  
    230                 <% if has_dhcp then %> 
    231                 var ls = document.getElementById('lease_status_table'); 
    232                 if (ls) 
    233                 { 
    234                     /* clear all rows */ 
    235                     while( ls.rows.length > 1 ) 
    236                         ls.rows[0].parentNode.deleteRow(1); 
    237  
    238                     for( var i = 0; i < info.leases.length; i++ ) 
    239                     { 
    240                         var timestr; 
    241  
    242                         if (info.leases[i].expires <= 0) 
    243                             timestr = '<em><%:expired%></em>'; 
    244                         else 
    245                             timestr = String.format('%t', info.leases[i].expires); 
    246  
    247                         var tr = ls.rows[0].parentNode.insertRow(-1); 
    248                             tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1); 
    249  
    250                         tr.insertCell(-1).innerHTML = info.leases[i].hostname ? info.leases[i].hostname : '?'; 
    251                         tr.insertCell(-1).innerHTML = info.leases[i].ipaddr; 
    252                         tr.insertCell(-1).innerHTML = info.leases[i].macaddr; 
    253                         tr.insertCell(-1).innerHTML = timestr; 
    254                     } 
    255  
    256                     if( ls.rows.length == 1 ) 
    257                     { 
    258                         var tr = ls.rows[0].parentNode.insertRow(-1); 
    259                             tr.className = 'cbi-section-table-row'; 
    260  
    261                         var td = tr.insertCell(-1); 
    262                             td.colSpan = 4; 
    263                             td.innerHTML = '<em><br /><%:There are no active leases.%></em>'; 
    264                     } 
    265                 } 
    266                 <% end %> 
    267  
    268                 <% if has_wifi then %> 
    269                 var assoclist = [ ]; 
    270  
    271                 var ws = document.getElementById('wifi_status_table'); 
    272                 if (ws) 
    273                 { 
    274                     var wsbody = ws.rows[0].parentNode; 
    275                     while (ws.rows.length > 0) 
    276                         wsbody.deleteRow(0); 
    277  
    278                     for (var didx = 0; didx < info.wifinets.length; didx++) 
    279                     { 
    280                         var dev = info.wifinets[didx]; 
    281  
    282                         var tr = wsbody.insertRow(-1); 
    283                         var td; 
    284  
    285                         td = tr.insertCell(-1); 
    286                         td.width     = "33%"; 
    287                         td.innerHTML = dev.name; 
    288                         td.style.verticalAlign = "top"; 
    289  
    290                         td = tr.insertCell(-1); 
    291  
    292                         var s = ''; 
    293  
    294                         for (var nidx = 0; nidx < dev.networks.length; nidx++) 
    295                         { 
    296                             var net = dev.networks[nidx]; 
    297                             var is_assoc = (net.bssid != '00:00:00:00:00:00' && net.channel); 
    298  
    299                             var icon; 
    300                             if (!is_assoc) 
    301                                 icon = "<%=resource%>/icons/signal-none.png"; 
    302                             else if (net.quality == 0) 
    303                                 icon = "<%=resource%>/icons/signal-0.png"; 
    304                             else if (net.quality < 25) 
    305                                 icon = "<%=resource%>/icons/signal-0-25.png"; 
    306                             else if (net.quality < 50) 
    307                                 icon = "<%=resource%>/icons/signal-25-50.png"; 
    308                             else if (net.quality < 75) 
    309                                 icon = "<%=resource%>/icons/signal-50-75.png"; 
    310                             else 
    311                                 icon = "<%=resource%>/icons/signal-75-100.png"; 
    312  
    313                             s += String.format( 
    314                                 '<table><tr><td style="text-align:center; width:32px; padding:3px">' + 
    315                                     '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />' + 
    316                                     '<br /><small>%d%%</small>' + 
    317                                 '</td><td style="text-align:left; padding:3px"><small>' + 
    318                                     '<strong><%:SSID%>:</strong> <a href="%s">%h</a><br />' + 
    319                                     '<strong><%:Mode%>:</strong> %s<br />' + 
    320                                     '<strong><%:Channel%>:</strong> %d (%.2f GHz)<br />' + 
    321                                     '<strong><%:Bitrate%>:</strong> %s Mb/s<br />', 
    322                                     icon, net.signal, net.noise, 
    323                                     net.quality, 
    324                                     net.link, net.ssid, 
    325                                     net.mode, 
    326                                     net.channel, net.frequency, 
    327                                     net.bitrate || '?' 
    328                             ); 
    329  
    330                             if (is_assoc) 
    331                             { 
    332                                 s += String.format( 
    333                                     '<strong><%:BSSID%>:</strong> %s<br />' + 
    334                                     '<strong><%:Encryption%>:</strong> %s', 
    335                                         net.bssid, 
    336                                         net.encryption 
    337                                 ); 
    338                             } 
    339                             else 
    340                             { 
    341                                 s += '<em><%:Wireless is disabled or not associated%></em>'; 
    342                             } 
    343  
    344                             s += '</small></td></tr></table>'; 
    345  
    346                             for (var bssid in net.assoclist) 
    347                             { 
    348                                 assoclist.push({ 
    349                                     bssid:  bssid, 
    350                                     signal: net.assoclist[bssid].signal, 
    351                                     noise:  net.assoclist[bssid].noise, 
    352                                     link:   net.link, 
    353                                     name:   net.name 
    354                                 }); 
    355                             } 
    356                         } 
    357  
    358                         if (!s) 
    359                             s = '<em><%:No information available%></em>'; 
    360  
    361                         td.innerHTML = s; 
    362                     } 
    363                 } 
    364  
    365                 var ac = document.getElementById('wifi_assoc_table'); 
    366                 if (ac) 
    367                 { 
    368                     /* clear all rows */ 
    369                     while( ac.rows.length > 1 ) 
    370                         ac.rows[0].parentNode.deleteRow(1); 
    371  
    372                     assoclist.sort(function(a, b) { 
    373                         return (a.name == b.name) 
    374                             ? (a.bssid < b.bssid) 
    375                             : (a.name  > b.name ) 
    376                         ; 
    377                     }); 
    378  
    379                     for( var i = 0; i < assoclist.length; i++ ) 
    380                     { 
    381                         var tr = ac.rows[0].parentNode.insertRow(-1); 
    382                             tr.className = 'cbi-section-table-row cbi-rowstyle-' + (1 + (i % 2)); 
     292                        var net = dev.networks[nidx]; 
     293                        var is_assoc = (net.bssid != '00:00:00:00:00:00' && net.channel); 
    383294 
    384295                        var icon; 
    385                         var q = (-1 * (assoclist[i].noise - assoclist[i].signal)) / 5; 
    386                         if (q < 1) 
     296                        if (!is_assoc) 
     297                            icon = "<%=resource%>/icons/signal-none.png"; 
     298                        else if (net.quality == 0) 
    387299                            icon = "<%=resource%>/icons/signal-0.png"; 
    388                         else if (q < 2) 
     300                        else if (net.quality < 25) 
    389301                            icon = "<%=resource%>/icons/signal-0-25.png"; 
    390                         else if (q < 3) 
     302                        else if (net.quality < 50) 
    391303                            icon = "<%=resource%>/icons/signal-25-50.png"; 
    392                         else if (q < 4) 
     304                        else if (net.quality < 75) 
    393305                            icon = "<%=resource%>/icons/signal-50-75.png"; 
    394306                        else 
    395307                            icon = "<%=resource%>/icons/signal-75-100.png"; 
    396308 
    397                         tr.insertCell(-1).innerHTML = String.format( 
    398                             '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />', 
    399                             icon, assoclist[i].signal, assoclist[i].noise 
     309                        s += String.format( 
     310                            '<table><tr><td style="text-align:center; width:32px; padding:3px">' + 
     311                                '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />' + 
     312                                '<br /><small>%d%%</small>' + 
     313                            '</td><td style="text-align:left; padding:3px"><small>' + 
     314                                '<strong><%:SSID%>:</strong> <a href="%s">%h</a><br />' + 
     315                                '<strong><%:Mode%>:</strong> %s<br />' + 
     316                                '<strong><%:Channel%>:</strong> %d (%.2f GHz)<br />' + 
     317                                '<strong><%:Bitrate%>:</strong> %s Mb/s<br />', 
     318                                icon, net.signal, net.noise, 
     319                                net.quality, 
     320                                net.link, net.ssid, 
     321                                net.mode, 
     322                                net.channel, net.frequency, 
     323                                net.bitrate || '?' 
    400324                        ); 
    401325 
    402                         tr.insertCell(-1).innerHTML = assoclist[i].bssid; 
    403  
    404                         tr.insertCell(-1).innerHTML = String.format( 
    405                             '<a href="%s">%h</a>', 
    406                                 assoclist[i].link, 
    407                                 assoclist[i].name 
    408                         ); 
    409  
    410                         tr.insertCell(-1).innerHTML = String.format('%d dBm', assoclist[i].signal); 
    411                         tr.insertCell(-1).innerHTML = String.format('%d dBm', assoclist[i].noise); 
     326                        if (is_assoc) 
     327                        { 
     328                            s += String.format( 
     329                                '<strong><%:BSSID%>:</strong> %s<br />' + 
     330                                '<strong><%:Encryption%>:</strong> %s', 
     331                                    net.bssid, 
     332                                    net.encryption 
     333                            ); 
     334                        } 
     335                        else 
     336                        { 
     337                            s += '<em><%:Wireless is disabled or not associated%></em>'; 
     338                        } 
     339 
     340                        s += '</small></td></tr></table>'; 
     341 
     342                        for (var bssid in net.assoclist) 
     343                        { 
     344                            assoclist.push({ 
     345                                bssid:  bssid, 
     346                                signal: net.assoclist[bssid].signal, 
     347                                noise:  net.assoclist[bssid].noise, 
     348                                link:   net.link, 
     349                                name:   net.name 
     350                            }); 
     351                        } 
    412352                    } 
    413353 
    414                     if (ac.rows.length == 1) 
    415                     { 
    416                         var tr = ac.rows[0].parentNode.insertRow(-1); 
    417                             tr.className = 'cbi-section-table-row'; 
    418  
    419                         var td = tr.insertCell(-1); 
    420                             td.colSpan = 5; 
    421                             td.innerHTML = '<br /><em><%:No information available%></em>'; 
    422                     } 
    423                 } 
    424                 <% end %> 
    425  
    426                 var e; 
    427  
    428                 if (e = document.getElementById('localtime')) 
    429                     e.innerHTML = info.localtime; 
    430  
    431                 if (e = document.getElementById('uptime')) 
    432                     e.innerHTML = String.format('%t', info.uptime); 
    433  
    434                 if (e = document.getElementById('loadavg')) 
    435                     e.innerHTML = String.format('%.02f, %.02f, %.02f', 
    436                         info.loadavg[0], info.loadavg[1], info.loadavg[2]); 
    437  
    438                 if (e = document.getElementById('memtotal')) 
    439                     e.innerHTML = progressbar( 
    440                         (info.memfree + info.membuffers + info.memcached) + " kB", 
    441                         info.memtotal + " kB" 
    442                     ); 
    443  
    444                 if (e = document.getElementById('memfree')) 
    445                     e.innerHTML = progressbar( 
    446                         info.memfree + " kB", info.memtotal + " kB" 
    447                     ); 
    448  
    449                 if (e = document.getElementById('memcache')) 
    450                     e.innerHTML = progressbar( 
    451                         info.memcached + " kB", info.memtotal + " kB" 
    452                     ); 
    453  
    454                 if (e = document.getElementById('membuff')) 
    455                     e.innerHTML = progressbar( 
    456                         info.membuffers + " kB", info.memtotal + " kB" 
    457                     ); 
    458  
    459                 if (e = document.getElementById('conns')) 
    460                     e.innerHTML = progressbar(info.conncount, info.connmax); 
    461  
    462                 window.setTimeout(func, 5000); 
    463             } 
    464         ) 
    465     })(); 
     354                    if (!s) 
     355                        s = '<em><%:No information available%></em>'; 
     356 
     357                    td.innerHTML = s; 
     358                } 
     359            } 
     360 
     361            var ac = document.getElementById('wifi_assoc_table'); 
     362            if (ac) 
     363            { 
     364                /* clear all rows */ 
     365                while( ac.rows.length > 1 ) 
     366                    ac.rows[0].parentNode.deleteRow(1); 
     367 
     368                assoclist.sort(function(a, b) { 
     369                    return (a.name == b.name) 
     370                        ? (a.bssid < b.bssid) 
     371                        : (a.name  > b.name ) 
     372                    ; 
     373                }); 
     374 
     375                for( var i = 0; i < assoclist.length; i++ ) 
     376                { 
     377                    var tr = ac.rows[0].parentNode.insertRow(-1); 
     378                        tr.className = 'cbi-section-table-row cbi-rowstyle-' + (1 + (i % 2)); 
     379 
     380                    var icon; 
     381                    var q = (-1 * (assoclist[i].noise - assoclist[i].signal)) / 5; 
     382                    if (q < 1) 
     383                        icon = "<%=resource%>/icons/signal-0.png"; 
     384                    else if (q < 2) 
     385                        icon = "<%=resource%>/icons/signal-0-25.png"; 
     386                    else if (q < 3) 
     387                        icon = "<%=resource%>/icons/signal-25-50.png"; 
     388                    else if (q < 4) 
     389                        icon = "<%=resource%>/icons/signal-50-75.png"; 
     390                    else 
     391                        icon = "<%=resource%>/icons/signal-75-100.png"; 
     392 
     393                    tr.insertCell(-1).innerHTML = String.format( 
     394                        '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />', 
     395                        icon, assoclist[i].signal, assoclist[i].noise 
     396                    ); 
     397 
     398                    tr.insertCell(-1).innerHTML = assoclist[i].bssid; 
     399 
     400                    tr.insertCell(-1).innerHTML = String.format( 
     401                        '<a href="%s">%h</a>', 
     402                            assoclist[i].link, 
     403                            assoclist[i].name 
     404                    ); 
     405 
     406                    tr.insertCell(-1).innerHTML = String.format('%d dBm', assoclist[i].signal); 
     407                    tr.insertCell(-1).innerHTML = String.format('%d dBm', assoclist[i].noise); 
     408                } 
     409 
     410                if (ac.rows.length == 1) 
     411                { 
     412                    var tr = ac.rows[0].parentNode.insertRow(-1); 
     413                        tr.className = 'cbi-section-table-row'; 
     414 
     415                    var td = tr.insertCell(-1); 
     416                        td.colSpan = 5; 
     417                        td.innerHTML = '<br /><em><%:No information available%></em>'; 
     418                } 
     419            } 
     420            <% end %> 
     421 
     422            var e; 
     423 
     424            if (e = document.getElementById('localtime')) 
     425                e.innerHTML = info.localtime; 
     426 
     427            if (e = document.getElementById('uptime')) 
     428                e.innerHTML = String.format('%t', info.uptime); 
     429 
     430            if (e = document.getElementById('loadavg')) 
     431                e.innerHTML = String.format('%.02f, %.02f, %.02f', 
     432                    info.loadavg[0], info.loadavg[1], info.loadavg[2]); 
     433 
     434            if (e = document.getElementById('memtotal')) 
     435                e.innerHTML = progressbar( 
     436                    (info.memfree + info.membuffers + info.memcached) + " kB", 
     437                    info.memtotal + " kB" 
     438                ); 
     439 
     440            if (e = document.getElementById('memfree')) 
     441                e.innerHTML = progressbar( 
     442                    info.memfree + " kB", info.memtotal + " kB" 
     443                ); 
     444 
     445            if (e = document.getElementById('memcache')) 
     446                e.innerHTML = progressbar( 
     447                    info.memcached + " kB", info.memtotal + " kB" 
     448                ); 
     449 
     450            if (e = document.getElementById('membuff')) 
     451                e.innerHTML = progressbar( 
     452                    info.membuffers + " kB", info.memtotal + " kB" 
     453                ); 
     454 
     455            if (e = document.getElementById('conns')) 
     456                e.innerHTML = progressbar(info.conncount, info.connmax); 
     457 
     458        } 
     459    ); 
    466460//]]></script> 
    467461