Merge branch 'ent-5367-Anadir-buscador-y-filtro-en-la-pestaña-de-Acciones' into 'develop'

Add new filter search actions

See merge request artica/pandorafms!3362
This commit is contained in:
Alejandro Fraguas 2020-08-31 12:48:00 +02:00
commit 9ba72bb691
1 changed files with 132 additions and 48 deletions

View File

@ -1,17 +1,32 @@
<?php
/**
* Alert actions
*
* @category Alerts
* @package Pandora FMS
* @subpackage Community
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
* Please see http://pandorafms.org for full contribution list
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ============================================================================
*/
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Load global vars
// Load global vars.
global $config;
require_once $config['homedir'].'/include/functions_alerts.php';
@ -63,9 +78,9 @@ if ($copy_action) {
$al_action = alerts_get_alert_action($id);
if ($al_action !== false) {
// If user tries to copy an action with group=ALL
// If user tries to copy an action with group=ALL.
if ($al_action['id_group'] == 0) {
// then must have "PM" access privileges
// Then must have "PM" access privileges.
if (! check_acl($config['id_user'], 0, 'PM')) {
db_pandora_audit(
'ACL Violation',
@ -74,17 +89,20 @@ if ($copy_action) {
include 'general/noaccess.php';
exit;
}
} //end if
else {
} else {
$own_info = get_user_info($config['id_user']);
if ($own_info['is_admin'] || check_acl($config['id_user'], 0, 'PM')) {
$own_groups = array_keys(users_get_groups($config['id_user'], 'LM'));
$own_groups = array_keys(
users_get_groups($config['id_user'], 'LM')
);
} else {
$own_groups = array_keys(users_get_groups($config['id_user'], 'LM', false));
$own_groups = array_keys(
users_get_groups($config['id_user'], 'LM', false)
);
}
$is_in_group = in_array($al_action['id_group'], $own_groups);
// Then action group have to be in his own groups
// Then action group have to be in his own groups.
if (!$is_in_group) {
db_pandora_audit(
'ACL Violation',
@ -99,9 +117,15 @@ if ($copy_action) {
$result = alerts_clone_alert_action($id);
if ($result) {
db_pandora_audit('Command management', 'Duplicate alert action '.$id.' clone to '.$result);
db_pandora_audit(
'Command management',
'Duplicate alert action '.$id.' clone to '.$result
);
} else {
db_pandora_audit('Command management', 'Fail try to duplicate alert action '.$id);
db_pandora_audit(
'Command management',
'Fail try to duplicate alert action '.$id
);
}
ui_print_result_message(
@ -121,9 +145,9 @@ if ($delete_action) {
$al_action = alerts_get_alert_action($id);
if ($al_action !== false) {
// If user tries to delete an action with group=ALL
// If user tries to delete an action with group=ALL.
if ($al_action['id_group'] == 0) {
// then must have "PM" access privileges
// Then must have "PM" access privileges.
if (! check_acl($config['id_user'], 0, 'PM')) {
db_pandora_audit(
'ACL Violation',
@ -133,17 +157,21 @@ if ($delete_action) {
exit;
}
// If user tries to delete an action of others groups
// If user tries to delete an action of others groups.
} else {
$own_info = get_user_info($config['id_user']);
if ($own_info['is_admin'] || check_acl($config['id_user'], 0, 'PM')) {
$own_groups = array_keys(users_get_groups($config['id_user'], 'LM'));
$own_groups = array_keys(
users_get_groups($config['id_user'], 'LM')
);
} else {
$own_groups = array_keys(users_get_groups($config['id_user'], 'LM', false));
$own_groups = array_keys(
users_get_groups($config['id_user'], 'LM', false)
);
}
$is_in_group = in_array($al_action['id_group'], $own_groups);
// Then action group have to be in his own groups
// Then action group have to be in his own groups.
if (!$is_in_group) {
db_pandora_audit(
'ACL Violation',
@ -159,9 +187,15 @@ if ($delete_action) {
$result = alerts_delete_alert_action($id);
if ($result) {
db_pandora_audit('Command management', 'Delete alert action #'.$id);
db_pandora_audit(
'Command management',
'Delete alert action #'.$id
);
} else {
db_pandora_audit('Command management', 'Fail try to delete alert action #'.$id);
db_pandora_audit(
'Command management',
'Fail try to delete alert action #'.$id
);
}
ui_print_result_message(
@ -179,6 +213,8 @@ if (is_central_policies_on_node() === true) {
$search_string = (string) get_parameter('search_string', '');
$group = (int) get_parameter('group', 0);
$group_search = (int) get_parameter('group_search', 0);
$id_command_search = (int) get_parameter('id_command_search', 0);
$url = 'index.php?sec='.$sec.'&sec2=godmode/alerts/alert_actions';
// Filter table.
@ -188,6 +224,7 @@ $table_filter->class = 'databox filters';
$table_filter->style = [];
$table_filter->style[0] = 'font-weight: bold';
$table_filter->style[2] = 'font-weight: bold';
$table_filter->style[4] = 'font-weight: bold';
$table_filter->data = [];
$table_filter->data[0][0] = __('Search');
@ -200,16 +237,54 @@ $table_filter->data[0][1] = html_print_input_text(
true
);
$table_filter->data[0][2] = __('Group');
$table_filter->data[0][3] = html_print_select_groups($config['id_user'], 'LM', true, 'group', $group, '', '', 0, true);
$table_filter->data[0][4] = '<div class="action-buttons">';
$table_filter->data[0][4] .= html_print_submit_button(
$table_filter->data[0][3] = html_print_select_groups(
$config['id_user'],
'LM',
true,
'group_search',
$group_search,
'',
'',
0,
true
);
$table_filter->data[0][4] = __('Command');
$commands_sql = db_get_all_rows_filter(
'talert_commands',
['id_group' => array_keys(users_get_groups(false, 'LW'))],
[
'id',
'name',
],
'AND',
false,
true
);
$commands = db_get_all_rows_sql($commands_sql);
$table_filter->data[0][5] = html_print_select(
index_array($commands, 'id', 'name'),
'id_command_search',
$id_command_search,
'',
__('None'),
0,
true,
false,
true,
'',
false,
'width:150px'
);
$table_filter->data[0][6] = '<div class="action-buttons">';
$table_filter->data[0][6] .= html_print_submit_button(
__('Search'),
'',
false,
'class="sub search"',
true
);
$table_filter->data[0][4] .= '</div>';
$table_filter->data[0][5] .= '</div>';
$show_table_filter = '<form method="post" action="'.$url.'">';
@ -228,41 +303,49 @@ $table->class = 'info_table';
$table->data = [];
$table->head = [];
$table->head[0] = __('Name');
$table->head[1] = __('Group');
$table->head[1] = __('Command');
$table->head[2] = __('Group');
if (is_central_policies_on_node() === false) {
$table->head[2] = __('Copy');
$table->head[3] = __('Delete');
$table->head[3] = __('Copy');
$table->head[4] = __('Delete');
}
$table->style = [];
$table->style[0] = 'font-weight: bold';
$table->size = [];
$table->size[1] = '200px';
$table->size[2] = '40px';
$table->size[3] = '40px';
$table->size[4] = '40px';
$table->align = [];
$table->align[1] = 'left';
$table->align[2] = 'left';
$table->align[3] = 'left';
$table->align[4] = 'left';
$filter = [];
if (!is_user_admin($config['id_user']) && $group === 0) {
$filter['talert_actions.id_group'] = array_keys(users_get_groups(false, 'LM'));
$filter['talert_actions.id_group'] = array_keys(
users_get_groups(false, 'LM')
);
}
if ($group !== 0) {
$filter['talert_actions.id_group'] = $group;
if ($group_search !== 0) {
$filter['talert_actions.id_group'] = $group_search;
}
if ($search_string !== '') {
$filter['talert_actions.name'] = '%'.$search_string.'%';
}
if ($id_command_search !== 0) {
$filter['talert_commands.id'] = $id_command_search;
}
$actions = db_get_all_rows_filter(
'talert_actions INNER JOIN talert_commands ON talert_actions.id_alert_command = talert_commands.id',
$filter,
'talert_actions.* , talert_commands.id_group AS command_group'
'talert_actions.* , talert_commands.id_group AS command_group, talert_commands.name AS command_name'
);
if ($actions === false) {
$actions = [];
}
@ -288,9 +371,10 @@ foreach ($actions as $action) {
$data = [];
$data[0] = '<a href="index.php?sec='.$sec.'&sec2=godmode/alerts/configure_alert_action&id='.$action['id'].'&pure='.$pure.'">'.$action['name'].'</a>';
$data[1] = ui_print_group_icon($action['id_group'], true).'&nbsp;';
$data[1] = $action['command_name'];
$data[2] = ui_print_group_icon($action['id_group'], true).'&nbsp;';
if (!alerts_validate_command_to_action($action['id_group'], $action['command_group'])) {
$data[1] .= html_print_image(
$data[2] .= html_print_image(
'images/error.png',
true,
// FIXME: Translation.
@ -304,16 +388,16 @@ foreach ($actions as $action) {
&& check_acl($config['id_user'], $action['id_group'], 'LM')
) {
$table->cellclass[] = [
2 => 'action_buttons',
3 => 'action_buttons',
4 => 'action_buttons',
];
$id_action = $action['id'];
$text_confirm = __('Are you sure?');
$data[2] = '<a href="index.php?sec='.$sec.'&sec2=godmode/alerts/alert_actions"
$data[3] = '<a href="index.php?sec='.$sec.'&sec2=godmode/alerts/alert_actions"
onClick="copy_action('.$id_action.',\''.$text_confirm.'\');">'.html_print_image('images/copy.png', true).'</a>';
$data[3] = '<a href="index.php?sec='.$sec.'&sec2=godmode/alerts/alert_actions"
$data[4] = '<a href="index.php?sec='.$sec.'&sec2=godmode/alerts/alert_actions"
onClick="delete_action('.$id_action.',\''.$text_confirm.'\');">'.html_print_image('images/cross.png', true).'</a>';
}
@ -346,7 +430,7 @@ function copy_action(id_action, text_confirm) {
if (!confirm(text_confirm)) {
return false;
} else {
jQuery.post ("ajax.php",
jQuery.post ("ajax.php",
{
"page" : "godmode/alerts/alert_actions",
"copy_action" : 1,