From 938860dff2e0990941045036971cf7c493705bd9 Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Tue, 3 Nov 2020 17:15:01 +0100 Subject: [PATCH 01/13] Added wrapper attributes --- pandora_console/include/functions_html.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index e029ebda2e..af6f5ceed9 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -4203,8 +4203,16 @@ function html_print_input($data, $wrapper='div', $input_only=false) } } + // If wrapper has attributes. + // TODO. There is possible improve this handle of attributes. + if (isset($data['wrapper_attributes'])) { + $wrapper_attributes = $data['wrapper_attributes']; + } else { + $wrapper_attributes = ''; + } + if (isset($data['wrapper']) === true) { - $output = '<'.$data['wrapper'].' id="wr_'.$data['name'].'" '; + $output = '<'.$data['wrapper'].' '.$wrapper_attributes.' id="wr_'.$data['name'].'" '; $output .= ' class="'.$data['input_class'].'">'; } From b5dc75ce9323b7f9db7cfc23390b12756bdca41f Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Wed, 4 Nov 2020 16:40:18 +0100 Subject: [PATCH 02/13] WIP: Backup upload --- pandora_console/extensions/agents_alerts.php | 416 ++--- pandora_console/extensions/agents_modules.php | 11 - .../include/class/AgentsAlerts.class.php | 1362 +++++++++++++++++ pandora_console/include/styles/pandora.css | 38 +- 4 files changed, 1558 insertions(+), 269 deletions(-) create mode 100644 pandora_console/include/class/AgentsAlerts.class.php diff --git a/pandora_console/extensions/agents_alerts.php b/pandora_console/extensions/agents_alerts.php index 4fd7be94ae..01d1e7222d 100755 --- a/pandora_console/extensions/agents_alerts.php +++ b/pandora_console/extensions/agents_alerts.php @@ -1,44 +1,80 @@ $pageName.$e->getMessage() ]); + exit; + } else { + echo $pageName.$e->getMessage(); + } + + // Stop this execution, but continue 'globally'. + return; +} + +// AJAX controller. +if (is_ajax()) { + $method = get_parameter('method'); + + if (method_exists($obj, $method) === true) { + $obj->{$method}(); + } else { + $obj->error('Method not found. ['.$method.']'); + } + + // Stop any execution. + exit; +} else { + // Run. + $obj->run(); +} function mainAgentsAlerts() { - global $config; - - // Load global vars - include_once 'include/config.php'; - include_once 'include/functions_reporting.php'; - - check_login(); - // ACL Check - if (! check_acl($config['id_user'], 0, 'AR')) { - db_pandora_audit( - 'ACL Violation', - 'Trying to access Agent view (Grouped)' - ); - include 'general/noaccess.php'; - exit; - } - - // Update network modules for this group - // Check for Network FLAG change request - // Made it a subquery, much faster on both the database and server side - if (isset($_GET['update_netgroup'])) { + /* + // Update network modules for this group + // Check for Network FLAG change request + // Made it a subquery, much faster on both the database and server side + if (isset($_GET['update_netgroup'])) { $group = get_parameter_get('update_netgroup', 0); if (check_acl($config['id_user'], $group, 'AW')) { $where = ['id_agente' => 'ANY(SELECT id_agente FROM tagente WHERE id_grupo = '.$group]; @@ -49,19 +85,19 @@ function mainAgentsAlerts() include 'general/noaccess.php'; exit; } - } + } - if ($config['realtimestats'] == 0) { + if ($config['realtimestats'] == 0) { $updated_info = __('Last update').' : '.ui_print_timestamp(db_get_sql('SELECT min(utimestamp) FROM tgroup_stat'), true); - } else { + } else { // $updated_info = __("Updated at realtime"); $updated_info = ''; - } + } - $updated_time = $updated_info; - $create_alert = (int) get_parameter('create_alert', 0); + $updated_time = $updated_info; + $create_alert = (int) get_parameter('create_alert', 0); - if ($create_alert) { + if ($create_alert) { $template2 = get_parameter('template'); $module_action_threshold = get_parameter('module_action_threshold'); @@ -79,29 +115,29 @@ function mainAgentsAlerts() alerts_add_alert_agent_module_action($id_alert, $action_select, $values); } } - } + } - $refr = (int) get_parameter('refr', 30); - // By default 30 seconds - $show_modules = (bool) get_parameter('show_modules', 0); - $group_id = get_parameter('group_id', 0); - $offset = get_parameter('offset', 0); - $hor_offset = get_parameter('hor_offset', 0); - $block = 20; + $refr = (int) get_parameter('refr', 30); + // By default 30 seconds + $show_modules = (bool) get_parameter('show_modules', 0); + $group_id = get_parameter('group_id', 0); + $offset = get_parameter('offset', 0); + $hor_offset = get_parameter('hor_offset', 0); + $block = 20; - $groups = users_get_groups(); + $groups = users_get_groups(); - $filter_groups .= ''.__('Group').''; - $filter_groups .= '
'; - $filter_groups .= html_print_select_groups(false, 'AR', true, 'group_id', $group_id, false, '', '', true, false, true, '', false, 'margin-right: 10px; margin-top: 5px;'); - $filter_groups .= '
'; + $filter_groups .= ''.__('Group').''; + $filter_groups .= '
'; + $filter_groups .= html_print_select_groups(false, 'AR', true, 'group_id', $group_id, false, '', '', true, false, true, '', false, 'margin-right: 10px; margin-top: 5px;'); + $filter_groups .= '
'; - $check = ''.__('Show modules without alerts').''; - $check .= html_print_checkbox('slides_ids[]', $d['id'], $show_modules, true, false, '', true); + $check = ''.__('Show modules without alerts').''; + $check .= html_print_checkbox('slides_ids[]', $d['id'], $show_modules, true, false, '', true); - $comborefr = '
'; - $comborefr .= ''.__('Refresh').''; - $comborefr .= html_print_select( + $comborefr = ''; + $comborefr .= ''.__('Refresh').''; + $comborefr .= html_print_select( [ '30' => '30 '.__('seconds'), (string) SECONDS_1MINUTE => __('1 minute'), @@ -120,51 +156,51 @@ function mainAgentsAlerts() '', false, 'width: 100px; margin-right: 10px; margin-top: 5px;' - ); - $comborefr .= '
'; + ); + $comborefr .= ''; - if ($config['pure'] == 0) { + if ($config['pure'] == 0) { $fullscreen['text'] = ''.html_print_image('images/full_screen.png', true, ['title' => __('Full screen mode')]).''; - } else { + } else { $fullscreen['text'] = ''.html_print_image('images/normal_screen.png', true, ['title' => __('Back to normal mode')]).''; $config['refr'] = $refr; - } + } - $onheader = [ + $onheader = [ 'updated_time' => $updated_time, 'fullscreen' => $fullscreen, 'combo_groups' => $filter_groups, - ]; + ]; - if ($config['pure'] == 1) { + if ($config['pure'] == 1) { $onheader['combo_refr'] = $comborefr; - } + } - // Header. - ui_print_page_header( + // Header. + ui_print_page_header( __('Agents/Alerts'), 'images/op_alerts.png', false, '', false, $updated_time - ); - - // Old style table, we need a lot of special formatting,don't use table function - // Prepare old-style table - echo ''; - echo ''; - echo ''; - echo ''; - if ($config['pure'] == 1) { + );*/ + /* + // Old style table, we need a lot of special formatting,don't use table function + // Prepare old-style table + echo '
'.$filter_groups.''.$check.'
'; + echo ''; + echo ''; + echo ''; + if ($config['pure'] == 1) { echo ''; - } + } - echo ''; - echo ''; - echo '
'.$filter_groups.''.$check.''.$comborefr.' '.__('Full screen').''.$fullscreen['text'].'
'; + echo ' '.__('Full screen').''.$fullscreen['text'].''; + echo ''; + echo ''; - if ($show_modules) { + if ($show_modules) { if ($group_id > 0) { $grupo = " AND tagente.id_grupo = $group_id"; } else { @@ -172,17 +208,17 @@ function mainAgentsAlerts() } $offset_modules = get_parameter('offset', 0); - $sql_count = "SELECT COUNT(tagente_modulo.nombre) FROM tagente_modulo - INNER JOIN tagente ON tagente.id_agente = tagente_modulo.id_agente - WHERE id_agente_modulo NOT IN (SELECT id_agent_module FROM talert_template_modules) - $grupo"; + $sql_count = "SELECT COUNT(tagente_modulo.nombre) FROM tagente_modulo + INNER JOIN tagente ON tagente.id_agente = tagente_modulo.id_agente + WHERE id_agente_modulo NOT IN (SELECT id_agent_module FROM talert_template_modules) + $grupo"; $count_agent_module = db_get_all_rows_sql($sql_count); - $sql = "SELECT tagente.alias, tagente_modulo.nombre, - tagente_modulo.id_agente_modulo FROM tagente_modulo - INNER JOIN tagente ON tagente.id_agente = tagente_modulo.id_agente - WHERE id_agente_modulo NOT IN (SELECT id_agent_module FROM talert_template_modules) - $grupo LIMIT 20 OFFSET $offset_modules"; + $sql = "SELECT tagente.alias, tagente_modulo.nombre, + tagente_modulo.id_agente_modulo FROM tagente_modulo + INNER JOIN tagente ON tagente.id_agente = tagente_modulo.id_agente + WHERE id_agente_modulo NOT IN (SELECT id_agent_module FROM talert_template_modules) + $grupo LIMIT 20 OFFSET $offset_modules"; $agent_modules = db_get_all_rows_sql($sql); ui_pagination( @@ -315,7 +351,7 @@ function mainAgentsAlerts() } html_print_table($table); - } else { + } else { $filter = [ 'offset' => (int) $offset, 'limit' => (int) $config['block_size'], @@ -329,10 +365,10 @@ function mainAgentsAlerts() // Get the id of all agents with alerts $sql = 'SELECT DISTINCT(id_agente) - FROM tagente_modulo - WHERE id_agente_modulo IN - (SELECT id_agent_module - FROM talert_template_modules)'; + FROM tagente_modulo + WHERE id_agente_modulo IN + (SELECT id_agent_module + FROM talert_template_modules)'; $agents_with_alerts_raw = db_get_all_rows_sql($sql); if ($agents_with_alerts_raw === false) { @@ -369,12 +405,12 @@ function mainAgentsAlerts() $agent_alerts[$alert['agent_name']][$alert['id_alert_template']][] = $alert; } - // Prepare pagination + // Prepare pagination. ui_pagination( $nagents, false, 0, - 0, + 3, false, 'offset', true, @@ -391,18 +427,12 @@ function mainAgentsAlerts() echo ''; echo "".__('Agents').' / '.__('Alert templates').''; - if ($hor_offset > 0) { - $new_hor_offset = ($hor_offset - $block); - echo " - ".html_print_image('images/darrowleft.png', true, ['title' => __('Previous templates')]).' '; - } - $templates_raw = []; if (!empty($templates)) { $sql = sprintf( 'SELECT id, name - FROM talert_templates - WHERE id IN (%s)', + FROM talert_templates + WHERE id IN (%s)', implode(',', array_keys($templates)) ); @@ -435,19 +465,14 @@ function mainAgentsAlerts() } echo ''; - if (($hor_offset + $block) < $ntemplates) { - $new_hor_offset = ($hor_offset + $block); - echo " - ".html_print_image('images/darrowright.png', true, ['title' => __('More templates')]).' '; - } foreach ($agents as $agent) { $alias = db_get_row('tagente', 'id_agente', $agent['id_agente']); echo ''; - // Name of the agent + // Name of the agent. echo ''.$alias['alias'].''; - // Alerts of the agent + // Alerts of the agent. $anyfired = false; foreach ($templates as $tid => $tname) { if ($tname == '') { @@ -488,6 +513,23 @@ function mainAgentsAlerts() echo ''; } + echo ''; + + if ($hor_offset > 0) { + $new_hor_offset = ($hor_offset - $block); + echo " + ".html_print_image('images/darrowleft.png', true, ['style' => 'float: right;', 'title' => __('Previous templates')]).' '; + } + + if (($hor_offset + $block) < $ntemplates) { + $new_hor_offset = ($hor_offset + $block); + echo ""; + echo "".html_print_image('images/darrowright.png', true, ['style' => 'float: right;', 'title' => __('More templates')]).""; + echo ''; + } + + echo ''; + echo ''; ui_pagination( @@ -506,146 +548,6 @@ function mainAgentsAlerts() ], 'alerts_agents' ); - } - -} - - -// Print the modal window for the summary of each alerts group -function print_alerts_summary_modal_window($id, $alerts) -{ - $table->width = '98%'; - $table->class = 'info_table'; - $table->data = []; - - $table->head[0] = __('Module'); - $table->head[1] = __('Action'); - $table->head[2] = __('Last fired'); - $table->head[3] = __('Status'); - - foreach ($alerts as $alert) { - $data[0] = modules_get_agentmodule_name($alert['id_agent_module']); - - $actions = alerts_get_alert_agent_module_actions($alert['id']); - - $actionDefault = db_get_value_sql( - ' - SELECT id_alert_action - FROM talert_templates - WHERE id = '.$alert['id_alert_template'] - ); - - $actionText = ''; - - if (!empty($actions)) { - $actionText = '
    '; - foreach ($actions as $action) { - $actionText .= '
  • '.$action['name']; - if ($action['fires_min'] != $action['fires_max']) { - $actionText .= ' ('.$action['fires_min'].' / '.$action['fires_max'].')'; - } - - $actionText .= '

  • '; - } - - $actionText .= '
