<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="default.css">
    <title>Puavo's WLAN Controller - Status</title>
    <script src="autoreload.js"></script>
    <script src="sorttable.js"></script>
  </head>
  <body onload="checkAutoReload();">
    <h1>Status</h1>
    <input id="autoreload_checkbox" type="checkbox" onclick="toggleAutoReload();">
    <label for="autoreload_checkbox">Reload this page automatically every 5 seconds</label>
    <% unless hosts.empty? %>
    <h2>Hosts (<%= hosts.length %>)</h2>
    <table class="sortable">
      <thead>
        <tr>
          <th>Host</th>
          <th>Version</th>
          <th>System uptime</th>
          <th>Service uptime</th>
          <th>Load 5min</th>
          <th>PHYs</th>
          <th>APs</th>
          <th>STAs</th>
          <th>Rx rate</th>
          <th>Tx rate</th>
        </tr>
      </thead>
      <tbody>
        <% hosts.each do |host| %>
        <tr>
          <td><span class="statemark-<%= host[:state] %>"><%= host[:hostname] %></span></td>
          <td><%= host[:version] %></td>
          <td sorttable_customkey="<%= host[:system_uptime] %>"><%= prettify_seconds(host[:system_uptime]) %></td>
          <td sorttable_customkey="<%= host[:service_uptime] %>"><%= prettify_seconds(host[:service_uptime]) %></td>
          <td><%= host[:loadavg5] %></td>
          <td><%= host[:phy_count] %></td>
          <td><%= host[:ap_count] %></td>
          <td><%= host[:sta_count] %></td>
          <td sorttable_customkey="<%= host[:rx_rate] %>"><%= prettify_byterate(host[:rx_rate]) %></td>
          <td sorttable_customkey="<%= host[:tx_rate] %>"><%= prettify_byterate(host[:tx_rate]) %></td>
        </tr>
        <% end %>
      </tbody>
      <tfoot>
        <tr>
          <th colspan="5">Totals</th>
          <td><%= radios.length %></td>
          <td><%= accesspoints.length %></td>
          <td><%= stations.length %></td>
          <td><%= prettify_byterate(total_ap_rx_rate) %></td>
          <td><%= prettify_byterate(total_ap_tx_rate) %></td>
        </tr>
      </tfoot>
    </table>
    <% end %>

    <% unless radios.empty? %>
    <h2>Radios (<%= radios.length %>)</h2>
    <table class="sortable">
      <thead>
        <tr>
          <th>Host</th>
          <th>MAC</th>
          <th>Driver</th>
          <th>Vendor</th>
          <th>Channel</th>
          <th>Tx power</th>
          <th>APs</th>
          <th>STAs</th>
          <th>Rx rate</th>
          <th>Tx rate</th>
        </tr>
      </thead>
      <tbody>
        <% radios.each do |radio| %>
        <tr>
          <td><%= radio[:hostname] %></td>
          <td><%= radio[:mac] %></td>
          <td><%= radio[:driver] %></td>
          <td><%= radio[:vendor] %></td>
          <td><%= radio[:channel] %></td>
          <td sorttable_customkey="<%= radio[:tx_power] %>"><%= radio[:tx_power] %> dBm</td>
          <td><%= radio[:ap_count] %></td>
          <td><%= radio[:sta_count] %></td>
          <td sorttable_customkey="<%= radio[:rx_rate] %>"><%= prettify_byterate(radio[:rx_rate]) %></td>
          <td sorttable_customkey="<%= radio[:tx_rate] %>"><%= prettify_byterate(radio[:tx_rate]) %></td>
        </tr>
        <% end %>
      </tbody>
      <tfoot>
        <tr>
          <th colspan="6">Totals</th>
          <td><%= accesspoints.length %></td>
          <td><%= stations.length %></td>
          <td><%= prettify_byterate(total_ap_rx_rate) %></td>
          <td><%= prettify_byterate(total_ap_tx_rate) %></td>
        </tr>
      </tfoot>
    </table>
    <% end %>

    <% unless accesspoints.empty? %>
    <h2>Access points (<%= accesspoints.length %>)</h2>
    <table class="sortable">
      <thead>
        <tr>
          <th>Host</th>
          <th>BSSID</th>
          <th>Radio MAC</th>
          <th>SSID</th>
          <th>Uptime</th>
          <th>STAs</th>
          <th>Rx rate</th>
          <th>Tx rate</th>
        </tr>
      </thead>
      <tbody>
        <% accesspoints.each do |accesspoint| %>
        <tr>
          <td><%= accesspoint[:hostname] %></td>
          <td><%= accesspoint[:bssid] %></td>
          <td><%= accesspoint[:radio_mac] %></td>
          <td><%= accesspoint[:ssid] %></td>
          <td sorttable_customkey="<%= accesspoint[:uptime] %>"><%= prettify_seconds(accesspoint[:uptime]) %></td>
          <td><%= accesspoint[:sta_count] %></td>
          <td sorttable_customkey="<%= accesspoint[:rx_rate] %>"><%= prettify_byterate(accesspoint[:rx_rate]) %></td>
          <td sorttable_customkey="<%= accesspoint[:tx_rate] %>"><%= prettify_byterate(accesspoint[:tx_rate]) %></td>
        </tr>
        <% end %>
      </tbody>
      <tfoot>
        <tr>
          <th colspan="5">Totals</th>
          <td><%= stations.length %></td>
          <td><%= prettify_byterate(total_ap_rx_rate) %></td>
          <td><%= prettify_byterate(total_ap_tx_rate) %></td>
        </tr>
      </tfoot>
    </table>
    <% end %>

    <% unless stations.empty? %>
    <h2>Stations (<%= stations.length %>)</h2>
    <table class="sortable">
      <thead>
        <tr>
          <th>MAC</th>
          <th>Vendor</th>
          <th>AP host</th>
          <th>BSSID</th>
          <th>RSSI</th>
          <th>Uptime</th>
          <th>Rx rate</th>
          <th>Tx rate</th>
        </tr>
      </thead>
      <tbody>
        <% stations.each do |station| %>
        <tr>
          <td><%= station[:hostname] or station[:mac] %></td>
          <td><%= station[:vendor] %></td>
          <td><%= station[:ap_host] %></td>
          <td><%= station[:bssid] %></td>
          <td><%= station[:rssi] %></td>
          <td sorttable_customkey="<%= station[:uptime] %>"><%= prettify_seconds(station[:uptime]) %></td>
          <!-- Tx and Rx switched, because station's Rx is Access point's Tx. -->
          <td sorttable_customkey="<%= station[:tx_rate] %>"><%= prettify_byterate(station[:tx_rate]) %></td>
          <td sorttable_customkey="<%= station[:rx_rate] %>"><%= prettify_byterate(station[:rx_rate]) %></td>
        </tr>
        <% end %>
      </tbody>
      <tfoot>
        <tr>
          <th colspan="6">Totals</th>
          <!-- Tx and Rx switched, because station's Rx is Access point's Tx. -->
          <td><%= prettify_byterate(total_sta_tx_rate) %></td>
          <td><%= prettify_byterate(total_sta_rx_rate) %></td>
        </tr>
      </tfoot>
    </table>
    <% end %>
    <p id="timestamp"><%= Time.now %></p>
  </body>
</html>
