diff --git a/extras/PandoraFMS_android_console/src/pandorafms/pandorafmsandroidconsole/ConnectionCustomToast.java b/extras/PandoraFMS_android_console/src/pandorafms/pandorafmsandroidconsole/ConnectionCustomToast.java index 8540370a2b..5026d96d98 100644 --- a/extras/PandoraFMS_android_console/src/pandorafms/pandorafmsandroidconsole/ConnectionCustomToast.java +++ b/extras/PandoraFMS_android_console/src/pandorafms/pandorafmsandroidconsole/ConnectionCustomToast.java @@ -2,7 +2,7 @@ Pandora FMS - http://pandorafms.com ================================================== -Copyright (c) 2005-2021 Artica Soluciones Tecnologicas +Copyright (c) 2005-2023 Pandora FMS Please see http://pandorafms.org for full contribution list This program is free software; you can redistribute it and/or diff --git a/extras/PandoraFMS_android_console/src/pandorafms/pandorafmsandroidconsole/Help.java b/extras/PandoraFMS_android_console/src/pandorafms/pandorafmsandroidconsole/Help.java index 32d73a7fa8..60708495c1 100644 --- a/extras/PandoraFMS_android_console/src/pandorafms/pandorafmsandroidconsole/Help.java +++ b/extras/PandoraFMS_android_console/src/pandorafms/pandorafmsandroidconsole/Help.java @@ -2,7 +2,7 @@ Pandora FMS - http://pandorafms.com ================================================== -Copyright (c) 2005-2021 Artica Soluciones Tecnologicas +Copyright (c) 2005-2023 Pandora FMS Please see http://pandorafms.org for full contribution list This program is free software; you can redistribute it and/or diff --git a/extras/PandoraFMS_android_console/src/pandorafms/pandorafmsandroidconsole/Options.java b/extras/PandoraFMS_android_console/src/pandorafms/pandorafmsandroidconsole/Options.java index 2cd8542fa0..782448ace6 100644 --- a/extras/PandoraFMS_android_console/src/pandorafms/pandorafmsandroidconsole/Options.java +++ b/extras/PandoraFMS_android_console/src/pandorafms/pandorafmsandroidconsole/Options.java @@ -2,7 +2,7 @@ Pandora FMS - http://pandorafms.com ================================================== -Copyright (c) 2005-2021 Artica Soluciones Tecnologicas +Copyright (c) 2005-2023 Pandora FMS Please see http://pandorafms.org for full contribution list This program is free software; you can redistribute it and/or diff --git a/extras/PandoraFMS_android_console/src/pandorafms/pandorafmsandroidconsole/PandoraWebView.java b/extras/PandoraFMS_android_console/src/pandorafms/pandorafmsandroidconsole/PandoraWebView.java index 4c566ff0f4..5b03bd03d3 100644 --- a/extras/PandoraFMS_android_console/src/pandorafms/pandorafmsandroidconsole/PandoraWebView.java +++ b/extras/PandoraFMS_android_console/src/pandorafms/pandorafmsandroidconsole/PandoraWebView.java @@ -2,7 +2,7 @@ Pandora FMS - http://pandorafms.com ================================================== -Copyright (c) 2005-2021 Artica Soluciones Tecnologicas +Copyright (c) 2005-2023 Pandora FMS Please see http://pandorafms.org for full contribution list This program is free software; you can redistribute it and/or diff --git a/extras/android-event-viewer/app/src/main/AndroidManifest.xml b/extras/android-event-viewer/app/src/main/AndroidManifest.xml index 56e27364eb..1678445c33 100644 --- a/extras/android-event-viewer/app/src/main/AndroidManifest.xml +++ b/extras/android-event-viewer/app/src/main/AndroidManifest.xml @@ -2,7 +2,7 @@ @@ -952,6 +967,44 @@ echo sprintf('
', $menuTypeClass); $("#agent_access").css("display",""); }); + $("#welcome-icon-header").click(function () { + if (!$('#welcome_modal_window').length){ + $(document.body).append('
'); + $(document.body).append( $('').attr('href', 'include/styles/new_installation_welcome_window.css') ); + } + // Clean DOM. + load_modal({ + target: $('#welcome_modal_window'), + url: '', + modal: { + title: "", + cancel: '', + ok: '' + }, + onshow: { + page: 'include/ajax/welcome_window', + method: 'loadWelcomeWindow', + }, + oncancel: { + page: 'include/ajax/welcome_window', + title: "", + method: 'cancelWelcome', + confirm: function (fn) { + confirmDialog({ + title: '', + message: '', + ok: '', + cancel: '', + onAccept: function() { + // Continue execution. + fn(); + } + }) + } + } + }); + }); + // Feedback. $("#feedback-header").click(function () { diff --git a/pandora_console/general/logon_ok.php b/pandora_console/general/logon_ok.php index cf5379bf91..6567347999 100644 --- a/pandora_console/general/logon_ok.php +++ b/pandora_console/general/logon_ok.php @@ -259,6 +259,8 @@ if (!empty($news)) { $output_news .= '
'; } else { + $text = str_replace(''; $(`#sub${this.id}`).hide(); }) } else if ($('#menu_full').hasClass('menu_full_collapsed')) { + $(".arrow_menu_right").each(function() { + $(this).removeClass('arrow_menu_right'); + $(this).addClass('arrow_menu_down'); + }); localStorage.setItem("menuType", "classic"); $('ul.submenu').css('left', '280px'); var menuType_val = localStorage.getItem("menuType"); @@ -273,6 +277,14 @@ echo ''; $('.menu_icon').mouseenter(function() { var menuType_val = localStorage.getItem("menuType"); if (!click_display && menuType_val === 'collapsed') { + $(".arrow_menu_down").each(function() { + $(this).removeClass('arrow_menu_down'); + $(this).addClass('arrow_menu_right'); + }); + $(".arrow_menu_up").each(function() { + $(this).removeClass('arrow_menu_up'); + $(this).addClass('arrow_menu_right'); + }); table_hover = $(this); handsIn = 1; openTime = new Date().getTime(); @@ -305,6 +317,7 @@ echo ''; table_hover2 = $(this); handsIn2 = 1; openTime2 = new Date().getTime(); + $("#sub" + table_hover2[0].id).attr('style', 'display: none; position: fixed; left: 340px;'); $("#sub" + table_hover2[0].id).show(); if (typeof(table_noHover2) != 'undefined') { if ("ul#sub" + table_hover2[0].id != "ul#sub" + table_noHover2[0].id) { @@ -315,6 +328,7 @@ echo ''; }).mouseleave(function() { var menuType_val = localStorage.getItem("menuType"); if (!click_display && menuType_val === 'collapsed') { + $("#sub" + $(this)[0].id).attr('style', 'display: none;'); table_noHover2 = table_hover2; handsIn2 = 0; setTimeout(function() { @@ -349,7 +363,7 @@ echo ''; const id = table_hover[0].id; const classes = $(`#${id}`).attr('class'); - if (id === 'icon_about') { + if (id === 'icon_about' || id === 'icon_about_operation') { return; } @@ -474,4 +488,10 @@ echo ''; return height_logo + height_tabs + padding_menu + height_position; } }); + + + $('#icon_god-extensions').find('span').attr('style', 'white-space: nowrap;'); + \ No newline at end of file diff --git a/pandora_console/general/register.php b/pandora_console/general/register.php index 96f9232dab..759e319dbd 100644 --- a/pandora_console/general/register.php +++ b/pandora_console/general/register.php @@ -100,21 +100,23 @@ if ($initial && users_is_admin()) { ); } -$welcome = !$initial; -try { - $welcome_window = new WelcomeWindow($welcome); - if ($welcome_window !== null) { - $welcome_window->run(); +if (check_acl($config['id_user'], 0, 'AW')) { + $welcome = !$initial; + try { + $welcome_window = new WelcomeWindow($welcome); + if ($welcome_window !== null) { + $welcome_window->run(); + } + } catch (Exception $e) { + $welcome = false; } -} catch (Exception $e) { - $welcome = false; } try { if (isset($_SESSION['showed_tips_window']) === false) { $tips_window = new TipsWindow(); if ($tips_window !== null) { - $tips_window->run(); + $tips_window->run(); } } } catch (Exception $e) { diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 6efd958c5f..70c2b1cf60 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -212,7 +212,7 @@ $groups = users_get_groups($config['id_user'], 'AR', false); // Get modules. $modules = db_get_all_rows_sql( 'SELECT id_agente_modulo as id_module, nombre as name FROM tagente_modulo - WHERE id_agente = '.$id_parent + WHERE id_agente = '.$id_agente ); $modules_values = []; $modules_values[0] = __('Any'); @@ -300,7 +300,7 @@ if (enterprise_installed() === true) { // Parent agents. $paramsParentAgent = []; $paramsParentAgent['return'] = true; -$paramsParentAgent['show_helptip'] = false; +$paramsParentAgent['show_helptip'] = true; $paramsParentAgent['input_name'] = 'id_parent'; $paramsParentAgent['print_hidden_input_idagent'] = true; $paramsParentAgent['hidden_input_idagent_name'] = 'id_agent_parent'; @@ -646,7 +646,7 @@ if (enterprise_installed() === true) { // Parent agent. $tableAdvancedAgent->data['parent_agent'][] = html_print_label_input_block( - __('Parent'), + __('Agent parent'), ui_print_agent_autocomplete_input($paramsParentAgent) ); @@ -931,7 +931,7 @@ foreach ($fields as $field) { // Filling the data. $combo = []; $combo = $field['combo_values']; - $combo = explode(',', $combo); + $combo = explode(',', (empty($combo) === true) ? '' : $combo); $combo_values = []; foreach ($combo as $value) { $combo_values[$value] = $value; @@ -965,7 +965,7 @@ foreach ($fields as $field) { true ); } else if ($field['is_link_enabled']) { - list($link_text, $link_url) = json_decode($custom_value, true); + list($link_text, $link_url) = json_decode(io_safe_output($custom_value), true); if (json_last_error() !== JSON_ERROR_NONE) { $link_text = ''; @@ -1205,15 +1205,30 @@ ui_require_jquery_file('bgiframe'); $("#cascade_protection_module").attr("disabled", 'disabled'); } - $("#checkbox-cascade_protection").change(function () { - var checked = $("#checkbox-cascade_protection").is(":checked"); - - if (checked) { + $("#text-id_parent").change(function(){ + const parent = $("#text-id_parent").val(); + if (parent != '') { + $("#checkbox-cascade_protection").prop('checked', true); $("#cascade_protection_module").removeAttr("disabled"); } else { $("#cascade_protection_module").val(0); $("#cascade_protection_module").attr("disabled", 'disabled'); + $("#text-id_parent").removeAttr("required"); + $("#cascade_protection_module").empty(); + $("#checkbox-cascade_protection").prop('checked', false); + } + }); + + $("#checkbox-cascade_protection").change(function () { + var checked = $("#checkbox-cascade_protection").is(":checked"); if (checked) { + $("#cascade_protection_module").removeAttr("disabled"); + $("#text-id_parent").attr("required", "required"); + } + else { + $("#cascade_protection_module").val(0); + $("#cascade_protection_module").attr("disabled", 'disabled'); + $("#text-id_parent").removeAttr("required"); } }); diff --git a/pandora_console/godmode/agentes/agent_template.php b/pandora_console/godmode/agentes/agent_template.php index 163fc16af8..9c080fcf3f 100644 --- a/pandora_console/godmode/agentes/agent_template.php +++ b/pandora_console/godmode/agentes/agent_template.php @@ -80,7 +80,7 @@ if (isset($_POST['template_id']) === true) { $values = [ 'id_agente' => $id_agente, 'id_tipo_modulo' => $row2['type'], - 'descripcion' => __('Created by template ').$name_template.' . '.$row2['description'], + 'descripcion' => $row2['description'], 'max' => $row2['max'], 'min' => $row2['min'], 'module_interval' => $row2['module_interval'], diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index c68d483eaf..44823bfd6d 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -460,6 +460,18 @@ if ($id_agente) { $templatetab['active'] = ($tab === 'template'); + // Policy tab. + $policyTab['text'] = html_print_menu_button( + [ + 'href' => 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=policy&id_agente='.$id_agente, + 'image' => 'images/policy@svg.svg', + 'title' => __('Manage policy'), + ], + true + ); + + $policyTab['active'] = ($tab === 'policy'); + // Inventory. $inventorytab['text'] = ''.html_print_image( 'images/hardware-software-component@svg.svg', @@ -638,6 +650,7 @@ if ($id_agente) { 'template' => $templatetab, 'inventory' => $inventorytab, 'pluginstab' => $pluginstab, + 'policy' => (enterprise_installed() === true) ? $policyTab : '', 'collection' => $collectiontab, 'group' => $grouptab, 'gis' => $gistab, @@ -654,11 +667,11 @@ if ($id_agente) { 'template' => $templatetab, 'inventory' => $inventorytab, 'pluginstab' => $pluginstab, + 'policy' => (enterprise_installed() === true) ? $policyTab : '', 'collection' => $collectiontab, 'group' => $grouptab, 'gis' => $gistab, 'agent_wizard' => $agent_wizard, - ]; } @@ -725,6 +738,11 @@ if ($id_agente) { $tab_name = __('Inventory'); break; + case 'policy': + $help_header = 'policy_tab'; + $tab_name = __('Policies'); + break; + case 'plugins': $help_header = 'plugins_tab'; $tab_name = __('Agent plugins'); @@ -1740,7 +1758,10 @@ if ($update_module) { ]; - if ($id_module_type == 30 || $id_module_type == 31 || $id_module_type == 32 || $id_module_type == 33) { + if ($id_module_type === 30 || $id_module_type === 31 + || $id_module_type === 32 || $id_module_type === 33 + || $id_module_type === 38 + ) { $plugin_parameter_split = explode(' ', $values['plugin_parameter']); $values['plugin_parameter'] = ''; @@ -1936,7 +1957,10 @@ if ($create_module) { 'warning_time' => $warning_time, ]; - if ($id_module_type === 30 || $id_module_type === 31 || $id_module_type === 32 || $id_module_type === 33) { + if ($id_module_type === 30 || $id_module_type === 31 + || $id_module_type === 32 || $id_module_type === 33 + || $id_module_type === 38 + ) { $plugin_parameter_split = explode(' ', $values['plugin_parameter']); $values['plugin_parameter'] = ''; @@ -2428,6 +2452,10 @@ switch ($tab) { include 'inventory_manager.php'; break; + case 'policy': + enterprise_include('operation/agentes/policy_manager.php'); + break; + default: if (enterprise_hook('switch_agent_tab', [$tab])) { // This will make sure that blank pages will have at least some diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php index 4f28d256cd..a14bff4b92 100644 --- a/pandora_console/godmode/agentes/modificar_agente.php +++ b/pandora_console/godmode/agentes/modificar_agente.php @@ -996,6 +996,8 @@ if ($agents !== false) { $tableAgents->data[$key][6] = $actionButtonsColumn; } + $total_items = '
'.sprintf(__('Total items: %s'), $total_agents).'
'; + echo $total_items; html_print_table($tableAgents); $tablePagination = ui_pagination( @@ -1072,16 +1074,20 @@ if ((bool) check_acl($config['id_user'], 0, 'AW') === true) { function () { $(".actions", this).css ("visibility", "hidden"); }); - + $("#ag_group").click ( function () { $(this).css ("width", "auto"); $(this).css ("min-width", "100px"); }); - + $("#ag_group").blur (function () { $(this).css ("width", "100px"); }); - + + var show_deploy_agent = ""; + if (show_deploy_agent !== '0'){ + $('#button-modal_deploy_agent').click(); + } }); diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index 19ea5e2340..5c21fa71a0 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -116,7 +116,6 @@ ui_toggle( echo ''; - if (isset($id_agente) === false) { return; } diff --git a/pandora_console/godmode/agentes/module_manager_editor_common.php b/pandora_console/godmode/agentes/module_manager_editor_common.php index d63dff4035..f70af23627 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_common.php +++ b/pandora_console/godmode/agentes/module_manager_editor_common.php @@ -407,8 +407,7 @@ if ($edit_module === true) { $help_header = 'local_module'; } - if ($id_module_type === 6 || $id_module_type === 7 - ) { + if ($id_module_type === 6 || $id_module_type === 7) { $help_header = 'icmp_module_tab'; } @@ -420,7 +419,7 @@ if ($edit_module === true) { $help_header = 'tcp_module_tab'; } - if ($id_module_type >= 30 && $id_module_type <= 33) { + if (($id_module_type >= 30 && $id_module_type <= 33) || $id_module_type === 38) { $help_header = 'webserver_module_tab'; } } @@ -1847,6 +1846,22 @@ $(document).ready (function () { setModuleType(type_name_selected); }); + $('#checkbox-warning_inverse_string').change( function () { + if ($(this).prop('checked') === true) { + $('input[name="warning_thresholds_checks"]').val('warning_inverse'); + } else { + $('input[name="warning_thresholds_checks"]').val('normal_warning'); + } + }); + + $('#checkbox-critical_inverse_string').change( function () { + if ($(this).prop('checked') === true) { + $('input[name="critical_thresholds_checks"]').val('critical_inverse'); + } else { + $('input[name="critical_thresholds_checks"]').val('normal_critical'); + } + }); + function setModuleType(type_name_selected) { if (type_name_selected.match(/_string$/) == null) { // Hide string fields. diff --git a/pandora_console/godmode/agentes/module_manager_editor_network.php b/pandora_console/godmode/agentes/module_manager_editor_network.php index b8233fe89d..656dac2b0b 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_network.php +++ b/pandora_console/godmode/agentes/module_manager_editor_network.php @@ -233,14 +233,13 @@ if ($adopt === false) { } $snmp_versions['1'] = 'v. 1'; -$snmp_versions['2'] = 'v. 2'; $snmp_versions['2c'] = 'v. 2c'; $snmp_versions['3'] = 'v. 3'; $snmpVersionsInput = html_print_select( $snmp_versions, 'snmp_version', - ($id_module_type >= 15 && $id_module_type <= 18) ? $snmp_version : 0, + ($id_module_type >= 15 && $id_module_type <= 18) ? $snmp_version : '2c', '', '', '', diff --git a/pandora_console/godmode/agentes/module_manager_editor_plugin.php b/pandora_console/godmode/agentes/module_manager_editor_plugin.php index 0744a5849e..970a2c4d9f 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_plugin.php +++ b/pandora_console/godmode/agentes/module_manager_editor_plugin.php @@ -171,6 +171,8 @@ foreach ($password_fields as $k => $p) { } $(document).ready(function () { - changePluginSelect(); + if ($("#id_plugin").val() === 0) { + changePluginSelect(); + } }); diff --git a/pandora_console/godmode/agentes/module_manager_editor_web.php b/pandora_console/godmode/agentes/module_manager_editor_web.php index 281963108a..727e16d5bf 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_web.php +++ b/pandora_console/godmode/agentes/module_manager_editor_web.php @@ -113,7 +113,8 @@ if ($id_policy_module > 0) { $plugin_parameter_split = explode(' ', $plugin_parameter); $plugin_parameter_final_split = ''; -foreach ($plugin_parameter_split as $key => $value) { +$new_plugin_parameter_split = array_filter($plugin_parameter_split, 'strlen'); +foreach ($new_plugin_parameter_split as $key => $value) { if (strpos($value, 'http_auth_user') === false && strpos($value, 'http_auth_pass') === false) { $plugin_parameter_final_split .= $value.' '; } @@ -317,8 +318,7 @@ foreach ($texts as $code => $text) { return; } - $(plugin_parameter).val( - 'task_begin\ncookie 0\nresource 0\ntask_end'); + $(plugin_parameter).val('task_begin\ncookie 0\nresource 0\ntask_end'); $('#button-btn_loadbasic').attr('disabled', 'disabled'); diff --git a/pandora_console/godmode/agentes/planned_downtime.list.php b/pandora_console/godmode/agentes/planned_downtime.list.php index 4669b98858..959db70ed6 100755 --- a/pandora_console/godmode/agentes/planned_downtime.list.php +++ b/pandora_console/godmode/agentes/planned_downtime.list.php @@ -89,7 +89,7 @@ if (is_ajax() === true) { [ 'id' => 'agent_modules_affected_planned_downtime', 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => 'godmode/agentes/planned_downtime.list', @@ -835,7 +835,7 @@ if ($downtimes === false && $filter_performed === false) { // If user have writting permissions. if (in_array($downtime['id_group'], $groupsAD) === true) { // Stop button. - if ($downtime['type_execution'] === 'once' + if (($downtime['type_execution'] === 'once' || $downtime['type_execution'] === 'periodically') && (int) $downtime['executed'] === 1 ) { if ((bool) check_acl_restricted_all($config['id_user'], $downtime['id_group'], 'AW') === true diff --git a/pandora_console/godmode/alerts/alert_actions.php b/pandora_console/godmode/alerts/alert_actions.php index b972e1ff5a..97a492809e 100644 --- a/pandora_console/godmode/alerts/alert_actions.php +++ b/pandora_console/godmode/alerts/alert_actions.php @@ -333,7 +333,7 @@ $show_table_filter .= ui_toggle( __('Search'), 'search', true, - false, + true, '', 'white-box-content no_border', 'filter-datatable-main box-flat white_table_graph fixed_filter_bar ' diff --git a/pandora_console/godmode/alerts/alert_commands.php b/pandora_console/godmode/alerts/alert_commands.php index 771a842cc3..75a80d8d57 100644 --- a/pandora_console/godmode/alerts/alert_commands.php +++ b/pandora_console/godmode/alerts/alert_commands.php @@ -725,17 +725,17 @@ if ($copy_command) { $is_management_allowed = is_management_allowed(); if ($is_management_allowed === false) { if (is_metaconsole() === false) { - $url = '
'.__('metaconsole').''; } else { - $url = __('any node'); + $url_redirect = __('any node'); } ui_print_warning_message( __( 'This node is configured with centralized mode. All alert commands information is read only. Go to %s to manage it.', - $url + $url_redirect ) ); } @@ -807,12 +807,12 @@ foreach ($commands as $command) { // (IMPORTANT, DO NOT CHANGE!) only users with permissions over "All" group have access to edition of commands belonging to "All" group. if ($is_management_allowed === true && !$command['internal'] && check_acl_restricted_all($config['id_user'], $command['id_group'], 'LM')) { if (is_user_admin($config['id_user']) === true) { - $data['action'] = ''; + $data['action'] = ''; $data['action'] .= ''.html_print_image('images/copy.svg', true, ['class' => 'main_menu_icon invert_filter']).''; + onClick="if (!confirm(\''.__('Are you sure?').'\')) return false;">'.html_print_image('images/copy.svg', true, ['class' => 'main_menu_icon invert_filter ', 'title' => 'Duplicate']).''; $data['action'] .= ''.html_print_image('images/delete.svg', true, ['class' => 'main_menu_icon invert_filter']).''; + onClick="if (!confirm(\''.__('Are you sure?').'\')) return false;">'.html_print_image('images/delete.svg', true, ['class' => 'main_menu_icon invert_filter', 'title' => 'Delete']).''; $data['action'] .= ''; } } diff --git a/pandora_console/godmode/alerts/alert_list.builder.php b/pandora_console/godmode/alerts/alert_list.builder.php index b68ae38162..de07bce961 100644 --- a/pandora_console/godmode/alerts/alert_list.builder.php +++ b/pandora_console/godmode/alerts/alert_list.builder.php @@ -40,27 +40,45 @@ $table->size = []; $table->style[0] = 'width: 50%'; $table->style[1] = 'width: 50%'; -// Add an agent selector -if (! $id_agente) { +$modules = []; + +if (is_metaconsole() === true) { $params = []; $params['return'] = true; $params['show_helptip'] = true; $params['input_name'] = 'id_agent'; $params['selectbox_id'] = 'id_agent_module'; $params['javascript_is_function_select'] = true; - $params['metaconsole_enabled'] = false; + $params['metaconsole_enabled'] = true; $params['use_hidden_input_idagent'] = true; $params['print_hidden_input_idagent'] = true; + $params['javascript_page'] = 'enterprise/meta/include/ajax/events.ajax'; + $table->data[0][0] = html_print_label_input_block( __('Agent'), - ui_print_agent_autocomplete_input($params) + '
'.ui_print_agent_autocomplete_input($params).'
' ); -} +} else { + // Add an agent selector. + if (! $id_agente) { + $params = []; + $params['return'] = true; + $params['show_helptip'] = true; + $params['input_name'] = 'id_agent'; + $params['selectbox_id'] = 'id_agent_module'; + $params['javascript_is_function_select'] = true; + $params['metaconsole_enabled'] = false; + $params['use_hidden_input_idagent'] = true; + $params['print_hidden_input_idagent'] = true; + $table->data[0][0] = html_print_label_input_block( + __('Agent'), + ui_print_agent_autocomplete_input($params) + ); + } -$modules = []; - -if ($id_agente) { - $modules = agents_get_modules($id_agente, false, ['delete_pending' => 0]); + if ($id_agente) { + $modules = agents_get_modules($id_agente, false, ['delete_pending' => 0]); + } } $table->data[0][1] = html_print_label_input_block( @@ -319,7 +337,8 @@ $(document).ready (function () { jQuery.post ( + "ajax.php", {"page" : "operation/agentes/estado_agente", "get_agent_module_last_value" : 1, - "id_agent_module" : this.value + "id_agent_module" : this.value, + "server_name" : $('#text-id_agent').val(), }, function (data, status) { if (data === false) { @@ -338,5 +357,4 @@ $(document).ready (function () { ); }); }); -/* ]]> */ diff --git a/pandora_console/godmode/alerts/alert_list.list.php b/pandora_console/godmode/alerts/alert_list.list.php index 136a170066..5dc0c78019 100644 --- a/pandora_console/godmode/alerts/alert_list.list.php +++ b/pandora_console/godmode/alerts/alert_list.list.php @@ -14,7 +14,7 @@ * |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______| * * ========================================================== - * Copyright (c) 2005-2022 Artica Soluciones Tecnol贸gicas S.L + * Copyright (c) 2005-2023 Pandora FMS * This code is NOT free software. This code is NOT licenced under GPL2 licence * You cannot redistribute it without written permission of copyright holder. * ============================================================================ @@ -912,7 +912,10 @@ foreach ($simple_alerts as $alert) { 1, 'padding:0px; width: 22px; height: 22px;', true, - ['class' => 'invert_filter main_menu_icon'] + [ + 'class' => 'invert_filter main_menu_icon', + 'title' => __('Enable'), + ] ); $data[4] .= html_print_input_hidden('enable_alert', 1, true); } else { @@ -922,7 +925,10 @@ foreach ($simple_alerts as $alert) { 1, 'padding:0px; width: 22px; height: 22px;', true, - ['class' => 'main_menu_icon'] + [ + 'class' => 'invert filter main_menu_icon', + 'title' => __('Disable'), + ] ); $data[4] .= html_print_input_hidden('disable_alert', 1, true); } @@ -940,7 +946,10 @@ foreach ($simple_alerts as $alert) { 1, 'padding:0px; width: 22px; height: 22px;', true, - ['class' => 'invert_filter main_menu_icon'] + [ + 'class' => 'invert_filter main_menu_icon', + 'title' => __('Standby off'), + ] ); $data[4] .= html_print_input_hidden('standbyon_alert', 1, true); } else { @@ -950,7 +959,10 @@ foreach ($simple_alerts as $alert) { 1, 'padding:0px; width: 22px; height: 22px;', true, - ['class' => 'invert_filter main_menu_icon'] + [ + 'class' => 'invert_filter main_menu_icon', + 'title' => __('Standby on'), + ] ); $data[4] .= html_print_input_hidden('standbyoff_alert', 1, true); } @@ -1139,8 +1151,7 @@ if (! $id_agente) { return false; }); - $("input[name=disable]").attr ("title", "") - .hover (function () { + $("input[name=disable]").hover (function () { $(this).attr ("src", ") - .hover (function () { + $("input[name=enable]").hover (function () { $(this).attr ("src", ") - .hover (function () { + $("input[name=standby_on]").hover (function () { $(this).attr ("src", ") - .hover (function () { + $("input[name=standby_off]").hover (function () { $(this).attr ("src", window.location.assign("index.php?sec=estado&sec2=operation/agentes/alerts_status")'; + } } if ($delete_alert) { + if (is_metaconsole()) { + if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) { + $server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0]; + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) !== NOERR) { + echo json_encode(false); + // Restore db connection. + metaconsole_restore_db(); + return; + } + } + } + $id_alert_agent_module = (int) get_parameter('id_alert'); $temp = db_get_row('talert_template_modules', 'id', $id_alert_agent_module); @@ -241,9 +273,27 @@ if ($delete_alert) { '', true ); + if (is_metaconsole()) { + // Restore db connection. + metaconsole_restore_db(); + echo ''; + } } if ($add_action) { + if (is_metaconsole()) { + if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) { + $server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0]; + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) !== NOERR) { + echo json_encode(false); + // Restore db connection. + metaconsole_restore_db(); + return; + } + } + } + $id_action = (int) get_parameter('action_select'); $id_alert_module = (int) get_parameter('id_alert_module'); $fires_min = (int) get_parameter('fires_min'); @@ -280,9 +330,28 @@ if ($add_action) { '', true ); + + if (is_metaconsole()) { + // Restore db connection. + metaconsole_restore_db(); + echo ''; + } } if ($update_action) { + if (is_metaconsole()) { + if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) { + $server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0]; + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) !== NOERR) { + echo json_encode(false); + // Restore db connection. + metaconsole_restore_db(); + return; + } + } + } + $alert_id = (int) get_parameter('alert_id'); $id_action = (int) get_parameter('action_select_ajax-'.$alert_id); $id_module_action = (int) get_parameter('id_module_action_ajax'); @@ -321,9 +390,28 @@ if ($update_action) { '', true ); + + if (is_metaconsole()) { + // Restore db connection. + metaconsole_restore_db(); + echo ''; + } } if ($delete_action) { + if (is_metaconsole()) { + if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) { + $server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0]; + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) !== NOERR) { + echo json_encode(false); + // Restore db connection. + metaconsole_restore_db(); + return; + } + } + } + $id_action = (int) get_parameter('id_action'); $id_alert = (int) get_parameter('id_alert'); @@ -348,6 +436,12 @@ if ($delete_action) { '', true ); + + if (is_metaconsole()) { + // Restore db connection. + metaconsole_restore_db(); + echo ''; + } } if ($enable_alert) { diff --git a/pandora_console/godmode/alerts/alert_view.php b/pandora_console/godmode/alerts/alert_view.php index cd5a271971..8d4d07e578 100644 --- a/pandora_console/godmode/alerts/alert_view.php +++ b/pandora_console/godmode/alerts/alert_view.php @@ -262,7 +262,7 @@ $data[1] = ''; $table_conditions->data[] = $data; $data[0] = __('Use special days list'); -$data[1] = (isset($alert['special_day']) && $alert['special_day'] == 1) ? __('Yes') : __('No'); +$data[1] = (isset($template['special_day']) && (int) $template['special_day'] !== 0) ? __('Yes') : __('No'); $table_conditions->data[] = $data; $data[0] = __('Time threshold'); @@ -318,61 +318,59 @@ if (count($actions) == 1 && isset($actions[0])) { } else { foreach ($actions as $kaction => $action) { $table->data[$kaction][0] = $action['name']; - if ((int) $kaction === 0) { - $table->data[$kaction][0] .= ui_print_help_tip( - __('The default actions will be executed every time that the alert is fired and no other action is executed'), - true - ); - } - - foreach ($action['escalation'] as $k => $v) { - if (count($table->head) >= count($action['escalation'])) { - if ($k === count($action['escalation'])) { - if ($k === 1) { - $table->head[$kaction] = __('Every time that the alert is fired'); - } else { - $table->head[$kaction] = '>#'.($kaction - 1); - } + if (count($action['escalation']) > 1) { + foreach ($action['escalation'] as $k => $v) { + $table->head[$k] = '#'.$k; + if ($v > 0) { + $table->data[$kaction][$k] .= html_print_image( + 'images/tick.png', + true, + ['class' => 'invert_filter'] + ); } else { - $table->head[$kaction] = '#'.($kaction); - if ($v > 0) { - $table->data[$kaction][($kaction + 1)] = html_print_image( - 'images/tick.png', - true, - ['class' => 'invert_filter'] - ); - } else { - $table->data[$kkaction][($kaction + 1)] = html_print_image( - 'images/blade.png', - true - ); - } + $table->data[$kaction][$k] = html_print_image( + 'images/blade.png', + true + ); } } - } - - $table->head[($kaction + 1)] = '#'.($kaction); - if (count($action['escalation']) === 0) { - $table->data[$kaction][($kaction + 2)] = html_print_image( - 'images/blade.png', - true - ); + } else { + $table->head[1] = __('Every time that the alert is fired'); + if (count($action['escalation']) > 0) { + if ($action['escalation'][0] > 0) { + $table->data[$kaction][1] .= html_print_image( + 'images/tick.png', + true, + ['class' => 'invert_filter'] + ); + } else { + $table->data[$kaction][1] = html_print_image( + 'images/blade.png', + true + ); + } + } else { + $table->data[$kaction][1] = html_print_image( + 'images/blade.png', + true + ); + } } $action_threshold = ($action['module_action_threshold'] > 0) ? $action['module_action_threshold'] : $action['action_threshold']; if ($action_threshold == 0) { - $table->data[$kaction][($k + 1)] = __('No'); + $table->data[$kaction][] = __('No'); } else { - $table->data[$kaction][($k + 1)] = human_time_description_raw( + $table->data[$kaction][] = human_time_description_raw( $action_threshold, true, 'tiny' ); } - - $table->head[($kaction + 1)] = __('Threshold'); } + + $table->head[] = __('Threshold'); } html_print_table($table); @@ -680,6 +678,23 @@ ui_require_javascript_file('pandora_fullcalendar'); diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index cc0d26d575..fbb63c49d3 100755 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -224,30 +224,14 @@ if ($update) { $table = new stdClass(); $table->id = 'delete_table'; -$table->class = 'databox filters'; +$table->class = 'databox filters filter-table-adv'; $table->width = '100%'; $table->data = []; $table->style = []; -$table->style[0] = 'font-weight: bold;'; -$table->style[2] = 'font-weight: bold'; $table->rowstyle = []; $table->size = []; -$table->size[0] = '15%'; -$table->size[1] = '35%'; -$table->size[2] = '15%'; -$table->size[3] = '35%'; -if (! $module_type) { - $table->rowstyle['edit1'] = 'display: none'; - $table->rowstyle['edit0'] = 'display: none'; - $table->rowstyle['edit1_1'] = 'display: none'; - $table->rowstyle['edit2'] = 'display: none'; - $table->rowstyle['edit3'] = 'display: none'; - $table->rowstyle['edit35'] = 'display: none'; - $table->rowstyle['edit4'] = 'display: none'; - $table->rowstyle['edit5'] = 'display: none'; - $table->rowstyle['edit6'] = 'display: none'; - $table->rowstyle['edit7'] = 'display: none'; -} +$table->size[0] = '50%'; +$table->size[1] = '50%'; $agents = agents_get_group_agents( array_keys(users_get_groups()), @@ -310,44 +294,41 @@ foreach ($module_types as $type) { $types[$type['id_tipo']] = $type['description']; } -$snmp_versions['1'] = 'v. 1'; -$snmp_versions['2'] = 'v. 2'; -$snmp_versions['2c'] = 'v. 2c'; -$snmp_versions['3'] = 'v. 3'; - -$table->width = '100%'; -$table->data = []; - -$table->data['selection_mode'][0] = __('Selection mode'); -$table->data['selection_mode'][1] = ''.__('Select modules first ').''.html_print_radio_button_extended('selection_mode', 'modules', '', $selection_mode, false, '', 'class="mrgn_right_40px"', true).'
'; -$table->data['selection_mode'][1] .= ''.__('Select agents first ').''.html_print_radio_button_extended('selection_mode', 'agents', '', $selection_mode, false, '', 'class="mrgn_right_40px"', true); - -$table->rowclass['form_modules_1'] = 'select_modules_row'; -$table->data['form_modules_1'][0] = __('Module type'); - -$types[0] = __('All'); -$table->colspan['form_modules_1'][1] = 2; -$table->data['form_modules_1'][1] = html_print_select( - $types, - 'module_type', - '', - false, - __('Select'), - -1, - true, - false, - true +$table->data[0][0] = html_print_label_input_block( + __('Selection mode'), + '
'.__('Select modules first ').''.html_print_radio_button_extended('selection_mode', 'modules', '', $selection_mode, false, '', 'class="mrgn_right_40px"', true).'
'.__('Select agents first ').''.html_print_radio_button_extended('selection_mode', 'agents', '', $selection_mode, false, '', 'class="mrgn_right_40px"', true).'
' ); -$table->data['form_modules_1'][3] = __('Select all modules of this type').' '.html_print_checkbox_extended( - 'force_type', - 'type', - '', - '', - false, - 'class="mrgn_right_40px"', - true, - '' +$table->rowclass[1] = 'select_modules_row'; +$types[0] = __('All'); +$table->data[1][0] = html_print_label_input_block( + __('Module type'), + html_print_select( + $types, + 'module_type', + '', + false, + __('Select'), + -1, + true, + false, + true, + 'w100p', + false, + 'width:100%' + ) +); +$table->data[1][1] = html_print_label_input_block( + __('Select all modules of this type'), + html_print_checkbox_extended( + 'force_type', + 'type', + '', + '', + false, + '', + true + ) ); $modules = []; @@ -369,919 +350,1184 @@ foreach ($names as $name) { -$table->rowclass['form_agents_1'] = 'select_agents_row'; -$table->data['form_agents_1'][0] = __('Agent group'); +$table->rowclass[2] = 'select_agents_row'; $groups = groups_get_all(true); $groups[0] = __('All'); -$table->colspan['form_agents_1'][1] = 2; -$table->data['form_agents_1'][1] = html_print_select_groups( - false, - 'AW', - true, - 'groups_select', - '', - false, - '', - '', - true -).' '.__('Group recursion').' '.html_print_checkbox('recursion', 1, false, true, false); -$table->data['form_agents_1'][3] = __('Select all modules of this group').' '.html_print_checkbox_extended( - 'force_group', - 'group', - '', - '', - false, - '', - 'class="mrgn_right_40px"' +$table->data[2][0] = html_print_label_input_block( + __('Agent group'), + html_print_select_groups( + false, + 'AW', + true, + 'groups_select', + '', + false, + '', + '', + true, + false, + false, + 'w100p', + false, + 'width:100%' + ).' '.__('Group recursion').' '.html_print_checkbox('recursion', 1, false, true, false) +); +$table->data[2][1] = html_print_label_input_block( + __('Select all modules of this group'), + html_print_checkbox_extended( + 'force_group', + 'group', + '', + '', + false, + '', + true + ) ); -$table->rowclass['form_modules_3'] = ''; -$table->data['form_modules_3'][0] = __('Module Status'); -$table->colspan['form_modules_3'][1] = 2; +$table->rowclass[3] = ''; $status_list = []; +$table->colspan[3][0] = 2; $status_list[AGENT_MODULE_STATUS_NORMAL] = __('Normal'); $status_list[AGENT_MODULE_STATUS_WARNING] = __('Warning'); $status_list[AGENT_MODULE_STATUS_CRITICAL_BAD] = __('Critical'); $status_list[AGENT_MODULE_STATUS_UNKNOWN] = __('Unknown'); $status_list[AGENT_MODULE_STATUS_NOT_NORMAL] = __('Not normal'); $status_list[AGENT_MODULE_STATUS_NOT_INIT] = __('Not init'); -$table->data['form_modules_3'][1] = html_print_select( - $status_list, - 'status_module', - 'selected', - '', - __('All'), - AGENT_MODULE_STATUS_ALL, - true +$table->data[3][0] = html_print_label_input_block( + __('Module Status'), + html_print_select( + $status_list, + 'status_module', + 'selected', + '', + __('All'), + AGENT_MODULE_STATUS_ALL, + true, + false, + true, + 'w100p', + false, + 'width:100%' + ) ); -$table->data['form_modules_3'][3] = ''; $tags = tags_get_user_tags(); -$table->rowstyle['form_modules_4'] = 'vertical-align: top;'; -$table->rowclass['form_modules_4'] = 'select_modules_row select_modules_row_2'; -$table->data['form_modules_4'][0] = __('Tags'); -$table->data['form_modules_4'][1] = html_print_select( - $tags, - 'tags[]', - $tags_name, - false, - __('Any'), - -1, - true, - true, - true +$table->rowstyle[4] = 'vertical-align: top;'; +$table->rowclass[4] = 'select_modules_row select_modules_row_2'; +$table->colspan[4][0] = 2; +$table->data[4][0] = html_print_label_input_block( + __('Tags'), + html_print_select( + $tags, + 'tags[]', + $tags_name, + false, + __('Any'), + -1, + true, + true, + true, + 'w100p', + false, + 'width:100%' + ) ); -$table->rowstyle['form_modules_filter'] = 'vertical-align: top;'; -$table->rowclass['form_modules_filter'] = 'select_modules_row select_modules_row_2'; -$table->data['form_modules_filter'][0] = __('Filter Modules'); -$table->data['form_modules_filter'][1] = html_print_input_text('filter_modules', '', '', 20, 255, true); - -$table->rowstyle['form_modules_2'] = 'vertical-align: top;'; -$table->rowclass['form_modules_2'] = 'select_modules_row select_modules_row_2'; -$table->data['form_modules_2'][0] = __('Modules'); -$table->data['form_modules_2'][1] = html_print_select( - $modules, - 'module_name[]', - $module_name, - false, - __('Select'), - -1, - true, - true, - true -).' '.__('Select all modules').' '.html_print_checkbox('select_all_modules', 1, false, true, false, '', false, "class='static'"); - -$table->data['form_modules_2'][2] = __('When select modules'); -$table->data['form_modules_2'][2] .= '
'; -$table->data['form_modules_2'][2] .= html_print_select( - [ - 'common' => __('Show common agents'), - 'all' => __('Show all agents'), - ], - 'agents_selection_mode', - 'common', - false, - '', - '', - true +$table->rowstyle[5] = 'vertical-align: top;'; +$table->rowclass[5] = 'select_modules_row select_modules_row_2'; +$table->data[5][0] = html_print_label_input_block( + __('Filter Modules'), + html_print_input_text('filter_modules', '', '', false, 255, true) ); -$table->data['form_modules_2'][3] = html_print_select( - [], - 'agents[]', - $agents_select, - false, - __('None'), - 0, - true, - true, - false +$table->data[5][1] = html_print_label_input_block( + __('When select modules'), + html_print_select( + [ + 'common' => __('Show common agents'), + 'all' => __('Show all agents'), + ], + 'agents_selection_mode', + 'common', + false, + '', + '', + true, + false, + true, + 'w100p', + false, + 'width:100%' + ) +); + +$table->rowclass[6] = 'select_modules_row select_modules_row_2'; +$table->data[6][0] = html_print_label_input_block( + __('Modules'), + html_print_select( + $modules, + 'module_name[]', + $module_name, + false, + __('Select'), + -1, + true, + true, + true, + 'w100p', + false, + 'width:100%' + ).' '.__('Select all modules').' '.html_print_checkbox('select_all_modules', 1, false, true, false, '', false, "class='static'") +); + +$table->data[6][1] = html_print_label_input_block( + __('Agent'), + html_print_select( + [], + 'agents[]', + $agents_select, + false, + __('None'), + 0, + true, + true, + false, + 'w100p', + false, + 'width:100%' + ) ); -$table->rowclass['form_agents_2'] = 'select_agents_row'; -$table->data['form_agents_2'][0] = __('Agent Status'); -$table->colspan['form_agents_2'][1] = 2; +$table->rowclass[7] = 'select_agents_row'; $status_list = []; +$table->colspan[7][0] = 2; $status_list[AGENT_STATUS_NORMAL] = __('Normal'); $status_list[AGENT_STATUS_WARNING] = __('Warning'); $status_list[AGENT_STATUS_CRITICAL] = __('Critical'); $status_list[AGENT_STATUS_UNKNOWN] = __('Unknown'); $status_list[AGENT_STATUS_NOT_NORMAL] = __('Not normal'); $status_list[AGENT_STATUS_NOT_INIT] = __('Not init'); -$table->data['form_agents_2'][1] = html_print_select( - $status_list, - 'status_agents', - 'selected', - '', - __('All'), - AGENT_STATUS_ALL, - true +$table->data[7][0] = html_print_label_input_block( + __('Agent Status'), + html_print_select( + $status_list, + 'status_agents', + 'selected', + '', + __('All'), + AGENT_STATUS_ALL, + true, + false, + true, + 'w100p', + false, + 'width:100%' + ) ); -$table->data['form_agents_2'][3] = ''; $tags = tags_get_user_tags(); -$table->rowstyle['form_agents_4'] = 'vertical-align: top;'; -$table->rowclass['form_agents_4'] = 'select_agents_row select_agents_row_2'; -$table->data['form_agents_4'][0] = __('Tags'); -$table->data['form_agents_4'][1] = html_print_select( - $tags, - 'tags[]', - $tags_name, - false, - __('Any'), - -1, - true, - true, - true +$table->colspan[8][0] = 2; +$table->rowstyle[8] = 'vertical-align: top;'; +$table->rowclass[8] = 'select_agents_row select_agents_row_2'; +$table->data[8][0] = html_print_label_input_block( + __('Tags'), + html_print_select( + $tags, + 'tags[]', + $tags_name, + false, + __('Any'), + -1, + true, + true, + true, + 'w100p', + false, + 'width:100%' + ) ); -$table->rowstyle['form_agents_filter'] = 'vertical-align: top;'; -$table->rowclass['form_agents_filter'] = 'select_agents_row select_agents_row_2'; -$table->data['form_agents_filter'][0] = __('Filter agents'); -$table->data['form_agents_filter'][1] = html_print_input_text('filter_agents', '', '', 20, 255, true); - -$table->rowstyle['form_agents_3'] = 'vertical-align: top;'; -$table->rowclass['form_agents_3'] = 'select_agents_row select_agents_row_2'; -$table->data['form_agents_3'][0] = __('Agents'); -$table->data['form_agents_3'][1] = html_print_select( - $agents, - 'id_agents[]', - $agents_id, - false, - '', - '', - true, - true, - false -).' '.__('Select all agents').' '.html_print_checkbox('select_all_agents', 1, false, true, false, '', false, "class='static'"); - -$table->data['form_agents_3'][2] = __('When select agents'); -$table->data['form_agents_3'][2] .= '
'; -$table->data['form_agents_3'][2] .= html_print_select( - [ - 'common' => __('Show common modules'), - 'all' => __('Show all modules'), - 'unknown' => __('Show unknown and not init modules'), - ], - 'modules_selection_mode', - 'common', - false, - '', - '', - true +$table->rowstyle[9] = 'vertical-align: top;'; +$table->rowclass[9] = 'select_agents_row select_agents_row_2'; +$table->data[9][0] = html_print_label_input_block( + __('Filter agents'), + html_print_input_text('filter_agents', '', '', false, 255, true) ); -$table->data['form_agents_3'][3] = html_print_select( - [], - 'module[]', - $modules_select, - false, - '', - '', - true, - true, - false + +$table->data[9][1] = html_print_label_input_block( + __('When select agents'), + html_print_select( + [ + 'common' => __('Show common modules'), + 'all' => __('Show all modules'), + 'unknown' => __('Show unknown and not init modules'), + ], + 'modules_selection_mode', + 'common', + false, + '', + '', + true, + false, + true, + 'w100p', + false, + 'width:100%' + ) +); + +$table->rowstyle[10] = 'vertical-align: top;'; +$table->rowclass[10] = 'select_agents_row select_agents_row_2'; +$table->data[10][0] = html_print_label_input_block( + __('Agents'), + html_print_select( + $agents, + 'id_agents[]', + $agents_id, + false, + '', + '', + true, + true, + false, + 'w100p', + false, + 'width:100%' + ).' '.__('Select all agents').' '.html_print_checkbox('select_all_agents', 1, false, true, false, '', false, "class='static'") +); + +$table->data[10][1] = html_print_label_input_block( + __('Modules'), + html_print_select( + [], + 'module[]', + $modules_select, + false, + '', + '', + true, + true, + false, + 'w100p', + false, + 'width:100%' + ) ); -$table->data['edit0'][0] = __('Dynamic Interval'); -$table->data['edit0'][1] = html_print_extended_select_for_time( - 'dynamic_interval', - -2, - '', - 'None', - '0', - 10, - true, - 'width:150px', - false, - '', - false, - false, - '', - true +$table->data[11][0] = html_print_label_input_block( + __('Dynamic Interval'), + html_print_extended_select_for_time( + 'dynamic_interval', + -2, + '', + 'None', + '0', + 10, + true, + 'width:100%', + false, + '', + false, + false, + '', + true + ) +); +$table->data[11][1] = html_print_label_input_block( + __('Dynamic Two Tailed: '), + html_print_checkbox('dynamic_two_tailed', 1, '', true) ); -$table->data['edit0'][2] = ''; -$table->data['edit0'][2] .= ''; -$table->data['edit0'][2] .= ''; -$table->data['edit0'][2] .= '
'.__('Dynamic Min.').''.html_print_input_text('dynamic_min', '', '', 10, 255, true).'
'.__('Dynamic Max.').''.html_print_input_text('dynamic_max', '', '', 10, 255, true).'
'; -$table->data['edit0'][3] = __('Dynamic Two Tailed: '); -$table->data['edit0'][3] .= html_print_checkbox('dynamic_two_tailed', 1, '', true); - -$table->data['edit1'][0] = __('Warning status'); -$table->data['edit1'][1] = ''; - $table->data['edit1'][1] .= ""; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= ""; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= ""; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= '
'; - $table->data['edit1'][1] .= ''.__('Min.').''; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= html_print_input_text( - 'min_warning', - '', - '', - 5, - 255, - true - ); - $table->data['edit1'][1] .= '
'; - $table->data['edit1'][1] .= ''.__('Max.').''; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= html_print_input_text( - 'max_warning', - '', - '', - 5, - 255, - true - ); - $table->data['edit1'][1] .= '
'; - $table->data['edit1'][1] .= ''.__('Str.').''; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= html_print_input_text( - 'str_warning', - '', - '', - 5, - 1024, - true - ); - $table->data['edit1'][1] .= '
'; - $table->data['edit1'][1] .= ''.__('Inverse interval').''; - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= html_print_select( - [ - '' => __('No change'), - '1' => __('Yes'), - '0' => __('No'), - ], - 'warning_inverse', - '', - '', - '', - '', - true - ); - $table->data['edit1'][1] .= '
'; - $table->data['edit1'][1] .= ''.__('Percentage').''; - $table->data['edit1'][1] .= ui_print_help_tip('Defines threshold as a percentage of value decrease/increment', true); - - $table->data['edit1'][1] .= ''; - $table->data['edit1'][1] .= html_print_select( - [ - '' => __('No change'), - '1' => __('Yes'), - '0' => __('No'), - ], - 'percentage_warning', - '', - '', - '', - '', - true - ); - $table->data['edit1'][1] .= '
'; - - $table->data['edit1'][2] = __('Critical status'); - $table->data['edit1'][3] = ''; - $table->data['edit1'][3] .= ""; - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= ""; - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= ""; - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= ''; - - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= '
'; - $table->data['edit1'][3] .= ''.__('Min.').''; - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= html_print_input_text( - 'min_critical', - '', - '', - 5, - 255, - true - ); - $table->data['edit1'][3] .= '
'; - $table->data['edit1'][3] .= ''.__('Max.').''; - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= html_print_input_text( - 'max_critical', - '', - '', - 5, - 255, - true - ); - $table->data['edit1'][3] .= '
'; - $table->data['edit1'][3] .= ''.__('Str.').''; - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= html_print_input_text( - 'str_critical', - '', - '', - 5, - 1024, - true - ); - $table->data['edit1'][3] .= '
'; - $table->data['edit1'][3] .= ''.__('Inverse interval').''; - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= html_print_select( - [ - '' => __('No change'), - '1' => __('Yes'), - '0' => __('No'), - ], - 'critical_inverse', - '', - '', - '', - '', - true - ); - $table->data['edit1'][3] .= '
'; - $table->data['edit1'][3] .= ''.__('Percentage').''; - $table->data['edit1'][3] .= ui_print_help_tip('Defines threshold as a percentage of value decrease/increment', true); - $table->data['edit1'][3] .= ''; - $table->data['edit1'][3] .= html_print_select( - [ - '' => __('No change'), - '1' => __('Yes'), - '0' => __('No'), - ], - 'percentage_critical', - '', - '', - '', - '', - true - ); - $table->data['edit1'][3] .= '
'; - - $table->data['edit1_1'][0] = ''.__('Description').''; - $table->data['edit1_1'][1] = html_print_textarea( - 'descripcion', - 2, - 50, - '', - '', - true - ); - $table->colspan['edit1_1'][1] = 3; - - $table->data['edit2'][0] = __('Interval'); - $table->data['edit2'][1] = html_print_extended_select_for_time( - 'module_interval', - 0, - '', - __('No change'), - '0', - 10, - true, - 'width: 150px' - ); - $table->data['edit2'][2] = __('Disabled'); - $table->data['edit2'][3] = html_print_select( - [ - '' => __('No change'), - '1' => __('Yes'), - '0' => __('No'), - ], - 'disabled', - '', - '', - '', - '', - true - ); - - $table->data['edit3'][0] = __('Post process'); - - $table->data['edit3'][1] = html_print_extended_select_for_post_process( - 'post_process', - -1, - '', - '', - 0, - false, - true, - 'width:150px;', - true, - false, - 1 - ); - - $table->data['edit3'][2] = __('SNMP community'); - $table->data['edit3'][3] = html_print_input_text( - 'snmp_community', - '', - '', - 10, - 100, - true - ); - - $table->data['edit15'][2] = __('SNMP OID'); - $table->data['edit15'][3] = html_print_input_text( - 'snmp_oid', - '', - '', - 80, - 80, - true - ); - - $target_ip_values = []; - $target_ip_values['auto'] = __('Auto'); - $target_ip_values['force_pri'] = __('Force primary key'); - $target_ip_values['custom'] = __('Custom'); - - $table->data['edit35'][0] = __('Target IP'); - $table->data['edit35'][1] = html_print_select( - $target_ip_values, - 'ip_target', - '', - '', - __('No change'), - '', - true, - false, - false, - '', - false, - 'width:200px;' - ); - - $table->data['edit35'][1] .= html_print_input_text('custom_ip_target', '', '', 15, 60, true); - - $table->data['edit35'][2] = __('SNMP version'); - $table->data['edit35'][3] = html_print_select( - $snmp_versions, - 'snmp_version', - '', - '', - __('No change'), - '', - true, - false, - false, - '' - ); - $table->data['edit36'][0] = __('Auth user'); - $table->data['edit36'][1] = html_print_input_text( - 'plugin_user_snmp', - '', - '', - 15, - 60, - true - ); - $table->data['edit36'][2] = __('Auth password').ui_print_help_tip(__('The pass length must be eight character minimum.'), true); - $table->data['edit36'][3] = html_print_input_password('plugin_pass_snmp', '', '', 15, 60, true); - $table->data['edit37'][0] = __('Privacy method'); - $table->data['edit37'][1] = html_print_select(['DES' => __('DES'), 'AES' => __('AES')], 'snmp3_privacy_method', '', '', __('No change'), '', true); - $table->data['edit37'][2] = __('Privacy pass').ui_print_help_tip(__('The pass length must be eight character minimum.'), true); - $table->data['edit37'][3] = html_print_input_password('snmp3_privacy_pass', '', '', 15, 60, true); - $table->data['edit38'][0] = __('Auth method'); - $table->data['edit38'][1] = html_print_select(['MD5' => __('MD5'), 'SHA' => __('SHA')], 'plugin_parameter', '', '', __('No change'), '', true); - $table->data['edit38'][2] = __('Security level'); - $table->data['edit38'][3] = html_print_select( - [ - 'noAuthNoPriv' => __('Not auth and not privacy method'), - 'authNoPriv' => __('Auth and not privacy method'), - 'authPriv' => __('Auth and privacy method'), - ], - 'custom_string_3', - '', - '', - __('No change'), - '', - true - ); - - $table->data['edit4'][0] = __('Value'); - $table->data['edit4'][1] = ''.__('Min.').''; - $table->data['edit4'][1] .= html_print_input_text('min', '', '', 5, 15, true); - $table->data['edit4'][1] .= '
'.__('Max.').''; - $table->data['edit4'][1] .= html_print_input_text('max', '', '', 5, 15, true); - $table->data['edit4'][2] = __('Module group'); - // Create module groups values for select - $module_groups = modules_get_modulegroups(); - $module_groups[0] = __('Not assigned'); - - $table->data['edit4'][3] = html_print_select( - $module_groups, - 'id_module_group', - '', - '', - __('No change'), - '', - true, - false, - false - ); - - $table->data['edit5'][0] = __('Username'); - $table->data['edit5'][1] = html_print_input_text('plugin_user', '', '', 15, 60, true); - $table->data['edit5'][2] = __('Password'); - $table->data['edit5'][3] = html_print_input_password('plugin_pass', '', '', 15, 60, true); - - // Export target - $table->data['edit6'][0] = __('Export target'); - $targets2 = db_get_all_rows_sql('SELECT id, name FROM tserver_export ORDER by name'); - if ($targets2 === false) { - $targets2 = []; - } - - $targets = []; - $targets[0] = __('None'); - foreach ($targets2 as $t) { - $targets[$t['id']] = $t['name']; - } - - $table->data['edit6'][1] = html_print_select($targets, 'id_export', '', '', __('No change'), '', true, false, false); - $table->data['edit6'][2] = __('Unit'); - $table->data['edit6'][3] = html_print_extended_select_for_unit('unit', '-1', '', '', '0', '15', true, false, false, false, 1); - // FF stands for Flip-flop. - $table->data['edit7'][0] = __('FF threshold').' '; +$table->data[12][0] = html_print_label_input_block( + __('Dynamic Min.'), + html_print_input_text('dynamic_min', '', '', false, 255, true) +); +$table->data[12][1] = html_print_label_input_block( + __('Dynamic Max.'), + html_print_input_text('dynamic_max', '', '', false, 255, true) +); - $table->colspan['edit7'][1] = 3; - $table->data['edit7'][1] = __('Mode').' '; - $table->data['edit7'][1] .= html_print_select( - [ - '' => __('No change'), - '1' => __('Each state changing'), - '0' => __('All state changing'), - ], - 'each_ff', - '', - '', - '', - '', - true, - false, - true, - '', - false, - 'width: 400px;' - ).'
'; +$table_warning = new stdClass(); +$table_warning->class = 'filters filter-table-adv'; +$table_warning->width = '100%'; +$table_warning->size[0] = '33%'; +$table_warning->size[1] = '33%'; +$table_warning->size[2] = '33%'; +$table_warning->tdid[0][0] = 'edit1-1-min'; +$table_warning->data[0][0] = html_print_label_input_block( + __('Min.'), + html_print_input_text( + 'min_warning', + '', + '', + false, + 255, + true + ) +); - $table->data['edit7'][1] .= __('All state changing').' : '; - $table->data['edit7'][1] .= html_print_input_text( - 'min_ff_event', - '', - '', - 5, - 15, - true - ).'
'; +$table_warning->tdid[0][1] = 'edit1-1-max'; +$table_warning->data[0][1] = html_print_label_input_block( + __('Max.'), + html_print_input_text( + 'max_warning', + '', + '', + false, + 255, + true + ) +); - $table->data['edit7'][1] .= __('Each state changing').' : '; - $table->data['edit7'][1] .= __('To normal').' '; - $table->data['edit7'][1] .= html_print_input_text( - 'min_ff_event_normal', - '', - '', - 5, - 15, - true - ).' '; +$table_warning->tdid[0][2] = 'edit1-1-str'; +$table_warning->data[0][2] = html_print_label_input_block( + __('Str.'), + html_print_input_text( + 'str_warning', + '', + '', + false, + 1024, + true + ) +); - $table->data['edit7'][1] .= __('To warning').' '; - $table->data['edit7'][1] .= html_print_input_text( - 'min_ff_event_warning', - '', - '', - 5, - 15, - true - ).' '; +$table_warning->data[1][0] = html_print_label_input_block( + __('Inverse interval'), + html_print_select( + [ + '' => __('No change'), + '1' => __('Yes'), + '0' => __('No'), + ], + 'warning_inverse', + '', + '', + '', + '', + true, + false, + true, + 'w100p', + false, + 'width:100%' + ) +); - $table->data['edit7'][1] .= __('To critical').' '; - $table->data['edit7'][1] .= html_print_input_text( - 'min_ff_event_critical', - '', - '', - 5, - 15, - true - ).'
'; +$table_warning->data[1][1] = html_print_label_input_block( + __('Percentage').ui_print_help_tip('Defines threshold as a percentage of value decrease/increment', true), + html_print_select( + [ + '' => __('No change'), + '1' => __('Yes'), + '0' => __('No'), + ], + 'percentage_warning', + '', + '', + '', + '', + true, + false, + true, + 'w100p', + false, + 'width:100%' + ) +); - $table->data['edit7'][1] .= __('Keep counters').' '; - $table->data['edit7'][1] .= html_print_select( - [ - '' => __('No change'), - '1' => __('Active Counters'), - '0' => __('Inactive Counters'), - ], - 'ff_type', - '', - '', - '', - '', - true, - false, - true, - '', - false, - 'width: 400px;' - ); +$table_warning->data[1][2] = html_print_label_input_block( + __('Change to critical status after.'), + html_print_input_text( + 'warning_time', + '', + '', + false, + 15, + true + ) +); - $table->data['edit8'][0] = __('FF interval'); - $table->data['edit8'][1] = html_print_input_text( - 'module_ff_interval', - '', - '', - 5, - 10, - true - ); - $table->data['edit8'][1] .= ui_print_help_tip( - __('Module execution flip flop time interval (in secs).'), - true - ); - - $table->data['edit8'][2] = __('FF timeout'); - $table->data['edit8'][3] = html_print_input_text( - 'ff_timeout', - '', - '', - 5, - 10, - true - ); - $table->data['edit8'][3] .= ui_print_help_tip( - __('Timeout in secs from start of flip flop counting. If this value is exceeded, FF counter is reset. Set to 0 for no timeout.'), - true - ); - - $table->data['edit9'][0] = __('Historical data'); - $table->data['edit9'][1] = html_print_select(['' => __('No change'), '1' => __('Yes'), '0' => __('No')], 'history_data', '', '', '', '', true); - - // Tags avalaible - $id_tag = []; - $table->data['edit10'][0] = __('Tags'); - $table->data['edit10'][1] = html_print_select_from_sql( - 'SELECT id_tag, name FROM ttag ORDER BY name', - 'id_tag[]', - $id_tag, - '', - __('None'), - '0', - true, - true, - false, - false - ); - $table->data['edit10'][2] = __('Category'); - $table->data['edit10'][3] = html_print_select(categories_get_all_categories('forselect'), 'id_category', '', '', __('No change'), '', true, false, false); - - if (enterprise_installed()) { - $table->rowspan['edit10'][0] = $table->rowspan['edit10'][1] = 2; - - $table->data['edit101'][2] = __('Policy linking status').ui_print_help_tip(__('This field only has sense in modules adopted by a policy.'), true); - $table->data['edit101'][3] = html_print_select([MODULE_PENDING_LINK => __('Linked'), MODULE_PENDING_UNLINK => __('Unlinked')], 'policy_linked', '', '', __('No change'), '', true, false, false); - } - - if ($table->rowspan['edit10'][0] == 2) { - $table->rowspan['edit10'][0] = $table->rowspan['edit10'][1] = 3; - } else { - $table->rowspan['edit10'][0] = $table->rowspan['edit10'][1] = 2; - } - - $table->data['edit102'][2] = __('Discard unknown events'); - - $table->data['edit102'][3] = html_print_select( - [ - '' => __('No change'), - '1' => __('Yes'), - '0' => __('No'), - ], - 'throw_unknown_events', - '', - '', - '', - '', - true - ); - - $table->data['edit12'][0] = ''.__('Critical instructions').''.ui_print_help_tip(__('Instructions when the status is critical'), true); - $table->data['edit12'][1] = html_print_textarea('critical_instructions', 2, 50, '', '', true); - $table->colspan['edit12'][1] = 3; - - $table->data['edit13'][0] = ''.__('Warning instructions').''.ui_print_help_tip(__('Instructions when the status is warning'), true); - $table->data['edit13'][1] = html_print_textarea('warning_instructions', 2, 50, '', '', true); - $table->colspan['edit13'][1] = 3; - - $table->data['edit14'][0] = ''.__('Unknown instructions').''.ui_print_help_tip(__('Instructions when the status is unknown'), true); - $table->data['edit14'][1] = html_print_textarea('unknown_instructions', 2, 50, '', '', true); - $table->colspan['edit14'][1] = 3; - - $table->data['edit11'][0] = __('Quiet'); - $table->data['edit11'][0] .= ui_print_help_tip(__('The module still store data but the alerts and events will be stop'), true); - $table->data['edit11'][1] = html_print_select( - [ - -1 => __('No change'), - 1 => __('Yes'), - 0 => __('No'), - ], - 'quiet_select', - -1, - '', - '', - 0, - true - ); +$table->colspan[13][0] = 2; +$table->data[13][0] = html_print_label_input_block(__('Warning status'), html_print_table($table_warning, true)); - $table->data['edit11'][2] = __('Timeout'); - $table->data['edit11'][3] = html_print_input_text( - 'max_timeout', - '', - '', - 5, - 10, - true - ).' '.ui_print_help_tip( - __('Seconds that agent will wait for the execution of the module.'), - true - ); +$table_critical = new stdClass(); +$table_critical->class = 'filters filter-table-adv'; +$table_critical->width = '100%'; +$table_critical->size[0] = '33%'; +$table_critical->size[1] = '33%'; +$table_critical->size[2] = '33%'; +$table_critical->tdid[0][0] = 'edit1-3-min'; +$table_critical->data[0][0] = html_print_label_input_block( + __('Min.'), + html_print_input_text( + 'min_warning', + '', + '', + false, + 255, + true + ) +); - $table->data['edit16'][0] = __('Retries'); - $table->data['edit16'][1] = html_print_input_text('max_retries', '', '', 5, 10, true).' '.ui_print_help_tip( - __('Number of retries that the module will attempt to run.'), - true - ); +$table_critical->tdid[0][1] = 'edit1-3-max'; +$table_critical->data[0][1] = html_print_label_input_block( + __('Max.'), + html_print_input_text( + 'max_warning', + '', + '', + false, + 255, + true + ) +); - $table->data['edit22'][0] = __('Web checks'); - ; - $table->data['edit22'][1] = ''; +$table_critical->tdid[0][2] = 'edit1-3-str'; +$table_critical->data[0][2] = html_print_label_input_block( + __('Str.'), + html_print_input_text( + 'str_warning', + '', + '', + false, + 1024, + true + ) +); - $table->data['edit16'][2] = __('Port'); - $table->data['edit16'][3] = html_print_input_text('tcp_port', '', '', 5, 20, true); +$table_critical->data[1][0] = html_print_label_input_block( + __('Inverse interval'), + html_print_select( + [ + '' => __('No change'), + '1' => __('Yes'), + '0' => __('No'), + ], + 'warning_inverse', + '', + '', + '', + '', + true, + false, + true, + 'w100p', + false, + 'width:100%' + ) +); - $table->data['edit17'][0] = __('TCP send'); - $table->data['edit17'][1] = html_print_textarea('tcp_send2', 2, 65, '', '', true); +$table_critical->data[1][1] = html_print_label_input_block( + __('Percentage').ui_print_help_tip('Defines threshold as a percentage of value decrease/increment', true), + html_print_select( + [ + '' => __('No change'), + '1' => __('Yes'), + '0' => __('No'), + ], + 'percentage_warning', + '', + '', + '', + '', + true, + false, + true, + 'w100p', + false, + 'width:100%' + ) +); - $table->data['edit17'][2] = __('TCP receive'); - $table->data['edit17'][3] = html_print_textarea('tcp_rcv', 2, 65, '', '', true); +$table->colspan[14][0] = 2; +$table->data[14][0] = html_print_label_input_block(__('Critical status'), html_print_table($table_critical, true)); - $table->data['edit18'][0] = __('WMI query'); - $table->data['edit18'][1] = html_print_input_text('wmi_query', '', '', 35, 255, true); +$table->colspan[15][0] = 2; +$table->data[15][0] = html_print_label_input_block( + __('Description'), + html_print_textarea( + 'descripcion', + 2, + 50, + '', + '', + true + ) +); - $table->data['edit18'][2] = __('Key string'); - $table->data['edit18'][3] = html_print_input_text('key_string', '', '', 20, 60, true); +$table->data[16][0] = html_print_label_input_block( + __('Interval'), + html_print_extended_select_for_time( + 'module_interval', + 0, + '', + __('No change'), + '0', + 10, + true, + 'width:100%' + ) +); - $table->data['edit19'][0] = __('Field number'); - $table->data['edit19'][1] = html_print_input_text('field_number', '', '', 5, 15, true); +$table->data[16][1] = html_print_label_input_block( + __('Disabled'), + html_print_select( + [ + '' => __('No change'), + '1' => __('Yes'), + '0' => __('No'), + ], + 'disabled', + '', + '', + '', + '', + true, + false, + true, + 'w100p', + false, + 'width:100%' + ) +); - $table->data['edit20'][0] = __('Plugin').ui_print_help_icon('plugin_macros', true); - $table->data['edit20'][1] = html_print_select_from_sql( - 'SELECT id, name FROM tplugin ORDER BY name', - 'id_plugin', - '', - 'changePluginSelect();', - __('None'), - 0, - true, - false, - false - ); +$table->data[17][0] = html_print_label_input_block( + __('Post process'), + html_print_extended_select_for_post_process( + 'post_process', + -1, + '', + '', + 0, + false, + true, + 'width:95%', + true, + false, + 1 + ) +); + +$table->data[17][1] = html_print_label_input_block( + __('SNMP community'), + html_print_input_text( + 'snmp_community', + '', + '', + false, + 100, + true + ) +); + +$table->colspan[18][0] = 2; +$table->data[18][0] = html_print_label_input_block( + __('SNMP OID'), + html_print_input_text( + 'snmp_oid', + '', + '', + false, + 80, + true + ) +); + +$target_ip_values = []; +$target_ip_values['auto'] = __('Auto'); +$target_ip_values['force_pri'] = __('Force primary key'); +$target_ip_values['custom'] = __('Custom'); + +$table->data[19][0] = html_print_label_input_block( + __('Target IP'), + html_print_select( + $target_ip_values, + 'ip_target', + '', + '', + __('No change'), + '', + true, + false, + false, + 'w100p', + false, + 'width:100%' + ).html_print_input_text('custom_ip_target', '', '', false, 60, true) +); + +$snmp_versions['1'] = 'v. 1'; +$snmp_versions['2c'] = 'v. 2c'; +$snmp_versions['3'] = 'v. 3'; + +$table->data[19][1] = html_print_label_input_block( + __('SNMP version'), + html_print_select( + $snmp_versions, + 'snmp_version', + '', + '', + __('No change'), + '', + true, + false, + false, + 'w100p', + false, + 'width:100%' + ) +); + +$table->data[20][0] = html_print_label_input_block( + __('Auth user'), + html_print_input_text( + 'plugin_user_snmp', + '', + '', + false, + 60, + true + ) +); + +$table->data[20][1] = html_print_label_input_block( + __('Auth password').ui_print_help_tip(__('The pass length must be eight character minimum.'), true), + html_print_input_password('plugin_pass_snmp', '', '', 15, 60, true) +); + +$table->data[21][0] = html_print_label_input_block( + __('Privacy method'), + html_print_select(['DES' => __('DES'), 'AES' => __('AES')], 'snmp3_privacy_method', '', '', __('No change'), '', true, false, true, 'w100p', false, 'width:100%') +); + +$table->data[21][1] = html_print_label_input_block( + __('Privacy pass').ui_print_help_tip(__('The pass length must be eight character minimum.'), true), + html_print_input_password('snmp3_privacy_pass', '', '', 15, 60, true) +); + +$table->data[22][0] = html_print_label_input_block( + __('Auth method'), + html_print_select(['MD5' => __('MD5'), 'SHA' => __('SHA')], 'plugin_parameter', '', '', __('No change'), '', true, false, true, 'w100p', false, 'width:100%') +); + +$table->data[22][1] = html_print_label_input_block( + __('Security level'), + html_print_select( + [ + 'noAuthNoPriv' => __('Not auth and not privacy method'), + 'authNoPriv' => __('Auth and not privacy method'), + 'authPriv' => __('Auth and privacy method'), + ], + 'custom_string_3', + '', + '', + __('No change'), + '', + true, + false, + true, + 'w100p', + false, + 'width:100%' + ) +); - // Store the macros in base64 into a hidden control to move between pages - $table->data['edit21'][0] = html_print_input_hidden('macros', base64_encode($macros), true); +$table_value = new stdClass(); +$table_value->class = 'filters filter-table-adv'; +$table_value->width = '100%'; +$table_value->size[0] = '50%'; +$table_value->size[1] = '50%'; - $table->colspan['edit23'][1] = 3; - $table->data['edit23'][0] = __('Command'); - $table->data['edit23'][1] = html_print_input_text_extended( - 'tcp_send', - '', - 'command_text', - '', - 100, - 10000, - false, - '', - '', - true - ); +$table_value->data[0][0] = html_print_label_input_block( + __('Min.'), + html_print_input_text('min', '', '', false, 15, true) +); - require_once $config['homedir'].'/include/class/CredentialStore.class.php'; - $array_credential_identifier = CredentialStore::getKeys('CUSTOM'); +$table_value->data[0][1] = html_print_label_input_block( + __('Max.'), + html_print_input_text('max', '', '', false, 15, true) +); - $table->data['edit24'][0] = __('Credential identifier'); - $table->data['edit24'][1] = html_print_select( - $array_credential_identifier, - 'custom_string_1', - '', - '', - __('None'), - '', - true, - false, - false - ); +$table->data[23][0] = html_print_label_input_block( + __('Value'), + html_print_table($table_value, true) +); - $array_os = [ - '' => __('No change'), - 'inherited' => __('Inherited'), - 'linux' => __('Linux'), - 'windows' => __('Windows'), - ]; - $table->data['edit24'][2] = __('Target OS'); - $table->data['edit24'][3] = html_print_select( - $array_os, - 'custom_string_2', - '', - '', - '', - '', - true, - false, - false, - '' - ); +// Create module groups values for select. +$module_groups = modules_get_modulegroups(); +$module_groups[0] = __('Not assigned'); +$table->data[23][1] = html_print_label_input_block( + __('Module group'), + html_print_select( + $module_groups, + 'id_module_group', + '', + '', + __('No change'), + '', + true, + false, + false, + 'w100p', + false, + 'width:100%' + ) +); - if (empty($id_plugin) === false) { - $preload = db_get_sql( - sprintf( - 'SELECT description FROM tplugin WHERE id = %s', - $id_plugin - ) - ); - $preload = io_safe_output($preload); - $preload = str_replace("\n", '
', $preload); - } else { - $preload = ''; - } +$table->data[24][0] = html_print_label_input_block( + __('Username'), + html_print_input_text('plugin_user', '', '', false, 60, true) +); - $table->data['edit21'][1] = sprintf( - '%s', - $preload - ); +$table->data[24][1] = html_print_label_input_block( + __('Password'), + html_print_input_password('plugin_pass', '', '', 15, 60, true) +); - $table->data['exclude_policy_modules'][0] = html_print_input_hidden('exclude_policy_modules', 1); - echo '
'; +// Export target. +$targets2 = db_get_all_rows_sql('SELECT id, name FROM tserver_export ORDER by name'); +if ($targets2 === false) { + $targets2 = []; +} + +$targets = []; +$targets[0] = __('None'); +foreach ($targets2 as $t) { + $targets[$t['id']] = $t['name']; +} + +$table->data[25][0] = html_print_label_input_block( + __('Export target'), + html_print_select($targets, 'id_export', '', '', __('No change'), '', true, false, false, 'w100p', false, 'width:100%') +); + +$table->data[25][1] = html_print_label_input_block( + __('Unit'), + html_print_extended_select_for_unit('unit', '-1', '', '', '0', false, true, 'width:100%;', false, false, 1, 'w100p flex') +); + +// FF stands for Flip-flop. +$table_threshold = new stdClass(); +$table_threshold->class = 'filters filter-table-adv'; +$table_threshold->width = '100%'; +$table_threshold->size[0] = '33%'; +$table_threshold->size[1] = '33%'; +$table_threshold->size[2] = '33%'; + +$table_threshold->data[0][0] = html_print_label_input_block( + __('Mode'), + html_print_select( + [ + '' => __('No change'), + '1' => __('Each state changing'), + '0' => __('All state changing'), + ], + 'each_ff', + '', + '', + '', + '', + true, + false, + true, + 'w100p', + false, + 'width:100%' + ) +); + +$table_threshold->data[0][1] = html_print_label_input_block( + __('All state changing'), + html_print_input_text( + 'min_ff_event', + '', + '', + false, + 15, + true, + false, + false, + '', + 'w100p' + ) +); + +$table_threshold->data[0][2] = html_print_label_input_block( + __('Keep counters'), + html_print_select( + [ + '' => __('No change'), + '1' => __('Active Counters'), + '0' => __('Inactive Counters'), + ], + 'ff_type', + '', + '', + '', + '', + true, + false, + true, + 'w100p', + false, + 'width:100%' + ) +); + +$table_change_status = new stdClass(); +$table_change_status->class = 'filters filter-table-adv'; +$table_change_status->width = '100%'; +$table_change_status->size[0] = '33%'; +$table_change_status->size[1] = '33%'; +$table_change_status->size[2] = '33%'; + + +$table_change_status->data[0][0] = html_print_label_input_block( + __('To normal'), + html_print_input_text( + 'min_ff_event_normal', + '', + '', + false, + 15, + true + ) +); + +$table_change_status->data[0][1] = html_print_label_input_block( + __('To warning'), + html_print_input_text( + 'min_ff_event_warning', + '', + '', + false, + 15, + true + ) +); + +$table_change_status->data[0][2] = html_print_label_input_block( + __('To critical'), + html_print_input_text( + 'min_ff_event_critical', + '', + '', + false, + 15, + true + ) +); + +$table_threshold->colspan[1][0] = 3; +$table_threshold->data[1][0] = html_print_label_input_block( + __('Each state changing'), + html_print_table($table_change_status, true) +); + +$table->colspan[26][0] = 2; +$table->data[26][0] = html_print_label_input_block( + __('FF threshold'), + html_print_table($table_threshold, true) +); + +$table->data[27][0] = html_print_label_input_block( + __('FF interval').ui_print_help_tip( + __('Module execution flip flop time interval (in secs).'), + true + ), + html_print_input_text( + 'module_ff_interval', + '', + '', + false, + 10, + true + ) +); + +$table->data[27][1] = html_print_label_input_block( + __('FF timeout').ui_print_help_tip( + __('Timeout in secs from start of flip flop counting. If this value is exceeded, FF counter is reset. Set to 0 for no timeout.'), + true + ), + html_print_input_text( + 'ff_timeout', + '', + '', + false, + 10, + true + ) +); + +$table->data[28][0] = html_print_label_input_block( + __('Historical data'), + html_print_select(['' => __('No change'), '1' => __('Yes'), '0' => __('No')], 'history_data', '', '', '', '', true, false, true, 'w100p', false, 'width:100%') +); + +$table->data[28][1] = html_print_label_input_block( + __('Category'), + html_print_select(categories_get_all_categories('forselect'), 'id_category', '', '', __('No change'), '', true, false, false, 'w100p', false, 'width:100%') +); + +// Tags avalaible. +$table->data[29][0] = html_print_label_input_block( + __('Tags'), + html_print_select_from_sql( + 'SELECT id_tag, name FROM ttag ORDER BY name', + 'id_tag[]', + $id_tag, + '', + __('None'), + '0', + true, + true, + false, + false, + 'width: 100%', + false, + 'width:100%' + ) +); + +$table->data[29][1] = html_print_label_input_block( + __('Discard unknown events'), + html_print_select( + [ + '' => __('No change'), + '1' => __('Yes'), + '0' => __('No'), + ], + 'throw_unknown_events', + '', + '', + '', + '', + true, + false, + true, + 'w100p', + false, + 'width:100%' + ) +); + +if (enterprise_installed()) { + $table->data[30][0] = html_print_label_input_block( + __('Policy linking status').ui_print_help_tip(__('This field only has sense in modules adopted by a policy.'), true), + html_print_select([MODULE_PENDING_LINK => __('Linked'), MODULE_PENDING_UNLINK => __('Unlinked')], 'policy_linked', '', '', __('No change'), '', true, false, false, 'w100p', false, 'width:100%') + ); +} + +$table->data[32][0] = html_print_label_input_block( + __('Critical instructions').ui_print_help_tip(__('Instructions when the status is critical'), true), + html_print_textarea('critical_instructions', 2, 50, '', '', true) +); + +$table->data[32][1] = html_print_label_input_block( + __('Warning instructions').ui_print_help_tip(__('Instructions when the status is warning'), true), + html_print_textarea('warning_instructions', 2, 50, '', '', true) +); + +$table->data[33][0] = html_print_label_input_block( + __('Unknown instructions').ui_print_help_tip(__('Instructions when the status is unknown'), true), + html_print_textarea('unknown_instructions', 2, 50, '', '', true) +); + +$table->data[33][1] = html_print_label_input_block( + __('Quiet').ui_print_help_tip(__('The module still store data but the alerts and events will be stop'), true), + html_print_select( + [ + -1 => __('No change'), + 1 => __('Yes'), + 0 => __('No'), + ], + 'quiet_select', + -1, + '', + '', + 0, + true, + false, + true, + 'w100p', + false, + 'width:100%' + ) +); + +$table_timeout = new stdClass(); +$table_timeout->class = 'filters filter-table-adv'; +$table_timeout->width = '100%'; +$table_timeout->size[0] = '33%'; +$table_timeout->size[1] = '33%'; +$table_timeout->size[2] = '33%'; + +$table_timeout->data[0][0] = html_print_label_input_block( + __('Timeout').ui_print_help_tip( + __('Seconds that agent will wait for the execution of the module.'), + true + ), + html_print_input_text( + 'max_timeout', + '', + '', + false, + 10, + true + ) +); + +$table_timeout->data[0][1] = html_print_label_input_block( + __('Retries').ui_print_help_tip(__('Number of retries that the module will attempt to run.'), true), + html_print_input_text('max_retries', '', '', false, 10, true), +); + +$table_timeout->data[0][2] = html_print_label_input_block( + __('Port'), + html_print_input_text('tcp_port', '', '', false, 20, true) +); + +$table->colspan[34][0] = 2; +$table->data[34][0] = html_print_label_input_block( + '', + html_print_table($table_timeout, true) +); + +$table->colspan[35][0] = 2; +$table->data[35][0] = html_print_label_input_block( + __('Web checks'), + '' +); + +$table->data[36][0] = html_print_label_input_block( + __('TCP send'), + html_print_textarea('tcp_send2', 2, 65, '', '', true) +); + +$table->data[36][1] = html_print_label_input_block( + __('TCP receive'), + html_print_textarea('tcp_rcv', 2, 65, '', '', true) +); + +$table->data[37][0] = html_print_label_input_block( + __('WMI query'), + html_print_input_text('wmi_query', '', '', false, 255, true) +); + +$table->data[37][1] = html_print_label_input_block( + __('Key string'), + html_print_input_text('key_string', '', '', false, 60, true) +); + +$table->data[38][0] = html_print_label_input_block( + __('Field number'), + html_print_input_text('field_number', '', '', false, 15, true) +); + +if (empty($id_plugin) === false) { + $preload = db_get_sql( + sprintf( + 'SELECT description FROM tplugin WHERE id = %s', + $id_plugin + ) + ); + $preload = io_safe_output($preload); + $preload = str_replace("\n", '
', $preload); +} else { + $preload = ''; +} + +$table->data[38][1] = html_print_label_input_block( + __('Plugin').ui_print_help_icon('plugin_macros', true), + html_print_select_from_sql( + 'SELECT id, name FROM tplugin ORDER BY name', + 'id_plugin', + '', + 'changePluginSelect();', + __('None'), + 0, + true, + false, + false, + false, + 'width:100%' + ).sprintf( + '%s', + $preload + ) +); + +// Store the macros in base64 into a hidden control to move between pages. +$table->data[39][0] = html_print_label_input_block( + __('Command'), + html_print_input_text_extended( + 'tcp_send', + '', + 'command_text', + '', + false, + 10000, + false, + '', + '', + true + ).html_print_input_hidden('macros', base64_encode($macros), true) +); + +require_once $config['homedir'].'/include/class/CredentialStore.class.php'; +$array_credential_identifier = CredentialStore::getKeys('CUSTOM'); + +$table->data[39][1] = html_print_label_input_block( + __('Credential identifier'), + html_print_select( + $array_credential_identifier, + 'custom_string_1', + '', + '', + __('None'), + '', + true, + false, + false, + 'w100p' + ) +); + +$array_os = [ + '' => __('No change'), + 'inherited' => __('Inherited'), + 'linux' => __('Linux'), + 'windows' => __('Windows'), +]; +$table->data[40][0] = html_print_label_input_block( + __('rget OS'), + html_print_select( + $array_os, + 'custom_string_2', + '', + '', + '', + '', + true, + false, + false, + 'w100p' + ) +); + + echo ''; html_print_table($table); attachActionButton('update', 'update', $table->width, false, $SelectAction); @@ -1296,15 +1542,15 @@ $table->data['edit1'][1] = ''; ui_require_javascript_file('pandora_modules'); ui_require_jquery_file('pandora.controls'); - if ($selection_mode == 'modules') { - $modules_row = ''; - $agents_row = 'none'; - } else { - $modules_row = 'none'; - $agents_row = ''; - } +if ($selection_mode == 'modules') { + $modules_row = ''; + $agents_row = 'none'; +} else { + $modules_row = 'none'; + $agents_row = ''; +} - ?> +?> $extension) { + $url = sprintf( + 'godmode/servers/discovery&wiz=app&mode=%s', + $extension['short_name'] + ); + $sub2[$url]['text'] = __($extension['name']); + } + } + + if ($extensions !== false || enterprise_installed() === true) { + $sub['godmode/servers/discovery&wiz=app']['text'] = __('Applications'); + $sub['godmode/servers/discovery&wiz=app']['id'] = 'app'; + $sub['godmode/servers/discovery&wiz=app']['type'] = 'direct'; + $sub['godmode/servers/discovery&wiz=app']['subtype'] = 'nolink'; + $sub['godmode/servers/discovery&wiz=app']['sub2'] = $sub2; + } + + // Cloud. + $sub2 = []; + if (enterprise_installed() === true) { + $sub2['godmode/servers/discovery&wiz=cloud&mode=amazonws']['text'] = __('Amazon Web Services (legacy)'); + $sub2['godmode/servers/discovery&wiz=cloud&mode=azure']['text'] = __('Microsoft Azure (legacy)'); + $sub2['godmode/servers/discovery&wiz=cloud&mode=gcp']['text'] = __('Google Compute Platform (legacy)'); + } + + + $extensions = ManageExtensions::getExtensionBySection('cloud'); + if ($extensions !== false) { + foreach ($extensions as $key => $extension) { + $url = sprintf( + 'godmode/servers/discovery&wiz=cloud&mode=%s', + $extension['short_name'] + ); + $sub2[$url]['text'] = __($extension['name']); + } + } + + if ($extensions !== false || enterprise_installed() === true) { + $sub['godmode/servers/discovery&wiz=cloud']['text'] = __('Cloud'); + $sub['godmode/servers/discovery&wiz=cloud']['id'] = 'cloud'; + $sub['godmode/servers/discovery&wiz=cloud']['type'] = 'direct'; + $sub['godmode/servers/discovery&wiz=cloud']['subtype'] = 'nolink'; + $sub['godmode/servers/discovery&wiz=cloud']['sub2'] = $sub2; + } + + // Custom. + $sub2 = []; + $extensions = ManageExtensions::getExtensionBySection('custom'); + if ($extensions !== false) { + foreach ($extensions as $key => $extension) { + $url = sprintf( + 'godmode/servers/discovery&wiz=custom&mode=%s', + $extension['short_name'] + ); + $sub2[$url]['text'] = __($extension['name']); + } + + $sub['godmode/servers/discovery&wiz=custom']['text'] = __('Custom'); + $sub['godmode/servers/discovery&wiz=custom']['id'] = 'customExt'; + $sub['godmode/servers/discovery&wiz=custom']['type'] = 'direct'; + $sub['godmode/servers/discovery&wiz=custom']['subtype'] = 'nolink'; + $sub['godmode/servers/discovery&wiz=custom']['sub2'] = $sub2; + } + + if (check_acl($config['id_user'], 0, 'RW') + || check_acl($config['id_user'], 0, 'RM') + || check_acl($config['id_user'], 0, 'PM') + ) { + $sub['godmode/servers/discovery&wiz=magextensions']['text'] = __('Manage disco packages'); + $sub['godmode/servers/discovery&wiz=magextensions']['id'] = 'mextensions'; + } + + if ((bool) check_acl($config['id_user'], 0, 'RW') === true + || (bool) check_acl($config['id_user'], 0, 'RM') === true + || (bool) check_acl($config['id_user'], 0, 'PM') === true + ) { + enterprise_hook('console_task_menu'); + } } } @@ -174,6 +257,13 @@ if ($access_console_node === true) { } $sub = []; + if ((bool) check_acl($config['id_user'], 0, 'AW') === true) { + $sub['wizard']['text'] = __('Configuration wizard'); + $sub['wizard']['id'] = 'conf_wizard'; + $sub['wizard']['type'] = 'direct'; + $sub['wizard']['subtype'] = 'nolink_no_arrow'; + } + if ((bool) check_acl($config['id_user'], 0, 'PM') === true) { $sub['templates']['text'] = __('Templates'); $sub['templates']['id'] = 'Templates'; @@ -495,9 +585,13 @@ if ($access_console_node === true) { $sub2[$extmenu['sec2']]['refr'] = 0; } else { if (is_array($extmenu) === true && array_key_exists('fatherId', $extmenu) === true) { - if (strlen($extmenu['fatherId']) > 0) { + if (empty($extmenu['fatherId']) === false + && strlen($extmenu['fatherId']) > 0 + ) { if (array_key_exists('subfatherId', $extmenu) === true) { - if (strlen($extmenu['subfatherId']) > 0) { + if (empty($extmenu['subfatherId']) === false + && strlen($extmenu['subfatherId']) > 0 + ) { $menu_godmode[$extmenu['fatherId']]['sub'][$extmenu['subfatherId']]['sub2'][$extmenu['sec2']]['text'] = __($extmenu['name']); $menu_godmode[$extmenu['fatherId']]['sub'][$extmenu['subfatherId']]['sub2'][$extmenu['sec2']]['id'] = str_replace(' ', '_', $extmenu['name']); $menu_godmode[$extmenu['fatherId']]['sub'][$extmenu['subfatherId']]['sub2'][$extmenu['sec2']]['refr'] = 0; @@ -620,3 +714,55 @@ if ((bool) $config['pure'] === false) { } echo '
'; +// Need to be here because the translate string. +if (check_acl($config['id_user'], $group, 'AW')) { + ?> + + + data[0][] = html_print_label_input_block( 'width: 100%' ) ); - +$table->data[0][] = html_print_label_input_block( + __('Recursive'), + html_print_checkbox_switch( + 'group_recursive', + 1, + $group_recursive, + true + ) +); $table->data[0][] = html_print_label_input_block( __('Free Search'), html_print_input_text( @@ -712,7 +721,11 @@ ui_toggle( $filter = []; if ($search_id_group) { - $filter['id_group'] = $search_id_group; + if ($group_recursive === true) { + $filter['id_group'] = network_component_get_groups_recursive($search_id_group); + } else { + $filter['id_group'] = $search_id_group; + } } if ($search_string != '') { diff --git a/pandora_console/godmode/modules/manage_network_components_form_network.php b/pandora_console/godmode/modules/manage_network_components_form_network.php index a19c05f2a2..02af457706 100755 --- a/pandora_console/godmode/modules/manage_network_components_form_network.php +++ b/pandora_console/godmode/modules/manage_network_components_form_network.php @@ -45,7 +45,6 @@ if (!$id && !isset($snmp_community)) { } $snmp_versions['1'] = 'v. 1'; -$snmp_versions['2'] = 'v. 2'; $snmp_versions['2c'] = 'v. 2c'; $snmp_versions['3'] = 'v. 3'; diff --git a/pandora_console/godmode/netflow/nf_edit_form.php b/pandora_console/godmode/netflow/nf_edit_form.php index 9083cd2881..e79ed2715a 100644 --- a/pandora_console/godmode/netflow/nf_edit_form.php +++ b/pandora_console/godmode/netflow/nf_edit_form.php @@ -261,8 +261,8 @@ $table->data['first_line'][] = html_print_label_input_block( 'assign_group', $assign_group, '', - '', - -1, + __('All'), + 0, true, false, false, diff --git a/pandora_console/godmode/reporting/graphs.php b/pandora_console/godmode/reporting/graphs.php index 6e66c886fb..1a5fbb4283 100644 --- a/pandora_console/godmode/reporting/graphs.php +++ b/pandora_console/godmode/reporting/graphs.php @@ -488,14 +488,38 @@ if (!empty($graphs)) { true ); $ActionButtons[] = ''; + + $offset = (int) get_parameter('offset', 0); + $block_size = (int) $config['block_size']; + + $tablePagination = ui_pagination( + count($graphs), + false, + $offset, + $block_size, + true, + 'offset', + false + ); } // FALTA METER EL PRINT TABLE. html_print_table($table); - html_print_action_buttons( - implode('', $ActionButtons), - ['type' => 'form_action'] - ); + + if (is_metaconsole() === true) { + html_print_action_buttons( + implode('', $ActionButtons), + ['type' => 'form_action'] + ); + } else { + html_print_action_buttons( + implode('', $ActionButtons), + [ + 'type' => 'form_action', + 'right_content' => $tablePagination, + ] + ); + } } echo ''; diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index b33aa1efe5..397e533366 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -38,6 +38,9 @@ require_once $config['homedir'].'/include/db/oracle.php'; // Login check. check_login(); +// Validate enterprise. +$is_enterprise = enterprise_installed(); + if (! check_acl($config['id_user'], 0, 'RW') && ! check_acl($config['id_user'], 0, 'RM') ) { @@ -321,6 +324,21 @@ switch ($action) { $full_text = empty($es['full_text']) ? 0 : $es['full_text']; break; + case 'event_report_log_table': + $period = $item['period']; + $period_range = $item['period_range']; + $description = $item['description']; + + $es = json_decode($item['external_source'], true); + $id_agents = $es['id_agents']; + $source = $es['source']; + $search = $es['search']; + $log_number = empty($es['log_number']) ? $log_number : $es['log_number']; + $full_text = empty($es['full_text']) ? 0 : $es['full_text']; + $show_graph = $item['show_graph']; + $group_by_agent = $item['group_by_agent']; + break; + case 'simple_graph': $fullscale = isset($style['fullscale']) ? (bool) $style['fullscale'] : 0; $percentil = isset($style['percentil']) ? (bool) $style['percentil'] : 0; @@ -1025,6 +1043,7 @@ switch ($action) { case 'prediction_date': case 'simple_baseline_graph': case 'event_report_log': + case 'event_report_log_table': case 'increment': $label = (isset($style['label'])) ? $style['label'] : ''; break; @@ -1411,6 +1430,29 @@ $class = 'databox filters'; + + + + + - - - - - - - - + + + + + + + - - - - + } + ?> '; } diff --git a/pandora_console/godmode/setup/news.php b/pandora_console/godmode/setup/news.php index 9eb2eb8f45..6ad346586e 100644 --- a/pandora_console/godmode/setup/news.php +++ b/pandora_console/godmode/setup/news.php @@ -419,6 +419,9 @@ ui_require_jquery_file('ui.datepicker-'.get_user_language(), 'include/javascript // Include tiny for wysiwyg editor. ui_require_javascript_file('tinymce', 'vendor/tinymce/tinymce/'); ui_require_javascript_file('pandora'); +if ($config['style'] === 'pandora_black') { + html_print_input_hidden('selected_style_theme', 'pandora_black'); +} ?> diff --git a/pandora_console/godmode/setup/os.list.php b/pandora_console/godmode/setup/os.list.php index ddf2145212..330071353f 100644 --- a/pandora_console/godmode/setup/os.list.php +++ b/pandora_console/godmode/setup/os.list.php @@ -132,7 +132,15 @@ foreach ($osList as $os) { $data[] = html_print_anchor( [ 'href' => $hrefDelete, - 'content' => html_print_image('images/delete.svg', true, ['class' => 'main_menu_icon invert_filter']), + 'content' => html_print_image( + 'images/delete.svg', + true, + [ + 'alt' => __('Delete'), + 'title' => __('Delete'), + 'class' => 'main_menu_icon invert_filter', + ] + ), ], true ); diff --git a/pandora_console/godmode/setup/performance.php b/pandora_console/godmode/setup/performance.php index 0cd6c53d2d..51cd554a66 100644 --- a/pandora_console/godmode/setup/performance.php +++ b/pandora_console/godmode/setup/performance.php @@ -545,23 +545,8 @@ $table->data[6][0] = html_print_label_input_block( ) ); -$table->data[6][1] = html_print_label_input_block( - __('Max. days before delete old network matrix data'), - html_print_input( - [ - 'type' => 'number', - 'size' => 5, - 'max' => $performance_variables_control['delete_old_network_matrix']->max, - 'name' => 'delete_old_network_matrix', - 'value' => $config['delete_old_network_matrix'], - 'return' => true, - 'min' => $performance_variables_control['delete_old_network_matrix']->min, - ] - ) -); - if (enterprise_installed()) { - $table->data[7][0] = html_print_label_input_block( + $table->data[6][1] = html_print_label_input_block( __('Max. days before delete inventory data'), html_print_input_text( 'inventory_purge', @@ -574,6 +559,18 @@ if (enterprise_installed()) { ); } +$table->data[7][1] = html_print_label_input_block( + __('Max. days before disabled agents are deleted'), + html_print_input_text( + 'delete_disabled_agents', + $config['delete_disabled_agents'], + '', + false, + 0, + true + ) +); + $table_other = new stdClass(); $table_other->width = '100%'; $table_other->class = 'filter-table-adv'; diff --git a/pandora_console/godmode/setup/setup_auth.php b/pandora_console/godmode/setup/setup_auth.php index 2a7834ee1e..6616cd765c 100644 --- a/pandora_console/godmode/setup/setup_auth.php +++ b/pandora_console/godmode/setup/setup_auth.php @@ -210,7 +210,7 @@ if (is_ajax() === true) { // Ldapsearch timeout. // Default Ldapsearch timeout. - set_when_empty($config['ldap_searh_timeout'], 5); + set_when_empty($config['ldap_search_timeout'], 5); $row = []; $row['name'] = __('Ldap search timeout (secs)'); $row['control'] = html_print_input_text( @@ -418,7 +418,27 @@ if (is_ajax() === true) { $table->rowclass['2FA_all_users'] = ''; } - $table->data['2FA_all_users'] = $row; + $table->data['2FA_all_users'] = $row; + + // Session timeout behavior. + // Set default value. + $row = []; + $options = [ + 'check_activity' => __('Check activity'), + 'ignore_activity' => __('Ignore activity'), + ]; + + $row['name'] = __('Control of timeout session').ui_print_help_tip(__('Select \'ignore activity\' to ignore user activity when checking the session.'), true); + $row['control'] = html_print_select( + $options, + 'control_session_timeout', + $config['control_session_timeout'], + '', + '', + 0, + true + ); + $table->data['session_timeouts'] = $row; // Session timeout. @@ -538,7 +558,13 @@ echo ''; if ($('input[type=checkbox][name=secondary_ldap_enabled]:checked').val() == 1) { $("tr[id*='ldap_'][id$='_secondary']").show(); } else { - $( "tr[id*='ldap_'][id$='_secondary']" ).hide(); + $( "tr[id*='ldap_'][id$='_secondary']" ).hide(); + } + + if ($('input[type=checkbox][name=secondary_active_directory]:checked').val() == 1) { + $("tr[id*='ad_'][id$='_secondary']").show(); + } else { + $( "tr[id*='ad_'][id$='_secondary']" ).hide(); } } $( document ).ready(function() { diff --git a/pandora_console/godmode/setup/setup_general.php b/pandora_console/godmode/setup/setup_general.php index ed351317dd..aa55893d11 100644 --- a/pandora_console/godmode/setup/setup_general.php +++ b/pandora_console/godmode/setup/setup_general.php @@ -433,7 +433,7 @@ $table->data[$i++][] = html_print_label_input_block( __('Enable Feedback'), html_print_checkbox_switch_extended( 'activate_feedback', - 1, + true, $config['activate_feedback'], false, '', @@ -681,15 +681,19 @@ $table->data[$i++][] = html_print_label_input_block( ) ); +$help_tip = ui_print_help_tip( + __('This log is recommended to be DISABLED by default due to the large amount of debug data it generates.'), + true +); $table->data[$i][] = html_print_label_input_block( - __('Enable console log'), + __('Enable console log').$help_tip, html_print_checkbox_switch( 'console_log_enabled', 1, $config['console_log_enabled'], true ).ui_print_input_placeholder( - __('Log location').': pandora_console/log/console.log', + __('Log location').': /var/log/php-fpm/error.log', true ) ); @@ -743,6 +747,26 @@ $table->data[$i][] = html_print_label_input_block( ) ); +$table->data[$i++][] = html_print_label_input_block( + __('Max. hours old events comments'), + html_print_input_number( + [ + 'name' => 'max_hours_old_event_comment', + 'min' => 0, + 'value' => $config['max_hours_old_event_comment'], + ] + ) +); +$table->data[$i][] = html_print_label_input_block( + __('Show experimental features'), + html_print_checkbox_switch( + 'show_experimental_features', + 1, + $config['show_experimental_features'], + true + ) +); + echo ''; echo '
'; diff --git a/pandora_console/godmode/setup/setup_visuals.php b/pandora_console/godmode/setup/setup_visuals.php index 340cb30565..6753d1d499 100755 --- a/pandora_console/godmode/setup/setup_visuals.php +++ b/pandora_console/godmode/setup/setup_visuals.php @@ -1344,17 +1344,6 @@ $table_vc->style[0] = 'font-weight: bold'; $table_vc->size[0] = '50%'; $table_vc->data = []; -// Remove when the new view reaches rock solid stability. -$table_vc->data[$row][] = html_print_label_input_block( - __('Legacy Visual Console View'), - html_print_checkbox_switch( - 'legacy_vc', - 1, - (bool) $config['legacy_vc'], - true - ) -); - $table_vc->data[$row][] = html_print_label_input_block( __('Default cache expiration'), html_print_extended_select_for_time( @@ -1372,7 +1361,6 @@ $table_vc->data[$row][] = html_print_label_input_block( $intervals ) ); -$row++; $table_vc->data[$row][] = html_print_label_input_block( __('Default interval for refresh on Visual Console'), @@ -1388,6 +1376,7 @@ $table_vc->data[$row][] = html_print_label_input_block( false ) ); +$row++; $table_vc->data[$row][] = html_print_label_input_block( __('Type of view of visual consoles'), @@ -1401,12 +1390,12 @@ $table_vc->data[$row][] = html_print_label_input_block( true ) ); -$row++; $table_vc->data[$row][] = html_print_label_input_block( __('Number of favorite visual consoles to show in the menu'), "" ); +$row++; $table_vc->data[$row][] = html_print_label_input_block( __('Default line thickness for the Visual Console'), @@ -1419,10 +1408,9 @@ $table_vc->data[$row][] = html_print_label_input_block( true ) ); -$row++; $table_vc->data[$row][] = html_print_label_input_block( - __('Mobile view not allow visual console orientation'), + __('Lock screen orientation when viewing on mobile devices'), html_print_checkbox_switch( 'mobile_view_orientation_vc', 1, @@ -1430,6 +1418,7 @@ $table_vc->data[$row][] = html_print_label_input_block( true ) ); +$row++; $table_vc->data[$row][] = html_print_label_input_block( __('Display item frame on alert triggered'), @@ -1783,7 +1772,9 @@ $table_other->data[$row][] = html_print_label_input_block( 100, true ).ui_print_input_placeholder( - __('Example').': '.date($config['date_format']), + __('Example').': '.date( + str_replace(' ', ' ', $config['date_format']) + ), true ) ); @@ -1936,7 +1927,7 @@ $table_other->data[$row][] = html_print_label_input_block( ).html_print_div( [ 'class' => '', - 'content' => __('Interval').html_print_select($units, 'interval_unit', 1, '', '', '', true, false, false, '', false, 'width: 100%'), + 'content' => __('Interval').html_print_select($units, 'interval_unit', '', '', '', '', true, false, false, '', false, 'width: 100%'), ], true ).html_print_button( @@ -1984,7 +1975,7 @@ $table_other->data[$row][] = html_print_label_input_block( ).html_print_button( __('Delete'), 'interval_del_btn', - empty($config['interval_values']), + false, '', [ 'mode' => 'link', @@ -2018,7 +2009,7 @@ $table_other->data[$row][] = html_print_label_input_block( ).html_print_div( [ 'class' => '', - 'content' => __('Interval').html_print_select($units, 'interval_unit', 1, '', '', '', true, false, false, '', false, 'width: 100%'), + 'content' => __('Interval').html_print_select($units, 'module_interval_unit', 1, '', '', '', true, false, false, '', false, 'width: 100%'), ], true ).html_print_button( @@ -2325,9 +2316,15 @@ $(document).ready (function () { // CUSTOM INTERVAL VALUES //------------------------------------------------------------------ $("#button-interval_del_btn").click( function() { - var interval_selected = $('#intervals option:selected').val(); - $('#hidden-interval_to_delete').val(interval_selected); - $('#submit-update_button').trigger('click'); + confirmDialog({ + title: "", + message: "", + onAccept: function() { + var interval_selected = $('#intervals option:selected').val(); + $('#hidden-interval_to_delete').val(interval_selected); + $('#button-update_button').trigger('click'); + } + }); }); $("#button-interval_add_btn").click( function() { diff --git a/pandora_console/godmode/snmpconsole/snmp_alert.php b/pandora_console/godmode/snmpconsole/snmp_alert.php index dd0190f1ae..d23b65d7ea 100755 --- a/pandora_console/godmode/snmpconsole/snmp_alert.php +++ b/pandora_console/godmode/snmpconsole/snmp_alert.php @@ -786,7 +786,7 @@ if ($create_alert || $update_alert) { 2, 2, $custom_value, - 'class="w100p"', + 'class="w100p" required="required"', true ) ); @@ -804,6 +804,8 @@ if ($create_alert || $update_alert) { '', 50, 255, + true, + false, true ) ); @@ -818,6 +820,8 @@ if ($create_alert || $update_alert) { '', 20, 255, + true, + false, true ) ); @@ -2002,6 +2006,7 @@ if ($create_alert || $update_alert) { 'alt' => __('Update'), 'border' => 0, 'class' => 'main_menu_icon', + 'title' => __('Edit'), ] ), ], @@ -2170,24 +2175,11 @@ if ($create_alert || $update_alert) { echo ''; } - echo '
'; - echo '
'; - html_print_input_hidden('create_alert', 1); - $submitButton = html_print_submit_button( - __('Create'), - 'alert', - false, - ['icon' => 'wand'], - true - ); - html_print_action_buttons($submitButton.$deleteButton, ['right_content' => $pagination]); - echo '
'; - - $legend = '
+ + + +
- -
+
+ +
+ +
option:selected").val() == undefined) { dialog_message('#message_no_group'); @@ -6385,6 +6436,7 @@ function chooseType() { $("#row_description").hide(); $("#row_label").hide(); $("#row_period").hide(); + $("#row_period_range").hide(); $("#row_agent").hide(); $("#row_module").hide(); $("#row_period").hide(); @@ -6559,7 +6611,24 @@ function chooseType() { loadLogAgents(); - break; + break; + + case 'event_report_log_table': + $("#log_help_tip").css("visibility", "visible"); + $("#row_description").show(); + $("#row_period").show(); + $("#row_period_range").show(); + $("#row_search").show(); + $("#row_log_number").show(); + $("#agents_row").show(); + $("#row_source").show(); + $("#row_historical_db_check").hide(); + $("#row_show_graph").show(); + $("#row_group_by_agent").show(); + + loadLogAgents(); + + break; case 'increment': $("#row_description").show(); @@ -6651,6 +6720,8 @@ function chooseType() { $("#row_agent").show(); $("#row_module").show(); $("#row_historical_db_check").hide(); + period_set_value($("#hidden-period").attr('class'), 3600); + $("#row_period").find('select').val('3600').trigger('change'); break; case 'SLA_monthly': @@ -7522,9 +7593,68 @@ function dialog_message(message_id) { } }); } - +function control_period_range() { + let value_period_range = $('#row_period_range #hidden-period_range').val(); + let current_value = $('#row_period #hidden-period').val(); + let min_range = (current_value/12); + if(min_range > value_period_range) { + $('#row_period_range div:nth-child(2) select option').removeAttr("selected"); + $('#row_period_range div:nth-child(1)').hide(); + $('#row_period_range div:nth-child(2)').show(); + setTimeout(() => { + if(min_range >= 2592000) { + $('#row_period_range input').val(Math.round((min_range/2592000) * 100) / 100); + $('#row_period_range div:nth-child(2) select option[value="2592000"]').attr("selected", "selected"); + $('#row_period_range div:nth-child(2) select').val(2592000); + $('#row_period_range #hidden-period_range').val(min_range); + return; + } + if(min_range >= 604800) { + $('#row_period_range input').val(Math.round((min_range/604800) * 100) / 100); + $('#row_period_range div:nth-child(2) select option[value="604800"]').attr("selected", "selected"); + $('#row_period_range div:nth-child(2) select').val(604800); + $('#row_period_range #hidden-period_range').val(min_range); + return; + } + if(min_range >= 86400) { + $('#row_period_range input').val(Math.round((min_range/86400) * 100) / 100); + $('#row_period_range div:nth-child(2) select option[value="86400"]').attr("selected", "selected"); + $('#row_period_range div:nth-child(2) select').val(86400); + $('#row_period_range #hidden-period_range').val(min_range); + return; + } + if(min_range >= 3600) { + $('#row_period_range input').val(Math.round((min_range/3600) * 100) / 100); + $('#row_period_range div:nth-child(2) select option[value="3600"]').attr("selected", "selected"); + $('#row_period_range div:nth-child(2) select').val(3600); + $('#row_period_range #hidden-period_range').val(min_range); + return; + } + if(min_range >= 60) { + $('#row_period_range input').val(Math.round((min_range/60) * 100) / 100); + $('#row_period_range div:nth-child(2) select option[value="60"]').attr("selected", "selected"); + $('#row_period_range div:nth-child(2) select option[value="60"]').val(60); + $('#row_period_range #hidden-period_range').val(min_range); + return; + } + }, 800); + } +} $(document).ready(function () { $('[id^=period], #combo_graph_options, #combo_sla_sort_options').next().css('z-index', 0); + + $('#row_period input').change(function(e){ + control_period_range(); + }); + $('#row_period select').change(function(e){ + control_period_range(); + }); + $('#row_period_range input').change(function(e){ + control_period_range(); + }); + $('#row_period_range select').change(function(e){ + control_period_range(); + }); }); diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index edf4df6a40..2600c9aea2 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -116,10 +116,13 @@ if (!$report_r && !$report_w && !$report_m) { } require_once $config['homedir'].'/include/functions_reports.php'; +require_once $config['homedir'].'/godmode/wizards/DiscoveryTaskList.class.php'; // Load enterprise extensions. enterprise_include('operation/reporting/custom_reporting.php'); enterprise_include_once('include/functions_metaconsole.php'); +enterprise_include_once('include/functions_tasklist.php'); +enterprise_include_once('include/functions_cron.php'); @@ -508,11 +511,11 @@ switch ($action) { $buttons = [ 'list_reports' => [ 'active' => false, - 'text' => ''.html_print_image( + 'text' => ''.html_print_image( 'images/logs@svg.svg', true, [ - 'title' => __('Reports list'), + 'title' => __('Reports'), 'class' => 'main_menu_icon invert_filter', ] ).'', @@ -545,7 +548,7 @@ switch ($action) { // Header. ui_print_standard_header( - __('List of reports'), + __('Reports'), 'images/op_reporting.png', false, '', @@ -782,7 +785,7 @@ switch ($action) { ''.__('Filters').'', 'filter_form', '', - false, + true, false, '', 'white-box-content', @@ -1251,7 +1254,12 @@ switch ($action) { array_push($table->data, $data); } - html_print_table($table); + $reports_table = '
'; + $reports_table .= ''.__('Reports').''; + $reports_table .= html_print_table($table, true); + $reports_table .= '
'; + echo $reports_table; + $tablePagination = ui_pagination( $total_reports, $url, @@ -1259,7 +1267,7 @@ switch ($action) { $pagination, true, 'offset', - false, + false ); } else { ui_print_info_message( @@ -1270,6 +1278,24 @@ switch ($action) { ); } + $discovery_tasklist = new DiscoveryTaskList(); + $report_task_data = $discovery_tasklist->showListConsoleTask(true); + if (is_array($report_task_data) === true || (strpos($report_task_data, 'class="nf"') === false && $report_task_data !== -1)) { + $task_table = '
'; + $task_table .= ''.__('Report tasks'); + $task_table .= ui_print_help_tip(__('To schedule a report, do it from the editing view of each report.'), true); + $task_table .= '
'; + $task_table .= $report_task_data; + $task_table .= '
'; + echo $task_table; + } else { + if ($report_task_data === -1) { + $report_task_data = ''; + } + + ui_print_info_message($report_task_data.__('To schedule a report, do it from the editing view of each report.')); + } + if (check_acl($config['id_user'], 0, 'RW') || check_acl($config['id_user'], 0, 'RM') ) { @@ -1621,6 +1647,27 @@ switch ($action) { $good_format = true; break; + case 'event_report_log_table': + $agents_to_report = get_parameter('id_agents3'); + $source = get_parameter('source', ''); + $search = get_parameter('search', ''); + $full_text = (integer) get_parameter('full_text', 0); + $log_number = get_parameter('log_number', ''); + + $es['source'] = $source; + $es['id_agents'] = $agents_to_report; + $es['search'] = $search; + $es['full_text'] = $full_text; + $es['log_number'] = $log_number; + + $values['external_source'] = json_encode($es); + $values['period'] = get_parameter('period'); + $values['period_range'] = get_parameter('period_range'); + $values['show_graph'] = get_parameter('combo_graph_options'); + $values['group_by_agent'] = get_parameter('checkbox_row_group_by_agent'); + $good_format = true; + break; + case 'prediction_date': $values['period'] = get_parameter('period1'); $values['top_n'] = get_parameter( @@ -2605,6 +2652,27 @@ switch ($action) { $good_format = true; break; + case 'event_report_log_table': + $agents_to_report = get_parameter('id_agents3'); + $source = get_parameter('source', ''); + $search = get_parameter('search', ''); + $full_text = (integer) get_parameter('full_text', 0); + $log_number = get_parameter('log_number', ''); + + $es['source'] = $source; + $es['id_agents'] = $agents_to_report; + $es['search'] = $search; + $es['full_text'] = $full_text; + $es['log_number'] = $log_number; + + $values['external_source'] = json_encode($es); + $values['period'] = get_parameter('period'); + $values['period_range'] = get_parameter('period_range'); + $values['show_graph'] = get_parameter('combo_graph_options'); + $values['group_by_agent'] = get_parameter('checkbox_row_group_by_agent'); + $good_format = true; + break; + case 'agent_module': case 'agent_module_status': $agents_to_report_text = get_parameter('id_agents2-multiple-text'); @@ -3636,7 +3704,7 @@ switch ($action) { $buttons = [ 'list_reports' => [ 'active' => false, - 'text' => ''.html_print_image('images/logs@svg.svg', true, ['title' => __('Reports list'), 'class' => 'invert_filter main_menu_icon']).'', + 'text' => ''.html_print_image('images/logs@svg.svg', true, ['title' => __('Reports'), 'class' => 'invert_filter main_menu_icon']).'', ], ]; @@ -3703,7 +3771,7 @@ $buttons = [ 'images/report_list.png', true, [ - 'title' => __('Reports list'), + 'title' => __('Reports'), 'class' => 'main_menu_icon invert_filter', ] ).'', @@ -3751,12 +3819,13 @@ if ($idReport != 0) { $buttons = [ 'main' => [ 'active' => true, - 'text' => ''.html_print_image('images/report_list.png', true, ['title' => __('Reports list'), 'class' => 'main_menu_icon invert_filter']).'', + 'text' => ''.html_print_image('images/report_list.png', true, ['title' => __('Reports'), 'class' => 'main_menu_icon invert_filter']).'', ], ]; $textReportName = __('Create Custom Report'); } +// here1 $tab_builder = ($activeTab === 'item_editor') ? 'reporting_item_editor_tab' : ''; if (is_metaconsole() === true || $action !== 'update') { @@ -3817,7 +3886,7 @@ if ($resultOperationDB !== null) { break; case 'SLA': - $err .= 'You must enter some character in SLA limit field'; + $err .= 'No changes found.'; default: $err .= ''; break; @@ -3826,7 +3895,7 @@ if ($resultOperationDB !== null) { ui_print_result_message( $resultOperationDB, __('Successfull action'), - __('Unsuccessful action

'.$err) + __($err) ); } diff --git a/pandora_console/godmode/reporting/visual_console_builder.editor.js b/pandora_console/godmode/reporting/visual_console_builder.editor.js index 3035fed8ae..6f941c7902 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.editor.js +++ b/pandora_console/godmode/reporting/visual_console_builder.editor.js @@ -2,7 +2,7 @@ // Pandora FMS - http://pandorafms.com // ================================================== -// Copyright (c) 2005-2021 Artica Soluciones Tecnologicas +// Copyright (c) 2005-2023 Pandora FMS // Please see http://pandorafms.org for full contribution list // This program is free software; you can redistribute it and/or diff --git a/pandora_console/godmode/reporting/visual_console_builder.elements.php b/pandora_console/godmode/reporting/visual_console_builder.elements.php index 05668797ec..300ea33f40 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.elements.php +++ b/pandora_console/godmode/reporting/visual_console_builder.elements.php @@ -182,7 +182,7 @@ if ($layoutDatas === false) { $alternativeStyle = true; $parents = visual_map_get_items_parents($idVisualConsole); - +$x = 0; foreach ($layoutDatas as $layoutData) { $idLayoutData = $layoutData['id']; @@ -537,7 +537,8 @@ foreach ($layoutDatas as $layoutData) { $table->data[($i + 1)][5] = ''; $table->data[($i + 1)][5] .= html_print_checkbox('multiple_delete_items', $idLayoutData, false, true); - $table->data[($i + 1)][5] .= ''.html_print_image('images/delete.svg', true, ['class' => 'main_menu_icon invert_filter']).''; + $table->data[($i + 1)][5] .= ''.html_print_image('images/delete.svg', true, ['class' => 'main_menu_icon invert_filter']).''; + $table->data[($i + 1)][5] .= html_print_input_hidden('updated_'.$idLayoutData, '0', true); // Second row $table->data[($i + 2)]['icon'] = ''; @@ -778,6 +779,12 @@ foreach ($layoutDatas as $layoutData) { $alternativeStyle = !$alternativeStyle; $i = ($i + 3); + $x++; +} + +$x = (($x * 13) + 14); +if ($x > ini_get('max_input_vars')) { + ui_print_warning_message(__('You have to change the "max_input_vars" and set bigger value on php.ini for update, there is too much elements to update')); } $pure = get_parameter('pure', 0); @@ -888,6 +895,16 @@ ui_require_javascript_file('tinymce', 'vendor/tinymce/tinymce/'); return false; }); + $('select[id^="image_"], input[name^="width_"], input[name^="height"], input[name^="left_"], input[name^="top_"], select[id^="parent_"], input[id^="agent_"], select[id^="module_"]').change(function(){ + var id = $(this).attr('id').split('_')[1]; + $('#hidden-updated_'+id).val('1'); + }); + + $('select[id^="map_linked"]').change(function(){ + var id = $(this).attr('id').split('_')[2]; + $('#hidden-updated_'+id).val('1'); + }); + defineTinyMCE('#tinyMCE_editor'); $("#dialog_label_editor").hide () diff --git a/pandora_console/godmode/reporting/visual_console_builder.php b/pandora_console/godmode/reporting/visual_console_builder.php index 740b97708a..c7da988cd0 100755 --- a/pandora_console/godmode/reporting/visual_console_builder.php +++ b/pandora_console/godmode/reporting/visual_console_builder.php @@ -418,7 +418,6 @@ switch ($activeTab) { case 'update': // Update background $background = get_parameter('background'); - $background_color = get_parameter('background_color'); $width = get_parameter('width'); $height = get_parameter('height'); @@ -433,10 +432,9 @@ switch ($activeTab) { db_process_sql_update( 'tlayout', [ - 'background' => $background, - 'background_color' => $background_color, - 'width' => $width, - 'height' => $height, + 'background' => $background, + 'width' => $width, + 'height' => $height, ], ['id' => $idVisualConsole] ); @@ -463,62 +461,65 @@ switch ($activeTab) { foreach ($idsElements as $idElement) { $id = $idElement['id']; - $values = []; - $values['label'] = get_parameter('label_'.$id, ''); - $values['image'] = get_parameter('image_'.$id, ''); - $values['width'] = get_parameter('width_'.$id, 0); - $values['height'] = get_parameter('height_'.$id, 0); - $values['pos_x'] = get_parameter('left_'.$id, 0); - $values['pos_y'] = get_parameter('top_'.$id, 0); - switch ($idElement['type']) { - case NETWORK_LINK: - case LINE_ITEM: - continue 2; + $update = get_parameter('updated_'.$id, 0); + if ($update === '1') { + $values = []; + $values['label'] = get_parameter('label_'.$id, ''); + $values['image'] = get_parameter('image_'.$id, ''); + $values['width'] = get_parameter('width_'.$id, 0); + $values['height'] = get_parameter('height_'.$id, 0); + $values['pos_x'] = get_parameter('left_'.$id, 0); + $values['pos_y'] = get_parameter('top_'.$id, 0); + switch ($idElement['type']) { + case NETWORK_LINK: + case LINE_ITEM: + continue 2; - break; + break; - case SIMPLE_VALUE_MAX: - case SIMPLE_VALUE_MIN: - case SIMPLE_VALUE_AVG: - $values['period'] = get_parameter('period_'.$id, 0); - break; + case SIMPLE_VALUE_MAX: + case SIMPLE_VALUE_MIN: + case SIMPLE_VALUE_AVG: + $values['period'] = get_parameter('period_'.$id, 0); + break; - case MODULE_GRAPH: - $values['period'] = get_parameter('period_'.$id, 0); - unset($values['image']); - break; + case MODULE_GRAPH: + $values['period'] = get_parameter('period_'.$id, 0); + unset($values['image']); + break; - case GROUP_ITEM: - $values['id_group'] = get_parameter('group_'.$id, 0); - break; + case GROUP_ITEM: + $values['id_group'] = get_parameter('group_'.$id, 0); + break; - case CIRCULAR_PROGRESS_BAR: - case CIRCULAR_INTERIOR_PROGRESS_BAR: - case PERCENTILE_BUBBLE: - case PERCENTILE_BAR: - unset($values['height']); - break; + case CIRCULAR_PROGRESS_BAR: + case CIRCULAR_INTERIOR_PROGRESS_BAR: + case PERCENTILE_BUBBLE: + case PERCENTILE_BAR: + unset($values['height']); + break; + } + + $agentName = get_parameter('agent_'.$id, ''); + if (defined('METACONSOLE')) { + $values['id_metaconsole'] = (int) get_parameter('id_server_id_'.$id, ''); + $values['id_agent'] = (int) get_parameter('id_agent_'.$id, 0); + } else { + $agent_id = (int) get_parameter('id_agent_'.$id, 0); + $values['id_agent'] = $agent_id; + } + + $values['id_agente_modulo'] = get_parameter('module_'.$id, 0); + $values['id_custom_graph'] = get_parameter('custom_graph_'.$id, 0); + $values['parent_item'] = get_parameter('parent_'.$id, 0); + $values['id_layout_linked'] = get_parameter('map_linked_'.$id, 0); + + if (enterprise_installed()) { + enterprise_visual_map_update_action_from_list_elements($type, $values, $id); + } + + db_process_sql_update('tlayout_data', $values, ['id' => $id]); } - - $agentName = get_parameter('agent_'.$id, ''); - if (defined('METACONSOLE')) { - $values['id_metaconsole'] = (int) get_parameter('id_server_id_'.$id, ''); - $values['id_agent'] = (int) get_parameter('id_agent_'.$id, 0); - } else { - $agent_id = (int) get_parameter('id_agent_'.$id, 0); - $values['id_agent'] = $agent_id; - } - - $values['id_agente_modulo'] = get_parameter('module_'.$id, 0); - $values['id_custom_graph'] = get_parameter('custom_graph_'.$id, 0); - $values['parent_item'] = get_parameter('parent_'.$id, 0); - $values['id_layout_linked'] = get_parameter('map_linked_'.$id, 0); - - if (enterprise_installed()) { - enterprise_visual_map_update_action_from_list_elements($type, $values, $id); - } - - db_process_sql_update('tlayout_data', $values, ['id' => $id]); } break; @@ -837,12 +838,6 @@ $buttons['wizard'] = [ 'active' => false, 'text' => ''.html_print_image('images/wizard@svg.svg', true, ['title' => __('Wizard'), 'class' => 'invert_filter']).'', ]; -if ($config['legacy_vc']) { - $buttons['editor'] = [ - 'active' => false, - 'text' => ''.html_print_image('images/builder@svg.svg', true, ['title' => __('Builder'), 'class' => 'invert_filter']).'', - ]; -} $buttons['view'] = [ 'active' => false, diff --git a/pandora_console/godmode/servers/discovery.php b/pandora_console/godmode/servers/discovery.php index 3df3342f52..9af4343a84 100755 --- a/pandora_console/godmode/servers/discovery.php +++ b/pandora_console/godmode/servers/discovery.php @@ -53,6 +53,12 @@ function get_wiz_class($str) case 'deploymentCenter': return 'DeploymentCenter'; + case 'magextensions': + return 'ManageExtensions'; + + case 'custom': + return 'Custom'; + default: // Main, show header. ui_print_standard_header( @@ -161,7 +167,7 @@ if ($classname_selected === null) { $wiz_data = []; foreach ($classes as $classpath) { if (is_reporting_console_node() === true) { - if ($classpath !== '/var/www/html/pandora_console/godmode/wizards/DiscoveryTaskList.class.php') { + if ($classpath !== $config['homedir'].'/godmode/wizards/DiscoveryTaskList.class.php') { continue; } } @@ -169,6 +175,12 @@ if ($classname_selected === null) { $classname = basename($classpath, '.class.php'); $obj = new $classname(); + if (method_exists($obj, 'isEmpty') === true) { + if ($obj->isEmpty() === true) { + continue; + } + } + $button = $obj->load(); if ($button === false) { diff --git a/pandora_console/godmode/servers/modificar_server.php b/pandora_console/godmode/servers/modificar_server.php index acc9ad7665..4b3f26606a 100644 --- a/pandora_console/godmode/servers/modificar_server.php +++ b/pandora_console/godmode/servers/modificar_server.php @@ -45,9 +45,120 @@ if (! check_acl($config['id_user'], 0, 'AW')) { if (isset($_GET['server']) === true) { $id_server = get_parameter_get('server'); + $title = __('Update').' '; + $sql = sprintf('SELECT name, ip_address, description, server_type, exec_proxy, port FROM tserver WHERE id_server = %d', $id_server); + $row = db_get_row_sql($sql); + + switch ($row['server_type']) { + case SERVER_TYPE_DATA: + $title .= __('Data server').' ID: '.$id_server; + break; + + case SERVER_TYPE_NETWORK: + $title .= __('Network server').' ID: '.$id_server; + break; + + case SERVER_TYPE_SNMP: + $title .= __('SNMP Trap server').' ID: '.$id_server; + break; + + case SERVER_TYPE_DISCOVERY: + $title .= __('Discovery server').' ID: '.$id_server; + break; + + case SERVER_TYPE_PLUGIN: + $title .= __('Plugin server').' ID: '.$id_server; + break; + + case SERVER_TYPE_PREDICTION: + $title .= __('Prediction server').' ID: '.$id_server; + break; + + case SERVER_TYPE_WMI: + $title .= __('WMI server').' ID: '.$id_server; + break; + + case SERVER_TYPE_EXPORT: + $title .= __('Export server').' ID: '.$id_server; + $id_modulo = 0; + break; + + case SERVER_TYPE_INVENTORY: + $title .= __('Inventory server').' ID: '.$id_server; + break; + + case SERVER_TYPE_WEB: + $title .= __('Web server').' ID: '.$id_server; + break; + + case SERVER_TYPE_EVENT: + $title .= __('Event server').' ID: '.$id_server; + break; + + case SERVER_TYPE_CORRELATION: + $title .= __('Correlation server').' ID: '.$id_server; + break; + + case SERVER_TYPE_ENTERPRISE_ICMP: + $title .= __('Enterprise ICMP server').' ID: '.$id_server; + break; + + case SERVER_TYPE_ENTERPRISE_SNMP: + $title .= __('Enterprise SNMP server').' ID: '.$id_server; + break; + + case SERVER_TYPE_ENTERPRISE_SATELLITE: + $title .= __('Enterprise Satellite server').' ID: '.$id_server; + break; + + case SERVER_TYPE_ENTERPRISE_TRANSACTIONAL: + $title .= __('Enterprise Transactional server').' ID: '.$id_server; + break; + + case SERVER_TYPE_MAINFRAME: + $title .= __('Mainframe server').' ID: '.$id_server; + break; + + case SERVER_TYPE_SYNC: + $title .= __('Sync server').' ID: '.$id_server; + break; + + case SERVER_TYPE_WUX: + $title .= __('Wux server').' ID: '.$id_server; + break; + + case SERVER_TYPE_SYSLOG: + $title .= __('Log server').' ID: '.$id_server; + break; + + case SERVER_TYPE_NCM: + $title .= __('NCM server').' ID: '.$id_server; + break; + + case SERVER_TYPE_AUTOPROVISION: + $title .= __('Autoprovision server').' ID: '.$id_server; + break; + + case SERVER_TYPE_MIGRATION: + $title .= __('Migration server').' ID: '.$id_server; + break; + + case SERVER_TYPE_ALERT: + $title .= __('Alert server').' ID: '.$id_server; + break; + + case SERVER_TYPE_NETFLOW: + $title .= __('Netflow server').' ID: '.$id_server; + break; + + default: + $title = __('Update server').' ID: '.$id_server; + break; + } + // Headers. ui_print_standard_header( - __('Update Server'), + $title, 'images/gm_servers.png', false, '', @@ -65,8 +176,6 @@ if (isset($_GET['server']) === true) { ] ); - $sql = sprintf('SELECT name, ip_address, description, server_type, exec_proxy, port FROM tserver WHERE id_server = %d', $id_server); - $row = db_get_row_sql($sql); echo '
'; html_print_input_hidden('server', $id_server); @@ -212,7 +321,7 @@ if (isset($_GET['server']) === true) { false, 'servers', true, - [], + $buttons, [ [ 'link' => '', diff --git a/pandora_console/godmode/servers/pending_alerts_list.php b/pandora_console/godmode/servers/pending_alerts_list.php new file mode 100644 index 0000000000..054a48aeb0 --- /dev/null +++ b/pandora_console/godmode/servers/pending_alerts_list.php @@ -0,0 +1,71 @@ + '[PendingAlertsList]'.$e->getMessage() ]); + exit; + } else { + echo '[PendingAlertsList]'.$e->getMessage(); + } + + // Stop this execution, but continue 'globally'. + return; +} + +// AJAX controller. +if (is_ajax()) { + $method = get_parameter('method'); + + if (method_exists($adw, $method) === true) { + if ($adw->ajaxMethod($method) === true) { + $adw->{$method}(); + } else { + $adw->error('Unavailable method.'); + } + } else { + $adw->error('Method not found. ['.$method.']'); + } + + // Stop any execution. + exit; +} else { + // Run. + $adw->run(); +} diff --git a/pandora_console/godmode/servers/plugin.php b/pandora_console/godmode/servers/plugin.php index 8acaa41311..315702528e 100644 --- a/pandora_console/godmode/servers/plugin.php +++ b/pandora_console/godmode/servers/plugin.php @@ -537,17 +537,16 @@ if (empty($create) === false || empty($view) === false) { $data = []; $data[0] = html_print_label_input_block( __('Plug-in parameters'), - html_print_input_text( + html_print_textarea( 'form_parameters', + 4, + 50, $parameters, '', - 100, - 255, true, + 'command_component command_advanced_conf text_input', false, - false, - '', - 'command_component command_advanced_conf text_input' + false ) ); @@ -561,7 +560,14 @@ if (empty($create) === false || empty($view) === false) { // $data[0] = html_print_div(['id' => 'command_preview', 'class' => 'mono'], true); $data[0] = html_print_label_input_block( __('Command preview'), - html_print_div(['id' => 'command_preview', 'class' => 'mono'], true) + html_print_div( + [ + 'id' => 'command_preview', + 'class' => 'mono', + 'style' => 'max-width: 1050px;overflow-wrap: break-word;', + ], + true + ) ); $table->data['plugin_preview_inputs'] = $data; $table->colspan['plugin_preview_inputs'][0] = 2; @@ -1167,7 +1173,7 @@ ui_require_javascript_file('pandora_modules'); function update_preview() { var command = $('#text-form_execute').val(); - var parameters = $('#text-form_parameters').val(); + var parameters = $('#textarea_form_parameters').val(); var i = 1; while (1) { diff --git a/pandora_console/godmode/servers/servers.build_table.php b/pandora_console/godmode/servers/servers.build_table.php index cce4e1e053..101a99d955 100644 --- a/pandora_console/godmode/servers/servers.build_table.php +++ b/pandora_console/godmode/servers/servers.build_table.php @@ -28,6 +28,7 @@ // Begin. require_once 'include/functions_clippy.php'; +require_once 'pending_alerts_list.php'; global $config; @@ -101,6 +102,13 @@ foreach ($servers as $server) { } } +$ext = ''; + +// Check for any data-type server present in servers list. If none, enable server access for first server. +if (array_search('data', array_column($servers, 'type')) === false) { + $ext = '_server'; +} + foreach ($servers as $server) { $data = []; @@ -185,14 +193,12 @@ foreach ($servers as $server) { $data[7] = ui_print_timestamp($server['keepalive'], true); - - $ext = '_server'; - if ($server['type'] != 'data') { - $ext = ''; + if ($server['type'] === 'data') { + $ext = '_server'; } $safe_server_name = servers_get_name($server['id_server']); - if (($server['type'] == 'data' || $server['type'] == 'enterprise satellite')) { + if (($ext === '_server' || $server['type'] == 'enterprise satellite')) { if (servers_check_remote_config($safe_server_name.$ext) && enterprise_installed()) { $names_servers[$safe_server_name] = true; } else { @@ -242,6 +248,19 @@ foreach ($servers as $server) { $data[8] .= ''; } + if ($server['type'] === 'event' && (bool) check_acl($config['id_user'], 0, 'LM') === true) { + $data[8] .= ''; + $data[8] .= html_print_image( + 'images/alert@svg.svg', + true, + [ + 'title' => __('Pending alerts list'), + 'class' => 'main_menu_icon invert_filter', + ] + ); + $data[8] .= ''; + } + $data[8] .= ''; $data[8] .= html_print_image( 'images/edit.svg', @@ -253,7 +272,7 @@ foreach ($servers as $server) { ); $data[8] .= ''; - if (($names_servers[$safe_server_name] === true) && ($server['type'] === 'data' || $server['type'] === 'enterprise satellite')) { + if (($names_servers[$safe_server_name] === true) && ($ext === '_server' || $server['type'] === 'enterprise satellite')) { $data[8] .= ''; $data[8] .= html_print_image( 'images/agents@svg.svg', @@ -298,6 +317,8 @@ foreach ($servers as $server) { unset($data[8]); } + $ext = ''; + array_push($table->data, $data); } diff --git a/pandora_console/godmode/setup/license.php b/pandora_console/godmode/setup/license.php index e11c54eec9..e3e25935f9 100644 --- a/pandora_console/godmode/setup/license.php +++ b/pandora_console/godmode/setup/license.php @@ -189,7 +189,8 @@ $table->data[1][1] = html_print_label_input_block( 255, true, true - ).' '.($license['limit_mode'] == 0 ? __('agents') : __('modules')) + ) + // .' '.($license['limit_mode'] == 0 ? __('agents') : __('modules')) ); $table->data[2][0] = html_print_label_input_block( @@ -202,7 +203,8 @@ $table->data[2][0] = html_print_label_input_block( 255, true, true - ).' '.($license['limit_mode'] == 0 ? __('agents') : __('modules')) + ) + // .' '.($license['limit_mode'] == 0 ? __('agents') : __('modules')) ); $table->data[2][1] = html_print_label_input_block( @@ -215,7 +217,8 @@ $table->data[2][1] = html_print_label_input_block( 255, true, true - ).' '.($license['limit_mode'] == 0 ? __('agents') : __('modules')) + ) + // .' '.($license['limit_mode'] == 0 ? __('agents') : __('modules')) ); $table->data[3][0] = html_print_label_input_block( @@ -228,7 +231,8 @@ $table->data[3][0] = html_print_label_input_block( 255, true, true - ).' '.($license['limit_mode'] == 0 ? __('agents') : __('modules')) + ) + // .' '.($license['limit_mode'] == 0 ? __('agents') : __('modules')) ); $table->data[3][1] = html_print_label_input_block( @@ -325,6 +329,18 @@ if (enterprise_installed() || defined('DESTDIR')) { ], true ); + $buttons .= html_print_button( + __('Show agent usage details'), + 'agents_details', + false, + 'show_agents_details_dialog()', + [ + 'fixed_id' => 'button-agents_details', + 'icon' => 'next', + 'mode' => 'secondary', + ], + true + ); html_print_action_buttons( $buttons @@ -369,3 +385,80 @@ if (enterprise_hook('print_activate_licence_dialog') == ENTERPRISE_NOT_HOOK) { echo ''; echo ''; } + +$table = new stdClass(); +$table->width = '100%'; +$table->class = 'databox filter-table-adv'; +$table->size = []; +$table->size[0] = '50%'; +$table->size[1] = '50%'; +$table->data = []; +$table->colspan = []; + +$table->data[0][0] = html_print_label_input_block( + __('Total Agents'), + html_print_input_text( + 'total_agents', + $total_agents, + '', + 30, + 255, + true, + true + ) +); + +$table->data[0][1] = html_print_label_input_block( + __('Network & other devices'), + html_print_input_text( + 'type_network', + $network_others, + '', + 30, + 255, + true, + true + ) +); + +$table->data[1][0] = html_print_label_input_block( + __('Workstations'), + html_print_input_text( + 'type_workstation', + $workstations, + '', + 30, + 255, + true, + true + ) +); + +$table->data[1][1] = html_print_label_input_block( + __('Servers'), + html_print_input_text( + 'type_server', + $servers, + '', + 30, + 255, + true, + true + ) +); + +$table->data[2][0] = html_print_label_input_block( + __('Show disabled agents'), + html_print_checkbox_switch( + 'show_disabled_agents', + 1, + 1, + true, + false, + 'show_disabled_agents()' + ) +); + +echo ''; \ No newline at end of file diff --git a/pandora_console/godmode/setup/links.php b/pandora_console/godmode/setup/links.php index b830ede88a..fc27454b48 100644 --- a/pandora_console/godmode/setup/links.php +++ b/pandora_console/godmode/setup/links.php @@ -210,7 +210,10 @@ if ((isset($_GET['form_add'])) or (isset($_GET['form_edit']))) { echo '
'.html_print_image( 'images/delete.svg', true, - ['class' => 'invert_filter'] + [ + 'class' => 'invert_filter main_menu_icon', + 'title' => __('Delete'), + ] ).'
'; - $legend .= '
'; - $priorities = get_priorities(); - $half = (count($priorities) / 2); - $count = 0; + $legend = ''; + $legend .= '
'; + $legend .= '
'; + $priorities = get_priorities(); + $half = (count($priorities) / 2); + $count = 0; foreach ($priorities as $num => $name) { if ($count == $half) { $legend .= '
'; @@ -2198,11 +2190,24 @@ if ($create_alert || $update_alert) { $count++; } - $legend .= '
'; - ui_toggle($legend, __('Legend')); + ui_toggle($legend, __('Legend')); - unset($table); + unset($table); + + echo '
'; + echo '
'; + html_print_input_hidden('create_alert', 1); + $submitButton = html_print_submit_button( + __('Create'), + 'alert', + false, + ['icon' => 'wand'], + true + ); + html_print_action_buttons($submitButton.$deleteButton, ['right_content' => $pagination]); + echo '
'; } ui_require_javascript_file('pandora', 'include/javascript/', true); diff --git a/pandora_console/godmode/update_manager/update_manager.history.php b/pandora_console/godmode/update_manager/update_manager.history.php index e827951e88..7caab40f8b 100644 --- a/pandora_console/godmode/update_manager/update_manager.history.php +++ b/pandora_console/godmode/update_manager/update_manager.history.php @@ -50,7 +50,7 @@ try { [ 'id' => $tableId, 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => 'include/ajax/update_manager', diff --git a/pandora_console/godmode/users/configure_user.php b/pandora_console/godmode/users/configure_user.php index 047d0b0925..7227aaa09e 100644 --- a/pandora_console/godmode/users/configure_user.php +++ b/pandora_console/godmode/users/configure_user.php @@ -353,8 +353,7 @@ if ($create_user === true) { $values['data_section'] = get_parameter('data_section'); } - $values['section'] = $homeScreenValues[$values['section']]; - + // $values['section'] = $homeScreenValues[$values['section']]; if (enterprise_installed() === true) { $values['force_change_pass'] = 1; $values['last_pass_change'] = date('Y/m/d H:i:s', get_system_time()); @@ -371,6 +370,9 @@ if ($create_user === true) { $values['strict_acl'] = (bool) get_parameter('strict_acl', false); $values['session_time'] = (int) get_parameter('session_time', 0); + // Previously defined. + $values['autorefresh_white_list'] = $autorefresh_white_list; + // eHorus user level conf. if ((bool) $config['ehorus_user_level_conf'] === true) { $values['ehorus_user_level_enabled'] = (bool) get_parameter('ehorus_user_level_enabled', false); @@ -645,8 +647,7 @@ if ($update_user) { $values['data_section'] = get_parameter('data_section'); } - $values['section'] = $homeScreenValues[$values['section']]; - + // $values['section'] = $homeScreenValues[$values['section']]; if (enterprise_installed() === true && is_metaconsole() === true) { if (users_is_admin() === true) { $values['metaconsole_access'] = get_parameter('metaconsole_access'); @@ -663,20 +664,31 @@ if ($update_user) { $values['local_user'] = (bool) get_parameter('local_user', false); $values['strict_acl'] = (bool) get_parameter('strict_acl', false); $values['session_time'] = (int) get_parameter('session_time', 0); + + $force_update_session_expire = false; + if ($values['session_time'] !== $user_info['session_time']) { + $force_update_session_expire = true; + } + // Previously defined. $values['autorefresh_white_list'] = $autorefresh_white_list; $res1 = update_user($id, $values); + if ($force_update_session_expire === true) { + config_prepare_expire_time_session(true); + } + if ($config['user_can_update_password']) { $password_new = (string) get_parameter('password_new', ''); $password_confirm = (string) get_parameter('password_confirm', ''); $own_password_confirm = (string) get_parameter('own_password_confirm', ''); + $id_user = (string) get_parameter('id_user', ''); if ($password_new != '') { $correct_password = false; - $user_credentials_check = process_user_login($config['id_user'], $own_password_confirm, true); + $user_credentials_check = process_user_login($id_user, $own_password_confirm, true); if ($user_credentials_check !== false) { $correct_password = true; @@ -1832,7 +1844,6 @@ if (is_metaconsole() === false) { }); $("#button-uptbutton").click (function () { - console.log('aaaaaaaaaaaaa'); if($("#autorefresh_list option").length > 0) { $('#autorefresh_list option').prop('selected', true); } diff --git a/pandora_console/godmode/users/user_management.php b/pandora_console/godmode/users/user_management.php index 7fc3bf23e3..90bf79a50c 100644 --- a/pandora_console/godmode/users/user_management.php +++ b/pandora_console/godmode/users/user_management.php @@ -302,25 +302,45 @@ $passwordManageTable->data['fields_repeatpassword'][0] = html_print_input_text_e true ); -if ($new_user === false) { +if ($new_user === false && users_is_admin() === false) { $passwordManageTable->data['captions_currentpassword'][0] = __('Current password'); $passwordManageTable->rowclass['fields_currentpassword'] = 'w540px'; - $passwordManageTable->data['fields_currentpassword'][0] = html_print_input_text_extended( - 'own_password_confirm', - '', - 'own_password_confirm', - '', - '20', - '150', - $view_mode, - '', - [ - 'class' => 'input w100p', - 'placeholder' => __('Own password confirmation'), - ], - true, - true - ); + + if ($user_info['id_user'] === $config['id_user']) { + $passwordManageTable->data['fields_currentpassword'][0] = html_print_input_text_extended( + 'own_password_confirm', + '', + 'own_password_confirm', + '', + '20', + '45', + $view_mode, + '', + [ + 'class' => 'input w100p', + 'placeholder' => __('Own password confirmation'), + ], + true, + true + ); + } else { + $passwordManageTable->data['fields_currentpassword'][0] = html_print_input_text_extended( + 'own_password_confirm', + '', + 'own_password_confirm', + '', + '20', + '45', + $view_mode, + '', + [ + 'class' => 'input w100p', + 'placeholder' => __('Third user password confirmation'), + ], + true, + true + ); + } } $userManagementTable->data['passwordManage_table'] = html_print_table($passwordManageTable, true); @@ -633,7 +653,7 @@ $homeScreenTable->rowclass['fields_homescreen'] = 'field_half_width flex'; $homeScreenTable->data['fields_homescreen'][0] = html_print_select( $homeScreenValues, 'section', - array_search($user_info['section'], $homeScreenValues), + $user_info['section'], 'show_data_section();', '', -1, @@ -764,10 +784,12 @@ $userManagementTable->data['fields_addSettings'][1] .= html_print_div( if (isset($CodeQRTable) === true || isset($apiTokenContent) === true) { // QR Code and API Token advice. + $titleQr = ''.__('Contact details (QR)').''; + $titleApi = ''.__('API Token credentials').''; html_print_div( [ 'id' => 'api_qrcode_display', - 'content' => $CodeQRTable.$apiTokenContent, + 'content' => $titleQr.$CodeQRTable.$titleApi.$apiTokenContent, ] ); } diff --git a/pandora_console/godmode/wizards/Applications.class.php b/pandora_console/godmode/wizards/Applications.class.php new file mode 100644 index 0000000000..107550c261 --- /dev/null +++ b/pandora_console/godmode/wizards/Applications.class.php @@ -0,0 +1,224 @@ +setBreadcrum([]); + + $this->access = 'AW'; + $this->task = []; + $this->msg = $msg; + $this->icon = $icon; + $this->class = $class_style; + $this->label = $label; + $this->page = $page; + $this->url = ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=app' + ); + + // Print Warning Message. + $this->printWarningMessage(); + + return $this; + } + + + /** + * Run wizard manager. + * + * @return mixed Returns null if wizard is ongoing. Result if done. + */ + public function run() + { + global $config; + + // Load styles. + parent::run(); + + // Load current wiz. sub-styles. + ui_require_css_file( + 'application', + ENTERPRISE_DIR.'/include/styles/wizards/' + ); + + $mode = get_parameter('mode', null); + + // Load application wizards. + $enterprise_classes = glob( + $config['homedir'].'/'.ENTERPRISE_DIR.'/include/class/*.app.php' + ); + $extensions = new ExtensionsDiscovery('app', $mode); + + foreach ($enterprise_classes as $classpath) { + enterprise_include_once( + 'include/class/'.basename($classpath) + ); + } + + switch ($mode) { + case 'DB2': + $classname_selected = 'DB2'; + break; + + case 'SAP': + $classname_selected = 'SAP'; + break; + + case 'vmware': + $classname_selected = 'VMware'; + break; + + case 'mysql': + $classname_selected = 'MySQL'; + break; + + case 'oracle': + $classname_selected = 'Oracle'; + break; + + case 'MicrosoftSQLServer': + $classname_selected = 'MicrosoftSQLServer'; + break; + + default: + $classname_selected = null; + break; + } + + // Else: class not found pseudo exception. + if ($classname_selected !== null) { + $wiz = new $classname_selected($this->page); + $result = $wiz->run(); + if (is_array($result) === true) { + return $result; + } + } + + if ($classname_selected === null) { + if ($mode !== null) { + // Load extension if exist. + $extensions->run(); + return; + } + + // Load classes and print selector. + $wiz_data = []; + foreach ($enterprise_classes as $classpath) { + $classname = basename($classpath, '.app.php'); + $obj = new $classname(); + $wiz_data[] = $obj->load(); + } + + $wiz_data = array_merge($wiz_data, $extensions->loadExtensions()); + + $this->prepareBreadcrum( + [ + [ + 'link' => ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery' + ), + 'label' => __('Discovery'), + ], + [ + 'link' => ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=app' + ), + 'label' => __('Applications'), + 'selected' => true, + ], + ] + ); + + // Header. + ui_print_page_header( + __('Applications'), + '', + false, + '', + true, + '', + false, + '', + GENERIC_SIZE_TEXT, + '', + $this->printHeader(true) + ); + + Wizard::printBigButtonsList($wiz_data); + + echo '
*'.__('All company names used here are for identification purposes only. Use of these names, logos, and brands does not imply endorsement.').'
'; + } + + return $result; + } + + + /** + * Check if section have extensions. + * + * @return boolean Return true if section is empty. + */ + public function isEmpty() + { + $extensions = new ExtensionsDiscovery('app'); + $listExtensions = $extensions->getExtensionsApps(); + if ($listExtensions > 0 || enterprise_installed() === true) { + return false; + } else { + return true; + } + } + + +} diff --git a/pandora_console/godmode/wizards/Cloud.class.php b/pandora_console/godmode/wizards/Cloud.class.php new file mode 100644 index 0000000000..4c5074cd3c --- /dev/null +++ b/pandora_console/godmode/wizards/Cloud.class.php @@ -0,0 +1,664 @@ +setBreadcrum([]); + + $this->access = 'AW'; + $this->task = []; + $this->msg = $msg; + $this->icon = $icon; + $this->label = $label; + $this->page = $page; + $this->url = ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=cloud' + ); + + return $this; + } + + + /** + * Run wizard manager. + * + * @return mixed Returns null if wizard is ongoing. Result if done. + */ + public function run() + { + global $config; + + // Load styles. + parent::run(); + + // Load current wiz. sub-styles. + ui_require_css_file( + 'cloud', + ENTERPRISE_DIR.'/include/styles/wizards/' + ); + + $mode = get_parameter('mode', null); + + // Load cloud wizards. + $enterprise_classes = glob( + $config['homedir'].'/'.ENTERPRISE_DIR.'/include/class/*.cloud.php' + ); + $extensions = new ExtensionsDiscovery('cloud', $mode); + + foreach ($enterprise_classes as $classpath) { + enterprise_include_once( + 'include/class/'.basename($classpath) + ); + } + + switch ($mode) { + case 'amazonws': + $classname_selected = 'Aws'; + break; + + case 'azure': + $classname_selected = 'Azure'; + break; + + case 'gcp': + $classname_selected = 'Google'; + break; + + default: + $classname_selected = null; + break; + } + + // Else: class not found pseudo exception. + if ($classname_selected !== null) { + $wiz = new $classname_selected($this->page); + $result = $wiz->run(); + if (is_array($result) === true) { + return $result; + } + } + + if ($classname_selected === null) { + if ($mode !== null) { + // Load extension if exist. + $extensions->run(); + return; + } + + // Load classes and print selector. + $wiz_data = []; + foreach ($enterprise_classes as $classpath) { + $classname = basename($classpath, '.cloud.php'); + $obj = new $classname(); + $wiz_data[] = $obj->load(); + } + + $wiz_data = array_merge($wiz_data, $extensions->loadExtensions()); + + $this->prepareBreadcrum( + [ + [ + 'link' => ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery' + ), + 'label' => __('Discovery'), + ], + [ + 'link' => $this->url, + 'label' => __('Cloud'), + 'selected' => true, + ], + ], + true + ); + + // Header. + ui_print_page_header( + __('Cloud'), + '', + false, + '', + true, + '', + false, + '', + GENERIC_SIZE_TEXT, + '', + $this->printHeader(true) + ); + + Wizard::printBigButtonsList($wiz_data); + + echo '
*'.__('All company names used here are for identification purposes only. Use of these names, logos, and brands does not imply endorsement.').'
'; + } + + // Print Warning Message. + $this->printWarningMessage(); + + return $result; + } + + + /** + * Run credentials wizard. + * + * @return boolean True if credentials wizard is displayed and false if not. + */ + public function runCredentials() + { + global $config; + + if ($this->status === false) { + $empty_account = true; + } + + // Checks credentials. If check not passed. Show the form to fill it. + if ($this->checkCredentials()) { + return true; + } + + // Add breadcrum and print header. + $this->prepareBreadcrum( + [ + [ + 'link' => $this->url.'&credentials=1', + 'label' => __('%s credentials', $this->product), + 'selected' => true, + ], + ], + true + ); + // Header. + ui_print_page_header( + __('%s credentials', $this->product), + '', + false, + $this->product.'_credentials_tab', + true, + '', + false, + '', + GENERIC_SIZE_TEXT, + '', + $this->printHeader(true) + ); + + if ($this->product === 'Aws') { + ui_print_warning_message( + __( + 'If a task with the selected credentials is already running, it will be edited. To create a new one, another account from the credential store must be selected.' + ) + ); + } + + if ($this->status === true) { + ui_print_success_message($this->msg); + } else if ($this->status === false) { + ui_print_error_message($this->msg); + } + + if ($empty_account === true) { + ui_print_error_message($this->msg); + } + + $link_to_cs = ''; + if (check_acl($config['id_user'], 0, 'UM')) { + $link_to_cs = ''; + $link_to_cs .= __('Manage accounts').''; + } + + $this->getCredentials(); + $this->printFormAsList( + [ + 'form' => [ + 'action' => $this->url, + 'method' => 'POST', + 'id' => 'form-credentials', + ], + 'inputs' => [ + [ + 'label' => __('Cloud tool full path'), + 'arguments' => [ + 'name' => 'cloud_util_path', + 'value' => isset($config['cloud_util_path']) ? io_safe_output($config['cloud_util_path']) : '/usr/bin/pandora-cm-api', + 'type' => 'text', + ], + ], + [ + 'label' => __('Account'), + 'extra' => $link_to_cs, + 'arguments' => [ + 'name' => 'account_identifier', + 'type' => 'select', + 'fields' => CredentialStore::getKeys($this->keyStoreType), + 'selected' => $this->keyIdentifier, + 'return' => true, + ], + ], + [ + 'arguments' => [ + 'name' => 'parse_credentials', + 'value' => 1, + 'type' => 'hidden', + 'return' => true, + ], + ], + ], + ] + ); + + $buttons_form = $this->printInput( + [ + 'name' => 'submit', + 'label' => __('Validate'), + 'type' => 'submit', + 'attributes' => [ + 'icon' => 'wand', + 'form' => 'form-credentials', + ], + 'return' => true, + 'width' => 'initial', + ] + ); + + $buttons_form .= $this->printGoBackButton( + ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=cloud' + ), + true + ); + + html_print_action_buttons($buttons_form); + return false; + } + + + /** + * Check credentials. + * + * @return boolean True if credentials are OK. + */ + public function checkCredentials() + { + global $config; + + $pandora = io_safe_output($config['cloud_util_path']); + + if (isset($pandora) === false) { + config_update_value('cloud_util_path', '/usr/bin/pandora-cm-api'); + } + + if ((bool) get_parameter('disconnect_account', false) === true) { + $this->status = null; + return false; + } + + if ($this->keyIdentifier === null) { + // Ask user for available credentials. + $this->msg = __('Select a set of credentials from the list'); + $this->status = null; + return false; + } + + $credentials = $this->getCredentials($this->keyIdentifier); + + if (empty($credentials['username']) === true + || empty($credentials['password']) === true + || isset($pandora) === false + || is_executable($pandora) === false + ) { + if (is_executable($pandora) === false) { + $this->msg = (__('Path %s is not executable.', $pandora)); + $this->status = false; + } else { + $this->msg = __('Invalid username or password'); + $this->status = false; + } + + return false; + } + + try { + $value = $this->executeCMCommand('--get availability'); + } catch (Exception $e) { + $this->msg = $e->getMessage(); + $this->status = false; + return false; + } + + if ($value == '1') { + return true; + } + + $this->status = false; + + // Error message directly from pandora-cm-api. + $this->msg = str_replace('"', '', $value); + + return false; + } + + + /** + * Handle the click on disconnect account link. + * + * @return void But it prints some info to user. + */ + protected function parseDisconnectAccount() + { + // Check if disconection account link is pressed. + if ((bool) get_parameter('disconnect_account') === false) { + return; + } + + $ret = $this->setCredentials(null); + if ($ret) { + $this->msg = __('Account disconnected'); + } else { + $this->msg = __('Failed disconnecting account'); + } + + $this->status = $ret; + $this->page = 0; + } + + + /** + * Build an array with Product credentials. + * + * @return array with credentials (pass and id). + */ + public function getCredentials() + { + return CredentialStore::getKey($this->keyIdentifier); + } + + + /** + * Set Product credentials. + * + * @param string|null $identifier Credential store identifier. + * + * @return boolean True if success. + */ + public function setCredentials($identifier) + { + if ($identifier === null) { + unset($this->keyIdentifier); + return true; + } + + if (isset($identifier) === false) { + return false; + } + + $all = CredentialStore::getKeys($this->type); + + if (in_array($identifier, $all) === true) { + $this->keyIdentifier = $identifier; + return true; + } + + return false; + } + + + /** + * Parse credentials form. + * + * @return void But it prints a message. + */ + protected function parseCredentials() + { + global $config; + + if (!$this->keyIdentifier) { + $this->setCredentials(get_parameter('ki', null)); + } + + // Check if credentials form is submitted. + if ((bool) get_parameter('parse_credentials') === false) { + return; + } + + $this->page = 0; + $ret = $this->setCredentials( + get_parameter('account_identifier') + ); + + $path = get_parameter('cloud_util_path'); + $ret_path = config_update_value('cloud_util_path', $path); + if ($ret_path) { + $config['cloud_util_path'] = $path; + } + + if ($ret && $ret_path) { + $this->msg = __('Credentials successfully updated'); + } else { + $this->msg = __('Failed updating credentials process'); + } + + $this->status = ($ret && $ret_path); + } + + + /** + * This method must be implemented. + * + * Execute a pandora-cm-api request. + * + * @param string $command Command to execute. + * + * @return void But must return string STDOUT of executed command. + * @throws Exception If not implemented. + */ + protected function executeCMCommand($command) + { + throw new Exception('executeCMCommand must be implemented.'); + } + + + /** + * Get a recon token value + * + * @param string $token The recon key to retrieve. + * + * @return string String with the value. + */ + protected function getConfigReconElement($token) + { + if ($this->reconConfig === false + || isset($this->reconConfig[0][$token]) === false + ) { + if (is_array($this->task) === true + && isset($this->task[$token]) === true + ) { + return $this->task[$token]; + } else { + return ''; + } + } else { + return $this->reconConfig[0][$token]; + } + } + + + /** + * Print global inputs + * + * @param boolean $last True if is last element. + * + * @return array Array with all global inputs. + */ + protected function getGlobalInputs(bool $last=false) + { + $task_id = $this->task['id_rt']; + if (!$task_id) { + $task_id = $this->getConfigReconElement('id_rt'); + } + + return [ + [ + 'arguments' => [ + 'name' => 'page', + 'value' => ($this->page + 1), + 'type' => 'hidden', + 'return' => true, + ], + ], + [ + 'arguments' => [ + 'name' => 'submit', + 'label' => ($last) ? __('Finish') : __('Next'), + 'type' => 'submit', + 'attributes' => 'class="sub '.(($last) ? 'wand' : 'next').'"', + 'return' => true, + ], + ], + [ + 'arguments' => [ + 'name' => 'task', + 'value' => $task_id, + 'type' => 'hidden', + 'return' => true, + ], + ], + [ + 'arguments' => [ + 'name' => 'parse_form', + 'value' => 1, + 'type' => 'hidden', + 'return' => true, + ], + ], + ]; + } + + + /** + * Print required css in some points. + * + * @return string With js code. + */ + protected function cloudJS() + { + return ' + function toggleCloudSubmenu(curr_elem, id_csm){ + if (document.getElementsByName(curr_elem)[0].checked){ + $("#li-"+id_csm).show(); + } else { + $("#li-"+id_csm).hide(); + } + }; + '; + } + + + /** + * Check if section have extensions. + * + * @return boolean Return true if section is empty. + */ + public function isEmpty() + { + $extensions = new ExtensionsDiscovery('cloud'); + $listExtensions = $extensions->getExtensionsApps(); + if ($listExtensions > 0 || enterprise_installed() === true) { + return false; + } else { + return true; + } + } + + +} diff --git a/pandora_console/godmode/wizards/Custom.class.php b/pandora_console/godmode/wizards/Custom.class.php new file mode 100644 index 0000000000..41a177b3e3 --- /dev/null +++ b/pandora_console/godmode/wizards/Custom.class.php @@ -0,0 +1,160 @@ +setBreadcrum([]); + + $this->access = 'AW'; + $this->task = []; + $this->msg = $msg; + $this->icon = $icon; + $this->class = $class_style; + $this->label = $label; + $this->page = $page; + $this->url = ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=custom' + ); + + return $this; + } + + + /** + * Run wizard manager. + * + * @return mixed Returns null if wizard is ongoing. Result if done. + */ + public function run() + { + global $config; + + // Load styles. + parent::run(); + + // Load current wiz. sub-styles. + ui_require_css_file( + 'custom', + ENTERPRISE_DIR.'/include/styles/wizards/' + ); + + $mode = get_parameter('mode', null); + $extensions = new ExtensionsDiscovery('custom', $mode); + if ($mode !== null) { + // Load extension if exist. + $extensions->run(); + return; + } + + // Load classes and print selector. + $wiz_data = $extensions->loadExtensions(); + + $this->prepareBreadcrum( + [ + [ + 'link' => ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery' + ), + 'label' => __('Discovery'), + ], + [ + 'link' => ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=custom' + ), + 'label' => __('Custom'), + 'selected' => true, + ], + ] + ); + + // Header. + ui_print_page_header( + __('Custom'), + '', + false, + '', + true, + '', + false, + '', + GENERIC_SIZE_TEXT, + '', + $this->printHeader(true) + ); + + Wizard::printBigButtonsList($wiz_data); + + echo '
*'.__('All company names used here are for identification purposes only. Use of these names, logos, and brands does not imply endorsement.').'
'; + return $result; + } + + + /** + * Check if section have extensions. + * + * @return boolean Return true if section is empty. + */ + public function isEmpty() + { + $extensions = new ExtensionsDiscovery('custom'); + $listExtensions = $extensions->getExtensionsApps(); + if ($listExtensions > 0) { + return false; + } else { + return true; + } + } + + +} diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index c0ee9646c1..af88c3e51f 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -32,6 +32,8 @@ require_once $config['homedir'].'/include/class/HTML.class.php'; require_once $config['homedir'].'/include/functions_users.php'; require_once $config['homedir'].'/include/functions_reports.php'; require_once $config['homedir'].'/include/functions_cron.php'; +require_once $config['homedir'].'/godmode/wizards/Wizard.main.php'; + enterprise_include_once('include/functions_tasklist.php'); enterprise_include_once('include/functions_cron.php'); @@ -129,6 +131,11 @@ class DiscoveryTaskList extends HTML } $delete_console_task = (bool) get_parameter('delete_console_task'); + $report_task = (bool) get_parameter('report_task', 0); + if ($report_task === true) { + $this->url = ui_get_full_url('index.php?sec=reporting&sec2=godmode/reporting/reporting_builder'); + } + if ($delete_console_task === true) { return $this->deleteConsoleTask(); } @@ -163,7 +170,10 @@ class DiscoveryTaskList extends HTML } if (is_reporting_console_node() === false) { - $ret2 = $this->showList(); + $ret2 = $this->showList(__('Host & devices tasks'), [0, 1]); + $ret2 .= $this->showList(__('Applications tasks'), [3, 4, 5, 10, 11, 12], 'app'); + $ret2 .= $this->showList(__('Cloud tasks'), [6, 7, 8, 13, 14], 'cloud'); + $ret2 .= $this->showList(__('Custom tasks'), [-1], 'custom'); } if ($ret === false && $ret2 === false) { @@ -206,6 +216,10 @@ class DiscoveryTaskList extends HTML html_print_action_buttons($this->printForm($form, true)); } + // Warning Message. + $wizar_main = new Wizard(); + $wizar_main->printWarningMessage(); + return $ret; } @@ -287,6 +301,10 @@ class DiscoveryTaskList extends HTML } $id_console_task = (int) get_parameter('id_console_task'); + $report_task = (bool) get_parameter('report_task', 0); + if ($report_task === true) { + $this->url = ui_get_full_url('index.php?sec=reporting&sec2=godmode/reporting/reporting_builder'); + } if ($id_console_task != null) { // -------------------------------- @@ -352,6 +370,10 @@ class DiscoveryTaskList extends HTML } $id_console_task = (int) get_parameter('id_console_task'); + $report_task = (bool) get_parameter('report_task', 0); + if ($report_task === true) { + $this->url = ui_get_full_url('index.php?sec=reporting&sec2=godmode/reporting/reporting_builder'); + } if ($id_console_task > 0) { $result = db_process_sql_update( @@ -505,9 +527,13 @@ class DiscoveryTaskList extends HTML /** * Show complete list of running tasks. * + * @param string $titleTable Title of section. + * @param array $filter Ids array from apps for filter. + * @param boolean $extension_section Extension to add in table. + * * @return boolean Success or not. */ - public function showList() + public function showList($titleTable, $filter, $extension_section=false) { global $config; @@ -531,7 +557,16 @@ class DiscoveryTaskList extends HTML include_once $config['homedir'].'/include/functions_network_profiles.php'; if (users_is_admin()) { - $recon_tasks = db_get_all_rows_sql('SELECT * FROM trecon_task'); + $recon_tasks = db_get_all_rows_sql( + sprintf( + 'SELECT tasks.*, apps.section AS section, apps.short_name AS short_name + FROM trecon_task tasks + LEFT JOIN tdiscovery_apps apps ON tasks.id_app = apps.id_app + WHERE type IN (%s) OR section = "%s"', + implode(',', $filter), + $extension_section + ) + ); } else { $user_groups = implode( ',', @@ -539,9 +574,14 @@ class DiscoveryTaskList extends HTML ); $recon_tasks = db_get_all_rows_sql( sprintf( - 'SELECT * FROM trecon_task - WHERE id_group IN (%s)', - $user_groups + 'SELECT tasks.*, apps.section AS section, apps.short_name AS short_name + FROM trecon_task tasks + LEFT JOIN tdiscovery_apps apps ON tasks.id_app = apps.id_app + WHERE id_group IN (%s) AND + (type IN (%s) OR section = "%s")', + $user_groups, + implode(',', $filter), + $extension_section ) ); } @@ -658,7 +698,9 @@ class DiscoveryTaskList extends HTML $recon_script_name = false; } - if ($task['disabled'] == 0 && $server_name !== '') { + if (($task['disabled'] == 0 && $server_name !== '' && (int) $task['type'] !== DISCOVERY_EXTENSION) + || ((int) $task['type'] === DISCOVERY_EXTENSION && (int) $task['setup_complete'] === 1) + ) { if (check_acl($config['id_user'], 0, 'AW')) { $data[0] = ''; $data[9] .= html_print_image( 'images/web@groups.svg', @@ -999,13 +1056,24 @@ class DiscoveryTaskList extends HTML ).''; } } else { + $url_edit = sprintf( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&%s&task=%d', + $this->getTargetWiz($task, $recon_script_data), + $task['id_rt'] + ); + + if ((int) $task['type'] === DISCOVERY_EXTENSION) { + $url_edit = sprintf( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=%s&mode=%s&id_task=%s', + $task['section'], + $task['short_name'], + $task['id_rt'], + ); + } + // Check if is a H&D, Cloud or Application or IPAM. $data[9] .= ''.html_print_image( 'images/edit.svg', true, @@ -1069,7 +1137,7 @@ class DiscoveryTaskList extends HTML $return = true; } - ui_toggle($content, __('Server Tasks'), '', '', false); + ui_toggle($content, $titleTable, '', '', false); // Div neccesary for modal map task. echo ''; @@ -1096,9 +1164,9 @@ class DiscoveryTaskList extends HTML * * @return boolean Success or not. */ - public function showListConsoleTask() + public function showListConsoleTask($report_task=false) { - return enterprise_hook('tasklist_showListConsoleTask', [$this]); + return enterprise_hook('tasklist_showListConsoleTask', [$this, $report_task]); } @@ -1137,6 +1205,9 @@ class DiscoveryTaskList extends HTML case DISCOVERY_CLOUD_AWS_S3: return 'wiz=cloud&mode=amazonws&ki='.$task['auth_strings'].'&sub=s3&page=0'; + case DISCOVERY_CLOUD_GCP_COMPUTE_ENGINE: + return 'wiz=cloud&mode=gcp&ki='.$task['auth_strings'].'&sub=compute&page=0'; + default: return 'wiz=cloud'; } @@ -1224,7 +1295,7 @@ class DiscoveryTaskList extends HTML ($task['status'] < 0) ? 100 : $task['status'], 150, 150, - '#3A3A3A', + '#14524f', '%', '', '#ececec', @@ -1294,7 +1365,7 @@ class DiscoveryTaskList extends HTML $task['stats']['c_network_percent'], 150, 150, - '#3A3A3A', + '#14524f', '%', '', '#ececec', @@ -1337,14 +1408,14 @@ class DiscoveryTaskList extends HTML $output = ''; - if (is_array($task['stats']) === false) { - $task['stats'] = json_decode($task['summary'], true); + if (is_array($task['stats']) === false && (int) $task['type'] !== DISCOVERY_EXTENSION) { + $task['stats'] = json_decode(io_safe_output($task['summary']), true); if (json_last_error() !== JSON_ERROR_NONE) { return $task['summary']; } } - if (is_array($task['stats'])) { + if (is_array($task['stats']) || (int) $task['type'] === DISCOVERY_EXTENSION) { $i = 0; $table = new StdClasS(); $table->class = 'databox data'; @@ -1402,6 +1473,65 @@ class DiscoveryTaskList extends HTML $table->data[$i][1] = ''; $table->data[$i][1] .= ($total - $agents); $table->data[$i++][1] .= ''; + } else if ((int) $task['type'] === DISCOVERY_EXTENSION) { + // Content. + $countSummary = 1; + if (is_array($task['stats']) === true && count(array_filter(array_keys($task['stats']), 'is_numeric')) === count($task['stats'])) { + foreach ($task['stats'] as $key => $summary) { + $table->data[$i][0] = ''.__('Summary').' '.$countSummary.''; + $table->data[$i][1] = ''; + $countSummary++; + $i++; + if (is_array($summary) === true) { + if (empty($summary['summary']) === true && empty($summary['info']) === true) { + $table->data[$i][0] = json_encode($summary, JSON_PRETTY_PRINT); + $table->data[$i][1] = ''; + $i++; + continue; + } + + $unknownJson = $summary; + foreach ($summary as $k2 => $v) { + if (is_array($v) === true) { + if ($k2 === 'summary') { + foreach ($v as $k3 => $v2) { + $table->data[$i][0] = $k3; + $table->data[$i][1] = $v2; + $i++; + } + + unset($unknownJson[$k2]); + } + } else { + if ($k2 === 'info') { + $table->data[$i][0] = $v; + $table->data[$i][1] = ''; + $i++; + + unset($unknownJson[$k2]); + } + } + } + + if (empty($unknownJson) === false) { + $table->data[$i][0] = json_encode($unknownJson, JSON_PRETTY_PRINT); + $table->data[$i][1] = ''; + $i++; + } + } else { + $table->data[$i][0] = $summary; + $table->data[$i][1] = ''; + $i++; + } + } + } else { + $table->data[$i][0] = ''.__('Summary').''; + $table->data[$i][1] = ''; + $i++; + $table->data[$i][0] = $task['summary']; + $table->data[$i][1] = ''; + $i++; + } } else { // Content. if (is_array($task['stats']['summary']) === true) { @@ -1463,7 +1593,7 @@ class DiscoveryTaskList extends HTML } $task = db_get_row('trecon_task', 'id_rt', $id_task); - $task['stats'] = json_decode($task['summary'], true); + $task['stats'] = json_decode(io_safe_output($task['summary']), true); $summary = $this->progressTaskSummary($task); $output = ''; @@ -1856,7 +1986,11 @@ class DiscoveryTaskList extends HTML if ($task['status'] <= 0 && empty($task['summary']) === false ) { - $status = __('Done'); + if ($task['status'] == -2) { + $status = __('Failed'); + } else { + $status = __('Done'); + } } else if ($task['utimestamp'] == 0 && empty($task['summary']) ) { @@ -1894,4 +2028,28 @@ class DiscoveryTaskList extends HTML } + /* + * Generates warning message. + * + * @return void Warning message. + + public function getWarningMessage() + { + return ui_print_warning_message( + __( + 'Starting with version 773, the new modular system of discovery 2.0 has been implemented. The current + discovery (1.0) and its defined tasks will continue to function normally until the next LTS version, + in which migration to the new system will be mandatory. + The tasks of the current discovery (1.0) will be marked as legacy although it will not affect their + operation, it will only be a visual indicator to identify and differentiate the tasks of discovery 1.0 + from those of the new version 2.0. + In the intermediate versions between the 773 and the next LTS version, more applications of the new + discovery 2.0 will be added. Both new and those that will come to replace the applications of the + current discovery 1.0. In addition, an automatic migration tool for legacy (1.0) tasks to the new 2.0 + model will be included.' + ) + ); + }*/ + + } diff --git a/pandora_console/godmode/wizards/ManageExtensions.class.php b/pandora_console/godmode/wizards/ManageExtensions.class.php new file mode 100644 index 0000000000..e088278eea --- /dev/null +++ b/pandora_console/godmode/wizards/ManageExtensions.class.php @@ -0,0 +1,1056 @@ +ajaxController = $config['homedir'].'/include/ajax/manage_extensions.ajax'; + $this->url = ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=magextensions' + ); + } + + + /** + * Checks if target method is available to be called using AJAX. + * + * @param string $method Target method. + * + * @return boolean True allowed, false not. + */ + public function ajaxMethod($method) + { + // Check access. + check_login(); + + return in_array($method, $this->AJAXMethods); + } + + + /** + * Implements load method. + * + * @return mixed Skeleton for button. + */ + public function load() + { + return [ + 'icon' => $this->icon, + 'label' => $this->label, + 'url' => $this->url, + + ]; + + } + + + /** + * Generates a JSON error. + * + * @param string $msg Error message. + * + * @return void + */ + public function errorAjax(string $msg) + { + echo json_encode( + ['error' => $msg] + ); + } + + + /** + * Implements run method. + * + * @return void + */ + public function run() + { + global $config; + // Load styles. + parent::run(); + + $uploadDisco = get_parameter('upload_disco', ''); + $action = get_parameter('action', ''); + $shortName = get_parameter('short_name', ''); + + if (empty($uploadDisco) === false) { + if ($_FILES['file']['error'] == 0) { + $result = $this->uploadExtension($_FILES['file']); + if ($result === true) { + ui_print_success_message( + __('Uploaded extension') + ); + } else { + if (is_string($result)) { + echo $this->error($result); + } else { + echo $this->error(__('Failed to upload extension')); + } + } + } else { + echo $this->error(__('Failed to upload extension')); + } + } + + if (empty($action) === false && empty($shortName) === false) { + switch ($action) { + case 'delete': + $result = $this->uninstallExtension($shortName); + if ($result === true) { + ui_print_success_message( + __('Deleted extension') + ); + } else { + echo $this->error(__('Fail delete extension')); + } + + case 'sync_server': + $syncAction = get_parameter('sync_action', ''); + if ($syncAction === 'refresh') { + $installationFolder = $config['homedir'].'/'.$this->path.'/'.$shortName; + $result = $this->copyExtensionToServer($installationFolder, $shortName); + if ($result === true) { + ui_print_success_message( + __('Extension folder created successfully') + ); + } else { + echo $this->error(__('Fail created extension folder')); + } + } + break; + + default: + continue; + } + } + + $this->prepareBreadcrum( + [ + [ + 'link' => ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery' + ), + 'label' => __('Discovery'), + ], + [ + 'link' => '', + 'label' => _('Manage disco packages'), + 'selected' => 1, + ], + ] + ); + + // Header. + ui_print_page_header( + __('Manage disco packages'), + '', + false, + '', + true, + '', + false, + '', + GENERIC_SIZE_TEXT, + '', + $this->printHeader(true) + ); + + $table = new stdClass(); + $table->width = '100%'; + $table->class = 'databox filters'; + $table->size = []; + $table->size[0] = '80%'; + $table->align[3] = 'right'; + $table->data = []; + $table->data[0][0] = html_print_label_input_block( + __('Load DISCO'), + html_print_div( + [ + 'id' => 'upload_file', + 'content' => html_print_input_file( + 'file', + true, + ['style' => 'width:100%'] + ), + 'class' => 'mrgn_top_15px', + ], + true + ) + ); + $table->data[0][3] = html_print_submit_button( + __('Upload DISCO'), + 'upload_button', + false, + [ + 'class' => 'sub ok float-right', + 'icon' => 'next', + ], + true + ); + + echo '
'; + html_print_input_hidden('upload_disco', 1); + html_print_table($table); + echo '
'; + + echo '
'; + echo '
'; + + echo ''; + ui_require_javascript_file('manage_extensions'); + try { + $columns = [ + 'name', + 'short_name', + 'section', + 'description', + 'version', + [ + 'text' => 'actions', + 'class' => 'flex flex-items-center', + ], + ]; + + $columnNames = [ + __('Name'), + __('Short name'), + __('Section'), + __('Description'), + __('Version'), + __('Actions'), + ]; + + // Load datatables user interface. + ui_print_datatable( + [ + 'id' => 'list_extensions', + 'class' => 'info_table', + 'style' => 'width: 99%', + 'dom_elements' => 'plfti', + 'filter_main_class' => 'box-flat white_table_graph fixed_filter_bar', + 'columns' => $columns, + 'column_names' => $columnNames, + 'ajax_url' => $this->ajaxController, + 'ajax_data' => ['method' => 'getExtensionsInstalled'], + 'no_sortable_columns' => [-1], + 'order' => [ + 'field' => 'name', + 'direction' => 'asc', + ], + 'search_button_class' => 'sub filter float-right', + ] + ); + } catch (Exception $e) { + echo $e->getMessage(); + } + + } + + + /** + * Upload extension to server. + * + * @param array $disco File disco tu upload. + * + * @return boolean $result Of operation, true if is ok. + */ + private function uploadExtension($disco) + { + global $config; + if (substr($disco['name'], -6) !== '.disco') { + return false; + } + + $nameFile = str_replace('.disco', '.zip', $disco['name']); + $nameTempDir = $config['attachment_store'].'/downloads/'; + if (file_exists($nameTempDir) === false) { + mkdir($nameTempDir); + } + + $tmpPath = Files::tempdirnam( + $nameTempDir, + 'extensions_uploaded_' + ); + $result = move_uploaded_file($disco['tmp_name'], $tmpPath.'/'.$nameFile); + if ($result === true) { + $unzip = $this->unZip($tmpPath.'/'.$nameFile, $tmpPath); + if ($unzip === true) { + unlink($tmpPath.'/'.$nameFile); + db_process_sql_begin(); + $this->iniFile = parse_ini_file($tmpPath.'/discovery_definition.ini', true, INI_SCANNER_TYPED); + if ($this->iniFile === false) { + db_process_sql_rollback(); + Files::rmrf($tmpPath); + return __('Failed to upload extension: Error while parsing dicovery_definition.ini'); + } + + $error = ExtensionsDiscovery::validateIni($this->iniFile); + if ($error !== false) { + db_process_sql_rollback(); + Files::rmrf($tmpPath); + return $error; + } + + $id = $this->installExtension(); + if ($id === false) { + db_process_sql_rollback(); + Files::rmrf($tmpPath); + return false; + } + + $result = $this->autoLoadConfigExec($id); + if ($result === false) { + db_process_sql_rollback(); + Files::rmrf($tmpPath); + return false; + } + + $result = $this->autoUpdateDefaultMacros($id); + if ($result === false) { + db_process_sql_rollback(); + Files::rmrf($tmpPath); + return false; + } + + $nameFolder = $this->iniFile['discovery_extension_definition']['short_name']; + $installationFolder = $config['homedir'].'/'.$this->path.'/'.$nameFolder; + if (file_exists($installationFolder) === false) { + mkdir($installationFolder, 0777, true); + } else { + Files::rmrf($installationFolder, true); + } + + $result = Files::move($tmpPath, $installationFolder, true); + if ($result === false) { + db_process_sql_rollback(); + Files::rmrf($tmpPath); + return false; + } + + $this->setPermissionfiles($installationFolder, $this->iniFile['discovery_extension_definition']['execution_file']); + $this->setPermissionfiles( + $installationFolder, + [ + $this->iniFile['discovery_extension_definition']['passencrypt_script'], + $this->iniFile['discovery_extension_definition']['passdecrypt_script'], + ] + ); + + $result = $this->copyExtensionToServer($installationFolder, $nameFolder); + if ($result === false) { + db_process_sql_rollback(); + Files::rmrf($tmpPath); + return false; + } + + Files::rmrf($tmpPath); + db_process_sql_commit(); + return true; + } + } else { + Files::rmrf($tmpPath); + return false; + } + } + + + /** + * Copy the extension folder into remote path server. + * + * @param string $path Path extension folder. + * @param string $nameFolder Name of extension folder. + * + * @return boolean Result of operation. + */ + public function copyExtensionToServer($path, $nameFolder) + { + global $config; + $filesToExclude = [ + 'discovery_definition.ini', + 'logo.png', + ]; + $serverPath = $config['remote_config'].'/discovery/'.$nameFolder; + if (file_exists($serverPath) === false) { + mkdir($serverPath, 0777, true); + } else { + Files::rmrf($serverPath, true); + } + + $result = $this->copyFolder($path, $serverPath, $filesToExclude); + $this->setPermissionfiles($serverPath, $this->iniFile['discovery_extension_definition']['execution_file']); + + return $result; + } + + + /** + * Copy from $source path to $destination + * + * @param string $source Initial folder path. + * @param string $destination Destination folder path. + * @param array $exclude Files to exlcude in copy. + * + * @return boolean Result of operation. + */ + public function copyFolder($source, $destination, $exclude=[]) + { + if (file_exists($destination) === false) { + mkdir($destination, 0777, true); + } + + $files = scandir($source); + foreach ($files as $file) { + if ($file !== '.' && $file !== '..') { + if (is_dir($source.'/'.$file)) { + $result = $this->copyFolder($source.'/'.$file, $destination.'/'.$file); + if ($result === false) { + return false; + } + } else { + if (in_array($file, $exclude) === false) { + $result = copy($source.'/'.$file, $destination.'/'.$file); + if ($result === false) { + return false; + } + } + } + } + } + + return true; + } + + + /** + * Delete extension from database and delete folder + * + * @param integer $shortName Short name app for delete. + * + * @return boolean Result of operation. + */ + private function uninstallExtension($shortName) + { + global $config; + + $result = db_process_sql_delete( + 'tdiscovery_apps', + ['short_name' => $shortName] + ); + + if ($result !== false) { + Files::rmrf($config['homedir'].'/'.$this->path.'/'.$shortName); + Files::rmrf($config['remote_config'].'/discovery/'.$shortName); + return true; + } else { + return false; + } + } + + + /** + * Load the basic information of the app into database. + * + * @return boolean Result of query. + */ + private function installExtension() + { + $exist = db_get_row_filter( + 'tdiscovery_apps', + [ + 'short_name' => $this->iniFile['discovery_extension_definition']['short_name'], + ] + ); + $version = $this->iniFile['discovery_extension_definition']['version']; + if ($version === null) { + $version = ''; + } + + $description = $this->iniFile['discovery_extension_definition']['description']; + if ($description === null) { + $description = ''; + } + + if ($exist === false) { + return db_process_sql_insert( + 'tdiscovery_apps', + [ + 'short_name' => $this->iniFile['discovery_extension_definition']['short_name'], + 'name' => io_safe_input($this->iniFile['discovery_extension_definition']['name']), + 'description' => io_safe_input($description), + 'section' => $this->iniFile['discovery_extension_definition']['section'], + 'version' => $version, + ] + ); + } else { + $result = db_process_sql_update( + 'tdiscovery_apps', + [ + 'name' => io_safe_input($this->iniFile['discovery_extension_definition']['name']), + 'description' => io_safe_input($description), + 'section' => $this->iniFile['discovery_extension_definition']['section'], + 'version' => $version, + ], + [ + 'short_name' => $this->iniFile['discovery_extension_definition']['short_name'], + ] + ); + + if ($result !== false) { + return $exist['id_app']; + } + } + } + + + /** + * Return all extension installed by ajax. + * + * @return void + */ + public function getExtensionsInstalled() + { + global $config; + + $data = []; + $start = get_parameter('start', 0); + $length = get_parameter('length', $config['block_size']); + $orderDatatable = get_datatable_order(true); + $pagination = ''; + $order = ''; + + try { + ob_start(); + + if (isset($orderDatatable)) { + $order = sprintf( + ' ORDER BY %s %s', + $orderDatatable['field'], + $orderDatatable['direction'] + ); + } + + if (isset($length) && $length > 0 + && isset($start) && $start >= 0 + ) { + $pagination = sprintf( + ' LIMIT %d OFFSET %d ', + $length, + $start + ); + } + + $sql = sprintf( + 'SELECT short_name, name, section, description, version + FROM tdiscovery_apps + %s %s', + $order, + $pagination + ); + + $data = db_get_all_rows_sql($sql); + + $sqlCount = sprintf( + 'SELECT short_name, name, section, description, version + FROM tdiscovery_apps + %s', + $order, + ); + + $count = db_get_num_rows($sqlCount); + + foreach ($data as $key => $row) { + $logo = $this->path.'/'.$row['short_name'].'/logo.png'; + if (file_exists($logo) === false) { + $logo = $this->defaultLogo; + } + + $logo = html_print_image($logo, true, ['style' => 'max-width: 30px; margin-right: 15px;']); + $data[$key]['name'] = $logo.io_safe_output($row['name']); + $data[$key]['short_name'] = $row['short_name']; + $data[$key]['description'] = io_safe_output($row['description']); + $data[$key]['version'] = $row['version']; + $data[$key]['actions'] = '
'; + $data[$key]['actions'] .= html_print_input_image( + 'button_delete', + 'images/delete.svg', + '', + '', + true, + [ + 'onclick' => 'if (!confirm(\''.__('Deleting this application will also delete all the discovery tasks using it. Do you want to delete it?').'\')) return false;', + 'class' => 'main_menu_icon invert_filter action_button_hidden', + 'title' => 'Delete', + ] + ); + $data[$key]['actions'] .= html_print_input_hidden('short_name', $row['short_name'], true); + $data[$key]['actions'] .= '
'; + if ($this->checkFolderConsole($row['short_name']) === true) { + $data[$key]['actions'] .= '
'; + $data[$key]['actions'] .= html_print_input_image( + 'button_refresh', + 'images/refresh@svg.svg', + '', + '', + true, + [ + 'onclick' => 'if (!confirm(\''.__('Are you sure you want to reapply?').'\')) return false;', + 'class' => 'main_menu_icon invert_filter action_button_hidden', + 'title' => 'Refresh', + ] + ); + $data[$key]['actions'] .= html_print_input_hidden('sync_action', 'refresh', true); + $data[$key]['actions'] .= html_print_input_hidden('short_name', $row['short_name'], true); + $data[$key]['actions'] .= '
'; + } else { + $data[$key]['actions'] .= html_print_image( + 'images/error_red.png', + true, + [ + 'title' => __('The extension directory or .ini does not exist in console.'), + 'alt' => __('The extension directory or .ini does not exist in console.'), + 'class' => 'main_menu_icon invert_filter', + ], + ); + } + } + + if (empty($data) === true) { + $total = 0; + $data = []; + } else { + $total = $count; + } + + echo json_encode( + [ + 'data' => $data, + 'recordsTotal' => $total, + 'recordsFiltered' => $total, + ] + ); + // Capture output. + $response = ob_get_clean(); + } catch (Exception $e) { + echo json_encode(['error' => $e->getMessage()]); + exit; + } + + json_decode($response); + if (json_last_error() === JSON_ERROR_NONE) { + echo $response; + } else { + echo json_encode( + [ + 'success' => false, + 'error' => $response, + ] + ); + } + + exit; + } + + + /** + * Insert new the default values for extension. + * + * @param integer $id Id of extension. + * + * @return boolean Result of query. + */ + private function autoUpdateDefaultMacros($id) + { + $defaultValues = $this->iniFile['discovery_extension_definition']['default_value']; + + foreach ($defaultValues as $macro => $value) { + $sql = 'INSERT IGNORE INTO `tdiscovery_apps_tasks_macros` + (`id_task`, `macro`, `type`, `value`, `temp_conf`) + SELECT `id_rt`, "'.$macro.'", "custom", "'.(string) io_safe_input($value).'", "0" + FROM `trecon_task` + WHERE `id_app` = "'.$id.'";'; + $result = db_process_sql($sql); + if ($result === false) { + return false; + } + } + + $tempFiles = $this->iniFile['tempfile_confs']['file']; + foreach ($tempFiles as $macro => $value) { + $sql = 'UPDATE `tdiscovery_apps_tasks_macros` + SET `value` = "'.(string) io_safe_input($value).'" WHERE `id_task` + IN (SELECT `id_rt` FROM `trecon_task` WHERE `id_app` = "'.$id.'") AND `macro` = "'.$macro.'"'; + $result = db_process_sql($sql); + if ($result === false) { + return false; + } + + $sql = 'INSERT IGNORE INTO `tdiscovery_apps_tasks_macros` + (`id_task`, `macro`, `type`, `value`, `temp_conf`) + SELECT `id_rt`, "'.$macro.'", "custom", "'.(string) io_safe_input($value).'", "1" + FROM `trecon_task` + WHERE `id_app` = "'.$id.'";'; + $result = db_process_sql($sql); + if ($result === false) { + return false; + } + } + + return true; + } + + + /** + * Load the exec files in database + * + * @param integer $id Id of extension. + * + * @return boolean Result of query. + */ + private function autoLoadConfigExec($id) + { + $executionFiles = $this->iniFile['discovery_extension_definition']['execution_file']; + + foreach ($executionFiles as $key => $value) { + $exist = db_get_row_filter( + 'tdiscovery_apps_scripts', + [ + 'id_app' => $id, + 'macro' => $key, + ] + ); + if ($exist === false) { + $result = db_process_sql_insert( + 'tdiscovery_apps_scripts', + [ + 'id_app' => $id, + 'macro' => $key, + 'value' => io_safe_input($value), + ] + ); + if ($result === false) { + return false; + } + } else { + $result = db_process_sql_update( + 'tdiscovery_apps_scripts', + ['value' => io_safe_input($value)], + [ + 'id_app' => $id, + 'macro' => $key, + ] + ); + if ($result === false) { + return false; + } + } + } + + $execCommands = $this->iniFile['discovery_extension_definition']['exec']; + $result = db_process_sql_delete( + 'tdiscovery_apps_executions', + ['id_app' => $id] + ); + if ($result === false) { + return false; + } + + foreach ($execCommands as $key => $value) { + $result = db_process_sql_insert( + 'tdiscovery_apps_executions', + [ + 'id_app' => $id, + 'execution' => io_safe_input($value), + ] + ); + if ($result === false) { + return false; + } + } + + return true; + } + + + /** + * Check if exist folder extension in console. + * + * @param string $shortName Name of folder. + * + * @return boolean Return true if exist folder + */ + private function checkFolderConsole($shortName) + { + global $config; + + $folderPath = $config['homedir'].'/'.$this->path.'/'.$shortName; + $iniPath = $config['homedir'].'/'.$this->path.'/'.$shortName.'/discovery_definition.ini'; + if (file_exists($folderPath) === false || file_exists($iniPath) === false) { + return false; + } else { + return true; + } + } + + + /** + * Validate the ini name by ajax. + * + * @return void + */ + public function validateIniName() + { + global $config; + $uploadDisco = get_parameter('upload_disco', ''); + if (empty($uploadDisco) === false) { + if ($_FILES['file']['error'] == 0) { + $disco = $_FILES['file']; + } else { + echo json_encode(['success' => false, 'message' => 'Failed to upload extension']); + return; + } + } + + if (substr($disco['name'], -6) !== '.disco') { + echo json_encode(['success' => false, 'message' => 'Failed to upload extension']); + return; + } + + $nameFile = str_replace('.disco', '.zip', $disco['name']); + $nameTempDir = $config['attachment_store'].'/downloads/'; + if (file_exists($nameTempDir) === false) { + mkdir($nameTempDir); + } + + $tmpPath = Files::tempdirnam( + $nameTempDir, + 'extensions_uploaded_' + ); + $result = move_uploaded_file($disco['tmp_name'], $tmpPath.'/'.$nameFile); + if ($result === true) { + $unzip = $this->unZip($tmpPath.'/'.$nameFile, $tmpPath, 'discovery_definition.ini'); + if ($unzip === true) { + unlink($tmpPath.'/'.$nameFile); + $this->iniFile = parse_ini_file($tmpPath.'/discovery_definition.ini', true, INI_SCANNER_TYPED); + if ($this->iniFile === false) { + Files::rmrf($tmpPath); + echo json_encode(['success' => false, 'message' => __('Failed to upload extension: Error while parsing dicovery_definition.ini')]); + return; + } + + $message = false; + $shortName = $this->iniFile['discovery_extension_definition']['short_name']; + if (strpos($shortName, 'pandorafms.') === 0) { + $message = __('The \'short_name\' starting with \'pandorafms.\' is reserved for Pandora FMS applications. If this is not an official Pandora FMS application, consider changing the \'short_name\'. Do you want to continue?'); + } + + $exist = db_get_row_filter( + 'tdiscovery_apps', + ['short_name' => $shortName] + ); + + if ($exist !== false) { + $message = __('There is another application with the same \'short_name\': \'%s\'. Do you want to overwrite the application and all of its contents?', $shortName); + } + + if ($message !== false) { + echo json_encode( + [ + 'success' => true, + 'warning' => true, + 'message' => $message, + ] + ); + } else { + echo json_encode(['success' => true]); + } + + Files::rmrf($tmpPath); + return; + } + } else { + Files::rmrf($tmpPath); + echo json_encode(['success' => false, 'message' => __('Failed to upload extension')]); + return; + } + } + + + /** + * Return all extensions from section. + * + * @param string $section Section to filter. + * + * @return array List of sections. + */ + static public function getExtensionBySection($section) + { + return db_get_all_rows_filter( + 'tdiscovery_apps', + ['section' => $section] + ); + } + + + /** + * Set execution permission in folder items and subfolders. + * + * @param string $path Array of files to apply permissions. + * @param array $filter Array of files for apply permission only. + * + * @return void + */ + private function setPermissionfiles($path, $filter=false) + { + global $config; + + if ($filter !== false && is_array($filter) === true) { + foreach ($filter as $key => $file) { + if (substr($file, 0, 1) !== '/') { + $file = $path.'/'.$file; + } + + chmod($file, 0777); + } + } else { + chmod($path, 0777); + + if (is_dir($path)) { + $items = scandir($path); + foreach ($items as $item) { + if ($item != '.' && $item != '..') { + $itemPath = $path.'/'.$item; + $this->setPermissionfiles($itemPath); + } + } + } + } + } + + + /** + * Unzip folder or only file. + * + * @param string $zipFile File to unzip. + * @param string $target_path Target path into unzip. + * @param string $file If only need unzip one file. + * + * @return boolean $result True if the file has been successfully decompressed. + */ + public function unZip($zipFile, $target_path, $file=null) + { + $zip = new \ZipArchive; + + if ($zip->open($zipFile) === true) { + $zip->extractTo($target_path, $file); + $zip->close(); + return true; + } else { + return false; + } + } + + +} diff --git a/pandora_console/godmode/wizards/Wizard.main.php b/pandora_console/godmode/wizards/Wizard.main.php index 39c81569c4..a286b97fca 100644 --- a/pandora_console/godmode/wizards/Wizard.main.php +++ b/pandora_console/godmode/wizards/Wizard.main.php @@ -522,4 +522,28 @@ class Wizard } + /** + * Generates warning message. + * + * @return void Warning message. + */ + public function printWarningMessage() + { + return ui_print_warning_message( + __( + 'Starting with version 773, the new modular system of discovery 2.0 has been implemented. The current + discovery (1.0) and its defined tasks will continue to function normally until the next LTS version, + in which migration to the new system will be mandatory. + The tasks of the current discovery (1.0) will be marked as legacy although it will not affect their + operation, it will only be a visual indicator to identify and differentiate the tasks of discovery 1.0 + from those of the new version 2.0. + In the intermediate versions between the 773 and the next LTS version, more applications of the new + discovery 2.0 will be added. Both new and those that will come to replace the applications of the + current discovery 1.0. In addition, an automatic migration tool for legacy (1.0) tasks to the new 2.0 + model will be included.' + ) + ); + } + + } diff --git a/pandora_console/images/Netflow2@svg.svg b/pandora_console/images/Netflow2@svg.svg new file mode 100644 index 0000000000..c1b66201b3 --- /dev/null +++ b/pandora_console/images/Netflow2@svg.svg @@ -0,0 +1,7 @@ + + + Netflow@svg + + + + \ No newline at end of file diff --git a/pandora_console/images/checkbox_green.svg b/pandora_console/images/checkbox_green.svg new file mode 100644 index 0000000000..044726fc65 --- /dev/null +++ b/pandora_console/images/checkbox_green.svg @@ -0,0 +1,8 @@ + + + Icons/Dark/20/checkbox-on@svg + + + + + \ No newline at end of file diff --git a/pandora_console/images/circle_title.svg b/pandora_console/images/circle_title.svg new file mode 100644 index 0000000000..23c906e4e5 --- /dev/null +++ b/pandora_console/images/circle_title.svg @@ -0,0 +1,19 @@ + + + EB094270-FB38-4A58-BE94-D40EA44EA568 + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/data-group@svg.svg b/pandora_console/images/data-group@svg.svg new file mode 100644 index 0000000000..58bc904f58 --- /dev/null +++ b/pandora_console/images/data-group@svg.svg @@ -0,0 +1,7 @@ + + + data-group@svg + + + + \ No newline at end of file diff --git a/pandora_console/images/fail_red@svg.svg b/pandora_console/images/fail_red@svg.svg new file mode 100644 index 0000000000..b07e7cb835 --- /dev/null +++ b/pandora_console/images/fail_red@svg.svg @@ -0,0 +1,12 @@ + + + + Dark / 20 / delete-v2@svg + Created with Sketch. + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/report-task.svg b/pandora_console/images/report-task.svg new file mode 100644 index 0000000000..b16b7144da --- /dev/null +++ b/pandora_console/images/report-task.svg @@ -0,0 +1,8 @@ + + + Reportes programados@svg + + + + + \ No newline at end of file diff --git a/pandora_console/images/security_scan@svg.svg b/pandora_console/images/security_scan@svg.svg new file mode 100644 index 0000000000..dacc06907a --- /dev/null +++ b/pandora_console/images/security_scan@svg.svg @@ -0,0 +1,7 @@ + + + Security scan@svg + + + + \ No newline at end of file diff --git a/pandora_console/images/widgets/AgentHive.png b/pandora_console/images/widgets/AgentHive.png new file mode 100644 index 0000000000..9a3c4623e5 Binary files /dev/null and b/pandora_console/images/widgets/AgentHive.png differ diff --git a/pandora_console/images/widgets/netflow.png b/pandora_console/images/widgets/netflow.png new file mode 100644 index 0000000000..5a34c1635f Binary files /dev/null and b/pandora_console/images/widgets/netflow.png differ diff --git a/pandora_console/images/wizard/Configurar_app@svg.svg b/pandora_console/images/wizard/Configurar_app@svg.svg new file mode 100644 index 0000000000..59507e2cf4 --- /dev/null +++ b/pandora_console/images/wizard/Configurar_app@svg.svg @@ -0,0 +1,22 @@ + + + + Configurar app@svg + Created with Sketch. + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/wizard/Custom_apps@svg.svg b/pandora_console/images/wizard/Custom_apps@svg.svg new file mode 100644 index 0000000000..23e251912d --- /dev/null +++ b/pandora_console/images/wizard/Custom_apps@svg.svg @@ -0,0 +1,21 @@ + + + + Custom apps@svg + Created with Sketch. + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/wizard/app_generico.svg b/pandora_console/images/wizard/app_generico.svg new file mode 100644 index 0000000000..99d3e5cf42 --- /dev/null +++ b/pandora_console/images/wizard/app_generico.svg @@ -0,0 +1,18 @@ + + + + App gen茅rico@svg + Created with Sketch. + + + + + + + + + + + + + \ No newline at end of file diff --git a/pandora_console/images/wizard/applications.png b/pandora_console/images/wizard/applications.png new file mode 100644 index 0000000000..01c10178bd Binary files /dev/null and b/pandora_console/images/wizard/applications.png differ diff --git a/pandora_console/images/wizard/cloud.png b/pandora_console/images/wizard/cloud.png new file mode 100644 index 0000000000..a016599e2f Binary files /dev/null and b/pandora_console/images/wizard/cloud.png differ diff --git a/pandora_console/images/wizard/consoletasks.png b/pandora_console/images/wizard/consoletasks.png new file mode 100644 index 0000000000..0087897495 Binary files /dev/null and b/pandora_console/images/wizard/consoletasks.png differ diff --git a/pandora_console/include/ajax/alert_list.ajax.php b/pandora_console/include/ajax/alert_list.ajax.php index 1be86560c8..2fbda5d75c 100644 --- a/pandora_console/include/ajax/alert_list.ajax.php +++ b/pandora_console/include/ajax/alert_list.ajax.php @@ -14,7 +14,7 @@ * |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______| * * ========================================================== - * Copyright (c) 2005-2022 Artica Soluciones Tecnol贸gicas S.L + * Copyright (c) 2005-2023 Pandora FMS * This code is NOT free software. This code is NOT licenced under GPL2 licence * You cannot redistribute it without written permission of copyright holder. * ============================================================================ @@ -419,6 +419,19 @@ if ($get_actions_module) { } if ($show_update_action_menu) { + if (is_metaconsole()) { + if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) { + $server_name = explode(' ', io_safe_output(get_parameter('id_agent')))[0]; + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) !== NOERR) { + echo json_encode(false); + // Restore db connection. + metaconsole_restore_db(); + return; + } + } + } + if (! check_acl($config['id_user'], 0, 'LW')) { db_pandora_audit( AUDIT_LOG_ACL_VIOLATION, @@ -449,7 +462,12 @@ if ($show_update_action_menu) { $id_action ); - $data .= '
'; + if (is_metaconsole()) { + $data .= ''; + } else { + $data .= ''; + } + $data .= ''; $data .= html_print_input_hidden( 'update_action', @@ -466,6 +484,11 @@ if ($show_update_action_menu) { $id_action, true ); + $data .= html_print_input_hidden( + 'id_agent', + $server_name, + true + ); if (! $id_agente) { $data .= ''; $data .= ''; $data .= ''; + + if (isset($action_option['module_action_threshold']) === false) { + $action_option['module_action_threshold'] = '300'; + } + $data .= ''; $data .= ''; $data .= ''; @@ -584,6 +612,11 @@ if ($show_update_action_menu) { true ); $data .= ''; + if (is_metaconsole()) { + // Restore db connection. + metaconsole_restore_db(); + } + echo $data; return; } @@ -954,6 +987,7 @@ if ($get_agent_alerts_datatable === true) { $tmp->last_fired = $row[8]; $tmp->status = $row[9]; $tmp->validate = $row[10]; + $tmp->actions = $row[11]; } else { // Open. $tmp->standby = $row[0]; diff --git a/pandora_console/include/ajax/audit_log.php b/pandora_console/include/ajax/audit_log.php index c979568b21..c0d1c4f73e 100644 --- a/pandora_console/include/ajax/audit_log.php +++ b/pandora_console/include/ajax/audit_log.php @@ -84,7 +84,7 @@ if ($save_log_filter) { if ($recover_aduit_log_select) { - echo json_encode(audit_get_audit_filter_select()); + echo json_encode(audit_get_audit_filter_select_fix_order()); } if ($update_log_filter) { @@ -190,7 +190,7 @@ function show_filter() { draggable: true, modal: false, closeOnEscape: true, - width: 380 + width: "auto" }); } @@ -207,12 +207,13 @@ function load_filter_values() { }, success: function(data) { var options = ""; + console.log(data); $.each(data,function(i,value){ if (i == 'text'){ $("#text-filter_text").val(value); } if (i == 'period'){ - $("#text-filter_period").val(value); + $("#filter_period").val(value).change(); } if (i == 'ip'){ $("#text-filter_ip").val(value); @@ -265,19 +266,31 @@ if ($save_filter_modal) { $data = []; $table->rowid[0] = 'update_save_selector'; - $data[0] = html_print_radio_button( - 'filter_mode', - 'new', - __('New filter'), - true, + $data[0] = html_print_div( + [ + 'style' => 'display: flex;', + 'content' => html_print_radio_button( + 'filter_mode', + 'new', + __('New filter'), + true, + true + ), + ], true ); - $data[1] = html_print_radio_button( - 'filter_mode', - 'update', - __('Update filter'), - false, + $data[1] = html_print_div( + [ + 'style' => 'display: flex;', + 'content' => html_print_radio_button( + 'filter_mode', + 'update', + __('Update filter'), + false, + true + ), + ], true ); @@ -395,7 +408,7 @@ function save_new_filter() { "save_log_filter" : 1, "id_name" : $("#text-id_name").val(), "text" : $("#text-filter_text").val(), - "period" : $("#text-filter_period").val(), + "period" : $("#filter_period :selected").val(), "ip" : $('#text-filter_ip').val(), "type" : $('#filter_type :selected').val(), "user" : $('#filter_user :selected').val(), @@ -431,7 +444,7 @@ function save_update_filter() { "update_log_filter" : 1, "id" : $("#overwrite_filter :selected").val(), "text" : $("#text-filter_text").val(), - "period" : $("#text-filter_period").val(), + "period" : $("#filter_period :selected").val(), "ip" : $('#text-filter_ip').val(), "type" : $('#filter_type :selected').val(), "user" : $('#filter_user :selected').val(), diff --git a/pandora_console/include/ajax/consoles.ajax.php b/pandora_console/include/ajax/consoles.ajax.php index 1d76e3131e..d060d6f9b6 100644 --- a/pandora_console/include/ajax/consoles.ajax.php +++ b/pandora_console/include/ajax/consoles.ajax.php @@ -14,7 +14,7 @@ * |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______| * * ========================================================== - * Copyright (c) 2005-2022 Artica Soluciones Tecnol贸gicas S.L + * Copyright (c) 2005-2023 Pandora FMS * This code is NOT free software. This code is NOT licenced under GPL2 licence * You cannot redistribute it without written permission of copyright holder. * ============================================================================ diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 666d23d244..571955fd25 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -90,86 +90,38 @@ $get_comments = (bool) get_parameter('get_comments', false); $get_events_fired = (bool) get_parameter('get_events_fired'); $get_id_source_event = get_parameter('get_id_source_event'); $node_id = (int) get_parameter('node_id', 0); +$settings_modal = get_parameter('settings', 0); +$parameters_modal = get_parameter('parameters', 0); if ($get_comments === true) { - $event = get_parameter('event', false); - $event_rep = (int) get_parameter_post('event')['event_rep']; - $group_rep = (int) get_parameter_post('event')['group_rep']; + global $config; + $event = json_decode(io_safe_output(base64_decode(get_parameter('event', ''))), true); + $filter = json_decode(io_safe_output(base64_decode(get_parameter('filter', ''))), true); + + $default_hour = (int) $filter['event_view_hr']; + if (isset($config['max_hours_old_event_comment']) === true + && empty($config['max_hours_old_event_comment']) === false + ) { + $default_hour = (int) $config['max_hours_old_event_comment']; + } + + $custom_event_view_hr = (int) get_parameter('custom_event_view_hr', 0); + if (empty($custom_event_view_hr) === false) { + if ($custom_event_view_hr === -2) { + $filter['event_view_hr_cs'] = ($default_hour * 3600); + } else { + $filter['event_view_hr_cs'] = $custom_event_view_hr; + } + } else { + $filter['event_view_hr_cs'] = ($default_hour * 3600); + } if ($event === false) { return __('Failed to retrieve comments'); } - $eventsGrouped = []; - // Consider if the event is grouped. - $whereGrouped = '1=1'; - if ($group_rep === EVENT_GROUP_REP_EVENTS && $event_rep > 1) { - // Default grouped message filtering (evento and estado). - $whereGrouped = sprintf( - '`evento` = "%s"', - $event['evento'] - ); - - // If id_agente is reported, filter the messages by them as well. - if ((int) $event['id_agente'] > 0) { - $whereGrouped .= sprintf( - ' AND `id_agente` = %d', - (int) $event['id_agente'] - ); - } - - if ((int) $event['id_agentmodule'] > 0) { - $whereGrouped .= sprintf( - ' AND `id_agentmodule` = %d', - (int) $event['id_agentmodule'] - ); - } - } else if ($group_rep === EVENT_GROUP_REP_EXTRAIDS) { - $whereGrouped = sprintf( - '`id_extra` = "%s"', - io_safe_output($event['id_extra']) - ); - } else { - $whereGrouped = sprintf('`id_evento` = %d', $event['id_evento']); - } - - try { - if (is_metaconsole() === true - && $event['server_id'] > 0 - ) { - $node = new Node($event['server_id']); - $node->connect(); - } - - $sql = sprintf( - 'SELECT `user_comment` - FROM tevento - WHERE %s', - $whereGrouped - ); - - // Get grouped comments. - $eventsGrouped = db_get_all_rows_sql($sql); - } catch (\Exception $e) { - // Unexistent agent. - if (is_metaconsole() === true - && $event['server_id'] > 0 - ) { - $node->disconnect(); - } - - $eventsGrouped = []; - } finally { - if (is_metaconsole() === true - && $event['server_id'] > 0 - ) { - $node->disconnect(); - } - } - - // End of get_comments. - echo events_page_comments($event, true, $eventsGrouped); - + $eventsGrouped = event_get_comment($event, $filter); + echo events_page_comments($event, $eventsGrouped, $filter); return; } @@ -562,8 +514,13 @@ if ($load_filter_modal) { false ); + $action = 'index.php?sec=eventos&sec2=operation/events/events&pure='; + if ($settings_modal !== 0 && $parameters_modal !== 0) { + $action .= '&settings='.$settings_modal.'¶meters='.$parameters_modal; + } + echo '
'; - echo '
'; + echo ''; $table = new StdClass; $table->id = 'load_filter_form'; @@ -1003,7 +960,7 @@ function save_new_filter() { } else { id_filter_save = data; - + $("#info_box").filter(function(i, item) { if ($(item).data('type_info_box') == "success_create_filter") { return true; @@ -2003,23 +1960,7 @@ if ($get_extended_event) { $js .= '});'; - $js .= ' - $("#link_comments").click(function (){ - $.post ({ - url : "ajax.php", - data : { - page: "include/ajax/events", - get_comments: 1, - event: '.json_encode($event).', - event_rep: '.$event_rep.' - }, - dataType : "html", - success: function (data) { - $("#extended_event_comments_page").empty(); - $("#extended_event_comments_page").html(data); - } - }); - });'; + $js .= '$("#link_comments").click(get_table_events_tabs(\''.base64_encode(json_encode($event)).'\',\''.base64_encode(json_encode($filter)).'\'));'; if (events_has_extended_info($event['id_evento']) === true) { $js .= ' @@ -2525,7 +2466,7 @@ if ($drawConsoleSound === true) { 'label' => __('Start'), 'type' => 'button', 'name' => 'start-search', - 'attributes' => [ 'class' => 'play' ], + 'attributes' => [ 'class' => 'play secondary' ], 'return' => true, ], 'div', @@ -2651,23 +2592,24 @@ if ($get_events_fired) { $return[] = array_merge( $event, [ - 'fired' => $event['id_evento'], - 'message' => ui_print_string_substr( + 'fired' => $event['id_evento'], + 'message' => ui_print_string_substr( strip_tags(io_safe_output($event['evento'])), 75, true, '9' ), - 'priority' => ui_print_event_priority($event['criticity'], true, true), - 'type' => events_print_type_img( + 'priority' => ui_print_event_priority($event['criticity'], true, true), + 'type' => events_print_type_img( $event['event_type'], true ), - 'timestamp' => ui_print_timestamp( + 'timestamp' => ui_print_timestamp( $event['timestamp'], true, ['style' => 'font-size: 9pt; letter-spacing: 0.3pt;'] ), + 'event_timestamp' => $event['timestamp'], ] ); } diff --git a/pandora_console/include/ajax/graph.ajax.php b/pandora_console/include/ajax/graph.ajax.php index 7b2d08970b..6ea76f373b 100644 --- a/pandora_console/include/ajax/graph.ajax.php +++ b/pandora_console/include/ajax/graph.ajax.php @@ -17,6 +17,8 @@ $save_custom_graph = (bool) get_parameter('save_custom_graph'); $print_custom_graph = (bool) get_parameter('print_custom_graph', false); $print_sparse_graph = (bool) get_parameter('print_sparse_graph'); $get_graphs = (bool) get_parameter('get_graphs_container'); +$width = get_parameter('width', 0); +$height = get_parameter('height', 0); if ($save_custom_graph) { $return = []; @@ -25,8 +27,6 @@ if ($save_custom_graph) { $name = get_parameter('name', ''); $description = get_parameter('description', ''); $stacked = get_parameter('stacked', CUSTOM_GRAPH_LINE); - $width = get_parameter('width', 0); - $height = get_parameter('height', 0); $events = get_parameter('events', 0); $period = get_parameter('period', 0); $fullscale = get_parameter('fullscale', 0); @@ -126,6 +126,8 @@ if ($print_sparse_graph) { 'force_interval' => '', 'time_interval' => 300, 'array_data_create' => 0, + 'height' => $height, + 'width' => $width, ]; echo grafico_modulo_sparse($params); diff --git a/pandora_console/include/ajax/hostDevices.ajax.php b/pandora_console/include/ajax/hostDevices.ajax.php index 69007a6ef4..9b0fac2930 100644 --- a/pandora_console/include/ajax/hostDevices.ajax.php +++ b/pandora_console/include/ajax/hostDevices.ajax.php @@ -14,7 +14,7 @@ * |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______| * * ========================================================== - * Copyright (c) 2004-2019 Artica Soluciones Tecnol贸gicas S.L + * Copyright (c) 2004-2023 Pandora FMS * This code is NOT free software. This code is NOT licenced under GPL2 licence * You cannnot redistribute it without written permission of copyright holder. * ============================================================================ diff --git a/pandora_console/include/ajax/manage_extensions.ajax.php b/pandora_console/include/ajax/manage_extensions.ajax.php new file mode 100644 index 0000000000..b116277a23 --- /dev/null +++ b/pandora_console/include/ajax/manage_extensions.ajax.php @@ -0,0 +1,60 @@ +ajaxMethod($method) === true) { + $actions->{$method}(); + } else { + $actions->errorAjax('Unavailable method.'); + } +} else { + $actions->errorAjax('Method not found. ['.$method.']'); +} + + +// Stop any execution. +exit; diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index 8072dbea0a..921a1e1bc0 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -97,6 +97,21 @@ if (check_login()) { return; } + $id_plugin = get_parameter('id_plugin', 0); + + if ($id_plugin !== 0) { + $id_module_plugin = db_get_value( + 'id_plugin', + 'tagente_modulo', + 'id_agente_modulo', + $get_module_macros + ); + if ($id_plugin !== $id_module_plugin) { + $get_plugin_macros = true; + $get_module_macros = 0; + } + } + if ($get_plugin_macros) { if (https_is_running()) { header('Content-type: application/json'); @@ -606,7 +621,7 @@ if (check_login()) { } if (empty($table->data)) { - ui_print_error_message(__('No available data to show')); + ui_print_empty_data(__('No available data to show'), '', false); } else { ui_pagination( count($count), @@ -1252,7 +1267,10 @@ if (check_login()) { 'content' => html_print_image( 'images/event-history.svg', true, - [ 'class' => 'main_menu_icon' ] + [ + 'title' => __('Event history'), + 'class' => 'main_menu_icon forced_title', + ] ), ], true @@ -1267,7 +1285,10 @@ if (check_login()) { 'content' => html_print_image( 'images/module-graph.svg', true, - [ 'class' => 'main_menu_icon' ] + [ + 'title' => __('Module graph'), + 'class' => 'main_menu_icon forced_title', + ] ), ], true @@ -1284,7 +1305,10 @@ if (check_login()) { 'content' => html_print_image( 'images/simple-value.svg', true, - [ 'class' => 'main_menu_icon' ] + [ + 'title' => __('Module detail'), + 'class' => 'main_menu_icon forced_title', + ] ), ], true @@ -1320,7 +1344,10 @@ if (check_login()) { 'content' => html_print_image( $imgaction, true, - [ 'class' => 'main_menu_icon' ] + [ + 'title' => __('Force remote check'), + 'class' => 'main_menu_icon forced_title', + ] ), ], true @@ -1337,7 +1364,10 @@ if (check_login()) { 'content' => html_print_image( 'images/edit.svg', true, - [ 'class' => 'main_menu_icon' ] + [ + 'title' => __('Edit configuration'), + 'class' => 'main_menu_icon forced_title', + ] ), ], true diff --git a/pandora_console/include/ajax/snmp_browser.ajax.php b/pandora_console/include/ajax/snmp_browser.ajax.php index 9461dd8ca8..7bff27da4a 100644 --- a/pandora_console/include/ajax/snmp_browser.ajax.php +++ b/pandora_console/include/ajax/snmp_browser.ajax.php @@ -182,6 +182,7 @@ try { if ($method == 'snmp_browser_create_modules') { // Get target ids from form. + $use_agent_ip = get_parameter('use_agent_ip', ''); $id_items = get_parameter('id_item2', null); $id_target = null; if (empty($id_items) === false) { @@ -209,7 +210,8 @@ try { $module_target, $snmp_conf_values, $id_target, - $server_to_exec + $server_to_exec, + $use_agent_ip ); // Return fail modules for error/success message. diff --git a/pandora_console/include/ajax/task_to_perform.php b/pandora_console/include/ajax/task_to_perform.php new file mode 100644 index 0000000000..53bdf0556a --- /dev/null +++ b/pandora_console/include/ajax/task_to_perform.php @@ -0,0 +1,190 @@ + SERVER_TYPE_WEB], 'status')['status']; + if ($status_webserver === '1') { + $name = array_keys(servers_get_names())[0]; + $id_group = get_parameter('id_group', 4); + + $array_other['data'] = [ + 'Web monitoring', + '', + 2, + $id_group, + 0, + 30, + 30, + 9, + $name, + 0, + 0, + 0, + __('Agent Web monitoring created on welcome'), + ]; + + $id_agent = api_set_new_agent(0, '', $array_other, '', true, true); + if (is_integer($id_agent)) { + $module_name = get_parameter('module_name', 'Web_monitoring_module'); + $text_to_search = get_parameter('text_to_search', ''); + $url_goliat = get_parameter('url_goliat', 'https://pandorafms.com/en/'); + $module_latency = create_module_latency_goliat($id_agent, $module_name, $id_group, $url_goliat, $text_to_search); + $module_status = create_module_status_goliat($id_agent, $module_name, $id_group, $url_goliat, $text_to_search); + if ($module_latency > 0 && $module_status > 0) { + ui_print_success_message(__('Your check has been created, click here to view the data. Please note that it may take a few seconds to see data if your server is busy')); + } + } else { + ui_print_error_message(__($id_agent)); + } + } else { + ui_print_error_message(__('Web server is not enabled.')); + } +} + +if ($check_connectivity) { + include_once '../functions_api.php'; + include_once '../functions_servers.php'; + + $status_newtwork = db_get_row_filter('tserver', ['server_type' => SERVER_TYPE_NETWORK], 'status')['status']; + $status_pluggin = db_get_row_filter('tserver', ['server_type' => SERVER_TYPE_PLUGIN], 'status')['status']; + if ($status_newtwork === '1' && $status_pluggin === '1') { + $name = array_keys(servers_get_names())[0]; + $id_group = get_parameter('id_group', 4); + $agent_name = get_parameter('agent_name', __('Agent check connectivity')); + + $array_other['data'] = [ + $agent_name, + '', + 2, + $id_group, + 0, + 30, + 30, + 9, + $name, + 0, + 0, + 0, + __('Basic connectivity'), + ]; + + $id_agent = api_set_new_agent(0, '', $array_other, '', true, true); + if (is_integer($id_agent)) { + $ip_target = get_parameter('ip_target', '127.0.0.1'); + $basic_network = create_module_basic_network($id_agent, $id_group, $ip_target); + $latency_network = create_module_latency_network($id_agent, $id_group, $ip_target); + $packet_lost = create_module_packet_lost($id_agent, $id_group, $ip_target); + if ($basic_network > 0 && $latency_network > 0 && $packet_lost > 0) { + ui_print_success_message(__('Your check has been created, click here to view the data. Please note that it may take a few seconds to see data if your server is busy')); + } + } else { + ui_print_error_message(__($id_agent)); + } + } else { + ui_print_error_message(__('Web server is not enabled.')); + } +} + +if ($create_net_scan) { + $ip_target = get_parameter('ip_target', '192.168.10.0/24'); + $id_net_scan = create_net_scan($ip_target); + if ($id_net_scan > 0) { + $id_recon_server = db_get_row_filter('tserver', ['server_type' => SERVER_TYPE_DISCOVERY], 'id_server')['id_server']; + ui_print_success_message(__('Basic net created and scan in progress. Click here to view the data. Please note that it may take a few seconds to see data if your server is busy')); + } else { + ui_print_error_message(__('Basic net already exists. Click here to view the data')); + } +} + +if ($create_mail_alert) { + include_once '../functions_alerts.php'; + $id_action = db_get_row_filter('talert_actions', ['name' => 'Email to '.$config['id_user']], 'id')['id']; + if (!$id_action) { + $al_action = alerts_get_alert_action($id); + $id_action = alerts_clone_alert_action(1, $al_action['id_group'], 'Email to '.$config['id_user']); + } + + $id_alert_template = get_parameter('id_condition', 0); + $id_agent_module = get_parameter('id_agent_module', 0); + + $exist = db_get_value_sql( + sprintf( + 'SELECT COUNT(id) + FROM talert_template_modules + WHERE id_agent_module = %d + AND id_alert_template = %d + AND id_policy_alerts = 0 + ', + $id_agent_module, + $id_alert_template + ) + ); + + if ($exist > 0) { + ui_print_error_message(__('Alert already exists. Click here to view the data')); + } else { + $id = alerts_create_alert_agent_module($id_agent_module, $id_alert_template); + if ($id !== false) { + $values = []; + $values['fires_min'] = (int) get_parameter('fires_min'); + $values['fires_max'] = (int) get_parameter('fires_max'); + $values['module_action_threshold'] = (int) 300; + + $alert_created = alerts_add_alert_agent_module_action($id, $id_action, $values); + } + } + + if ($alert_created === true) { + ui_print_success_message(__('Congratulations, you have already created a simple alert. You can see it. Pandora FMS alerts are very flexible, you can do many more things with them, we recommend you to read the documentation for more information. You can create advanced alerts from here.')); + } +} + +if ($create_unknown_template_alert) { + if (is_array(alerts_get_alert_templates(['name' => io_safe_input('Unknown condition')]))) { + echo 1; + } else { + echo create_template_alert_unknown(); + } +} diff --git a/pandora_console/include/ajax/update_manager.php b/pandora_console/include/ajax/update_manager.php index 75d92a9389..bf33f414a3 100644 --- a/pandora_console/include/ajax/update_manager.php +++ b/pandora_console/include/ajax/update_manager.php @@ -129,19 +129,67 @@ if ($method === 'draw') { $count = db_get_value('count(*)', '('.$sql.') t'); if ($data) { - $data = array_reduce( - $data, - function ($carry, $item) { - // Transforms array of arrays $data into an array - // of objects, making a post-process of certain fields. - $tmp = (object) $item; + if ($config['prominent_time'] === 'timestamp') { + $data = array_reduce( + $data, + function ($carry, $item) { + // Transforms array of arrays $data into an array + // of objects, making a post-process of certain fields. + $tmp = (object) $item; + date_default_timezone_set($user_timezone); + $title = human_time_comparation($tmp->utimestamp); + $tmp->utimestamp = ''.modules_format_timestamp($tmp->utimestamp).''; - $tmp->utimestamp = human_time_comparation($tmp->utimestamp); + $carry[] = $tmp; + return $carry; + } + ); + } else if ($config['prominent_time'] === 'comparation') { + $data = array_reduce( + $data, + function ($carry, $item) { + // Transforms array of arrays $data into an array + // of objects, making a post-process of certain fields. + $tmp = (object) $item; + date_default_timezone_set($user_timezone); + $title = modules_format_timestamp($tmp->utimestamp); + $tmp->utimestamp = ''.human_time_comparation($tmp->utimestamp).''; - $carry[] = $tmp; - return $carry; - } - ); + $carry[] = $tmp; + return $carry; + } + ); + } else if ($config['prominent_time'] === 'compact') { + $data = array_reduce( + $data, + function ($carry, $item) { + // Transforms array of arrays $data into an array + // of objects, making a post-process of certain fields. + $tmp = (object) $item; + date_default_timezone_set($user_timezone); + $title = modules_format_timestamp($tmp->utimestamp); + $tmp->utimestamp = ''.human_time_comparation($tmp->utimestamp, 'tiny').''; + + $carry[] = $tmp; + return $carry; + } + ); + } else { + $data = array_reduce( + $data, + function ($carry, $item) { + // Transforms array of arrays $data into an array + // of objects, making a post-process of certain fields. + $tmp = (object) $item; + date_default_timezone_set($user_timezone); + $title = modules_format_timestamp($tmp->utimestamp); + $tmp->utimestamp = ''.human_time_comparation($tmp->utimestamp).''; + + $carry[] = $tmp; + return $carry; + } + ); + } } // Datatables format: RecordsTotal && recordsfiltered. diff --git a/pandora_console/include/ajax/visual_console.ajax.php b/pandora_console/include/ajax/visual_console.ajax.php index cf2f83bdcf..402a5ddc1a 100644 --- a/pandora_console/include/ajax/visual_console.ajax.php +++ b/pandora_console/include/ajax/visual_console.ajax.php @@ -39,6 +39,7 @@ $graph_javascript = (bool) get_parameter('graph_javascript', false); $force_remote_check = (bool) get_parameter('force_remote_check', false); $update_maintanance_mode = (bool) get_parameter('update_maintanance_mode', false); $load_css_cv = (bool) get_parameter('load_css_cv', false); +$update_grid_style = (bool) get_parameter('update_grid_style', false); if ($render_map) { $width = (int) get_parameter('width', '400'); @@ -126,3 +127,22 @@ if ($update_maintanance_mode === true) { echo json_encode(['result' => $result]); return; } + +if ($update_grid_style === true) { + $idVisualConsole = (int) get_parameter('idVisualConsole', 0); + $color = get_parameter('color', '#CCC'); + $size = get_parameter('size', '10'); + + $values = []; + $values['grid_color'] = $color; + $values['grid_size'] = $size; + + $result = db_process_sql_update( + 'tlayout', + $values, + ['id' => $idVisualConsole] + ); + + echo json_encode(['result' => $result]); + return; +} diff --git a/pandora_console/include/ajax/welcome_window.php b/pandora_console/include/ajax/welcome_window.php index 52fdcea8d2..2ca1a5e953 100644 --- a/pandora_console/include/ajax/welcome_window.php +++ b/pandora_console/include/ajax/welcome_window.php @@ -35,6 +35,13 @@ if (is_ajax() === false) { } $ajaxPage = 'include/ajax/welcome_window'; +// Ajax controller. +$method = get_parameter('method', ''); + +if ($method === 'loadWelcomeWindow') { + unset($config['welcome_state']); +} + // Control call flow. try { @@ -44,9 +51,6 @@ try { exit; } -// Ajax controller. -$method = get_parameter('method', ''); - if (method_exists($welcome_actions, $method) === true) { if ($welcome_actions->ajaxMethod($method) === true) { $welcome_actions->{$method}(); diff --git a/pandora_console/include/api.php b/pandora_console/include/api.php index 6566a3a3d5..b5f6d44ab7 100644 --- a/pandora_console/include/api.php +++ b/pandora_console/include/api.php @@ -129,6 +129,14 @@ if (empty($apiPassword) === true // Compat. $config['id_user'] = 'admin'; $correctLogin = true; + // Bypass credentials if server-auth and api-pass are correct. + } else if (($config['server_unique_identifier'] === get_parameter('server_auth')) + && ($api_password === $apiPassword) + && ((bool) isInACL($ipOrigin) === true) + ) { + $config['id_usuario'] = 'admin'; + $config['id_user'] = 'admin'; + $correctLogin = true; } else if ((bool) isInACL($ipOrigin) === true) { // External access. // Token is valid. Bypass the credentials. @@ -203,9 +211,9 @@ if ($correctLogin === true) { } break; - case 'create_network_module': + // case 'create_network_module': case 'create_plugin_module': - case 'create_data_module': + // case 'create_data_module': case 'create_synthetic_module': case 'create_snmp_module': case 'delete_module': diff --git a/pandora_console/include/auth/ldap.php b/pandora_console/include/auth/ldap.php index 3f01dcc124..76f7a6411c 100644 --- a/pandora_console/include/auth/ldap.php +++ b/pandora_console/include/auth/ldap.php @@ -27,8 +27,8 @@ if (!isset($config)) { - - + + diff --git a/pandora_console/include/auth/mysql.php b/pandora_console/include/auth/mysql.php index 614dba20b1..a24769e528 100644 --- a/pandora_console/include/auth/mysql.php +++ b/pandora_console/include/auth/mysql.php @@ -43,8 +43,8 @@ if (isset($config) === false) { - - + + @@ -237,8 +237,13 @@ function process_user_login_remote($login, $pass, $api=false) // Active Directory. case 'ad': - if (enterprise_hook('ad_process_user_login', [$login, $pass]) === false) { - $config['auth_error'] = 'User not found in database or incorrect password'; + $sr = enterprise_hook('ad_process_user_login', [$login, $pass]); + // Try with secondary server. + if ($sr === false && (bool) $config['secondary_active_directory'] === true) { + $sr = enterprise_hook('ad_process_user_login', [$login, $pass, true]); + } + + if ($sr === false) { return false; } break; @@ -814,10 +819,6 @@ function update_user(string $id_user, array $values) HOME_SCREEN_DASHBOARD => __('Dashboard'), ]; - if (array_key_exists($values['section'], $homeScreenValues) === true) { - $values['section'] = $homeScreenValues[$values['section']]; - } - if (is_metaconsole() === true) { $values['metaconsole_section'] = $values['section']; $values['metaconsole_data_section'] = $values['data_section']; diff --git a/pandora_console/include/chart_generator.php b/pandora_console/include/chart_generator.php index e22fb4d325..e8ee5f294c 100644 --- a/pandora_console/include/chart_generator.php +++ b/pandora_console/include/chart_generator.php @@ -136,37 +136,41 @@ if (file_exists('languages/'.$user_language.'.mo') === true) { $l10n->load_tables(); } +$hack_metaconsole = (is_metaconsole() === true) ? '../../' : ''; ?> Pandora FMS Graph - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + ;'> '1', - '2' => '2', '2c' => '2c', '3' => '3', ]; @@ -1645,13 +1644,13 @@ class AgentWizard extends HTML } else if (preg_match('/module-critical-max/', $k) > 0) { $result[$value]['criticalMax'] = $data[$k]; } else if (preg_match('/module-critical-inv/', $k) > 0) { - $result[$value]['criticalInv'] = $data[$k.'_sent']; + $result[$value]['criticalInv'] = $data[$k]; } else if (preg_match('/module-warning-inv/', $k) > 0) { - $result[$value]['warningInv'] = $data[$k.'_sent']; + $result[$value]['warningInv'] = $data[$k]; } else if (preg_match('/module-warning-perc/', $k) > 0) { - $result[$value]['warningPerc'] = $data[$k.'_sent']; + $result[$value]['warningPerc'] = $data[$k]; } else if (preg_match('/module-critical-perc/', $k) > 0) { - $result[$value]['criticalPerc'] = $data[$k.'_sent']; + $result[$value]['criticalPerc'] = $data[$k]; } else if (preg_match('/module-type/', $k) > 0) { $result[$value]['moduleType'] = $data[$k]; } else if (preg_match('/module-unit/', $k) > 0) { @@ -4360,7 +4359,7 @@ class AgentWizard extends HTML true, false, 'change_control(this, \''.$uniqueId.'\')', - false, + true, 'form="form-create-modules"' ), ], @@ -4376,7 +4375,7 @@ class AgentWizard extends HTML true, false, 'change_control(this, \''.$uniqueId.'\')', - false, + true, 'form="form-create-modules"' ), ], @@ -4442,7 +4441,7 @@ class AgentWizard extends HTML true, false, 'change_control(this, \''.$uniqueId.'\')', - false, + true, 'form="form-create-modules"' ), ], @@ -4459,7 +4458,7 @@ class AgentWizard extends HTML true, false, 'change_control(this,\''.$uniqueId.'\')', - false, + true, 'form="form-create-modules"' ), ], @@ -6240,22 +6239,24 @@ class AgentWizard extends HTML function change_control(checkbox, uniqueId) { var checkbox_name = $(checkbox).attr('name'); - if($(checkbox).prop('checked', true)) { - if(checkbox_name.match(/warning-inv/gm) !== null) { - $('#checkbox-module-warning-perc-'+uniqueId.replace('/','\\/')).prop('checked', false); - } + if(checkbox_name.match(/warning-inv/gm) !== null) { + $('#checkbox-module-warning-perc-'+uniqueId.replace('/','\\/')).prop('checked', false); + $('#checkbox-'+checkbox_name).val(1) + } - if(checkbox_name.match(/critical-inv/gm) !== null) { - $('#checkbox-module-critical-perc-'+uniqueId.replace('/','\\/')).prop('checked', false); - } + if(checkbox_name.match(/warning-perc/gm) !== null) { + $('#checkbox-module-warning-inv-'+uniqueId.replace('/','\\/')).prop('checked', false); + $('#checkbox-'+checkbox_name).val(1) + } - if(checkbox_name.match(/warning-perc/gm) !== null) { - $('#checkbox-module-warning-inv-'+uniqueId.replace('/','\\/')).prop('checked', false); - } + if(checkbox_name.match(/critical-inv/gm) !== null) { + $('#checkbox-module-critical-perc-'+uniqueId.replace('/','\\/')).prop('checked', false); + $('#checkbox-'+checkbox_name).val(1) + } - if(checkbox_name.match(/critical-perc/gm) !== null) { - $('#checkbox-module-critical-inv-'+uniqueId.replace('/','\\/')).prop('checked', false); - } + if(checkbox_name.match(/critical-perc/gm) !== null) { + $('#checkbox-module-critical-inv-'+uniqueId.replace('/','\\/')).prop('checked', false); + $('#checkbox-'+checkbox_name).val(1) } } diff --git a/pandora_console/include/class/AlertsList.class.php b/pandora_console/include/class/AlertsList.class.php new file mode 100644 index 0000000000..843a5fa304 --- /dev/null +++ b/pandora_console/include/class/AlertsList.class.php @@ -0,0 +1,488 @@ +AJAXMethods); + } + + + /** + * Generates a JSON error. + * + * @param string $msg Error message. + * + * @return void + */ + public function error($msg) + { + echo json_encode( + ['error' => $msg] + ); + } + + + /** + * Minor function to dump json message as ajax response. + * + * @param string $type Type: result || error. + * @param string $msg Message. + * @param boolean $delete Deletion messages. + * + * @return void + */ + private function ajaxMsg($type, $msg, $delete=false) + { + if ($type === 'error') { + $msg_title = ($delete === true) ? 'Failed while removing' : 'Failed while saving'; + } else { + $msg_title = ($delete === true) ? 'Successfully deleted' : 'Successfully saved into keystore'; + } + + echo json_encode( + [ $type => __($msg_title).':
'.$msg ] + ); + + exit; + } + + + /** + * Initializes object and validates user access. + * + * @param string $ajax_controller Path of ajaxController, is the 'page' + * variable sent in ajax calls. + * + * @return object + */ + public function __construct($ajax_controller) + { + global $config; + + // Check access. + check_login(); + + if ((bool) check_acl($config['id_user'], 0, 'LM') === false) { + db_pandora_audit( + AUDIT_LOG_ACL_VIOLATION, + 'Trying to access pending alerts list' + ); + + if (is_ajax()) { + echo json_encode(['error' => 'noaccess']); + } else { + include 'general/noaccess.php'; + } + + exit; + } + + $this->ajaxController = $ajax_controller; + + return $this; + } + + + /** + * Prints inputs for modal "Pending alerts list". + * + * @return void + */ + public function loadModal() + { + ob_start(); + echo '
'; + echo $this->getModalContent(); + echo '
'; + echo ob_get_clean(); + } + + + /** + * Run. + * + * @return void + */ + public function run() + { + global $config; + + ui_require_css_file('tables'); + + if ((bool) check_acl($config['id_user'], 0, 'LM') === false) { + db_pandora_audit( + AUDIT_LOG_ACL_VIOLATION, + 'Trying to access pending alerts list.' + ); + include 'general/noaccess.php'; + return; + } + + // Auxiliar div for modal. + echo ''; + + echo $this->loadJS(); + } + + + /** + * Draw table. + * + * @return void + */ + public function drawTable() + { + global $config; + + $start = get_parameter('start', 0); + $length = get_parameter('length', $config['block_size']); + $order = get_datatable_order(true); + + try { + ob_start(); + + $order_by_clause = ''; + + if (in_array($order['field'], ['agentAlias', 'moduleName', 'alertType']) === false) { + $order_by_clause = 'ORDER BY id '.$order['direction']; + } + + if ($length !== '-1') { + $sql = sprintf( + 'SELECT * + FROM talert_execution_queue %s + LIMIT %d, %d', + $order_by_clause, + $start, + $length + ); + } else { + $sql = sprintf( + 'SELECT * FROM talert_execution_queue %s', + $order_by_clause + ); + } + + // Retrieve data and count. + $data = db_get_all_rows_sql($sql); + $count = (int) db_get_sql('SELECT COUNT(*) FROM talert_execution_queue'); + + if ($data) { + $data = array_reduce( + $data, + function ($carry, $item) { + // Check if the item is an array before proceeding. + if (is_array($item) === true) { + // Transforms array of arrays $data into an array + // of objects, making a post-process of certain fields. + $tmp = (object) $item; + $decoded_data = base64_decode($tmp->data); + $decoded_data = json_decode($decoded_data, true); + + if (is_array($decoded_data) === true) { + // Access the second element of $decoded_data (index 1) to get 'alias' and 'type'. + $tmp->agentAlias = isset($decoded_data[1]['alias']) ? $decoded_data[1]['alias'] : null; + $tmp->alertType = isset($decoded_data[3]['type']) ? $decoded_data[3]['type'] : null; + // Access the third element of $decoded_data (index 2) to get 'nombre'. + $tmp->moduleName = isset($decoded_data[2]['nombre']) ? $decoded_data[2]['nombre'] : null; + + $carry[] = $tmp; + } + } + + return $carry; + } + ); + } + + echo json_encode( + [ + 'data' => $data, + 'recordsTotal' => $count, + 'recordsFiltered' => $count, + ] + ); + + // Capture output. + $response = ob_get_clean(); + } catch (Exception $e) { + echo json_encode(['error' => $e->getMessage()]); + exit; + } + + // If not valid, show error with issue. + json_decode($response); + if (json_last_error() == JSON_ERROR_NONE) { + // If valid dump. + echo $response; + } else { + echo json_encode( + ['error' => $response] + ); + } + + exit; + } + + + /** + * Generates content of modal. + * + * @return string Modal content. + */ + public function getModalContent() + { + global $config; + + ob_start(); + + try { + $columns = [ + 'id', + 'agentAlias', + 'moduleName', + 'alertType', + ]; + + $column_names = [ + __('ID'), + __('Agent'), + __('Module'), + __('Type'), + ]; + + $this->tableId = 'pending_alerts'; + ui_print_datatable( + [ + 'id' => $this->tableId, + 'class' => 'info_table', + 'style' => 'width: 99%', + 'columns' => $columns, + 'column_names' => $column_names, + 'ajax_url' => $this->ajaxController, + 'default_pagination' => 7, + 'dom_elements' => 'pfti', + 'ajax_data' => ['method' => 'drawTable'], + 'no_sortable_columns' => [ + 1, + 2, + 3, + ], + 'order' => [ + 'field' => 'id', + 'direction' => 'asc', + ], + ] + ); + } catch (Exception $e) { + echo $e->getMessage(); + } + + return ob_get_clean(); + } + + + /** + * Loads JS content. + * + * @return string JS content. + */ + public function loadJS() + { + ob_start(); + + ui_require_javascript_file('stepper', 'include/javascript/', true); + + // Javascript content. + ?> + + $this->tableId, 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => $this->ajaxController, @@ -469,7 +469,7 @@ class AuditLog extends HTML success: function(data) { var options = ""; $.each(data,function(key,value){ - options += ""; + options += ""; }); $('#overwrite_filter').html(options); $('#overwrite_filter').select2(); @@ -509,8 +509,12 @@ class AuditLog extends HTML /* Filter management */ $('#button-load-filter').click(function (){ if($('#load-filter-select').length) { - $('#load-filter-select').dialog({width: "20%", - maxWidth: "25%", + $('#load-filter-select').dialog({ + resizable: true, + draggable: true, + modal: false, + closeOnEscape: true, + width: "auto", title: "" }); $.ajax({ @@ -523,8 +527,9 @@ class AuditLog extends HTML }, success: function(data) { var options = ""; + console.log(data) $.each(data,function(key,value){ - options += ""; + options += ""; }); $('#filter_id').html(options); $('#filter_id').select2(); diff --git a/pandora_console/include/class/CalendarManager.class.php b/pandora_console/include/class/CalendarManager.class.php index ba1761d6f9..560fb6f4ad 100644 --- a/pandora_console/include/class/CalendarManager.class.php +++ b/pandora_console/include/class/CalendarManager.class.php @@ -701,7 +701,7 @@ class CalendarManager true, [ 'title' => __('Edit'), - 'class' => 'invert_filter', + 'class' => 'invert_filter main_menu_icon', ] ); $tmp->options .= ''; @@ -735,7 +735,7 @@ class CalendarManager true, [ 'title' => __('Delete'), - 'class' => 'invert_filter', + 'class' => 'invert_filter main_menu_icon', ] ); $tmp->options .= ''; @@ -1040,7 +1040,7 @@ class CalendarManager 'id' => 'templates_alerts_special_days', 'return' => true, 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => 'godmode/alerts/alert_special_days', diff --git a/pandora_console/include/class/ConfigPEN.class.php b/pandora_console/include/class/ConfigPEN.class.php index 2177e73a74..cea6123f08 100644 --- a/pandora_console/include/class/ConfigPEN.class.php +++ b/pandora_console/include/class/ConfigPEN.class.php @@ -612,7 +612,7 @@ class ConfigPEN extends HTML 'id' => $tableId, 'return' => true, 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => $this->ajaxController, diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index 99299a21ac..3eb093ab17 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -597,7 +597,6 @@ class ConsoleSupervisor 'days_delete_unknown' => 'Max. days before unknown modules are deleted', 'days_delete_not_initialized' => 'Max. days before delete not initialized modules', 'days_autodisable_deletion' => 'Max. days before autodisabled agents are deleted', - 'delete_old_network_matrix' => 'Max. days before delete old network matrix data', 'report_limit' => 'Item limit for real-time reports', 'event_view_hr' => 'Default hours for event view', 'big_operation_step_datos_purge' => 'Big Operation Step to purge old data', @@ -681,20 +680,24 @@ class ConsoleSupervisor */ public function checkAccessStatisticsPerformance() { + global $config; + $total_agents = db_get_value('count(*)', 'tagente'); if ($total_agents >= 200) { - db_process_sql_update('tconfig', ['value' => 0], ['token' => 'agentaccess']); - $this->notify( - [ - 'type' => 'NOTIF.ACCESSSTASTICS.PERFORMANCE', - 'title' => __('Access statistics performance'), - 'message' => __( - 'Usage of agent access statistics IS NOT RECOMMENDED on systems with more than 200 agents due performance penalty' - ), - 'url' => '__url__/index.php?sec=general&sec2=godmode/setup/setup§ion=perf', - ] - ); + if ($config['agentaccess'] !== 0) { + db_process_sql_update('tconfig', ['value' => 0], ['token' => 'agentaccess']); + $this->notify( + [ + 'type' => 'NOTIF.ACCESSSTASTICS.PERFORMANCE', + 'title' => __('Access statistics performance'), + 'message' => __( + 'Usage of agent access statistics IS NOT RECOMMENDED on systems with more than 200 agents due performance penalty' + ), + 'url' => '__url__/index.php?sec=general&sec2=godmode/setup/setup§ion=perf', + ] + ); + } } else { $this->cleanNotifications('NOTIF.ACCESSSTASTICS.PERFORMANCE'); } @@ -1806,7 +1809,8 @@ class ConsoleSupervisor $this->cleanNotifications('NOTIF.PHP.SERIALIZE_PRECISION'); } - if (version_compare('8.1', PHP_VERSION) >= 0) { + // If PHP_VERSION is lower than 8.0.27 version_compare() returns 1. + if (version_compare('8.0.27', PHP_VERSION) === 1) { $url = 'https://www.php.net/supported-versions.php'; $this->notify( [ @@ -2378,7 +2382,8 @@ class ConsoleSupervisor 'SELECT count(*) FROM tusuario WHERE id_user="admin" - AND password="1da7ee7d45b96d0e1f45ee4ee23da560" + AND (password="1da7ee7d45b96d0e1f45ee4ee23da560" OR + password="$2y$10$Wv/xoxjI2VAkthJhk/PzeeGIhBKYU/K.TMgUdmW7fEP2NQkdWlB9K") AND is_admin=1 and disabled!=1' ); diff --git a/pandora_console/include/class/CredentialStore.class.php b/pandora_console/include/class/CredentialStore.class.php index b82a129cd1..94036c7ad8 100644 --- a/pandora_console/include/class/CredentialStore.class.php +++ b/pandora_console/include/class/CredentialStore.class.php @@ -827,7 +827,7 @@ class CredentialStore extends Wizard [ 'id' => $this->tableId, 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => $this->ajaxController, @@ -1112,7 +1112,6 @@ class CredentialStore extends Wizard 'script' => 'showVersion()', 'fields' => [ '1' => __('1'), - '2' => __('2'), '2c' => __('2c'), '3' => __('3'), ], diff --git a/pandora_console/include/class/Diagnostics.class.php b/pandora_console/include/class/Diagnostics.class.php index 7483cbca30..2c00a6b328 100644 --- a/pandora_console/include/class/Diagnostics.class.php +++ b/pandora_console/include/class/Diagnostics.class.php @@ -1579,7 +1579,7 @@ class Diagnostics extends Wizard [ 'id' => $tableId, 'class' => 'info_table caption_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $columnNames, 'ajax_data' => [ @@ -1591,6 +1591,7 @@ class Diagnostics extends Wizard 'no_sortable_columns' => [-1], 'caption' => $title, 'print' => true, + 'mini_csv' => true, ] ); } else { diff --git a/pandora_console/include/class/EventSound.class.php b/pandora_console/include/class/EventSound.class.php index e485ac4dfb..5658b44324 100644 --- a/pandora_console/include/class/EventSound.class.php +++ b/pandora_console/include/class/EventSound.class.php @@ -320,7 +320,7 @@ class EventSound extends HTML [ 'id' => $this->tableId, 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => $this->ajaxController, diff --git a/pandora_console/include/class/ExtensionsDiscovery.class.php b/pandora_console/include/class/ExtensionsDiscovery.class.php new file mode 100644 index 0000000000..da26fb1780 --- /dev/null +++ b/pandora_console/include/class/ExtensionsDiscovery.class.php @@ -0,0 +1,2555 @@ +section = $_section; + $this->mode = $_mode; + $this->url = 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz='.$_section; + $this->loadConfig(); + } + + + /** + * Load config from extension. + * + * @return void + */ + private function loadConfig() + { + $row = db_get_row('tdiscovery_apps', 'short_name', $this->mode); + $this->id = $row['id_app']; + $this->name = $row['name']; + $this->description = $row['description']; + } + + + /** + * Return array extensions filtered by section + * + * @return array Extensions for + */ + public function loadExtensions() + { + global $config; + // Check access. + check_login(); + $extensions = []; + $rows = $this->getExtensionsApps(); + foreach ($rows as $key => $extension) { + $logo = $this->path.'/'.$extension['short_name'].'/'.$this->icon; + if (file_exists($config['homedir'].$logo) === false) { + $logo = $this->defaultLogo; + } + + $extensions[] = [ + 'icon' => $logo, + 'label' => $extension['name'], + 'url' => ui_get_full_url( + 'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz='.$this->section.'&mode='.$extension['short_name'] + ), + ]; + } + + return $extensions; + } + + + /** + * Return all extensions from apps section + * + * @return array extensions. + */ + public function getExtensionsApps() + { + return db_get_all_rows_filter('tdiscovery_apps', ['section' => $this->section]); + + } + + + /** + * Load the extension information from discovery_definition.ini. + * + * @return array Information ini file. + */ + public function loadIni() + { + global $config; + $iniFile = parse_ini_file($config['homedir'].$this->path.'/'.$this->mode.'/discovery_definition.ini', true, INI_SCANNER_TYPED); + + return $iniFile; + } + + + /** + * Return next page from config_steps. + * + * @return integer Return the number of next page. + */ + public function nextPage() + { + $pages = array_keys($this->iniFile['config_steps']['name']); + if ($this->currentPage === 0 || empty($this->currentPage) === true) { + return $pages[0]; + } + + foreach ($pages as $k => $page) { + if ($page === $this->currentPage) { + if (end($pages) === $this->currentPage) { + return $this->currentPage; + } else { + return $pages[($k + 1)]; + } + } + } + } + + + /** + * Draw the extension forms. + * + * @return boolean Return boolean if exist error. + */ + public function run() + { + ui_require_javascript_file('extensions_discovery'); + $_iniFile = $this->loadIni(); + if ($_iniFile === false) { + include 'general/noaccess.php'; + return false; + } + + $this->iniFile = $_iniFile; + if (empty($this->iniFile['config_steps']) === false) { + $this->lastPage = end(array_keys($this->iniFile['config_steps']['name'])); + } else { + $this->lastPage = 0; + } + + $this->currentPage = (int) get_parameter('page', '0'); + $this->idTask = get_parameter('id_task', ''); + $action = get_parameter('action', ''); + $isTheEnd = get_parameter('complete_button', ''); + + // Control parameters and errors. + $error = false; + + if ($action === 'task_definition_form') { + $error = $this->processTaskDefinition(); + } + + if ($action === 'process_macro') { + $error = $this->processCustomMacro(); + } + + $task = $this->getTask(); + + if ($task === false && $this->currentPage > 0) { + $error = __('Task not defined'); + } + + // Build breadcrum. + $breadcrum = [ + [ + 'link' => 'index.php?sec=gservers&sec2=godmode/servers/discovery', + 'label' => 'Discovery', + ], + ]; + + switch ($this->section) { + case 'app': + $breadcrum[] = [ + 'link' => $this->url, + 'label' => __('Application'), + ]; + break; + + case 'cloud': + $breadcrum[] = [ + 'link' => $this->url, + 'label' => __('Cloud'), + ]; + break; + + case 'custom': + $breadcrum[] = [ + 'link' => $this->url, + 'label' => __('Custom'), + ]; + break; + + default: + $breadcrum[] = [ + 'link' => $this->url, + 'label' => __('Custom'), + ]; + break; + } + + $parameters = ''; + if (empty($this->idTask) === false) { + $parameters .= '&id_task='.$this->idTask; + } + + $breadcrum[] = [ + 'link' => $this->url.'&mode='.$this->mode.$parameters, + 'label' => 'Task definition', + 'selected' => ((0 === (int) $this->currentPage) ? 1 : 0), + ]; + + foreach ($this->iniFile['config_steps']['name'] as $key => $step) { + $parameters = '&mode='.$this->mode.'&page='.$key; + if (empty($this->idTask) === false) { + $parameters .= '&id_task='.$this->idTask; + } + + $breadcrum[] = [ + 'link' => $this->url.$parameters, + 'label' => $step, + 'selected' => (($key === (int) $this->currentPage) ? 1 : 0), + ]; + } + + // Avoid to print header out of wizard. + $this->prepareBreadcrum($breadcrum); + + // Header. + ui_print_page_header( + $this->iniFile['discovery_extension_definition']['name'], + '', + false, + '', + true, + '', + false, + '', + GENERIC_SIZE_TEXT, + '', + $this->printHeader(true) + ); + + if ($error !== false) { + ui_print_error_message( + $error + ); + return; + } else if ($action !== '') { + ui_print_success_message(__('Operation realized')); + + if (empty($isTheEnd) === false) { + header('Location:'.$config['homeurl'].'index.php?sec=discovery&sec2=godmode/servers/discovery&wiz=tasklist'); + } + } + + $_url = ui_get_full_url( + sprintf( + $this->url.'&mode=%s&page=%s%s', + $this->mode, + $this->nextPage(), + (empty($this->idTask) === false) ? '&id_task='.$this->idTask : '', + ) + ); + + $table = new StdClass(); + $table->id = 'form_editor'; + $table->width = '100%'; + $table->class = 'databox filter-table-adv max_floating_element_size'; + + $table->style = []; + $table->style[0] = 'width: 50%'; + $table->style[1] = 'width: 50%'; + $table->data = []; + if ($this->currentPage === 0) { + // If page is 0 then create form for task definition. + $table->data = $this->viewTaskDefinition(); + } else { + // If page is bigger than 0 then render form .ini. + $table->data = $this->viewMacroForm(); + } + + echo ''; + html_print_table($table); + + $actionButtons = ''; + + if ($this->currentPage !== $this->nextPage()) { + $actionButtons = html_print_submit_button( + __('Next'), + 'next_button', + false, + [ + 'class' => 'sub', + 'icon' => 'plus', + ], + true + ); + } + + $actionButtons .= html_print_submit_button( + __('Complete setup'), + 'complete_button', + false, + [ + 'class' => 'sub', + 'icon' => 'update', + 'value' => '1', + ], + true + ); + + html_print_action_buttons($actionButtons); + echo ''; + + } + + + /** + * Draw a select with the pandora data + * + * @param string $selectData Type of select. + * @param string $name Name of select. + * @param string $defaultValue Default value. + * @param boolean $multiple Define if the select is multiple. + * @param boolean $required Define if field is required. + * + * @return string Return the html select. + */ + private function drawSelectPandora($selectData, $name, $defaultValue, $multiple=false, $required=false) + { + if ($multiple === true && $selectData !== 'interval') { + $name .= '[]'; + $defaultValue = json_decode($defaultValue); + } else { + $defaultValue = io_safe_input($defaultValue); + } + + switch ($selectData) { + case 'agent_groups': + $input = html_print_select_groups( + false, + 'AR', + true, + $name, + $defaultValue, + '', + '', + '', + true, + $multiple, + false, + '', + false, + false, + false, + false, + 'id_grupo', + true, + false, + false, + false, + false, + $required + ); + break; + + case 'agents': + $input = html_print_select_from_sql( + 'SELECT nombre, alias as n FROM tagente', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%;', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'module_groups': + $input = html_print_select_from_sql( + 'SELECT id_mg, name + FROM tmodule_group ORDER BY name', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'modules': + $input = html_print_select_from_sql( + 'select nombre, nombre as n from tagente_modulo', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'module_types': + $input = html_print_select_from_sql( + 'select nombre, descripcion from ttipo_modulo', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'status': + $module_status_arr = []; + // Default. + $module_status_arr[AGENT_MODULE_STATUS_NORMAL] = __('Normal'); + $module_status_arr[AGENT_MODULE_STATUS_WARNING] = __('Warning'); + $module_status_arr[AGENT_MODULE_STATUS_CRITICAL_BAD] = __('Critical'); + $module_status_arr[AGENT_MODULE_STATUS_UNKNOWN] = __('Unknown'); + $module_status_arr[AGENT_MODULE_STATUS_NOT_INIT] = __('Not init'); + $input = html_print_select( + $module_status_arr, + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + '', + false, + 'width:100%', + false, + false, + false, + '', + false, + false, + $required, + false, + true, + true + ); + break; + + case 'alert_templates': + $input = html_print_select_from_sql( + 'select id, name from talert_templates', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'alert_actions': + $input = html_print_select_from_sql( + 'select id, name from talert_actions', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'interval': + $input = html_print_extended_select_for_time( + $name, + (string) $defaultValue, + '', + '', + '0', + false, + true + ); + break; + + case 'tags': + $input = html_print_select_from_sql( + 'select id_tag, name from ttag', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'credentials.custom': + $input = html_print_select_from_sql( + 'select identifier, identifier as i from tcredential_store WHERE product = "custom"', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'credentials.aws': + $input = html_print_select_from_sql( + 'select identifier, identifier as i from tcredential_store WHERE product = "AWS"', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'credentials.azure': + $input = html_print_select_from_sql( + 'select identifier, identifier as i from tcredential_store WHERE product = "AZURE"', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'credentials.sap': + $input = html_print_select_from_sql( + 'select identifier, identifier as i from tcredential_store WHERE product = "SAP"', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'credentials.snmp': + $input = html_print_select_from_sql( + 'select identifier, identifier as i from tcredential_store WHERE product = "SNMP"', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'credentials.gcp': + $input = html_print_select_from_sql( + 'select identifier, identifier as i from tcredential_store WHERE product = "GOOGLE"', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'credentials.wmi': + $input = html_print_select_from_sql( + 'select identifier, identifier as i from tcredential_store WHERE product = "WMI"', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + case 'os': + $input = html_print_select_from_sql( + 'SELECT id_os, name FROM tconfig_os ORDER BY name', + $name, + $defaultValue, + '', + ($multiple === false) ? __('None selected') : '', + '', + true, + $multiple, + true, + false, + 'width: 100%', + false, + GENERIC_SIZE_TEXT, + '', + $required + ); + break; + + default: + $input = html_print_select( + [], + $name, + $defaultValue, + '', + '', + 0, + true + ); + break; + } + + return $input; + } + + + /** + * Draw input from parameters of .ini. + * + * @param array $parameters Configuration of input. + * @param boolean $implicit Indicates if all the configuration is indicated in the array. + * + * @return string Html from input. + */ + public function drawInput($parameters, $implicit=false) + { + $input = ''; + $defaultValue = $this->macrosValues[$parameters['macro']]; + switch ($parameters['type']) { + case 'string': + $input = html_print_input_text( + $parameters['macro'], + $defaultValue, + '', + 50, + 255, + true, + false, + ($parameters['mandatory_field'] === false) ? false : true + ); + break; + + case 'number': + $config = [ + 'type' => 'number', + 'name' => $parameters['macro'], + 'value' => $defaultValue, + 'return' => true, + ]; + if ($parameters['mandatory_field'] !== false) { + $config['required'] = true; + } + + $input = html_print_input($config); + break; + + case 'password': + $isEncrypted = (bool) $this->macrosValues[$parameters['encrypt_on_true']]; + if ($isEncrypted === true) { + $defaultValueEncrypted = $this->encryptPassword($defaultValue, true); + if (empty($defaultValueEncrypted) === false) { + $defaultValue = $defaultValueEncrypted; + } + } + + $input = html_print_input_password( + $parameters['macro'], + $defaultValue, + '', + 50, + 255, + true, + false, + ($parameters['mandatory_field'] === false) ? false : true, + '', + 'on' + ); + if (empty($parameters['encrypt_on_true']) === false) { + $input .= html_print_input_hidden( + $parameters['macro'].'_encrypt', + $parameters['encrypt_on_true'], + true + ); + } + break; + + case 'checkbox': + $input = html_print_checkbox_switch( + $parameters['macro'], + 1, + (bool) $defaultValue, + true + ); + break; + + case 'textarea': + $input = html_print_textarea( + $parameters['macro'], + 5, + 20, + $defaultValue, + ($parameters['mandatory_field'] === false) ? '' : 'required="required"', + true + ); + break; + + case 'select': + if (in_array($parameters['select_data'], $this->pandoraSelectData) === true) { + $input = $this->drawSelectPandora( + $parameters['select_data'], + $parameters['macro'], + $defaultValue, + false, + ($parameters['mandatory_field'] === false) ? false : true, + ); + $parameters['type'] = $parameters['select_data']; + } else { + if ($implicit === false) { + $options = $this->iniFile[$parameters['select_data']]['option']; + } else { + $options = $parameters['select_data']; + } + + $input = html_print_select( + $options, + $parameters['macro'], + $defaultValue, + '', + __('None selected'), + '', + true, + false, + true, + '', + false, + 'width: 100%;', + false, + false, + false, + '', + false, + false, + ($parameters['mandatory_field'] === false) ? false : true, + ); + } + break; + + case 'multiselect': + if (in_array($parameters['select_data'], $this->pandoraSelectData) === true) { + $input = $this->drawSelectPandora( + $parameters['select_data'], + $parameters['macro'], + $defaultValue, + true, + ); + $parameters['type'] = $parameters['select_data']; + } else { + if ($implicit === false) { + $options = $this->iniFile[$parameters['select_data']]['option']; + } else { + $options = $parameters['select_data']; + } + + $input = html_print_select( + $options, + $parameters['macro'].'[]', + json_decode($defaultValue, true), + '', + '', + 0, + true, + true, + true, + '', + false, + 'width: 100%', + false, + false, + false, + '', + false, + false, + false, + false, + true, + true + ); + } + break; + + case 'tree': + // Show bucket tree explorer. + ui_require_javascript_file('pandora_snmp_browser'); + if ($implicit === false) { + $treeData = $this->iniFile[$parameters['tree_data']]; + $treeInfo = $this->getTreeStructure($parameters, $treeData); + } else { + $treeData = $parameters['tree_data']; + $treeInfo = $this->getTreeStructureByScript($parameters, $treeData); + } + + $input = ui_print_tree( + $treeInfo, + // Id. + 0, + // Depth. + 0, + // Last. + 0, + // Last_array. + [], + // Sufix. + true, + // Return. + true, + // Descriptive ids. + false + ); + break; + + default: + $input = html_print_input_text( + $parameters['macro'], + $defaultValue, + '', + 50, + 255, + true, + false, + ($parameters['mandatory_field'] === false) ? false : true + ); + break; + } + + $input .= html_print_input_hidden( + $parameters['macro'].'type', + $parameters['type'], + true + ); + $class = ''; + if ($parameters['show_on_true'] !== null) { + $class = $parameters['macro'].'_hide'; + $input .= $this->showOnTrue($parameters['show_on_true'], $class); + } + + $name = $parameters['name']; + if (empty($parameters['tip']) === false) { + $name .= ui_print_help_tip($parameters['tip'], true); + } + + return html_print_label_input_block( + $name, + $input, + ['div_class' => $class] + ); + } + + + /** + * Return the task app from database. + * + * @return array $task Task of database. + */ + private function getTask() + { + return db_get_row_filter( + 'trecon_task', + [ + 'id_app' => $this->id, + 'id_rt' => $this->idTask, + 'type' => 15, + ], + ); + } + + + /** + * Returns the value of the macro. + * + * @param string $macro Name of macro for filter. + * + * @return mixed Value of the macro. + */ + private function getValueMacro($macro) + { + return db_get_value_filter( + 'value', + 'tdiscovery_apps_tasks_macros', + [ + 'id_task' => $this->idTask, + 'macro' => $macro, + ] + ); + } + + + /** + * Return form for macro form. + * + * @return array $form Form macro. + */ + private function viewMacroForm() + { + $data = []; + + $macros = db_get_all_rows_filter( + 'tdiscovery_apps_tasks_macros', + ['id_task' => $this->idTask], + ['*'] + ); + if ($macros !== false) { + foreach ($macros as $key => $macro) { + $this->macrosValues[$macro['macro']] = io_safe_output($macro['value']); + } + } + + // Process ini or script. + $customFields = $this->iniFile['config_steps']['custom_fields'][$this->currentPage]; + $customFieldsByScript = $this->getStructureFormByScript($this->iniFile['config_steps']['script_data_fields'][$this->currentPage]); + + if ($customFields === null && $customFieldsByScript === null) { + $data[0][0] = html_print_image( + 'images/no_data_toshow.png', + true, + ['class' => 'w200px'] + ); + $data[1][0] = html_print_input_hidden( + 'action', + 'process_macro', + true + ); + return $data; + } + + $columns = 2; + if ($this->iniFile['config_steps']['fields_columns'][$this->currentPage] !== null + && $this->iniFile['config_steps']['fields_columns'][$this->currentPage] === 1 + ) { + $columns = 1; + } + + $row = 0; + $col = 0; + foreach ($customFieldsByScript as $key => $value) { + $this->nameFields[] = $value['macro']; + $data[$row][$col] = $this->drawInput($value, true); + $col++; + if ($col == $columns) { + $row++; + $col = 0; + } + } + + foreach ($this->iniFile[$customFields]['macro'] as $key => $id) { + $parameters = [ + 'macro' => $id, + 'name' => $this->iniFile[$customFields]['name'][$key], + 'tip' => $this->iniFile[$customFields]['tip'][$key], + 'type' => $this->iniFile[$customFields]['type'][$key], + 'placeholder' => $this->iniFile[$customFields]['placeholder'][$key], + 'mandatory_field' => $this->iniFile[$customFields]['mandatory_field'][$key], + 'show_on_true' => $this->iniFile[$customFields]['show_on_true'][$key], + 'encrypt_on_true' => $this->iniFile[$customFields]['encrypt_on_true'][$key], + 'select_data' => $this->iniFile[$customFields]['select_data'][$key], + 'tree_data' => $this->iniFile[$customFields]['tree_data'][$key], + ]; + $this->nameFields[] = $id; + $data[$row][$col] = $this->drawInput($parameters); + $col++; + if ($col == $columns) { + $row++; + $col = 0; + } + } + + $data[($row + 1)][1] = html_print_input_hidden( + 'action', + 'process_macro', + true + ); + $data[($row + 1)][1] .= html_print_input_hidden( + 'name_fields', + implode(',', $this->nameFields), + true + ); + + return $data; + } + + + /** + * Return form for task definition. + * + * @return array $form Form for task definition. + */ + private function viewTaskDefinition() + { + $task = $this->getTask(); + + $data = []; + $data[0][0] = html_print_label_input_block( + __('Task name'), + html_print_input_text( + 'task_name', + $task['name'], + '', + 50, + 255, + true, + false, + true + ) + ); + + $data[1][0] = html_print_label_input_block( + __('Description'), + html_print_textarea( + 'description', + 5, + 20, + $task['description'], + '', + true + ) + ); + + $data[2][0] = html_print_label_input_block( + __('Discovery server'), + html_print_select_from_sql( + sprintf( + 'SELECT id_server, name + FROM tserver + WHERE server_type = %d + ORDER BY name', + SERVER_TYPE_DISCOVERY + ), + 'discovery_server', + $task['id_recon_server'], + '', + '', + '0', + true, + false, + true, + false, + false, + false, + GENERIC_SIZE_TEXT, + '', + false + ) + ); + + $data[3][0] = html_print_label_input_block( + __('Group'), + html_print_select_groups( + false, + 'AR', + false, + 'group', + $task['id_group'], + '', + '', + 0, + true, + false, + false, + '', + false, + false, + false, + false, + 'id_grupo', + false, + false, + false, + false, + false, + true + ) + ); + + $inputs_interval = html_print_select( + [ + 'defined' => 'Defined', + 'manual' => 'Manual', + ], + 'mode_interval', + ($task['interval_sweep'] === '0') ? 'manual' : 'defined', + 'changeModeInterval(this)', + '', + '0', + true, + false, + true, + '', + false + ).html_print_extended_select_for_time( + 'interval', + (empty($task['interval_sweep']) === true) ? '300' : $task['interval_sweep'], + '', + '', + '0', + false, + true, + false, + true, + ); + $js_variables = ''; + $data[4][0] = html_print_label_input_block( + __('Interval'), + html_print_div( + [ + 'style' => 'display: flex;max-width: 345px; justify-content: space-between;', + 'content' => $inputs_interval.$js_variables, + ], + true + ) + ); + + $data[5][0] = html_print_label_input_block( + __('Timeout').ui_print_help_tip('This timeout will be applied for each task execution', true), + html_print_extended_select_for_time( + 'tiemout', + (empty($task['executions_timeout']) === true) ? '60' : $task['executions_timeout'], + '', + '', + '0', + false, + true + ), + ); + + $data[6][0] = html_print_input_hidden( + 'action', + 'task_definition_form', + true + ); + + $data[7][0] = html_print_input_hidden( + 'id_task', + $task['id_rt'], + true + ); + + return $data; + } + + + /** + * Sabe data from task definition form. + * + * @return string $error Error string if exist. + */ + private function processTaskDefinition() + { + $taskName = get_parameter('task_name', ''); + $description = get_parameter('description', ''); + $discoveryServer = get_parameter('discovery_server', ''); + $group = get_parameter('group', 0); + $mode_interval = get_parameter('mode_interval', 'defined'); + $interval = get_parameter('interval', ''); + $tiemout = get_parameter('tiemout', 60); + $completeTask = get_parameter('complete_button', ''); + + if ($mode_interval === 'manual') { + $interval = '0'; + } + + $error = false; + + if ($taskName === '' + || $discoveryServer === '' + || $group === '' + || $interval === '' + ) { + $error = __('Fields empties'); + return $error; + } + + if ($this->idTask === '') { + db_process_sql_begin(); + try { + $_idTask = db_process_sql_insert( + 'trecon_task', + [ + 'id_app' => $this->id, + 'name' => $taskName, + 'description' => $description, + 'id_group' => $group, + 'interval_sweep' => $interval, + 'id_recon_server' => $discoveryServer, + 'type' => 15, + 'setup_complete' => (empty($completeTask) === false) ? 1 : 0, + 'executions_timeout' => $tiemout, + ] + ); + + if ($_idTask === false) { + $error = __('Error creating the discovery task'); + } else { + $this->idTask = $_idTask; + $this->autoLoadConfigMacro(); + } + } catch (Exception $e) { + $error = __('Error creating the discovery task'); + } + + if ($error === false) { + db_process_sql_commit(); + } else { + db_process_sql_rollback(); + } + } else { + $result = db_process_sql_update( + 'trecon_task', + [ + 'id_app' => $this->id, + 'name' => $taskName, + 'description' => $description, + 'id_group' => $group, + 'interval_sweep' => $interval, + 'id_recon_server' => $discoveryServer, + 'type' => 15, + 'setup_complete' => (empty($completeTask) === false) ? 1 : 0, + 'executions_timeout' => $tiemout, + ], + ['id_rt' => $this->idTask] + ); + + if ($result === false) { + $error = __('Error updating the discovery task'); + } + } + + return $error; + } + + + /** + * Process the values of input from macro defined in .ini + * + * @return string $error Error string if exist. + */ + private function processCustomMacro() + { + $error = false; + + $keyParameters = explode(',', get_parameter('name_fields', '')); + + foreach ($keyParameters as $v => $key) { + $type = get_parameter($key.'type', ''); + switch ($type) { + case 'checkbox': + $value = get_parameter_switch($key, 0); + break; + + case 'multiselect': + $value = io_safe_input(json_encode(get_parameter($key, ''))); + break; + + case 'password': + $value = get_parameter($key, ''); + $encryptKey = get_parameter($key.'_encrypt', ''); + if ($encryptKey !== '') { + $encrypt = (bool) get_parameter_switch($encryptKey, 0); + if ($encrypt === true) { + $valueEncrypt = $this->encryptPassword($value); + if (empty($valueEncrypt) === false) { + $value = $valueEncrypt; + } + } + } + break; + + default: + $value = get_parameter($key, ''); + break; + } + + if (is_array($value) === true) { + $value = io_safe_input(json_encode($value)); + } + + $exist = db_get_row_filter( + 'tdiscovery_apps_tasks_macros', + [ + 'id_task' => $this->idTask, + 'macro' => $key, + ] + ); + + if (in_array($type, $this->pandoraSelectData) === false) { + $type = 'custom'; + } + + if ($exist === false) { + $result = db_process_sql_insert( + 'tdiscovery_apps_tasks_macros', + [ + 'id_task' => $this->idTask, + 'macro' => $key, + 'value' => $value, + 'type' => $type, + ] + ); + if ($result === false) { + $error = __('Field %s not insert', $key); + } + } else { + $result = db_process_sql_update( + 'tdiscovery_apps_tasks_macros', + [ + 'value' => $value, + 'type' => $type, + ], + [ + 'id_task' => $this->idTask, + 'macro' => $key, + ] + ); + if ($result === false) { + $error = __('Field %s not updated', $key); + } + } + } + + $completeTask = get_parameter('complete_button', ''); + if (empty($completeTask) === false) { + $result = db_process_sql_update( + 'trecon_task', + ['setup_complete' => 1], + ['id_rt' => $this->idTask] + ); + if ($result === false) { + $error = __('Task not updated'); + } + } + + return $error; + } + + + /** + * Check if name of input macro is correct. + * + * @param string $name Name of input. + * + * @return boolean value true if name is correct. + */ + private function isCorrectNameInput($name) + { + if (substr($name, 0, 1) === '_' && substr($name, -1) === '_') { + return true; + } else { + return false; + } + } + + + /** + * Return logic for component show on true. + * + * @param string $checkbox Name the checkbox for hide input. + * @param string $elementToHide Name the element to hide HIS PARENT. + * + * @return string String Name the element + */ + private function showOnTrue($checkbox, $elementToHide) + { + return ''; + } + + + /** + * Load the macros task in database + * + * @throws Exception Excepcion to control possible error for default value. + * + * @return void + */ + private function autoLoadConfigMacro() + { + $defaultValues = $this->iniFile['discovery_extension_definition']['default_value']; + + foreach ($defaultValues as $key => $value) { + if ($value === false) { + $value = 0; + } + + $result = db_process_sql_insert( + 'tdiscovery_apps_tasks_macros', + [ + 'id_task' => $this->idTask, + 'macro' => $key, + 'value' => (string) io_safe_input($value), + 'type' => 'custom', + ] + ); + if ($result === false) { + throw new Exception('Error creating task'); + } + } + + $tempFiles = $this->iniFile['tempfile_confs']['file']; + + foreach ($tempFiles as $key => $value) { + $result = db_process_sql_insert( + 'tdiscovery_apps_tasks_macros', + [ + 'id_task' => $this->idTask, + 'macro' => $key, + 'value' => (string) io_safe_input($value), + 'type' => 'custom', + 'temp_conf' => 1, + ] + ); + if ($result === false) { + throw new Exception('Error creating task'); + } + } + } + + + /** + * Return array structure for draw tree when array is by .ini. + * + * @param array $parent Parent from the tree. + * @param array $firstChildren First children from parent. + * + * @return array $treeInfo Return the array with format for render treee + */ + private function getTreeStructure($parent, $firstChildren) + { + $treeInfo = []; + foreach ($firstChildren['name'] as $key => $value) { + $checked = false; + $name = (empty($firstChildren['macro'][$key]) === false) ? $firstChildren['macro'][$key].'[]' : $parent['id'].'[]'; + $nameField = (empty($firstChildren['macro'][$key]) === false) ? $firstChildren['macro'][$key] : $parent['id']; + if (in_array($nameField, $this->nameFields) === false) { + $this->nameFields[] = $nameField; + } + + $checkedValues = json_decode(io_safe_output($this->macrosValues[$nameField]), true); + if (empty($checkedValues) === false) { + if (in_array($firstChildren['value'][$key], $checkedValues)) { + $checked = true; + } + } + + $treeInfo['__LEAVES__'][$key] = [ + 'label' => $value, + 'selectable' => (bool) $firstChildren['selectable'][$key], + 'name' => $name, + 'value' => $firstChildren['value'][$key], + 'checked' => $checked, + ]; + + if (empty($firstChildren['children'][$key]) === false) { + $children = $this->iniFile[$firstChildren['children'][$key]]; + $treeInfo['__LEAVES__'][$key]['sublevel'] = $this->getTreeStructure($parent, $children); + } + } + + return $treeInfo; + } + + + /** + * Return array structure for draw tree when array is by script. + * + * @param array $parent Parent from the tree. + * @param array $firstChildren First children from parent. + * + * @return array $treeInfo Return the array with format for render treee + */ + private function getTreeStructureByScript($parent, $firstChildren) + { + $treeInfo = []; + foreach ($firstChildren as $key => $value) { + $checked = false; + $name = (empty($value['macro']) === false) ? $value['macro'].'[]' : $parent['macro'].'[]'; + $nameField = (empty($value['macro']) === false) ? $value['macro'] : $parent['macro']; + if (in_array($nameField, $this->nameFields) === false) { + $this->nameFields[] = $nameField; + } + + $checkedValues = json_decode(io_safe_output($this->macrosValues[$nameField]), true); + if (empty($checkedValues) === false) { + if (in_array($value['value'], $checkedValues, true) === true) { + $checked = true; + } + } + + $treeInfo['__LEAVES__'][$key] = [ + 'label' => $value['name'], + 'selectable' => (bool) $value['selectable'], + 'name' => $name, + 'value' => $value['value'], + 'checked' => $checked, + ]; + + if (empty($value['children']) === false) { + $children = $value['children']; + $treeInfo['__LEAVES__'][$key]['sublevel'] = $this->getTreeStructureByScript($parent, $children); + } + } + + return $treeInfo; + } + + + /** + * Return a json with the form structure for draw. + * + * @param mixed $command String. + * + * @return array Result of command. + */ + private function getStructureFormByScript($command) + { + global $config; + $executionFiles = $this->iniFile['discovery_extension_definition']['execution_file']; + foreach ($executionFiles as $key => $file) { + $file = $config['homedir'].$this->path.'/'.$this->mode.'/'.$file; + $command = str_replace($key, $file, $command); + } + + $values = $this->replaceValues($command); + $command = $values['command']; + $toDelete = $values['delete']; + if (empty($command) === false) { + $result = $this->executeCommand($command); + } + + if (count($toDelete) > 0) { + foreach ($toDelete as $key => $folder) { + Files::rmrf($folder); + } + } + + return json_decode($result, true); + } + + + /** + * Replace values in command + * + * @param string $command String command for replace macros. + * + * @return array $values Command and files to delete. + */ + private function replaceValues($command) + { + preg_match_all('/\b_[a-zA-Z0-9]*_\b/', $command, $matches); + $foldersToDelete = []; + foreach ($matches[0] as $key => $macro) { + $row = db_get_row_filter( + 'tdiscovery_apps_tasks_macros', + [ + 'macro' => $macro, + 'id_task' => $this->idTask, + ] + ); + if ($row !== false) { + if (in_array($row['type'], $this->pandoraSelectData) === true) { + $value = $this->getValuePandoraSelect($row['type'], $row['value']); + $command = str_replace($macro, $value, $command); + } else if ((int) $row['temp_conf'] === 1) { + $nameFile = $row['id_task'].'_'.$row['id_task'].'_'.uniqid(); + $value = $this->getValueTempFile($nameFile, $row['value']); + $command = str_replace($macro, $value, $command); + $foldersToDelete[] = str_replace($nameFile, '', $value); + } else { + $command = str_replace($macro, io_safe_output($row['value']), $command); + } + } + } + + return [ + 'command' => $command, + 'delete' => $foldersToDelete, + ]; + } + + + /** + * Create a temp file for tempfile_confs macros. + * + * @param string $nameFile Name file only. + * @param string $content Content to save to file. + * + * @return string $pathNameFile Name file and with path for replace. + */ + private function getValueTempFile($nameFile, $content) + { + global $config; + $content = io_safe_output($content); + $content = $this->replaceValues($content)['command']; + $nameTempDir = $config['attachment_store'].'/temp_files/'; + if (file_exists($nameTempDir) === false) { + mkdir($nameTempDir); + } + + $tmpPath = Files::tempdirnam( + $nameTempDir, + 'temp_files_' + ); + $pathNameFile = $tmpPath.'/'.$nameFile; + file_put_contents($pathNameFile, $content); + + return $pathNameFile; + } + + + /** + * Return the correct value for pandora select + * + * @param string $type Type of input. + * @param string $id Value of the row macro. + * + * @return string $id New id with the values replaced + */ + private function getValuePandoraSelect($type, $id) + { + $id = io_safe_output($id); + $idsArray = json_decode($id); + if (is_array($idsArray) === false) { + $idsArray = [$id]; + } + + foreach ($idsArray as $key => $v) { + $value = false; + switch ($type) { + case 'agent_groups': + $value = groups_get_name($v); + break; + + case 'module_groups': + $value = modules_get_modulegroup_name($v); + break; + + case 'tags': + $value = tags_get_name($v); + break; + + case 'alert_templates': + $value = alerts_get_alert_template_name($v); + break; + + case 'alert_actions': + $value = alerts_get_alert_action_name($v); + break; + + case 'credentials.custom': + $credentials = CredentialStore::getKey($v); + $value = base64_encode( + json_encode( + [ + 'user' => $credentials['username'], + 'password' => $credentials['password'], + ] + ) + ); + break; + + case 'credentials.aws': + $credentials = CredentialStore::getKey($v); + $value = base64_encode( + json_encode( + [ + 'access_key_id' => $credentials['username'], + 'secret_access_key' => $credentials['password'], + ] + ) + ); + break; + + case 'credentials.azure': + $credentials = CredentialStore::getKey($v); + $value = base64_encode( + json_encode( + [ + 'client_id' => $credentials['username'], + 'application_secret' => $credentials['password'], + 'tenant_domain' => $credentials['extra_1'], + 'subscription_id' => $credentials['extra_2'], + ] + ) + ); + break; + + case 'credentials.gcp': + $credentials = CredentialStore::getKey($v); + $value = base64_encode($credentials['extra_1']); + break; + + case 'credentials.sap': + $credentials = CredentialStore::getKey($v); + $value = base64_encode( + json_encode( + [ + 'user' => $credentials['username'], + 'password' => $credentials['password'], + ] + ) + ); + break; + + case 'credentials.snmp': + $credentials = CredentialStore::getKey($v); + $value = base64_encode($credentials['extra_1']); + break; + + case 'credentials.wmi': + $credentials = CredentialStore::getKey($v); + $value = base64_encode( + json_encode( + [ + 'user' => $credentials['username'], + 'password' => $credentials['password'], + 'namespace' => $credentials['extra_1'], + ] + ) + ); + break; + + case 'os': + $value = get_os_name($v); + break; + + default: + continue; + } + + if ($value !== false) { + $id = str_replace($v, io_safe_output($value), $id); + } + } + + return $id; + } + + + /** + * Encrypt and decode password with the user script. + * + * @param string $password Password to encrypt. + * @param boolean $decode True for decode password. + * + * @return string Password encrypted + */ + private function encryptPassword($password, $decode=false) + { + global $config; + if ($decode === false) { + $command = $this->iniFile['discovery_extension_definition']['passencrypt_exec']; + $nameFile = $this->iniFile['discovery_extension_definition']['passencrypt_script']; + $file = $config['homedir'].$this->path.'/'.$this->mode.'/'.$nameFile; + $command = str_replace('_passencrypt_script_', $file, $command); + } else { + $command = $this->iniFile['discovery_extension_definition']['passdecrypt_exec']; + $nameFile = $this->iniFile['discovery_extension_definition']['passdecrypt_script']; + $file = $config['homedir'].$this->path.'/'.$this->mode.'/'.$nameFile; + $command = str_replace('_passdecrypt_script_', $file, $command); + } + + $command = str_replace('_password_', $password, $command); + + if (empty($command) === false) { + return $this->executeCommand($command); + } else { + return false; + } + } + + + /** + * Valid the .ini + * + * @param array $iniForValidate IniFile to validate. + * + * @return mixed Return false if is ok and string for error. + */ + public static function validateIni($iniForValidate) + { + $discoveryExtension = $iniForValidate['discovery_extension_definition']; + + if (!$discoveryExtension) { + return __('The file does not contain the block \'discovery_extension_definition\''); + } + + if (!array_key_exists('short_name', $discoveryExtension)) { + return __('The \'discovery_extension_definition\' block must contain a \'short_name\' parameter'); + } + + $defaultValues = $discoveryExtension['default_value']; + foreach ($defaultValues as $key => $value) { + if (!preg_match('/^_[a-zA-Z0-9]+_$/', $key)) { + return __( + 'The \'discovery_extension_definition\' block \'default_value\' parameter has a key with invalid format. Use only letters (A-Z and a-z) and numbers (0-9) between opening and ending underscores (_): \'%s\'', + $key + ); + } + } + + $shortName = $discoveryExtension['short_name']; + + if (!preg_match('/^[A-Za-z0-9._-]+$/', $shortName)) { + return __('The \'discovery_extension_definition\' block \'short_name\' parameter contains illegal characters. Use only letters (A-Z and a-z), numbers (0-9), points (.), hyphens (-) and underscores (_)'); + } + + if (!array_key_exists('section', $discoveryExtension) || !array_key_exists('name', $discoveryExtension)) { + return __('The \'discovery_extension_definition\' block must contain a \'section\' and a \'name\' parameters'); + } + + $section = $discoveryExtension['section']; + $name = $discoveryExtension['name']; + + if (!in_array($section, ['app', 'cloud', 'custom'])) { + return __('The \'discovery_extension_definition\' block \'section\' parameter must be \'app\', \'cloud\' or \'custom\''); + } + + if (empty($name)) { + return __('The \'discovery_extension_definition\' block \'name\' parameter can not be empty'); + } + + if (!array_key_exists('exec', $discoveryExtension)) { + return __('The \'discovery_extension_definition\' block must contain an \'exec\' parameter'); + } + + $execs = $discoveryExtension['exec']; + + foreach ($execs as $exec) { + if (empty($exec)) { + return __('All the \'discovery_extension_definition\' block \'exec\' parameter definitions can not be empty'); + } + } + + $checkEmptyFields = [ + 'passencrypt_script', + 'passencrypt_exec', + 'passdecrypt_script', + 'passdecrypt_exec', + ]; + + foreach ($checkEmptyFields as $key) { + if ($discoveryExtension[$key] !== null && empty($discoveryExtension[$key]) === true) { + return __('The \'discovery_extension_definition\' block \'%s\' parameter can not be empty', $key); + } + } + + foreach ($discoveryExtension['execution_file'] as $key => $value) { + if (!preg_match('/^_[a-zA-Z0-9]+_$/', $key)) { + return __('The \'discovery_extension_definition\' block \'execution_file\' parameter has a key with invalid format. Use only letters (A-Z and a-z) and numbers (0-9) between opening and ending underscores (_): \'%s\'', $key); + } + + if (empty($value) === true) { + return __('All the \'discovery_extension_definition\' block \'execution_file\' parameter definitions can not be empty: \'%s\'', $key); + } + } + + if ($iniForValidate['config_steps'] !== null && empty($iniForValidate['config_steps']) === true) { + return __('The \'config_steps\' block must contain a \'name\' parameter that can not be empty.'); + } + + foreach ($iniForValidate['config_steps'] as $key => $value) { + foreach ($value as $innerKey => $inner_value) { + if (isset($inner_steps[$innerKey])) { + $inner_steps[$innerKey][$key] = $inner_value; + } else { + $inner_steps[$innerKey] = [$key => $inner_value]; + } + } + } + + $customFields = []; + foreach ($inner_steps as $key => $step) { + if (is_numeric($key) === false || $key === 0) { + return __('All the \'config_steps\' block parameters must use numbers greater than 0 as keys: \'%s\'.', $key); + } + + if (empty($step['name']) === true) { + return __('The \'config_steps\' block must contain a \'name\' parameter for all the configuration steps: \'%s\'', $key); + } + + if (empty($step['custom_fields']) === true + && empty($step['script_data_fields']) === true + ) { + return __('The \'config_steps\' block must contain a \'custom_fields\' or \'script_data_fields\' parameter that can not be empty'); + } else if (empty($step['custom_fields']) === false) { + if (empty($iniForValidate[$step['custom_fields']]) === true) { + return __('The \'config_steps\' block \'custom_fields\' parameter has a key value reference that does not exist: \'%s\'', $step['custom_fields']); + } else { + $customFields[] = $step['custom_fields']; + } + } + + $customFields[] = $step['name']; + } + + $requiredKeys = [ + 'macro', + 'name', + 'type', + ]; + + $validTypes = [ + 'string', + 'number', + 'password', + 'textarea', + 'checkbox', + 'select', + 'multiselect', + 'tree', + ]; + + $validSelectData = [ + 'agent_groups', + 'agents', + 'module_groups', + 'modules', + 'module_types', + 'status', + 'alert_templates', + 'alert_actions', + 'interval', + 'tags', + 'credentials.custom', + 'credentials.aws', + 'credentials.azure', + 'credentials.sap', + 'credentials.snmp', + 'credentials.gcp', + 'credentials.wmi', + 'os', + ]; + + $selectDataNames = []; + $treeDataNames = []; + + foreach ($customFields as $key => $customField) { + $innerFields = []; + foreach ($iniForValidate[$customField] as $key => $value) { + foreach ($value as $innerKey => $innerValue) { + if (isset($innerFields[$innerKey])) { + $innerFields[$innerKey][$key] = $innerValue; + } else { + $innerFields[$innerKey] = [$key => $innerValue]; + } + } + } + + foreach ($innerFields as $key => $field) { + if (is_numeric($key) === false || $key === 0) { + return __('All the \'%s\' block parameters must use numbers greater than 0 as keys: \'%s\'.', $customField, $key); + } + + foreach ($requiredKeys as $k => $value) { + if (empty($field[$value]) === true) { + return __('The \'%s\' block \'%s\' parameter definitions can not be empty: \'%s\'.', $customField, $value, $key); + } + } + + if (!preg_match('/^_[a-zA-Z0-9]+_$/', $field['macro'])) { + return __('The \'%s\' block \'macro\' parameter has a definition with invalid format. Use only letters (A-Z and a-z) and numbers (0-9) between opening and ending underscores (_): \'%s\'', $customField, $field['macro']); + } + + if (in_array($field['type'], $validTypes) === false) { + return __('The \'%s\' block \'type\' parameter has a definition with invalid value. Must be \'string\', \'number\', \'password\', \'textarea\', \'checkbox\', \'select\', \'multiselect\' or \'tree\': \'%s\'', $customField, $field['type']); + } + + if ($field['type'] === 'select' || $field['type'] === 'multiselect') { + if (empty($field['select_data']) === true) { + return __('All the \'%s\' block \'select_data\' parameter definitions can not be empty: \'%s\'.', $customField, $key); + } else if ($iniForValidate[$field['select_data']] === null && in_array($field['select_data'], $validSelectData) === false) { + return __( + 'The \'%s\' block \'select_data\' parameter has a definition with invalid select type. Must be \'agent_groups\', \'agents\', \'module_groups\', \'modules\', \'module_types\', \'tags\', \'status\', \'alert_templates\', \'alert_actions\', \'interval\', \'credentials.custom\', \'credentials.aws\', \'credentials.azure\', \'credentials.gcp\', \'credentials.sap\', \'credentials.snmp\', \'os\' or an existint reference: \'%s\'', + $customField, + $field['select_data'] + ); + } else if ($iniForValidate[$field['select_data']] !== null) { + $selectDataNames[] = $field['select_data']; + } + } + + if ($field['type'] === 'tree') { + if (empty($field['tree_data']) === true) { + return __('All the \'%s\' block \'tree_data\' parameter definitions can not be empty: \'%s\'', $field['macro'], $key); + } else if ($iniForValidate[$field['tree_data']] === null) { + return __('The \'%s\' block \'tree_data\' parameter has a key value reference that does not exist: \'%s\'', $customField, $field['tree_data']); + } else { + $treeDataNames[] = $field['tree_data']; + } + } + + if (empty($field['mandatory_field']) === false) { + $validValues = [ + 'true', + 'false', + '1', + '0', + 'yes', + 'no', + ]; + + if (in_array($field['mandatory_field'], $validValues) === false) { + return __( + 'The \'%s\' block \'mandatory_field\' parameter has a definition with invalid value. Must be \'true\' or \'false\', \'1\' or \'0\', \'yes\' or \'no\': \'%s\'', + $customField, + $field['mandatory_field'] + ); + } + } + + if ($field['tip'] !== null && empty($field['tip']) === true) { + return __('All the \'%s\' block \'tip\' parameter definitions can not be empty: \'%s\'.', $customField, $key); + } + + if ($field['placeholder'] !== null && empty($field['placeholder']) === true) { + return __('All the \'%s\' block \'placeholder\' parameter definitions can not be empty: \'%s\'.', $customField, $key); + } + + if (empty($field['show_on_true']) === false) { + if (!preg_match('/^_[a-zA-Z0-9]+_$/', $field['show_on_true'])) { + return __( + 'The \'%s\' block \'show_on_true\' parameter has a definition with invalid format. Use only letters (A-Z and a-z) and numbers (0-9) between opening and ending underscores (_): \'%s\'', + $customField, + $field['show_on_true'] + ); + } + } + + if (empty($field['encrypt_on_true']) === false) { + if (!preg_match('/^_[a-zA-Z0-9]+_$/', $field['encrypt_on_true'])) { + return __( + 'The \'%s\' block \'encrypt_on_true\' parameter has a definition with invalid format. Use only letters (A-Z and a-z) and numbers (0-9) between opening and ending underscores (_): \'%s\'', + $customField, + $field['encrypt_on_true'] + ); + } + } + } + } + + foreach ($treeDataNames as $key => $name) { + $error = self::validateTreeRecursive($name, $iniForValidate); + if ($error !== false) { + return $error; + } + } + + foreach ($selectDataNames as $key => $name) { + if (empty($iniForValidate[$name]['option']) === true) { + return __('The \'%s\' block must contain an \'option\' parameter', $name); + } + + foreach ($iniForValidate[$name]['option'] as $key => $option) { + if (empty($option) === true) { + return __('All the \'%s\' block \'option\' parameter definitions can not be empty: \'%s\'.', $name, $key); + } + } + } + + if ($iniForValidate['tempfile_confs'] !== null && empty($iniForValidate['tempfile_confs']['file']) === true) { + return __('The \'tempfile_confs\' block must contain a \'file\' parameter.'); + } + + foreach ($iniForValidate['tempfile_confs']['file'] as $key => $tempfile) { + if (!preg_match('/^_[a-zA-Z0-9]+_$/', $key)) { + return __( + 'The \'tempfile_confs\' block \'file\' parameter has a key with invalid format. Use only letters (A-Z and a-z) and numbers (0-9) between opening and ending underscores (_): \'%s\'', + $key + ); + } + + if (empty($tempfile) === true) { + return __('All the \'tempfile_confs\' block \'file\' parameter definitions can not be empty: \'%s\'.', $key); + } + } + + return false; + } + + + /** + * Validate a tree recursively + * + * @param string $dataTree Name of parent data_tree. + * @param array $iniFile Inifile for search children. + * @param array $parents Array of parents for recursive action, DO NOT SET. + * + * @return boolean True if tree is correct. + */ + public static function validateTreeRecursive($dataTree, $iniFile, $parents=[]) + { + $innerData = []; + $parents[] = $dataTree; + foreach ($iniFile[$dataTree] as $key => $value) { + foreach ($value as $innerKey => $innerValue) { + if (isset($innerData[$innerKey])) { + $innerData[$innerKey][$key] = $innerValue; + } else { + $innerData[$innerKey] = [$key => $innerValue]; + } + } + } + + if (count($innerData) === 0) { + return __('The \'%s\' block must contain a \'name\' parameter that can not be empty.', $dataTree); + } + + foreach ($innerData as $key => $prop) { + if (is_numeric($key) === false || $key === 0) { + return __('All the \'%s\' block parameters must use numbers greater than 0 as keys: \'%s\'.', $dataTree, $key); + } + + if (empty($prop['name']) === true) { + return __('The \'%s\' block must contain a \'name\' parameter for all the tree elements: \'%s\'.', $dataTree, $key); + } + + if ($prop['selectable'] !== null && $prop['selectable'] === '') { + return __('All the \'%s\' block \'selectable\' parameter definitions can not be empty: \'%s\'.', $dataTree, $key); + } else { + $validValues = [ + 'true', + 'false', + '1', + '0', + 'yes', + 'no', + ]; + + if (in_array($prop['selectable'], $validValues) === false) { + return __( + 'The \'%s\' block \'selectable\' parameter has a definition with invalid value. Must be \'true\' or \'false\', \'1\' or \'0\', \'yes\' or \'no\': \'%s\'', + $dataTree, + $prop['selectable'] + ); + } + } + + if ($prop['macro'] !== null && !preg_match('/^_[a-zA-Z0-9]+_$/', $prop['macro'])) { + return __( + 'The \'%s\' block \'macro\' parameter has a definition with invalid format. Use only letters (A-Z and a-z) and numbers (0-9) between opening and ending underscores (_): \'%s\'', + $dataTree, + $prop['macro'] + ); + } + + if ($prop['children'] !== null && empty($iniFile[$prop['children']]) === true) { + return __('The \'%s\' block \'children\' parameter has a key value reference that does not exist: \'%s\'', $dataTree, $prop['children']); + } else if (in_array($prop['children'], $parents) === true) { + return __('The \'%s\' block \'children\' parameter has a key value reference to a parent tree element: \'%s\'', $dataTree, $prop['children']); + } else if (empty($iniFile[$prop['children']]) === false) { + $result = self::validateTreeRecursive($prop['children'], $iniFile, $parents); + if ($result !== false) { + return $result; + } + } + } + + return false; + } + + + /** + * Excute command with the timeout of the task. + * + * @param string $command Command to execute. + * + * @return string Output of command + */ + private function executeCommand($command) + { + $task = $this->getTask(); + $timeout = $task['executions_timeout']; + + $descriptors = [ + 0 => [ + 'pipe', + 'r', + ], + 1 => [ + 'pipe', + 'w', + ], + 2 => [ + 'pipe', + 'w', + ], + ]; + + $process = proc_open($command, $descriptors, $pipes); + + if (!is_resource($process)) { + return false; + } + + stream_set_blocking($pipes[1], 0); + + stream_set_blocking($pipes[2], 0); + + if (!$timeout) { + $timeout = 5; + } + + $real_timeout = ($timeout * 1000000); + + $buffer = ''; + + while ($real_timeout > 0) { + $start = microtime(true); + + $read = [$pipes[1]]; + $other = []; + stream_select($read, $other, $other, 0, $real_timeout); + + $status = proc_get_status($process); + + $buffer .= stream_get_contents($pipes[1]); + + if ($status['running'] === false) { + break; + } + + $real_timeout -= ((microtime(true) - $start) * 1000000); + } + + if ($real_timeout <= 0) { + proc_terminate($process, 9); + + fclose($pipes[0]); + fclose($pipes[1]); + fclose($pipes[2]); + + proc_close($process); + + return false; + } + + $errors = stream_get_contents($pipes[2]); + + if (empty($errors) === false && empty($buffer)) { + proc_terminate($process, 9); + + fclose($pipes[0]); + fclose($pipes[1]); + fclose($pipes[2]); + + proc_close($process); + + return false; + } + + proc_terminate($process, 9); + + fclose($pipes[0]); + fclose($pipes[1]); + fclose($pipes[2]); + + proc_close($process); + + return $buffer; + } + + +} diff --git a/pandora_console/include/class/NetworkMap.class.php b/pandora_console/include/class/NetworkMap.class.php index f65ddf95ce..353a17b80e 100644 --- a/pandora_console/include/class/NetworkMap.class.php +++ b/pandora_console/include/class/NetworkMap.class.php @@ -2392,7 +2392,9 @@ class NetworkMap unlink($filename_dot); - if (function_exists($this->customParser)) { + if (empty($this->customParser) === false + && function_exists($this->customParser) + ) { try { if (empty($this->customParserArgs)) { $graph = call_user_func( diff --git a/pandora_console/include/class/SatelliteAgent.class.php b/pandora_console/include/class/SatelliteAgent.class.php index 31cd2550d9..29fa2e3b77 100644 --- a/pandora_console/include/class/SatelliteAgent.class.php +++ b/pandora_console/include/class/SatelliteAgent.class.php @@ -162,7 +162,7 @@ class SatelliteAgent extends HTML [ 'id' => $this->tableId, 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => $this->ajaxController, diff --git a/pandora_console/include/class/SatelliteCollection.class.php b/pandora_console/include/class/SatelliteCollection.class.php index 8af5f210c8..a1ef24393c 100644 --- a/pandora_console/include/class/SatelliteCollection.class.php +++ b/pandora_console/include/class/SatelliteCollection.class.php @@ -142,7 +142,7 @@ class SatelliteCollection extends HTML [ 'id' => $this->tableId, 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => $this->ajaxController, diff --git a/pandora_console/include/class/SnmpConsole.class.php b/pandora_console/include/class/SnmpConsole.class.php index d83bad6f22..4a2c32de2e 100644 --- a/pandora_console/include/class/SnmpConsole.class.php +++ b/pandora_console/include/class/SnmpConsole.class.php @@ -236,27 +236,27 @@ class SnmpConsole extends HTML 'status', [ 'text' => 'snmp_agent', - 'class' => 'snmp-td', + 'class' => 'snmp-td datos_green', ], [ 'text' => 'enterprise_string', - 'class' => 'snmp-td', + 'class' => 'snmp-td datos_green', ], [ 'text' => 'count', - 'class' => 'snmp-td', + 'class' => 'snmp-td datos_green', ], [ 'text' => 'trap_subtype', - 'class' => 'snmp-td', + 'class' => 'snmp-td datos_green', ], [ 'text' => 'user_id', - 'class' => 'snmp-td', + 'class' => 'snmp-td datos_green', ], [ 'text' => 'timestamp', - 'class' => 'snmp-td', + 'class' => 'snmp-td datos_green', ], 'alert', [ @@ -326,7 +326,7 @@ class SnmpConsole extends HTML [ 'id' => $tableId, 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => $this->ajaxController, @@ -519,6 +519,8 @@ class SnmpConsole extends HTML $legend .= '
'; $legend .= ''; + echo '
'; + ui_toggle($legend, __('Legend')); // Load own javascript file. @@ -1331,17 +1333,8 @@ class SnmpConsole extends HTML * Show more information */ function toggleVisibleExtendedInfo(id, position) { - // Show all "Show more" - $('[id^=img_]').each(function() { - $(this).show(); - }); - // Hide all "Hide details" - $('[id^=img_hide_]').each(function() { - $(this).hide(); - }); var status = $('#eye_'+id).attr('data-show'); if(status == "show"){ - $('tr[id^=show_]').remove() $.ajax({ method: 'get', url: '', @@ -1360,14 +1353,14 @@ class SnmpConsole extends HTML datatype: "json", success: function(data) { let trap = JSON.parse(data); - var tr = $('#snmp_console tr').eq(position+1); + var tr = $('#snmp_console tr:not([id^="show_"])').eq(position+1); // Count. if ($('#filter_group_by').val() == 1) { let labelCount = ''; let variableCount = ``; - tr.after(`${labelCount}${variableCount}`); + tr.after(`${labelCount}${variableCount}`); } // Type. @@ -1405,27 +1398,27 @@ class SnmpConsole extends HTML let labelType = ''; let variableType = ``; - tr.after(`${labelType}${variableType}`); + tr.after(`${labelType}${variableType}`); // Description. if (trap['description']) { let labelDesc = ''; let variableDesc = ``; - tr.after(`${labelDesc}${variableDesc}`); + tr.after(`${labelDesc}${variableDesc}`); } // Enterprise String. let labelOid = ''; let variableOId = ``; - tr.after(`${labelOid}${variableOId}`); + tr.after(`${labelOid}${variableOId}`); // Variable bindings. let labelBindings = ''; let variableBindings = ''; if ($('#filter_group_by').val() == 1) { - labelBindings = ''; + labelBindings = ''; let new_url = 'index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view'; new_url += '&filter_severity='+$('#filter_severity').val(); @@ -1439,7 +1432,7 @@ class SnmpConsole extends HTML variableBindings = ``; } else { - labelBindings = ''; + labelBindings = ''; const binding_vars = trap['oid_custom'].split("\t"); let string = ''; binding_vars.forEach(function(oid) { @@ -1448,7 +1441,7 @@ class SnmpConsole extends HTML variableBindings = ``; } - tr.after(`${labelBindings}${variableBindings}`); + tr.after(`${labelBindings}${variableBindings}`); }, error: function(e) { console.error(e); @@ -1458,7 +1451,7 @@ class SnmpConsole extends HTML $('#img_'+id).hide(); $('#img_hide_'+id).show(); } else{ - $('tr[id^=show_]').remove(); + $(`tr#show_${id}`).remove(); $('#eye_'+id).attr('data-show', 'show'); $('#img_'+id).show(); $('#img_hide_'+id).hide(); diff --git a/pandora_console/include/class/TipsWindow.class.php b/pandora_console/include/class/TipsWindow.class.php index cf0824f626..ae4271fba9 100644 --- a/pandora_console/include/class/TipsWindow.class.php +++ b/pandora_console/include/class/TipsWindow.class.php @@ -475,7 +475,7 @@ class TipsWindow [ 'id' => 'list_tips_windows', 'class' => 'info_table', - 'style' => 'width: 99%', + 'style' => 'width: 100%', 'dom_elements' => 'lpfti', 'filter_main_class' => 'box-flat white_table_graph fixed_filter_bar', 'columns' => $columns, diff --git a/pandora_console/include/class/WelcomeWindow.class.php b/pandora_console/include/class/WelcomeWindow.class.php index 8d81ceee73..5e66268403 100644 --- a/pandora_console/include/class/WelcomeWindow.class.php +++ b/pandora_console/include/class/WelcomeWindow.class.php @@ -336,54 +336,7 @@ class WelcomeWindow extends Wizard public function loadWelcomeWindow() { global $config; - - $btn_configure_mail_class = 'pending'; - $btn_create_agent_class = 'pending'; - $btn_create_module_class = ''; - $btn_create_alert_class = ''; - $btn_create_discovery_class = 'pending'; - - $li_configure_mail_class = 'row_green'; - $li_create_agent_class = 'row_green'; - $li_create_module_class = 'row_grey'; - $li_create_alert_class = 'row_grey'; - $li_create_discovery_class = 'row_green'; - - if (empty($config['welcome_mail_configured']) === false) { - $btn_configure_mail_class = ' completed'; - } - - if (empty($config['welcome_id_agent']) === false) { - $btn_create_agent_class = ' completed'; - $btn_create_module_class = ' pending'; - $li_create_module_class = 'row_green'; - } - - if (empty($config['welcome_module']) === false) { - $btn_create_module_class = ' completed'; - $btn_create_alert_class = ' pending'; - $li_create_module_class = 'row_green'; - } - - if (empty($config['welcome_alert']) === false) { - $btn_create_alert_class = ' completed'; - $li_create_alert_class = 'row_green'; - } - - if (empty($config['welcome_task']) === false) { - $btn_create_discovery_class = ' completed'; - } - - if ((int) $config['welcome_state'] === WELCOME_FINISHED) { - // Nothing left to do. - $btn_configure_mail_class = ' completed'; - $btn_create_agent_class = ' completed'; - $btn_create_module_class = ' completed'; - $btn_create_alert_class = ' completed'; - $btn_create_discovery_class = ' completed'; - $li_create_module_class = 'row_green'; - $li_create_alert_class = 'row_green'; - } + $flag_task = false; $form = [ 'action' => '#', @@ -392,207 +345,279 @@ class WelcomeWindow extends Wizard 'class' => 'modal', ]; - $logo_url = 'images/custom_logo/pandora_logo_head_white_bg.png'; - if (enterprise_installed() === true) { $logo_url = ENTERPRISE_DIR.'/'.$logo_url; } - $inputs = [ - [ - 'class' => 'white_box', - 'block_content' => [ - [ - 'class' => 'centered_full', - 'arguments' => [ - 'type' => 'image', - 'src' => $logo_url, - 'value' => 1, - 'return' => true, - ], - ], - ], - ], - [ + if (check_acl($config['id_user'], 0, 'PM')) { + $flag_um = false; + $flag_cm = false; + $flag_su = false; + $flag_lv = false; + + $btn_update_manager_class = ' fail'; + $btn_configure_mail_class = ' fail'; + $btn_servers_up_class = ' fail'; + $btn_license_valid_class = ' fail'; + + $li_update_manager_class = 'row_grey'; + $li_configure_mail_class = 'row_grey'; + $li_servers_up_class = 'row_grey'; + $li_license_valid_class = 'row_grey'; + + include_once 'include/functions_update_manager.php'; + if (update_manager_verify_registration()) { + $btn_update_manager_class = ''; + $li_update_manager_class = 'row_green'; + $flag_um = true; + } + + if (empty($config['welcome_mail_configured']) === false) { + $btn_configure_mail_class = ''; + $li_configure_mail_class = 'row_green'; + $flag_cm = true; + } + + include_once 'include/functions_servers.php'; + if (check_all_servers_up() === true) { + $btn_servers_up_class = ''; + $li_servers_up_class = 'row_green'; + $flag_su = true; + } + + if (enterprise_installed()) { + $license_valid = true; + enterprise_include_once('include/functions_license.php'); + $license = enterprise_hook('license_get_info'); + $days_to_expiry = ((strtotime($license['expiry_date']) - time()) / (60 * 60 * 24)); + if ($license === ENTERPRISE_NOT_HOOK || $days_to_expiry <= 30) { + $license_valid = false; + } + + if ($license_valid === true) { + $btn_license_valid_class = ''; + $li_license_valid_class = 'row_green'; + $flag_lv = true; + } else { + $btn_license_valid_class = 'fail'; + $li_license_valid_class = 'row_grey'; + $flag_lv = false; + } + } else { + $btn_license_valid_class = 'fail'; + $li_license_valid_class = 'row_grey'; + $flag_lv = false; + } + + $inputs[] = [ 'wrapper' => 'div', - 'block_id' => 'div_configure_mail', - 'class' => 'hole flex-row flex-items-center w98p '.$li_configure_mail_class, + 'block_id' => 'div_diagnosis', + 'class' => 'flex-row flex-items-center w98p ', 'direct' => 1, 'block_content' => [ [ - 'label' => __('Please ensure mail configuration matches your needs'), + 'label' => __('Post-installation status diagnostic'), 'arguments' => [ 'class' => 'first_lbl', - 'name' => 'lbl_create_agent', - 'id' => 'lbl_create_agent', - ], - ], - [ - 'arguments' => [ - 'label' => '', - 'type' => 'button', - 'attributes' => [ - 'class' => (empty($btn_configure_mail_class) === false) ? $btn_configure_mail_class : 'invisible_important', - 'mode' => 'onlyIcon', - ], - 'name' => 'btn_email_conf', - 'id' => 'btn_email_conf', + 'name' => 'lbl_diagnosis', + 'id' => 'lbl_diagnosis', ], ], ], - ], - [ - 'label' => 'Learn to monitor', - 'class' => 'extra', - 'arguments' => [ - 'class' => 'class="lbl_learn"', - 'name' => 'lbl_learn', - 'id' => 'lbl_learn', - ], - ], - [ - 'wrapper' => 'div', - 'block_id' => 'div_create_agent', - 'class' => 'learn_content_indented flex-row flex-items-center w98p '.$li_create_agent_class, - 'direct' => 1, - 'block_content' => [ - [ - 'label' => __('Create an agent'), - 'arguments' => [ - 'class' => 'first_lbl', - 'name' => 'lbl_create_agent', - 'id' => 'lbl_create_agent', - ], - ], - [ - 'arguments' => [ - 'label' => '', - 'type' => 'button', - 'attributes' => [ - 'class' => (empty($btn_create_agent_class) === false) ? $btn_create_agent_class : 'invisible_important', - 'mode' => 'onlyIcon', + ]; + + if ($flag_um === false || $flag_cm === false || $flag_su === false || $flag_lv === false) { + $inputs[] = [ + 'wrapper' => 'div', + 'block_id' => 'div_update_manager', + 'class' => 'hole flex-row flex-items-center w98p '.$li_update_manager_class, + 'direct' => 1, + 'block_content' => [ + [ + 'label' => __('Warp Update registration'), + 'arguments' => [ + 'class' => 'first_lbl', + 'name' => 'lbl_update_manager', + 'id' => 'lbl_update_manager', ], - 'name' => 'btn_create_agent', - 'id' => 'btn_create_agent', ], - ], - ], - ], - [ - 'wrapper' => 'div', - 'block_id' => 'div_monitor_actions', - 'class' => 'learn_content_indented flex-row flex-items-center w98p '.$li_create_module_class, - 'direct' => 1, - 'block_content' => [ - [ - 'label' => __('Create a module to check if an agent is online'), - 'arguments' => [ - 'class' => 'second_lbl', - 'name' => 'lbl_check_agent', - 'id' => 'lbl_check_agent', - ], - ], - [ - 'arguments' => [ - 'label' => '', - 'type' => 'button', - 'attributes' => [ - 'class' => (empty($btn_create_module_class) === false) ? $btn_create_module_class : 'invisible_important', - 'mode' => 'onlyIcon', + [ + 'arguments' => [ + 'label' => '', + 'type' => 'button', + 'attributes' => [ + 'class' => (empty($btn_update_manager_class) === false) ? $btn_update_manager_class : 'invisible_important', + 'mode' => 'onlyIcon', + ], + 'name' => 'btn_update_manager_conf', + 'id' => 'btn_update_manager_conf', ], - 'name' => 'btn_create_module', - 'id' => 'btn_create_module', ], ], - ], - ], - [ - 'wrapper' => 'div', - 'block_id' => 'div_monitor_actions', - 'class' => 'hole learn_content_indented flex-row flex-items-center w98p '.$li_create_alert_class, - 'direct' => 1, - 'block_content' => [ - [ - 'label' => __('Be warned if something is wrong, create an alert on the module'), - 'arguments' => [ - 'class' => 'second_lbl', - 'name' => 'lbl_create_alert', - 'id' => 'lbl_create_alert', - ], - ], - [ - 'arguments' => [ - 'label' => '', - 'type' => 'button', - 'attributes' => [ - 'class' => (empty($btn_create_alert_class) === false) ? $btn_create_alert_class : 'invisible_important', - 'mode' => 'onlyIcon', + ]; + $inputs[] = [ + 'wrapper' => 'div', + 'block_id' => 'div_configure_mail', + 'class' => 'hole flex-row flex-items-center w98p '.$li_configure_mail_class, + 'direct' => 1, + 'block_content' => [ + [ + 'label' => __('Default mail to send alerts'), + 'arguments' => [ + 'class' => 'first_lbl', + 'name' => 'lbl_create_agent', + 'id' => 'lbl_create_agent', ], - 'name' => 'btn_create_alert', - 'id' => 'btn_create_alert', ], - ], - ], - ], - [ - 'wrapper' => 'div', - 'block_id' => 'div_discover', - 'class' => 'hole flex-row flex-items-center w98p '.$li_create_discovery_class, - 'direct' => 1, - 'block_content' => [ - [ - 'label' => __('Discover hosts and devices in your network'), - 'arguments' => [ - 'class' => 'first_lbl', - 'name' => 'lbl_discover_devices', - 'id' => 'lbl_discover_devices', - ], - ], - [ - 'arguments' => [ - 'label' => '', - 'type' => 'button', - 'attributes' => [ - 'class' => (empty($btn_create_discovery_class) === false) ? $btn_create_discovery_class : 'invisible_important', - 'mode' => 'onlyIcon', + [ + 'arguments' => [ + 'label' => '', + 'type' => 'button', + 'attributes' => [ + 'class' => (empty($btn_configure_mail_class) === false) ? $btn_configure_mail_class : 'invisible_important', + 'mode' => 'onlyIcon', + ], + 'name' => 'btn_email_conf', + 'id' => 'btn_email_conf', ], - 'name' => 'btn_discover_devices', - 'id' => 'btn_discover_devices', ], ], + ]; + $inputs[] = [ + 'wrapper' => 'div', + 'block_id' => 'div_servers_up', + 'class' => 'hole flex-row flex-items-center w98p '.$li_servers_up_class, + 'direct' => 1, + 'block_content' => [ + [ + 'label' => __('All servers running'), + 'arguments' => [ + 'class' => 'first_lbl', + 'name' => 'lbl_servers_up', + 'id' => 'lbl_servers_up', + ], + ], + [ + 'arguments' => [ + 'label' => '', + 'type' => 'button', + 'attributes' => [ + 'class' => (empty($btn_servers_up_class) === false) ? $btn_servers_up_class : 'invisible_important', + 'mode' => 'onlyIcon', + ], + 'name' => 'btn_servers_up_conf', + 'id' => 'btn_servers_up_conf', + ], + ], + ], + ]; + $inputs[] = [ + 'wrapper' => 'div', + 'block_id' => 'div_license_valid', + 'class' => 'hole flex-row flex-items-center w98p '.$li_license_valid_class, + 'direct' => 1, + 'block_content' => [ + [ + 'label' => __('Enterprise licence valid'), + 'arguments' => [ + 'class' => 'first_lbl', + 'name' => 'lbl_license_valid', + 'id' => 'lbl_license_valid', + ], + ], + [ + 'arguments' => [ + 'label' => '', + 'type' => 'button', + 'attributes' => [ + 'class' => (empty($btn_license_valid_class) === false) ? $btn_license_valid_class : 'invisible_important', + 'mode' => 'onlyIcon', + ], + 'name' => 'btn_license_valid_conf', + 'id' => 'btn_license_valid_conf', + ], + ], + ], + ]; + } else { + $inputs[] = [ + 'wrapper' => 'div', + 'block_id' => 'div_all_correct', + 'class' => 'hole flex-row flex-items-center w98p', + 'direct' => 1, + 'block_content' => [ + [ + 'label' => __('It seems that your Pandora FMS is working correctly and registered with ID:
#'.$config['pandora_uid'].'.
For more information use the self-diagnosis tool.'), + 'arguments' => [ + 'class' => 'first_lbl w98p', + 'name' => 'lbl_all_correct', + 'id' => 'lbl_all_correct', + ], + ], + ], + ]; + } + + if ($flag_um === false || $flag_cm === false || $flag_su === false || $flag_lv === false) { + $flag_task = true; + } + } + + // Task to do. + $inputs[] = [ + 'wrapper' => 'div', + 'block_id' => 'div_task_todo', + 'class' => 'flex-row flex-items-center w98p', + 'direct' => 1, + 'block_content' => [ + [ + 'label' => __('Task to perform'), + 'arguments' => [ + 'class' => 'first_lbl', + 'name' => 'lbl_task_todo', + 'id' => 'lbl_task_todo', + ], ], ], ]; - if (enterprise_installed() === true) { - $inputs[] = [ - 'wrapper' => 'div', - 'block_id' => 'div_not_working', - 'class' => 'hole flex-row flex-items-center w98p', - 'direct' => 1, - 'block_content' => [ - [ - 'label' => __('If something is not working as expected, look for this icon and report!'), - 'arguments' => [ - 'class' => 'first_lbl', - 'name' => 'lbl_not_working', - 'id' => 'lbl_not_working', - ], - ], - [ - 'label' => html_print_image( - 'images/feedback-header.png', - true, - [ - 'onclick' => '$(\'#feedback-header\').click()', - 'style' => 'cursor: pointer;', - ] - ), + $fields['wizard_agent'] = __('Agent installation wizard'); + $fields['check_web'] = __('Create WEB monitoring'); + $fields['check_connectivity'] = __('Create network monitoring'); + $fields['check_net'] = __('Discover my network'); + $fields['check_mail_alert'] = __('Create email alert'); + $inputs[] = [ + 'wrapper' => 'div', + 'block_id' => 'div_wizard_agent', + 'class' => 'flex space-between w98p', + 'direct' => 1, + 'block_content' => [ + [ + 'arguments' => [ + 'type' => 'select', + 'fields' => $fields, + 'name' => 'task_to_perform', + 'selected' => '', + 'return' => true, + 'nothing' => \__('Please select one'), + 'nothing_value' => '', ], ], - ]; - } + [ + 'arguments' => [ + 'label' => __("Let's do it!"), + 'type' => 'button', + 'attributes' => [ + 'class' => 'secondary', + 'icon' => 'next', + ], + 'name' => 'go_wizard', + 'id' => 'go_wizard', + ], + ], + ], + ]; $output = $this->printForm( [ @@ -602,9 +627,235 @@ class WelcomeWindow extends Wizard true ); - $output .= $this->loadJS(); + $output .= $this->loadJS($flag_task); echo $output; + ?> + + + + + 0) { $ret .= "$seconds seconds"; } @@ -907,7 +907,7 @@ function set_cookie($name, $value) { if (is_null($value)) { unset($_COOKIE[$value]); - setcookie($name, null, -1, '/'); + setcookie($name, '', -1, '/'); } else { setcookie($name, $value); } @@ -4337,10 +4337,22 @@ function generator_chart_to_pdf( // Creates a new page. $page = $browser->createPage(); + $curl = curl_init(); - // Navigate to an URL. - $navigation = $page->navigate($url.'?data='.urlencode(json_encode($data))); - $navigation->waitForNavigation(Page::DOM_CONTENT_LOADED); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, ['data' => json_encode($data)]); + + $response = curl_exec($curl); + + curl_close($curl); + + $page->setHtml($response); + /* + //For debug url with parameters. + $navigation = $page->navigate($url.'?data='.urlencode(json_encode($data))); + $navigation->waitForNavigation(Page::DOM_CONTENT_LOADED); + */ // Dynamic. $dynamic_height = $page->evaluate('document.getElementById("container-chart-generator-item").clientHeight')->getReturnValue(); @@ -4415,8 +4427,8 @@ function get_product_name() /** * Get the copyright notice. * - * @return string If the installation is open, it will be 'Artica ST'. - * If the product name stored is empty, it returns 'Artica ST' too. + * @return string If the installation is open, it will be 'Pandora FMS'. + * If the product name stored is empty, it returns 'Pandora FMS' too. */ function get_copyright_notice() { diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 2c09fda820..bb5b19a27e 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -583,12 +583,6 @@ function agents_get_agents( $status_sql = '( normal_count <> total_count OR total_count = notinit_count)'; - // The AGENT_STATUS_NOT_NORMAL filter must show all agents that are not in normal status - /* - "( - normal_count <> total_count - AND - (normal_count + notinit_count) <> total_count)";*/ break; case AGENT_STATUS_NOT_INIT: @@ -605,32 +599,28 @@ function agents_get_agents( $filter_nogroup = $filter; - // Get user groups + // Get user groups. $groups = array_keys(users_get_groups($config['id_user'], $access, false)); - // If no group specified, get all user groups + // If no group specified, get all user groups. if (empty($filter['id_grupo'])) { $all_groups = true; $filter['id_grupo'] = $groups; } else if (! is_array($filter['id_grupo'])) { $all_groups = false; - // If group is specified but not allowed, return false + // If group is specified but not allowed, return false. if (! in_array($filter['id_grupo'], $groups)) { return false; } $filter['id_grupo'] = (array) $filter['id_grupo']; - // Make an array + // Make an array. } else { $all_groups = true; - // Check each group specified to the user groups, remove unwanted groups - foreach ($filter['id_grupo'] as $key => $id_group) { - if (! in_array($id_group, $groups)) { - unset($filter['id_grupo'][$key]); - } - } - // If no allowed groups are specified return false + $filter['id_grupo'] = array_intersect($groups, $filter['id_grupo']); + + // If no allowed groups are specified return false. if (count($filter['id_grupo']) == 0) { return false; } @@ -2770,6 +2760,69 @@ function agents_delete_agent($id_agents, $disableACL=false) enterprise_include_once('include/functions_agents.php'); enterprise_hook('agent_delete_from_cache', [$id_agent]); + // Delete agent from visual console. + db_process_sql_delete( + 'tlayout_data', + ['id_agent' => $id_agent] + ); + + // Delete agent from visual dashboards. + db_process_sql( + 'UPDATE twidget_dashboard + SET options = NULL + WHERE options LIKE ("%\"agentid\":\"'.$id_agent.'\"%")' + ); + + // Delete agent from treport. + db_process_sql_delete( + 'treport_content', + ['id_agent' => $id_agent] + ); + + // Delete rules from tevent alerts (correlative alerts) + db_process_sql_delete( + 'tevent_rule', + [ + 'agent' => $id_agent, + 'operator_agent' => '==', + ] + ); + + db_process_sql_delete( + 'tevent_rule', + [ + 'log_agent' => $id_agent, + 'operator_log_agent' => '==', + ] + ); + + // Delete from gis maps history + db_process_sql_delete( + 'tgis_data_history', + ['tagente_id_agente' => $id_agent] + ); + + // Delete from policies. + db_process_sql_delete( + 'tpolicy_agents', + ['id_agent' => $id_agent] + ); + + // Delete from tnetwork maps + db_process_sql_delete( + 'titem', + ['source_data' => $id_agent] + ); + + db_process_sql_delete( + 'trel_item', + [ + 'id_parent_source_data' => $id_agent, + 'id_child_source_data' => $id_agent, + ], + 'OR' + ); + // Delete agent from fav menu. db_process_sql_delete( 'tfavmenu_user', diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index d98057b97c..8d51a3b536 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -455,7 +455,7 @@ function alerts_delete_alert_action($id_alert_action) * * @return mixed Id of the cloned action or false in case of fail. */ -function alerts_clone_alert_action($id_alert_action, $id_group) +function alerts_clone_alert_action($id_alert_action, $id_group, $copy_name='') { $id_alert_action = safe_int($id_alert_action, 1); if (empty($id_alert_action)) { @@ -474,7 +474,13 @@ function alerts_clone_alert_action($id_alert_action, $id_group) unset($action['id']); - return alerts_create_alert_action($action['name'].' '.__('copy'), $action['id_alert_command'], $action); + if ($copy_name !== '') { + $copy_name = $copy_name; + } else { + $copy_name = $action['name'].' '.__('copy'); + } + + return alerts_create_alert_action($copy_name, $action['id_alert_command'], $action); } @@ -1562,13 +1568,13 @@ function alerts_delete_alert_agent_module_action($id_alert_agent_module_action) * * @return mixed Actions associated or false if something goes wrong. */ -function alerts_get_alert_agent_module_actions($id_alert_agent_module, $fields=false, $server_id=-1) +function alerts_get_alert_agent_module_actions($id_alert_agent_module, $fields=false, $server_id=-1, $ignore_metaconsole=false) { if (empty($id_alert_agent_module)) { return false; } - if (defined('METACONSOLE')) { + if (defined('METACONSOLE') && $ignore_metaconsole === false) { $server = db_get_row('tmetaconsole_setup', 'id', $server_id); if (metaconsole_connect($server) == NOERR) { @@ -1602,6 +1608,7 @@ function alerts_get_alert_agent_module_actions($id_alert_agent_module, $fields=f $action['fires_min'] = $element['fires_min']; $action['fires_max'] = $element['fires_max']; $action['module_action_threshold'] = $element['module_action_threshold']; + $action['original_id'] = $element['id']; if (isset($element['id'])) { $retval[$element['id']] = $action; diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 77b2f9e3fa..7e22befbee 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -1916,7 +1916,7 @@ function api_set_update_agent_field($id_agent, $use_agent_alias, $params) * * @param $thrash3 Don't use. */ -function api_set_new_agent($id_node, $thrash2, $other, $trhash3) +function api_set_new_agent($id_node, $thrash2, $other, $trhash3, $return=false, $message=false) { global $config; @@ -2009,16 +2009,40 @@ function api_set_new_agent($id_node, $thrash2, $other, $trhash3) // Check if agent exists (BUG WC-50518-2). if ($alias == '' && $alias_as_name === 0) { + if ($message === true) { + return 'No agent alias specified'; + } + returnError('No agent alias specified'); } else if (agents_get_agent_id($nombre_agente)) { + if ($message === true) { + return 'The agent name already exists in DB.'; + } + returnError('The agent name already exists in DB.'); } else if (db_get_value_sql('SELECT id_grupo FROM tgrupo WHERE id_grupo = '.$grupo) === false) { + if ($message === true) { + return 'The group does not exist.'; + } + returnError('The group does not exist.'); } else if (group_allow_more_agents($grupo, true, 'create') === false) { + if ($message === true) { + return 'Agent cannot be created due to the maximum agent limit for this group'; + } + returnError('Agent cannot be created due to the maximum agent limit for this group'); } else if (db_get_value_sql('SELECT id_os FROM tconfig_os WHERE id_os = '.$id_os) === false) { + if ($message === true) { + return 'The OS does not exist.'; + } + returnError('The OS does not exist.'); } else if ($server_name === false) { + if ($message === true) { + return 'The '.get_product_name().' Server does not exist.'; + } + returnError('The '.get_product_name().' Server does not exist.'); } else { if ($alias_as_name === 1) { @@ -2038,13 +2062,17 @@ function api_set_new_agent($id_node, $thrash2, $other, $trhash3) } } - returnData( - 'string', - [ - 'type' => 'string', - 'data' => $id_agente, - ] - ); + if ($return === false) { + returnData( + 'string', + [ + 'type' => 'string', + 'data' => $id_agente, + ] + ); + } else { + return $id_agente; + } } catch (\Exception $e) { returnError($e->getMessage()); return; @@ -7833,24 +7861,26 @@ function api_set_planned_downtimes_add_agents($id, $thrash1, $other, $thrash3) } if (!empty($other['data'][0])) { - $agents = $other['data']; + $agents = explode(';', $other['data'][0]); $results = false; foreach ($agents as $agent) { - if (db_get_value_sql(sprintf('SELECT id from tplanned_downtime_agents tpd WHERE tpd.id_agent = %d AND id_downtime = %d', $agent, $id)) === false) { - $res = db_process_sql_insert( - 'tplanned_downtime_agents', - [ - 'id_agent' => $agent, - 'id_downtime' => $id, - 'all_modules' => 0, - 'manually_disabled' => 0, - ] - ); - if ($res) { - $results = true; + if (!empty($agent)) { + if (db_get_value_sql(sprintf('SELECT id from tplanned_downtime_agents tpd WHERE tpd.id_agent = %d AND id_downtime = %d', $agent, $id)) === false) { + $res = db_process_sql_insert( + 'tplanned_downtime_agents', + [ + 'id_agent' => $agent, + 'id_downtime' => $id, + 'all_modules' => 0, + 'manually_disabled' => 0, + ] + ); + if ($res) { + $results = true; + } + } else { + returnError(" Agent $agent is already at the planned downtime."); } - } else { - returnError(" Agent $agent is already at the planned downtime."); } } @@ -11544,6 +11574,11 @@ function api_get_events($node_id, $trash2, $other, $returnType) } } + // Add agent name to nodo. + if (is_metaconsole() === false && empty($row['id_agente']) === false) { + $row['agent_name'] = agents_get_name($row['id_agente']); + } + // FOR THE TEST THE API IN THE ANDROID. $row['description_event'] = events_print_type_description($row['event_type'], true); $row['img_description'] = events_print_type_img($row['event_type'], true, true); @@ -11643,7 +11678,7 @@ function api_set_add_user_profile($id, $thrash1, $other, $thrash2) return; } - if (!check_acl($config['id_user'], 0, 'PM')) { + if (!check_acl($config['id_user'], 0, 'UM')) { returnError('forbidden', 'string'); return; } @@ -11667,7 +11702,7 @@ function api_set_add_user_profile($id, $thrash1, $other, $thrash2) return; } - if (!check_acl($config['id_user'], $group, 'PM')) { + if (!check_acl($config['id_user'], $group, 'UM')) { returnError('forbidden', 'string'); return; } @@ -11702,7 +11737,7 @@ function api_set_delete_user_profile($id, $thrash1, $other, $thrash2) return; } - if (!check_acl($config['id_user'], 0, 'PM')) { + if (!check_acl($config['id_user'], 0, 'UM')) { returnError('forbidden', 'string'); return; } @@ -11726,7 +11761,7 @@ function api_set_delete_user_profile($id, $thrash1, $other, $thrash2) return; } - if (!check_acl($config['id_user'], $group, 'PM')) { + if (!check_acl($config['id_user'], $group, 'UM')) { returnError('forbidden', 'string'); return; } @@ -11759,7 +11794,7 @@ function api_get_user_profiles_info($thrash1, $thrash2, $thrash3, $returnType) { global $config; - if (!check_acl($config['id_user'], 0, 'PM')) { + if (!check_acl($config['id_user'], 0, 'UM')) { returnError('forbidden', 'string'); return; } @@ -13091,9 +13126,14 @@ function api_set_create_event($id, $trash1, $other, $returnType) $values['custom_data'] = ''; } + $ack_utimestamp = 0; + if ($other['data'][18] != '') { $values['id_extra'] = $other['data'][18]; - $sql_validation = 'SELECT id_evento,estado FROM tevento where estado IN (0,2) and id_extra ="'.$other['data'][18].'";'; + $sql_validation = 'SELECT id_evento,estado,ack_utimestamp,id_usuario + FROM tevento + WHERE estado IN (0,2) AND id_extra ="'.$other['data'][18].'";'; + $validation = db_get_all_rows_sql($sql_validation); if ($validation) { @@ -13103,6 +13143,8 @@ function api_set_create_event($id, $trash1, $other, $returnType) && (int) $values['status'] === 0 ) { $values['status'] = 2; + $ack_utimestamp = $val['ack_utimestamp']; + $values['id_usuario'] = $val['id_usuario']; } api_set_validate_event_by_id($val['id_evento']); @@ -13132,7 +13174,8 @@ function api_set_create_event($id, $trash1, $other, $returnType) $values['tags'], $custom_data, $values['server_id'], - $values['id_extra'] + $values['id_extra'], + $ack_utimestamp ); if ($other['data'][12] != '') { @@ -15744,6 +15787,8 @@ function api_get_cluster_items($cluster_id) */ function api_set_create_event_filter($name, $thrash1, $other, $thrash3) { + global $config; + if ($name == '') { returnError( 'The event filter could not be created. Event filter name cannot be left blank.' @@ -16972,7 +17017,7 @@ function api_set_delete_user_permission($thrash1, $thrash2, $other, $returnType) { global $config; - if (!check_acl($config['id_user'], 0, 'AW')) { + if (!check_acl($config['id_user'], 0, 'UM')) { returnError('forbidden', 'string'); return; } diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 91dd4b61d5..033b2067b6 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -378,6 +378,10 @@ function config_update_config() $error_update[] = __('keep_in_process_status_extra_id'); } + if (config_update_value('show_experimental_features', get_parameter('show_experimental_features'), true) === false) { + $error_update[] = __('show_experimental_features'); + } + if (config_update_value('console_log_enabled', get_parameter('console_log_enabled'), true) === false) { $error_update[] = __('Console log enabled'); } @@ -398,6 +402,10 @@ function config_update_config() $error_update[] = __('Check conexion interval'); } + if (config_update_value('max_hours_old_event_comment', get_parameter('max_hours_old_event_comment'), true) === false) { + $error_update[] = __('Max hours old event comments'); + } + if (config_update_value('unique_ip', get_parameter('unique_ip'), true) === false) { $error_update[] = __('Unique IP'); } @@ -627,6 +635,30 @@ function config_update_config() $error_update[] = __('Domain'); } + if (config_update_value('secondary_active_directory', get_parameter('secondary_active_directory'), true) === false) { + $error_update[] = __('Secondary active directory'); + } + + if (config_update_value('ad_server_secondary', get_parameter('ad_server_secondary'), true) === false) { + $error_update[] = __('Secondary active directory server'); + } + + if (config_update_value('ad_port_secondary', get_parameter('ad_port_secondary'), true) === false) { + $error_update[] = __('Secondary active directory port'); + } + + if (config_update_value('ad_start_tls_secondary', get_parameter('ad_start_tls_secondary'), true) === false) { + $error_update[] = __('Secondary start TLS'); + } + + if (config_update_value('ad_search_timeout', get_parameter('ad_search_timeout'), true) === false) { + $error_update[] = __('AD search timeout'); + } + + if (config_update_value('ad_domain_secondary', get_parameter('ad_domain_secondary'), true) === false) { + $error_update[] = __('Secondary domain'); + } + if (config_update_value('ad_adv_perms', get_parameter('ad_adv_perms'), true) === false) { $error_update[] = __('Advanced Permisions AD'); } @@ -819,6 +851,10 @@ function config_update_config() $error_update[] = __('2FA all users'); } + if (config_update_value('control_session_timeout', get_parameter('control_session_timeout'), true) === false) { + $error_update[] = __('Control timeout'); + } + if (config_update_value('session_timeout', get_parameter('session_timeout'), true) === false) { $error_update[] = __('Session timeout'); } else { @@ -828,6 +864,8 @@ function config_update_config() if (config_update_value('session_timeout', 90, true) === false) { $error_update[] = __('Session timeout'); } + } else { + config_prepare_expire_time_session(true); } } @@ -940,12 +978,12 @@ function config_update_config() } } - if (config_update_value('delete_old_messages', get_parameter('delete_old_messages'), true) === false) { - $error_update[] = __('Max. days before delete old messages'); + if (config_update_value('delete_disabled_agents', get_parameter('delete_disabled_agents'), true) === false) { + $error_update[] = __('Max. days before disabled agents are deleted'); } - if (config_update_value('delete_old_network_matrix', get_parameter('delete_old_network_matrix'), true) === false) { - $error_update[] = __('Max. days before delete old network matrix data'); + if (config_update_value('delete_old_messages', get_parameter('delete_old_messages'), true) === false) { + $error_update[] = __('Max. days before delete old messages'); } if (config_update_value('max_graph_container', get_parameter('max_graph_container'), true) === false) { @@ -1451,6 +1489,15 @@ function config_update_config() $interval_values_array = explode(',', $interval_values); if (in_array($new_interval, $interval_values_array) === false) { $interval_values_array[] = $new_interval; + // Get current periods. + $current_period = get_periods(false, false, true); + if (!isset($current_period[-1])) { + $new_current_period = array_keys($current_period); + $new_current_period = implode(',', $new_current_period); + // Add new periods to current. + array_push($interval_values_array, $new_current_period); + } + $interval_values = implode(',', $interval_values_array); } } @@ -2090,6 +2137,12 @@ function config_process_config() if (!isset($config['date_format'])) { config_update_value('date_format', 'F j, Y, g:i a'); + } else { + $config['date_format'] = str_replace( + ' ', + ' ', + $config['date_format'] + ); } if (!isset($config['event_view_hr'])) { @@ -2201,12 +2254,12 @@ function config_process_config() } } - if (!isset($config['delete_old_messages'])) { - config_update_value('delete_old_messages', 21); + if (!isset($config['delete_disabled_agents'])) { + config_update_value('delete_disabled_agents', 0); } - if (!isset($config['delete_old_network_matrix'])) { - config_update_value('delete_old_network_matrix', 10); + if (!isset($config['delete_old_messages'])) { + config_update_value('delete_old_messages', 21); } if (!isset($config['max_graph_container'])) { @@ -2371,6 +2424,10 @@ function config_process_config() config_update_value('keep_in_process_status_extra_id', 0); } + if (!isset($config['show_experimental_features'])) { + config_update_value('show_experimental_features', 0); + } + if (!isset($config['console_log_enabled'])) { config_update_value('console_log_enabled', 0); } @@ -2391,6 +2448,10 @@ function config_process_config() config_update_value('check_conexion_interval', 180); } + if (!isset($config['max_hours_old_event_comment'])) { + config_update_value('max_hours_old_event_comment', 8); + } + if (!isset($config['elasticsearch_ip'])) { config_update_value('elasticsearch_ip', ''); } @@ -2472,10 +2533,6 @@ function config_process_config() 'max' => 90, 'min' => 0, ], - 'delete_old_network_matrix' => [ - 'max' => 30, - 'min' => 1, - ], 'report_limit' => [ 'max' => 500, 'min' => 1, @@ -3094,6 +3151,14 @@ function config_process_config() config_update_value('ad_port', 389); } + if (!isset($config['ad_server_secondary'])) { + config_update_value('ad_server_secondary', 'localhost'); + } + + if (!isset($config['ad_port_secondary'])) { + config_update_value('ad_port_secondary', 389); + } + if (!isset($config['ad_start_tls'])) { config_update_value('ad_start_tls', 0); } @@ -3433,10 +3498,6 @@ function config_process_config() config_update_value('dbtype', 'mysql'); } - if (!isset($config['legacy_vc'])) { - config_update_value('legacy_vc', 0); - } - if (!isset($config['vc_default_cache_expiration'])) { config_update_value('vc_default_cache_expiration', 60); } @@ -3797,6 +3858,10 @@ function config_process_config() config_update_value('notification_autoclose_time', 5); } + if (isset($config['control_session_timeout']) === false) { + config_update_value('control_session_timeout', 'check_activity'); + } + // Finally, check if any value was overwritten in a form. config_update_config(); } @@ -3928,12 +3993,60 @@ function config_user_set_custom_config() } } + config_prepare_expire_time_session(); + if (is_metaconsole() === true) { $config['metaconsole_access'] = $userinfo['metaconsole_access']; } } +function config_prepare_expire_time_session($force_update=false) +{ + global $config; + if (empty($config['id_user']) === true) { + return; + } + + $userinfo = get_user_info($config['id_user']); + + if (isset($userinfo)) { + $user_sesion_time = $userinfo['session_time']; + } else { + $user_sesion_time = null; + } + + if ($user_sesion_time == 0) { + // Change the session timeout value to session_timeout minutes // 8*60*60 = 8 hours. + $sessionCookieExpireTime = $config['session_timeout']; + } else { + // Change the session timeout value to session_timeout minutes // 8*60*60 = 8 hours. + $sessionCookieExpireTime = $user_sesion_time; + } + + if ($sessionCookieExpireTime <= 0) { + $sessionCookieExpireTime = (10 * 365 * 24 * 60 * 60); + } else { + $sessionCookieExpireTime *= 60; + } + + if ($config['control_session_timeout'] === 'ignore_activity') { + $sessionMaxTimeout = (time() + $sessionCookieExpireTime); + if ((int) $userinfo['session_max_time_expire'] === 0 || $force_update === true) { + $userinfo['session_max_time_expire'] = $sessionMaxTimeout; + update_user($userinfo['id_user'], ['session_max_time_expire' => $sessionMaxTimeout]); + } else if (time() > (int) $userinfo['session_max_time_expire'] && (int) $userinfo['session_max_time_expire'] > 0) { + update_user($userinfo['id_user'], ['session_max_time_expire' => 0]); + } + } else { + if ((int) $userinfo['session_max_time_expire'] > 0) { + update_user($userinfo['id_user'], ['session_max_time_expire' => 0]); + } + } + +} + + /** * Undocumented function * @@ -3975,7 +4088,17 @@ function config_prepare_session() } if ($update_cookie === true) { - setcookie(session_name(), $_COOKIE[session_name()], (time() + $sessionCookieExpireTime), '/'); + if (isset($user) === true + && isset($user['session_max_time_expire']) === true + && (int) $user['session_max_time_expire'] > 0 + && time() < $user['session_max_time_expire'] + ) { + $sessionMaxTimeout = $user['session_max_time_expire']; + } else { + $sessionMaxTimeout = (time() + $sessionCookieExpireTime); + } + + setcookie(session_name(), $_COOKIE[session_name()], $sessionMaxTimeout, '/'); } } diff --git a/pandora_console/include/functions_cron.php b/pandora_console/include/functions_cron.php index 052dec9692..2eafd8dccb 100644 --- a/pandora_console/include/functions_cron.php +++ b/pandora_console/include/functions_cron.php @@ -923,16 +923,15 @@ function cron_list_table() } if ($manage_pandora) { - $data[7] .= ''; - $data[7] .= html_print_image( - 'images/delete.svg', - true, + $data[7] .= html_print_menu_button( [ - 'title' => __('Delete'), - 'class' => 'main_menu_icon invert_filter', - ] + 'href' => $url.'delete_task=1&id_user_task='.$task['id'], + 'image' => 'images/delete.svg', + 'title' => __('Delete'), + 'onClick' => 'if (!confirm(\''.__('Are you sure?').'\')) return false;', + ], + true ); - $data[7] .= ''; } } else { if ($write_perms || $manage_pandora) { @@ -949,17 +948,15 @@ function cron_list_table() } if ($manage_perms || $manage_pandora) { - $data[7] .= ''; - $data[7] .= html_print_image( - 'images/delete.svg', - true, + $data[7] .= html_print_menu_button( [ - 'title' => __('Delete'), - 'class' => 'main_menu_icon invert_filter', - ] + 'href' => $url.'delete_task=1&id_user_task='.$task['id'], + 'image' => 'images/delete.svg', + 'title' => __('Delete'), + 'onClick' => 'if (!confirm(\''.__('Are you sure?').'\')) return false;', + ], + true ); - $data[7] .= ''; } } diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 50ae4694b3..7581f8c6cb 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -613,6 +613,74 @@ function events_update_status($id_evento, $status, $filter=null) } +/** + * Get filter time. + * + * @param array $filter Filters. + * + * @return array conditions. + */ +function get_filter_date(array $filter) +{ + if (isset($filter['date_from']) === true + && empty($filter['date_from']) === false + && $filter['date_from'] !== '0000-00-00' + ) { + $date_from = $filter['date_from']; + } + + if (isset($filter['time_from']) === true) { + $time_from = (empty($filter['time_from']) === true) ? '00:00:00' : $filter['time_from']; + } + + if (isset($date_from) === true) { + if (isset($time_from) === false) { + $time_from = '00:00:00'; + } + + $from = $date_from.' '.$time_from; + $sql_filters[] = sprintf( + ' AND te.utimestamp >= %d', + strtotime($from) + ); + } + + if (isset($filter['date_to']) === true + && empty($filter['date_to']) === false + && $filter['date_to'] !== '0000-00-00' + ) { + $date_to = $filter['date_to']; + } + + if (isset($filter['time_to']) === true) { + $time_to = (empty($filter['time_to']) === true) ? '23:59:59' : $filter['time_to']; + } + + if (isset($date_to) === true) { + if (isset($time_to) === false) { + $time_to = '23:59:59'; + } + + $to = $date_to.' '.$time_to; + $sql_filters[] = sprintf( + ' AND te.utimestamp <= %d', + strtotime($to) + ); + } + + if (isset($from) === false) { + if (isset($filter['event_view_hr']) === true && ($filter['event_view_hr'] > 0)) { + $sql_filters[] = sprintf( + ' AND te.utimestamp > UNIX_TIMESTAMP(now() - INTERVAL %d HOUR) ', + $filter['event_view_hr'] + ); + } + } + + return $sql_filters; +} + + /** * Retrieve all events filtered. * @@ -700,60 +768,7 @@ function events_get_all( ); } - if (isset($filter['date_from']) === true - && empty($filter['date_from']) === false - && $filter['date_from'] !== '0000-00-00' - ) { - $date_from = $filter['date_from']; - } - - if (isset($filter['time_from']) === true) { - $time_from = (empty($filter['time_from']) === true) ? '00:00:00' : $filter['time_from']; - } - - if (isset($date_from) === true) { - if (isset($time_from) === false) { - $time_from = '00:00:00'; - } - - $from = $date_from.' '.$time_from; - $sql_filters[] = sprintf( - ' AND te.utimestamp >= %d', - strtotime($from) - ); - } - - if (isset($filter['date_to']) === true - && empty($filter['date_to']) === false - && $filter['date_to'] !== '0000-00-00' - ) { - $date_to = $filter['date_to']; - } - - if (isset($filter['time_to']) === true) { - $time_to = (empty($filter['time_to']) === true) ? '23:59:59' : $filter['time_to']; - } - - if (isset($date_to) === true) { - if (isset($time_to) === false) { - $time_to = '23:59:59'; - } - - $to = $date_to.' '.$time_to; - $sql_filters[] = sprintf( - ' AND te.utimestamp <= %d', - strtotime($to) - ); - } - - if (isset($from) === false) { - if (isset($filter['event_view_hr']) === true && ($filter['event_view_hr'] > 0)) { - $sql_filters[] = sprintf( - ' AND utimestamp > UNIX_TIMESTAMP(now() - INTERVAL %d HOUR) ', - $filter['event_view_hr'] - ); - } - } + $sql_filters = get_filter_date($filter); if (isset($filter['id_agent']) === true && $filter['id_agent'] > 0) { $sql_filters[] = sprintf( @@ -1069,7 +1084,6 @@ function events_get_all( $array_search = [ 'te.id_evento', 'lower(te.evento)', - 'lower(te.user_comment)', 'lower(te.id_extra)', 'lower(te.source)', 'lower('.$custom_data_search.')', @@ -1106,7 +1120,6 @@ function events_get_all( ' AND (lower(ta.alias) not like lower("%%%s%%") AND te.id_evento not like "%%%s%%" AND lower(te.evento) not like lower("%%%s%%") - AND lower(te.user_comment) not like lower("%%%s%%") AND lower(te.id_extra) not like lower("%%%s%%") AND lower(te.source) not like lower("%%%s%%") )', array_fill(0, 6, $filter['search_exclude']) @@ -1122,16 +1135,13 @@ function events_get_all( } // User comment. + $event_comment_join = ''; if (empty($filter['user_comment']) === false) { - // For filter field. + $event_comment_join = 'INNER JOIN tevent_comment ON te.id_evento = tevent_comment.id_event'; $sql_filters[] = sprintf( - ' AND lower(te.user_comment) like lower("%%%s%%") ', - io_safe_input($filter['user_comment']) - ); - - // For show comments on event details. - $sql_filters[] = sprintf( - ' OR lower(te.user_comment) like lower("%%%s%%") ', + ' AND (lower(tevent_comment.comment) like lower("%%%s%%") + OR lower(tevent_comment.comment) like lower("%%%s%%"))', + io_safe_input($filter['user_comment']), $filter['user_comment'] ); } @@ -1455,7 +1465,7 @@ function events_get_all( ' LIMIT %d', $config['max_number_of_events_per_node'] ); - } else if (isset($limit, $offset) === true && $limit > 0) { + } else if (isset($limit, $offset) === true && empty($limit) === false && $limit > 0) { $pagination = sprintf(' LIMIT %d OFFSET %d', $limit, $offset); } @@ -1552,36 +1562,20 @@ function events_get_all( $group_selects = ''; if ($group_by != '') { if ($count === false) { - $idx = array_search('te.user_comment', $fields); - if ($idx !== false) { - unset($fields[$idx]); - } - - db_process_sql('SET group_concat_max_len = 9999999'); - $group_selects = sprintf( ',COUNT(id_evento) AS event_rep, - %s - MAX(utimestamp) as timestamp_last, - MIN(utimestamp) as timestamp_first, - MAX(id_evento) as max_id_evento', - ($idx !== false) ? 'GROUP_CONCAT(DISTINCT user_comment SEPARATOR "
") AS comments,' : '' + MAX(te.utimestamp) as timestamp_last, + MIN(te.utimestamp) as timestamp_first, + MAX(id_evento) as max_id_evento' ); $group_selects_trans = sprintf( ',tmax_event.event_rep, - %s tmax_event.timestamp_last, tmax_event.timestamp_first, - tmax_event.max_id_evento', - ($idx !== false) ? 'tmax_event.comments,' : '' + tmax_event.max_id_evento' ); } - } else { - $idx = array_search('te.user_comment', $fields); - if ($idx !== false) { - $fields[$idx] = 'te.user_comment AS comments'; - } } if (((int) $filter['group_rep'] === EVENT_GROUP_REP_EVENTS @@ -1596,11 +1590,12 @@ function events_get_all( FROM %s %s %s + %s %s JOIN %s ta - ON ta.%s = te.id_agente + ON ta.%s = te.id_agente %s %s JOIN tgrupo tg - ON %s + ON %s WHERE 1=1 %s %s @@ -1611,6 +1606,7 @@ function events_get_all( ON te.id_evento = tmax_event.max_id_evento %s %s + %s %s JOIN %s ta ON ta.%s = te.id_agente %s @@ -1625,6 +1621,7 @@ function events_get_all( $tevento, $event_lj, $agentmodule_join, + $event_comment_join, $tagente_join, $tagente_table, $tagente_field, @@ -1638,6 +1635,7 @@ function events_get_all( $having, $event_lj, $agentmodule_join, + $event_comment_join, $tagente_join, $tagente_table, $tagente_field, @@ -1654,6 +1652,7 @@ function events_get_all( FROM %s %s %s + %s %s JOIN %s ta ON ta.%s = te.id_agente %s @@ -1671,6 +1670,7 @@ function events_get_all( $tevento, $event_lj, $agentmodule_join, + $event_comment_join, $tagente_join, $tagente_table, $tagente_field, @@ -1762,9 +1762,11 @@ function events_get_all( } } + $string_metaconsole_connections = implode(',', $metaconsole_connections); + $explode_metaconsole_connections = explode(',', $string_metaconsole_connections); $result_meta = Promise\wait( parallelMap( - $metaconsole_connections, + $explode_metaconsole_connections, function ($node_int) use ($sql, $history) { try { if (is_metaconsole() === true @@ -2238,91 +2240,18 @@ function events_comment( $first_event = reset($id_event); } - $sql = sprintf( - 'SELECT user_comment - FROM tevento - WHERE id_evento = %d', - $first_event + // Update comment. + $ret = db_process_sql_insert( + 'tevent_comment', + [ + 'id_event' => $first_event, + 'comment' => $comment, + 'action' => $action, + 'utimestamp' => time(), + 'id_user' => $config['id_user'], + ], ); - $event_comments = db_get_all_rows_sql($sql); - $event_comments_array = []; - - if ($event_comments[0]['user_comment'] == '') { - $comments_format = 'new'; - } else { - // If comments are not stored in json, the format is old. - $event_comments[0]['user_comment'] = str_replace( - [ - "\n", - ' ', - ], - '
', - $event_comments[0]['user_comment'] - ); - $event_comments_array = json_decode($event_comments[0]['user_comment']); - - if (empty($event_comments_array) === true) { - $comments_format = 'old'; - } else { - $comments_format = 'new'; - } - } - - switch ($comments_format) { - case 'new': - $comment_for_json['comment'] = io_safe_input($comment); - $comment_for_json['action'] = $action; - $comment_for_json['id_user'] = $config['id_user']; - $comment_for_json['utimestamp'] = time(); - $comment_for_json['event_id'] = $first_event; - - $event_comments_array[] = $comment_for_json; - - $event_comments = io_json_mb_encode($event_comments_array); - - // Update comment. - $ret = db_process_sql_update( - 'tevento', - ['user_comment' => $event_comments], - ['id_evento' => implode(',', $id_event)] - ); - break; - - case 'old': - // Give old ugly format to comment. - // Change this method for aux table or json. - $comment = str_replace(["\r\n", "\r", "\n"], '
', $comment); - - if ($comment !== '') { - $commentbox = '
'.io_safe_input($comment).'
'; - } else { - $commentbox = ''; - } - - // Don't translate 'by' word because if multiple users with - // different languages make comments in the same console - // will be a mess. - $comment = '-- '.$action.' by '.$config['id_user'].' ['.date($config['date_format']).'] --
'.$commentbox.'
'; - - // Update comment. - $sql_validation = sprintf( - 'UPDATE %s - SET user_comment = concat("%s", user_comment) - WHERE id_evento in (%s)', - 'tevento', - $comment, - implode(',', $id_event) - ); - - $ret = db_process_sql($sql_validation); - break; - - default: - // Ignore. - break; - } - if (($ret === false) || ($ret === 0)) { return false; } @@ -2407,7 +2336,8 @@ function events_create_event( $tags='', $custom_data='', $server_id=0, - $id_extra='' + $id_extra='', + $ack_utimestamp=0 ) { if ($source === false) { $source = get_product_name(); @@ -2428,7 +2358,6 @@ function events_create_event( 'id_agentmodule' => $id_agent_module, 'id_alert_am' => $id_aam, 'criticity' => $priority, - 'user_comment' => '', 'tags' => $tags, 'source' => $source, 'id_extra' => $id_extra, @@ -2436,7 +2365,7 @@ function events_create_event( 'warning_instructions' => $warning_instructions, 'unknown_instructions' => $unknown_instructions, 'owner_user' => '', - 'ack_utimestamp' => 0, + 'ack_utimestamp' => $ack_utimestamp, 'custom_data' => $custom_data, 'data' => '', 'module_status' => 0, @@ -2679,22 +2608,27 @@ function events_print_type_img( case 'going_down_critical': case 'going_up_critical': // This is to be backwards compatible. - $style .= ' event_module_background_state icon_background_critical'; + $icon = 'images/module_critical.png'; break; case 'going_up_normal': case 'going_down_normal': // This is to be backwards compatible. - $style .= ' event_module_background_state icon_background_normal'; + // $style .= ' event_module_background_state icon_background_normal'; + $icon = 'images/module_ok.png'; break; case 'going_up_warning': + $icon = 'images/module_warning.png'; + // $style .= ' event_module_background_state icon_background_warning'; case 'going_down_warning': - $style .= ' event_module_background_state icon_background_warning'; + $icon = 'images/module_warning.png'; + // $style .= ' event_module_background_state icon_background_warning'; break; case 'going_unknown': - $style .= ' event_module_background_state icon_background_unknown'; + // $style .= ' event_module_background_state icon_background_unknown'; + $icon = 'images/module_unknown.png'; break; case 'alert_fired': @@ -2731,23 +2665,24 @@ function events_print_type_img( if ($only_url) { $output = $urlImage.'/'.$icon; } else { - $output .= html_print_div( - [ - 'title' => events_print_type_description($type, true), - 'class' => $style, - 'style' => ((empty($icon) === false) ? 'background-image: url('.$icon.'); background-repeat: no-repeat;' : ''), - ], - true - ); /* - $output .= html_print_image( + $output .= html_print_div( + [ + 'title' => events_print_type_description($type, true), + 'class' => $style, + 'style' => ((empty($icon) === false) ? 'background-image: url('.$icon.'); background-repeat: no-repeat;' : ''), + ], + true + ); + */ + $output .= html_print_image( $icon, true, [ 'title' => events_print_type_description($type, true), 'class' => $style, ] - );*/ + ); } if ($return) { @@ -2850,16 +2785,14 @@ function events_print_type_img_pdf( break; case 'new_agent': - $svg = ' - Dark / 20 / agents@svg - Created with Sketch. - - - - - - - '; + $svg = html_print_image( + '/images/agent_mc.png', + true, + [ + 'class' => 'image_status invert_filter', + 'title' => 'agents', + ] + ); break; case 'configuration_change': @@ -2874,6 +2807,18 @@ function events_print_type_img_pdf( break; case 'unknown': + break; + + case 'alert_fired': + $svg = ' + Dark / 20 / alert@svg + Created with Sketch. + + + + '; + break; + default: $svg = ' Dark / 20 / event@svg @@ -4353,7 +4298,7 @@ function events_page_details($event, $server_id=0) } else if (can_user_access_node() && is_metaconsole()) { // Workaround to pass login hash data in POST body instead of directly in the URL. parse_str($hashstring, $url_hash_array); - $redirection_form = "
"; + $redirection_form = "
"; $redirection_form .= html_print_input_hidden( 'loginhash', $url_hash_array['loginhash'], @@ -5059,8 +5004,12 @@ function events_page_general($event) } $data[1] = $user_ack.' ( '; + // hd($config['date_format'], true); + // hd($event['ack_utimestamp_raw'], true); + // TODO: mirar en el manage y en la api que este ack de venir vacio lo herede del anterior que hubiera. if ($event['ack_utimestamp_raw'] !== false && $event['ack_utimestamp_raw'] !== 'false' + && empty($event['ack_utimestamp_raw']) === false ) { $data[1] .= date( $config['date_format'], @@ -5216,7 +5165,7 @@ function events_page_general_acknowledged($event_id) * * @return string HTML. */ -function events_page_comments($event, $ajax=false, $groupedComments=[]) +function events_page_comments($event, $groupedComments=[], $filter=null) { // Comments. global $config; @@ -5227,12 +5176,7 @@ function events_page_comments($event, $ajax=false, $groupedComments=[]) $table_comments->head = []; $table_comments->class = 'table_modal_alternate'; - if (isset($event['user_comment']) === false) { - $event['user_comment'] = ''; - } - - $comments = (empty($groupedComments) === true) ? $event['user_comment'] : $groupedComments; - + $comments = $groupedComments; if (empty($comments) === true) { $table_comments->style[0] = 'text-align:left;'; $table_comments->colspan[0][0] = 2; @@ -5241,49 +5185,7 @@ function events_page_comments($event, $ajax=false, $groupedComments=[]) $table_comments->data[] = $data; } else { if (is_array($comments) === true) { - $comments_array = []; - foreach ($comments as $comm) { - if (empty($comm) === true) { - continue; - } - - // If exists user_comments, come from grouped events and must be handled like this. - if (isset($comm['user_comment']) === true) { - $comm = $comm['user_comment']; - } - - $comm = str_replace(["\n", ' '], '

', $comm); - - $comments_array[] = io_safe_output(json_decode($comm, true)); - } - - // Plain comments. Can be improved. - $sortedCommentsArray = []; - foreach ($comments_array as $comm) { - if (isset($comm) === true - && empty($comm) === false - ) { - foreach ($comm as $subComm) { - $sortedCommentsArray[] = $subComm; - } - } - } - - // Sorting the comments by utimestamp (newer is first). - usort( - $sortedCommentsArray, - function ($a, $b) { - if ($a['utimestamp'] == $b['utimestamp']) { - return 0; - } - - return ($a['utimestamp'] > $b['utimestamp']) ? -1 : 1; - } - ); - - // Clean the unsorted comments and return it to the original array. - $comments_array = []; - $comments_array[] = $sortedCommentsArray; + $comments_array = $comments; } else { $comments = str_replace(["\n", ' '], '
', $comments); // If comments are not stored in json, the format is old. @@ -5291,76 +5193,70 @@ function events_page_comments($event, $ajax=false, $groupedComments=[]) } foreach ($comments_array as $comm) { - $comments_format = (empty($comm) === true && is_array($comments) === false) ? 'old' : 'new'; + $eventIdExplanation = (empty($groupedComments) === false) ? sprintf(' (#%d)', $comm['id_event']) : ''; + $data[0] = sprintf( + '%s %s %s%s', + $comm['action'], + __('by'), + get_user_fullname(io_safe_input($comm['id_user'])).' ('.io_safe_input($comm['id_user']).')', + $eventIdExplanation + ); - switch ($comments_format) { - case 'new': - foreach ($comm as $c) { - $eventIdExplanation = (empty($groupedComments) === false) ? sprintf(' (#%d)', $c['event_id']) : ''; + $data[0] .= sprintf( + '

%s', + date($config['date_format'], $comm['utimestamp']) + ); - $data[0] = sprintf( - '%s %s %s%s', - $c['action'], - __('by'), - get_user_fullname(io_safe_input($c['id_user'])).' ('.io_safe_input($c['id_user']).')', - $eventIdExplanation - ); + $data[1] = '

'.stripslashes(str_replace(['\n', '\r'], '
', $comm['comment'])).'

'; - $data[0] .= sprintf( - '

%s', - date($config['date_format'], $c['utimestamp']) - ); - - $data[1] = '

'.stripslashes(str_replace(['\n', '\r'], '
', $c['comment'])).'

'; - - $table_comments->data[] = $data; - } - break; - - case 'old': - $comm = explode('
', $comments); - - // Split comments and put in table. - $col = 0; - $data = []; - - foreach ($comm as $c) { - switch ($col) { - case 0: - $row_text = preg_replace('/\s*--\s*/', '', $c); - $row_text = preg_replace('/\<\/b\>/', '', $row_text); - $row_text = preg_replace('/\[/', '

[', $row_text); - $row_text = preg_replace('/[\[|\]]/', '', $row_text); - break; - - case 1: - $row_text = preg_replace("/[\r\n|\r|\n]/", '
', io_safe_output(strip_tags($c))); - break; - - default: - // Ignore. - break; - } - - $data[$col] = $row_text; - - $col++; - - if ($col == 2) { - $col = 0; - $table_comments->data[] = $data; - $data = []; - } - } - break; - - default: - // Ignore. - break; - } + $table_comments->data[] = $data; } } + $comments_filter = '
'; + $comments_filter .= html_print_label_input_block( + null, + html_print_extended_select_for_time( + 'comments_events_max_hours_old', + $filter['event_view_hr_cs'], + '', + __('Default'), + -2, + false, + true, + false, + true, + '', + false, + [ + SECONDS_1HOUR => __('1 hour'), + SECONDS_6HOURS => __('6 hours'), + SECONDS_12HOURS => __('12 hours'), + SECONDS_1DAY => __('24 hours'), + SECONDS_2DAY => __('48 hours'), + ], + '', + false, + 0, + [ SECONDS_1HOUR => __('hours') ], + ) + ); + + $eventb64 = base64_encode(json_encode($event)); + $filterb64 = base64_encode(json_encode($filter)); + $comments_filter .= html_print_submit_button( + __('Filter'), + 'filter_comments_button', + false, + [ + 'class' => 'mini mrgn_lft_15px', + 'icon' => 'search', + 'onclick' => 'get_table_events_tabs("'.$eventb64.'","'.$filterb64.'")', + ], + true + ); + $comments_filter .= '
'; + if (((tags_checks_event_acl( $config['id_user'], $event['id_grupo'], @@ -5386,7 +5282,10 @@ function events_page_comments($event, $ajax=false, $groupedComments=[]) true ); - $comments_form .= '
'; + $comments_form .= '
'; + $comments_form .= '
'; + $comments_form .= $comments_filter; + $comments_form .= '
'; $comments_form .= html_print_button( __('Add comment'), 'comment_button', @@ -5398,14 +5297,15 @@ function events_page_comments($event, $ajax=false, $groupedComments=[]) ], true ); - $comments_form .= '

'; + $comments_form .= '
'; + $comments_form .= ''; + + $comments_form .= '
'; + } else { + $comments_form = $comments_filter; } - if ($ajax === true) { - return $comments_form.html_print_table($table_comments, true); - } - - return '
'.$comments_form.html_print_table($table_comments, true).'
'; + return $comments_form.html_print_table($table_comments, true); } @@ -5540,7 +5440,7 @@ function events_get_sql_order($sort_field='timestamp', $sort='DESC', $group_rep= break; case 'comment': - $sort_field_translated = 'user_comment'; + $sort_field_translated = 'tevent_comment.comment'; break; case 'extra_id': @@ -6112,3 +6012,179 @@ function get_count_event_criticity( return db_get_all_rows_sql($sql_meta); } + + +/** + * Comments for this events. + * + * @param array $event Info event. + * @param integer $mode Mode group by. + * @param integer $event_rep Events. + * + * @return array Comments. + */ +function event_get_comment($event, $filter=null) +{ + $whereGrouped = []; + if (empty($filter) === false) { + if (isset($filter['event_view_hr_cs']) === true && ($filter['event_view_hr_cs'] > 0)) { + $whereGrouped[] = sprintf( + ' AND tevent_comment.utimestamp > UNIX_TIMESTAMP(now() - INTERVAL %d SECOND) ', + $filter['event_view_hr_cs'] + ); + } else if (isset($filter['event_view_hr']) === true && ($filter['event_view_hr'] > 0)) { + $whereGrouped[] = sprintf( + ' AND tevent_comment.utimestamp > UNIX_TIMESTAMP(now() - INTERVAL %d SECOND) ', + ((int) $filter['event_view_hr'] * 3600) + ); + } + } + + $mode = (int) $filter['group_rep']; + + $eventsGrouped = []; + // Consider if the event is grouped. + if ($mode === EVENT_GROUP_REP_EVENTS) { + // Default grouped message filtering (evento and estado). + $whereGrouped[] = sprintf( + 'AND `tevento`.`evento` = "%s"', + io_safe_input(io_safe_output($event['evento'])) + ); + + // If id_agente is reported, filter the messages by them as well. + if ((int) $event['id_agente'] > 0) { + $whereGrouped[] = sprintf( + ' AND `tevento`.`id_agente` = %d', + (int) $event['id_agente'] + ); + } + + if ((int) $event['id_agentmodule'] > 0) { + $whereGrouped[] = sprintf( + ' AND `tevento`.`id_agentmodule` = %d', + (int) $event['id_agentmodule'] + ); + } + } else if ($mode === EVENT_GROUP_REP_EXTRAIDS) { + $whereGrouped[] = sprintf( + 'AND `tevento`.`id_extra` = "%s"', + io_safe_input(io_safe_output($event['id_extra'])) + ); + } else { + $whereGrouped[] = sprintf('AND `tevento`.`id_evento` = %d', $event['id_evento']); + } + + try { + if (is_metaconsole() === true + && $event['server_id'] > 0 + ) { + $node = new Node($event['server_id']); + $node->connect(); + } + + $sql = sprintf( + 'SELECT tevent_comment.* + FROM tevento + INNER JOIN tevent_comment + ON tevento.id_evento = tevent_comment.id_event + WHERE 1=1 %s + ORDER BY tevent_comment.utimestamp DESC', + implode(' ', $whereGrouped) + ); + + // Get grouped comments. + $eventsGrouped = db_get_all_rows_sql($sql); + } catch (\Exception $e) { + // Unexistent agent. + if (is_metaconsole() === true + && $event['server_id'] > 0 + ) { + $node->disconnect(); + } + + $eventsGrouped = []; + } finally { + if (is_metaconsole() === true + && $event['server_id'] > 0 + ) { + $node->disconnect(); + } + } + + return $eventsGrouped; +} + + +/** + * Last comment for this event. + * + * @param array $event Info event. + * + * @return string Comment. + */ +function event_get_last_comment($event, $filter) +{ + $comments = event_get_comment($event, $filter); + if (empty($comments) === false) { + return $comments[0]; + } + + return ''; +} + + +/** + * Get counter events same extraid. + * + * @param array $event Event data. + * @param array $filters Filters. + * + * @return integer Counter. + */ +function event_get_counter_extraId(array $event, ?array $filters) +{ + $counters = 0; + + $where = get_filter_date($filters); + + $where[] = sprintf( + 'AND `te`.`id_extra` = "%s"', + $event['id_extra'] + ); + + try { + if (is_metaconsole() === true + && $event['server_id'] > 0 + ) { + $node = new Node($event['server_id']); + $node->connect(); + } + + $sql = sprintf( + 'SELECT count(*) + FROM tevento te + WHERE 1=1 %s', + implode(' ', $where) + ); + + // Get grouped comments. + $counters = db_get_value_sql($sql); + } catch (\Exception $e) { + // Unexistent agent. + if (is_metaconsole() === true + && $event['server_id'] > 0 + ) { + $node->disconnect(); + } + + $counters = 0; + } finally { + if (is_metaconsole() === true + && $event['server_id'] > 0 + ) { + $node->disconnect(); + } + } + + return $counters; +} diff --git a/pandora_console/include/functions_filemanager.php b/pandora_console/include/functions_filemanager.php index feb3379351..50ca449123 100644 --- a/pandora_console/include/functions_filemanager.php +++ b/pandora_console/include/functions_filemanager.php @@ -766,7 +766,18 @@ function filemanager_file_explorer( && ($readOnly === false) ) { $data[4] .= '
'; - $data[4] .= ''; + $data[4] .= html_print_input_image( + 'delete', + 'images/delete.svg', + 1, + 'margin-top: 2px;height:21px', + true, + [ + 'title' => __('Delete'), + 'class' => 'invert_filter main_menu_icon', + 'onclick' => 'if (!confirm(\' '.__('Are you sure?').'\')) return false;', + ] + ); $data[4] .= html_print_input_hidden('filename', $fileinfo['realpath'], true); $data[4] .= html_print_input_hidden('hash', md5($fileinfo['realpath'].$config['server_unique_identifier']), true); $data[4] .= html_print_input_hidden('delete_file', 1, true); @@ -899,7 +910,19 @@ function filemanager_file_explorer( if ($allowZipFiles === true) { $uploadFileElements .= ui_print_help_tip(__('The zip upload in this dir, easy to upload multiple files.'), true); $uploadFileElements .= html_print_input_file('file', true, false); - $uploadFileElements .= html_print_checkbox('decompress', 1, false, true).__('Decompress'); + $uploadFileElements .= html_print_div( + [ + 'id' => 'checkbox-decompress', + 'content' => html_print_checkbox( + 'decompress', + 1, + false, + true, + ).__('Decompress'), + 'style' => 'margin-top:25px', + ], + true + ); $uploadFileElements .= html_print_input_hidden('upload_file_or_zip', 1, true); } else { $uploadFileElements .= html_print_div( diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 116deea959..1892b0cd31 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -1003,6 +1003,10 @@ function grafico_modulo_sparse($params) ]; } + if ($data_module_graph === false) { + $data_module_graph = []; + } + $data_module_graph['series_suffix'] = $series_suffix; // Check available data. @@ -4560,6 +4564,10 @@ function graph_netflow_aggregate_pie($data, $aggregate, $ttl=1, $only_image=fals } $labels = array_keys($values); + foreach ($labels as $key => $label) { + $labels[$key] = (string) $label; + } + $values = array_values($values); if ($config['fixed_graph'] == false) { @@ -4624,7 +4632,10 @@ function graph_netflow_circular_mesh($data) include_once $config['homedir'].'/include/graphs/functions_d3.php'; - return d3_relationship_graph($data['elements'], $data['matrix'], 900, true); + $width = (empty($data['width']) === false) ? $data['width'] : 900; + $height = (empty($data['height']) === false) ? $data['height'] : 900; + + return d3_relationship_graph($data['elements'], $data['matrix'], $width, true, $height); } @@ -4983,19 +4994,18 @@ function graph_monitor_wheel($width=550, $height=600, $filter=false) $filter_module_group = (!empty($filter) && !empty($filter['module_group'])) ? $filter['module_group'] : false; if ($filter['group'] != 0) { - $filter_subgroups = ''; - if (!$filter['dont_show_subgroups']) { - $filter_subgroups = ' || parent IN ('.$filter['group'].')'; + if ($filter['dont_show_subgroups'] === false) { + $groups = groups_get_children($filter['group']); + $groups_ax = []; + foreach ($groups as $g) { + $groups_ax[$g['id_grupo']] = $g; + } + + $groups = $groups_ax; + } else { + $groups = groups_get_group_by_id($filter['group']); + $groups[$group['id_grupo']] = $group; } - - $groups = db_get_all_rows_sql('SELECT * FROM tgrupo where id_grupo IN ('.$filter['group'].') '.$filter_subgroups); - - $groups_ax = []; - foreach ($groups as $g) { - $groups_ax[$g['id_grupo']] = $g; - } - - $groups = $groups_ax; } else { $groups = users_get_groups(false, 'AR', false, true, (!empty($filter) && isset($filter['group']) ? $filter['group'] : null)); } diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 652e878e82..9ca7663ba3 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -578,6 +578,10 @@ function html_print_select_groups( if (empty($nothing) === false) { $fields[$nothing_value] = $nothing; + if ($include_groups === false) { + $include_groups = []; + } + $include_groups[$nothing_value] = $nothing; } @@ -768,7 +772,8 @@ function html_print_select( $select2_enable=true, $select2_multiple_enable=false, $select2_multiple_enable_all=false, - $form='' + $form='', + $order=false, ) { $output = "\n"; @@ -805,6 +810,10 @@ function html_print_select( } } + if ($multiple === true && $order === true) { + $class .= ' order-arrows'; + } + if (!empty($class)) { $attributes .= ' class="'.$class.'"'; } @@ -1129,6 +1138,49 @@ function html_print_select( $output .= ''; } + if ($multiple === true && $order === true) { + $output .= ''; + } + if ($return) { return $output; } @@ -1873,7 +1925,8 @@ function html_print_extended_select_for_unit( $select_style=false, $unique_name=true, $disabled=false, - $no_change=0 + $no_change=0, + $class='w100p' ) { global $config; @@ -1905,7 +1958,7 @@ function html_print_extended_select_for_unit( ob_start(); - echo '
'; + echo '
'; html_print_select( $fields, $uniq_name.'_select', @@ -2113,7 +2166,8 @@ function html_print_extended_select_for_time( $custom_fields=false, $style_icon='', $no_change=false, - $allow_zero=0 + $allow_zero=0, + $units=null ) { global $config; $admin = is_user_admin($config['id_user']); @@ -2139,15 +2193,17 @@ function html_print_extended_select_for_time( $selected = 300; } - $units = [ - 1 => __('seconds'), - SECONDS_1MINUTE => __('minutes'), - SECONDS_1HOUR => __('hours'), - SECONDS_1DAY => __('days'), - SECONDS_1WEEK => __('weeks'), - SECONDS_1MONTH => __('months'), - SECONDS_1YEAR => __('years'), - ]; + if (empty($units) === true) { + $units = [ + 1 => __('seconds'), + SECONDS_1MINUTE => __('minutes'), + SECONDS_1HOUR => __('hours'), + SECONDS_1DAY => __('days'), + SECONDS_1WEEK => __('weeks'), + SECONDS_1MONTH => __('months'), + SECONDS_1YEAR => __('years'), + ]; + } if ($unique_name === true) { $uniq_name = uniqid($name); @@ -2171,7 +2227,7 @@ function html_print_extended_select_for_time( $nothing_value, false, false, - false, + true, $class, $readonly, 'font-size: xx-small;'.$select_style @@ -3282,9 +3338,23 @@ function html_print_input_image($name, $src, $value, $style='', $return=false, $ 'disabled', ]; + if (isset($options['title']) && $options['title'] != '') { + if (isset($options['class'])) { + $options['class'] .= ' forced_title'; + } else { + $options['class'] = 'forced_title'; + } + + // New way to show the force_title (cleaner and better performance). + $output .= 'data-title="'.io_safe_input_html($options['title']).'" '; + $output .= 'data-use_title_for_force_title="1" '; + } + foreach ($attrs as $attribute) { - if (isset($options[$attribute])) { - $output .= ' '.$attribute.'="'.io_safe_input_html($options[$attribute]).'"'; + if ($attribute !== 'title') { + if (isset($options[$attribute])) { + $output .= ' '.$attribute.'="'.io_safe_input_html($options[$attribute]).'"'; + } } } @@ -3571,6 +3641,7 @@ function html_print_button($label='OK', $name='', $disabled=false, $script='', $ $classes = ''; $fixedId = ''; $iconStyle = ''; + $minimize_arrow = false; // $spanStyle = 'margin-top: 4px;'; $spanStyle = ''; if (empty($name) === true) { @@ -3608,6 +3679,8 @@ function html_print_button($label='OK', $name='', $disabled=false, $script='', $ $buttonType = ($attr_array['type'] ?? 'button'); $buttonAttributes = $value; break; + } else if ($attribute === 'minimize-arrow') { + $minimize_arrow = true; } else { $attributes .= $attribute.'="'.$value.'" '; } @@ -3632,15 +3705,30 @@ function html_print_button($label='OK', $name='', $disabled=false, $script='', $ $iconDiv = ''; } + if ($minimize_arrow === true) { + $minimezeDiv = html_print_div( + [ + 'id' => 'minimize_arrow_event_sound', + 'style' => 'background-color:transparent; right: 1em; margin-left:0.5em; position:relative; display:none;', + 'class' => 'arrow_menu_down w30p', + ], + true + ); + } else { + $minimezeDiv = ''; + } + // Defined id. Is usable for span and button. // TODO. Check if will be proper use button or submit when where appropiate. $mainId = ((empty($fixedId) === false) ? $fixedId : 'button-'.$name); if ($imageButton === false) { - $content = ''.$label.''; + $content = $minimezeDiv; + $content .= ''.$label.''; $content .= $iconDiv; } else { - $content = $iconDiv; + $content = $minimezeDiv; + $content .= $iconDiv; } // In case of not selected button type, in this case, will be normal button. @@ -3878,6 +3966,14 @@ function html_print_table(&$table, $return=false) } } + if (isset($table->tdid)) { + foreach ($table->tdid as $keyrow => $tid) { + foreach ($tid as $key => $id) { + $tdid[$keyrow][$key] = $id; + } + } + } + if (isset($table->cellstyle)) { foreach ($table->cellstyle as $keyrow => $cstyle) { foreach ($cstyle as $key => $cst) { @@ -4061,6 +4157,10 @@ function html_print_table(&$table, $return=false) $colspan[$keyrow][$key] = ''; } + if (!isset($tdid[$keyrow][$key])) { + $tdid[$keyrow][$key] = ''; + } + if (!isset($rowspan[$keyrow][$key])) { $rowspan[$keyrow][$key] = ''; } @@ -4081,10 +4181,16 @@ function html_print_table(&$table, $return=false) $style[$key] = ''; } - if ($class === 'datos5' && $key === 1) { - $output .= '
'."\n"; + if ($tdid[$keyrow][$key] !== '') { + $tid = $tdid[$keyrow][$key]; } else { - $output .= ''."\n"; + $tid = $tableid.'-'.$keyrow.'-'.$key; + } + + if ($class === 'datos5' && $key === 1) { + $output .= ''."\n"; + } else { + $output .= ''."\n"; } } @@ -4425,7 +4531,7 @@ function html_print_checkbox_switch_extended( $name.($idcounter[$name] ? $idcounter[$name] : '') ); - $output = '
'; @@ -548,6 +571,11 @@ if ($show_update_action_menu) { ); $data .= '
'; $data .= __('Threshold').ui_print_help_tip(__('If a value of 0 is assigned, the Threshold of the action will be used.'), true); @@ -568,7 +596,7 @@ if ($show_update_action_menu) { false, '', false, - true + false ); $data .= '


${trap['count']}
${trap['first']}
${trap['last']}
${desc_trap_type}
${trap['description']}
${trap['oid']}
${string}${string}
'.$item.''.$item.''.$item.''.$item.'
- logo + + logo +

'.$product_name.'

'.__('Version').' '.$pandora_version.$lts_name.' - '.(enterprise_installed() ? 'Enterprise' : 'Community').'

'.__('MR version').' MR'.$config['MR'].'

-

Build'.$build_version.'

-

'.__('Support expires').''.$license_expiry_date.'

'; +

Build'.$build_version.'

'; + if (enterprise_installed() === true) { + $dialog .= '

'.__('Support expires').''.$license_expiry_date.'

'; + } + + if ($license_expired === false) { + $dialog .= '

'.__('This system has official support, warranty and official updates.').'

'; + } else if (enterprise_installed() === true) { + $dialog .= '

'.__('This system has no active support contract, and has no support, upgrades or warranty.').'

'; + $dialog .= '

'.__('Contact Pandora FMS for expand your support contract.').'

'; + } else { + $dialog .= '

'.__('The OpenSource version has no support or warranty of any kind.').'

'; + $dialog .= '

'.__('Contact Pandora FMS for official support contract.').'

'; + } if (((bool) check_acl($config['id_user'], 0, 'PM') === true) && (is_metaconsole() === false)) { $dialogButtons = []; @@ -1004,7 +1027,7 @@ if (is_ajax()) {
- +
@@ -1224,4 +1247,104 @@ if (is_ajax()) { echo $dialog; } + + if ($about_operation) { + global $config; + global $pandora_version; + global $build_version; + $product_name = io_safe_output(get_product_name()); + $license_expiry_date = substr($config['license_expiry_date'], 0, 4).'/'.substr($config['license_expiry_date'], 4, 2).'/'.substr($config['license_expiry_date'], 6, 2); + $license_expired = false; + $timestamp = strtotime($license_expiry_date); + if ($timestamp < time() || enterprise_installed() === false) { + $license_expired = true; + } + + $lts_name = ''; + if (empty($config['lts_name']) === false) { + $lts_name = ' '.$config['lts_name'].''; + } + + $image_about = ui_get_full_url('/images/custom_logo/logo-default-pandorafms.png', false, false, false); + if (enterprise_installed() === false) { + if ($config['style'] === 'pandora_black') { + $image_about = 'images/custom_logo/'.HEADER_LOGO_BLACK_CLASSIC; + } else if ($config['style'] === 'pandora') { + $image_about = 'images/custom_logo/'.HEADER_LOGO_DEFAULT_CLASSIC; + } + } else { + if ($config['style'] === 'pandora_black' && $config['custom_logo'] === HEADER_LOGO_DEFAULT_CLASSIC) { + $config['custom_logo'] = HEADER_LOGO_BLACK_CLASSIC; + } else if ($config['style'] === 'pandora' && $config['custom_logo'] === HEADER_LOGO_BLACK_CLASSIC) { + $config['custom_logo'] = HEADER_LOGO_DEFAULT_CLASSIC; + } + + $image_about = 'images/custom_logo/'.$config['custom_logo']; + + if (file_exists(ENTERPRISE_DIR.'/'.$image_about) === true) { + $image_about = ENTERPRISE_DIR.'/'.$image_about; + } + } + + if (is_metaconsole() === true) { + $image_about = ui_get_full_url('/enterprise/images/custom_logo/pandoraFMS_metaconsole_full.svg', false, false, false); + + if ($config['meta_custom_logo'] === 'pandoraFMS_metaconsole_full.svg') { + $image_about = 'images/custom_logo/'.$config['meta_custom_logo']; + } else { + $image_about = '../images/custom_logo/'.$config['meta_custom_logo']; + } + + if (file_exists(ENTERPRISE_DIR.'/'.$image_about) === true) { + $image_about = $image_about; + } + } + + + $dialog = ' +
+ + + + + + +
+ + logo + + +

'.$product_name.'

+

'.__('Version').' '.$pandora_version.$lts_name.' - '.(enterprise_installed() ? 'Enterprise' : 'Community').'

+

'.__('MR version').' MR'.$config['MR'].'

+

Build'.$build_version.'

'; + if (enterprise_installed() === true) { + $dialog .= '

'.__('Support expires').''.$license_expiry_date.'

'; + } + + if ($license_expired === false) { + $dialog .= '

'.__('This system has official support, warranty and official updates.').'

'; + } else if (enterprise_installed() === true) { + $dialog .= '

'.__('This system has no active support contract, and has no support, upgrades or warranty.').'

'; + $dialog .= '

'.__('Contact Pandora FMS for expand your support contract.').'

'; + } else { + $dialog .= '

'.__('The OpenSource version has no support or warranty of any kind.').'

'; + $dialog .= '

'.__('Contact Pandora FMS for official support contract.').'

'; + } + + $dialog .= '
+ +
+
+ '; + + echo $dialog; + } } diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 8225d98513..d45bb5c4fc 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -743,7 +743,8 @@ function modules_create_agent_module( string $name, array $values=[], bool $disableACL=false, - $tags=false + $tags=false, + $use_agent_ip=false, ) { global $config; @@ -785,10 +786,14 @@ function modules_create_agent_module( return ERR_EXIST; } + if ($use_agent_ip === true) { + $values['ip_target'] = agents_get_address($id_agent); + } + // Encrypt passwords. if (isset($values['plugin_pass']) === true) { // Avoid two times encryption. - $plugin_pass = io_safe_output($values['plugin_pass']); + $plugin_pass = io_output_password($values['plugin_pass']); $values['plugin_pass'] = io_input_password($plugin_pass); } @@ -3676,6 +3681,10 @@ function get_modules_agents( implode(',', $id_agents) ) ); + + if ($rows === false) { + $rows = []; + } } else { $rows = []; } diff --git a/pandora_console/include/functions_netflow.php b/pandora_console/include/functions_netflow.php index 59d02ccb4f..79fcd9a0db 100644 --- a/pandora_console/include/functions_netflow.php +++ b/pandora_console/include/functions_netflow.php @@ -1233,7 +1233,9 @@ function netflow_draw_item( $max_aggregates, $connection_name='', $output='HTML', - $address_resolution=false + $address_resolution=false, + $width_content=false, + $height_content=false ) { $aggregate = $filter['aggregate']; $interval = ($end_date - $start_date); @@ -1432,6 +1434,9 @@ function netflow_draw_item( netflow_aggregate_is_ip($aggregate) ); + $data_circular['width'] = $width_content; + $data_circular['height'] = $height_content; + $html = '
'; $html .= graph_netflow_circular_mesh($data_circular); $html .= '
'; @@ -1734,7 +1739,12 @@ function netflow_get_top_summary( switch ($top_action) { case 'listeners': if (empty(!$filter)) { - $netflow_filter['ip_src'] = $filter; + if (!is_array($filter)) { + $netflow_filter['ip_src'] = $filter; + } else { + $netflow_filter['ip_src'] = $filter['ip']; + $netflow_filter['advanced_filter'] = $filter['advanced_filter']; + } } $sort = 'dstip'; @@ -1742,7 +1752,12 @@ function netflow_get_top_summary( case 'talkers': if (empty(!$filter)) { - $netflow_filter['ip_dst'] = $filter; + if (!is_array($filter)) { + $netflow_filter['ip_dst'] = $filter; + } else { + $netflow_filter['ip_dst'] = $filter['ip']; + $netflow_filter['advanced_filter'] = $filter['advanced_filter']; + } } $sort = 'srcip'; @@ -2069,7 +2084,7 @@ function netflow_aggregate_is_ip($aggregate) * * @return array With map structure. */ -function netflow_build_map_data($start_date, $end_date, $top, $aggregate) +function netflow_build_map_data($start_date, $end_date, $top, $aggregate, $advanced_filter='') { // Pass an empty filter data structure. $data = netflow_get_relationships_raw_data( @@ -2083,7 +2098,7 @@ function netflow_build_map_data($start_date, $end_date, $top, $aggregate) 'ip_src' => '', 'dst_port' => '', 'src_port' => '', - 'advanced_filter' => '', + 'advanced_filter' => $advanced_filter, 'router_ip' => '', ], $top, diff --git a/pandora_console/include/functions_network_components.php b/pandora_console/include/functions_network_components.php index 14146f7869..64e59ee28b 100644 --- a/pandora_console/include/functions_network_components.php +++ b/pandora_console/include/functions_network_components.php @@ -594,3 +594,26 @@ function network_components_duplicate_network_component($id_local_component) return network_components_create_network_component($name, $network['type'], $network['id_group'], $network); } + + +/** + * Return all children groups recursive include parent. + * + * @param integer $id_parent Id of parent. + * @param array $groups NO setting, array for recursive. + * + * @return array $groups All children ids include first parent. + */ +function network_component_get_groups_recursive($id_parent, $groups=[]) +{ + $groups[] = $id_parent; + $ids = db_get_all_rows_filter('tnetwork_component_group', ['parent' => $id_parent], 'id_sg'); + + if ($ids !== false) { + foreach ($ids as $key => $id) { + $groups = network_component_get_groups_recursive($id['id_sg'], $groups); + } + } + + return $groups; +} diff --git a/pandora_console/include/functions_notifications.php b/pandora_console/include/functions_notifications.php index 2e038c1c64..df458f3ad0 100644 --- a/pandora_console/include/functions_notifications.php +++ b/pandora_console/include/functions_notifications.php @@ -932,7 +932,7 @@ function notifications_print_two_ways_select($info_selec, $users, $source_id) true, [ 'title' => __('Add elements'), - 'style' => 'rotate: 90deg', + 'style' => 'rotate: 180deg', 'onclick' => sprintf( "notifications_modify_two_ways_element('%s', '%s', 'add')", $users, @@ -971,11 +971,7 @@ function notifications_print_two_ways_select($info_selec, $users, $source_id) __('Add'), 'Add', false, - sprintf( - "notifications_add_source_element_to_database('%s', '%s')", - $users, - $source_id - ), + 'notifications_add_source_element_to_database("'.$users.'",'.$source_id.')', "class='sub add'", true ) @@ -1210,6 +1206,12 @@ function notifications_print_dropdown_element($message_info) } $type = explode('.', $message_info['subtype'])[1]; + + if (strlen($body_preview) >= 170) { + $body_preview = substr($body_preview, 0, 150); + $body_preview .= __('. Read More...'); + } + return sprintf( " 0, + 'date_to' => time(), + ]; + + $result = db_process_sql_update( + 'tplanned_downtime', + $values, + ['id' => $id_downtime] + ); + break; default: // Nothing to do. @@ -635,9 +645,13 @@ function planned_downtimes_stop($downtime) foreach ($modules as $module) { $result = db_process_sql_update( 'tagente_modulo', - ['quiet' => 0], [ - 'id_agente_modulo' => $module['id_agent_module'], + 'quiet' => 0, + 'quiet_by_downtime' => 0, + ], + [ + 'quiet_by_downtime' => 1, + 'id_agente_modulo' => $module['id_agent_module'], ] ); @@ -662,32 +676,68 @@ function planned_downtimes_stop($downtime) foreach ($agents as $agent) { $result = db_process_sql_update( 'tagente', - [ - 'disabled' => 0, - 'update_module_count' => 1, - ], + ['update_module_count' => 1], ['id_agente' => $agent['id_agent']] ); - if ($result) { + $result_disabled = db_process_sql_update( + 'tagente', + [ + 'disabled' => 0, + 'disabled_by_downtime' => 0, + ], + [ + 'disabled_by_downtime' => 1, + 'id_agente' => $agent['id_agent'], + ] + ); + + if ($result !== false && $result_disabled !== false) { $count++; } } break; case 'disable_agent_modules': - $update_sql = sprintf( - 'UPDATE tagente_modulo tam, tagente ta, tplanned_downtime_modules tpdm - SET tam.disabled = 0, ta.update_module_count = 1 - WHERE tpdm.id_agent_module = tam.id_agente_modulo AND - ta.id_agente = tam.id_agente AND - tpdm.id_downtime = %d', - $id_downtime + $agents = db_get_all_rows_filter( + 'tplanned_downtime_agents', + ['id_downtime' => $id_downtime] ); + if (empty($agents)) { + $agents = []; + } - db_process_sql($update_sql); + $count = 0; + foreach ($agents as $agent) { + $modules = db_get_all_rows_filter( + 'tplanned_downtime_modules', + [ + 'id_agent' => $agent['id_agent'], + 'id_downtime' => $id_downtime, + ] + ); + if (empty($modules)) { + $modules = []; + } - $count = ''; + foreach ($modules as $module) { + $result = db_process_sql_update( + 'tagente_modulo', + [ + 'disabled' => 0, + 'disabled_by_downtime' => 0, + ], + [ + 'disabled_by_downtime' => 1, + 'id_agente_modulo' => $module['id_agent_module'], + ] + ); + + if ($result !== false) { + $count++; + } + } + } break; case 'disable_agents_alerts': @@ -712,13 +762,17 @@ function planned_downtimes_stop($downtime) foreach ($modules as $module) { $result = db_process_sql_update( 'talert_template_modules', - ['disabled' => 0], [ - 'id_agent_module' => $module['id_agente_modulo'], + 'disabled' => 0, + 'disabled_by_downtime' => 0, + ], + [ + 'disabled_by_downtime' => 1, + 'id_agent_module' => $module['id_agente_modulo'], ] ); - if ($result) { + if ($result !== false) { $count++; } } diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 0871cc1baa..c01e44157a 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -412,6 +412,13 @@ function reporting_make_reporting_data( ); break; + case 'event_report_log_table': + $report['contents'][] = reporting_log_table( + $report, + $content + ); + break; + case 'increment': $report['contents'][] = reporting_increment( $report, @@ -7735,7 +7742,7 @@ function reporting_sql_auxiliary($report, $content, $pdf=false) } $result = db_get_all_rows_sql($sql, $historical_db); - + if ($result !== false) { foreach ($result as $row) { $data_row = []; @@ -14861,7 +14868,13 @@ function reporting_get_stats_servers($filter=[]) 'class' => 'main_menu_icon invert_filter', ] ); - $tdata[1] = ''.html_print_image('images/spinner.gif', true).''; + $sql_count_event = 'SELECT SQL_NO_CACHE COUNT(id_evento) FROM tevento '; + if ($config['event_view_hr']) { + $sql_count_event .= 'WHERE utimestamp > (UNIX_TIMESTAMP(NOW()) - '.($config['event_view_hr'] * SECONDS_1HOUR).')'; + } + + $system_events = db_get_value_sql($sql_count_event); + $tdata[1] = ''.$system_events.''; if (isset($system_events) && $system_events > 50000 && !enterprise_installed()) { $tdata[2] = "
"; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 2f227e430c..91d8a9e5a5 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -259,6 +259,10 @@ function reporting_html_print_report($report, $mini=false, $report_info=1) reporting_html_log($table, $item); break; + case 'event_report_log_table': + reporting_html_log_table($table, $item); + break; + case 'permissions_report': reporting_html_permissions($table, $item); break; diff --git a/pandora_console/include/functions_reports.php b/pandora_console/include/functions_reports.php index 3be975fe2e..f13e935b6a 100755 --- a/pandora_console/include/functions_reports.php +++ b/pandora_console/include/functions_reports.php @@ -944,6 +944,11 @@ function reports_get_report_types($template=false, $not_editor=false) 'optgroup' => __('Log'), 'name' => __('Log report'), ]; + + $types['event_report_log_table'] = [ + 'optgroup' => __('Log'), + 'name' => __('Log report by period'), + ]; } if ($template === false) { diff --git a/pandora_console/include/functions_servers.php b/pandora_console/include/functions_servers.php index f42b791e8f..e4d1f655b0 100644 --- a/pandora_console/include/functions_servers.php +++ b/pandora_console/include/functions_servers.php @@ -964,7 +964,7 @@ function servers_get_info($id_server=-1, $sql_limit=-1) case SERVER_TYPE_NETFLOW: $server['img'] = html_print_image( - 'images/netflow@svg.svg', + 'images/Netflow2@svg.svg', true, [ 'title' => __('Netflow server'), @@ -1411,3 +1411,24 @@ function servers_get_master() return $result; } + + +/** + * Return true if all servers are up. + * + * @return boolean + */ +function check_all_servers_up() +{ + $status = true; + + $servers = servers_get_info(); + + foreach ($servers as $server) { + if ($server['status'] !== '1') { + return false; + } + } + + return $status; +} diff --git a/pandora_console/include/functions_snmp_browser.php b/pandora_console/include/functions_snmp_browser.php index f76e9e3ebc..480d0d865e 100644 --- a/pandora_console/include/functions_snmp_browser.php +++ b/pandora_console/include/functions_snmp_browser.php @@ -716,6 +716,13 @@ function snmp_browser_print_container( $table->size[0] = '30%'; $table->size[1] = '30%'; $table->size[2] = '30%'; + $target_ip = get_parameter('target_ip', ''); + if (str_contains($target_ip, '_')) { + $custom_field = explode('_', $target_ip)[2]; + $agent_alias = get_parameter('agent_alias', ''); + $id_agente = db_get_all_rows_sql('SELECT id_agente FROM tagente WHERE alias = "'.io_safe_output($agent_alias).'"')[0]['id_agente']; + $target_ip = db_get_all_rows_sql('SELECT description FROM tagent_custom_data WHERE id_field = '.$custom_field.' AND id_agent = '.$id_agente)[0]['description']; + } $table->data[0][0] = html_print_label_input_block( __('Target IP'), @@ -723,7 +730,7 @@ function snmp_browser_print_container( [ 'type' => 'text', 'name' => 'target_ip', - 'value' => get_parameter('target_ip', ''), + 'value' => $target_ip, 'required' => true, 'size' => 25, 'maxlength' => 0, @@ -775,7 +782,6 @@ function snmp_browser_print_container( html_print_select( [ '1' => 'v. 1', - '2' => 'v. 2', '2c' => 'v. 2c', '3' => 'v. 3', ], @@ -1284,7 +1290,8 @@ function snmp_browser_create_modules_snmp( string $module_target, array $snmp_values, ?array $id_target, - ?string $server_to_exec=null + ?string $server_to_exec=null, + ?string $use_agent_ip='' ) { $target_ip = null; $target_port = null; @@ -1343,6 +1350,12 @@ function snmp_browser_create_modules_snmp( } } + if (empty($use_agent_ip) === false) { + $use_agent_ip = true; + } else { + $use_agent_ip = false; + } + $fail_modules = []; foreach ($targets_oids as $key => $target_oid) { @@ -1507,7 +1520,7 @@ function snmp_browser_create_modules_snmp( 'history_data' => 1, ]; foreach ($id_target as $agent) { - $ids[] = modules_create_agent_module($agent, $oid['oid'], $values); + $ids[] = modules_create_agent_module($agent, $oid['oid'], $values, false, false, $use_agent_ip); } } else if ($module_target == 'policy') { // Policies only in enterprise version. @@ -1796,6 +1809,16 @@ function snmp_browser_print_create_module_massive( true ); + $table->data[4][0] = html_print_label_input_block( + __('Use agent IP'), + html_print_checkbox( + 'use_agent_ip', + 1, + false, + true + ) + ); + $output .= html_print_table($table, true); // SNMP extradata. diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index b2341ff6c9..90213d96dd 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -795,8 +795,14 @@ function tags_get_acl_tags( $acltags = []; foreach ($raw_acltags as $group => $taglist) { - if (empty($id_group) === false && array_key_exists($group, $id_group) === false) { - continue; + if ($return_mode === 'module_condition') { + if (!empty($id_group) && !in_array($group, $id_group)) { + continue; + } + } else { + if (empty($id_group) === false && array_key_exists($group, $id_group) === false) { + continue; + } } if (!empty($taglist)) { diff --git a/pandora_console/include/functions_treeview.php b/pandora_console/include/functions_treeview.php index 9451e4a196..025276ecef 100755 --- a/pandora_console/include/functions_treeview.php +++ b/pandora_console/include/functions_treeview.php @@ -650,15 +650,28 @@ function treeview_printTable($id_agente, $server_data=[], $no_head=false) // Agent name. $row = []; $row['title'] = __('Agent name'); - $row['data'] = html_print_anchor( - [ - 'href' => $urlAgent, - 'title' => __('Click here for view this agent'), - 'class' => 'font_11', - 'content' => $cellName, - ], - true - ); + if (is_metaconsole() === true) { + $row['data'] = html_print_anchor( + [ + 'href' => 'javascript:void(0)', + 'title' => __('Click here for view this agent'), + 'class' => 'font_11', + 'content' => $cellName, + 'onClick' => "sendHash('".$urlAgent."')", + ], + true + ); + } else { + $row['data'] = html_print_anchor( + [ + 'href' => $urlAgent, + 'title' => __('Click here for view this agent'), + 'class' => 'font_11', + 'content' => $cellName, + ], + true + ); + } $table->data['name'] = $row; @@ -879,11 +892,13 @@ function treeview_printTable($id_agente, $server_data=[], $no_head=false) $table_advanced->head = []; $table_advanced->data = []; - // Agent version. - $row = []; + $row = []; + // Agent version. + if (!empty($agent['agent_version'])) { $row['title'] = __('Agent Version'); $row['data'] = $agent['agent_version']; $table_advanced->data['agent_version'] = $row; + } // Position Information. if ($config['activate_gis']) { @@ -963,7 +978,7 @@ function treeview_printTable($id_agente, $server_data=[], $no_head=false) '', '', true, - false, + empty($table_advanced->data), '', 'white-box-content mrgn_top_0 mrgn_btn_0px border-bottom-gray', 'white_table_flex' @@ -1017,7 +1032,7 @@ function treeview_printTable($id_agente, $server_data=[], $no_head=false) echo " '; - } - $table .= '
'; - $pagination_class = 'pandora_pagination'; - if (!empty($parameters['pagination_class'])) { - $pagination_class = $parameters['pagination_class']; + $parameters['ajax_url_full'] = ui_get_full_url('ajax.php', false, false, false); + + $parameters['spinnerLoading'] = html_print_image( + 'images/spinner.gif', + true, + [ + 'id' => $form_id.'_loading', + 'class' => 'loading-search-datatables-button', + ] + ); + + $language = substr(get_user_language(), 0, 2); + if (is_metaconsole() === false) { + $parameters['language'] = 'include/javascript/i18n/dataTables.'.$language.'.json'; + } else { + $parameters['language'] = '../../include/javascript/i18n/dataTables.'.$language.'.json'; } - $columns = ''; - for ($i = 1; $i <= (count($parameters['columns']) - 3); $i++) { - if ($i != (count($parameters['columns']) - 3)) { - $columns .= $i.','; - } else { - $columns .= $i; - } + $parameters['phpDate'] = date('Y-m-d'); + $parameters['dataElements'] = json_encode($parameters['data_element']); + + // * START JAVASCRIPT. + if (is_metaconsole() === false) { + $file_path = ui_get_full_url('include/javascript/datatablesFunction.js'); + } else { + $file_path = ui_get_full_url('../../include/javascript/datatablesFunction.js'); } - $export_columns = ''; - if (isset($parameters['csv_exclude_latest']) === true - && $parameters['csv_exclude_latest'] === true - ) { - $export_columns = ',columns: \'th:not(:last-child)\''; - } + $file_content = file_get_contents($file_path); + $json_data = json_encode($parameters); + $json_config = json_encode($config); - if (isset($parameters['data_element']) === false || isset($parameters['print_pagination_search_csv'])) { - if (isset($parameters['ajax_url'])) { - $type_data = 'ajax: { - url: "'.ui_get_full_url('ajax.php', false, false, false).'", - type: "POST", - dataSrc: function (json) { - if($("#'.$form_id.'_search_bt") != undefined) { - $("#'.$form_id.'_loading").remove(); - } + $js = ''; - if (json.error) { - console.error(json.error); - $("#error-'.$table_id.'").html(json.error); - $("#error-'.$table_id.'").dialog({ - title: "Filter failed", - width: 630, - resizable: true, - draggable: true, - modal: false, - closeOnEscape: true, - buttons: { - "Ok" : function () { - $(this).dialog("close"); - } - } - }).parent().addClass("ui-state-error"); - } else {'; - - if (isset($parameters['ajax_return_operation']) === true - && empty($parameters['ajax_return_operation']) === false - && isset($parameters['ajax_return_operation_function']) === true - && empty($parameters['ajax_return_operation_function']) === false - ) { - $type_data .= ' - if (json.'.$parameters['ajax_return_operation'].' !== undefined) { - '.$parameters['ajax_return_operation_function'].'(json.'.$parameters['ajax_return_operation'].'); - } - '; - } - - if (isset($parameters['ajax_postprocess'])) { - $type_data .= ' - if (json.data) { - json.data.forEach(function(item) { - '.$parameters['ajax_postprocess'].' - }); - } else { - json.data = {}; - }'; - } - - $type_data .= ' - return json.data; - } - }, - data: function (data) { - if($("#button-'.$form_id.'_search_bt") != undefined) { - var loading = \''.html_print_image( - 'images/spinner.gif', - true, - [ - 'id' => $form_id.'_loading', - 'class' => 'loading-search-datatables-button', - ] - ).'\'; - $("#button-'.$form_id.'_search_bt").parent().append(loading); - } - - inputs = $("#'.$form_id.' :input"); - - values = {}; - inputs.each(function() { - values[this.name] = $(this).val(); - }) - - $.extend(data, { - filter: values,'."\n"; - - if (is_array($parameters['ajax_data'])) { - foreach ($parameters['ajax_data'] as $k => $v) { - $type_data .= $k.':'.json_encode($v).",\n"; - } - } - - $type_data .= 'page: "'.$parameters['ajax_url'].'" - }); - - return data; - } - },'; - } else { - $type_data = 'data: '.json_encode($parameters['data_element']).','; - } - - $serverside = 'true'; - if (isset($parameters['data_element'])) { - $serverside = 'false'; - } - - // Javascript controller. - $js = ''; - } - - // Order. + $js .= ''; + // * END JAVASCRIPT. $info_msg_arr = []; $info_msg_arr['message'] = $emptyTable; $info_msg_arr['div_class'] = 'info_box_container invisible_important datatable-msg-info-'.$table_id; - $spinner = '
'; + $spinner = '
'; + // TODO This widget should take a return: ui_print_info_message($info_msg_arr, '', true) $info_msg = '
'.ui_print_info_message($info_msg_arr).'
'; + $err_msg = '
'; $output = $info_msg.$err_msg.$filter.$extra.$spinner.$table.$js; if (is_ajax() === false) { @@ -4205,7 +4219,7 @@ function ui_print_datatable(array $parameters) false, false ); - $output .= '?v='.$config['current_package'].'"/>'; + $output .= '"/>'; // Load tables.css. $output .= '', $comments); - if (is_array($comments)) { - foreach ($comments as $comm) { - if (empty($comm)) { - continue; - } - - $comments_array[] = io_safe_output(json_decode($comm, true)); - } - } - - $order_utimestamp = array_reduce( - $comments_array, - function ($carry, $item) { - foreach ($item as $k => $v) { - $carry[$v['utimestamp']] = $v; - } - - return $carry; - } - ); - - $key_max_utimestamp = max(array_keys($order_utimestamp)); - - $last_comment = $order_utimestamp[$key_max_utimestamp]; - - if (empty($last_comment) === true) { + if (empty($comment) === true) { return ''; } // Only show the last comment. If commment its too long,the comment will short with ... // If $config['prominent_time'] is timestamp the date show Month, day, hour and minutes. // Else show comments hours ago - if ($last_comment['action'] != 'Added comment') { - $last_comment['comment'] = $last_comment['action']; + if ($comment['action'] != 'Added comment') { + $comment['comment'] = $comment['action']; } - $short_comment = substr($last_comment['comment'], 0, 20); + $short_comment = substr($comment['comment'], 0, 20); if ($config['prominent_time'] == 'timestamp') { - $comentario = ''.date($config['date_format'], $last_comment['utimestamp']).' ('.$last_comment['id_user'].'): '.$last_comment['comment'].''; + $comentario = ''.date($config['date_format'], $comment['utimestamp']).' ('.$comment['id_user'].'): '.$comment['comment'].''; - if (strlen($comentario) > '200px') { - $comentario = ''.date($config['date_format'], $last_comment['utimestamp']).' ('.$last_comment['id_user'].'): '.$short_comment.'...'; + if (strlen($comentario) > '200px' && $truncate_limit >= 255) { + $comentario = ''.date($config['date_format'], $comment['utimestamp']).' ('.$comment['id_user'].'): '.$short_comment.'...'; } } else { - $rest_time = (time() - $last_comment['utimestamp']); + $rest_time = (time() - $comment['utimestamp']); $time_last = (($rest_time / 60) / 60); - $comentario = ''.number_format($time_last, 0, $config['decimal_separator'], ($config['thousand_separator'] ?? ',')).'  Hours  ('.$last_comment['id_user'].'): '.$last_comment['comment'].''; + $comentario = ''.number_format($time_last, 0, $config['decimal_separator'], ($config['thousand_separator'] ?? ',')).'  Hours  ('.$comment['id_user'].'): '.$comment['comment'].''; - if (strlen($comentario) > '200px') { - $comentario = ''.number_format($time_last, 0, $config['decimal_separator'], ($config['thousand_separator'] ?? ',')).'  Hours  ('.$last_comment['id_user'].'): '.$short_comment.'...'; + if (strlen($comentario) > '200px' && $truncate_limit >= 255) { + $comentario = ''.number_format($time_last, 0, $config['decimal_separator'], ($config['thousand_separator'] ?? ',')).'  Hours  ('.$comment['id_user'].'): '.$short_comment.'...'; } } - return io_safe_output($comentario); + $comentario = io_safe_output($comentario); + if (strlen($comentario) >= $truncate_limit) { + $comentario = ui_print_truncate_text( + $comentario, + $truncate_limit, + false, + true, + false, + '…', + true, + true, + ); + } + + return $comentario; } @@ -7974,6 +7978,133 @@ function ui_print_fav_menu($id_element, $url, $label, $section) } +function ui_print_tree( + $tree, + $id=0, + $depth=0, + $last=0, + $last_array=[], + $sufix=false, + $descriptive_ids=false, + $previous_id='' +) { + static $url = false; + $output = ''; + + // Get the base URL for images. + if ($url === false) { + $url = ui_get_full_url('operation/tree', false, false, false); + } + + // Leaf. + if (empty($tree['__LEAVES__'])) { + return ''; + } + + $count = 0; + $total = (count(array_keys($tree['__LEAVES__'])) - 1); + $last_array[$depth] = $last; + $class = 'item_'.$depth; + + if ($depth > 0) { + $output .= '