'; - } else { - if (!empty($actionDefault)) { - $actionText = db_get_sql( - "SELECT name - FROM talert_actions - WHERE id = $actionDefault" - ).' ('.__('Default').')'; - } } - - $data[1] = $actionText; - $data[2] = ui_print_timestamp($alert['last_fired'], true); - - $status = STATUS_ALERT_NOT_FIRED; - - if ($alert['times_fired'] > 0) { - $status = STATUS_ALERT_FIRED; - $title = __('Alert fired').' '.$alert['internal_counter'].' '.__('time(s)'); - } else if ($alert['disabled'] > 0) { - $status = STATUS_ALERT_DISABLED; - $title = __('Alert disabled'); - } else { - $status = STATUS_ALERT_NOT_FIRED; - $title = __('Alert not fired'); - } - - $data[3] = ui_print_status_image($status, $title, true); - - array_push($table->data, $data); - } - - $content = html_print_table($table, true); - - $agent = modules_get_agentmodule_agent_alias($alerts[0]['id_agent_module']); - $template = alerts_get_alert_template_name($alerts[0]['id_alert_template']); - - echo ''; + */ } - - -extensions_add_operation_menu_option(__('Agents/Alerts view'), 'estado', null, 'v1r1', 'view'); -extensions_add_main_function('mainAgentsAlerts'); - -ui_require_jquery_file('pandora'); - -?> - - diff --git a/pandora_console/extensions/agents_modules.php b/pandora_console/extensions/agents_modules.php index 8aa032c9a8..5f9a984048 100644 --- a/pandora_console/extensions/agents_modules.php +++ b/pandora_console/extensions/agents_modules.php @@ -26,17 +26,6 @@ function agents_modules_load_js() $ignored_params['refresh'] = ''; ?> - - + + Date: Fri, 6 Nov 2020 12:38:06 +0100 Subject: [PATCH 03/13] Added html_print_anchor function for link tags --- pandora_console/include/functions_html.php | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index af6f5ceed9..7ffbda2417 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -2159,6 +2159,55 @@ function html_print_div($options, $return=false) } +/** + * Render an anchor html element. + * + * @param array $options Parameters + * - id: string + * - style: string + * - title: string + * - href: string. + * @param boolean $return Return or echo flag. + * + * @return string HTML code if return parameter is true. + */ +function html_print_anchor( + array $options, + bool $return=false +) { + $output = ' Date: Fri, 6 Nov 2020 12:38:35 +0100 Subject: [PATCH 04/13] WIP: Backup upload --- .../include/class/AgentsAlerts.class.php | 1139 ++++++++--------- 1 file changed, 550 insertions(+), 589 deletions(-) diff --git a/pandora_console/include/class/AgentsAlerts.class.php b/pandora_console/include/class/AgentsAlerts.class.php index 1d13db50cc..707e75cf17 100644 --- a/pandora_console/include/class/AgentsAlerts.class.php +++ b/pandora_console/include/class/AgentsAlerts.class.php @@ -85,7 +85,21 @@ class AgentsAlerts extends HTML /** * Full view parameter. */ - private $pure; + private $selectedFullScreen; + + /** + * Undocumented variable + * + * @var integer + */ + private $offset; + + /** + * Undocumented variable + * + * @var integer + */ + private $hor_offset; /** @@ -120,14 +134,17 @@ class AgentsAlerts extends HTML $this->ajaxController = $ajax_controller; // Refresh rate. $this->refreshSelectedRate = (string) get_parameter('refresh-rate', '30'); - // Show modules without alerts. - $this->showWithoutAlertModules = (bool) get_parameter('show-modules', false); + // Show Modules without alerts table. + $this->showWithoutAlertModules = isset($_POST['show-modules-without-alerts']); // Selected group. $this->groupId = (int) get_parameter('groupId', 0); // Create alert token. $this->createAlert = (int) get_parameter('create_alert', 0); // View token (for full screen view). - $this->pure = (int) get_parameter('full-screen-action', 0); + $this->selectedFullScreen = get_parameter('btn-full-screen', $config['pure']); + // Offset and hor-offset (for pagination). + $this->offset = (int) get_parameter('offset', 0); + $this->hor_offset = (int) get_parameter('hor_offset', 0); return $this; } @@ -140,8 +157,10 @@ class AgentsAlerts extends HTML */ public function run() { + global $config; // Javascript. ui_require_jquery_file('pandora'); + // Load own javascript file. $this->loadJS(); // CSS. ui_require_css_file('wizard'); @@ -154,10 +173,252 @@ class AgentsAlerts extends HTML 'v1r1', 'view' ); + + // Update network modules for this group + // Check for Network FLAG change request + // Made it a subquery, much faster on both the database and server side + // TODO. Check if this is used or necessary. + if (isset($_GET['update_netgroup'])) { + $group = get_parameter_get('update_netgroup', 0); + if (check_acl($config['id_user'], $group, 'AW')) { + $where = ['id_agente' => 'ANY(SELECT id_agente FROM tagente WHERE id_grupo = '.$group]; + + db_process_sql_update('tagente_modulo', ['flag' => 1], $where); + } else { + db_pandora_audit('ACL Violation', 'Trying to set flag for groups'); + include 'general/noaccess.php'; + exit; + } + } + // Load the header. - // extensions_add_main_function($this->loadHeader()); $this->loadHeader(); - // Load table. + // If the petition wants to create alert + if ($this->createAlert) { + $this->createAlertAction(); + } + + if ($this->showWithoutAlertModules === true) { + $this->createAlertTable(); + } else { + $this->loadMainAlertTable(); + } + } + + + /** + * + */ + private function createAlertTable() + { + global $config; + + $table = new stdClass(); + + $group_id = $this->groupId; + + if ($group_id > 0) { + $grupo = ' AND tagente.id_grupo = '.$group_id; + } else { + $grupo = ''; + } + + $offset_modules = $this->offset; + + $sql_count = 'SELECT COUNT(tagente_modulo.nombre) FROM tagente_modulo + INNER JOIN tagente ON tagente.id_agente = tagente_modulo.id_agente + WHERE id_agente_modulo NOT IN (SELECT id_agent_module FROM talert_template_modules)'.$grupo; + + $count_agent_module = db_get_all_rows_sql($sql_count); + + $sql = 'SELECT tagente.alias, tagente_modulo.nombre, + tagente_modulo.id_agente_modulo FROM tagente_modulo + INNER JOIN tagente ON tagente.id_agente = tagente_modulo.id_agente + WHERE id_agente_modulo NOT IN (SELECT id_agent_module FROM talert_template_modules) '.$grupo.' LIMIT 20 OFFSET '.$offset_modules; + + $agent_modules = db_get_all_rows_sql($sql); + + ui_pagination( + $count_agent_module[0]['COUNT(tagente_modulo.nombre)'], + ui_get_url_refresh(), + 0, + 0, + false, + 'offset', + true, + '', + '', + false, + 'alerts_modules' + ); + + $table->width = '100%'; + $table->class = 'databox data'; + $table->id = 'table_agent_module'; + $table->data = []; + + $table->head[0] = __('Agents'); + $table->head[1] = __('Modules'); + $table->head[2] = __('Actions'); + + $table->style[0] = 'width: 25%;'; + $table->style[1] = 'width: 33%;'; + $table->style[2] = 'width: 33%;'; + + foreach ($agent_modules as $agent_module) { + // Let's build the table. + $data[0] = io_safe_output($agent_module['alias']); + $data[1] = io_safe_output($agent_module['nombre']); + $uniqid = $agent_module['id_agente_modulo']; + $data[2] = html_print_anchor( + [ + 'href' => sprintf( + 'javascript:show_add_alerts(\'%s\')', + $uniqid + ), + 'content' => html_print_image('images/add_mc.png', true), + ], + true + ); + + array_push($table->data, $data); + + $table2 = new stdClass(); + + $table2->width = '100%'; + $table2->id = 'table_add_alert'; + $table2->class = 'databox filters'; + $table2->data = []; + + $table2->data[0][0] = __('Actions'); + + $groups_user = users_get_groups($config['id_user']); + + if (!empty($groups_user)) { + $groups = implode(',', array_keys($groups_user)); + $sql = sprintf( + 'SELECT id, name FROM talert_actions WHERE id_group IN (%s)', + $groups + ); + + $actions = db_get_all_rows_sql($sql); + } + + $table2->data[0][1] = html_print_select( + index_array($actions, 'id', 'name'), + 'action_select', + '', + '', + __('Default action'), + '0', + true, + '', + true, + '', + false, + 'width: 250px;' + ); + $table2->data[0][1] .= ''; + + // Check ACLs for LM users. + if (check_acl($config['id_user'], 0, 'LM')) { + $table2->data[0][1] .= ''; + $table2->data[0][1] .= html_print_image('images/add.png', true); + $table2->data[0][1] .= ''.__('Create Action').''; + $table2->data[0][1] .= ''; + } + + $table2->data[1][0] = __('Template'); + $own_info = get_user_info($config['id_user']); + if ($own_info['is_admin'] || check_acl($config['id_user'], 0, 'PM')) { + $templates = alerts_get_alert_templates(false, ['id', 'name']); + } else { + $usr_groups = users_get_groups($config['id_user'], 'LW', true); + $filter_groups = ''; + $filter_groups = implode(',', array_keys($usr_groups)); + $templates = alerts_get_alert_templates(['id_group IN ('.$filter_groups.')'], ['id', 'name']); + } + + $table2->data[1][1] = html_print_select( + index_array($templates, 'id', 'name'), + 'template', + '', + '', + __('Select'), + 0, + true, + false, + true, + '', + false, + 'width: 250px;' + ); + + $table2->data[1][1] .= html_print_anchor( + [ + 'href' => '#', + 'class' => 'template_details invisible', + 'content' => html_print_image('images/zoom.png', true, ['class' => 'img_help']), + ], + true + ); + + // Check ACLs for LM users. + if (check_acl($config['id_user'], 0, 'LM')) { + $table2->data[1][1] .= html_print_anchor( + [ + 'href' => 'index.php?sec=galertas&sec2=godmode/alerts/configure_alert_template&pure='.$config['pure'], + 'content' => html_print_image('images/add.png', true).''.__('Create Template').'', + ] + ); + } + + $table2->data[2][0] = __('Threshold'); + $table2->data[2][1] = html_print_input_text('module_action_threshold', '0', '', 5, 7, true); + $table2->data[2][1] .= ' '.__('seconds'); + + $content2 = '
'; + + $content2 .= html_print_table($table2, true); + $content2 .= html_print_div( + [ + 'class' => 'action-buttons', + 'style' => 'width: '.$table2->width, + 'content' => html_print_submit_button(__('Add alert'), 'add', false, 'class="sub wand"', true).html_print_input_hidden('create_alert', $uniqid, true), + ] + ); + + $content2 .= '
'; + + $module_name = ui_print_truncate_text(io_safe_output($agent_module['nombre']), 40, false, true, false, '…', false); + + html_print_div( + [ + 'id' => 'add_alerts_dialog_'.$uniqid, + 'title' => __('Agent').': '.$agent_module['alias'].' / '.__('module').': '.$module_name, + 'style' => 'display:none', + 'content' => $content2, + ] + ); + } + + html_print_table($table); + } + + + private function mainAlertTable() + { } @@ -167,7 +428,7 @@ class AgentsAlerts extends HTML * * @return void */ - private function createAlert() + private function createAlertAction() { $template2 = get_parameter('template'); $module_action_threshold = get_parameter('module_action_threshold'); @@ -188,6 +449,268 @@ class AgentsAlerts extends HTML } + /** + * Undocumented function + * + * @return void + */ + public function loadMainAlertTable() + { + global $config; + + $block = 20; + + $filter = [ + 'offset' => (int) $this->offset, + 'limit' => (int) $config['block_size'], + ]; + + $filter_count = []; + + if ($this->groupId > 0) { + $filter['id_grupo'] = $this->groupId; + $filter_count['id_grupo'] = $this->groupId; + } + + // Get the id of all agents with alerts. + $sql = 'SELECT DISTINCT(id_agente) + FROM tagente_modulo + WHERE id_agente_modulo IN + (SELECT id_agent_module + FROM talert_template_modules)'; + $agents_with_alerts_raw = db_get_all_rows_sql($sql); + + if ($agents_with_alerts_raw === false) { + $agents_with_alerts_raw = []; + } + + $agents_with_alerts = []; + foreach ($agents_with_alerts_raw as $awar) { + $agents_with_alerts[] = $awar['id_agente']; + } + + $filter['id_agente'] = $agents_with_alerts; + $filter_count['id_agente'] = $agents_with_alerts; + + $agents = agents_get_agents($filter); + + $nagents = count(agents_get_agents($filter_count)); + + if ($agents == false) { + ui_print_info_message( + [ + 'no_close' => true, + 'message' => __('There are no agents with alerts'), + ] + ); + + return false; + } + + $all_alerts = agents_get_alerts_simple(); + + if ($config['pure'] == 1) { + $block = count($all_alerts); + } + + $templates = []; + $agent_alerts = []; + foreach ($all_alerts as $alert) { + $templates[$alert['id_alert_template']] = ''; + $agent_alerts[$alert['agent_name']][$alert['id_alert_template']][] = $alert; + } + + // Prepare pagination. + ui_pagination( + $nagents, + false, + 0, + 3, + false, + 'offset', + true, + '', + '', + [ + 'count' => '', + 'offset' => 'offset_param', + ], + 'alerts_agents' + ); + + echo ''; + echo ''; + echo ''; + + $templates_raw = []; + if (!empty($templates)) { + $sql = sprintf( + 'SELECT id, name + FROM talert_templates + WHERE id IN (%s)', + implode(',', array_keys($templates)) + ); + + $templates_raw = db_get_all_rows_sql($sql); + } + + if (empty($templates_raw)) { + $templates_raw = []; + } + + $alerts = []; + $ntemplates = 0; + if ($this->hor_offset > 0) { + $new_hor_offset = ($this->hor_offset - $block); + echo "'; + } + + foreach ($templates_raw as $temp) { + if (isset($templates[$temp['id']]) && $templates[$temp['id']] == '') { + $ntemplates++; + + if ($ntemplates <= $this->hor_offset || $ntemplates > ($this->hor_offset + $block)) { + continue; + } + + $templates[$temp['id']] = $temp['name']; + + if (empty($temp['name']) === false) { + $outputLine = html_print_div( + [ + 'id' => 'line_header_'.$temp['id'], + 'class' => 'rotate_text_module', + 'content' => ''.ui_print_truncate_text(io_safe_output($temp['name']), 20).'', + ], + true + ); + + echo sprintf('', $outputLine); + } + } + } + + if (($this->hor_offset + $block) < $ntemplates) { + $new_hor_offset = ($this->hor_offset + $block); + echo "'; + } + + echo ''; + + foreach ($agents as $agent) { + $alias = db_get_row('tagente', 'id_agente', $agent['id_agente']); + echo ''; + // Name of the agent. + echo ''; + + // Alerts of the agent. + $anyfired = false; + foreach ($templates as $tid => $tname) { + if ($tname == '') { + continue; + } + + echo ''; + } + + echo ''; + } + + echo '
'.__('Agents').' / '.__('Alerts').'"; + + html_print_anchor( + [ + 'href' => sprintf( + 'index.php?sec=extensions&sec2=extensions/agents_alerts&hor_offset=%s&offset=%s&group_id=%s', + $new_hor_offset, + $this->offset, + $this->groupId + ), + 'content' => html_print_image( + 'images/arrow_left_green.png', + true, + [ + 'style' => 'float: right;', + 'title' => __('Previous alerts'), + ] + ), + ] + ); + echo '%s"; + html_print_anchor( + [ + 'href' => sprintf( + 'index.php?sec=extensions&sec2=extensions/agents_alerts&hor_offset=%s&offset=%s&group_id=%s', + $new_hor_offset, + $this->offset, + $this->groupId + ), + 'content' => html_print_image( + 'images/arrow_right_green.png', + true, + [ + 'style' => 'float: right;', + 'title' => __('More alerts'), + ] + ), + ] + ); + echo '
'.$alias['alias'].''; + + if (isset($agent_alerts[$agent['nombre']][$tid])) { + foreach ($agent_alerts[$agent['nombre']][$tid] as $alert) { + if ($alert['times_fired'] > 0) { + $anyfired = true; + } + } + + if ($anyfired) { + $cellstyle = 'background:'.COL_ALERTFIRED.';'; + } else { + $cellstyle = 'background:'.COL_NORMAL.';'; + } + + $uniqid = uniqid(); + + html_print_anchor( + [ + 'href' => sprintf('javascript:show_alerts_details(\'%s\')', $uniqid), + 'content' => html_print_div( + [ + 'id' => 'line_header_'.$temp['id'], + 'class' => 'status_rounded_rectangles text_inside', + 'style' => $cellstyle, + 'content' => count($agent_alerts[$agent['nombre']][$tid]), + ], + true + ), + ] + ); + + $this->printAlertsSummaryModalWindow($uniqid, $agent_alerts[$agent['nombre']][$tid]); + } + + echo '
'; + // echo ''; + ui_pagination( + $nagents, + false, + 0, + 0, + false, + 'offset', + true, + 'pagination-bottom', + '', + [ + 'count' => '', + 'offset' => 'offset_param', + ], + 'alerts_agents' + ); + } + + /** * Show headers and filters * @@ -196,22 +719,6 @@ class AgentsAlerts extends HTML public function loadHeader() { global $config; - // Update network modules for this group - // Check for Network FLAG change request - // Made it a subquery, much faster on both the database and server side - // TODO - if (isset($_GET['update_netgroup'])) { - $group = get_parameter_get('update_netgroup', 0); - if (check_acl($config['id_user'], $group, 'AW')) { - $where = ['id_agente' => 'ANY(SELECT id_agente FROM tagente WHERE id_grupo = '.$group]; - - db_process_sql_update('tagente_modulo', ['flag' => 1], $where); - } else { - db_pandora_audit('ACL Violation', 'Trying to set flag for groups'); - include 'general/noaccess.php'; - exit; - } - } $updated_info = ''; @@ -221,13 +728,6 @@ class AgentsAlerts extends HTML $updated_time = $updated_info; - if ($create_alert) { - $this->createAlert(); - } - - // Get parameters. - $offset = (int) get_parameter('offset', 0); - $hor_offset = (int) get_parameter('hor_offset', 0); // Magic number? $block = 20; $groups = users_get_groups(); @@ -265,10 +765,10 @@ class AgentsAlerts extends HTML $this->printHeader(true) ); - // Start Filter form. + // Start Header form. $headerForm = [ 'action' => ui_get_full_url(), - 'id' => 'form-refresh-rate', + 'id' => 'form-header-filters', 'method' => 'POST', 'class' => 'modal flex flex-row', 'extra' => '', @@ -296,23 +796,17 @@ class AgentsAlerts extends HTML 'label' => __('Show modules without alerts'), 'id' => 'txt-use-agent-ip', 'arguments' => [ - 'name' => 'slides_ids[]', - 'value' => $this->showWithoutAlertModules, - 'input_class' => 'flex-row', - 'type' => 'checkbox', - 'class' => '', - 'return' => true, + 'name' => 'show-modules-without-alerts', + 'checked' => $this->showWithoutAlertModules, + 'input_class' => 'flex-row', + 'type' => 'checkbox', + 'class' => '', + 'disabled_hidden' => true, + 'return' => true, ], ]; - $selectedFullScreen = get_parameter('btn-full-screen', null); - $screenStatus = $config['pure']; - - if ($selectedFullScreen == null) { - $selectedFullScreen = $screenStatus; - } - - if ($selectedFullScreen == 0) { + if ($this->selectedFullScreen == 0) { $screenSwitchTitle = __('Full screen mode'); $screenSwitchClass = 'pure_full'; $screenSwitchPure = 1; @@ -392,375 +886,6 @@ class AgentsAlerts extends HTML ); echo $header; - - if ($show_modules) { - if ($group_id > 0) { - $grupo = " AND tagente.id_grupo = $group_id"; - } else { - $grupo = ''; - } - - $offset_modules = get_parameter('offset', 0); - $sql_count = "SELECT COUNT(tagente_modulo.nombre) FROM tagente_modulo - INNER JOIN tagente ON tagente.id_agente = tagente_modulo.id_agente - WHERE id_agente_modulo NOT IN (SELECT id_agent_module FROM talert_template_modules) - $grupo"; - $count_agent_module = db_get_all_rows_sql($sql_count); - - $sql = "SELECT tagente.alias, tagente_modulo.nombre, - tagente_modulo.id_agente_modulo FROM tagente_modulo - INNER JOIN tagente ON tagente.id_agente = tagente_modulo.id_agente - WHERE id_agente_modulo NOT IN (SELECT id_agent_module FROM talert_template_modules) - $grupo LIMIT 20 OFFSET $offset_modules"; - $agent_modules = db_get_all_rows_sql($sql); - - ui_pagination( - $count_agent_module[0]['COUNT(tagente_modulo.nombre)'], - ui_get_url_refresh(), - 0, - 0, - false, - 'offset', - true, - '', - '', - false, - 'alerts_modules' - ); - - $table->width = '100%'; - $table->class = 'databox data'; - $table->id = 'table_agent_module'; - $table->data = []; - - $table->head[0] = __('Agents'); - $table->head[1] = __('Modules'); - $table->head[2] = __('Actions'); - - $table->style[0] = 'width: 25%;'; - $table->style[1] = 'width: 33%;'; - $table->style[2] = 'width: 33%;'; - - foreach ($agent_modules as $agent_module) { - $data[0] = io_safe_output($agent_module['alias']); - $data[1] = io_safe_output($agent_module['nombre']); - $uniqid = $agent_module['id_agente_modulo']; - $data[2] = "".html_print_image('images/add_mc.png', true).''; - array_push($table->data, $data); - - $table2->width = '100%'; - $table2->id = 'table_add_alert'; - $table2->class = 'databox filters'; - $table2->data = []; - // $data[0] = - $table2->data[0][0] = __('Actions'); - - $groups_user = users_get_groups($config['id_user']); - if (!empty($groups_user)) { - $groups = implode(',', array_keys($groups_user)); - $sql = "SELECT id, name FROM talert_actions WHERE id_group IN ($groups)"; - $actions = db_get_all_rows_sql($sql); - } - - $table2->data[0][1] = html_print_select( - index_array($actions, 'id', 'name'), - 'action_select', - '', - '', - __('Default action'), - '0', - true, - '', - true, - '', - false, - 'width: 250px;' - ); - $table2->data[0][1] .= ''; - if (check_acl($config['id_user'], 0, 'LM')) { - $table2->data[0][1] .= ''; - $table2->data[0][1] .= html_print_image('images/add.png', true); - $table2->data[0][1] .= ''.__('Create Action').''; - $table2->data[0][1] .= ''; - } - - $table2->data[1][0] = __('Template'); - $own_info = get_user_info($config['id_user']); - if ($own_info['is_admin'] || check_acl($config['id_user'], 0, 'PM')) { - $templates = alerts_get_alert_templates(false, ['id', 'name']); - } else { - $usr_groups = users_get_groups($config['id_user'], 'LW', true); - $filter_groups = ''; - $filter_groups = implode(',', array_keys($usr_groups)); - $templates = alerts_get_alert_templates(['id_group IN ('.$filter_groups.')'], ['id', 'name']); - } - - $table2->data[1][1] = html_print_select( - index_array($templates, 'id', 'name'), - 'template', - '', - '', - __('Select'), - 0, - true, - false, - true, - '', - false, - 'width: 250px;' - ); - $table2->data[1][1] .= ' '; - if (check_acl($config['id_user'], 0, 'LM')) { - $table2->data[1][1] .= ''; - $table2->data[1][1] .= html_print_image('images/add.png', true); - $table2->data[1][1] .= ''.__('Create Template').''; - $table2->data[1][1] .= ''; - } - - $table2->data[2][0] = __('Threshold'); - $table2->data[2][1] = html_print_input_text('module_action_threshold', '0', '', 5, 7, true); - $table2->data[2][1] .= ' '.__('seconds'); - - $content2 = '
'; - $content2 .= html_print_table($table2, true); - - $content2 .= '
'; - $content2 .= html_print_submit_button(__('Add alert'), 'add', false, 'class="sub wand"', true); - $content2 .= html_print_input_hidden('create_alert', $uniqid, true); - $content2 .= '
'; - - $module_name = ui_print_truncate_text(io_safe_output($agent_module['nombre']), 40, false, true, false, '…', false); - echo ''; - } - - html_print_table($table); - } else { - $filter = [ - 'offset' => (int) $offset, - 'limit' => (int) $config['block_size'], - ]; - $filter_count = []; - - if ($group_id > 0) { - $filter['id_grupo'] = $group_id; - $filter_count['id_grupo'] = $group_id; - } - - // Get the id of all agents with alerts - $sql = 'SELECT DISTINCT(id_agente) - FROM tagente_modulo - WHERE id_agente_modulo IN - (SELECT id_agent_module - FROM talert_template_modules)'; - $agents_with_alerts_raw = db_get_all_rows_sql($sql); - - if ($agents_with_alerts_raw === false) { - $agents_with_alerts_raw = []; - } - - $agents_with_alerts = []; - foreach ($agents_with_alerts_raw as $awar) { - $agents_with_alerts[] = $awar['id_agente']; - } - - $filter['id_agente'] = $agents_with_alerts; - $filter_count['id_agente'] = $agents_with_alerts; - - $agents = agents_get_agents($filter); - - $nagents = count(agents_get_agents($filter_count)); - - if ($agents == false) { - ui_print_info_message( - [ - 'no_close' => true, - 'message' => __('There are no agents with alerts'), - ] - ); - - return false; - } - - $all_alerts = agents_get_alerts_simple(); - - if ($config['pure'] == 1) { - $block = count($all_alerts); - } - - $templates = []; - $agent_alerts = []; - foreach ($all_alerts as $alert) { - $templates[$alert['id_alert_template']] = ''; - $agent_alerts[$alert['agent_name']][$alert['id_alert_template']][] = $alert; - } - - // Prepare pagination. - ui_pagination( - $nagents, - false, - 0, - 3, - false, - 'offset', - true, - '', - '', - [ - 'count' => '', - 'offset' => 'offset_param', - ], - 'alerts_agents' - ); - - echo ''; - echo ''; - echo ''; - - $templates_raw = []; - if (!empty($templates)) { - $sql = sprintf( - 'SELECT id, name - FROM talert_templates - WHERE id IN (%s)', - implode(',', array_keys($templates)) - ); - - $templates_raw = db_get_all_rows_sql($sql); - } - - if (empty($templates_raw)) { - $templates_raw = []; - } - - $alerts = []; - $ntemplates = 0; - if ($hor_offset > 0) { - $new_hor_offset = ($hor_offset - $block); - echo "'; - } - - foreach ($templates_raw as $temp) { - if (isset($templates[$temp['id']]) && $templates[$temp['id']] == '') { - $ntemplates++; - if ($ntemplates <= $hor_offset || $ntemplates > ($hor_offset + $block)) { - continue; - } - - $templates[$temp['id']] = $temp['name']; - - if (empty($temp['name']) === false) { - $outputLine = html_print_div( - [ - 'id' => 'line_header_'.$temp['id'], - 'class' => 'rotate_text_module', - 'content' => ''.ui_print_truncate_text(io_safe_output($temp['name']), 20).'', - ], - true - ); - - echo sprintf('', $outputLine); - } - } - } - - if (($hor_offset + $block) < $ntemplates) { - $new_hor_offset = ($hor_offset + $block); - echo "'; - } - - echo ''; - - foreach ($agents as $agent) { - $alias = db_get_row('tagente', 'id_agente', $agent['id_agente']); - echo ''; - // Name of the agent. - echo ''; - - // Alerts of the agent. - $anyfired = false; - foreach ($templates as $tid => $tname) { - if ($tname == '') { - continue; - } - - echo ''; - } - - echo ''; - } - - echo '
'.__('Agents').' / '.__('Alerts').' - ".html_print_image('images/arrow_left_green.png', true, ['style' => 'float: right;', 'title' => __('Previous templates')]).' %s"; - echo "".html_print_image('images/arrow_right_green.png', true, ['style' => 'float: right;', 'title' => __('More templates')]).''; - echo '
'.$alias['alias'].''; - - if (isset($agent_alerts[$agent['nombre']][$tid])) { - foreach ($agent_alerts[$agent['nombre']][$tid] as $alert) { - if ($alert['times_fired'] > 0) { - $anyfired = true; - } - } - - $cellstyle = ''; - if ($anyfired) { - $cellstyle = 'background:'.COL_ALERTFIRED.';'; - } else { - $cellstyle = 'background:'.COL_NORMAL.';'; - } - - $uniqid = uniqid(); - - $row = ''; - - $row .= html_print_div( - [ - 'id' => 'line_header_'.$temp['id'], - 'class' => 'status_rounded_rectangles text_inside', - 'style' => $cellstyle, - 'content' => count($agent_alerts[$agent['nombre']][$tid]), - ], - true - ); - - $row .= ''; - - echo $row; - - $this->printAlertsSummaryModalWindow($uniqid, $agent_alerts[$agent['nombre']][$tid]); - } - - echo '
'; - // echo ''; - ui_pagination( - $nagents, - false, - 0, - 0, - false, - 'offset', - true, - 'pagination-bottom', - '', - [ - 'count' => '', - 'offset' => 'offset_param', - ], - 'alerts_agents' - ); - } - - // return $header; - } @@ -883,181 +1008,7 @@ class AgentsAlerts extends HTML */ public function loadTable() { - // $hor_offset - // $block - // $nagents - // $modules_by_name - // $group_id - // $agents - // $total_pagination - // - echo ''; - echo ''; - - echo "'; - - if ($hor_offset > 0) { - $new_hor_offset = ($hor_offset - $block); - echo "'; - } - - $nmodules = 0; - foreach ($modules_by_name as $module) { - $nmodules++; - - if ($nmodules <= $hor_offset || $nmodules > ($hor_offset + $block)) { - continue; - } - - $text = ui_print_truncate_text(io_safe_output($module['name']), 'module_small'); - - echo ''; - } - - if (($hor_offset + $block) < $nmodules) { - $new_hor_offset = ($hor_offset + $block); - echo "'; - } - - echo ''; - - $filter_agents = [ - 'offset' => (int) $offset, - 'disabled' => 0, - ]; - if ($group_id > 0) { - $filter_agents['id_grupo'] = $group_id; - } - - // Prepare pagination. - $url = 'index.php?extension_in_menu=estado&sec=extensions&sec2=extensions/agents_modules&save_serialize=1&hor_offset='.$hor_offset.'&selection_a_m='.$selection_a_m; - ui_pagination($total_pagination, $url); - - foreach ($agents as $agent) { - // Get stats for this group. - $agent_status = agents_get_status($agent['id_agente']); - $alias = db_get_row('tagente', 'id_agente', $agent['id_agente']); - if (empty($alias['alias'])) { - $alias['alias'] = $agent['nombre']; - } - - switch ($agent_status) { - case 4: - // Alert fired status. - $rowcolor = 'group_view_alrm'; - break; - - case 1: - // Critical status. - $rowcolor = 'group_view_crit'; - break; - - case 2: - // Warning status. - $rowcolor = 'group_view_warn'; - break; - - case 0: - // Normal status. - $rowcolor = 'group_view_ok'; - break; - - case 3: - case -1: - default: - // Unknown status. - $rowcolor = 'group_view_unk'; - break; - } - - echo ""; - - echo "'; - // TODO TAGS agents_get_modules. - $agent_modules = agents_get_modules($agent['id_agente'], false, $filter_module_group, true, true); - - $nmodules = 0; - foreach ($modules_by_name as $module) { - $nmodules++; - - if ($nmodules <= $hor_offset || $nmodules > ($hor_offset + $block)) { - continue; - } - - $match = false; - - foreach ($module['id'] as $module_id) { - if (!$match && array_key_exists($module_id, $agent_modules)) { - $status = modules_get_agentmodule_status($module_id); - echo "'; - $match = true; - } - } - - if (!$match) { - echo ''; - } - } - - echo ''; - } - - echo '
".__('Agents').' / '.__('Alerts').'".html_print_image( - 'images/arrow_left_green.png', - true, - ['title' => __('Previous modules')] - ).' -
- -
-
".html_print_image( - 'images/arrow_right_green.png', - true, - ['title' => __('More modules')] - ).'
- ".$alias['alias'].'"; - $win_handle = dechex(crc32($module_id.$module['name'])); - $graph_type = return_graphtype(modules_get_agentmodule_type($module_id)); - $link = "winopeng_var('".'operation/agentes/stat_win.php?'."type=$graph_type&".'period='.SECONDS_1DAY.'&'.'id='.$module_id.'&'.'refresh='.SECONDS_10MINUTES."', 'day_".$win_handle."', 800, 480)"; - - echo ''; - - $module_last_value = modules_get_last_value($module_id); - if (!is_numeric($module_last_value)) { - $module_last_value = htmlspecialchars($module_last_value); - } - - switch ($status) { - case AGENT_MODULE_STATUS_NORMAL: - ui_print_status_image('module_ok.png', $module_last_value, false); - break; - - case AGENT_MODULE_STATUS_CRITICAL_BAD: - ui_print_status_image('module_critical.png', $module_last_value, false); - break; - - case AGENT_MODULE_STATUS_WARNING: - ui_print_status_image('module_warning.png', $module_last_value, false); - break; - - case AGENT_MODULE_STATUS_UNKNOWN: - ui_print_status_image('module_unknown.png', $module_last_value, false); - break; - - case AGENT_MODULE_STATUS_NORMAL_ALERT: - case AGENT_MODULE_STATUS_WARNING_ALERT: - case AGENT_MODULE_STATUS_CRITICAL_ALERT: - ui_print_status_image('module_alertsfired.png', $module_last_value, false); - break; - - case 4: - ui_print_status_image('module_no_data.png', $module_last_value, false); - break; - } - - echo ''; - echo '
'; } @@ -1074,6 +1025,12 @@ class AgentsAlerts extends HTML Date: Tue, 10 Nov 2020 16:51:28 +0100 Subject: [PATCH 08/13] Fix error with category --- pandora_console/extensions/agents_alerts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/extensions/agents_alerts.php b/pandora_console/extensions/agents_alerts.php index 8d05430ef5..53ebe3d2e2 100755 --- a/pandora_console/extensions/agents_alerts.php +++ b/pandora_console/extensions/agents_alerts.php @@ -2,7 +2,7 @@ /** * Agents/Alerts Monitoring view. * - * @category Agent Wizard + * @category Operations * @package Pandora FMS * @subpackage Opensource * @version 1.0.0 From ed1b8f9713abea84fae62168b8a61bb94d219a54 Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Tue, 24 Nov 2020 15:51:02 +0100 Subject: [PATCH 09/13] Fix some bugs and added surround input feature --- .../include/class/AgentsAlerts.class.php | 198 ++++++++++-------- pandora_console/include/class/HTML.class.php | 10 + .../include/styles/agent_alerts.css | 57 +++++ pandora_console/include/styles/pandora.css | 6 - 4 files changed, 175 insertions(+), 96 deletions(-) create mode 100644 pandora_console/include/styles/agent_alerts.css diff --git a/pandora_console/include/class/AgentsAlerts.class.php b/pandora_console/include/class/AgentsAlerts.class.php index 5bc613ace7..4633320e03 100644 --- a/pandora_console/include/class/AgentsAlerts.class.php +++ b/pandora_console/include/class/AgentsAlerts.class.php @@ -82,11 +82,18 @@ class AgentsAlerts extends HTML private $createAlert; /** - * Full view parameter. + * Full screen variable. * * @var integer */ - private $selectedFullScreen; + private $pure; + + /** + * Config id user. + * + * @var string + */ + private $idUser; /** * Undocumented variable @@ -133,6 +140,10 @@ class AgentsAlerts extends HTML // Capture all parameters before start. $this->ajaxController = $ajaxController; + // Pure variable for full screen selection + $this->pure = $config['pure']; + // Id user. + $this->idUser = $config['id_user']; // Refresh rate. $this->refreshSelectedRate = (string) get_parameter('refresh-rate', '30'); // Show Modules without alerts table. @@ -141,8 +152,6 @@ class AgentsAlerts extends HTML $this->groupId = (int) get_parameter('group-id', 0); // Create alert token. $this->createAlert = (int) get_parameter('create_alert', 0); - // View token (for full screen view). - $this->selectedFullScreen = get_parameter('btn-full-screen', $config['pure']); // Offset and hor-offset (for pagination). $this->offset = (int) get_parameter('offset', 0); $this->horOffset = (int) get_parameter('hor_offset', 0); @@ -158,7 +167,6 @@ class AgentsAlerts extends HTML */ public function run() { - global $config; // Javascript. ui_require_jquery_file('pandora'); // Load own javascript file. @@ -166,14 +174,14 @@ class AgentsAlerts extends HTML // CSS. ui_require_css_file('wizard'); ui_require_css_file('discovery'); - + ui_require_css_file('agent_alerts'); // Update network modules for this group // Check for Network FLAG change request // Made it a subquery, much faster on both the database and server side // TODO. Check if this is used or necessary. if (isset($_GET['update_netgroup']) === true) { $group = get_parameter_get('update_netgroup', 0); - if (check_acl($config['id_user'], $group, 'AW')) { + if (check_acl($this->idUser, $group, 'AW')) { $where = ['id_agente' => 'ANY(SELECT id_agente FROM tagente WHERE id_grupo = '.$group]; db_process_sql_update('tagente_modulo', ['flag' => 1], $where); @@ -186,7 +194,7 @@ class AgentsAlerts extends HTML // Load the header. $this->loadHeader(); - // If the petition wants to create alert + // If the petition wants to create alert. if ($this->createAlert) { $this->createAlertAction(); } @@ -206,8 +214,6 @@ class AgentsAlerts extends HTML */ private function createAlertTable() { - global $config; - $table = new stdClass(); if ($this->groupId > 0) { @@ -285,7 +291,7 @@ class AgentsAlerts extends HTML $table2->data[0][0] = __('Actions'); - $groups_user = users_get_groups($config['id_user']); + $groups_user = users_get_groups($this->idUser); if (!empty($groups_user)) { $groups = implode(',', array_keys($groups_user)); @@ -325,10 +331,10 @@ class AgentsAlerts extends HTML $table2->data[0][1] .= ''; // Check ACLs for LM users. - if (check_acl($config['id_user'], 0, 'LM')) { + if (check_acl($this->idUser, 0, 'LM')) { $table2->data[0][1] .= html_print_anchor( [ - 'href' => 'index.php?sec=galertas&sec2=godmode/alerts/configure_alert_action&pure='.$this->selectedFullScreen, + 'href' => 'index.php?sec=galertas&sec2=godmode/alerts/configure_alert_action&pure='.$this->pure, 'style' => 'margin-left:5px;', 'content' => html_print_image('images/add.png', true).''.__('Create Action').'', ], @@ -337,11 +343,11 @@ class AgentsAlerts extends HTML } $table2->data[1][0] = __('Template'); - $own_info = get_user_info($config['id_user']); - if ($own_info['is_admin'] || check_acl($config['id_user'], 0, 'PM')) { + $own_info = get_user_info($this->idUser); + if ($own_info['is_admin'] || check_acl($this->idUser, 0, 'PM')) { $templates = alerts_get_alert_templates(false, ['id', 'name']); } else { - $usr_groups = users_get_groups($config['id_user'], 'LW', true); + $usr_groups = users_get_groups($this->idUser, 'LW', true); $filter_groups = ''; $filter_groups = implode(',', array_keys($usr_groups)); $templates = alerts_get_alert_templates(['id_group IN ('.$filter_groups.')'], ['id', 'name']); @@ -372,10 +378,10 @@ class AgentsAlerts extends HTML ); // Check ACLs for LM users. - if (check_acl($config['id_user'], 0, 'LM')) { + if (check_acl($this->idUser, 0, 'LM')) { $table2->data[1][1] .= html_print_anchor( [ - 'href' => 'index.php?sec=galertas&sec2=godmode/alerts/configure_alert_template&pure='.$this->selectedFullScreen, + 'href' => 'index.php?sec=galertas&sec2=godmode/alerts/configure_alert_template&pure='.$this->pure, 'style' => 'margin-left:5px;', 'content' => html_print_image('images/add.png', true).''.__('Create Template').'', ], @@ -509,7 +515,7 @@ class AgentsAlerts extends HTML $all_alerts = agents_get_alerts_simple(); - if ($config['pure'] == 1) { + if ($this->pure == 1) { $block = count($all_alerts); } @@ -525,7 +531,7 @@ class AgentsAlerts extends HTML $nagents, false, 0, - 3, + $filter['limit'], false, 'offset', true, @@ -538,9 +544,9 @@ class AgentsAlerts extends HTML 'alerts_agents' ); - echo ''; + echo '
'; echo ''; - echo ''; + echo ''; $templates_raw = []; if (!empty($templates)) { @@ -565,7 +571,7 @@ class AgentsAlerts extends HTML $ntemplates = 0; if ($this->horOffset > 0) { $new_hor_offset = ($this->horOffset - $block); - echo "', $outputLine); + echo sprintf('', $outputLine); } } } if (($this->horOffset + $block) < $ntemplates) { $new_hor_offset = ($this->horOffset + $block); - echo "
'.__('Agents').' / '.__('Alerts').''.__('Agents').' / '.__('Alerts').'"; + echo ""; html_print_anchor( [ @@ -574,7 +580,7 @@ class AgentsAlerts extends HTML $new_hor_offset, $this->offset, $this->groupId, - $this->selectedFullScreen + $this->pure ), 'content' => html_print_image( 'images/arrow_left_green.png', @@ -603,21 +609,21 @@ class AgentsAlerts extends HTML $outputLine = html_print_div( [ 'id' => 'line_header_'.$temp['id'], - 'class' => 'rotate_text_module', - 'style' => 'margin: 0 -50px;', + 'class' => 'rotate_text_module position_text_module center', + 'style' => '', 'content' => ''.ui_print_truncate_text(io_safe_output($temp['name']), 20).'', ], true ); - echo sprintf('%s%s"; + echo ""; html_print_anchor( [ 'href' => sprintf( @@ -625,7 +631,7 @@ class AgentsAlerts extends HTML $new_hor_offset, $this->offset, $this->groupId, - $this->selectedFullScreen + $this->pure ), 'content' => html_print_image( 'images/arrow_right_green.png', @@ -658,7 +664,7 @@ class AgentsAlerts extends HTML continue; } - echo ''; + echo ''; if (isset($agent_alerts[$alias['alias']][$tid])) { foreach ($agent_alerts[$alias['alias']][$tid] as $alert) { @@ -727,48 +733,49 @@ class AgentsAlerts extends HTML */ public function loadHeader() { - global $config; + if ($this->pure == 0) { + // Breadcrums. + $this->setBreadcrum([]); - // Breadcrums. - $this->setBreadcrum([]); - - $this->prepareBreadcrum( - [ + $this->prepareBreadcrum( [ - 'link' => '', - 'label' => __('Monitoring'), - 'selected' => false, + [ + 'link' => '', + 'label' => __('Monitoring'), + 'selected' => false, + ], + [ + 'link' => '', + 'label' => __('Views'), + 'selected' => true, + ], ], - [ - 'link' => '', - 'label' => __('Views'), - 'selected' => true, - ], - ], - true - ); + true + ); - ui_print_page_header( - __('Agents/Alerts'), - '', - false, - '', - true, - '', - false, - '', - GENERIC_SIZE_TEXT, - '', - $this->printHeader(true) - ); + ui_print_page_header( + __('Agents/Alerts'), + '', + false, + '', + true, + '', + false, + '', + GENERIC_SIZE_TEXT, + '', + $this->printHeader(true) + ); + } // Start Header form. $headerForm = [ - 'action' => ui_get_full_url(), - 'id' => 'form-header-filters', - 'method' => 'POST', - 'class' => 'modal flex flex-row', - 'extra' => '', + 'action' => ui_get_full_url(), + 'id' => 'form-header-filters', + 'method' => 'POST', + 'class' => 'modal flex flex-row', + 'extra' => '', + 'onsubmit' => '', ]; $headerInputs = []; @@ -804,7 +811,7 @@ class AgentsAlerts extends HTML ], ]; - if ($this->selectedFullScreen == 0) { + if ($this->pure == 0) { $screenSwitchTitle = __('Full screen mode'); $screenSwitchClass = 'pure_full'; $screenSwitchPure = 1; @@ -829,16 +836,29 @@ class AgentsAlerts extends HTML 'arguments' => [ 'name' => 'pure', 'type' => 'hidden', - 'value' => $config['pure'], + 'value' => $this->pure, 'return' => true, ], ]; $headerInputs[] = [ - 'label' => __('Refresh'), - 'id' => 'slc-refresh-rate', - 'class' => ($refreshVisibility === true) ? '' : 'invisible', - 'arguments' => [ + 'label' => __('Full screen'), + 'id' => 'img-full-screen', + 'surround_start' => '
', + 'arguments' => [ + 'type' => 'button', + 'return' => true, + 'name' => 'pure', + 'attributes' => 'class="full_screen_button '.$screenSwitchClass.'" title="'.$screenSwitchTitle.'"', + ], + ]; + + $headerInputs[] = [ + 'label' => __('Refresh'), + 'id' => 'slc-refresh-rate', + 'class' => ($refreshVisibility === true) ? '' : 'invisible', + 'surround_end' => '
', + 'arguments' => [ 'name' => 'refresh-rate', 'input_class' => 'flex-row', 'type' => 'select', @@ -850,21 +870,6 @@ class AgentsAlerts extends HTML ], ]; - $headerInputs[] = [ - 'label' => __('Full screen'), - 'id' => 'img-full-screen', - 'arguments' => [ - 'type' => 'submit', - 'return' => true, - 'name' => 'pure', - 'label' => $screenSwitchPure, - 'attributes' => [ - 'title' => $screenSwitchTitle, - 'class' => 'full_screen_button '.$screenSwitchClass, - ], - ], - ]; - $filterForm = $this->printForm( [ 'form' => $headerForm, @@ -877,7 +882,7 @@ class AgentsAlerts extends HTML // Prints the header controls. $header = html_print_div( [ - 'class' => 'white_box', + 'class' => 'white_box agents_alerts_header', 'content' => $filterForm, ], true @@ -1001,15 +1006,28 @@ class AgentsAlerts extends HTML