diff --git a/extras/deploy-scripts/pandora_deploy_community.sh b/extras/deploy-scripts/pandora_deploy_community.sh index 0601c90688..fe4af3d924 100644 --- a/extras/deploy-scripts/pandora_deploy_community.sh +++ b/extras/deploy-scripts/pandora_deploy_community.sh @@ -170,7 +170,7 @@ http://rpms.remirepo.net/enterprise/remi-release-7.rpm \ https://repo.percona.com/yum/percona-release-latest.noarch.rpm" execute_cmd "yum install -y $extra_repos" "Installing extra repositories" -execute_cmd "yum-config-manager --enable remi-php74" "Configuring PHP" +execute_cmd "yum-config-manager --enable remi-php80" "Configuring PHP" # Install percona Database #[ -f /etc/my.cnf ] && rm -rf /etc/my.cnf diff --git a/extras/deploy-scripts/pandora_deploy_community_el8.sh b/extras/deploy-scripts/pandora_deploy_community_el8.sh index 7c55b91ed2..fd4855f67b 100644 --- a/extras/deploy-scripts/pandora_deploy_community_el8.sh +++ b/extras/deploy-scripts/pandora_deploy_community_el8.sh @@ -20,7 +20,7 @@ LOGFILE="/tmp/pandora-deploy-community-$(date +%F).log" # define default variables [ "$TZ" ] || TZ="Europe/Madrid" [ "$MYVER" ] || MYVER=57 -[ "$PHPVER" ] || PHPVER=7 +[ "$PHPVER" ] || PHPVER=8 [ "$DBHOST" ] || DBHOST=127.0.0.1 [ "$DBNAME" ] || DBNAME=pandora [ "$DBUSER" ] || DBUSER=pandora diff --git a/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh b/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh index 7c78908878..feced2cbe7 100644 --- a/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh +++ b/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh @@ -21,7 +21,7 @@ LOGFILE="/tmp/pandora-deploy-community-$(date +%F).log" # define default variables [ "$TZ" ] || TZ="Europe/Madrid" -[ "$PHPVER" ] || PHPVER=7.4 +[ "$PHPVER" ] || PHPVER=8.0 [ "$DBHOST" ] || DBHOST=127.0.0.1 [ "$DBNAME" ] || DBNAME=pandora [ "$DBUSER" ] || DBUSER=pandora @@ -138,6 +138,9 @@ check_root_permissions # Connectivity check_repo_connection +#Install awk, sed, grep if not present +execute_cmd "apt install -y gawk sed grep" 'Installing needed tools' + # Systemd execute_cmd "systemctl --version" "Checking SystemD" 'This is not a SystemD enable system, if tryng to use in a docker env please check: https://github.com/pandorafms/pandorafms/tree/develop/extras/docker/centos8' @@ -155,7 +158,7 @@ execute_cmd "timedatectl set-timezone $TZ" "Setting Timezone $TZ" execute_cmd "awk --version" 'Checking needed tools: awk' execute_cmd "grep --version" 'Checking needed tools: grep' execute_cmd "sed --version" 'Checking needed tools: sed' -execute_cmd "apt --version" 'Checking needed tools: dnf' +execute_cmd "apt --version" 'Checking needed tools: apt' # Creating working directory rm -rf "$WORKDIR" &>> "$LOGFILE" diff --git a/pandora_agents/pc/tentacle_server b/pandora_agents/pc/tentacle_server index d945a134e8..4458237003 100755 --- a/pandora_agents/pc/tentacle_server +++ b/pandora_agents/pc/tentacle_server @@ -5,7 +5,7 @@ # Tentacle have IANA assigned port tpc/41121 as official port. ########################################################################## # Copyright (c) 2007-2008 Ramon Novoa -# Copyright (c) 2005-2010 Artica Soluciones Tecnologicas S.L +# Copyright (c) 2005-2022 Artica Soluciones Tecnologicas S.L # # tentacle_server.pl Tentacle Server. See https://pandorafms.com/docs/ for # protocol description. @@ -1740,6 +1740,19 @@ sub callback_stop { Win32::Daemon::StopService(); } + +################################################################################ +## SUB check_ssleay_version +## Print a message if the installed version of Net::SSLeay may leak memory. +################################################################################ +sub check_ssleay_version { + eval { + require Net::SSLeay; + return unless defined($Net::SSLeay::VERSION) && $Net::SSLeay::VERSION =~ m/^(\d+)\.(\d+)/ && $1 <= 1 && $2 < 88; + print_log ("Net::SSLeay version $Net::SSLeay::VERSION detected. Versions prior to 1.88 may leak memory. To upgrade it see: https://metacpan.org/pod/Net::SSLeay"); + }; +} + ################################################################################ # Main ################################################################################ @@ -1753,12 +1766,20 @@ if ($> == 0 && $^O ne 'MSWin32') { # Parse command line options parse_options (); +# Try to open the log file. +if (defined($log_file)) { + open(my $fh, ">>", $log_file) || die("Error opening the log file '$log_file': $!.\n"); + close($fh); +} + # Check command line arguments if ($#ARGV != -1) { print_help (); exit 1; } +check_ssleay_version() if $t_ssl == 1; + # Show IPv6 status if ($SOCKET_MODULE eq 'IO::Socket::INET') { print_log ("IO::Socket::INET6 is not found. IPv6 is disabled."); diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control index 6f0ae93823..d8dc7bb0d0 100644 --- a/pandora_agents/unix/DEBIAN/control +++ b/pandora_agents/unix/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-agent-unix -Version: 7.0NG.765-221020 +Version: 7.0NG.765-221031 Architecture: all Priority: optional Section: admin diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh index 6cabe80795..a0f3e6e3d1 100644 --- a/pandora_agents/unix/DEBIAN/make_deb_package.sh +++ b/pandora_agents/unix/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.765-221020" +pandora_version="7.0NG.765-221031" echo "Test if you has the tools for to make the packages." whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index f2231c3a22..78cfe16c52 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -1015,7 +1015,7 @@ my $Sem = undef; my $ThreadSem = undef; use constant AGENT_VERSION => '7.0NG.765'; -use constant AGENT_BUILD => '221020'; +use constant AGENT_BUILD => '221031'; # Agent log default file size maximum and instances use constant DEFAULT_MAX_LOG_SIZE => 600000; diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec index 0df77e7444..472638398d 100644 --- a/pandora_agents/unix/pandora_agent.redhat.spec +++ b/pandora_agents/unix/pandora_agent.redhat.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.765 -%define release 221020 +%define release 221031 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec index d4e1993594..541c0c05f2 100644 --- a/pandora_agents/unix/pandora_agent.spec +++ b/pandora_agents/unix/pandora_agent.spec @@ -3,7 +3,7 @@ # %define name pandorafms_agent_unix %define version 7.0NG.765 -%define release 221020 +%define release 221031 Summary: Pandora FMS Linux agent, PERL version Name: %{name} diff --git a/pandora_agents/unix/pandora_agent_installer b/pandora_agents/unix/pandora_agent_installer index 745ce5ca0a..bde3b55ff2 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -10,7 +10,7 @@ # ********************************************************************** PI_VERSION="7.0NG.765" -PI_BUILD="221020" +PI_BUILD="221031" OS_NAME=`uname -s` FORCE=0 diff --git a/pandora_agents/unix/tentacle_server b/pandora_agents/unix/tentacle_server index d945a134e8..4458237003 100755 --- a/pandora_agents/unix/tentacle_server +++ b/pandora_agents/unix/tentacle_server @@ -5,7 +5,7 @@ # Tentacle have IANA assigned port tpc/41121 as official port. ########################################################################## # Copyright (c) 2007-2008 Ramon Novoa -# Copyright (c) 2005-2010 Artica Soluciones Tecnologicas S.L +# Copyright (c) 2005-2022 Artica Soluciones Tecnologicas S.L # # tentacle_server.pl Tentacle Server. See https://pandorafms.com/docs/ for # protocol description. @@ -1740,6 +1740,19 @@ sub callback_stop { Win32::Daemon::StopService(); } + +################################################################################ +## SUB check_ssleay_version +## Print a message if the installed version of Net::SSLeay may leak memory. +################################################################################ +sub check_ssleay_version { + eval { + require Net::SSLeay; + return unless defined($Net::SSLeay::VERSION) && $Net::SSLeay::VERSION =~ m/^(\d+)\.(\d+)/ && $1 <= 1 && $2 < 88; + print_log ("Net::SSLeay version $Net::SSLeay::VERSION detected. Versions prior to 1.88 may leak memory. To upgrade it see: https://metacpan.org/pod/Net::SSLeay"); + }; +} + ################################################################################ # Main ################################################################################ @@ -1753,12 +1766,20 @@ if ($> == 0 && $^O ne 'MSWin32') { # Parse command line options parse_options (); +# Try to open the log file. +if (defined($log_file)) { + open(my $fh, ">>", $log_file) || die("Error opening the log file '$log_file': $!.\n"); + close($fh); +} + # Check command line arguments if ($#ARGV != -1) { print_help (); exit 1; } +check_ssleay_version() if $t_ssl == 1; + # Show IPv6 status if ($SOCKET_MODULE eq 'IO::Socket::INET') { print_log ("IO::Socket::INET6 is not found. IPv6 is disabled."); diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi index 8ae5743490..7f9661be31 100644 --- a/pandora_agents/win32/installer/pandora.mpi +++ b/pandora_agents/win32/installer/pandora.mpi @@ -186,7 +186,7 @@ UpgradeApplicationID {} Version -{221020} +{221031} ViewReadme {Yes} diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc index 0072c2f178..744db55014 100644 --- a/pandora_agents/win32/pandora.cc +++ b/pandora_agents/win32/pandora.cc @@ -30,7 +30,7 @@ using namespace Pandora; using namespace Pandora_Strutils; #define PATH_SIZE _MAX_PATH+1 -#define PANDORA_VERSION ("7.0NG.765 Build 221020") +#define PANDORA_VERSION ("7.0NG.765 Build 221031") string pandora_path; string pandora_dir; diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc index 8b3317b378..c605d5cd56 100644 --- a/pandora_agents/win32/versioninfo.rc +++ b/pandora_agents/win32/versioninfo.rc @@ -11,7 +11,7 @@ BEGIN VALUE "LegalCopyright", "Artica ST" VALUE "OriginalFilename", "PandoraAgent.exe" VALUE "ProductName", "Pandora FMS Windows Agent" - VALUE "ProductVersion", "(7.0NG.765(Build 221020))" + VALUE "ProductVersion", "(7.0NG.765(Build 221031))" VALUE "FileVersion", "1.0.0.0" END END diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control index 1c311e17d2..c9bba1919b 100644 --- a/pandora_console/DEBIAN/control +++ b/pandora_console/DEBIAN/control @@ -1,5 +1,5 @@ package: pandorafms-console -Version: 7.0NG.765-221020 +Version: 7.0NG.765-221031 Architecture: all Priority: optional Section: admin diff --git a/pandora_console/DEBIAN/make_deb_package.sh b/pandora_console/DEBIAN/make_deb_package.sh index 27051ef7a3..611b5410bc 100644 --- a/pandora_console/DEBIAN/make_deb_package.sh +++ b/pandora_console/DEBIAN/make_deb_package.sh @@ -14,7 +14,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -pandora_version="7.0NG.765-221020" +pandora_version="7.0NG.765-221031" package_pear=0 package_pandora=1 diff --git a/pandora_console/extras/mr/58.sql b/pandora_console/extras/mr/58.sql index 83d16c09fc..05f3563be5 100644 --- a/pandora_console/extras/mr/58.sql +++ b/pandora_console/extras/mr/58.sql @@ -1,5 +1,7 @@ START TRANSACTION; +ALTER TABLE `tlayout` ADD COLUMN `maintenance_mode` TEXT; + ALTER TABLE `tusuario` ADD COLUMN `auth_token_secret` VARCHAR(45) DEFAULT NULL; ALTER TABLE `tmodule_inventory` ADD COLUMN `script_mode` INT NOT NULL DEFAULT 2; @@ -7,6 +9,8 @@ ALTER TABLE `tmodule_inventory` ADD COLUMN `script_path` VARCHAR(1000) DEFAULT ' ALTER TABLE `tevent_filter` ADD COLUMN `search_recursive_groups` INT NOT NULL DEFAULT 0; +ALTER TABLE `tcredential_store` MODIFY COLUMN `product` ENUM('CUSTOM', 'AWS', 'AZURE', 'GOOGLE', 'SAP', 'WMI', 'SNMP') DEFAULT 'CUSTOM'; + ALTER TABLE `talert_template_modules` DROP INDEX `id_agent_module`; ALTER TABLE `talert_template_modules` ADD UNIQUE (`id_agent_module`, `id_alert_template`, `id_policy_alerts`); diff --git a/pandora_console/general/register.php b/pandora_console/general/register.php index e71c96fb0f..1c8249ddf5 100644 --- a/pandora_console/general/register.php +++ b/pandora_console/general/register.php @@ -167,7 +167,7 @@ if (!$double_auth_enabled resizable: true, draggable: true, modal: true, - title: "", + title: "", overlay: { opacity: 0.5, background: "black" diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index 6cfa2685b4..b63392ac4c 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -40,16 +40,7 @@ require_once $config['homedir'].'/include/functions_modules.php'; require_once $config['homedir'].'/include/functions_agents.php'; require_once $config['homedir'].'/include/functions_servers.php'; -$search_string = io_safe_output( - urldecode( - trim( - get_parameter( - 'search_string', - '' - ) - ) - ) -); +$search_string = get_parameter('search_string'); global $policy_page; diff --git a/pandora_console/godmode/agentes/module_manager_editor_network.php b/pandora_console/godmode/agentes/module_manager_editor_network.php index 6109445d29..4a39db6d75 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_network.php +++ b/pandora_console/godmode/agentes/module_manager_editor_network.php @@ -140,6 +140,49 @@ if ($id_module_type >= 6 && $id_module_type <= 7) { push_table_simple($data, 'target_ip'); +$user_groups = users_get_groups(false, 'AR'); +if (users_is_admin() === true || isset($user_groups[0]) === true) { + $credentials = db_get_all_rows_sql( + 'SELECT identifier FROM tcredential_store WHERE product LIKE "SNMP"' + ); +} else { + $credentials = db_get_all_rows_sql( + sprintf( + 'SELECT identifier FROM tcredential_store WHERE product LIKE "SNMP" AND id_group IN (%s)', + implode(',', array_keys($user_groups)) + ) + ); +} + +if (empty($credentials) === false) { + $fields = []; + foreach ($credentials as $key => $value) { + $fields[$value['identifier']] = $value['identifier']; + } + + $data = []; + $data[0] = __('Credential store'); + $data[1] = html_print_select( + $fields, + 'credentials', + 0, + '', + __('None'), + 0, + true, + false, + false, + '', + false, + false, + '', + false + ); + + push_table_simple($data, 'snmp_credentials'); +} + + $snmp_versions['1'] = 'v. 1'; $snmp_versions['2'] = 'v. 2'; $snmp_versions['2c'] = 'v. 2c'; @@ -316,6 +359,7 @@ if ($id_module_type < 15 || $id_module_type > 18) { // NOT SNMP. $table_simple->rowstyle['snmp_1'] = 'display: none'; $table_simple->rowstyle['snmp_2'] = 'display: none'; + $table_simple->rowstyle['snmp_credentials'] = 'display: none'; } // For a policy. @@ -569,6 +613,49 @@ $(document).ready (function () { $(this).css ("width", "180px"); }); + $("#credentials").change (function() { + if ($('#credentials').val() !== '0') { + $.ajax({ + method: "post", + url: "", + data: { + page: "godmode/agentes/agent_wizard", + method: "getCredentials", + identifier: $('#credentials').val() + }, + datatype: "json", + success: function(data) { + data = JSON.parse(data); + extra = JSON.parse(data['extra_1']); + $('#snmp_version').val(extra['version']); + $('#snmp_version').trigger('change'); + $('#text-snmp_community').val(extra['community']); + + if (extra['version'] === '3') { + $('#snmp3_security_level').val(extra['securityLevelV3']); + $('#snmp3_security_level').trigger('change'); + $('#text-snmp3_auth_user').val(extra['authUserV3']); + + if (extra['securityLevelV3'] === 'authNoPriv' || extra['securityLevelV3'] === 'authPriv') { + $('#snmp3_auth_method').val(extra['authMethodV3']); + $('#snmp3_auth_method').trigger('change'); + $('#password-snmp3_auth_pass').val(extra['authPassV3']); + + if (extra['securityLevelV3'] === 'authPriv') { + $('#snmp3_privacy_method').val(extra['privacyMethodV3']); + $('#snmp3_privacy_method').trigger('change'); + $('#password-snmp3_privacy_pass').val(extra['privacyPassV3']); + } + } + } + }, + error: function(e) { + console.error(e); + } + }); + } + }); + $("#id_module_type").click ( function () { $(this).css ("width", "auto"); diff --git a/pandora_console/godmode/events/event_edit_filter.php b/pandora_console/godmode/events/event_edit_filter.php index 2e7e009686..af086d55d7 100644 --- a/pandora_console/godmode/events/event_edit_filter.php +++ b/pandora_console/godmode/events/event_edit_filter.php @@ -442,8 +442,12 @@ $table->data[10][1] = html_print_select( true ); -$repeated_sel[0] = __('All events'); -$repeated_sel[1] = __('Group events'); +$repeated_sel = [ + EVENT_GROUP_REP_ALL => __('All events'), + EVENT_GROUP_REP_EVENTS => __('Group events'), + EVENT_GROUP_REP_AGENTS => __('Group agents'), + EVENT_GROUP_REP_EXTRAIDS => __('Group extra id'), +]; $table->data[11][0] = ''.__('Repeated').''; $table->data[11][1] = html_print_select( $repeated_sel, diff --git a/pandora_console/godmode/massive/massive_delete_profiles.php b/pandora_console/godmode/massive/massive_delete_profiles.php index 3a8611f3c7..7c45b2a285 100644 --- a/pandora_console/godmode/massive/massive_delete_profiles.php +++ b/pandora_console/godmode/massive/massive_delete_profiles.php @@ -141,6 +141,7 @@ if ($table !== null) { unset($table); +$table = new stdClass(); $table->width = '100%'; $table->class = 'databox filters'; $table->data = []; diff --git a/pandora_console/godmode/massive/massive_edit_users.php b/pandora_console/godmode/massive/massive_edit_users.php new file mode 100644 index 0000000000..2f1cbeb4fe --- /dev/null +++ b/pandora_console/godmode/massive/massive_edit_users.php @@ -0,0 +1,717 @@ +'.__('metaconsole').''; + } else { + $url = __('any node'); + } + + ui_print_warning_message( + __( + 'This node is configured with centralized mode. All profiles user information is read only. Go to %s to manage it.', + $url + ) + ); + + return; +} + +if (is_metaconsole() === true) { + include_once $config['homedir'].'/include/functions_visual_map.php'; + open_meta_frame(); +} + +$edit_users = (int) get_parameter('edit_users'); +if ($edit_users === 1) { + $users = get_parameter('id_users', false, false); + if ($users !== false) { + $update = []; + + $language = (string) get_parameter('language', '-1'); + if ($language !== '-1') { + $update['language'] = $language; + } + + $block_size_change = (int) get_parameter('block_size_change'); + if ($block_size_change === 0) { + $block_size = (int) get_parameter('block_size', -1); + if ($block_size !== -1) { + $update['block_size'] = $block_size; + } + } + + $section = get_parameter('section', '-1'); + if ($section !== '-1') { + $update['section'] = $section; + } + + $data_section = get_parameter('data_section', ''); + $dashboard = get_parameter('dashboard', ''); + $visual_console = get_parameter('visual_console', ''); + $section = io_safe_output($section); + + if (($section === 'Event list') || ($section === 'Group view') + || ($section === 'Alert detail') || ($section === 'Tactical view') + || ($section === 'Default') + ) { + $update['data_section'] = ''; + } else if ($section === 'Dashboard') { + $update['data_section'] = $dashboard; + } else if ($section === 'Visual console') { + $update['data_section'] = $visual_console; + } + + $event = (int) get_parameter('event_filter', -1); + if ($event !== -1) { + $update['default_event_filter'] = $event; + } + + $autorefresh_list = get_parameter_post('autorefresh_list', [0 => '-1']); + if ($autorefresh_list[0] !== '-1') { + if (($autorefresh_list[0] === '') || ($autorefresh_list[0] === '0')) { + $update['autorefresh_white_list'] = ''; + } else { + $update['autorefresh_white_list'] = json_encode($autorefresh_list); + } + } + + $time_autorefresh = (int) get_parameter('time_autorefresh', -1); + if ($time_autorefresh !== -1) { + $update['time_autorefresh'] = $time_autorefresh; + } + + $timezone = (string) get_parameter('timezone', '-1'); + if ($timezone !== '-1') { + $update['timezone'] = $timezone; + } + + $disabled = (int) get_parameter('disabled', -1); + if ($disabled !== -1) { + $update['disabled'] = $disabled; + } + + $error = []; + $success = []; + foreach ($users as $key => $user) { + if (empty($update) === false) { + $result = update_user($user, $update); + if ($result === false) { + $error[] = $user; + } else { + $success[] = $user; + } + } else { + $error[] = $user; + } + } + + if (empty($success) === false) { + ui_print_success_message( + __( + 'Users updated successfully (%s)', + implode( + ',', + $success + ) + ) + ); + } + + if (empty($error) === false) { + ui_print_error_message( + __( + 'Users cannot be updated (%s)', + implode(',', $error) + ) + ); + } + } +} + +if (is_metaconsole() === false) { + include 'include/javascript/timezonepicker/includes/parser.inc'; + + // Read in options for map builder. + $bases = [ + 'gray' => 'Gray', + 'blue-marble' => 'Blue marble', + 'night-electric' => 'Night Electric', + 'living' => 'Living Earth', + ]; + + $local_file = 'include/javascript/timezonepicker/images/gray-400.png'; + + // Dimensions must always be exact since the imagemap does not scale. + $array_size = getimagesize($local_file); + + $map_width = $array_size[0]; + $map_height = $array_size[1]; + + $timezones = timezone_picker_parse_files( + $map_width, + $map_height, + 'include/javascript/timezonepicker/tz_world.txt', + 'include/javascript/timezonepicker/tz_islands.txt' + ); +} + + +$get_users = get_users(); +$users = []; +if (empty($get_users) === false) { + foreach ($get_users as $key => $value) { + $users[$key] = $key; + } +} + +$users_div = '

