filtering interfaces in wizard
This commit is contained in:
parent
63834c62a7
commit
9a439a96e5
|
@ -232,6 +232,17 @@ class AgentWizard extends HTML
|
|||
*/
|
||||
private $interfacesFound;
|
||||
|
||||
/**
|
||||
* Some useful information about interfaces:
|
||||
* `name` => [
|
||||
* operstatus
|
||||
* adminstatus
|
||||
* ]
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $interfacesData;
|
||||
|
||||
/**
|
||||
* X64 Interfaces
|
||||
*
|
||||
|
@ -2428,42 +2439,59 @@ class AgentWizard extends HTML
|
|||
'action' => $this->sectionUrl,
|
||||
'id' => 'form-filter-interfaces',
|
||||
'method' => 'POST',
|
||||
'class' => 'modal flex flex-row',
|
||||
'class' => 'modal flex flex-row searchbox',
|
||||
'extra' => '',
|
||||
];
|
||||
// Inputs.
|
||||
$inputs = [];
|
||||
|
||||
$inputs[] = [
|
||||
'direct' => 1,
|
||||
'class' => 'select-interfaces',
|
||||
'block_content' => [
|
||||
[
|
||||
'label' => __('Select all filtered interfaces'),
|
||||
'arguments' => [
|
||||
'name' => 'select-all-interfaces',
|
||||
'type' => 'switch',
|
||||
'class' => '',
|
||||
'return' => true,
|
||||
'value' => 1,
|
||||
'onclick' => 'switchBlockControlInterfaces(this);',
|
||||
// Inputs.
|
||||
$inputs = [
|
||||
[
|
||||
'direct' => 1,
|
||||
'class' => 'select-interfaces',
|
||||
'block_content' => [
|
||||
[
|
||||
'label' => __('Select all filtered interfaces'),
|
||||
'arguments' => [
|
||||
'name' => 'select-all-interfaces',
|
||||
'type' => 'switch',
|
||||
'class' => '',
|
||||
'return' => true,
|
||||
'value' => 1,
|
||||
'onclick' => 'switchBlockControlInterfaces(this);',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$inputs[] = [
|
||||
'direct' => 1,
|
||||
'block_content' => [
|
||||
[
|
||||
'label' => __('Search'),
|
||||
'id' => 'txt-filter-search',
|
||||
'arguments' => [
|
||||
'name' => 'filter-search',
|
||||
'type' => 'text',
|
||||
'class' => '',
|
||||
'return' => true,
|
||||
],
|
||||
[
|
||||
'label' => __('Search'),
|
||||
'id' => 'txt-filter-search',
|
||||
'class' => 'textbox',
|
||||
'arguments' => [
|
||||
'name' => 'filter-search',
|
||||
'type' => 'text',
|
||||
'return' => true,
|
||||
],
|
||||
],
|
||||
[
|
||||
'label' => __('OperStatus UP'),
|
||||
'arguments' => [
|
||||
'name' => 'search-oper',
|
||||
'type' => 'switch',
|
||||
'id' => 'search-oper',
|
||||
'onchange' => 'filterInterfaces()',
|
||||
'value' => 0,
|
||||
'return' => true,
|
||||
],
|
||||
],
|
||||
[
|
||||
'label' => __('AdminStatus UP'),
|
||||
'arguments' => [
|
||||
'name' => 'search-admin',
|
||||
'type' => 'switch',
|
||||
'id' => 'search-admin',
|
||||
'onchange' => 'filterInterfaces()',
|
||||
'value' => 0,
|
||||
'return' => true,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
@ -3573,6 +3601,40 @@ class AgentWizard extends HTML
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve operstatus for given interface.
|
||||
*
|
||||
* @param string $interface_name Interface name.
|
||||
*
|
||||
* @return integer OperStatus.
|
||||
*/
|
||||
private function getOperStatus(string $interface_name)
|
||||
{
|
||||
if (is_array($this->interfacesData[$interface_name]) === true) {
|
||||
return (int) $this->interfacesData[$interface_name]['operstatus'];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve adminstatus for given interface.
|
||||
*
|
||||
* @param string $interface_name Interface name.
|
||||
*
|
||||
* @return integer AdminStatus.
|
||||
*/
|
||||
private function getAdminStatus(string $interface_name)
|
||||
{
|
||||
if (is_array($this->interfacesData[$interface_name]) === true) {
|
||||
return (int) $this->interfacesData[$interface_name]['adminstatus'];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the tables with toggle interface for show the modules availables.
|
||||
*
|
||||
|
@ -3627,7 +3689,7 @@ class AgentWizard extends HTML
|
|||
true,
|
||||
false,
|
||||
'',
|
||||
'form="form-create-modules" class="interfaz_select"',
|
||||
'form="form-create-modules" class="interfaz_select" ',
|
||||
true,
|
||||
$md5IdBlock
|
||||
);
|
||||
|
@ -4156,6 +4218,10 @@ class AgentWizard extends HTML
|
|||
|
||||
$open = true;
|
||||
$buttonSwitch = false;
|
||||
$attr = 'operstatus="'.$this->getOperStatus($idBlock).'" ';
|
||||
$attr .= 'adminstatus="';
|
||||
$attr .= $this->getAdminStatus($idBlock).'" ';
|
||||
|
||||
$class = 'box-shadow white_table_graph interfaces_search';
|
||||
$reverseImg = true;
|
||||
if ($isPrincipal === true) {
|
||||
|
@ -4165,22 +4231,25 @@ class AgentWizard extends HTML
|
|||
$reverseImg = false;
|
||||
}
|
||||
|
||||
$output .= ui_toggle(
|
||||
$content,
|
||||
$blockTitle,
|
||||
'',
|
||||
$idBlock,
|
||||
$open,
|
||||
true,
|
||||
'',
|
||||
'white-box-content',
|
||||
$class,
|
||||
'images/arrow_down_green.png',
|
||||
'images/arrow_right_green.png',
|
||||
false,
|
||||
$reverseImg,
|
||||
$buttonSwitch,
|
||||
'form="form-create-modules"'
|
||||
$output .= ui_print_toggle(
|
||||
[
|
||||
'content' => $content,
|
||||
'name' => $blockTitle,
|
||||
'title' => '',
|
||||
'id' => $idBlock,
|
||||
'hidden_default' => $open,
|
||||
'return' => true,
|
||||
'toggle_class' => '',
|
||||
'container_class' => 'white-box-content',
|
||||
'main_class' => $class,
|
||||
'img_a' => 'images/arrow_down_green.png',
|
||||
'img_b' => 'images/arrow_right_green.png',
|
||||
'clean' => false,
|
||||
'reverseImg' => $reverseImg,
|
||||
'switch' => $buttonSwitch,
|
||||
'attributes_switch' => 'form="form-create-modules"',
|
||||
'toggl_attr' => $attr,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -4221,16 +4290,35 @@ class AgentWizard extends HTML
|
|||
// Definition object.
|
||||
$definition = [];
|
||||
|
||||
// Fulfill extra info.
|
||||
$this->interfacesData[$data['name']] = [];
|
||||
|
||||
// IfOperStatus.
|
||||
$adminStatusValue = 1;
|
||||
if (empty($data) === false) {
|
||||
$adminStatusValue = $this->snmpgetValue(
|
||||
'1.3.6.1.2.1.2.2.1.7.'.$value
|
||||
);
|
||||
|
||||
preg_match('/\((\d+?)\)/', $adminStatusValue, $match);
|
||||
$adminStatusValue = (int) $match[1];
|
||||
}
|
||||
|
||||
// IfOperStatus.
|
||||
$operStatusValue = 1;
|
||||
if (empty($data) === false) {
|
||||
$operStatusValue = $this->snmpgetValue(
|
||||
'1.3.6.1.2.1.2.2.1.8.'.$value
|
||||
);
|
||||
|
||||
preg_match('/\((\d+?)\)/', $operStatusValue, $match);
|
||||
$operStatusValue = (int) $match[1];
|
||||
}
|
||||
|
||||
// Store aux data.
|
||||
$this->interfacesData[$data['name']]['adminstatus'] = $adminStatusValue;
|
||||
$this->interfacesData[$data['name']]['operstatus'] = $operStatusValue;
|
||||
|
||||
if ($adminStatusValue === 3) {
|
||||
$min_warning = 3;
|
||||
$max_warning = 4;
|
||||
|
@ -4996,6 +5084,53 @@ class AgentWizard extends HTML
|
|||
ob_start();
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
|
||||
function filterInterfaces() {
|
||||
var string = $('#text-filter-search').val().trim();
|
||||
var filter_online = document.getElementById('search-admin').checked;
|
||||
var filter_up = document.getElementById('search-oper').checked;
|
||||
|
||||
var regex = new RegExp(string, 'i');
|
||||
var interfaces = $('.interfaces_search');
|
||||
|
||||
console.log(string);
|
||||
console.log('adminstatus');
|
||||
console.log(filter_online);
|
||||
|
||||
console.log('operstatus');
|
||||
console.log(filter_up);
|
||||
|
||||
interfaces.each(function() {
|
||||
if (string == ''
|
||||
&& filter_up == false
|
||||
&& filter_online == false
|
||||
) {
|
||||
$(this).removeClass('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.id.match(regex)) {
|
||||
$(this).removeClass('hidden');
|
||||
} else {
|
||||
$(this).addClass('hidden');
|
||||
}
|
||||
|
||||
if (filter_online == true) {
|
||||
if ($(this).attr('adminstatus') != 1) {
|
||||
$(this).addClass('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
if (filter_up == true) {
|
||||
console.log($(this));
|
||||
if ($(this).attr('operstatus') != 1) {
|
||||
$(this).addClass('hidden');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
// Meta.
|
||||
var meta = "<?php echo is_metaconsole(); ?>";
|
||||
|
@ -5009,20 +5144,7 @@ class AgentWizard extends HTML
|
|||
|
||||
// Filter search interfaces snmp.
|
||||
$('#text-filter-search').keyup(function() {
|
||||
var string = $('#text-filter-search').val();
|
||||
var regex = new RegExp(string);
|
||||
var interfaces = $('.interfaces_search');
|
||||
interfaces.each(function() {
|
||||
if (string == '') {
|
||||
$(this).removeClass('hidden');
|
||||
} else {
|
||||
if (this.id.match(regex)) {
|
||||
$(this).removeClass('hidden');
|
||||
} else {
|
||||
$(this).addClass('hidden');
|
||||
}
|
||||
}
|
||||
});
|
||||
filterInterfaces();
|
||||
});
|
||||
|
||||
// Loading.
|
||||
|
|
|
@ -2923,7 +2923,7 @@ function ui_progress(
|
|||
$id = uniqid();
|
||||
|
||||
ui_require_css_file('progress');
|
||||
$output .= '<span id="'.$id.'" class="progress_main" data-label="'.$text;
|
||||
$output = '<span id="'.$id.'" class="progress_main" data-label="'.$text;
|
||||
$output .= '" style="width: '.$width.'; height: '.$height.'em; border: 1px solid '.$color.'">';
|
||||
$output .= '<span id="'.$id.'_progress" class="progress" style="width: '.$progress.'%; background: '.$color.'"></span>';
|
||||
$output .= '</span>';
|
||||
|
@ -3076,7 +3076,7 @@ function ui_progress_extend(
|
|||
ui_require_css_file('progress');
|
||||
|
||||
// Main container.
|
||||
$output .= '<div class="progress_main_noborder" ';
|
||||
$output = '<div class="progress_main_noborder" ';
|
||||
$output .= '" style="width:'.$data['width'].'%;';
|
||||
$output .= ' height:'.$data['height'].'em;">';
|
||||
|
||||
|
@ -3419,6 +3419,7 @@ function ui_print_datatable(array $parameters)
|
|||
$js .= $parameters['drawCallback'];
|
||||
}
|
||||
|
||||
$columns = '';
|
||||
for ($i = 1; $i <= (count($parameters['columns']) - 3); $i++) {
|
||||
if ($i != (count($parameters['columns']) - 3)) {
|
||||
$columns .= $i.',';
|
||||
|
@ -3747,18 +3748,22 @@ function ui_print_event_priority(
|
|||
/**
|
||||
* Print a code into a DIV and enable a toggle to show and hide it.
|
||||
*
|
||||
* @param string $code Html code.
|
||||
* @param string $name Name of the link.
|
||||
* @param string $title Title of the link.
|
||||
* @param string $id Block id.
|
||||
* @param boolean $hidden_default If the div will be hidden by default (default: true).
|
||||
* @param boolean $return Whether to return an output string or echo now (default: true).
|
||||
* @param string $toggle_class Toggle class.
|
||||
* @param string $container_class Container class.
|
||||
* @param string $main_class Main object class.
|
||||
* @param string $img_a Image (closed).
|
||||
* @param string $img_b Image (opened).
|
||||
* @param string $clean Do not encapsulate with class boxes, clean print.
|
||||
* @param string $code Html code.
|
||||
* @param string $name Name of the link.
|
||||
* @param string $title Title of the link.
|
||||
* @param string $id Block id.
|
||||
* @param boolean $hidden_default If the div will be hidden by default (default: true).
|
||||
* @param boolean $return Whether to return an output string or echo now (default: true).
|
||||
* @param string $toggle_class Toggle class.
|
||||
* @param string $container_class Container class.
|
||||
* @param string $main_class Main object class.
|
||||
* @param string $img_a Image (closed).
|
||||
* @param string $img_b Image (opened).
|
||||
* @param string $clean Do not encapsulate with class boxes, clean print.
|
||||
* @param boolean $reverseImg Reverse img.
|
||||
* @param boolean $switch Use switch.
|
||||
* @param string $attributes_switch Switch attributes.
|
||||
* @param string $toggl_attr Main box extra attributes.
|
||||
*
|
||||
* @return string HTML.
|
||||
*/
|
||||
|
@ -3777,7 +3782,8 @@ function ui_toggle(
|
|||
$clean=false,
|
||||
$reverseImg=false,
|
||||
$switch=false,
|
||||
$attributes_switch=''
|
||||
$attributes_switch='',
|
||||
$toggl_attr=''
|
||||
) {
|
||||
// Generate unique Id.
|
||||
$uniqid = uniqid('');
|
||||
|
@ -3817,7 +3823,7 @@ function ui_toggle(
|
|||
}
|
||||
|
||||
// Link to toggle.
|
||||
$output = '<div class="'.$main_class.'" id="'.$id.'">';
|
||||
$output = '<div class="'.$main_class.'" id="'.$id.'" '.$toggl_attr.'>';
|
||||
$output .= '<div class="'.$header_class.'" style="cursor: pointer;" id="tgl_ctrl_'.$uniqid.'">';
|
||||
if ($reverseImg === false) {
|
||||
if ($switch === true) {
|
||||
|
@ -3953,7 +3959,11 @@ function ui_print_toggle($data)
|
|||
(isset($data['main_class']) === true) ? $data['main_class'] : 'box-shadow white_table_graph',
|
||||
(isset($data['img_a']) === true) ? $data['img_a'] : 'images/arrow_down_green.png',
|
||||
(isset($data['img_b']) === true) ? $data['img_b'] : 'images/arrow_right_green.png',
|
||||
(isset($data['clean']) === true) ? $data['clean'] : false
|
||||
(isset($data['clean']) === true) ? $data['clean'] : false,
|
||||
(isset($data['reverseImg']) === true) ? $data['reverseImg'] : false,
|
||||
(isset($data['switch']) === true) ? $data['switch'] : false,
|
||||
(isset($data['attributes_switch']) === true) ? $data['attributes_switch'] : '',
|
||||
(isset($data['toggl_attr']) === true) ? $data['toggl_attr'] : ''
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -5661,12 +5671,6 @@ function ui_print_module_string_value(
|
|||
$value = io_safe_input($value);
|
||||
}
|
||||
|
||||
$is_snapshot = is_snapshot_data($module['datos']);
|
||||
$is_large_image = is_text_to_black_string($module['datos']);
|
||||
if (($config['command_snapshot']) && ($is_snapshot || $is_large_image)) {
|
||||
$row[7] = ui_get_snapshot_image($link, $is_snapshot).' ';
|
||||
}
|
||||
|
||||
$is_snapshot = is_snapshot_data($value);
|
||||
$is_large_image = is_text_to_black_string($value);
|
||||
if (($config['command_snapshot']) && ($is_snapshot || $is_large_image)) {
|
||||
|
@ -5733,6 +5737,7 @@ function ui_print_module_string_value(
|
|||
*/
|
||||
function ui_print_tags_view($title='', $tags=[])
|
||||
{
|
||||
$tv = '';
|
||||
if (!empty($title)) {
|
||||
$tv .= '<div class="tag-wrapper">';
|
||||
$tv .= '<h3>'.$title.'</h3>';
|
||||
|
@ -6071,6 +6076,7 @@ function ui_print_comments($comments)
|
|||
}
|
||||
}
|
||||
|
||||
$last_comment = [];
|
||||
foreach ($comments_array as $comm) {
|
||||
// Show the comments more recent first.
|
||||
if (is_array($comm)) {
|
||||
|
|
|
@ -148,3 +148,20 @@ ul.wizard li > textarea {
|
|||
.action_button_list li {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.searchbox ul {
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.searchbox ul li:not(.textbox) {
|
||||
flex-direction: row-reverse !important;
|
||||
justify-content: flex-end !important;
|
||||
}
|
||||
|
||||
.searchbox ul li.textbox label {
|
||||
width: auto;
|
||||
}
|
||||
.searchbox ul li.textbox {
|
||||
justify-content: space-evenly !important;
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue