Resized alert action list and refactor

This commit is contained in:
José González 2022-06-23 12:21:00 +02:00
parent 7e206716d7
commit 237de0ee97
1 changed files with 92 additions and 79 deletions

View File

@ -1,25 +1,35 @@
<?php <?php
/**
* List view for Alerts.
*
* @category Alerts
* @package Community
* @subpackage Software agents repository
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ==========================================================
* Copyright (c) 2005-2022 Artica Soluciones Tecnológicas S.L
* This code is NOT free software. This code is NOT licenced under GPL2 licence
* You cannot redistribute it without written permission of copyright holder.
* ============================================================================
*/
// Pandora FMS - http://pandorafms.com // Begin.
// ==================================================
// Copyright (c) 2005-2021 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.
global $config; global $config;
// Login check // Login check.
check_login(); check_login();
// Check if this page is included from a agent edition // Check if this page is included from a agent edition.
if (! check_acl($config['id_user'], 0, 'LW') if ((bool) check_acl($config['id_user'], 0, 'LW') === false
&& ! check_acl($config['id_user'], 0, 'AD') && (bool) check_acl($config['id_user'], 0, 'AD') === false
&& ! check_acl($config['id_user'], 0, 'LM') && (bool) check_acl($config['id_user'], 0, 'LM') === false
) { ) {
db_pandora_audit( db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION, AUDIT_LOG_ACL_VIOLATION,
@ -36,7 +46,7 @@ require_once $config['homedir'].'/include/functions_users.php';
$pure = get_parameter('pure', 0); $pure = get_parameter('pure', 0);
$agent_id = get_parameter('agent_id', 0); $agent_id = get_parameter('agent_id', 0);
if (defined('METACONSOLE')) { if (is_metaconsole() === true) {
$sec = 'advanced'; $sec = 'advanced';
} else { } else {
$sec = 'galertas'; $sec = 'galertas';
@ -48,7 +58,7 @@ if ($id_agente) {
$sec2 = 'godmode/alerts/alert_list'; $sec2 = 'godmode/alerts/alert_list';
} }
// Table for filter controls // Table for filter controls.
$form_filter = '<form method="post" action="index.php?sec='.$sec.'&amp;sec2='.$sec2.'&amp;refr='.((int) get_parameter('refr', 0)).'&amp;pure='.$config['pure'].'">'; $form_filter = '<form method="post" action="index.php?sec='.$sec.'&amp;sec2='.$sec2.'&amp;refr='.((int) get_parameter('refr', 0)).'&amp;pure='.$config['pure'].'">';
$form_filter .= "<input type='hidden' name='search' value='1' />"; $form_filter .= "<input type='hidden' name='search' value='1' />";
$form_filter .= '<table cellpadding="0" cellspacing="0" class="databox filters w100p">'; $form_filter .= '<table cellpadding="0" cellspacing="0" class="databox filters w100p">';
@ -60,7 +70,7 @@ $temp = agents_get_agents();
$arrayAgents = []; $arrayAgents = [];
// Avoid empty arrays, warning messages are UGLY ! // Avoid empty arrays, warning messages are UGLY !
if ($temp) { if ($temp !== false) {
foreach ($temp as $agentElement) { foreach ($temp as $agentElement) {
$arrayAgents[$agentElement['id_agente']] = $agentElement['nombre']; $arrayAgents[$agentElement['id_agente']] = $agentElement['nombre'];
} }
@ -93,11 +103,11 @@ $form_filter .= '</tr>';
$all_groups = db_get_value('is_admin', 'tusuario', 'id_user', $config['id_user']); $all_groups = db_get_value('is_admin', 'tusuario', 'id_user', $config['id_user']);
if (check_acl($config['id_user'], 0, 'AD')) { if ((bool) check_acl($config['id_user'], 0, 'AD') === true) {
$groups_user = users_get_groups($config['id_user'], 'AD', $all_groups); $groups_user = users_get_groups($config['id_user'], 'AD', $all_groups);
} else if (check_acl($config['id_user'], 0, 'LW')) { } else if ((bool) check_acl($config['id_user'], 0, 'LW') === true) {
$groups_user = users_get_groups($config['id_user'], 'LW', $all_groups); $groups_user = users_get_groups($config['id_user'], 'LW', $all_groups);
} else if (check_acl($config['id_user'], 0, 'LM')) { } else if ((bool) check_acl($config['id_user'], 0, 'LM') === true) {
$groups_user = users_get_groups($config['id_user'], 'LM', $all_groups); $groups_user = users_get_groups($config['id_user'], 'LM', $all_groups);
} }
@ -109,9 +119,9 @@ $groups_id = implode(',', array_keys($groups_user));
$form_filter .= '<tr>'; $form_filter .= '<tr>';
$temp = db_get_all_rows_sql("SELECT id, name FROM talert_actions WHERE id_group IN ($groups_id);"); $temp = db_get_all_rows_sql('SELECT id, name FROM talert_actions WHERE id_group IN ('.$groups_id.');');
$arrayActions = []; $arrayActions = [];
if (is_array($temp)) { if (is_array($temp) === true) {
foreach ($temp as $actionElement) { foreach ($temp as $actionElement) {
$arrayActions[$actionElement['id']] = $actionElement['name']; $arrayActions[$actionElement['id']] = $actionElement['name'];
} }
@ -155,7 +165,7 @@ if (!$own_info['is_admin'] && !check_acl($config['id_user'], 0, 'AR') && !check_
$form_filter .= html_print_select_groups(false, 'AR', $return_all_group, 'ag_group', $ag_group, '', '', 0, true, false, true, '', false); $form_filter .= html_print_select_groups(false, 'AR', $return_all_group, 'ag_group', $ag_group, '', '', 0, true, false, true, '', false);
$form_filter .= '</td></tr>'; $form_filter .= '</td></tr>';
if (defined('METACONSOLE')) { if (is_metaconsole() === true) {
$form_filter .= '<tr>'; $form_filter .= '<tr>';
$form_filter .= "<td colspan='6' align='right'>"; $form_filter .= "<td colspan='6' align='right'>";
$form_filter .= html_print_submit_button(__('Update'), '', false, 'class="sub upd"', true); $form_filter .= html_print_submit_button(__('Update'), '', false, 'class="sub upd"', true);
@ -170,7 +180,7 @@ if (defined('METACONSOLE')) {
} }
$form_filter .= '</form>'; $form_filter .= '</form>';
if (defined('METACONSOLE')) { if (is_metaconsole() === true) {
echo '<br>'; echo '<br>';
} }
@ -253,7 +263,7 @@ $total = agents_get_alerts_simple(
true true
); );
if (empty($total)) { if (empty($total) === true) {
$total = 0; $total = 0;
} }
@ -277,14 +287,6 @@ $selectTemplateDown = false;
switch ($sortField) { switch ($sortField) {
case 'disabled': case 'disabled':
switch ($sort) { switch ($sort) {
case 'up':
$selectDisabledUp = $selected;
$order = [
'field' => 'disabled',
'order' => 'ASC',
];
break;
case 'down': case 'down':
$selectDisabledDown = $selected; $selectDisabledDown = $selected;
$order = [ $order = [
@ -292,19 +294,20 @@ switch ($sortField) {
'order' => 'DESC', 'order' => 'DESC',
]; ];
break; break;
default:
case 'up':
$selectDisabledUp = $selected;
$order = [
'field' => 'disabled',
'order' => 'ASC',
];
break;
} }
break; break;
case 'standby': case 'standby':
switch ($sort) { switch ($sort) {
case 'up':
$selectStandbyUp = $selected;
$order = [
'field' => 'standby',
'order' => 'ASC',
];
break;
case 'down': case 'down':
$selectStandbyDown = $selected; $selectStandbyDown = $selected;
$order = [ $order = [
@ -312,19 +315,20 @@ switch ($sortField) {
'order' => 'DESC', 'order' => 'DESC',
]; ];
break; break;
default:
case 'up':
$selectStandbyUp = $selected;
$order = [
'field' => 'standby',
'order' => 'ASC',
];
break;
} }
break; break;
case 'agent': case 'agent':
switch ($sort) { switch ($sort) {
case 'up':
$selectAgentUp = $selected;
$order = [
'field' => 'agent_name',
'order' => 'ASC',
];
break;
case 'down': case 'down':
$selectAgentDown = $selected; $selectAgentDown = $selected;
$order = [ $order = [
@ -332,19 +336,20 @@ switch ($sortField) {
'order' => 'DESC', 'order' => 'DESC',
]; ];
break; break;
default:
case 'up':
$selectAgentUp = $selected;
$order = [
'field' => 'agent_name',
'order' => 'ASC',
];
break;
} }
break; break;
case 'module': case 'module':
switch ($sort) { switch ($sort) {
case 'up':
$selectModuleUp = $selected;
$order = [
'field' => 'agent_module_name',
'order' => 'ASC',
];
break;
case 'down': case 'down':
$selectModuleDown = $selected; $selectModuleDown = $selected;
$order = [ $order = [
@ -352,19 +357,20 @@ switch ($sortField) {
'order' => 'DESC', 'order' => 'DESC',
]; ];
break; break;
default:
case 'up':
$selectModuleUp = $selected;
$order = [
'field' => 'agent_module_name',
'order' => 'ASC',
];
break;
} }
break; break;
case 'template': case 'template':
switch ($sort) { switch ($sort) {
case 'up':
$selectTemplateUp = $selected;
$order = [
'field' => 'template_name',
'order' => 'ASC',
];
break;
case 'down': case 'down':
$selectTemplateDown = $selected; $selectTemplateDown = $selected;
$order = [ $order = [
@ -372,6 +378,15 @@ switch ($sortField) {
'order' => 'DESC', 'order' => 'DESC',
]; ];
break; break;
default:
case 'up':
$selectTemplateUp = $selected;
$order = [
'field' => 'template_name',
'order' => 'ASC',
];
break;
} }
break; break;
@ -717,13 +732,13 @@ foreach ($simple_alerts as $alert) {
$data[3] .= '<div id="add_action-div-'.$alert['id'].'" class="invisible">'; $data[3] .= '<div id="add_action-div-'.$alert['id'].'" class="invisible">';
$data[3] .= '<form id="add_action_form-'.$alert['id'].'" method="post" style="height:85%;">'; $data[3] .= '<form id="add_action_form-'.$alert['id'].'" method="post" style="height:85%;">';
$data[3] .= '<table class="databox_color w100p bg_color222" style="height:100%;">'; $data[3] .= '<table class="w100p bg_color222">';
$data[3] .= html_print_input_hidden('add_action', 1, true); $data[3] .= html_print_input_hidden('add_action', 1, true);
$data[3] .= html_print_input_hidden('id_alert_module', $alert['id'], true); $data[3] .= html_print_input_hidden('id_alert_module', $alert['id'], true);
if (! $id_agente) { if (! $id_agente) {
$data[3] .= '<tr class="datos2">'; $data[3] .= '<tr class="datos2">';
$data[3] .= '<td class="datos2 bolder pdd_6px">'; $data[3] .= '<td class="datos2 bolder pdd_6px font_10pt">';
$data[3] .= __('Agent'); $data[3] .= __('Agent');
$data[3] .= '</td>'; $data[3] .= '</td>';
$data[3] .= '<td class="datos">'; $data[3] .= '<td class="datos">';
@ -733,7 +748,7 @@ foreach ($simple_alerts as $alert) {
} }
$data[3] .= '<tr class="datos">'; $data[3] .= '<tr class="datos">';
$data[3] .= '<td class="datos bolder pdd_6px">'; $data[3] .= '<td class="datos bolder pdd_6px font_10pt">';
$data[3] .= __('Module'); $data[3] .= __('Module');
$data[3] .= '</td>'; $data[3] .= '</td>';
$data[3] .= '<td class="datos">'; $data[3] .= '<td class="datos">';
@ -741,15 +756,15 @@ foreach ($simple_alerts as $alert) {
$data[3] .= '</td>'; $data[3] .= '</td>';
$data[3] .= '</tr>'; $data[3] .= '</tr>';
$data[3] .= '<tr class="datos2">'; $data[3] .= '<tr class="datos2">';
$data[3] .= '<td class="datos2 bolder pdd_6px">'; $data[3] .= '<td class="datos2 bolder pdd_6px font_10pt">';
$data[3] .= __('Action'); $data[3] .= __('Action');
$data[3] .= '</td>'; $data[3] .= '</td>';
$data[3] .= '<td class="datos2">'; $data[3] .= '<td class="datos2">';
$data[3] .= html_print_select($actions, 'action_select', '', '', __('None'), 0, true, false, true, '', false, 'width:150px'); $data[3] .= html_print_select($actions, 'action_select', '', '', __('None'), 0, true, false, true, '', false, 'width:95%');
$data[3] .= '</td>'; $data[3] .= '</td>';
$data[3] .= '</tr>'; $data[3] .= '</tr>';
$data[3] .= '<tr class="datos">'; $data[3] .= '<tr class="datos">';
$data[3] .= '<td class="datos bolder pdd_6px">'; $data[3] .= '<td class="datos bolder pdd_6px font_10pt">';
$data[3] .= __('Number of alerts match from'); $data[3] .= __('Number of alerts match from');
$data[3] .= '</td>'; $data[3] .= '</td>';
$data[3] .= '<td class="datos">'; $data[3] .= '<td class="datos">';
@ -773,7 +788,7 @@ foreach ($simple_alerts as $alert) {
$data[3] .= '</td>'; $data[3] .= '</td>';
$data[3] .= '</tr>'; $data[3] .= '</tr>';
$data[3] .= '<tr class="datos2">'; $data[3] .= '<tr class="datos2">';
$data[3] .= '<td class="datos2 bolder pdd_6px">'; $data[3] .= '<td class="datos2 bolder pdd_6px font_10pt">';
$data[3] .= __('Threshold'); $data[3] .= __('Threshold');
$data[3] .= '</td>'; $data[3] .= '</td>';
$data[3] .= '<td class="datos2">'; $data[3] .= '<td class="datos2">';
@ -1127,8 +1142,6 @@ function show_advance_options_action(id_alert) {
function show_add_action(id_alert) { function show_add_action(id_alert) {
$("#add_action-div-" + id_alert).hide () $("#add_action-div-" + id_alert).hide ()
.dialog ({ .dialog ({
resizable: true,
draggable: true,
title: '<?php echo __('Add action'); ?>', title: '<?php echo __('Add action'); ?>',
modal: true, modal: true,
overlay: { overlay: {
@ -1136,14 +1149,14 @@ function show_add_action(id_alert) {
background: "black" background: "black"
}, },
open: function() { open: function() {
$(`#add_action-div-${id_alert}`).css('overflow', 'hidden'); $(`#add_action-div-${id_alert}`).css('overflow', 'initial');
$("select[id^='action_select'], select[id^='action_select']").select2({ $("select[id^='action_select'], select[id^='action_select']").select2({
tags: true, tags: true,
dropdownParent: $("#add_action-div-" + id_alert) dropdownParent: $("#add_action-div-" + id_alert)
}); });
}, },
width: 455, width: 600,
height: 500 height: 300
}) })
.show (); .show ();
} }