'.__('Users').'

'; +$users_div .= html_print_select( + $users, + 'id_users[]', + 0, + false, + '', + '', + true, + true, + true, + '', + false, + '', + false, + false, + false, + '', + false, + false, + false, + false, + true, + true, + true +).'
'; +echo '
'; +echo '
'; +echo '
'.$users_div.'
'; +echo '
'; + +// Language. +$language_db = db_get_all_rows_sql('SELECT id_language, name FROM tlanguage'); +array_unshift($language_db, ['id_language' => 'default', 'name' => __('Default')]); +$language_list = []; +foreach ($language_db as $key => $value) { + $language_list[$value['id_language']] = $value['name']; +} + +$language = '

'.__('Language').'

'; +$language .= html_print_select( + $language_list, + 'language', + '', + '', + __('No change'), + -1, + true, + false, + false +).'
'; + +// Pagination. +$block_size = $config['global_block_size']; +$size_pagination = '

'.__('Block size for pagination').'

'; +$size_pagination .= html_print_input_text('block_size', $block_size, '', 5, 5, true); +$size_pagination .= html_print_checkbox_switch('block_size_change', 1, 1, true); +$size_pagination .= ''.__('No change').''; +$size_pagination .= '
'; + +// Home screen. +$home_screen = '

'.__('Home screen').ui_print_help_tip(__('User can customize the home page. By default, will display \'Agent Detail\'. Example: Select \'Other\' and type index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=1 to show agent detail view'), true).'

