mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-20 03:16:12 +00:00
dashboard: add ability for user to hide interfaces in list and stats widgets
PR: https://github.com/opnsense/core/pull/2649
This commit is contained in:
parent
d20c0fbcce
commit
f0e9bbe796
@ -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':
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<script>
|
||||
@ -67,11 +85,31 @@ require_once("interfaces.inc");
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<div id="interface_list-settings" class="widgetconfigdiv" style="display:none;">
|
||||
<form action="/widgets/widgets/interface_list.widget.php" method="post" name="iformd">
|
||||
<table class="table table-condensed">
|
||||
<tr>
|
||||
<td>
|
||||
<select id="interfaceslistfilter" name="interfaceslistfilter[]" multiple="multiple" XXXclass="selectpicker" title="<?= html_safe(gettext('All')) ?>">
|
||||
<?php foreach ($interfaces as $iface => $ifacename): ?>
|
||||
<option value="<?= html_safe($iface) ?>" <?= in_array($iface, $pconfig['interfaceslistfilter']) ? 'selected="selected"' : '' ?>><?= html_safe($ifacename) ?></option>
|
||||
<?php endforeach;?>
|
||||
</select>
|
||||
<input id="submitd" name="submitd" type="submit" class="btn btn-primary" value="<?=gettext("Save");?>" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<table class="table table-striped table-condensed" data-plugin="interfaces" data-callback="interface_widget_update">
|
||||
<tbody>
|
||||
<?php
|
||||
$ifsinfo = get_interfaces_info();
|
||||
foreach (get_configured_interface_with_descr() as $ifdescr => $ifname):
|
||||
foreach ($interfaces as $ifdescr => $ifname):
|
||||
if (!count($pconfig['interfaceslistfilter']) || in_array($ifdescr, $pconfig['interfaceslistfilter'])):?>
|
||||
<?php
|
||||
$ifinfo = $ifsinfo[$ifdescr];
|
||||
$iswireless = is_interface_wireless($ifdescr);?>
|
||||
<tr id="interface_widget_item_<?=$ifname;?>">
|
||||
@ -134,6 +172,14 @@ require_once("interfaces.inc");
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
endif;
|
||||
endforeach;?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<!-- needed to display the widget settings menu -->
|
||||
<script>
|
||||
//<![CDATA[
|
||||
$("#interface_list-configure").removeClass("disabled");
|
||||
//]]>
|
||||
</script>
|
||||
|
||||
@ -1,34 +1,67 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Copyright (C) 2014-2016 Deciso B.V.
|
||||
Copyright (C) 2007 Scott Dale
|
||||
Copyright (C) 2004-2005 T. Lechat <dev@lechat.org>
|
||||
Copyright (C) 2004-2005 Manuel Kasper <mk@neon1.net>
|
||||
Copyright (C) 2004-2005 Jonathan Watt <jwatt@jwatt.org>.
|
||||
All rights reserved.
|
||||
* Copyright (C) 2014-2016 Deciso B.V.
|
||||
* Copyright (C) 2007 Scott Dale
|
||||
* Copyright (C) 2004-2005 T. Lechat <dev@lechat.org>
|
||||
* Copyright (C) 2004-2005 Manuel Kasper <mk@neon1.net>
|
||||
* Copyright (C) 2004-2005 Jonathan Watt <jwatt@jwatt.org>.
|
||||
* 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.
|
||||
*/
|
||||
?>
|
||||
|
||||
<script>
|
||||
@ -37,40 +70,63 @@
|
||||
*/
|
||||
function interface_statistics_widget_update(sender, data)
|
||||
{
|
||||
var tbody = sender.find('tbody');
|
||||
var thead = sender.find('thead');
|
||||
data.map(function(interface_data) {
|
||||
var th_id = "interface_statistics_widget_intf_" + interface_data['name'];
|
||||
if (thead.find("#"+th_id).length == 0) {
|
||||
thead.find('tr:eq(0)').append('<th id="'+th_id+'">'+interface_data['name']+'</th>');
|
||||
tbody.find('tr').append('<td></td>')
|
||||
}
|
||||
// fill in stats, use column index to determine td location
|
||||
var item_index = $("#"+th_id).index();
|
||||
$("#interface_statistics_widget_pkg_in > td:eq("+item_index+")").html(interface_data['inpkts']);
|
||||
$("#interface_statistics_widget_pkg_out > td:eq("+item_index+")").html(interface_data['outpkts']);
|
||||
$("#interface_statistics_widget_bytes_in > td:eq("+item_index+")").html(interface_data['inbytes_frmt']);
|
||||
$("#interface_statistics_widget_bytes_out > td:eq("+item_index+")").html(interface_data['outbytes_frmt']);
|
||||
$("#interface_statistics_widget_errors_in > td:eq("+item_index+")").html(interface_data['inerrs']);
|
||||
$("#interface_statistics_widget_errors_out > td:eq("+item_index+")").html(interface_data['outerrs']);
|
||||
$("#interface_statistics_widget_collisions > td:eq("+item_index+")").html(interface_data['collisions']);
|
||||
var item_index = $("#interface_statistics_widget_intf_" + interface_data['descr']).index();
|
||||
if (item_index != -1) {
|
||||
$("#interface_statistics_widget_val_pkg_in > td:eq("+item_index+")").html(interface_data['inpkts']);
|
||||
$("#interface_statistics_widget_val_pkg_out > td:eq("+item_index+")").html(interface_data['outpkts']);
|
||||
$("#interface_statistics_widget_val_bytes_in > td:eq("+item_index+")").html(interface_data['inbytes_frmt']);
|
||||
$("#interface_statistics_widget_val_bytes_out > td:eq("+item_index+")").html(interface_data['outbytes_frmt']);
|
||||
$("#interface_statistics_widget_val_errors_in > td:eq("+item_index+")").html(interface_data['inerrs']);
|
||||
$("#interface_statistics_widget_val_errors_out > td:eq("+item_index+")").html(interface_data['outerrs']);
|
||||
$("#interface_statistics_widget_val_collisions > td:eq("+item_index+")").html(interface_data['collisions']);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<div id="interface_statistics-settings" class="widgetconfigdiv" style="display:none;">
|
||||
<form action="/widgets/widgets/interface_statistics.widget.php" method="post" name="iformd">
|
||||
<table class="table table-condensed">
|
||||
<tr>
|
||||
<td>
|
||||
<select id="interfacesstatisticsfilter" name="interfacesstatisticsfilter[]" multiple="multiple" XXXclass="selectpicker" title="<?= html_safe(gettext('All')) ?>">
|
||||
<?php foreach ($interfaces as $iface => $ifacename): ?>
|
||||
<option value="<?= html_safe($iface) ?>" <?= in_array($iface, $pconfig['interfacesstatisticsfilter']) ? 'selected="selected"' : '' ?>><?= html_safe($ifacename) ?></option>
|
||||
<?php endforeach;?>
|
||||
</select>
|
||||
<input id="submitd" name="submitd" type="submit" class="btn btn-primary" value="<?=gettext("Save");?>" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<table class="table table-striped table-condensed" data-plugin="interfaces" data-callback="interface_statistics_widget_update">
|
||||
<thead>
|
||||
<tr>
|
||||
<th> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr id="interface_statistics_widget_pkg_in"><td><strong><?=gettext('Packets In');?></strong></td></tr>
|
||||
<tr id="interface_statistics_widget_pkg_out"><td><strong><?=gettext('Packets Out');?></strong></td></tr>
|
||||
<tr id="interface_statistics_widget_bytes_in"><td><strong><?=gettext('Bytes In');?></strong></td></tr>
|
||||
<tr id="interface_statistics_widget_bytes_out"><td><strong><?=gettext('Bytes Out');?></strong></td></tr>
|
||||
<tr id="interface_statistics_widget_errors_in"><td><strong><?=gettext('Errors In');?></strong></td></tr>
|
||||
<tr id="interface_statistics_widget_errors_out"><td><strong><?=gettext('Errors Out');?></strong></td></tr>
|
||||
<tr id="interface_statistics_widget_collisions"><td><strong><?=gettext('Collisions');?></strong></td></tr>
|
||||
</tbody>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<?php
|
||||
foreach ($interfaces as $ifdescr => $ifname):
|
||||
if (!count($pconfig['interfacesstatisticsfilter']) || in_array($ifdescr, $pconfig['interfacesstatisticsfilter'])):?>
|
||||
<th id="interface_statistics_widget_intf_<?= html_safe($ifdescr) ?>"><?= $ifname ?></th>
|
||||
<?php endif; endforeach ?>
|
||||
</tr>
|
||||
<?php
|
||||
foreach ($ifvalues as $ifkey => $iflabel): ?>
|
||||
<tr id="interface_statistics_widget_val_<?= html_safe($ifkey) ?>">
|
||||
<td><strong><?= $iflabel ?></strong></td>
|
||||
<?php foreach ($interfaces as $ifdescr => $ifname):
|
||||
if (!count($pconfig['interfacesstatisticsfilter']) || in_array($ifdescr, $pconfig['interfacesstatisticsfilter'])):?>
|
||||
<td>~</td>
|
||||
<?php endif; endforeach ?>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</table>
|
||||
|
||||
<!-- needed to display the widget settings menu -->
|
||||
<script>
|
||||
//<![CDATA[
|
||||
$("#interface_statistics-configure").removeClass("disabled");
|
||||
//]]>
|
||||
</script>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user