From f0e9bbe796ac7c32c2c8a9c619f7b2ab5946537b Mon Sep 17 00:00:00 2001 From: marjohn56 Date: Sun, 19 Aug 2018 09:59:09 +0100 Subject: [PATCH] dashboard: add ability for user to hide interfaces in list and stats widgets PR: https://github.com/opnsense/core/pull/2649 --- src/www/widgets/api/plugins/interfaces.inc | 1 + .../widgets/widgets/interface_list.widget.php | 48 +++++- .../widgets/interface_statistics.widget.php | 162 ++++++++++++------ 3 files changed, 157 insertions(+), 54 deletions(-) diff --git a/src/www/widgets/api/plugins/interfaces.inc b/src/www/widgets/api/plugins/interfaces.inc index 27c944e27..0de0a2bc5 100644 --- a/src/www/widgets/api/plugins/interfaces.inc +++ b/src/www/widgets/api/plugins/interfaces.inc @@ -46,6 +46,7 @@ function interfaces_api() $interfaceItem['inerrs'] = isset($ifinfo['inerrs']) ? $ifinfo['inerrs'] : "0"; $interfaceItem['outerrs'] = isset($ifinfo['outerrs']) ? $ifinfo['outerrs'] : "0"; $interfaceItem['collisions'] = isset($ifinfo['collisions']) ? $ifinfo['collisions'] : "0"; + $interfaceItem['descr'] = $ifdescr; $interfaceItem['name'] = $ifname; switch ($ifinfo['status']) { case 'down': diff --git a/src/www/widgets/widgets/interface_list.widget.php b/src/www/widgets/widgets/interface_list.widget.php index 851c41f5e..8541b3ae2 100644 --- a/src/www/widgets/widgets/interface_list.widget.php +++ b/src/www/widgets/widgets/interface_list.widget.php @@ -34,6 +34,24 @@ require_once("guiconfig.inc"); require_once("widgets/include/interface_list.inc"); require_once("interfaces.inc"); +$interfaces = get_configured_interface_with_descr(); + +if ($_SERVER['REQUEST_METHOD'] === 'GET') { + $pconfig = array(); + $pconfig['interfaceslistfilter'] = !empty($config['widgets']['interfaceslistfilter']) ? + explode(',', $config['widgets']['interfaceslistfilter']) : array(); +} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { + $pconfig = $_POST; + if (!empty($pconfig['interfaceslistfilter'])) { + $config['widgets']['interfaceslistfilter'] = implode(',', $pconfig['interfaceslistfilter']); + } elseif (isset($config['widgets']['interfaceslistfilter'])) { + unset($config['widgets']['interfaceslistfilter']); + } + write_config("Saved Interface List Filter via Dashboard"); + header(url_safe('Location: /index.php')); + exit; +} + ?> + + + $ifname): + foreach ($interfaces as $ifdescr => $ifname): + if (!count($pconfig['interfaceslistfilter']) || in_array($ifdescr, $pconfig['interfaceslistfilter'])):?> + @@ -134,6 +172,14 @@ require_once("interfaces.inc");
+ + + diff --git a/src/www/widgets/widgets/interface_statistics.widget.php b/src/www/widgets/widgets/interface_statistics.widget.php index 13c973d74..00011acd9 100644 --- a/src/www/widgets/widgets/interface_statistics.widget.php +++ b/src/www/widgets/widgets/interface_statistics.widget.php @@ -1,34 +1,67 @@ - Copyright (C) 2004-2005 Manuel Kasper - Copyright (C) 2004-2005 Jonathan Watt . - All rights reserved. + * Copyright (C) 2014-2016 Deciso B.V. + * Copyright (C) 2007 Scott Dale + * Copyright (C) 2004-2005 T. Lechat + * Copyright (C) 2004-2005 Manuel Kasper + * Copyright (C) 2004-2005 Jonathan Watt . + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: +require_once("guiconfig.inc"); +require_once("widgets/include/interface_list.inc"); +require_once("interfaces.inc"); - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. +$interfaces = get_configured_interface_with_descr(); - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. +if ($_SERVER['REQUEST_METHOD'] === 'GET') { + $pconfig = array(); + $pconfig['interfacesstatisticsfilter'] = !empty($config['widgets']['interfacesstatisticsfilter']) ? + explode(',', $config['widgets']['interfacesstatisticsfilter']) : array(); +} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { + $pconfig = $_POST; + if (!empty($pconfig['interfacesstatisticsfilter'])) { + $config['widgets']['interfacesstatisticsfilter'] = implode(',', $pconfig['interfacesstatisticsfilter']); + } elseif (isset($config['widgets']['interfacesstatisticsfilter'])) { + unset($config['widgets']['interfacesstatisticsfilter']); + } + write_config("Saved Interface Statistics Filter via Dashboard"); + header(url_safe('Location: /index.php')); + exit; +} + +$ifvalues = array( + 'pkg_in' => gettext('Packets In'), + 'pkg_out' => gettext('Packets Out'), + 'bytes_in' => gettext('Bytes In'), + 'bytes_out' => gettext('Bytes Out'), + 'errors_in' => gettext('Errors In'), + 'errors_out' => gettext('Errors Out'), + 'collisions' => gettext('Collisions'), +); - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. -*/ ?> + + - - - - - - - - - - - - - - + + + $ifname): + if (!count($pconfig['interfacesstatisticsfilter']) || in_array($ifdescr, $pconfig['interfacesstatisticsfilter'])):?> + + + + $iflabel): ?> + + + $ifname): + if (!count($pconfig['interfacesstatisticsfilter']) || in_array($ifdescr, $pconfig['interfacesstatisticsfilter'])):?> + + + +
 
 
~
+ + +