'; +$values = [ + '-1' => __('No change'), + 'Default' => __('Default'), + 'Visual console' => __('Visual console'), + 'Event list' => __('Event list'), + 'Group view' => __('Group view'), + 'Tactical view' => __('Tactical view'), + 'Alert detail' => __('Alert detail'), + 'Other' => __('Other'), + 'Dashboard' => __('Dashboard'), +]; + +$home_screen .= html_print_select( + $values, + 'section', + '', + 'show_data_section();', + '', + -1, + true, + false, + false, + '', + false, + '', + '', + 10 +).'
'; + +$dashboards = get_user_dashboards($config['id_user']); + +$dashboards_aux = []; +if ($dashboards === false) { + $dashboards = ['None' => 'None']; +} else { + foreach ($dashboards as $key => $dashboard) { + $dashboards_aux[$dashboard['id']] = $dashboard['name']; + } +} + +$home_screen .= ''; + +$layouts = visual_map_get_user_layouts($config['id_user'], true); +$layouts_aux = []; +if (empty($layouts) === true) { + $layouts_aux = ['None' => 'None']; +} else { + foreach ($layouts as $layout) { + $layouts_aux[$layout] = $layout; + } +} + +$home_screen .= ''; +$home_screen .= html_print_input_text('data_section', '', '', 60, 255, true, false); + + +// Event filter. +$user_groups = implode(',', array_keys((users_get_groups($config['id_user'], 'AR', true)))); +$event_list = db_get_all_rows_sql('SELECT id_filter, id_name AS name FROM tevent_filter WHERE id_group_filter IN ('.$user_groups.')'); +if (empty($event_list) === true) { + $event_list = []; +} + +array_unshift($event_list, ['id_filter' => 'none', 'name' => __('None')]); + +$event_filter = '

'.__('Event filter').'

'; +$event_filter .= html_print_select( + $event_list, + 'event_filter', + '', + '', + __('No change'), + -1, + true, + false, + false +).'
'; + +// Autorefresh. +$autorefresh_list_out = []; +if (is_metaconsole() === false || is_centralized() === true) { + $autorefresh_list_out['operation/agentes/estado_agente'] = 'Agent detail'; + $autorefresh_list_out['operation/agentes/alerts_status'] = 'Alert detail'; + $autorefresh_list_out['enterprise/operation/cluster/cluster'] = 'Cluster view'; + $autorefresh_list_out['operation/gis_maps/render_view'] = 'Gis Map'; + $autorefresh_list_out['operation/reporting/graph_viewer'] = 'Graph Viewer'; + $autorefresh_list_out['operation/snmpconsole/snmp_view'] = 'SNMP console'; + + if (enterprise_installed()) { + $autorefresh_list_out['general/sap_view'] = 'SAP view'; + } +} + +$autorefresh_list_out['operation/agentes/tactical'] = 'Tactical view'; +$autorefresh_list_out['operation/agentes/group_view'] = 'Group view'; +$autorefresh_list_out['operation/agentes/status_monitor'] = 'Monitor detail'; +$autorefresh_list_out['enterprise/operation/services/services'] = 'Services'; +$autorefresh_list_out['operation/dashboard/dashboard'] = 'Dashboard'; + +$autorefresh_list_out['operation/agentes/pandora_networkmap'] = 'Network map'; +$autorefresh_list_out['operation/visual_console/render_view'] = 'Visual console'; +$autorefresh_list_out['operation/events/events'] = 'Events'; + +$autorefresh_show = '

'._('Autorefresh').ui_print_help_tip( + __('This will activate autorefresh in selected pages'), + true +).'

'; +$select_out = html_print_select( + $autorefresh_list_out, + 'autorefresh_list_out[]', + '', + '', + '', + '', + true, + true, + true, + '', + false, + 'width:100%;min-height: 150px;' +); +$arrows = ' '; +$autorefresh_list = []; +$autorefresh_list['-1'] = __('No change'); +$autorefresh_list[] = __('None'); + +$select_in = html_print_select( + $autorefresh_list, + 'autorefresh_list[]', + '-1', + '', + '', + '', + true, + true, + true, + '', + false, + 'width:100%;min-height: 150px;' +); + +$table_ichanges = ''; + +$autorefresh_show .= $table_ichanges; + +// Time autorefresh. +$times = get_refresh_time_array(); +$time_autorefresh = '

