diff options
Diffstat (limited to 'src/usr/local/www/widgets/widgets/interface_statistics.widget.php')
-rw-r--r-- | src/usr/local/www/widgets/widgets/interface_statistics.widget.php | 84 |
1 files changed, 58 insertions, 26 deletions
diff --git a/src/usr/local/www/widgets/widgets/interface_statistics.widget.php b/src/usr/local/www/widgets/widgets/interface_statistics.widget.php index b5368fa..9f94951 100644 --- a/src/usr/local/www/widgets/widgets/interface_statistics.widget.php +++ b/src/usr/local/www/widgets/widgets/interface_statistics.widget.php @@ -81,15 +81,32 @@ if ($_REQUEST && $_REQUEST['ajax']) { ); $skipinterfaces = explode(",", $user_settings['widgets']['interface_statistics']['iffilter']); + $an_interface_is_selected = false; // decide if at least 1 interface is selected for display + $an_interface_is_displayed = false; // decide if at least 1 interface is displayed (i.e. not down) print("<thead>"); print( "<tr>"); print( "<th></th>"); foreach ($ifdescrs as $ifdescr => $ifname) { - if (!in_array($ifdescr, $skipinterfaces)) { - print( "<th>" . $ifname . "</th>"); + if (in_array($ifdescr, $skipinterfaces)) { + continue; } + + $an_interface_is_selected = true; + $ifinfo_arr[$ifdescr] = get_interface_info($ifdescr); + $ifinfo_arr[$ifdescr]['inbytes'] = format_bytes($ifinfo_arr[$ifdescr]['inbytes']); + $ifinfo_arr[$ifdescr]['outbytes'] = format_bytes($ifinfo_arr[$ifdescr]['outbytes']); + if ($ifinfo_arr[$ifdescr]['status'] != "down") { + $an_interface_is_displayed = true; + print("<th>" . $ifname . "</th>"); + } + } + + if (!$an_interface_is_selected) { + print("<th>" . gettext('All interfaces are hidden.') . "</th>"); + } else if (!$an_interface_is_displayed) { + print("<th>" . gettext('All selected interfaces are down.') . "</th>"); } print( "</tr>"); @@ -105,19 +122,12 @@ if ($_REQUEST && $_REQUEST['ajax']) { continue; } - $ifinfo = get_interface_info($ifdescr); - - if ($ifinfo['status'] == "down") { - continue; + if ($ifinfo_arr[$ifdescr]['status'] != "down") { + print("<td>" . (isset($ifinfo_arr[$ifdescr][$key]) ? htmlspecialchars($ifinfo_arr[$ifdescr][$key]) : 'n/a') . "</td>"); } - $ifinfo['inbytes'] = format_bytes($ifinfo['inbytes']); - $ifinfo['outbytes'] = format_bytes($ifinfo['outbytes']); - - print("<td>" . (isset($ifinfo[$key]) ? htmlspecialchars($ifinfo[$key]) : 'n/a') . "</td>"); } - print( "</td>"); print( "</tr>"); } print( "</tbody>"); @@ -133,7 +143,7 @@ if ($_REQUEST && $_REQUEST['ajax']) { if (is_array($_POST['show'])) { $user_settings['widgets']['interface_statistics']['iffilter'] = implode(',', array_diff($validNames, $_POST['show'])); } else { - $user_settings['widgets']['interface_statistics']['iffilter'] = ""; + $user_settings['widgets']['interface_statistics']['iffilter'] = implode(',', $validNames); } save_widget_settings($_SESSION['Username'], $user_settings["widgets"], gettext("Saved Interface Statistics Filter via Dashboard.")); @@ -191,35 +201,57 @@ $widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period <script type="text/javascript"> //<![CDATA[ - - function get_if_stats() { +/* + function get_if_stats_<?=$widgetkey_nodash?>() { var ajaxRequest; ajaxRequest = $.ajax({ url: "/widgets/widgets/interface_statistics.widget.php", type: "post", - data: { ajax: "ajax"} + data: { ajax: "ajax", widgetkey: "<?=$widgetkey?>"} }); // Deal with the results of the above ajax call ajaxRequest.done(function (response, textStatus, jqXHR) { - $('#iftbl').html(response); + $('#<?=$widgetkey?>-iftbl').html(response); // and do it again - setTimeout(get_if_stats, "<?=$widgetperiod?>"); + setTimeout(get_if_stats_<?=$widgetkey_nodash?>, "<?=$widgetperiod?>"); }); } +*/ + events.push(function() { + // --------------------- Centralized widget refresh system ------------------------------ - events.push(function(){ - $("#showallinterfacesforstats").click(function() { - $("#widget-<?=$widgetname?>_panel-footer [id^=show]").each(function() { - $(this).prop("checked", true); - }); - }); + // Callback function called by refresh system when data is retrieved + function interface_statistics_callback(s) { + $('#iftbl').html(s); + } + + // POST data to send via AJAX + var postdata = { + ajax : "ajax", + widgetkey :"<?=$widgetkey?>" + }; + + // Create an object defining the widget refresh AJAX call + var ifstatObject = new Object(); + ifstatObject.name = "IFstats"; + ifstatObject.url = "/widgets/widgets/interface_statistics.widget.php"; + ifstatObject.callback = interface_statistics_callback; + ifstatObject.parms = postdata; + ifstatObject.freq = 1; + + // Register the AJAX object + register_ajax(ifstatObject); + + // --------------------------------------------------------------------------------------------------- + // Note: This manages all settings checkboxes with id starting with "show" + // (i.e. both the interface and stats item selection groups) + // using a single All/None button + set_widget_checkbox_events("#widget-<?=$widgetname?>_panel-footer [id^=show]", "showallinterfacesforstats"); - // Start polling for updates some small random number of seconds from now (so that all the widgets don't - // hit the server at exactly the same time) - setTimeout(get_if_stats, Math.floor((Math.random() * 10000) + 1000)); }); //]]> </script> + |