Changeset 6406

Show
Ignore:
Timestamp:
11/08/10 22:51:24 (3 years ago)
Author:
jow
Message:

modules/admin-full: live status for wifi overview page

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

Legend:

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

    r6351 r6406  
    7373    end 
    7474 
    75     function guess_wifi_signal(scale) 
    76         local icon 
    77  
    78         if scale < 0 then 
    79             icon = resource .. "/icons/signal-none.png" 
    80         elseif scale < 1 then 
    81             icon = resource .. "/icons/signal-0.png" 
    82         elseif scale < 2 then 
    83             icon = resource .. "/icons/signal-0-25.png" 
    84         elseif scale < 3 then 
    85             icon = resource .. "/icons/signal-25-50.png" 
    86         elseif scale < 4 then 
    87             icon = resource .. "/icons/signal-50-75.png" 
    88         else 
    89             icon = resource .. "/icons/signal-75-100.png" 
    90         end 
    91  
    92         return icon 
    93     end 
    94  
    9575    local devices  = ntm:get_wifidevs() 
    9676    local arpcache = { } 
    97     sys.net.arptable(function(e) arpcache[e["HW address"]] = e["IP address"] end) 
     77    sys.net.arptable(function(e) arpcache[e["HW address"]:upper()] = e["IP address"] end) 
     78 
     79    local netlist = { } 
     80    local netdevs = { } 
     81 
     82    local dev 
     83    for _, dev in ipairs(devices) do 
     84        local net 
     85        for _, net in ipairs(dev:get_wifinets()) do 
     86            netlist[#netlist+1] = net:ifname() 
     87            netdevs[net:ifname()] = dev:name() 
     88        end 
     89    end 
    9890-%> 
    9991 
    10092<%+header%> 
     93 
     94<script type="text/javascript" src="<%=resource%>/cbi.js"></script> 
     95<script type="text/javascript"><![CDATA[ 
     96    var iwxhr = new XHR(); 
     97    var wifidevs = <%=luci.http.write_json(netdevs)%>; 
     98    var arptable = <%=luci.http.write_json(arpcache)%>; 
     99 
     100    (function() { 
     101        iwxhr.get('<%=luci.dispatcher.build_url("admin", "network", "wireless_status", table.concat(netlist, ","))%>', null, 
     102            function(x) 
     103            { 
     104                var st = x.responseText ? eval('(' + x.responseText + ')') : null; 
     105                if (st) 
     106                { 
     107                    var assoctable = document.getElementById('iw-assoclist'); 
     108                    if (assoctable) 
     109                        while (assoctable.rows.length > 1) 
     110                            assoctable.rows[1].parentNode.removeChild(assoctable.rows[1]); 
     111 
     112                    for( var i = 0; i < st.length; i++ ) 
     113                    { 
     114                        var iw = st[i]; 
     115                        var p = (100 / iw.quality_max * iw.quality); 
     116                        var q = (iw.bssid && iw.channel) ? p : -1; 
     117 
     118                        var icon; 
     119                        if (q < 0) 
     120                            icon = "<%=resource%>/icons/signal-none.png"; 
     121                        else if (q == 0) 
     122                            icon = "<%=resource%>/icons/signal-0.png"; 
     123                        else if (q < 25) 
     124                            icon = "<%=resource%>/icons/signal-0-25.png"; 
     125                        else if (q < 50) 
     126                            icon = "<%=resource%>/icons/signal-25-50.png"; 
     127                        else if (q < 75) 
     128                            icon = "<%=resource%>/icons/signal-50-75.png"; 
     129                        else 
     130                            icon = "<%=resource%>/icons/signal-75-100.png"; 
     131 
     132                        var sig = document.getElementById(iw.id + '-iw-signal'); 
     133                        if (sig) 
     134                            sig.innerHTML = String.format( 
     135                                '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" /><br />' + 
     136                                '<small>%d%%</small>', icon, iw.signal, iw.noise, p 
     137                            ); 
     138 
     139                        var info = document.getElementById(iw.id + '-iw-status'); 
     140                        if (info) 
     141                            info.innerHTML = String.format( 
     142                                '<strong><%:SSID%>:</strong> %s | ' + 
     143                                '<strong><%:Mode%>:</strong> %s<br />' + 
     144                                '<strong><%:BSSID%>:</strong> %s | ' + 
     145                                '<strong><%:Encryption%>:</strong> %s', 
     146                                    iw.ssid, iw.mode, iw.bssid, 
     147                                    iw.encryption ? iw.encryption.description : '<%:None%>' 
     148                            ); 
     149 
     150                        var dev = document.getElementById(wifidevs[iw.id] + '-iw-devinfo'); 
     151                        if (dev) 
     152                            dev.innerHTML = String.format( 
     153                                '<strong><%:Channel%>:</strong> %s (%s GHz) | ' + 
     154                                '<strong><%:Bitrate%>:</strong> %s Mb/s', 
     155                                    iw.channel ? iw.channel : '?', 
     156                                    iw.frequency ? iw.frequency / 1000 : '?', 
     157                                    iw.bitrate ? iw.bitrate / 1000 : '?' 
     158                            ); 
     159 
     160                        if (assoctable) 
     161                        { 
     162                            var assoclist = [ ]; 
     163                            for( var bssid in iw.assoclist ) 
     164                            { 
     165                                assoclist.push(iw.assoclist[bssid]); 
     166                                assoclist[assoclist.length-1].bssid = bssid; 
     167                            } 
     168 
     169                            assoclist.sort(function(a, b) { a.bssid < b.bssid }); 
     170 
     171                            for( var j = 0; j < assoclist.length; j++ ) 
     172                            { 
     173                                var tr = document.createElement('tr'); 
     174                                    tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((j % 2) + (i % 2)); 
     175 
     176                                var icon; 
     177                                var q = (-1 * (assoclist[j].noise - assoclist[j].signal)) / 5; 
     178                                if (q < 1) 
     179                                    icon = "<%=resource%>/icons/signal-0.png"; 
     180                                else if (q < 2) 
     181                                    icon = "<%=resource%>/icons/signal-0-25.png"; 
     182                                else if (q < 3) 
     183                                    icon = "<%=resource%>/icons/signal-25-50.png"; 
     184                                else if (q < 4) 
     185                                    icon = "<%=resource%>/icons/signal-50-75.png"; 
     186                                else 
     187                                    icon = "<%=resource%>/icons/signal-75-100.png"; 
     188 
     189                                tr.innerHTML = String.format( 
     190                                    '<td class="cbi-value-field">' + 
     191                                        '<img src="%s" title="<%:Signal%>: %d dBm / <%:Noise%>: %d dBm" />' + 
     192                                    '</td>' + 
     193                                    '<td class="cbi-value-field">%s</td>' + 
     194                                    '<td class="cbi-value-field">%s</td>' + 
     195                                    '<td class="cbi-value-field">%s</td>' + 
     196                                    '<td class="cbi-value-field">%d dBm</td>' + 
     197                                    '<td class="cbi-value-field">%d dBm</td>', 
     198                                        icon, 
     199                                        assoclist[j].signal, assoclist[j].noise, 
     200                                        iw.ssid ? iw.ssid : '?', 
     201                                        assoclist[j].bssid, 
     202                                        arptable[assoclist[j].bssid] 
     203                                            ? arptable[assoclist[j].bssid] : '?', 
     204                                        assoclist[j].signal, assoclist[j].noise 
     205                                ); 
     206 
     207                                assoctable.rows[0].parentNode.appendChild(tr); 
     208                            } 
     209                        } 
     210                    } 
     211 
     212                    if (assoctable && assoctable.rows.length == 1) 
     213                    { 
     214                        var tr = document.createElement('tr'); 
     215                            tr.className = 'cbi-section-table-row'; 
     216 
     217                        tr.innerHTML = '<td class="cbi-value-field" colspan="6"><br /><em><%:No information available%></em></td>'; 
     218 
     219                        assoctable.rows[0].parentNode.appendChild(tr); 
     220                    } 
     221                } 
     222            } 
     223        ) 
     224 
     225        window.setTimeout(arguments.callee, 5000); 
     226    })(); 
     227]]></script> 
    101228 
    102229<h2><a id="content" name="content"><%:Wireless Overview%></a></h2> 
     
    113240                <td colspan="2" style="text-align:left"> 
    114241                    <big><strong><%=guess_wifi_hw(dev:name())%> (<%=dev:name()%>)</strong></big><br /> 
    115                     <% if nets[1] then %> 
    116                         <strong>Channel:</strong> <%=nets[1]:channel() or "?"%> (<%=nets[1]:frequency() or "?"%> GHz) | 
    117                         <strong>Bitrate:</strong> <%=nets[1]:bitrate() or "?"%> Mb/s 
    118                     <% end %> 
     242                    <span id="<%=dev:name()%>-iw-devinfo"></span> 
    119243                </td> 
    120244                <td style="width:40px"> 
     
    130254                <tr class="cbi-section-table-row cbi-rowstyle-<%=1 + ((i-1) % 2)%>"> 
    131255                    <td></td> 
    132                     <td class="cbi-value-field" style="width:16px; padding:3px"> 
    133                         <img src="<%=guess_wifi_signal(net:signal_level())%>" title="Signal: <%=net:signal()%> dBm / Noise: <%=net:noise()%> dBm" /><br /> 
    134                         <small><%=net:signal_percent()%>%</small> 
     256                    <td class="cbi-value-field" style="width:16px; padding:3px" id="<%=net:ifname()%>-iw-signal"> 
     257                        <img src="<%=resource%>/icons/signal-none.png" title="<%:Not associated%>" /><br /> 
     258                        <small>0%</small> 
    135259                    </td> 
    136                     <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px"> 
    137                         <strong>SSID:</strong> <%=utl.pcdata(net:active_ssid())%> | 
    138                         <strong>Mode:</strong> <%=net:active_mode_i18n()%><br /> 
    139                         <strong>BSSID:</strong> <%=net:active_bssid()%> | 
    140                         <strong>Encryption:</strong> <%=net:active_encryption()%> 
     260                    <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px" id="<%=net:ifname()%>-iw-status"> 
     261                        <em><%:Collecting data...%></em> 
    141262                    </td> 
    142263                    <td class="cbi-value-field" style="width:40px"> 
     
    161282 
    162283 
    163  
    164  
    165284    <h2><a id="content" name="content"><%:Associated Stations%></a></h2> 
    166285 
    167286    <fieldset class="cbi-section"> 
    168         <table class="cbi-section-table" style="margin:10px; width:50%"> 
     287        <table class="cbi-section-table" style="margin:10px; width:50%" id="iw-assoclist"> 
    169288            <tr class="cbi-section-table-titles"> 
    170289                <th class="cbi-section-table-cell"></th> 
    171                 <th class="cbi-section-table-cell">SSID</th> 
    172                 <th class="cbi-section-table-cell">MAC</th> 
    173                 <th class="cbi-section-table-cell">Address</th> 
    174                 <th class="cbi-section-table-cell">Signal</th> 
    175                 <th class="cbi-section-table-cell">Noise</th> 
     290                <th class="cbi-section-table-cell"><%:SSID%></th> 
     291                <th class="cbi-section-table-cell"><%:MAC%></th> 
     292                <th class="cbi-section-table-cell"><%:Address%></th> 
     293                <th class="cbi-section-table-cell"><%:Signal%></th> 
     294                <th class="cbi-section-table-cell"><%:Noise%></th> 
    176295            </tr> 
    177  
    178             <% local count = -1 %> 
    179             <% for _, dev in ipairs(devices) do local nets = dev:get_wifinets() %> 
    180                 <% for _, net in ipairs(nets) do %> 
    181                     <% for mac, info in utl.kspairs(net:assoclist()) do count = count + 1 %> 
    182                     <tr class="cbi-section-table-row cbi-rowstyle-<%=1 + (count % 2)%>"> 
    183                         <td class="cbi-value-field"><img src="<%=guess_wifi_signal(net:signal_level(info.signal, info.noise))%>" title="Signal: <%=info.signal%> dBm / Noise: <%=info.noise%> dBm" /></td> 
    184                         <td class="cbi-value-field"><%=net:active_ssid()%></td> 
    185                         <td class="cbi-value-field"><%=mac%></td> 
    186                         <td class="cbi-value-field"><%=arpcache[mac:lower()] or "n/a"%></td> 
    187                         <td class="cbi-value-field"><%=info.signal%> dBm</td> 
    188                         <td class="cbi-value-field"><%=info.noise%> dBm</td> 
    189                     </tr> 
    190                     <% end %> 
    191                 <% end %> 
    192             <% end %> 
    193             <% if count < 0 then %> 
    194296            <tr class="cbi-section-table-row cbi-rowstyle-2"> 
    195297                <td class="cbi-value-field" colspan="6"> 
    196                     <em>No information available</em> 
     298                    <em><%:Collecting data...%></em> 
    197299                </td> 
    198300            </tr> 
    199             <% end %> 
    200301        </table> 
    201302    </fieldset> 
  • luci/trunk/modules/admin-full/luasrc/view/admin_network/wifi_status.htm

    r6351 r6406  
    3131                    if (s) 
    3232                        s.innerHTML = String.format( 
    33                             '<img src="%s" title="Signal: %d dBm / Noise: %d dBm" /><br />' + 
     33                            '<img src="%s" title="<%:Signal%>: %d dBm / <%Noise%>: %d dBm" /><br />' + 
    3434                            '<small>%d%%</small>', icon, iw.signal, iw.noise, p 
    3535                        );