'.__('Time autorefresh'); +$time_autorefresh .= ui_print_help_tip( + __('Interval of autorefresh of the elements, by default they are 30 seconds, needing to enable the autorefresh first'), + true +).'

'; +$time_autorefresh .= html_print_select( + $times, + 'time_autorefresh', + '', + '', + __('No change'), + '-1', + true, + false, + false +).'
'; + +$timezone = '

'.__('Timezone').ui_print_help_tip(__('The timezone must be that of the associated server.'), true).'

'; +$timezone .= html_print_timezone_select('timezone', '-1', __('No change'), '-1').'
'; +$timezone_map = ''; + +if (is_metaconsole() === false) { + foreach ($timezones as $timezone_name => $tz) { + if ($timezone_name == 'America/Montreal') { + $timezone_name = 'America/Toronto'; + } else if ($timezone_name == 'Asia/Chongqing') { + $timezone_name = 'Asia/Shanghai'; + } + + $area_data_timezone_polys .= ''; + foreach ($tz['polys'] as $coords) { + $area_data_timezone_polys .= ''; + } + + $area_data_timezone_rects .= ''; + foreach ($tz['rects'] as $coords) { + $area_data_timezone_rects .= ''; + } + } + + $timezone_map = '
+ + + '.$area_data_timezone_polys.$area_data_timezone_rects.' +
'; +} + +// Status (Disable / Enable). +$status = '
'; +$status .= '

'.__('Status').'

