From e300f2244d027d65fa20100629bb81be24f13c99 Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Wed, 28 Oct 2020 17:56:42 +0100 Subject: [PATCH 01/89] Adding delete_agent control for meta --- pandora_console/include/functions_api.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 6401910faa..f9fd4efaa9 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -1885,11 +1885,17 @@ function api_set_delete_agent($id, $thrash1, $other, $thrash3) } } else { // Delete only if the centralised mode is disabled. - if (is_central_policies_on_node()) { + $headers = getallheaders(); + if (!isset($headers['idk']) || !is_management_allowed($headers['idk'])) { returnError('centralized'); exit; } + // Support for Pandora Enterprise. + if (license_free() === false) { + define('PANDORA_ENTERPRISE', true); + } + if ($agent_by_alias) { $idsAgents = agents_get_agent_id_by_alias(io_safe_input($id)); } else { From d75bb46f3431ff7d78d5d5df43436cf4300c1711 Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Thu, 5 Nov 2020 12:47:25 +0100 Subject: [PATCH 02/89] changed action/alert priority of fields for snmp alerts --- pandora_server/lib/PandoraFMS/Core.pm | 40 +++++++++++++-------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 0d3bc2652f..cddc89117f 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1023,26 +1023,26 @@ sub pandora_execute_action ($$$$$$$$$;$) { $field20 = defined($action->{'field20'}) && $action->{'field20'} ne "" ? $action->{'field20'} : $alert->{'field20'}; } else { - $field1 = defined($action->{'field1'}) && $action->{'field1'} ne "" ? $action->{'field1'} : $alert->{'field1'}; - $field2 = defined($action->{'field2'}) && $action->{'field2'} ne "" ? $action->{'field2'} : $alert->{'field2'}; - $field3 = defined($action->{'field3'}) && $action->{'field3'} ne "" ? $action->{'field3'} : $alert->{'field3'}; - $field4 = defined($action->{'field4'}) && $action->{'field4'} ne "" ? $action->{'field4'} : $alert->{'field4'}; - $field5 = defined($action->{'field5'}) && $action->{'field5'} ne "" ? $action->{'field5'} : $alert->{'field5'}; - $field6 = defined($action->{'field6'}) && $action->{'field6'} ne "" ? $action->{'field6'} : $alert->{'field6'}; - $field7 = defined($action->{'field7'}) && $action->{'field7'} ne "" ? $action->{'field7'} : $alert->{'field7'}; - $field8 = defined($action->{'field8'}) && $action->{'field8'} ne "" ? $action->{'field8'} : $alert->{'field8'}; - $field9 = defined($action->{'field9'}) && $action->{'field9'} ne "" ? $action->{'field9'} : $alert->{'field9'}; - $field10 = defined($action->{'field10'}) && $action->{'field10'} ne "" ? $action->{'field10'} : $alert->{'field10'}; - $field11 = defined($action->{'field11'}) && $action->{'field11'} ne "" ? $action->{'field11'} : $alert->{'field11'}; - $field12 = defined($action->{'field12'}) && $action->{'field12'} ne "" ? $action->{'field12'} : $alert->{'field12'}; - $field13 = defined($action->{'field13'}) && $action->{'field13'} ne "" ? $action->{'field13'} : $alert->{'field13'}; - $field14 = defined($action->{'field14'}) && $action->{'field14'} ne "" ? $action->{'field14'} : $alert->{'field14'}; - $field15 = defined($action->{'field15'}) && $action->{'field15'} ne "" ? $action->{'field15'} : $alert->{'field15'}; - $field16 = defined($action->{'field16'}) && $action->{'field16'} ne "" ? $action->{'field16'} : $alert->{'field16'}; - $field17 = defined($action->{'field17'}) && $action->{'field17'} ne "" ? $action->{'field17'} : $alert->{'field17'}; - $field18 = defined($action->{'field18'}) && $action->{'field18'} ne "" ? $action->{'field18'} : $alert->{'field18'}; - $field19 = defined($action->{'field19'}) && $action->{'field19'} ne "" ? $action->{'field19'} : $alert->{'field19'}; - $field20 = defined($action->{'field20'}) && $action->{'field20'} ne "" ? $action->{'field20'} : $alert->{'field20'}; + $field1 = defined($alert->{'field1'}) && $alert->{'field1'} ne "" ? $alert->{'field1'} : $action->{'field1'}; + $field2 = defined($alert->{'field2'}) && $alert->{'field2'} ne "" ? $alert->{'field2'} : $action->{'field2'}; + $field3 = defined($alert->{'field3'}) && $alert->{'field3'} ne "" ? $alert->{'field3'} : $action->{'field3'}; + $field4 = defined($alert->{'field4'}) && $alert->{'field4'} ne "" ? $alert->{'field4'} : $action->{'field4'}; + $field5 = defined($alert->{'field5'}) && $alert->{'field5'} ne "" ? $alert->{'field5'} : $action->{'field5'}; + $field6 = defined($alert->{'field6'}) && $alert->{'field6'} ne "" ? $alert->{'field6'} : $action->{'field6'}; + $field7 = defined($alert->{'field7'}) && $alert->{'field7'} ne "" ? $alert->{'field7'} : $action->{'field7'}; + $field8 = defined($alert->{'field8'}) && $alert->{'field8'} ne "" ? $alert->{'field8'} : $action->{'field8'}; + $field9 = defined($alert->{'field9'}) && $alert->{'field9'} ne "" ? $alert->{'field9'} : $action->{'field9'}; + $field10 = defined($alert->{'field10'}) && $alert->{'field10'} ne "" ? $alert->{'field10'} : $action->{'field10'}; + $field11 = defined($alert->{'field11'}) && $alert->{'field11'} ne "" ? $alert->{'field11'} : $action->{'field11'}; + $field12 = defined($alert->{'field12'}) && $alert->{'field12'} ne "" ? $alert->{'field12'} : $action->{'field12'}; + $field13 = defined($alert->{'field13'}) && $alert->{'field13'} ne "" ? $alert->{'field13'} : $action->{'field13'}; + $field14 = defined($alert->{'field14'}) && $alert->{'field14'} ne "" ? $alert->{'field14'} : $action->{'field14'}; + $field15 = defined($alert->{'field15'}) && $alert->{'field15'} ne "" ? $alert->{'field15'} : $action->{'field15'}; + $field16 = defined($alert->{'field16'}) && $alert->{'field16'} ne "" ? $alert->{'field16'} : $action->{'field16'}; + $field17 = defined($alert->{'field17'}) && $alert->{'field17'} ne "" ? $alert->{'field17'} : $action->{'field17'}; + $field18 = defined($alert->{'field18'}) && $alert->{'field18'} ne "" ? $alert->{'field18'} : $action->{'field18'}; + $field19 = defined($alert->{'field19'}) && $alert->{'field19'} ne "" ? $alert->{'field19'} : $action->{'field19'}; + $field20 = defined($alert->{'field20'}) && $alert->{'field20'} ne "" ? $alert->{'field20'} : $action->{'field20'}; } # Recovery fields, thanks to Kato Atsushi From c6cf4ab9ee64726f0f77498577cf09894414e250 Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Wed, 11 Nov 2020 16:25:58 +0100 Subject: [PATCH 03/89] fixed query --- pandora_console/include/lib/Dashboard/Manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/lib/Dashboard/Manager.php b/pandora_console/include/lib/Dashboard/Manager.php index 07e253a2d8..eebfc3233c 100644 --- a/pandora_console/include/lib/Dashboard/Manager.php +++ b/pandora_console/include/lib/Dashboard/Manager.php @@ -702,8 +702,8 @@ class Manager FROM tdashboard td LEFT JOIN twidget_dashboard twd ON td.id = twd.id_dashboard - WHERE (td.id_group IN (%s) AND td.id_user = '') OR - td.id_user = '%s' %s + WHERE ((td.id_group IN (%s) AND td.id_user = '') OR + td.id_user = '%s') %s GROUP BY td.id ORDER BY name%s", $string_groups, From 915c039fcd233f3b5059db5aeece9ae486203be9 Mon Sep 17 00:00:00 2001 From: marcos Date: Thu, 12 Nov 2020 12:13:57 +0100 Subject: [PATCH 04/89] fixed sql error with secundary groups ZOS --- pandora_console/include/functions_tags.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/functions_tags.php b/pandora_console/include/functions_tags.php index fe36bc34fa..c759597706 100644 --- a/pandora_console/include/functions_tags.php +++ b/pandora_console/include/functions_tags.php @@ -900,7 +900,11 @@ function tags_get_acl_tags_module_condition($acltags, $modules_table='', $force_ } $in_group = implode(',', $without_tags); - $condition .= sprintf('(tagente.id_grupo IN (%s) OR tasg.id_group IN (%s))', $in_group, $in_group); + if ($has_secondary) { + $condition .= sprintf('(tagente.id_grupo IN (%s) OR tasg.id_group IN (%s))', $in_group, $in_group); + } else { + $condition .= sprintf('(tagente.id_grupo IN (%s))', $in_group); + } } $condition = !empty($condition) ? "($condition)" : ''; From 0ea8196db003a646c5469a61a20279f23ef1fcbe Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Thu, 12 Nov 2020 13:44:52 +0100 Subject: [PATCH 05/89] Fixed create network components --- pandora_console/include/ajax/snmp_browser.ajax.php | 2 +- pandora_console/include/functions_snmp_browser.php | 2 +- pandora_console/include/javascript/pandora_snmp_browser.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/ajax/snmp_browser.ajax.php b/pandora_console/include/ajax/snmp_browser.ajax.php index 571399c703..f91bc7ef3e 100644 --- a/pandora_console/include/ajax/snmp_browser.ajax.php +++ b/pandora_console/include/ajax/snmp_browser.ajax.php @@ -170,7 +170,7 @@ if (is_ajax()) { $id_target = explode(',', $id_items[0]); } - if (empty($id_items[0])) { + if (empty($id_items[0]) && $module_target !== 'network_component') { echo json_encode([0 => -1]); exit; } diff --git a/pandora_console/include/functions_snmp_browser.php b/pandora_console/include/functions_snmp_browser.php index c4ef3b05ab..7146752554 100644 --- a/pandora_console/include/functions_snmp_browser.php +++ b/pandora_console/include/functions_snmp_browser.php @@ -616,7 +616,7 @@ function snmp_browser_print_oid( $output .= html_print_table($table, true); $url = 'index.php?'.'sec=gmodules&'.'sec2=godmode/modules/manage_network_components'; - $output .= '
'; + $output .= ''; $output .= html_print_input_hidden('create_network_from_snmp_browser', 1, true); $output .= html_print_input_hidden('id_component_type', 2, true); $output .= html_print_input_hidden('type', 17, true); diff --git a/pandora_console/include/javascript/pandora_snmp_browser.js b/pandora_console/include/javascript/pandora_snmp_browser.js index 961619b80b..f02bdad4fc 100644 --- a/pandora_console/include/javascript/pandora_snmp_browser.js +++ b/pandora_console/include/javascript/pandora_snmp_browser.js @@ -541,7 +541,7 @@ function setOID() { } /** - * Create module on selected module_target (agent, networlk component or policy). + * Create module on selected module_target (agent, network component or policy). * * @param string module_target Target to create module. * @param return_values Return snmp values. From 4023327091890ad44f7e7f6d50c37dbb068fb62a Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Mon, 16 Nov 2020 12:30:58 +0100 Subject: [PATCH 06/89] Added search by secondary group name --- .../operation/search_agents.getdata.php | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/pandora_console/operation/search_agents.getdata.php b/pandora_console/operation/search_agents.getdata.php index aad2835a36..e9d315d291 100644 --- a/pandora_console/operation/search_agents.getdata.php +++ b/pandora_console/operation/search_agents.getdata.php @@ -179,6 +179,8 @@ if ($searchAgents) { $userGroups = users_get_groups($config['id_user'], 'AR', false); $id_userGroups = array_keys($userGroups); + $has_secondary = enterprise_hook('agents_is_using_secondary_groups'); + $sql = "SELECT DISTINCT taddress_agent.id_agent FROM taddress INNER JOIN taddress_agent ON taddress.id_a = taddress_agent.id_a @@ -188,10 +190,10 @@ if ($searchAgents) { if ($id != '') { $aux = $id[0]['id_agent']; $search_sql = " t1.nombre COLLATE utf8_general_ci LIKE '%%cd ".$stringSearchSQL."%%' OR - t2.nombre COLLATE utf8_general_ci LIKE '%%".$stringSearchSQL."%%' OR - t1.alias COLLATE utf8_general_ci LIKE '%%".$stringSearchSQL."%%' OR - t1.comentarios COLLATE utf8_general_ci LIKE '%%".$stringSearchSQL."%%' OR - t1.id_agente = $aux"; + t2.nombre COLLATE utf8_general_ci LIKE '%%".$stringSearchSQL."%%' OR + t1.alias COLLATE utf8_general_ci LIKE '%%".$stringSearchSQL."%%' OR + t1.comentarios COLLATE utf8_general_ci LIKE '%%".$stringSearchSQL."%%' OR + t1.id_agente = $aux"; if (count($id) >= 2) { for ($i = 1; $i < count($id); $i++) { @@ -201,10 +203,15 @@ if ($searchAgents) { } } else { $search_sql = " t1.nombre COLLATE utf8_general_ci LIKE '%%".$stringSearchSQL."%%' OR - t2.nombre COLLATE utf8_general_ci LIKE '%%".$stringSearchSQL."%%' OR + t2.nombre COLLATE utf8_general_ci LIKE '%%".$stringSearchSQL."%%' OR t1.direccion COLLATE utf8_general_ci LIKE '%%".$stringSearchSQL."%%' OR t1.comentarios COLLATE utf8_general_ci LIKE '%%".$stringSearchSQL."%%' OR - t1.alias COLLATE utf8_general_ci LIKE '%%".$stringSearchSQL."%%'"; + t1.alias COLLATE utf8_general_ci LIKE '%%".$stringSearchSQL."%%'"; + } + + if ($has_secondary === true) { + $search_sql .= " OR (tasg.id_group IS NOT NULL AND + tasg.id_group IN (SELECT id_grupo FROM tgrupo WHERE nombre COLLATE utf8_general_ci LIKE '%%".$stringSearchSQL."%%'))"; } $sql = " @@ -235,7 +242,7 @@ if ($searchAgents) { AND ( ".$search_sql.' ) - '; + '; $select = 'SELECT DISTINCT(t1.id_agente), t1.ultimo_contacto, t1.nombre, t1.comentarios, t1.id_os, t1.intervalo, t1.id_grupo, t1.disabled, t1.alias, t1.quiet'; if ($only_count) { From 55c368f957547ae09d20fd99ea85b19b5b13fd6d Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Mon, 16 Nov 2020 17:34:23 +0100 Subject: [PATCH 07/89] fixed last_compact in history db --- pandora_server/util/pandora_db.pl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 48104968ac..206f854f90 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -428,8 +428,8 @@ sub pandora_purgedb ($$) { ############################################################################### # Compact agent data. ############################################################################### -sub pandora_compactdb ($$) { - my ($conf, $dbh) = @_; +sub pandora_compactdb ($$$) { + my ($conf, $dbh, $dbh_conf) = @_; my %count_hash; my %id_agent_hash; @@ -534,9 +534,9 @@ sub pandora_compactdb ($$) { # Mark the last compact date if (defined ($conf->{'_last_compact'})) { - db_do ($dbh, 'UPDATE tconfig SET value=? WHERE token=?', $last_compact, 'last_compact'); + db_do ($dbh_conf, 'UPDATE tconfig SET value=? WHERE token=?', $last_compact, 'last_compact'); } else { - db_do ($dbh, 'INSERT INTO tconfig (value, token) VALUES (?, ?)', $last_compact, 'last_compact'); + db_do ($dbh_conf, 'INSERT INTO tconfig (value, token) VALUES (?, ?)', $last_compact, 'last_compact'); } } @@ -1018,7 +1018,7 @@ sub pandoradb_main ($$$) { # Compact on if enable and DaysCompact are below DaysPurge if (($conf->{'_onlypurge'} == 0) && ($conf->{'_days_compact'} < $conf->{'_days_purge'})) { - pandora_compactdb ($conf, defined ($history_dbh) ? $history_dbh : $dbh); + pandora_compactdb ($conf, defined ($history_dbh) ? $history_dbh : $dbh, $dbh); } # Update tconfig with last time of database maintance time (now) From 2ee187ae53468e90d4b1b8fae1182efc272e5785 Mon Sep 17 00:00:00 2001 From: Luis Calvo Date: Mon, 16 Nov 2020 18:30:23 +0100 Subject: [PATCH 08/89] Fixed acl on discovery tasklist --- pandora_console/godmode/wizards/DiscoveryTaskList.class.php | 4 ++++ pandora_console/include/class/HTML.class.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index 59a9fab84a..de2f70a629 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -448,6 +448,10 @@ class DiscoveryTaskList extends HTML $table->align[9] = 'left'; foreach ($recon_tasks as $task) { + if ($this->aclMulticheck('AR|AW|AM', $task['id_group']) === false) { + continue; + } + $no_operations = false; $data = []; $server_name = servers_get_name($task['id_recon_server']); diff --git a/pandora_console/include/class/HTML.class.php b/pandora_console/include/class/HTML.class.php index 41ceabf5ab..92cd8cc29f 100644 --- a/pandora_console/include/class/HTML.class.php +++ b/pandora_console/include/class/HTML.class.php @@ -254,7 +254,7 @@ class HTML * * @return boolean Alowed or not. */ - public function aclMulticheck($access=null) + public function aclMulticheck($access=null, $id_group=0) { global $config; @@ -268,7 +268,7 @@ class HTML foreach ($perms as $perm) { $allowed = $allowed || (bool) check_acl( $config['id_user'], - 0, + $id_group, $perm ); } From ef899ef529cf4d8608e88e8bba1eb78788465592 Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Tue, 17 Nov 2020 15:21:38 +0100 Subject: [PATCH 09/89] Fix error --- pandora_server/lib/PandoraFMS/Core.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 0d3bc2652f..74e81778c8 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -5373,7 +5373,9 @@ sub pandora_self_monitoring ($$) { get_db_value($dbh, "SELECT COUNT(*) FROM tagente_datos"); my $read_speed = int((time - $start_performance) * 1e6); - $xml_output .= enterprise_hook("elasticsearch_performance", [$pa_config, $dbh]); + my $elasticsearch_perfomance = enterprise_hook("elasticsearch_performance", [$pa_config, $dbh]); + + $xml_output .= $elasticsearch_perfomance if defined($elasticsearch_perfomance); $xml_output .=" "; $xml_output .=" Database Maintenance"; From 141259181379f938a55bc97f7a1e5303c5d3db6c Mon Sep 17 00:00:00 2001 From: Jose Gonzalez Date: Wed, 18 Nov 2020 12:37:39 +0100 Subject: [PATCH 10/89] Fix --- pandora_console/general/sap_view.php | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/pandora_console/general/sap_view.php b/pandora_console/general/sap_view.php index a66ae80d0a..626de03118 100644 --- a/pandora_console/general/sap_view.php +++ b/pandora_console/general/sap_view.php @@ -1,10 +1,10 @@ Date: Wed, 18 Nov 2020 16:48:49 +0100 Subject: [PATCH 11/89] fixed status filter when applying changes to a module of any agent --- .../godmode/massive/massive_edit_modules.php | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index 8c5a611847..c3abea586a 100755 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -50,6 +50,7 @@ if ($update) { $agents_ = []; $force = get_parameter('force_type', false); + $module_status = get_parameter('status_module', null); if ($agents_select == false) { $agents_select = []; @@ -109,7 +110,7 @@ if ($update) { } foreach ($module_name as $mod_name) { - $result = process_manage_edit($mod_name['nombre'], $id_agent, $modules_selection_mode); + $result = process_manage_edit($mod_name['nombre'], $id_agent, $module_status, $modules_selection_mode); $count++; $success += (int) $result; } @@ -132,7 +133,7 @@ if ($update) { } foreach ($module_name as $mod_name) { - $result = process_manage_edit($mod_name['nombre'], $id_agent, $modules_selection_mode); + $result = process_manage_edit($mod_name['nombre'], $id_agent, $module_status, $modules_selection_mode); $count++; $success += (int) $result; } @@ -150,7 +151,7 @@ if ($update) { } foreach ($modules_ as $module_) { - $result = process_manage_edit($module_, $agent_, $modules_selection_mode); + $result = process_manage_edit($module_, $agent_, $module_status, $modules_selection_mode); $count++; $success += (int) $result; } @@ -1859,7 +1860,7 @@ function disabled_status () { /* ]]> */ = 15 && $module['id_tipo_modulo'] <= 18) { if ($snmp_version != '') { From 1ad1671612273fb02dd97dd412f3b41c32cd1b4e Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Mon, 23 Nov 2020 09:29:11 +0100 Subject: [PATCH 12/89] fix remove acl widget agent/module --- .../lib/Dashboard/Widgets/agent_module.php | 137 ++++++++---------- pandora_console/include/styles/dashboards.css | 4 + 2 files changed, 61 insertions(+), 80 deletions(-) diff --git a/pandora_console/include/lib/Dashboard/Widgets/agent_module.php b/pandora_console/include/lib/Dashboard/Widgets/agent_module.php index 9913b28aaf..7953550b7a 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/agent_module.php +++ b/pandora_console/include/lib/Dashboard/Widgets/agent_module.php @@ -27,6 +27,8 @@ */ namespace PandoraFMS\Dashboard; +use PandoraFMS\Agent; +use PandoraFMS\Module; /** * Agent module Widgets. @@ -324,7 +326,7 @@ class AgentModuleWidget extends Widget } foreach ($agents as $agent) { - if (!users_access_to_agent($agent['id_agente'])) { + if (users_access_to_agent($agent['id_agente']) === false) { continue; } @@ -343,8 +345,10 @@ class AgentModuleWidget extends Widget foreach ($modules_by_name as $module) { $row['modules'][$module['name']] = null; foreach ($module['id'] as $module_id) { - if (array_key_exists($module_id, $agent_modules)) { - $row['modules'][$module['name']] = modules_get_agentmodule_status($module_id); + if (array_key_exists($module_id, $agent_modules) === true) { + $row['modules'][$module['name']] = modules_get_agentmodule_status( + $module_id + ); break; } } @@ -361,12 +365,16 @@ class AgentModuleWidget extends Widget * Draw table Agent/Module. * * @param array $visualData Data for draw. + * @param array $allModules Data for th draw. * * @return string Html output. */ - private function generateViewAgentModule(array $visualData):string - { - $table_data = '
'; + private function generateViewAgentModule( + array $visualData, + array $allModules + ):string { + $style = 'display:flex; width:100%; height:100%; margin: 10px;'; + $table_data = '
'; $table_data .= ''; if (empty($visualData) === false) { @@ -374,20 +382,7 @@ class AgentModuleWidget extends Widget $array_names = []; - foreach ($visualData as $data) { - foreach ($data['modules'] as $module_name => $module) { - if ($module === null - || in_array($module_name, $array_names) - ) { - continue; - } else { - $array_names[] = $module_name; - } - } - } - - natcasesort($array_names); - foreach ($array_names as $module_name) { + foreach ($allModules as $module_name) { $file_name = ui_print_truncate_text( $module_name, 'module_small', @@ -444,14 +439,17 @@ class AgentModuleWidget extends Widget foreach ($row['modules'] as $module_name => $module) { if ($module === null) { - if (in_array($module_name, $array_names)) { - $table_data .= "'; } else { continue; } } else { - $table_data .= "
"; + if (in_array($module_name, $allModules) === true) { + $style = 'background-color: transparent;'; + $table_data .= ""; $table_data .= '"; + $style = 'text-align: center;'; + $style .= ' background-color: transparent;'; + $table_data .= ""; switch ($module) { case AGENT_STATUS_NORMAL: $table_data .= \ui_print_status_image( @@ -592,70 +590,49 @@ class AgentModuleWidget extends Widget return $output; } - if (isset($this->values['mAgents']) === true - && empty($this->values['mAgents']) === false - ) { - $sql = sprintf( - 'SELECT id_agente,nombre,alias - FROM tagente - WHERE id_agente IN (%s) - ORDER BY id_agente', - $this->values['mAgents'] - ); - $agents = db_get_all_rows_sql($sql); - if ($agents === false) { - $agents = []; + // Estract info all modules selected. + $target_modules = explode(',', $this->values['mModules']); + $all_modules = Module::search( + ['id_agente_modulo' => $target_modules] + ); + $reduceAllModules = array_reduce( + $all_modules, + function ($carry, $item) { + $carry[$item->name()] = null; + return $carry; } + ); - $modules = false; - if (isset($this->values['mModules']) === true - && empty($this->values['mModules']) === false - ) { - $sql = sprintf( - 'SELECT nombre - FROM tagente_modulo - WHERE id_agente_modulo IN (%s)', - $this->values['mModules'] + \ksort($reduceAllModules); + + $visualData = []; + // Estract info agents selected. + $target_agents = explode(',', $this->values['mAgents']); + foreach ($target_agents as $agent_id) { + try { + $agent = new Agent($agent_id); + $visualData[$agent_id]['agent_status'] = $agent->lastStatus(); + $visualData[$agent_id]['agent_name'] = $agent->name(); + $visualData[$agent_id]['agent_alias'] = $agent->alias(); + + $modules = $agent->searchModules( + ['id_agente_modulo' => $target_modules] ); - $arrayNames = db_get_all_rows_sql($sql); - $names = array_reduce( - $arrayNames, - function ($carry, $item) { - $carry[] = $item['nombre']; - return $carry; - } - ); - - $sql = sprintf( - 'SELECT id_agente_modulo,nombre - FROM tagente_modulo - WHERE id_agente IN (%s) - AND nombre IN ("%s") - AND delete_pending = 0 - ORDER BY nombre', - $this->values['mAgents'], - implode('","', $names) - ); - - $modules = index_array( - db_get_all_rows_sql($sql), - 'id_agente_modulo', - 'nombre' - ); + $visualData[$agent_id]['modules'] = $reduceAllModules; + foreach ($modules as $module) { + $visualData[$agent_id]['modules'][$module->name()] = $module->getStatus()->estado(); + } + } catch (Exception $e) { + echo 'Error: '.$e->getMessage(); } - - if ($modules === false) { - $modules = []; - } - } else { - $agents = []; - $modules = []; } - $visualData = $this->generateDataAgentModule($agents, $modules); - - $output = $this->generateViewAgentModule($visualData); + $allModules = array_keys($reduceAllModules); + $output = $this->generateViewAgentModule( + $visualData, + $allModules + ); return $output; } diff --git a/pandora_console/include/styles/dashboards.css b/pandora_console/include/styles/dashboards.css index bbbf993112..70c41dd643 100644 --- a/pandora_console/include/styles/dashboards.css +++ b/pandora_console/include/styles/dashboards.css @@ -407,6 +407,10 @@ table.group_modules_status_box tr td span a { text-align: center; } +table.widget_agent_module tbody tr td { + padding: 5px; +} + .container-center .widget-histogram-chart .flot-text .flot-x-axis div { white-space: nowrap; } From 266dc8ba4ab76babc1a01deda0292b9a825bc6dc Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Mon, 23 Nov 2020 16:38:06 +0100 Subject: [PATCH 13/89] fix public view link remove hash --- .../models/VisualConsole/Container.php | 21 +++++++++++++++++ .../operation/visual_console/public_view.php | 23 +++++++++++++++++++ .../operation/visual_console/view.php | 7 ++++++ 3 files changed, 51 insertions(+) diff --git a/pandora_console/include/rest-api/models/VisualConsole/Container.php b/pandora_console/include/rest-api/models/VisualConsole/Container.php index 16d72c9d95..04e2927893 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Container.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Container.php @@ -88,6 +88,7 @@ final class Container extends Model 'height' => (int) $data['height'], 'backgroundURL' => static::extractBackgroundUrl($data), 'relationLineWidth' => (int) $data['relationLineWidth'], + 'hash' => static::extractHash($data), ]; } @@ -198,6 +199,22 @@ final class Container extends Model } + /** + * Extract a hash. + * + * @param array $data Unknown input data structure. + * + * @return mixed String representing hash (not empty) or null. + */ + private static function extractHash(array $data) + { + return static::notEmptyStringOr( + static::issetInArray($data, ['hash']), + null + ); + } + + /** * Extract a background color value. * @@ -279,6 +296,10 @@ final class Container extends Model ); } + $row['hash'] = md5( + $config['dbpass'].$row['id'].$config['id_user'] + ); + return \io_safe_output($row); } diff --git a/pandora_console/operation/visual_console/public_view.php b/pandora_console/operation/visual_console/public_view.php index 6cc9f817a1..f8b7c0eff9 100644 --- a/pandora_console/operation/visual_console/public_view.php +++ b/pandora_console/operation/visual_console/public_view.php @@ -177,6 +177,22 @@ $visualConsoleItems = VisualConsole::getItemsFromDB( var handleUpdate = function (prevProps, newProps) { if (!newProps) return; + //Remove spinner change VC. + document + .getElementById("visual-console-container") + .classList.remove("is-updating"); + + var div = document + .getElementById("visual-console-container") + .querySelector(".div-visual-console-spinner"); + + if (div !== null) { + var parent = div.parentElement; + if (parent !== null) { + parent.removeChild(div); + } + } + // Change the background color when the fullscreen mode is enabled. if (prevProps && prevProps.backgroundColor != newProps.backgroundColor @@ -200,17 +216,24 @@ $visualConsoleItems = VisualConsole::getItemsFromDB( var regex = /(id=|id_visual_console=|id_layout=|id_visualmap=)\d+(&?)/gi; var replacement = '$1' + newProps.id + '$2'; + var regex_hash = /(hash=)[^&]+(&?)/gi; + var replacement_hash = '$1' + newProps.hash + '$2'; // Tab links. var menuLinks = document.querySelectorAll("div#menu_tab a"); if (menuLinks !== null) { menuLinks.forEach(function (menuLink) { menuLink.href = menuLink.href.replace(regex, replacement); + menuLink.href = menuLink.href.replace( + regex_hash, + replacement_hash + ); }); } // Change the URL (if the browser has support). if ("history" in window) { var href = window.location.href.replace(regex, replacement); + href = href.replace(regex_hash, replacement_hash); window.history.replaceState({}, document.title, href); } } diff --git a/pandora_console/operation/visual_console/view.php b/pandora_console/operation/visual_console/view.php index 3b70215aa2..7f889509a0 100644 --- a/pandora_console/operation/visual_console/view.php +++ b/pandora_console/operation/visual_console/view.php @@ -470,11 +470,17 @@ ui_require_css_file('form'); var regex = /(id=|id_visual_console=|id_layout=|id_visualmap=)\d+(&?)/gi; var replacement = '$1' + newProps.id + '$2'; + var regex_hash = /(hash=)[^&]+(&?)/gi; + var replacement_hash = '$1' + newProps.hash + '$2'; // Tab links. var menuLinks = document.querySelectorAll("div#menu_tab a"); if (menuLinks !== null) { menuLinks.forEach(function (menuLink) { menuLink.href = menuLink.href.replace(regex, replacement); + menuLink.href = menuLink.href.replace( + regex_hash, + replacement_hash + ); }); } @@ -487,6 +493,7 @@ ui_require_css_file('form'); // Change the URL (if the browser has support). if ("history" in window) { var href = window.location.href.replace(regex, replacement); + href = href.replace(regex_hash, replacement_hash); window.history.replaceState({}, document.title, href); } } From a767b6c13374e729a1afd084e50acc7c15e22e48 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 23 Nov 2020 20:16:11 +0100 Subject: [PATCH 14/89] Fixes in history db settings and improved pandora_db tool --- pandora_console/godmode/setup/performance.php | 7 +-- pandora_server/util/pandora_db.pl | 54 ++++++++++++++++--- 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/pandora_console/godmode/setup/performance.php b/pandora_console/godmode/setup/performance.php index 096defb664..bc79631697 100644 --- a/pandora_console/godmode/setup/performance.php +++ b/pandora_console/godmode/setup/performance.php @@ -64,7 +64,7 @@ if ($update_config == 1 && $config['history_db_enabled'] == 1) { $historical_string_purge = get_parameter('historical_string_purge', 0); $history_connect = @mysql_db_process_sql( - 'SELECT 1 FROM tconfig', + 'DESCRIBE tconfig', 'affected_rows', $config['history_db_connection'], false @@ -390,8 +390,8 @@ if ($config['history_db_enabled'] == 1) { $config_history = false; if ($config['history_db_connection']) { - $history_connect = @mysql_db_process_sql( - 'SELECT 1 FROM tconfig', + $history_connect = mysql_db_process_sql( + 'DESCRIBE tconfig', 'affected_rows', $config['history_db_connection'], false @@ -408,6 +408,7 @@ if ($config['history_db_enabled'] == 1) { if (isset($config_history_array) && is_array($config_history_array)) { foreach ($config_history_array as $key => $value) { $config_history[$value['token']] = $value['value']; + $config_history = true; } } } else { diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 2c55dbf933..4cac97dd34 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -581,6 +581,28 @@ sub pandora_init_pdb ($) { help_screen () if ($conf->{'_pandora_path'} eq ''); } +######################################################################## +# Prepares conf read from historical database settings. +######################################################################## +sub pandoradb_load_history_conf($) { + my $dbh = shift; + + my @options = get_db_rows($dbh, 'SELECT * FROM `tconfig`'); + + my %options = map + { + '_' . $_->{'token'} => $_->{'value'} + } @options; + + $options{'_days_autodisable_deletion'} = 0 unless defined ($options{'_days_autodisable_deletion'}); + $options{'_num_past_special_days'} = 0 unless defined($options{'_num_past_special_days'}); + $options{'_delete_old_network_matrix'} = 0 unless defined($options{'_delete_old_network_matrix'}); + $options{'_delete_old_messages'} = 0 unless defined($options{'_delete_old_messages'}); + $options{'_netflow_max_lifetime'} = 0 unless defined($options{'_netflow_max_lifetime'}); + $options{'claim_back_snmp_modules'} = 0 unless defined($options{'claim_back_snmp_modules'}); + + return \%options; +} ######################################################################## # Read external configuration file. @@ -651,7 +673,7 @@ sub pandora_load_config_pdb ($) { $conf->{'_metaconsole_events_history'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'metaconsole_events_history'"); $conf->{'_netflow_max_lifetime'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'netflow_max_lifetime'"); $conf->{'_netflow_nfexpire'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'netflow_nfexpire'"); - $conf->{'_netflow_path'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'netflow_path'"); + $conf->{'_netflow_path'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'netflow_path'"); $conf->{'_delete_notinit'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'delete_notinit'"); $conf->{'_session_timeout'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = 'session_timeout'"); @@ -726,7 +748,7 @@ sub pandora_checkdb_consistency { # 1. Check for modules that do not have tagente_estado but have # tagente_module #------------------------------------------------------------------- - if (defined($conf->{'_delete_notinit'}) && $conf->{'_delete_notinit'} == 1) { + if (defined($conf->{'_delete_notinit'}) && $conf->{'_delete_notinit'} eq "1") { log_message ('CHECKDB', "Deleting not-init data."); my @modules = get_db_rows ($dbh, 'SELECT id_agente_modulo, id_agente @@ -956,7 +978,7 @@ sub pandora_delete_old_module_data { sub pandora_delete_old_export_data { my ($dbh, $ulimit_timestamp) = @_; - log_message ('PURGE', "Deleting old export data from tserver_export_data\n"); + log_message ('PURGE', "Deleting old export data from tserver_export_data"); while((my $rc = db_delete_limit ($dbh, 'tserver_export_data', 'UNIX_TIMESTAMP(timestamp) < ?', $SMALL_OPERATION_STEP, $ulimit_timestamp)) ne '0E0') { print "RC:$rc\n"; usleep (10000); @@ -982,7 +1004,7 @@ sub pandora_delete_old_session_data { $ulimit_timestamp = time() - $session_timeout; } - log_message ('PURGE', "Deleting old session data from tsessions_php\n"); + log_message ('PURGE', "Deleting old session data from tsessions_php"); while(db_delete_limit ($dbh, 'tsessions_php', 'last_active < ?', $SMALL_OPERATION_STEP, $ulimit_timestamp) ne '0E0') { usleep (10000); }; @@ -1076,8 +1098,9 @@ if ($conf{'_force'} == 0 && pandora_is_master(\%conf) == 0) { exit 1; } -# Get a lock -my $lock = db_get_lock ($dbh, 'pandora_db'); +# Get a lock on dbname. +my $lock_name = $conf{'dbname'}; +my $lock = db_get_lock ($dbh, $lock_name); if ($lock == 0 && $conf{'_force'} == 0) { log_message ('', " [*] Another instance of DB Tool seems to be running.\n\n"); exit 1; @@ -1086,9 +1109,26 @@ if ($lock == 0 && $conf{'_force'} == 0) { # Main pandoradb_main(\%conf, $dbh, $history_dbh); +# history_dbh is unset in pandoradb_main if not in use. +if (defined($history_dbh)) { + log_message('', " [>] DB Tool running on historical database.\n"); + my $h_conf = pandoradb_load_history_conf($history_dbh); + + # Keep base settings. + $h_conf->{'_onlypurge'} = $conf{'_onlypurge'}; + + # Re-launch maintenance process for historical database. + pandoradb_main( + $h_conf, + $history_dbh, + undef + ); + +} + # Release the lock if ($lock == 1) { - db_release_lock ($dbh, 'pandora_db'); + db_release_lock ($dbh, $lock_name); } # Cleanup and exit From 2428558a39a8d5d57829a971903403df3e319a01 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Tue, 24 Nov 2020 10:59:42 +0100 Subject: [PATCH 15/89] fix bugs vc serialez module string donuts and bars charts --- .../rest-api/models/VisualConsole/Items/DonutGraph.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/rest-api/models/VisualConsole/Items/DonutGraph.php b/pandora_console/include/rest-api/models/VisualConsole/Items/DonutGraph.php index 65f671d405..f73806967e 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Items/DonutGraph.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Items/DonutGraph.php @@ -167,10 +167,12 @@ final class DonutGraph extends Item ); } else { $src = 'images/console/signes/wrong_donut_graph.png'; - if (\is_metaconsole() === true && $metaconsoleId !== null) { + if (\is_metaconsole() === true) { $src = '../../'.$src; } + $src = ui_get_full_url($src); + $style = 'width:'.$width.'px; height:'.$height.'px;'; $data['html'] = ''; } From 7931f171447572b2e8ddd5be9c6511fa87d0185f Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Tue, 24 Nov 2020 14:08:37 +0100 Subject: [PATCH 16/89] fixed selector --- pandora_console/godmode/massive/massive_edit_modules.php | 1 + 1 file changed, 1 insertion(+) diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php index 1948ba4fa0..8bf6817310 100755 --- a/pandora_console/godmode/massive/massive_edit_modules.php +++ b/pandora_console/godmode/massive/massive_edit_modules.php @@ -1138,6 +1138,7 @@ $table->data['edit1'][1] = ''; ); $array_os = [ + '' => __('No change'), 'inherited' => __('Inherited'), 'linux' => __('Linux'), 'windows' => __('Windows'), From e2bdb4858a53970fda7c0b2b51433f93c0393af9 Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Tue, 24 Nov 2020 16:13:28 +0100 Subject: [PATCH 17/89] included not init modules in total count --- pandora_console/include/functions_reporting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 479adc67c8..6ffdf374bd 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -10688,7 +10688,7 @@ function reporting_tiny_stats( if (isset($counts_info['total_count'])) { $not_init = isset($counts_info['notinit_count']) ? $counts_info['notinit_count'] : 0; - $total_count = ($counts_info['total_count'] - $not_init); + $total_count = $counts_info['total_count']; $stats[] = [ 'name' => 'total_count', 'count' => $total_count, From 2e950af548ac67ea40a73dc8d5f653af80e3eafd Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Wed, 25 Nov 2020 11:33:36 +0100 Subject: [PATCH 18/89] fix dashboard VC --- .../Dashboard/Widgets/maps_made_by_user.php | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/pandora_console/include/lib/Dashboard/Widgets/maps_made_by_user.php b/pandora_console/include/lib/Dashboard/Widgets/maps_made_by_user.php index f480c45389..89fb8b6c6c 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/maps_made_by_user.php +++ b/pandora_console/include/lib/Dashboard/Widgets/maps_made_by_user.php @@ -368,26 +368,27 @@ class MapsMadeByUser extends Widget // of the visual consoles. $output .= '