From d87a9a1c9720f2093b57979d1b0f1e69e38750af Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Sat, 29 Apr 2017 21:02:37 +0545 Subject: [PATCH 1/2] Fix interface down in interface statistics widget If an interface is down, the widget would write the interface description in a column heading but then omit the stats items. So later columns (to the right) would have the headings and stats items out of line. This also fixes the performance problem that get_interface_info($ifdescr) was being called for every row of stats data for every interface. i.e. it was called 7 times for each interface when 1 time is enough. --- .../widgets/interface_statistics.widget.php | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 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 7944b4b25d..ac1301a86d 100644 --- a/src/usr/local/www/widgets/widgets/interface_statistics.widget.php +++ b/src/usr/local/www/widgets/widgets/interface_statistics.widget.php @@ -56,9 +56,16 @@ if ($_REQUEST && $_REQUEST['ajax']) { print( ""); foreach ($ifdescrs as $ifdescr => $ifname) { - if (!in_array($ifdescr, $skipinterfaces)) { - print( "" . $ifname . ""); - $interface_is_displayed = true; + if (in_array($ifdescr, $skipinterfaces)) { + continue; + } + + $interface_is_displayed = 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") { + print("" . $ifname . ""); } } @@ -79,16 +86,10 @@ if ($_REQUEST && $_REQUEST['ajax']) { continue; } - $ifinfo = get_interface_info($ifdescr); - - if ($ifinfo['status'] == "down") { - continue; + if ($ifinfo_arr[$ifdescr]['status'] != "down") { + print("" . (isset($ifinfo_arr[$ifdescr][$key]) ? htmlspecialchars($ifinfo_arr[$ifdescr][$key]) : 'n/a') . ""); } - $ifinfo['inbytes'] = format_bytes($ifinfo['inbytes']); - $ifinfo['outbytes'] = format_bytes($ifinfo['outbytes']); - - print("" . (isset($ifinfo[$key]) ? htmlspecialchars($ifinfo[$key]) : 'n/a') . ""); } print( ""); From b22fceb2d7973b8c80a55b4ec492819ddd5ae9f9 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Sat, 29 Apr 2017 21:17:58 +0545 Subject: [PATCH 2/2] Let he user know if all selected interfaces are down in the interface statistics widget. At the moment, if all the selected interfaces are down, the widget will just display no columns. That will make users wonder what happened. --- .../widgets/widgets/interface_statistics.widget.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 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 ac1301a86d..cb3b4634cb 100644 --- a/src/usr/local/www/widgets/widgets/interface_statistics.widget.php +++ b/src/usr/local/www/widgets/widgets/interface_statistics.widget.php @@ -49,7 +49,8 @@ if ($_REQUEST && $_REQUEST['ajax']) { ); $skipinterfaces = explode(",", $user_settings['widgets'][$_REQUEST['widgetkey']]['iffilter']); - $interface_is_displayed = false; + $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(""); print( ""); @@ -60,17 +61,20 @@ if ($_REQUEST && $_REQUEST['ajax']) { continue; } - $interface_is_displayed = true; + $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("" . $ifname . ""); } } - if (!$interface_is_displayed) { + if (!$an_interface_is_selected) { print("" . gettext('All interfaces are hidden.') . ""); + } else if (!$an_interface_is_displayed) { + print("" . gettext('All selected interfaces are down.') . ""); } print( "");