'; + +$table = new StdClass(); +$table->width = '100%'; +$table->class = 'databox filters'; + +$table->data[0][0] = __('No change'); +$table->data[0][0] .= html_print_radio_button_extended( + 'disabled', + -1, + '', + -1, + false, + '', + 'class="mrgn_right_40px"', + true +); +$table->data[0][0] .= __('Disable'); +$table->data[0][0] .= html_print_radio_button_extended( + 'disabled', + 1, + '', + '', + false, + '', + 'class="mrgn_right_40px"', + true +); +$table->data[0][0] .= __('Enable'); +$table->data[0][0] .= html_print_radio_button_extended( + 'disabled', + 0, + '', + '', + false, + '', + 'class="mrgn_right_40px"', + true +); + +$status .= html_print_table($table, true); + +echo ''; + +attachActionButton('edit_users', 'update', '100%'); + +echo ''; + +if (is_metaconsole() === false) { + // Include OpenLayers and timezone user map library. + echo ''."\n\t"; + echo ''."\n\t"; + // Closes no meta condition. + ?> + + + + + + \ No newline at end of file diff --git a/pandora_console/godmode/massive/massive_operations.php b/pandora_console/godmode/massive/massive_operations.php index 49b151b7d4..1bc1d60e85 100755 --- a/pandora_console/godmode/massive/massive_operations.php +++ b/pandora_console/godmode/massive/massive_operations.php @@ -70,10 +70,16 @@ $options_agents = [ ]; if (check_acl($config['id_user'], 0, 'UM')) { - $options_users = [ - 'add_profiles' => __('Bulk profile add'), - 'delete_profiles' => __('Bulk profile delete'), - ]; + if (is_metaconsole() === false) { + $options_users = [ + 'add_profiles' => __('Bulk profile add'), + 'delete_profiles' => __('Bulk profile delete'), + ]; + } + + if (users_is_admin() === true) { + $options_users['edit_users'] = __('Edit users in bulk'); + } } else { $options_users = []; } @@ -479,6 +485,10 @@ switch ($option) { include_once $config['homedir'].'/godmode/massive/massive_edit_plugins.php'; break; + case 'edit_users': + include_once $config['homedir'].'/godmode/massive/massive_edit_users.php'; + break; + default: if (!enterprise_hook('massive_operations', [$option])) { include_once $config['homedir'].'/godmode/massive/massive_config.php'; diff --git a/pandora_console/godmode/setup/setup_auth.php b/pandora_console/godmode/setup/setup_auth.php index e1318f96c2..0a93a36da2 100644 --- a/pandora_console/godmode/setup/setup_auth.php +++ b/pandora_console/godmode/setup/setup_auth.php @@ -199,6 +199,21 @@ if (is_ajax()) { ); $table->data['ldap_admin_pass'] = $row; + // Ldapsearch timeout. + // Default Ldapsearch timeout. + set_when_empty($config['ldap_searh_timeout'], 5); + $row = []; + $row['name'] = __('Ldap search timeout (secs)'); + $row['control'] = html_print_input_text( + 'ldap_search_timeout', + $config['ldap_search_timeout'], + '', + 10, + 10, + true + ); + $table->data['ldap_search_timeout'] = $row; + // Enable/disable secondary ldap. // Set default value. set_unless_defined($config['secondary_ldap_enabled'], false); diff --git a/pandora_console/godmode/snmpconsole/snmp_trap_generator.php b/pandora_console/godmode/snmpconsole/snmp_trap_generator.php index 72578868e7..e03cfa9bb9 100755 --- a/pandora_console/godmode/snmpconsole/snmp_trap_generator.php +++ b/pandora_console/godmode/snmpconsole/snmp_trap_generator.php @@ -76,6 +76,7 @@ if ($generate_trap) { ); } +$table = new stdClass(); $traps_generator = '
'; $table->width = '100%'; $table->class = 'databox filters'; diff --git a/pandora_console/godmode/users/configure_user.php b/pandora_console/godmode/users/configure_user.php index 355d93abff..b0dd7da0e3 100644 --- a/pandora_console/godmode/users/configure_user.php +++ b/pandora_console/godmode/users/configure_user.php @@ -442,6 +442,13 @@ if ($create_user) { $password_new = ''; $password_confirm = ''; $new_user = true; + } else if (excludedPassword($password_new) === true) { + $is_err = true; + ui_print_error_message(__('The password provided is not valid. Please set another one.')); + $user_info = $values; + $password_new = ''; + $password_confirm = ''; + $new_user = true; } else { if ((!is_user_admin($config['id_user']) || $config['enable_pass_policy_admin']) && $config['enable_pass_policy']) { $pass_ok = login_validate_pass($password_new, $id, true); @@ -1964,7 +1971,7 @@ function show_double_auth_activation () { resizable: true, draggable: true, modal: true, - title: "", + title: "", overlay: { opacity: 0.5, background: "black" @@ -2042,7 +2049,7 @@ function show_double_auth_deactivation () { resizable: true, draggable: true, modal: true, - title: "", + title: "", overlay: { opacity: 0.5, background: "black" diff --git a/pandora_console/include/ajax/config.ajax.php b/pandora_console/include/ajax/config.ajax.php index 1f0ea777f9..abe4d6f1ff 100644 --- a/pandora_console/include/ajax/config.ajax.php +++ b/pandora_console/include/ajax/config.ajax.php @@ -1,6 +1,7 @@ 0) { + if ($event_rep === EVENT_GROUP_REP_EVENTS) { // Default grouped message filtering (evento and estado). $whereGrouped = sprintf( '`evento` = "%s"', @@ -119,6 +119,11 @@ if ($get_comments === true) { (int) $event['id_agentmodule'] ); } + } else if ($event_rep === EVENT_GROUP_REP_EXTRAIDS) { + $whereGrouped = sprintf( + '`id_extra` = "%s"', + $event['id_extra'] + ); } else { $whereGrouped = sprintf('`id_evento` = %d', $event['id_evento']); } @@ -175,7 +180,7 @@ if ($delete_event === true) { $filter = get_parameter('filter', []); $id_evento = (int) get_parameter('id_evento', 0); $server_id = (int) get_parameter('server_id', 0); - $event_rep = get_parameter('event_rep', 0); + $event_rep = (int) get_parameter('event_rep', 0); try { if (is_metaconsole() === true @@ -228,7 +233,7 @@ if ($validate_event === true) { $filter = get_parameter('filter', []); $id_evento = (int) get_parameter('id_evento', 0); $server_id = (int) get_parameter('server_id', 0); - $event_rep = get_parameter('event_rep', 0); + $event_rep = (int) get_parameter('event_rep', 0); try { if (is_metaconsole() === true @@ -240,7 +245,7 @@ if ($validate_event === true) { if ($event_rep === 0) { // Disable group by when there're result is unique. - $filter['group_rep'] = 0; + $filter['group_rep'] = EVENT_GROUP_REP_ALL; } // Check acl. @@ -285,7 +290,7 @@ if ($in_process_event === true) { $filter = get_parameter('filter', []); $id_evento = (int) get_parameter('id_evento', 0); $server_id = (int) get_parameter('server_id', 0); - $event_rep = get_parameter('event_rep', 0); + $event_rep = (int) get_parameter('event_rep', 0); try { if (is_metaconsole() === true @@ -297,7 +302,7 @@ if ($in_process_event === true) { if ($event_rep === 0) { // Disable group by when there're result is unique. - $filter['group_rep'] = 0; + $filter['group_rep'] = EVENT_GROUP_REP_ALL; } // Check acl. @@ -466,7 +471,6 @@ if ($get_filter_values) { $event_filter = [ 'status' => EVENT_NO_VALIDATED, 'event_view_hr' => $config['event_view_hr'], - 'group_rep' => 1, 'tag_with' => [], 'tag_without' => [], 'history' => false, @@ -483,7 +487,7 @@ if ($get_filter_values) { 'time_to' => '', 'severity' => '', 'event_type' => '', - 'group_rep' => 0, + 'group_rep' => EVENT_GROUP_REP_ALL, 'id_group' => 0, 'id_group_filter' => 0, 'group_name' => 'All', @@ -2418,7 +2422,7 @@ if ($get_events_fired) { 'id_agent_module' => 0, 'pagination' => 0, 'id_user_ack' => 0, - 'group_rep' => 0, + 'group_rep' => EVENT_GROUP_REP_ALL, 'tag_with' => [], 'tag_without' => [], 'filter_only_alert' => -1, diff --git a/pandora_console/include/ajax/heatmap.ajax.php b/pandora_console/include/ajax/heatmap.ajax.php index 6d06c0e2ce..c33b0015aa 100644 --- a/pandora_console/include/ajax/heatmap.ajax.php +++ b/pandora_console/include/ajax/heatmap.ajax.php @@ -78,6 +78,7 @@ if (is_ajax() === true) { 0 => __('Group agents'), 1 => __('Group modules by tag'), 2 => __('Group modules by module group'), + 3 => __('Group modules by agents'), ], 'type', $type, @@ -203,6 +204,10 @@ if (is_ajax() === true) { '5' ); break; + + case 3: + // Empty. + break; } echo '
'; @@ -212,6 +217,7 @@ if (is_ajax() === true) { enterprise_include_once('include/functions_agents.php'); $id = get_parameter('id', 0); switch ($type) { + case 3: case 2: $data = db_get_row('tagente_modulo', 'id_agente_modulo', $id); diff --git a/pandora_console/include/ajax/visual_console.ajax.php b/pandora_console/include/ajax/visual_console.ajax.php index 316d5ff022..cd4dde48e1 100644 --- a/pandora_console/include/ajax/visual_console.ajax.php +++ b/pandora_console/include/ajax/visual_console.ajax.php @@ -37,6 +37,7 @@ $ajax = true; $render_map = (bool) get_parameter('render_map', false); $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); if ($render_map) { @@ -99,3 +100,29 @@ if ($load_css_cv === true) { echo $output; return; } + +if ($update_maintanance_mode === true) { + $idVisualConsole = (int) get_parameter('idVisualConsole', 0); + $mode = (bool) get_parameter('mode', false); + + $values = []; + if ($mode === true) { + $values['maintenance_mode'] = json_encode( + [ + 'user' => $config['id_user'], + 'timestamp' => time(), + ] + ); + } else { + $values['maintenance_mode'] = null; + } + + $result = db_process_sql_update( + 'tlayout', + $values, + ['id' => $idVisualConsole] + ); + + echo json_encode(['result' => $result]); + return; +} diff --git a/pandora_console/include/auth/mysql.php b/pandora_console/include/auth/mysql.php index f13dfbf62e..13bd0428a0 100644 --- a/pandora_console/include/auth/mysql.php +++ b/pandora_console/include/auth/mysql.php @@ -305,7 +305,7 @@ function process_user_login_remote($login, $pass, $api=false) // Authentication ok, check if the user exists in the local database if (is_user($login)) { - if (!user_can_login($login)) { + if (!user_can_login($login) && $api === false) { return false; } @@ -758,6 +758,12 @@ function delete_user(string $id_user) function update_user_password(string $user, string $password_new) { global $config; + + if (excludedPassword($password_new) === true) { + $config['auth_error'] = __('The password provided is not valid. Please, set another one.'); + return false; + } + if (isset($config['auth']) === true && $config['auth'] === 'pandora') { $sql = sprintf( "UPDATE tusuario SET password = '".md5($password_new)."', last_pass_change = '".date('Y-m-d H:i:s', get_system_time())."' WHERE id_user = '".$user."'" @@ -840,6 +846,9 @@ function ldap_process_user_login($login, $password, $secondary_server=false) $ldap[$token] = $secondary_server === true ? $config[$token.'_secondary'] : $config[$token]; } + // Remove entities ldap admin pass. + $ldap['ldap_admin_pass'] = io_safe_output($ldap['ldap_admin_pass']); + // Connect to the LDAP server if (stripos($ldap['ldap_server'], 'ldap://') !== false || stripos($ldap['ldap_server'], 'ldaps://') !== false @@ -856,8 +865,16 @@ function ldap_process_user_login($login, $password, $secondary_server=false) return false; } - // Set the LDAP version + // Set the LDAP version. ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, $ldap['ldap_version']); + ldap_set_option($ds, LDAP_OPT_NETWORK_TIMEOUT, 1); + + // Set ldap search timeout. + ldap_set_option( + $ds, + LDAP_OPT_TIMELIMIT, + (empty($config['ldap_search_timeout']) === true) ? 5 : ((int) $config['ldap_search_timeout']) + ); if ($ldap['ldap_start_tls']) { if (!@ldap_start_tls($ds)) { @@ -878,7 +895,8 @@ function ldap_process_user_login($login, $password, $secondary_server=false) io_safe_output($ldap['ldap_admin_login']), io_output_password($ldap['ldap_admin_pass']), io_safe_output($login), - $ldap['ldap_start_tls'] + $ldap['ldap_start_tls'], + $config['ldap_search_timeout'] ); if ($sr) { @@ -1487,7 +1505,8 @@ function local_ldap_search( $ldap_admin_user=null, $ldap_admin_pass=null, $user=null, - $ldap_start_tls=null + $ldap_start_tls=null, + $ldap_search_time=5 ) { global $config; @@ -1520,8 +1539,8 @@ function local_ldap_search( } $dn = " -b '".$dn."'"; - - $shell_ldap_search = explode("\n", shell_exec('ldapsearch -LLL -o ldif-wrap=no -x'.$ldap_host.$ldap_version.' -E pr=10000/noprompt '.$ldap_admin_user.$ldap_admin_pass.$dn.$filter.$tls.' | grep -v "^#\|^$" | sed "s/:\+ /=>/g"')); + $ldapsearch_command = 'ldapsearch -LLL -o ldif-wrap=no -o nettimeout='.$ldap_search_time.' -x'.$ldap_host.$ldap_version.' -E pr=10000/noprompt '.$ldap_admin_user.$ldap_admin_pass.$dn.$filter.$tls.' | grep -v "^#\|^$" | sed "s/:\+ /=>/g"'; + $shell_ldap_search = explode("\n", shell_exec($ldapsearch_command)); foreach ($shell_ldap_search as $line) { $values = explode('=>', $line); if (!empty($values[0]) && !empty($values[1])) { diff --git a/pandora_console/include/class/AgentWizard.class.php b/pandora_console/include/class/AgentWizard.class.php index dc6bd5df5f..5dad75e5ad 100644 --- a/pandora_console/include/class/AgentWizard.class.php +++ b/pandora_console/include/class/AgentWizard.class.php @@ -33,6 +33,7 @@ global $config; require_once $config['homedir'].'/include/class/HTML.class.php'; require_once $config['homedir'].'/include/functions_snmp_browser.php'; require_once $config['homedir'].'/include/functions_wmi.php'; +require_once $config['homedir'].'/include/class/CredentialStore.class.php'; use PandoraFMS\Module; @@ -696,6 +697,43 @@ class AgentWizard extends HTML 'return' => true, ], ]; + + $user_groups = users_get_groups(false, 'AR'); + if (users_is_admin() === true || isset($user_groups[0]) === true) { + $credentials = db_get_all_rows_sql( + 'SELECT identifier FROM tcredential_store WHERE product LIKE "WMI"' + ); + } else { + $credentials = db_get_all_rows_sql( + sprintf( + 'SELECT identifier FROM tcredential_store WHERE product LIKE "WMI" AND id_group IN (%s)', + implode(',', array_keys($user_groups)) + ) + ); + } + + if (empty($credentials) === false) { + $fields = []; + foreach ($credentials as $key => $value) { + $fields[$value['identifier']] = $value['identifier']; + } + + $inputs[] = [ + 'label' => __('Credential store'), + 'id' => 'slc-credential', + 'arguments' => [ + 'name' => 'credential', + 'input_class' => 'flex-row', + 'type' => 'select', + 'nothing' => __('None'), + 'nothing_value' => 0, + 'fields' => $fields, + 'class' => '', + 'return' => true, + 'sort' => true, + ], + ]; + } } $hint_server = ' '; @@ -716,6 +754,43 @@ class AgentWizard extends HTML ]; if ($this->actionType === 'snmp') { + $user_groups = users_get_groups(false, 'AR'); + if (users_is_admin() === true || isset($user_groups[0]) === true) { + $credentials = db_get_all_rows_sql( + 'SELECT identifier FROM tcredential_store WHERE product LIKE "SNMP"' + ); + } else { + $credentials = db_get_all_rows_sql( + sprintf( + 'SELECT identifier FROM tcredential_store WHERE product LIKE "SNMP" AND id_group IN (%s)', + implode(',', array_keys($user_groups)) + ) + ); + } + + if (empty($credentials) === false) { + $fields = []; + foreach ($credentials as $key => $value) { + $fields[$value['identifier']] = $value['identifier']; + } + + $inputs[] = [ + 'label' => __('Credential store'), + 'id' => 'slc-credential', + 'arguments' => [ + 'name' => 'credential', + 'input_class' => 'flex-row', + 'type' => 'select', + 'nothing' => __('None'), + 'nothing_value' => 0, + 'fields' => $fields, + 'class' => '', + 'return' => true, + 'sort' => true, + ], + ]; + } + $inputs[] = [ 'label' => __('SNMP community'), 'id' => 'txt-community', @@ -1336,6 +1411,21 @@ class AgentWizard extends HTML } + /** + * Build an array with Product credentials. + * + * @return array with credentials (pass and id). + */ + public function getCredentials(string $identifier='') + { + if (empty($identifier) === true) { + $identifier = get_parameter('identifier', ''); + } + + echo json_encode(credentialStore::getKey($identifier)); + } + + /** * Prepare data module to create. * @@ -5813,6 +5903,58 @@ class AgentWizard extends HTML filterInterfaces(); }); + $('#credential').change(function() { + if ($('#credential').val() !== '0') { + $.ajax({ + method: "post", + url: "", + data: { + page: "ajaxController; ?>", + method: "getCredentials", + identifier: $('#credential').val() + }, + datatype: "json", + success: function(data) { + data = JSON.parse(data); + + if ($('#text-namespaceWMI').length > 0) { + // WMI. + $('#text-namespaceWMI').val(data['extra_1']); + $('#text-usernameWMI').val(data['username']); + $('#password-passwordWMI').val(data['password']); + } else { + // SNMP. + extra = JSON.parse(data['extra_1']); + $('#version').val(extra['version']); + $('#version').trigger('change'); + $('#text-community').val(extra['community']); + + if (extra['version'] === '3') { + $('#securityLevelV3').val(extra['securityLevelV3']); + $('#securityLevelV3').trigger('change'); + $('#text-authUserV3').val(extra['authUserV3']); + + if (extra['securityLevelV3'] === 'authNoPriv' || extra['securityLevelV3'] === 'authPriv') { + $('#authMethodV3').val(extra['authMethodV3']); + $('#authMethodV3').trigger('change'); + $('#password-authPassV3').val(extra['authPassV3']); + + if (extra['securityLevelV3'] === 'authPriv') { + $('#privacyMethodV3').val(extra['privacyMethodV3']); + $('#privacyMethodV3').trigger('change'); + $('#password-privacyPassV3').val(extra['privacyPassV3']); + } + } + } + } + }, + error: function(e) { + showMsg(e); + } + }); + } + }); + // Loading. $('#submit-sub-protocol').click(function() { $('.wizard-result').remove(); diff --git a/pandora_console/include/class/CredentialStore.class.php b/pandora_console/include/class/CredentialStore.class.php index 27486433ee..a134f999b8 100644 --- a/pandora_console/include/class/CredentialStore.class.php +++ b/pandora_console/include/class/CredentialStore.class.php @@ -617,33 +617,71 @@ class CredentialStore extends Wizard $password = $google_creds->private_key_id; } - if (empty($identifier) === true) { - $error = __('Key identifier is required'); - } else if ($id_group === null) { - $error = __('You must select a group where store this key!'); - } else if (empty($product) === true) { - $error = __('You must specify a product type'); - } else if (empty($username) === true || (empty($password) === true)) { - $error = __('You must specify a username and/or password'); - } else if (evaluate_ascii_valid_string(io_safe_output($identifier)) === false) { - $error = __('Identifier with forbidden characters. Check the documentation.'); - } + if ($product !== 'SNMP') { + if (empty($identifier) === true) { + $error = __('Key identifier is required'); + } else if ($id_group === null) { + $error = __('You must select a group where store this key!'); + } else if (empty($product) === true) { + $error = __('You must specify a product type'); + } else if (empty($username) === true || (empty($password) === true)) { + $error = __('You must specify a username and/or password'); + } else if (evaluate_ascii_valid_string(io_safe_output($identifier)) === false) { + $error = __('Identifier with forbidden characters. Check the documentation.'); + } - if (isset($error) === true) { - $this->ajaxMsg('error', $error); - exit; - } + if (isset($error) === true) { + $this->ajaxMsg('error', $error); + exit; + } - // Encrypt content (if needed). - $values = [ - 'identifier' => $identifier, - 'id_group' => $id_group, - 'product' => $product, - 'username' => io_input_password(io_safe_output($username)), - 'password' => io_input_password(io_safe_output($password)), - 'extra_1' => io_input_password(io_safe_output($extra_1)), - 'extra_2' => io_input_password(io_safe_output($extra_2)), - ]; + // Encrypt content (if needed). + $values = [ + 'identifier' => $identifier, + 'id_group' => $id_group, + 'product' => $product, + 'username' => io_input_password(io_safe_output($username)), + 'password' => io_input_password(io_safe_output($password)), + 'extra_1' => io_input_password(io_safe_output($extra_1)), + 'extra_2' => io_input_password(io_safe_output($extra_2)), + ]; + } else { + $values = [ + 'identifier' => $identifier, + 'id_group' => $id_group, + 'product' => $product, + ]; + + $community = (string) get_parameter('community', ''); + $version = (string) get_parameter('version', '1'); + $extra_json = [ + 'community' => $community, + 'version' => $version, + ]; + if ($version === '3') { + $securityLevelV3 = (string) get_parameter('securityLevelV3', 'authNoPriv'); + $extra_json['securityLevelV3'] = $securityLevelV3; + $authUserV3 = (string) get_parameter('authUserV3', ''); + $extra_json['authUserV3'] = $authUserV3; + if ($securityLevelV3 === 'authNoPriv' || $securityLevelV3 === 'authPriv') { + $authUserV3 = (string) get_parameter('authUserV3', ''); + $extra_json['authUserV3'] = $authUserV3; + $authMethodV3 = (string) get_parameter('authMethodV3', 'MD5'); + $extra_json['authMethodV3'] = $authMethodV3; + $authPassV3 = (string) get_parameter('authPassV3', ''); + $extra_json['authPassV3'] = $authPassV3; + + if ($securityLevelV3 === 'authPriv') { + $privacyMethodV3 = (string) get_parameter('privacyMethodV3', 'AES'); + $extra_json['privacyMethodV3'] = $privacyMethodV3; + $privacyPassV3 = (string) get_parameter('privacyPassV3', ''); + $extra_json['privacyPassV3'] = $privacyPassV3; + } + } + } + + $values['extra_1'] = json_encode($extra_json); + } // Spaces are not allowed. $values['identifier'] = \io_safe_input( @@ -947,6 +985,8 @@ class CredentialStore extends Wizard 'AZURE' => __('Azure'), 'SAP' => __('SAP'), 'GOOGLE' => __('Google'), + 'WMI' => __('WMI'), + 'SNMP' => __('SNMP'), ], 'selected' => (isset($values['product']) ? $values['product'] : 'CUSTOM'), 'disabled' => (bool) $values['product'], @@ -989,6 +1029,19 @@ class CredentialStore extends Wizard $extra1_type = 'textarea'; break; + case 'WMI': + $extra_1_label = __('Namespace'); + $extra1 = true; + $extra2 = false; + break; + + case 'SNMP': + $user = false; + $pass = false; + $extra1 = false; + $extra2 = false; + break; + case 'CUSTOM': case 'SAP': $user_label = __('Account ID'); @@ -1059,6 +1112,141 @@ class CredentialStore extends Wizard ]; } + if ($values['product'] === 'SNMP') { + $json_values = json_decode($values['extra_1'], true); + $inputs[] = [ + 'label' => __('SNMP community'), + 'id' => 'li_snmp_1', + 'arguments' => [ + 'name' => 'community', + 'input_class' => 'flex-row', + 'type' => 'text', + 'value' => $json_values['community'], + 'return' => true, + ], + ]; + + $inputs[] = [ + 'label' => __('SNMP version'), + 'id' => 'li_snmp_2', + 'arguments' => [ + 'name' => 'version', + 'input_class' => 'flex-row', + 'type' => 'select', + 'script' => 'showVersion()', + 'fields' => [ + '1' => __('1'), + '2' => __('2'), + '2c' => __('2c'), + '3' => __('3'), + ], + 'selected' => (isset($json_values['version']) ? $json_values['version'] : '1'), + 'return' => true, + ], + ]; + + $inputs[] = [ + 'label' => __('Security level'), + 'id' => 'li_snmp_3', + 'style' => ($json_values['version'] !== '3') ? 'display: none;' : '', + 'arguments' => [ + 'name' => 'securityLevelV3', + 'input_class' => 'flex-row', + 'type' => 'select', + 'script' => 'showSecurity()', + 'fields' => [ + 'authNoPriv' => __('Authenticated and non-private method'), + 'authPriv' => __('Authenticated and private method'), + 'noAuthNoPriv' => __('Non-authenticated and non-private method'), + ], + 'selected' => (isset($json_values['securityLevelV3']) ? $json_values['securityLevelV3'] : 'authNoPriv'), + 'return' => true, + ], + ]; + + $inputs[] = [ + 'label' => __('User authentication'), + 'id' => 'li_snmp_4', + 'style' => ($json_values['version'] !== '3') ? 'display: none;' : '', + 'arguments' => [ + 'name' => 'authUserV3', + 'input_class' => 'flex-row', + 'type' => 'text', + 'value' => $json_values['authUserV3'], + 'return' => true, + ], + ]; + + $authNoPrivate = ( + isset($json_values['securityLevelV3']) && + ($json_values['securityLevelV3'] === 'authNoPriv' || $json_values['securityLevelV3'] === 'authPriv') + ) ? '' : 'display: none;'; + + $inputs[] = [ + 'label' => __('Authentication method'), + 'id' => 'li_snmp_5', + 'style' => $authNoPrivate, + 'arguments' => [ + 'name' => 'authMethodV3', + 'input_class' => 'flex-row', + 'type' => 'select', + 'fields' => [ + 'MD5' => __('MD5'), + 'SHA' => __('SHA'), + ], + 'selected' => (isset($json_values['authMethodV3']) ? $json_values['authMethodV3'] : 'MD5'), + 'return' => true, + ], + ]; + + $inputs[] = [ + 'label' => __('Password authentication'), + 'id' => 'li_snmp_6', + 'style' => $authNoPrivate, + 'arguments' => [ + 'name' => 'authPassV3', + 'input_class' => 'flex-row', + 'type' => 'password', + 'value' => $json_values['authPassV3'], + 'return' => true, + ], + ]; + + $authPrivate = (isset($json_values['securityLevelV3']) && $json_values['securityLevelV3'] === 'authPriv') + ? '' + : 'display: none;'; + + $inputs[] = [ + 'label' => __('Privacy method'), + 'id' => 'li_snmp_7', + 'style' => $authPrivate, + 'arguments' => [ + 'name' => 'privacyMethodV3', + 'input_class' => 'flex-row', + 'type' => 'select', + 'fields' => [ + 'AES' => __('AES'), + 'DES' => __('DES'), + ], + 'selected' => (isset($json_values['privacyMethodV3']) ? $json_values['privacyMethodV3'] : 'AES'), + 'return' => true, + ], + ]; + + $inputs[] = [ + 'label' => __('Privacy pass'), + 'id' => 'li_snmp_8', + 'style' => $authPrivate, + 'arguments' => [ + 'name' => 'privacyPassV3', + 'input_class' => 'flex-row', + 'type' => 'password', + 'value' => $json_values['privacyPassV3'], + 'return' => true, + ], + ]; + } + return $this->printForm( [ 'form' => $form, @@ -1175,9 +1363,248 @@ class CredentialStore extends Wizard $('') ); $('#div-extra_1').show(); + } else if ($('#product :selected').val() == "WMI") { + $('#div-username label').text(''); + $('#div-password label').text(''); + $('#div-extra_1 label').text(''); + $('#div-username').show(); + $('#div-password').show(); + $('#div-extra_1').show(); + $('#div-extra_2').hide(); + } else if ($('#product :selected').val() == "SNMP") { + $('#div-username').hide(); + $('#div-password').hide(); + $('#div-extra_1').hide(); + $('#div-extra_2').hide(); + + if ($('#li_snmp_1').length > 0) { + console.log($('#li_snmp_1').length); + const test = ''; + console.log(test); + } else { + const ul = $('#modal_form').children('ul')[0]; + + // SNMP community. + const li_community = document.createElement("li"); + li_community.id = 'li_snmp_1'; + const label_community = document.createElement("label"); + label_community.textContent = ''; + const input_community = document.createElement("input"); + input_community.type = 'text'; + input_community.className = 'text_input'; + input_community.name = 'community'; + li_community.append(label_community); + li_community.append(input_community); + ul.append(li_community); + + // SNMP version. + const li_version = document.createElement("li"); + li_version.id = 'li_snmp_2'; + const label_version = document.createElement("label"); + label_version.textContent = ''; + const select_version = document.createElement("select"); + select_version.name = 'version'; + select_version.id = 'version'; + select_version.onchange = function() { + showVersion(); + }; + let option1 = document.createElement("option"); + let option2 = document.createElement("option"); + let option2c = document.createElement("option"); + let option3 = document.createElement("option"); + option1.value = '1'; + option1.text = '1'; + option2.value = '2'; + option2.text = '2'; + option2c.value = '2c'; + option2c.text = '2c'; + option3.value = '3'; + option3.text = '3'; + select_version.appendChild(option1); + select_version.appendChild(option2); + select_version.appendChild(option2c); + select_version.appendChild(option3); + li_version.append(label_version); + li_version.append(select_version); + ul.append(li_version); + $("#version").select2(); + + // Security. + const li_security = document.createElement("li"); + li_security.id = 'li_snmp_3'; + const label_security = document.createElement("label"); + label_security.textContent = ''; + const select_security = document.createElement("select"); + select_security.name = 'securityLevelV3'; + select_security.id = 'securityLevelV3'; + select_security.onchange = function() { + showSecurity(); + } + option1 = document.createElement("option"); + option2 = document.createElement("option"); + option3 = document.createElement("option"); + option1.value = 'authNoPriv'; + option1.text = ''; + option2.value = 'authPriv'; + option2.text = ''; + option3.value = 'noAuthNoPriv'; + option3.text = ''; + select_security.appendChild(option1); + select_security.appendChild(option2); + select_security.appendChild(option3); + li_security.append(label_security); + li_security.append(select_security); + ul.append(li_security); + $("#securityLevelV3").select2(); + + // User. + const li_user = document.createElement("li"); + li_user.id = 'li_snmp_4'; + const label_user = document.createElement("label"); + label_user.textContent = ''; + const input_user = document.createElement("input"); + input_user.type = 'text'; + input_user.className = 'text_input'; + input_user.name = 'authUserV3'; + li_user.append(label_user); + li_user.append(input_user); + ul.append(li_user); + + // Authentication method. + const li_method = document.createElement("li"); + li_method.id = 'li_snmp_5'; + const label_method = document.createElement("label"); + label_method.textContent = ''; + const select_method = document.createElement("select"); + select_method.name = 'authMethodV3'; + select_method.id = 'method'; + option1 = document.createElement("option"); + option2 = document.createElement("option"); + option1.value = 'MD5'; + option1.text = ''; + option2.value = 'SHA'; + option2.text = ''; + select_method.appendChild(option1); + select_method.appendChild(option2); + li_method.append(label_method); + li_method.append(select_method); + ul.append(li_method); + $("#method").select2(); + + // Password. + const li_password = document.createElement("li"); + li_password.id = 'li_snmp_6'; + const label_password = document.createElement("label"); + label_password.textContent = ''; + const input_password = document.createElement("input"); + input_password.type = 'password'; + input_password.className = 'text_input'; + input_password.name = 'authPassV3'; + li_password.append(label_password); + li_password.append(input_password); + ul.append(li_password); + + // Privacy method. + const li_privacy = document.createElement("li"); + li_privacy.id = 'li_snmp_7'; + const label_privacy = document.createElement("label"); + label_privacy.textContent = ''; + const select_privacy = document.createElement("select"); + select_privacy.name = 'privacyMethodV3'; + select_privacy.id = 'privacy'; + option1 = document.createElement("option"); + option2 = document.createElement("option"); + option1.value = 'AES'; + option1.text = ''; + option2.value = 'DES'; + option2.text = ''; + select_privacy.appendChild(option1); + select_privacy.appendChild(option2); + li_privacy.append(label_privacy); + li_privacy.append(select_privacy); + ul.append(li_privacy); + $("#privacy").select2(); + + // Privacy pass. + const li_privacyPassV3 = document.createElement("li"); + li_privacyPassV3.id = 'li_snmp_8'; + const label_privacyPassV3 = document.createElement("label"); + label_privacyPassV3.textContent = ''; + const input_privacyPassV3 = document.createElement("input"); + input_privacyPassV3.type = 'password'; + input_privacyPassV3.className = 'text_input'; + input_privacyPassV3.name = 'privacyPassV3'; + li_privacyPassV3.append(label_privacyPassV3); + li_privacyPassV3.append(input_privacyPassV3); + ul.append(li_privacyPassV3); + + $('#li_snmp_3').hide(); + $('#li_snmp_4').hide(); + $('#li_snmp_5').hide(); + $('#li_snmp_6').hide(); + $('#li_snmp_7').hide(); + $('#li_snmp_8').hide(); + } } } + function showVersion() { + if ($('#version').val() === '3') { + $('#li_snmp_3').show(); + $('#li_snmp_4').show(); + $('#li_snmp_5').show(); + $('#li_snmp_6').show(); + } else { + $('#li_snmp_3').hide(); + $('#li_snmp_4').hide(); + $('#li_snmp_5').hide(); + $('#li_snmp_6').hide(); + $('#li_snmp_7').hide(); + $('#li_snmp_8').hide(); + } + } + + function showSecurity() { + const value = $('#securityLevelV3').val(); + switch (value) { + case 'noAuthNoPriv': + $('#li_snmp_4').show(); + $('#li_snmp_5').hide(); + $('#li_snmp_6').hide(); + $('#li_snmp_7').hide(); + $('#li_snmp_8').hide(); + break; + + case 'authPriv': + $('#li_snmp_4').show(); + $('#li_snmp_5').show(); + $('#li_snmp_6').show(); + $('#li_snmp_7').show(); + $('#li_snmp_8').show(); + break; + + case 'authNoPriv': + default: + $('#li_snmp_4').show(); + $('#li_snmp_5').show(); + $('#li_snmp_6').show(); + $('#li_snmp_7').hide(); + $('#li_snmp_8').hide(); + break; + } + } + + function hideSNMP() { + $('#li_snmp_1').hide(); + $('#li_snmp_2').hide(); + $('#li_snmp_3').hide(); + $('#li_snmp_4').hide(); + $('#li_snmp_5').hide(); + $('#li_snmp_6').hide(); + $('#li_snmp_7').hide(); + $('#li_snmp_8').hide(); + } + /** * Process ajax responses and shows a dialog with results. */ diff --git a/pandora_console/include/class/HTML.class.php b/pandora_console/include/class/HTML.class.php index 6b4d153a7a..f2b6ed3630 100644 --- a/pandora_console/include/class/HTML.class.php +++ b/pandora_console/include/class/HTML.class.php @@ -485,6 +485,10 @@ class HTML $class = ''; } + if (empty($input['style']) === false) { + $style_li = $input['style']; + } + if (isset($input['class']) === true) { $class = $input['class'].$class; } @@ -498,7 +502,7 @@ class HTML } // Print independent block of inputs. - $output .= '
  • '; + $output .= '
  • '; if (isset($input['wrapper']) === true) { $output .= '<'.$input['wrapper'].' id="'.($input['block_id'] ?? '').'" class="'.$class.'">'; @@ -562,7 +566,7 @@ class HTML } if (!$direct) { - $output .= '
  • '; + $output .= '
  • '; } if (isset($input['label']) === true) { @@ -933,7 +937,13 @@ class HTML $cb_args = $data['cb_args']; $output_head = ''; + $output_head .= '" id="'.$form['id'].'" '.$form['extra'].'>'; + + if (isset($form['title']) === true && empty($form['title']) === false) { + $output_head .= '
    '; + $output_head .= ''.$form['title'].''; + $output_head .= '
    '; + } if ($return === false) { echo $output_head; diff --git a/pandora_console/include/class/Heatmap.class.php b/pandora_console/include/class/Heatmap.class.php index 916b4b9873..8572d6cad1 100644 --- a/pandora_console/include/class/Heatmap.class.php +++ b/pandora_console/include/class/Heatmap.class.php @@ -139,7 +139,7 @@ class Heatmap ui_require_css_file('heatmap'); $settings = [ - 'type' => 'POST', + 'type' => 'GET', 'dataType' => 'html', 'url' => ui_get_full_url( 'ajax.php', @@ -169,11 +169,41 @@ class Heatmap setting['data']['height'] = $(`#div_${randomId}`).height() + 10; setting['data']['width'] = $(`#div_${randomId}`).width(); + var totalModules = 0; + // Initial charge. - ajaxRequest( - `div_${randomId}`, - setting - ); + $.ajax({ + type: setting.type, + dataType: setting.dataType, + url: setting.url, + data: setting.data, + success: function(data) { + $(`#div_${randomId}`).append(data); + totalModules = $('rect').length; + let cont = 0; + while (cont < Math.ceil(totalModules / 10)) { + oneSquare(getRandomInteger(1, 10), getRandomInteger(100, 900)); + cont ++; + } + } + }); + + function getRandomInteger(min, max) { + return Math.floor(Math.random() * max) + min; + } + + function oneSquare(solid, time) { + var randomPoint = getRandomInteger(1, totalModules); + let target = $(`#${randomId}_${randomPoint}`); + setTimeout(function() { + let class_name = target.attr('class'); + class_name = class_name.split(' ')[0]; + const newClassName = class_name.split('_')[0]; + target.removeClass(`${class_name} hover`); + target.addClass(`${newClassName}_${solid} hover`); + oneSquare(getRandomInteger(1, 10), getRandomInteger(100, 900)); + }, time); + } // Refresh. setInterval( @@ -206,23 +236,29 @@ class Heatmap // randomly sort. lista = lista.sort(function() {return Math.random() - 0.5}); - const countPerSecond = total / refresh; + let countPerSecond = total / refresh; + if (countPerSecond < 1) { + countPerSecond = 1; + } let cont = 0; let limit = countPerSecond - 1; const timer = setInterval( - function() { - while (cont <= limit) { - $(`#${randomId}_${lista[cont]['id']}`).removeClass(); - $(`#${randomId}_${lista[cont]['id']}`).addClass(`${lista[cont]['status']} hover`); - - cont++; + function() { + while (cont <= limit) { + if (typeof lista[cont] !== 'undefined') { + const rect = document.getElementsByName(`${lista[cont]['id']}`); + $(`#${rect[0].id}`).removeClass(); + $(`#${rect[0].id}`).addClass(`${lista[cont]['status']} hover`); } - limit = limit + countPerSecond; - }, - 1000 - ); + + cont++; + } + limit = limit + countPerSecond; + }, + 1000 + ); setTimeout( function(){ @@ -314,8 +350,10 @@ class Heatmap // All agents. $sql = sprintf( - 'SELECT DISTINCT id_agente as id,alias,id_grupo,normal_count,warning_count,critical_count, unknown_count,notinit_count,total_count,fired_count, - (SELECT last_status_change FROM tagente_estado WHERE id_agente = tagente.id_agente ORDER BY last_status_change DESC LIMIT 1) AS last_status_change + 'SELECT DISTINCT id_agente as id,alias,id_grupo,normal_count,warning_count,critical_count, + unknown_count,notinit_count,total_count,fired_count, + (SELECT last_status_change FROM tagente_estado WHERE id_agente = tagente.id_agente + ORDER BY last_status_change DESC LIMIT 1) AS last_status_change FROM tagente WHERE `disabled` = 0 %s %s ORDER BY id_grupo,id_agente ASC', $alias, $id_grupo @@ -391,7 +429,8 @@ class Heatmap // All modules. $sql = sprintf( - 'SELECT am.id_agente_modulo AS id, ae.known_status AS `status`, am.id_module_group AS id_grupo, ae.last_status_change FROM tagente_modulo am + 'SELECT am.id_agente_modulo AS id, ae.estado AS `status`, am.id_module_group AS id_grupo, + ae.last_status_change FROM tagente_modulo am INNER JOIN tagente_estado ae ON am.id_agente_modulo = ae.id_agente_modulo WHERE am.disabled = 0 %s %s GROUP BY am.id_module_group, am.id_agente_modulo', $filter_group, @@ -489,7 +528,8 @@ class Heatmap // All modules. $sql = sprintf( - 'SELECT ae.id_agente_modulo AS id, ae.known_status AS `status`, tm.id_tag AS id_grupo, ae.last_status_change FROM tagente_estado ae + 'SELECT ae.id_agente_modulo AS id, ae.estado AS `status`, tm.id_tag AS id_grupo, + ae.last_status_change FROM tagente_estado ae INNER JOIN ttag_module tm ON tm.id_agente_modulo = ae.id_agente_modulo WHERE 1=1 %s %s GROUP BY tm.id_tag, ae.id_agente_modulo', $filter_tag, @@ -567,6 +607,98 @@ class Heatmap } + /** + * Get all modules group by agents + * + * @return array + */ + protected function getAllModulesByAgents() + { + $filter_name = ''; + if (empty($this->search) === false) { + $filter_name = 'AND nombre LIKE "%'.$this->search.'%"'; + } + + // All modules. + $sql = sprintf( + 'SELECT am.id_agente_modulo AS id, ae.estado AS `status`, am.id_agente AS id_grupo, + ae.last_status_change FROM tagente_modulo am + INNER JOIN tagente_estado ae ON am.id_agente_modulo = ae.id_agente_modulo + WHERE am.disabled = 0 %s GROUP BY ae.id_agente_modulo ORDER BY id_grupo', + $filter_name + ); + + $result = db_get_all_rows_sql($sql); + + // Module status. + foreach ($result as $key => $module) { + $status = ''; + switch ($module['status']) { + case AGENT_MODULE_STATUS_CRITICAL_BAD: + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case 1: + case 100: + $status = 'critical'; + break; + + case AGENT_MODULE_STATUS_NORMAL: + case AGENT_MODULE_STATUS_NORMAL_ALERT: + case 0: + case 300: + $status = 'normal'; + break; + + case AGENT_MODULE_STATUS_WARNING: + case AGENT_MODULE_STATUS_WARNING_ALERT: + case 2: + case 200: + $status = 'warning'; + break; + + default: + case AGENT_MODULE_STATUS_UNKNOWN: + case 3: + $status = 'unknown'; + break; + case AGENT_MODULE_STATUS_NOT_INIT: + case 5: + $status = 'notinit'; + break; + } + + if ($module['last_status_change'] != 0) { + $seconds = (time() - $module['last_status_change']); + + if ($seconds >= SECONDS_1DAY) { + $status .= '_10'; + } else if ($seconds >= 77760) { + $status .= '_9'; + } else if ($seconds >= 69120) { + $status .= '_8'; + } else if ($seconds >= 60480) { + $status .= '_7'; + } else if ($seconds >= 51840) { + $status .= '_6'; + } else if ($seconds >= 43200) { + $status .= '_5'; + } else if ($seconds >= 34560) { + $status .= '_4'; + } else if ($seconds >= 25920) { + $status .= '_3'; + } else if ($seconds >= 17280) { + $status .= '_2'; + } else if ($seconds >= 8640) { + $status .= '_1'; + } + } + + $result[$key]['status'] = $status; + } + + return $result; + } + + /** * GetData * @@ -575,6 +707,10 @@ class Heatmap public function getData() { switch ($this->type) { + case 3: + $data = $this->getAllModulesByAgents(); + break; + case 2: $data = $this->getAllModulesByGroup(); break; @@ -709,9 +845,10 @@ class Heatmap $groups = []; $contX = 0; $contY = 0; + $cont = 1; foreach ($result as $value) { - echo ''; + echo ''; $contX++; if ($contX >= $Xaxis) { @@ -724,14 +861,15 @@ class Heatmap } else { $groups[$value['id_grupo']] += 1; } + + $cont++; } ?>