From 3dc57f8a8ce732305fc2ac606cfe28770fd40ad0 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 6 Apr 2022 14:29:24 +0200 Subject: [PATCH 001/174] some fixes in version control and php memory usage --- .../include/class/ConsoleSupervisor.php | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index 767722931d..ae61026fb3 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -1528,7 +1528,7 @@ class ConsoleSupervisor $this->cleanNotifications('NOTIF.PHP.UPLOAD_MAX_FILESIZE'); } - if ($PHPmemory_limit < $PHPmemory_limit_min && $PHPmemory_limit !== '-1') { + if ($PHPmemory_limit < $PHPmemory_limit_min && (int) $PHPmemory_limit !== -1) { $url = 'http://php.net/manual/en/ini.core.php#ini.memory-limit'; if ($config['language'] == 'es') { $url = 'http://php.net/manual/es/ini.core.php#ini.memory-limit'; @@ -2490,7 +2490,7 @@ class ConsoleSupervisor foreach ($server_version_list as $server) { if (strpos( $server['version'], - $config['current_package'] + floor($config['current_package']) ) === false ) { $missed++; @@ -2511,6 +2511,8 @@ class ConsoleSupervisor 'url' => '__url__/index.php?sec=messages&sec2=godmode/update_manager/update_manager&tab=online', ] ); + + break; } } } @@ -2532,18 +2534,19 @@ class ConsoleSupervisor global $config; $message = 'If AllowOverride is disabled, .htaccess will not works.'; - if (PHP_OS == 'FreeBSD') { - $message .= '
Please check /usr/local/etc/apache24/httpd.conf to resolve this problem.';
-	} else {
+        if (PHP_OS == 'FreeBSD') {
+            $message .= '
Please check /usr/local/etc/apache24/httpd.conf to resolve this problem.';
+        } else {
             $message .= '
Please check /etc/httpd/conf/httpd.conf to resolve this problem.';
-	}
+        }
 
         // Get content file.
-	if (PHP_OS == 'FreeBSD') {
-	    $file = file_get_contents('/usr/local/etc/apache24/httpd.conf');
-	} else {
+        if (PHP_OS == 'FreeBSD') {
+            $file = file_get_contents('/usr/local/etc/apache24/httpd.conf');
+        } else {
             $file = file_get_contents('/etc/httpd/conf/httpd.conf');
-	}
+        }
+
         $file_lines = preg_split("#\r?\n#", $file, -1, PREG_SPLIT_NO_EMPTY);
         $is_none = false;
 

From 2ab1aa601c7d8220a3f7c9b021c14d719f1578b2 Mon Sep 17 00:00:00 2001
From: fbsanchez 
Date: Wed, 20 Apr 2022 14:10:23 +0200
Subject: [PATCH 002/174] Service tree view with local scope parents

---
 pandora_console/general/header.php            |  2 +-
 .../include/class/TreeService.class.php       |  2 +
 pandora_console/include/functions.php         | 50 +++++++++++++++++++
 .../include/javascript/tree/TreeController.js |  3 +-
 4 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/pandora_console/general/header.php b/pandora_console/general/header.php
index 9b0333c55a..5e2ad24ce2 100644
--- a/pandora_console/general/header.php
+++ b/pandora_console/general/header.php
@@ -954,7 +954,7 @@ echo sprintf('
', $menuTypeClass); $("a.autorefresh").click (function () { $("a.autorefresh_txt").toggle (); - $("#combo_refr").toggle (); + $("#combo_refr").toggle(); $("select#ref").change (function () { href = $("a.autorefresh").attr ("href"); diff --git a/pandora_console/include/class/TreeService.class.php b/pandora_console/include/class/TreeService.class.php index ebca4562a6..e69862a9fd 100644 --- a/pandora_console/include/class/TreeService.class.php +++ b/pandora_console/include/class/TreeService.class.php @@ -523,6 +523,8 @@ class TreeService extends Tree continue 2; } + $tmp['parents'] = $item->service()->getAncestors(); + $tmp['title'] = join('/', $tmp['parents']); $tmp['id'] = (int) $item->service()->id(); $tmp['name'] = $item->service()->name(); $tmp['alias'] = $item->service()->name(); diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index ca0c9dad7d..c1b6697022 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -5986,6 +5986,56 @@ function send_test_email( } +/** + * Return array of ancestors of item, given array. + * + * @param integer $item From index. + * @param array $data Array data. + * @param string $key Pivot key (identifies the parent). + * @param string|null $extract Extract certain column or index. + * @param array $visited Cycle detection. + * + * @return array Array of ancestors. + */ +function get_ancestors( + int $item, + array $data, + string $key, + ?string $extract=null, + array &$visited=[] +) :array { + if (isset($visited[$item]) === true) { + return []; + } + + $visited[$item] = 1; + + if (isset($data[$item]) === false) { + return []; + } + + if (isset($data[$item][$key]) === false) { + if ($extract !== null) { + return [$data[$item][$extract]]; + } + + return [$item]; + } + + if ($extract !== null) { + return array_merge( + get_ancestors($data[$item][$key], $data, $key, $extract, $visited), + [$data[$item][$extract]] + ); + } + + return array_merge( + get_ancestors($data[$item][$key], $data, $key, $extract, $visited), + [$item] + ); +} + + if (function_exists('str_contains') === false) { diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index 7f22c6e9d0..a09be1880d 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -848,6 +848,7 @@ var TreeController = { break; case "services": + console.log(element); if ( typeof element.statusImageHTML != "undefined" && element.statusImageHTML.length > 0 @@ -861,7 +862,7 @@ var TreeController = { '' +
                 element.name +
                 ' '; From 87cd23b08a214eba49ae59f4a2d05c7d0a7dc6a1 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 20 Apr 2022 18:41:03 +0200 Subject: [PATCH 003/174] a nice trick --- pandora_console/include/class/TreeService.class.php | 10 ++++++++-- .../include/javascript/tree/TreeController.js | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/class/TreeService.class.php b/pandora_console/include/class/TreeService.class.php index e69862a9fd..43da11116e 100644 --- a/pandora_console/include/class/TreeService.class.php +++ b/pandora_console/include/class/TreeService.class.php @@ -523,8 +523,14 @@ class TreeService extends Tree continue 2; } - $tmp['parents'] = $item->service()->getAncestors(); - $tmp['title'] = join('/', $tmp['parents']); + $title = get_parameter('title', ''); + if (empty($title) === true) { + $tmp['title'] = ''; + } else { + $tmp['title'] = $title.'/'; + } + + $tmp['title'] .= $service->name(); $tmp['id'] = (int) $item->service()->id(); $tmp['name'] = $item->service()->name(); $tmp['alias'] = $item->service()->name(); diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index a09be1880d..b90b76a021 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -848,7 +848,6 @@ var TreeController = { break; case "services": - console.log(element); if ( typeof element.statusImageHTML != "undefined" && element.statusImageHTML.length > 0 @@ -1302,6 +1301,7 @@ var TreeController = { .removeClass("leaf-error") .addClass("leaf-loading"); + console.log(element); $.ajax({ url: controller.ajaxURL, type: "POST", @@ -1315,6 +1315,7 @@ var TreeController = { serverID: element.serverID, rootType: element.rootType, metaID: element.metaID, + title: element.title, filter: controller.filter, auth_class: controller.auth_class, id_user: controller.id_user, From 78907e691c810cfee568aac4b6e05dfde138967e Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 20 Apr 2022 18:45:52 +0200 Subject: [PATCH 004/174] removed traces --- pandora_console/include/javascript/tree/TreeController.js | 1 - 1 file changed, 1 deletion(-) diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index b90b76a021..073a862c4c 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -1301,7 +1301,6 @@ var TreeController = { .removeClass("leaf-error") .addClass("leaf-loading"); - console.log(element); $.ajax({ url: controller.ajaxURL, type: "POST", From 00f594293cbb57f05ecbb1d1930ae5eb3a4857e8 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 20 Apr 2022 19:20:54 +0200 Subject: [PATCH 005/174] hint parents in service selection --- .../include/lib/Dashboard/Widgets/service_map.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/lib/Dashboard/Widgets/service_map.php b/pandora_console/include/lib/Dashboard/Widgets/service_map.php index a2122c6dca..3dbcbdf5b0 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/service_map.php +++ b/pandora_console/include/lib/Dashboard/Widgets/service_map.php @@ -268,7 +268,20 @@ class ServiceMapWidget extends Widget $fields = array_reduce( $services_res, function ($carry, $item) { - $carry[$item['id']] = $item['name']; + $parents = ''; + if (class_exists('\PandoraFMS\Enterprise\Service') === true) { + try { + $service = new \PandoraFMS\Enterprise\Service($item['id']); + $ancestors = $service->getAncestors(); + if (empty($ancestors) === false) { + $parents = '('.join('/', $ancestors).')'; + } + } catch (\Exception $e) { + $parents = ''; + } + } + + $carry[$item['id']] = $item['name'].' '.$parents; return $carry; }, [] From ab9557c681c329cc741e36bf7dc3a0f594583d36 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Thu, 21 Apr 2022 18:09:26 +0200 Subject: [PATCH 006/174] prevent registration dialog from showing up in update manager of metaconsole nodes --- pandora_console/godmode/update_manager/update_manager.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pandora_console/godmode/update_manager/update_manager.php b/pandora_console/godmode/update_manager/update_manager.php index da9eb8543d..991491843a 100644 --- a/pandora_console/godmode/update_manager/update_manager.php +++ b/pandora_console/godmode/update_manager/update_manager.php @@ -107,7 +107,11 @@ switch ($tab) { case 'online': default: - $mode = \UpdateManager\UI\Manager::MODE_ONLINE; - include $config['homedir'].'/godmode/um_client/index.php'; + if ($config['node_metaconsole'] === 0) { + $mode = \UpdateManager\UI\Manager::MODE_ONLINE; + include $config['homedir'].'/godmode/um_client/index.php'; + } else { + ui_print_warning_message(__('Please register on metaconsole.')); + } break; } From dfc599b2d8004ed883337780509116dc339344f7 Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 22 Apr 2022 18:27:29 +0200 Subject: [PATCH 007/174] WIP: Meta disable groups CLI --- pandora_server/util/pandora_manage.pl | 66 +++++++++++++++++++-------- 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 0b6a96f3a4..a80b55c8ac 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -375,29 +375,55 @@ sub pandora_disable_group ($$$) { exit; } - if ($group == 0){ - # Extract all the names of the pandora agents if it is for all = 0. - @agents_bd = get_db_rows ($dbh, 'SELECT nombre FROM tagente'); + if(is_metaconsole($conf) == 1) { + my $servers = enterprise_hook('get_metaconsole_setup_servers',[$dbh]); + my @servers_id = split(',',$servers); + use Data:Dumper; + print Dumper() + foreach my $server (@servers_id) { + my $dbh_metaconsole = enterprise_hook('get_node_dbh',[$conf, $server, $dbh]); - # Update bbdd. - db_do ($dbh, "UPDATE tagente SET disabled = 1"); - } - else { - # Extract all the names of the pandora agents if it is for group. - @agents_bd = get_db_rows ($dbh, 'SELECT nombre FROM tagente WHERE id_grupo = ?', $group); + if ($group == 0){ + # Extract all the names of the pandora agents if it is for all = 0. + @agents_bd = get_db_rows ($dbh_metaconsole, 'SELECT id_agente FROM tagente'); + } + else { + # Extract all the names of the pandora agents if it is for group. + @agents_bd = get_db_rows ($dbh_metaconsole, 'SELECT id_agente FROM tagente WHERE id_grupo = ?', $group); + } - # Update bbdd. - db_do ($dbh, "UPDATE tagente SET disabled = 1 WHERE id_grupo = $group"); - } + foreach my $id_agent (@agents_bd) { + # Call the API. + $result = api_call( + $conf, 'set', 'disabled_and_standby', $id_agent, $server, 1 + ); + } + } + } else { + if ($group == 0){ + # Extract all the names of the pandora agents if it is for all = 0. + @agents_bd = get_db_rows ($dbh, 'SELECT nombre FROM tagente'); - foreach my $name_agent (@agents_bd) { - # Check the standby field I put it to 0. - my $new_conf = update_conf_txt( - $conf, - $name_agent->{'nombre'}, - 'standby', - '1' - ); + # Update bbdd. + db_do ($dbh, "UPDATE tagente SET disabled = 1"); + } + else { + # Extract all the names of the pandora agents if it is for group. + @agents_bd = get_db_rows ($dbh, 'SELECT nombre FROM tagente WHERE id_grupo = ?', $group); + + # Update bbdd. + db_do ($dbh, "UPDATE tagente SET disabled = 1 WHERE id_grupo = $group"); + } + + foreach my $name_agent (@agents_bd) { + # Check the standby field I put it to 0. + my $new_conf = update_conf_txt( + $conf, + $name_agent->{'nombre'}, + 'standby', + '1' + ); + } } return $result; From f4ac0d19d033c46bd658d91690c0bdcebc19d688 Mon Sep 17 00:00:00 2001 From: Luis Date: Mon, 25 Apr 2022 13:17:13 +0200 Subject: [PATCH 008/174] WIP: pandora manage disable group --- pandora_server/util/pandora_manage.pl | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index a80b55c8ac..6b89b6c35c 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -36,7 +36,7 @@ use Encode::Locale; Encode::Locale::decode_argv; # version: define current version -my $version = "7.0NG.761 Build 220420"; +my $version = "7.0NG.761 Build 220425"; # save program name for logging my $progname = basename($0); @@ -378,8 +378,6 @@ sub pandora_disable_group ($$$) { if(is_metaconsole($conf) == 1) { my $servers = enterprise_hook('get_metaconsole_setup_servers',[$dbh]); my @servers_id = split(',',$servers); - use Data:Dumper; - print Dumper() foreach my $server (@servers_id) { my $dbh_metaconsole = enterprise_hook('get_node_dbh',[$conf, $server, $dbh]); @@ -394,9 +392,11 @@ sub pandora_disable_group ($$$) { foreach my $id_agent (@agents_bd) { # Call the API. - $result = api_call( - $conf, 'set', 'disabled_and_standby', $id_agent, $server, 1 - ); + use Data::Dumper; + print Dumper($conf); + $result .= api_call( + $conf, 'set', 'disabled_and_standby', $id_agent, $server, 1, 1 + ).'\n'; } } } else { @@ -1164,7 +1164,8 @@ sub cli_disable_group() { print_log "[INFO] Disabling group '$group_name'\n\n"; } - pandora_disable_group ($conf, $dbh, $id_group); + my $result = pandora_disable_group ($conf, $dbh, $id_group); + print $result.'\n\n'; } ############################################################################## From 1a8a90a82f464490cd8c30b9d51347c36325d5ac Mon Sep 17 00:00:00 2001 From: Rafael Date: Mon, 25 Apr 2022 20:22:42 +0200 Subject: [PATCH 009/174] fix os check for rhel8 --- extras/deploy-scripts/pandora_agent_deploy.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/extras/deploy-scripts/pandora_agent_deploy.sh b/extras/deploy-scripts/pandora_agent_deploy.sh index 74db9d7c72..9be1edf00f 100644 --- a/extras/deploy-scripts/pandora_agent_deploy.sh +++ b/extras/deploy-scripts/pandora_agent_deploy.sh @@ -4,7 +4,7 @@ # define variables PANDORA_AGENT_CONF=/etc/pandora/pandora_agent.conf -S_VERSION='2021100601' +S_VERSION='2022042501' LOGFILE="/tmp/pandora-agent-deploy-$(date +%F).log" # Ansi color code variables @@ -83,6 +83,7 @@ execute_cmd "[ $PANDORA_SERVER_IP ]" 'Check Server IP Address' 'Please define e OS=$([[ $(grep '^ID_LIKE=' /etc/os-release) ]] && grep ^ID_LIKE= /etc/os-release | cut -d '=' -f2 | tr -d '"' || grep ^ID= /etc/os-release | cut -d '=' -f2 | tr -d '"') [[ $OS =~ 'rhel' ]] && OS_RELEASE=$OS +[[ $OS =~ 'fedora' ]] && OS_RELEASE=$OS [[ $OS =~ 'debian' ]] && OS_RELEASE=$OS #[[ $OS == 'rhel fedora' ]] && OS_RELEASE=$OS #[[ $OS == 'centos rhel fedora' ]] && OS_RELEASE=$OS @@ -113,7 +114,7 @@ execute_cmd "cd $HOME/pandora_deploy_tmp" "Moving to workspace: $HOME/pandora_d # Downloading and installing packages -if [[ $OS_RELEASE =~ 'rhel' ]]; then +if [[ $OS_RELEASE =~ 'rhel' ]] || [[ $OS_RELEASE =~ 'fedora' ]]; then yum install -y perl wget curl perl-Sys-Syslog unzip &>> $LOGFILE echo -e "${cyan}Instaling agent dependencies...${reset}" ${green}OK${reset} From 7190a797ec17f0d2fe86c6a4f94928c091aca43e Mon Sep 17 00:00:00 2001 From: Luis Date: Tue, 26 Apr 2022 14:47:49 +0200 Subject: [PATCH 010/174] Fix meta CLI disable group --- pandora_server/util/pandora_manage.pl | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 6b89b6c35c..8bdfc165cf 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -21,7 +21,7 @@ use JSON qw(decode_json encode_json); use MIME::Base64; use Encode qw(decode encode_utf8); use LWP::Simple; -use Data::Dumper; +#use Data::Dumper; # Default lib dir for RPM and DEB packages BEGIN { push @INC, '/usr/lib/perl5'; } @@ -392,11 +392,9 @@ sub pandora_disable_group ($$$) { foreach my $id_agent (@agents_bd) { # Call the API. - use Data::Dumper; - print Dumper($conf); - $result .= api_call( - $conf, 'set', 'disabled_and_standby', $id_agent, $server, 1, 1 - ).'\n'; + $result += api_call( + $conf, 'set', 'disabled_and_standby', $id_agent->{'id_agente'}, $server, '1|1' + ); } } } else { @@ -405,14 +403,14 @@ sub pandora_disable_group ($$$) { @agents_bd = get_db_rows ($dbh, 'SELECT nombre FROM tagente'); # Update bbdd. - db_do ($dbh, "UPDATE tagente SET disabled = 1"); + $result = db_update ($dbh, "UPDATE tagente SET disabled = 1"); } else { # Extract all the names of the pandora agents if it is for group. @agents_bd = get_db_rows ($dbh, 'SELECT nombre FROM tagente WHERE id_grupo = ?', $group); # Update bbdd. - db_do ($dbh, "UPDATE tagente SET disabled = 1 WHERE id_grupo = $group"); + $result = db_update ($dbh, "UPDATE tagente SET disabled = 1 WHERE id_grupo = $group"); } foreach my $name_agent (@agents_bd) { @@ -1165,7 +1163,7 @@ sub cli_disable_group() { } my $result = pandora_disable_group ($conf, $dbh, $id_group); - print $result.'\n\n'; + print_log "[INFO] Disbaled ".$result." agents from group ".$group_name."\n\n"; } ############################################################################## @@ -5566,8 +5564,6 @@ sub cli_get_agents() { my $head_print = 0; - # use Data::Dumper; - foreach my $agent (@agents) { if($status ne '') { From b5b273407090cd2ffd5834cf16b209291add5c27 Mon Sep 17 00:00:00 2001 From: Luis Date: Wed, 27 Apr 2022 10:42:06 +0200 Subject: [PATCH 011/174] Fix CLI delete group on meta --- pandora_server/util/pandora_manage.pl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 96253a489c..890c905823 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -5953,6 +5953,24 @@ sub cli_delete_group() { $group_id = db_do ($dbh, 'DELETE FROM tgrupo WHERE nombre=?', safe_input($group_name)); + # Delete on nodes too if metaconsole. + if(is_metaconsole($conf) == 1 && pandora_get_tconfig_token ($dbh, 'centralized_management', '')) { + my $servers = enterprise_hook('get_metaconsole_setup_servers',[$dbh]); + my @servers_id = split(',',$servers); + + foreach my $server (@servers_id) { + + my $dbh_node = enterprise_hook('get_node_dbh',[$conf, $server, $dbh]); + + my $group_id = get_group_id($dbh_node,$group_name); + exist_check($group_id, 'group name', $group_name); + + $group_id = db_do ($dbh_node, 'DELETE FROM tgrupo WHERE nombre=?', safe_input($group_name)); + + } + } + + if($group_id == -1) { print_log "[ERROR] A problem has been ocurred deleting group '$group_name'\n\n"; }else{ From 5c029effdb47dadd83015540979c6fe7f74f29e1 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Thu, 28 Apr 2022 11:51:48 +0200 Subject: [PATCH 012/174] minor fix --- pandora_server/lib/PandoraFMS/DataServer.pm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index 232361a50f..083fb77f8e 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -583,6 +583,11 @@ sub process_xml_data ($$$$$) { $module_data->{'data'} = $data->{'value'}; my $data_timestamp = get_tag_value ($data, 'timestamp', $timestamp); + + if ($pa_config->{'use_xml_timestamp'} eq '0' && defined($timestamp)) { + $data_timestamp = $timestamp; + } + process_module_data ($pa_config, $module_data, $server_id, $agent, $module_name, $module_type, $interval, $data_timestamp, $dbh, $new_agent); } From 7164bb0137011b7f5743a2deac121e1d0c18a813 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Thu, 28 Apr 2022 13:13:10 +0200 Subject: [PATCH 013/174] #8153 Added custom data --- .../reporting_builder.item_editor.php | 26 +++++++++- .../godmode/reporting/reporting_builder.php | 12 +++++ .../include/functions_reporting.php | 18 +++++-- .../include/functions_reporting_html.php | 51 ++++++++++++++++++- 4 files changed, 101 insertions(+), 6 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 2186c455d2..b5c66651b1 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -606,6 +606,7 @@ switch ($action) { $event_graph_by_criticity = $style['event_graph_by_criticity']; $event_graph_validated_vs_unvalidated = $style['event_graph_validated_vs_unvalidated']; $include_extended_events = $item['show_extended_events']; + $custom_data_events = $style['custom_data_events']; $filter_search = $style['event_filter_search']; $filter_exclude = $style['event_filter_exclude']; @@ -631,6 +632,7 @@ switch ($action) { $include_extended_events = $item['show_extended_events']; + $custom_data_events = $style['custom_data_events']; break; case 'event_report_module': @@ -665,6 +667,7 @@ switch ($action) { $include_extended_events = $item['show_extended_events']; + $custom_data_events = $style['custom_data_events']; break; case 'general': @@ -2911,6 +2914,23 @@ $class = 'databox filters'; + + + + + + + + + @@ -5974,6 +5994,7 @@ function chooseType() { $("#row_event_graph_by_criticity").hide(); $("#row_event_graph_by_validated").hide(); $("#row_extended_events").hide(); + $("#row_custom_data_events").hide(); $("#row_netflow_filter").hide(); $("#row_max_values").hide(); $("#row_resolution").hide(); @@ -6044,6 +6065,7 @@ function chooseType() { $("#row_event_graph_by_criticity").show(); $("#row_event_graph_by_validated").show(); $("#row_extended_events").show(); + $("#row_custom_data_events").show(); $("#row_filter_search").show(); $("#row_filter_exclude").show(); @@ -6371,6 +6393,7 @@ function chooseType() { $("#row_event_graph_by_validated").show(); $("#row_event_type").show(); $("#row_extended_events").show(); + $("#row_custom_data_events").show(); $("#row_filter_search").show(); $("#row_filter_exclude").show(); @@ -6389,7 +6412,7 @@ function chooseType() { $("#row_event_graphs").show(); $("#row_event_type").show(); $("#row_extended_events").show(); - $("#row_extended_events").show(); + $("#row_custom_data_events").show(); $("#row_event_graph_by_user").show(); $("#row_event_graph_by_criticity").show(); @@ -6414,6 +6437,7 @@ function chooseType() { $("#row_event_graphs").show(); $("#row_event_type").show(); $("#row_extended_events").show(); + $("#row_custom_data_events").show(); $("#row_event_graph_by_user").show(); $("#row_event_graph_by_criticity").show(); diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 608f2f6a54..94c9e0b454 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -2224,12 +2224,18 @@ switch ($action) { $filter_event_status ); + $custom_data_events = get_parameter_switch( + 'custom_data_events', + 0 + ); + $style['event_graph_by_agent'] = $event_graph_by_agent; $style['event_graph_by_user_validator'] = $event_graph_by_user_validator; $style['event_graph_by_criticity'] = $event_graph_by_criticity; $style['event_graph_validated_vs_unvalidated'] = $event_graph_validated_vs_unvalidated; $style['event_filter_search'] = $event_filter_search; $style['event_filter_exclude'] = $event_filter_exclude; + $style['custom_data_events'] = $custom_data_events; if ($label != '') { @@ -2957,6 +2963,11 @@ switch ($action) { '' ); + $custom_data_events = get_parameter_switch( + 'custom_data_events', + 0 + ); + // Added for events items. $style['show_summary_group'] = $show_summary_group; @@ -2976,6 +2987,7 @@ switch ($action) { $style['event_graph_validated_vs_unvalidated'] = $event_graph_validated_vs_unvalidated; $style['event_filter_search'] = $event_filter_search; $style['event_filter_exclude'] = $event_filter_exclude; + $style['custom_data_events'] = $custom_data_events; if ($label != '') { $style['label'] = $label; diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 6bf29c1235..ae40d03de3 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -810,7 +810,7 @@ function reporting_make_reporting_data( break; } - $report['contents'][] = $report_control; + $report['contents'][] = $report_control; break; case 'event_report_module': @@ -826,7 +826,7 @@ function reporting_make_reporting_data( break; } - $report['contents'][] = $report_control; + $report['contents'][] = $report_control; break; case 'event_report_group': @@ -1943,6 +1943,8 @@ function reporting_event_report_group( $event_filter = $content['style']; $return['show_summary_group'] = $event_filter['show_summary_group']; + $return['show_custom_data'] = (isset($event_filter['custom_data_events']) === true) ? (bool) $event_filter['custom_data_events'] : false; + // Filter. $show_summary_group = $event_filter['show_summary_group']; $filter_event_severity = json_decode($event_filter['filter_event_severity'], true); @@ -2246,6 +2248,8 @@ function reporting_event_report_module( $event_filter = $content['style']; $return['show_summary_group'] = $event_filter['show_summary_group']; + $return['show_custom_data'] = (isset($event_filter['custom_data_events']) === true) ? (bool) $event_filter['custom_data_events'] : false; + // Filter. $show_summary_group = $event_filter['show_summary_group']; $filter_event_severity = json_decode( @@ -3779,6 +3783,8 @@ function reporting_event_report_agent( $filter_event_status = json_decode($style['filter_event_status'], true); $filter_event_filter_search = $style['event_filter_search']; $filter_event_filter_exclude = $style['event_filter_exclude']; + $show_custom_data = (isset($style['custom_data_events']) === true) ? (bool) $style['custom_data_events'] : false; + $return['show_custom_data'] = $show_custom_data; // Graph. $event_graph_by_user_validator = $style['event_graph_by_user_validator']; @@ -3798,7 +3804,8 @@ function reporting_event_report_agent( $filter_event_status, $filter_event_filter_search, $filter_event_filter_exclude, - $id_server + $id_server, + $show_custom_data ); if (is_metaconsole() === true) { @@ -10594,7 +10601,8 @@ function reporting_get_agents_detailed_event( $filter_event_status=false, $filter_event_filter_search=false, $filter_event_filter_exclude=false, - $id_server=0 + $id_server=0, + $show_custom_data=false ) { global $config; @@ -10651,6 +10659,7 @@ function reporting_get_agents_detailed_event( 'validated_by' => $e['id_usuario'], 'timestamp' => $e['timestamp_rep'], 'id_evento' => $e['id_evento'], + 'custom_data' => ($show_custom_data === true) ? $e['custom_data'] : '', ]; } else { $return_data[] = [ @@ -10661,6 +10670,7 @@ function reporting_get_agents_detailed_event( 'validated_by' => $e['id_usuario'], 'timestamp' => $e['timestamp'], 'id_evento' => $e['id_evento'], + 'custom_data' => ($show_custom_data === true) ? $e['custom_data'] : '', ]; } } diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index cd6af07794..d6450e37bd 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -1025,6 +1025,7 @@ function reporting_html_event_report_group($table, $item, $pdf=0) global $config; $show_extended_events = $item['show_extended_events']; + $show_custom_data = (bool) $item['show_custom_data']; if ($item['total_events']) { $table1 = new stdClass(); @@ -1060,6 +1061,10 @@ function reporting_html_event_report_group($table, $item, $pdf=0) $table1->head[6] = __('Timestamp'); } + if ($show_custom_data === true) { + $table1->head[8] = __('Custom data'); + } + foreach ($item['data'] as $k => $event) { // First pass along the class of this row. if ($item['show_summary_group']) { @@ -1132,6 +1137,16 @@ function reporting_html_event_report_group($table, $item, $pdf=0) $data[] = ''.date($config['date_format'], strtotime($event['timestamp'])).''; } + if ($show_custom_data === true) { + $custom_data = json_decode($event['custom_data'], true); + $custom_data_text = ''; + foreach ($custom_data as $key => $value) { + $custom_data_text .= $key.' = '.$value.'
'; + } + + $data[] = $custom_data_text; + } + array_push($table1->data, $data); if ($show_extended_events == 1 && events_has_extended_info($event['id_evento'])) { @@ -1246,10 +1261,10 @@ function reporting_html_event_report_group($table, $item, $pdf=0) function reporting_html_event_report_module($table, $item, $pdf=0) { global $config; - $show_extended_events = $item['show_extended_events']; $show_summary_group = $item['show_summary_group']; + $show_custom_data = (bool) $item['show_custom_data']; if ($item['total_events']) { if (!empty($item['failed'])) { $table->colspan['events']['cell'] = 3; @@ -1279,6 +1294,10 @@ function reporting_html_event_report_module($table, $item, $pdf=0) $table1->style[0] = 'text-align: center;'; } + if ($show_custom_data === true) { + $table1->head[6] = __('Custom data'); + } + if (is_array($item['data']) || is_object($item['data'])) { $item_data = array_reverse($item['data']); } @@ -1331,6 +1350,16 @@ function reporting_html_event_report_module($table, $item, $pdf=0) $data[4] = date($config['date_format'], strtotime($event['timestamp'])); } + if ($show_custom_data === true) { + $custom_data = json_decode($event['custom_data'], true); + $custom_data_text = ''; + foreach ($custom_data as $key => $value) { + $custom_data_text .= $key.' = '.$value.'
'; + } + + $data[6] = $custom_data_text; + } + $table1->data[] = $data; if ($show_extended_events == 1 && events_has_extended_info($event['id_evento'])) { @@ -2341,6 +2370,13 @@ function reporting_html_event_report_agent($table, $item, $pdf=0) $table1->align[0] = 'center'; $table1->align[1] = 'center'; $table1->align[3] = 'center'; + if ((bool) $item['show_custom_data'] === true) { + if ($item['show_summary_group']) { + $table1->align[7] = 'left'; + } else { + $table1->align[6] = 'left'; + } + } $table1->data = []; @@ -2355,6 +2391,9 @@ function reporting_html_event_report_agent($table, $item, $pdf=0) $table1->head[4] = __('Severity'); $table1->head[5] = __('Val. by'); $table1->head[6] = __('Timestamp'); + if ((bool) $item['show_custom_data'] === true) { + $table1->head[7] = __('Custom data'); + } foreach ($item['data'] as $i => $event) { if ($item['show_summary_group']) { @@ -2420,6 +2459,16 @@ function reporting_html_event_report_agent($table, $item, $pdf=0) $data[] = ''.date($config['date_format'], strtotime($event['timestamp'])).''; } + if ((bool) $item['show_custom_data'] === true) { + $custom_data = json_decode($event['custom_data'], true); + $custom_data_text = ''; + foreach ($custom_data as $key => $value) { + $custom_data_text .= $key.' = '.$value.'
'; + } + + $data[] = $custom_data_text; + } + array_push($table1->data, $data); if ($show_extended_events == 1 && events_has_extended_info($event['id_evento'])) { From 9fd4e415c0f1911d579bb5e0d8d2057d843b4f60 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 3 May 2022 10:02:39 +0200 Subject: [PATCH 014/174] #8899 Fixed pass with entities --- pandora_console/include/functions_config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 07537de173..c934a7aea7 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -1607,7 +1607,7 @@ function config_update_config() 'port' => $config['history_db_port'], 'name' => $config['history_db_name'], 'user' => $config['history_db_user'], - 'pass' => $config['history_db_pass'], + 'pass' => io_output_password($config['history_db_pass']), ] ); From a858c31d3973c7f00ded4f540bc3e539c99c2829 Mon Sep 17 00:00:00 2001 From: Luis Date: Wed, 4 May 2022 12:48:39 +0000 Subject: [PATCH 015/174] Update pandora_manage.pl --- pandora_server/util/pandora_manage.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index ee6dc73d2b..681d035916 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -1163,7 +1163,7 @@ sub cli_disable_group() { } my $result = pandora_disable_group ($conf, $dbh, $id_group); - print_log "[INFO] Disbaled ".$result." agents from group ".$group_name."\n\n"; + print_log "[INFO] Disabled ".$result." agents from group ".$group_name."\n\n"; } ############################################################################## @@ -8744,4 +8744,4 @@ sub pandora_validate_alert_id($$$$) { ); return 1; -} \ No newline at end of file +} From eaef84b5b297063bff52ff2f5e6b27dc8f2211bc Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Wed, 4 May 2022 16:38:38 +0200 Subject: [PATCH 016/174] #8708 only enabled agent --- pandora_console/include/functions_alerts.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 81b36f7476..070ff52831 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -118,6 +118,9 @@ function alerts_get_alerts($id_group=0, $free_search='', $status='all', $standby $sql .= ' AND t3.id_agente = '.$id_agent; } + // Only enabled agent. + $sql .= ' AND t3.disabled = 0'; + $row_alerts = db_get_all_rows_sql($sql); if ($total) { From e685cf729473fafd334283af2342be28d1442d44 Mon Sep 17 00:00:00 2001 From: Calvo Date: Wed, 4 May 2022 18:42:56 +0200 Subject: [PATCH 017/174] Api create agent meta support --- pandora_console/include/functions_api.php | 231 +++++++++------------- pandora_console/include/lib/Agent.php | 23 ++- 2 files changed, 119 insertions(+), 135 deletions(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 71128946c5..1f3dd91045 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -53,8 +53,10 @@ enterprise_include_once('include/functions_clusters.php'); enterprise_include_once('include/functions_alerts.php'); // Clases. +use PandoraFMS\Agent; use PandoraFMS\Module; use PandoraFMS\Enterprise\Cluster; +use PandoraFMS\Enterprise\Metaconsole\Node; use PandoraFMS\SpecialDay; @@ -1826,18 +1828,18 @@ function api_set_update_agent_field($id_agent, $use_agent_alias, $params) /** * Create a new agent, and print the id for new agent. * - * @param $thrash1 Don't use. + * @param $id_node Id_node target (if metaconsole) * @param $thrash2 Don't use. - * @param array $other it's array, $other as param is ;;;; - * ;;;;;;; in this order - * and separator char (after text ; ) and separator (pass in param othermode as othermode=url_encode_separator_) - * example: + * @param array $other it's array, $other as param is ;;;; + * ;;;;;;; in this order + * and separator char (after text ; ) and separator (pass in param othermode as othermode=url_encode_separator_) + * example: * - * api.php?op=set&op2=new_agent&other=pepito|1.1.1.1|0|4|0|30|8|10||0|0|nose%20nose&other_mode=url_encode_separator_| + * api.php?op=set&op2=new_agent&other=pepito|1.1.1.1|0|4|0|30|8|10||0|0|nose%20nose&other_mode=url_encode_separator_| * * @param $thrash3 Don't use. */ -function api_set_new_agent($thrash1, $thrash2, $other, $thrash3) +function api_set_new_agent($id_node, $thrash2, $other, $trhash3) { global $config; @@ -1846,146 +1848,104 @@ function api_set_new_agent($thrash1, $thrash2, $other, $thrash3) return; } - if (defined('METACONSOLE')) { - return; - } - if ((int) $other['data'][3] == 0) { returnError('For security reasons, the agent was not created. Use a group other than 0.'); return; } - $alias = io_safe_input(trim(preg_replace('/[\/\\\|%#&$]/', '', $other['data'][0]))); - $direccion_agente = io_safe_input($other['data'][1]); - $nombre_agente = hash('sha256', $direccion_agente.'|'.$direccion_agente.'|'.time().'|'.sprintf('%04d', rand(0, 10000))); - $id_parent = (int) $other['data'][2]; - $grupo = (int) $other['data'][3]; - $cascade_protection = (int) $other['data'][4]; - $cascade_protection_module = (int) $other['data'][5]; - $intervalo = (string) $other['data'][6]; - $id_os = (int) $other['data'][7]; - $server_name = (string) $other['data'][8]; - $custom_id = (string) $other['data'][9]; - $modo = (int) $other['data'][10]; - $disabled = (int) $other['data'][11]; - $comentarios = (string) $other['data'][12]; - $alias_as_name = (int) $other['data'][13]; - $update_module_count = (int) $config['metaconsole_agent_cache'] == 1; + try { + $agent = new Agent(); - if ($cascade_protection == 1) { - if (($id_parent != 0) && (db_get_value_sql( - 'SELECT id_agente_modulo - FROM tagente_modulo - WHERE id_agente = '.$id_parent.' AND id_agente_modulo = '.$cascade_protection_module - ) === false) - ) { - returnError('Cascade protection is not applied because it is not a parent module.'); - return; - } - } else { - $cascadeProtectionModule = 0; - } - - $server_name = db_get_value_sql('SELECT name FROM tserver WHERE BINARY name LIKE "'.$server_name.'"'); - - // Check if agent exists (BUG WC-50518-2). - if ($alias == '' && $alias_as_name === 0) { - returnError('No agent alias specified'); - } else if (agents_get_agent_id($nombre_agente)) { - returnError('The agent name already exists in DB.'); - } else if (db_get_value_sql('SELECT id_grupo FROM tgrupo WHERE id_grupo = '.$grupo) === false) { - returnError('The group does not exist.'); - } else if (group_allow_more_agents($grupo, true, 'create') === false) { - returnError('Agent cannot be created due to the maximum agent limit for this group'); - } else if (db_get_value_sql('SELECT id_os FROM tconfig_os WHERE id_os = '.$id_os) === false) { - returnError('The OS does not exist.'); - } else if ($server_name === false) { - returnError('The '.get_product_name().' Server does not exist.'); - } else { - if ($alias_as_name === 1) { - $exists_alias = db_get_row_sql('SELECT nombre FROM tagente WHERE nombre = "'.$alias.'"'); - $nombre_agente = $alias; - } - - $exists_ip = false; - - if ($config['unique_ip'] && $direccion_agente != '') { - $exists_ip = db_get_row_sql('SELECT direccion FROM tagente WHERE direccion = "'.$direccion_agente.'"'); - } - - if (!$exists_alias && !$exists_ip) { - $id_agente = db_process_sql_insert( - 'tagente', - [ - 'nombre' => $nombre_agente, - 'alias' => $alias, - 'alias_as_name' => $alias_as_name, - 'direccion' => $direccion_agente, - 'id_grupo' => $grupo, - 'intervalo' => $intervalo, - 'comentarios' => $comentarios, - 'modo' => $modo, - 'id_os' => $id_os, - 'disabled' => $disabled, - 'cascade_protection' => $cascade_protection, - 'cascade_protection_module' => $cascade_protection_module, - 'server_name' => $server_name, - 'id_parent' => $id_parent, - 'custom_id' => $custom_id, - 'os_version' => '', - 'agent_version' => '', - 'timezone_offset' => 0, - 'icon_path' => '', - 'url_address' => '', - 'update_module_count' => $update_module_count, - ] - ); - enterprise_hook('update_agent', [$id_agente]); - } else { - $id_agente = false; - } - - if ($id_agente !== false) { - // Create address for this agent in taddress. - if ($direccion_agente != '') { - agents_add_address($id_agente, $direccion_agente); + if (is_metaconsole() === true) { + if ($id_node <= 0) { + throw new Exception('No node id specified'); } - $info = '{"Name":"'.$nombre_agente.'", - "IP":"'.$direccion_agente.'", - "Group":"'.$grupo.'", - "Interval":"'.$intervalo.'", - "Comments":"'.$comentarios.'", - "Mode":"'.$modo.'", - "ID_parent:":"'.$id_parent.'", - "Server":"'.$server_name.'", - "ID os":"'.$id_os.'", - "Disabled":"'.$disabled.'", - "Custom ID":"'.$custom_id.'", - "Cascade protection":"'.$cascade_protection.'", - "Cascade protection module":"'.$cascade_protection_module.'"}'; - - $unsafe_alias = io_safe_output($alias); - db_pandora_audit( - AUDIT_LOG_AGENT_MANAGEMENT, - 'Created agent '.$unsafe_alias, - false, - true, - $info + $node = new Node($id_node); + $id_agente = $node->callApi( + 'new_agent', + 'set', + null, + null, + $other['data'], + null ); } else { - $id_agente = 0; + $alias = io_safe_input(trim(preg_replace('/[\/\\\|%#&$]/', '', $other['data'][0]))); + $direccion_agente = io_safe_input($other['data'][1]); + $id_parent = (int) $other['data'][2]; + $grupo = (int) $other['data'][3]; + $cascade_protection = (int) $other['data'][4]; + $cascade_protection_module = (int) $other['data'][5]; + $intervalo = (string) $other['data'][6]; + $id_os = (int) $other['data'][7]; + $server_name = (string) $other['data'][8]; + $custom_id = (string) $other['data'][9]; + $modo = (int) $other['data'][10]; + $disabled = (int) $other['data'][11]; + $comentarios = (string) html_entity_decode($other['data'][12]); + $alias_as_name = (int) $other['data'][13]; + $update_module_count = (int) $config['metaconsole_agent_cache'] == 1; - if ($exists_alias) { - $agent_creation_error = 'Could not be created because name already exists'; - } else if ($exists_ip) { - $agent_creation_error = 'Could not be created because IP already exists'; + $agent->nombre($alias); + $agent->alias($alias); + $agent->alias_as_name($alias_as_name); + $agent->direccion($direccion_agente); + $agent->id_grupo($grupo); + $agent->intervalo($intervalo); + $agent->comentarios($comentarios); + $agent->modo($modo); + $agent->id_os($id_os); + $agent->disabled($disabled); + $agent->cascade_protection($cascade_protection); + $agent->cascade_protection_module($cascade_protection_module); + $agent->server_name($server_name); + $agent->id_parent($id_parent); + $agent->custom_id($custom_id); + $agent->timezone_offset(0); + $agent->update_module_count($update_module_count); + + if ($cascade_protection == 1) { + if ($id_parent != 0) { + try { + $parent = new Agent($id_parent); + } catch (\Exception $e) { + returnError('Cascade protection is not applied because it is not a parent module.'); + } + } + } + + $server_name = db_get_value_sql('SELECT name FROM tserver WHERE BINARY name LIKE "'.$server_name.'"'); + + // Check if agent exists (BUG WC-50518-2). + if ($alias == '' && $alias_as_name === 0) { + returnError('No agent alias specified'); + } else if (agents_get_agent_id($nombre_agente)) { + returnError('The agent name already exists in DB.'); + } else if (db_get_value_sql('SELECT id_grupo FROM tgrupo WHERE id_grupo = '.$grupo) === false) { + returnError('The group does not exist.'); + } else if (group_allow_more_agents($grupo, true, 'create') === false) { + returnError('Agent cannot be created due to the maximum agent limit for this group'); + } else if (db_get_value_sql('SELECT id_os FROM tconfig_os WHERE id_os = '.$id_os) === false) { + returnError('The OS does not exist.'); + } else if ($server_name === false) { + returnError('The '.get_product_name().' Server does not exist.'); } else { - $agent_creation_error = 'Could not be created for unknown reason'; - } + if ($alias_as_name === 1) { + $exists_alias = db_get_row_sql('SELECT nombre FROM tagente WHERE nombre = "'.$alias.'"'); + $nombre_agente = $alias; + } - returnError($agent_creation_error); - return; + $exists_ip = false; + + if ($config['unique_ip'] && $direccion_agente != '') { + $exists_ip = db_get_row_sql('SELECT direccion FROM tagente WHERE direccion = "'.$direccion_agente.'"'); + } + + $agent->save((bool) $alias_as_name); + $id_agente = $agent->id_agente(); + $agent->updateFromCache(); + } } returnData( @@ -1995,6 +1955,9 @@ function api_set_new_agent($thrash1, $thrash2, $other, $thrash3) 'data' => $id_agente, ] ); + } catch (\Exception $e) { + returnError($e->getMessage()); + return; } } diff --git a/pandora_console/include/lib/Agent.php b/pandora_console/include/lib/Agent.php index d561bba6f7..888cba6970 100644 --- a/pandora_console/include/lib/Agent.php +++ b/pandora_console/include/lib/Agent.php @@ -248,7 +248,7 @@ class Agent extends Entity /** - * Calculates cascade protection service value for this service. + * Calculates cascade protection _nameice value for this service. * * @param integer|null $id_node Meta searching node will use this field. * @@ -621,4 +621,25 @@ class Agent extends Entity } + /** + * Update agent in metaconsole + * + * @return void + */ + public function updateFromCache() + { + $res = (bool) \enterprise_hook( + 'agent_update_from_cache', + [ + $this->id_agente(), + $this->toArray(), + $this->server_name(), + ] + ); + + return $res; + + } + + } From f3272eb3dfca58b216f57841c41c998c4e017f0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Thu, 5 May 2022 17:36:07 +0200 Subject: [PATCH 018/174] Applied fix for snmp --- pandora_console/include/class/AgentWizard.class.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/class/AgentWizard.class.php b/pandora_console/include/class/AgentWizard.class.php index bc34fa5258..df9299078f 100644 --- a/pandora_console/include/class/AgentWizard.class.php +++ b/pandora_console/include/class/AgentWizard.class.php @@ -3572,7 +3572,12 @@ class AgentWizard extends HTML if ($full_output === true) { $output[] = $key.' = '.$oid_unit; } else { - preg_match('/\.\d+$/', $key, $index); + $index = []; + $index[] = preg_replace('/^'.$oid.'/', '', $key); + if (empty($index) === true) { + preg_match('/\.\d+$/', $key, $index); + } + $tmp = explode(': ', $oid_unit); $output[$index[0]] = str_replace('"', '', ($tmp[1] ?? '')); } From 1b3994d32ccafc006c949cf838c6a0c8a5179b3e Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Fri, 6 May 2022 11:54:17 +0200 Subject: [PATCH 019/174] #8730 Fixed console server version --- pandora_console/godmode/um_client/index.php | 2 +- pandora_console/include/class/ConsoleSupervisor.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_console/godmode/um_client/index.php b/pandora_console/godmode/um_client/index.php index d700a05e9b..3cbf584109 100644 --- a/pandora_console/godmode/um_client/index.php +++ b/pandora_console/godmode/um_client/index.php @@ -224,7 +224,7 @@ if (is_ajax() !== true) { if ($server_version !== false && preg_match('/NG\.(\d\.*\d*?) /', $server_version, $matches) > 0 ) { - if ((float) $matches[1] !== (float) $current_package) { + if ((float) $matches[1] !== floor((float) $current_package)) { ui_print_warning_message( __( 'Master server version %s does not match console version %s.', diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index ae61026fb3..c4a43105b3 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -2490,7 +2490,7 @@ class ConsoleSupervisor foreach ($server_version_list as $server) { if (strpos( $server['version'], - floor($config['current_package']) + (string) floor($config['current_package']) ) === false ) { $missed++; From dfc4786ef187a9063412c91bbac995e6c177ff8f Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 6 May 2022 13:35:04 +0200 Subject: [PATCH 020/174] Changed snmpwalk parameters for wizard --- .../modules/manage_network_components_form_wizard.php | 1 + pandora_console/include/class/AgentWizard.class.php | 3 ++- pandora_console/include/functions.php | 11 ++++++----- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pandora_console/godmode/modules/manage_network_components_form_wizard.php b/pandora_console/godmode/modules/manage_network_components_form_wizard.php index 0fa9d763c5..15b8f2a508 100644 --- a/pandora_console/godmode/modules/manage_network_components_form_wizard.php +++ b/pandora_console/godmode/modules/manage_network_components_form_wizard.php @@ -178,6 +178,7 @@ switch ($type) { break; } +$query_filter = []; if (empty($query_filter) === false) { $query_filter = json_decode($query_filter, true); } diff --git a/pandora_console/include/class/AgentWizard.class.php b/pandora_console/include/class/AgentWizard.class.php index bc34fa5258..671142817f 100644 --- a/pandora_console/include/class/AgentWizard.class.php +++ b/pandora_console/include/class/AgentWizard.class.php @@ -3559,7 +3559,8 @@ class AgentWizard extends HTML $this->targetPort, $this->server, $this->extraArguments, - (($full_output === false) ? '-Oa -On' : '-Oa') + (($full_output === false) ? '-On' : '-Oa'), + '' ); if ($pure === true) { diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index ca0c9dad7d..172b8de169 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -1993,7 +1993,8 @@ function get_snmpwalk( $snmp_port='', $server_to_exec=0, $extra_arguments='', - $format='-Oa' + $format='-Oa', + $load_mibs='-m ALL' ) { global $config; @@ -2057,15 +2058,15 @@ function get_snmpwalk( case '3': switch ($snmp3_security_level) { case 'authNoPriv': - $command_str = $snmpwalk_bin.' -m ALL '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; + $command_str = $snmpwalk_bin.' '.$load_mibs.' '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; break; case 'noAuthNoPriv': - $command_str = $snmpwalk_bin.' -m ALL '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -l '.escapeshellarg($snmp3_security_level).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; + $command_str = $snmpwalk_bin.' '.$load_mibs.' '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -l '.escapeshellarg($snmp3_security_level).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; break; default: - $command_str = $snmpwalk_bin.' -m ALL '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' -x '.escapeshellarg($snmp3_privacy_method).' -X '.escapeshellarg($snmp3_privacy_pass).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; + $command_str = $snmpwalk_bin.' '.$load_mibs.' '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' -x '.escapeshellarg($snmp3_privacy_method).' -X '.escapeshellarg($snmp3_privacy_pass).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; break; } break; @@ -2074,7 +2075,7 @@ function get_snmpwalk( case '2c': case '1': default: - $command_str = $snmpwalk_bin.' -m ALL '.$extra_arguments.' '.$format.' -v '.escapeshellarg($snmp_version).' -c '.escapeshellarg(io_safe_output($snmp_community)).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; + $command_str = $snmpwalk_bin.' '.$load_mibs.' '.$extra_arguments.' '.$format.' -v '.escapeshellarg($snmp_version).' -c '.escapeshellarg(io_safe_output($snmp_community)).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; break; } From 758933a2117c68bf6f33891a4246964295251d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Fri, 6 May 2022 14:23:24 +0200 Subject: [PATCH 021/174] Fix black theme issues --- pandora_console/include/graphs/pandora.d3.js | 15 +++++++-- .../operation/netflow/nf_live_view.php | 33 +++++++++++++------ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/pandora_console/include/graphs/pandora.d3.js b/pandora_console/include/graphs/pandora.d3.js index 8495a8728b..5f30f7379b 100644 --- a/pandora_console/include/graphs/pandora.d3.js +++ b/pandora_console/include/graphs/pandora.d3.js @@ -29,6 +29,12 @@ function chordDiagram(recipient, elements, matrix, width) { var width = 700; var margin = 150; var padding = 0.02; + var consoleStyle = document.getElementById("hidden-selected_style_theme") + .value; + var textColor = + consoleStyle === "pandora_black" ? "rgb(240, 240, 240)" : "rgb(0, 0, 0)"; + var tooltipColor = + consoleStyle === "pandora_black" ? "rgb(0, 0, 0)" : "rgb(240, 240, 240)"; function chart(selection) { selection.each(function(data) { @@ -103,7 +109,6 @@ function chordDiagram(recipient, elements, matrix, width) { const chords = chord.chords(); let aux = 0; $.each(chords, function(key, value) { - console.log(aux); if (aux < 5) { if ( (value.source.index == i && value.target.subindex == i) || @@ -159,6 +164,7 @@ function chordDiagram(recipient, elements, matrix, width) { .attr("text-anchor", function(d) { return d.angle > Math.PI ? "end" : null; }) + .attr("style", "fill: " + textColor) .attr("transform", function(d) { return ( "rotate(" + @@ -266,7 +272,12 @@ function chordDiagram(recipient, elements, matrix, width) { $("#tooltip").attr( "style", - "background: #fff;" + + "background: " + + tooltipColor + + ";" + + "color: " + + textColor + + ";" + "position: absolute;" + "display: inline-block;" + "width: auto;" + diff --git a/pandora_console/operation/netflow/nf_live_view.php b/pandora_console/operation/netflow/nf_live_view.php index 442b1b2fa5..e717d92bfb 100644 --- a/pandora_console/operation/netflow/nf_live_view.php +++ b/pandora_console/operation/netflow/nf_live_view.php @@ -2,20 +2,28 @@ /** * Netflow live view * - * @package Pandora FMS open. - * @subpackage UI file. + * @category Netflow + * @package Pandora FMS + * @subpackage Community + * @version 1.0.0 + * @license See below * - * Pandora FMS - http://pandorafms.com - * ================================================== - * Copyright (c) 2005-2021 Artica Soluciones Tecnologicas + * ______ ___ _______ _______ ________ + * | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __| + * | __/| _ | | _ || _ | _| _ | | ___| |__ | + * |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______| + * + * ============================================================================ + * Copyright (c) 2005-2022 Artica Soluciones Tecnologicas * Please see http://pandorafms.org for full contribution list * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; version 2 + * as published by the Free Software Foundation for version 2. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. + * ============================================================================ */ global $config; @@ -40,7 +48,7 @@ if (! check_acl($config['id_user'], 0, 'AR') && ! check_acl($config['id_user'], $pure = get_parameter('pure', 0); // Ajax callbacks. -if (is_ajax()) { +if (is_ajax() === true) { $get_filter_type = get_parameter('get_filter_type', 0); $get_filter_values = get_parameter('get_filter_values', 0); @@ -117,7 +125,7 @@ $draw = get_parameter('draw_button', ''); $save = get_parameter('save_button', ''); $update = get_parameter('update_button', ''); -if (!is_metaconsole()) { +if (is_metaconsole() === false) { // Header. ui_print_page_header( __('Netflow live view'), @@ -505,7 +513,7 @@ if (is_metaconsole()) { echo ''; - if ($draw != '') { + if (empty($draw) === false) { // Draw. echo '
'; @@ -513,6 +521,11 @@ if (is_metaconsole()) { if ($netflow_disable_custom_lvfilters && $filter_selected == 0) { ui_print_error_message(__('No filter selected')); } else { + // Hidden input for handle properly the text colors. + html_print_input_hidden( + 'selected_style_theme', + $config['style'] + ); // Draw the netflow chart. echo netflow_draw_item( $start_date, From 752a716c21a17069deb8f2d04f23805e28571c5a Mon Sep 17 00:00:00 2001 From: Calvo Date: Mon, 9 May 2022 08:58:14 +0200 Subject: [PATCH 022/174] Changed link to Suggest new feature on new installation --- pandora_console/pandoradb_data.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index 865d06cfba..4072e4b77f 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -218,7 +218,7 @@ INSERT INTO `tlink` VALUES (1,'Documentation','https://pandorafms.com/manual'), (2,'Enterprise Edition','http://pandorafms.com'), (3,'Report a bug','https://github.com/pandorafms/pandorafms/issues'), -(4,'Suggest new feature','http://forums.pandorafms.com/index.php?board=22.0'), +(4,'Suggest new feature','https://pandorafms.com/community/beta-program/'), (5,'Module library','http://library.pandorafms.com/'); UNLOCK TABLES; From 5c789125f2b561017a7fab325da91764eb8cf462 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Mon, 9 May 2022 12:40:36 +0200 Subject: [PATCH 023/174] changed id_user field length from tusuario --- pandora_console/extras/mr/55.sql | 15 +++++++++++++++ .../extras/pandoradb_migrate_6.0_to_759.mysql.sql | 15 +++++++++++++++ pandora_console/pandoradb.sql | 12 ++++++------ 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 pandora_console/extras/mr/55.sql diff --git a/pandora_console/extras/mr/55.sql b/pandora_console/extras/mr/55.sql new file mode 100644 index 0000000000..b00619d357 --- /dev/null +++ b/pandora_console/extras/mr/55.sql @@ -0,0 +1,15 @@ +START TRANSACTION; + +ALTER TABLE `tuser_double_auth` DROP FOREIGN KEY `tuser_double_auth_ibfk_1`, MODIFY `id_user` VARCHAR(255) NOT NULL; +ALTER TABLE `tnotification_user` DROP FOREIGN KEY `tnotification_user_ibfk_2`, MODIFY `id_user` VARCHAR(255) NOT NULL; +ALTER TABLE `tnotification_source_user` DROP FOREIGN KEY `tnotification_source_user_ibfk_2`, MODIFY `id_user` VARCHAR(255) NOT NULL; +ALTER TABLE `tnotification_source_group_user` DROP FOREIGN KEY `tnotification_source_group_user_ibfk_2`, MODIFY `id_user` VARCHAR(255) NOT NULL; +ALTER TABLE `tvisual_console_elements_cache` DROP FOREIGN KEY `tvisual_console_elements_cache_ibfk_3`, MODIFY `user_id` VARCHAR(255) DEFAULT NULL; +ALTER TABLE `tusuario` MODIFY `id_user` VARCHAR(255) NOT NULL DEFAULT '0'; +ALTER TABLE `tuser_double_auth` ADD CONSTRAINT `tuser_double_auth_ibfk_1` FOREIGN KEY (`id_user`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE; +ALTER TABLE `tnotification_user` ADD CONSTRAINT `tnotification_user_ibfk_2` FOREIGN KEY (`id_user`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `tnotification_source_user` ADD CONSTRAINT `tnotification_source_user_ibfk_2` FOREIGN KEY (`id_user`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `tnotification_source_group_user` ADD CONSTRAINT `tnotification_source_group_user_ibfk_2` FOREIGN KEY (`id_user`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `tvisual_console_elements_cache` ADD CONSTRAINT `tvisual_console_elements_cache_ibfk_3` FOREIGN KEY (`user_id`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE; + +COMMIT; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql index ca68a5472a..242e7d42c6 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql @@ -4338,3 +4338,18 @@ ALTER TABLE `talert_special_days` DROP COLUMN `same_day`; ALTER TABLE `talert_special_days` ADD FOREIGN KEY (`id_calendar`) REFERENCES `talert_calendar`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; UPDATE `tconfig` c1 JOIN (select count(*) as n FROM `tconfig` c2 WHERE (c2.`token` = "node_metaconsole" AND c2.`value` = 1) OR (c2.`token` = "centralized_management" AND c2.`value` = 1) ) v SET c1. `value` = 0 WHERE c1.token = "autocreate_remote_users" AND v.n = 2; + +-- ---------------------------------------------------------------------- +-- Table `tusuario` +-- ---------------------------------------------------------------------- +ALTER TABLE `tuser_double_auth` DROP FOREIGN KEY `tuser_double_auth_ibfk_1`, MODIFY `id_user` VARCHAR(255) NOT NULL; +ALTER TABLE `tnotification_user` DROP FOREIGN KEY `tnotification_user_ibfk_2`, MODIFY `id_user` VARCHAR(255) NOT NULL; +ALTER TABLE `tnotification_source_user` DROP FOREIGN KEY `tnotification_source_user_ibfk_2`, MODIFY `id_user` VARCHAR(255) NOT NULL; +ALTER TABLE `tnotification_source_group_user` DROP FOREIGN KEY `tnotification_source_group_user_ibfk_2`, MODIFY `id_user` VARCHAR(255) NOT NULL; +ALTER TABLE `tvisual_console_elements_cache` DROP FOREIGN KEY `tvisual_console_elements_cache_ibfk_3`, MODIFY `user_id` VARCHAR(255) DEFAULT NULL; +ALTER TABLE `tusuario` MODIFY `id_user` VARCHAR(255) NOT NULL DEFAULT '0'; +ALTER TABLE `tuser_double_auth` ADD CONSTRAINT `tuser_double_auth_ibfk_1` FOREIGN KEY (`id_user`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE; +ALTER TABLE `tnotification_user` ADD CONSTRAINT `tnotification_user_ibfk_2` FOREIGN KEY (`id_user`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `tnotification_source_user` ADD CONSTRAINT `tnotification_source_user_ibfk_2` FOREIGN KEY (`id_user`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `tnotification_source_group_user` ADD CONSTRAINT `tnotification_source_group_user_ibfk_2` FOREIGN KEY (`id_user`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `tvisual_console_elements_cache` ADD CONSTRAINT `tvisual_console_elements_cache_ibfk_3` FOREIGN KEY (`user_id`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 29ec6e572b..bb98a706e3 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -1260,7 +1260,7 @@ CREATE TABLE IF NOT EXISTS `tevent_filter` ( -- Table `tusuario` -- ---------------------------------------------------------------------- CREATE TABLE IF NOT EXISTS `tusuario` ( - `id_user` VARCHAR(60) NOT NULL DEFAULT '0', + `id_user` VARCHAR(255) NOT NULL DEFAULT '0', `fullname` VARCHAR(255) NOT NULL, `firstname` VARCHAR(255) NOT NULL, `lastname` VARCHAR(255) NOT NULL, @@ -1328,7 +1328,7 @@ CREATE TABLE IF NOT EXISTS `tusuario_perfil` ( -- ---------------------------------------------------------------------- CREATE TABLE IF NOT EXISTS `tuser_double_auth` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - `id_user` VARCHAR(60) NOT NULL, + `id_user` VARCHAR(255) NOT NULL, `secret` VARCHAR(20) NOT NULL, PRIMARY KEY (`id`), UNIQUE (`id_user`), @@ -1388,7 +1388,7 @@ CREATE TABLE IF NOT EXISTS `tmensajes` ( -- ---------------------------------------------------------------------- CREATE TABLE IF NOT EXISTS `tnotification_user` ( `id_mensaje` INT UNSIGNED NOT NULL, - `id_user` VARCHAR(60) NOT NULL, + `id_user` VARCHAR(255) NOT NULL, `utimestamp_read` BIGINT, `utimestamp_erased` BIGINT, `postpone` INT, @@ -1415,7 +1415,7 @@ CREATE TABLE IF NOT EXISTS `tnotification_group` ( -- ---------------------------------------------------------------------- CREATE TABLE IF NOT EXISTS `tnotification_source_user` ( `id_source` BIGINT UNSIGNED NOT NULL, - `id_user` VARCHAR(60), + `id_user` VARCHAR(255), `enabled` INT DEFAULT NULL, `also_mail` INT DEFAULT NULL, PRIMARY KEY (`id_source`,`id_user`), @@ -1443,7 +1443,7 @@ CREATE TABLE IF NOT EXISTS `tnotification_source_group` ( CREATE TABLE IF NOT EXISTS `tnotification_source_group_user` ( `id_source` BIGINT UNSIGNED NOT NULL, `id_group` MEDIUMINT UNSIGNED NOT NULL, - `id_user` VARCHAR(60), + `id_user` VARCHAR(255), `enabled` INT DEFAULT NULL, `also_mail` INT DEFAULT NULL, PRIMARY KEY (`id_source`,`id_user`), @@ -3836,7 +3836,7 @@ CREATE TABLE IF NOT EXISTS `tvisual_console_elements_cache` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `vc_id` INT UNSIGNED NOT NULL, `vc_item_id` INT UNSIGNED NOT NULL, - `user_id` VARCHAR(60) DEFAULT NULL, + `user_id` VARCHAR(255) DEFAULT NULL, `data` TEXT, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `expiration` INT UNSIGNED NOT NULL COMMENT 'Seconds to expire', From a2de9121b764e4d02e9ef55b8e83f081fd391ec7 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 10 May 2022 15:15:40 +0200 Subject: [PATCH 024/174] #8958 remove the option none --- pandora_console/godmode/alerts/configure_alert_action.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/godmode/alerts/configure_alert_action.php b/pandora_console/godmode/alerts/configure_alert_action.php index 8b276d7233..068026c953 100644 --- a/pandora_console/godmode/alerts/configure_alert_action.php +++ b/pandora_console/godmode/alerts/configure_alert_action.php @@ -261,7 +261,7 @@ $table->data[2][1] = html_print_select_from_sql( 'id_command', $id_command, '', - __('None'), + '', 0, true, false, From 15d92d5cd6c8ecfac04dfaf645f5dc215386d151 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Wed, 11 May 2022 13:51:16 +0200 Subject: [PATCH 025/174] #8517 Fixed module name --- pandora_server/lib/PandoraFMS/Recon/Base.pm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Recon/Base.pm b/pandora_server/lib/PandoraFMS/Recon/Base.pm index f0b70cd0df..66d47a782a 100644 --- a/pandora_server/lib/PandoraFMS/Recon/Base.pm +++ b/pandora_server/lib/PandoraFMS/Recon/Base.pm @@ -1628,9 +1628,14 @@ sub database_scan($$$) { $self->{'summary'}->{'discovered'} += 1; $self->{'summary'}->{'alive'} += 1; + my $name = $type . ' connection'; + if (defined $obj->{'prefix_module_name'} && $obj->{'prefix_module_name'} ne '') { + $name = $obj->{'prefix_module_name'} . $type . ' connection'; + } + push @modules, { - name => $type . ' connection', + name => $name, type => 'generic_proc', data => 1, description => $type . ' availability' @@ -1778,8 +1783,14 @@ sub app_scan($) { # Update progress $self->call('update_progress', $global_percent + (90 / (scalar @targets))); $self->{'summary'}->{'not_alive'} += 1; + + my $name = $type . ' connection'; + if (defined $obj->{'prefix_module_name'} && $obj->{'prefix_module_name'} ne '') { + $name = $obj->{'prefix_module_name'} . $type . ' connection'; + } + push @modules, { - name => $type . ' connection', + name => $name, type => 'generic_proc', data => 0, description => $type . ' availability' From 4589a7c298de516a1503b0c29ce08210da8bf799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Thu, 12 May 2022 18:31:24 +0200 Subject: [PATCH 026/174] Added control for WMI binary --- pandora_console/godmode/setup/performance.php | 10 ++++++++++ .../include/class/AgentWizard.class.php | 18 +++++++++++++----- pandora_console/include/functions_config.php | 8 ++++++++ pandora_console/include/functions_wmi.php | 6 +++--- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/pandora_console/godmode/setup/performance.php b/pandora_console/godmode/setup/performance.php index ad74c490c2..a2851b568c 100644 --- a/pandora_console/godmode/setup/performance.php +++ b/pandora_console/godmode/setup/performance.php @@ -661,6 +661,16 @@ $tip = ui_print_help_tip( true ); +$table_other->data[$i][0] = __('WMI binary'); +$table_other->data[$i++][1] = html_print_input_text( + 'wmiBinary', + $config['wmiBinary'], + '', + 50, + 10, + true +); + if (enterprise_installed() === true) { $table_other->data[$i][0] = __('PhantomJS cache cleanup ').$tip; $table_other->data[$i++][1] = html_print_input( diff --git a/pandora_console/include/class/AgentWizard.class.php b/pandora_console/include/class/AgentWizard.class.php index 2d7f2f37da..0cf4afaeab 100644 --- a/pandora_console/include/class/AgentWizard.class.php +++ b/pandora_console/include/class/AgentWizard.class.php @@ -278,6 +278,13 @@ class AgentWizard extends HTML */ private $extraArguments = ''; + /** + * Binary of wmic. + * + * @var string + */ + private $wmiBinary = ''; + /** * Constructor @@ -291,7 +298,7 @@ class AgentWizard extends HTML // Check access. check_login(); - if (!check_acl($config['id_user'], 0, 'AR')) { + if ((bool) check_acl($config['id_user'], 0, 'AR') === false) { db_pandora_audit( AUDIT_LOG_ACL_VIOLATION, 'Trying to access event viewer' @@ -311,6 +318,7 @@ class AgentWizard extends HTML $this->idAgent = get_parameter('id_agente', ''); $this->idPolicy = get_parameter('id', ''); $this->targetIp = get_parameter('targetIp', ''); + $this->wmiBinary = $config['wmiBinary']; if (empty($this->idAgent) === false) { $array_aux = db_get_all_rows_sql( @@ -1044,7 +1052,7 @@ class AgentWizard extends HTML $oidExplore = '.1.3.6.1.2.1.1.2.0'; } - // Explore general or interfaces + // Explore general or interfaces. $receivedOid = $this->snmpWalkValues( $oidExplore, false, @@ -1080,7 +1088,7 @@ class AgentWizard extends HTML // Capture the parameters. // Call WMI Explorer function. $this->wmiCommand = wmi_compose_query( - 'wmic', + $this->wmiBinary, $this->usernameWMI, $this->passwordWMI, $this->targetIp, @@ -5717,7 +5725,7 @@ class AgentWizard extends HTML $(this).removeClass('hidden'); return; } - + if (this.id.match(regex)) { $(this).removeClass('hidden'); } else { @@ -5729,7 +5737,7 @@ class AgentWizard extends HTML $(this).addClass('hidden'); } } - + if (filter_up == true) { if ($(this).attr('operstatus') != 1) { $(this).addClass('hidden'); diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 07537de173..b730d9cfe0 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -928,6 +928,10 @@ function config_update_config() $error_update[] = __('SNMP walk binary path (fallback for v1)'); } + if (config_update_value('wmiBinary', get_parameter('wmiBinary'), true) === false) { + $error_update[] = __('Default WMI Binary'); + } + $pjs = get_parameter('phantomjs_cache_interval'); switch ($pjs) { case $config['phantomjs_cache_interval']: @@ -2088,6 +2092,10 @@ function config_process_config() config_update_value('snmpwalk_fallback', 'snmpwalk'); } + if (isset($config['wmiBinary']) === false) { + config_update_value('wmiBinary', 'pandorawmic'); + } + if (!isset($config['event_purge'])) { config_update_value('event_purge', 15); } diff --git a/pandora_console/include/functions_wmi.php b/pandora_console/include/functions_wmi.php index 7148233957..7f01e3f2bd 100644 --- a/pandora_console/include/functions_wmi.php +++ b/pandora_console/include/functions_wmi.php @@ -32,13 +32,13 @@ function wmi_compose_query($wmi_client, $user, $password, $host, $namespace='') { $wmi_command = ''; - if (!empty($password)) { - $wmi_command = $wmi_client.' -U "'.$user.'"%"'.$password.'"'; + if (empty($password) === false) { + $wmi_command = $wmi_client.' -U \''.$user.'\'%\''.$password.'\''; } else { $wmi_command = $wmi_client.' -U "'.$user.'"'; } - if (!empty($namespace)) { + if (empty($namespace) === false) { $namespace = str_replace('"', "'", $namespace); $wmi_command .= ' --namespace="'.$namespace.'"'; } From ececdca0b6ddf7f1d2e161b34f7e5891e025b406 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Fri, 13 May 2022 12:54:58 +0200 Subject: [PATCH 027/174] Not orientation CV view mobile pandora_enterprise#8888 --- pandora_console/general/logon_ok.php | 2 +- .../godmode/setup/setup_visuals.php | 61 ++++++++++++++++--- pandora_console/include/class/HTML.class.php | 2 + .../include/class/WelcomeWindow.class.php | 2 +- pandora_console/include/functions_config.php | 8 +++ pandora_console/include/functions_html.php | 2 +- .../include/functions_tactical.php | 17 ++++-- .../include/functions_visual_map.php | 28 ++++++--- .../include/javascript/pandora_dashboards.js | 54 ++++++++-------- .../Dashboard/Widgets/maps_made_by_user.php | 27 ++++---- .../include/rest-api/models/Model.php | 13 +++- .../VisualConsole/Items/StaticGraph.php | 8 +++ .../style/jquery.mobile-1.5.0-rc1.min.css | 2 +- pandora_console/mobile/include/ui.class.php | 4 ++ .../mobile/operation/visualmap.php | 29 ++++++--- 15 files changed, 184 insertions(+), 75 deletions(-) diff --git a/pandora_console/general/logon_ok.php b/pandora_console/general/logon_ok.php index d836d9f22c..7cb8f1d81b 100644 --- a/pandora_console/general/logon_ok.php +++ b/pandora_console/general/logon_ok.php @@ -288,7 +288,7 @@ foreach ($sessions as $session) { array_push($table->data, $data); } -$activity .= html_print_table($table, true); +$activity = html_print_table($table, true); unset($table); ui_toggle( diff --git a/pandora_console/godmode/setup/setup_visuals.php b/pandora_console/godmode/setup/setup_visuals.php index 9a36b3ac1c..d425c13b14 100755 --- a/pandora_console/godmode/setup/setup_visuals.php +++ b/pandora_console/godmode/setup/setup_visuals.php @@ -11,7 +11,7 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// Load global vars +// Load global vars. global $config; check_login(); @@ -181,7 +181,8 @@ $backgrounds_list = array_merge($backgrounds_list_jpg, $backgrounds_list_png); $backgrounds_list = array_merge($backgrounds_list, $backgrounds_list_gif); asort($backgrounds_list); -if (!enterprise_installed()) { +$open = false; +if (enterprise_installed() === false) { $open = true; } @@ -953,7 +954,7 @@ $options_full_escale[2] = __('On Boolean graphs'); $table_chars->data[$row][1] = html_print_select( $options_full_escale, 'full_scale_option', - $config['full_scale_option'], + (isset($config['full_scale_option']) === true) ? $config['full_scale_option'] : 0, '', '', 0, @@ -973,7 +974,7 @@ $options_soft_graphs[1] = __('Show MAX/AVG/MIN by default'); $table_chars->data[$row][1] = html_print_select( $options_soft_graphs, 'type_mode_graph', - $config['type_mode_graph'], + (isset($config['type_mode_graph']) === true) ? $config['type_mode_graph'] : 0, '', '', 0, @@ -1053,13 +1054,31 @@ $table_vc->data[$row][1] = html_print_extended_select_for_time( $row++; $table_vc->data[$row][0] = __('Default interval for refresh on Visual Console'); -$table_vc->data[$row][1] = html_print_select($values, 'vc_refr', (int) $config['vc_refr'], '', 'N/A', 0, true, false, false); +$table_vc->data[$row][1] = html_print_select( + $values, + 'vc_refr', + (int) $config['vc_refr'], + '', + 'N/A', + 0, + true, + false, + false +); $row++; $vc_favourite_view_array[0] = __('Classic view'); $vc_favourite_view_array[1] = __('View of favorites'); $table_vc->data[$row][0] = __('Type of view of visual consoles'); -$table_vc->data[$row][1] = html_print_select($vc_favourite_view_array, 'vc_favourite_view', $config['vc_favourite_view'], '', '', 0, true); +$table_vc->data[$row][1] = html_print_select( + $vc_favourite_view_array, + 'vc_favourite_view', + $config['vc_favourite_view'], + '', + '', + 0, + true +); $row++; $table_vc->data[$row][0] = __('Number of favorite visual consoles to show in the menu'); @@ -1067,7 +1086,23 @@ $table_vc->data[$row][1] = " $visualConsoleData, - 'items' => $visualConsoleItems, - 'baseUrl' => ui_get_full_url('/', false, false, false), - 'ratio' => $ratio, - 'size' => $size, - 'cellId' => $this->cellId, - 'hash' => User::generatePublicHash(), - 'id_user' => $config['id_user'], - 'page' => 'include/ajax/visual_console.ajax', - 'uniq' => $uniq, + 'props' => $visualConsoleData, + 'items' => $visualConsoleItems, + 'baseUrl' => ui_get_full_url( + '/', + false, + false, + false + ), + 'ratio' => $ratio, + 'size' => $size, + 'cellId' => $this->cellId, + 'hash' => User::generatePublicHash(), + 'id_user' => $config['id_user'], + 'page' => 'include/ajax/visual_console.ajax', + 'uniq' => $uniq, + 'mobile_view_orientation_vc' => false, ] ); @@ -507,7 +513,6 @@ class MapsMadeByUser extends Widget }, dataType: 'JSON', success: function(data) { - console.log(data); $('#vcId').empty(); Object.entries(data).forEach(e => { key = e[0]; diff --git a/pandora_console/include/rest-api/models/Model.php b/pandora_console/include/rest-api/models/Model.php index fda301983a..c257c05b9f 100644 --- a/pandora_console/include/rest-api/models/Model.php +++ b/pandora_console/include/rest-api/models/Model.php @@ -223,6 +223,7 @@ abstract class Model */ public function adjustToViewport($size, $mode='') { + global $config; $ratio_visualconsole = $this->getRatio(); $ratio_w = ($size['width'] / $this->data['width']); $ratio_h = ($size['height'] / $this->data['height']); @@ -232,8 +233,16 @@ abstract class Model $ratio = $ratio_w; if ($mode === 'mobile') { - if ($this->data['height'] < $this->data['width']) { - if ($this->data['height'] > $size['height']) { + if ((bool) $config['mobile_view_orientation_vc'] === true) { + if ($this->data['height'] < $this->data['width']) { + if ($this->data['height'] > $size['height']) { + $ratio = $ratio_h; + $this->data['height'] = $size['height']; + $this->data['width'] = ($size['height'] / $ratio_visualconsole); + } + } + } else { + if ($this->data['height'] > $this->data['width']) { $ratio = $ratio_h; $this->data['height'] = $size['height']; $this->data['width'] = ($size['height'] / $ratio_visualconsole); diff --git a/pandora_console/include/rest-api/models/VisualConsole/Items/StaticGraph.php b/pandora_console/include/rest-api/models/VisualConsole/Items/StaticGraph.php index 2bc262103a..adeaa9c29e 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Items/StaticGraph.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Items/StaticGraph.php @@ -174,6 +174,14 @@ final class StaticGraph extends Item throw new \InvalidArgumentException('missing module Id'); } + if (isset($data['agentDisabled']) === false) { + $data['agentDisabled'] = false; + } + + if (isset($data['moduleDisabled']) === false) { + $data['moduleDisabled'] = false; + } + if ((bool) $data['agentDisabled'] === false && (bool) $data['moduleDisabled'] === false ) { diff --git a/pandora_console/mobile/include/style/jquery.mobile-1.5.0-rc1.min.css b/pandora_console/mobile/include/style/jquery.mobile-1.5.0-rc1.min.css index 60cf0cf83a..e543176676 100644 --- a/pandora_console/mobile/include/style/jquery.mobile-1.5.0-rc1.min.css +++ b/pandora_console/mobile/include/style/jquery.mobile-1.5.0-rc1.min.css @@ -1396,7 +1396,7 @@ div.ui-mobile-viewport { overflow: visible; overflow-x: hidden; padding: 1em; - min-height: calc(100vh - 60px); + /*min-height: calc(100vh - 60px);*/ } .ui-corner-all > .ui-toolbar-header:first-child, .ui-corner-all > .ui-content:first-child, diff --git a/pandora_console/mobile/include/ui.class.php b/pandora_console/mobile/include/ui.class.php index 31d841d353..a08d29a208 100755 --- a/pandora_console/mobile/include/ui.class.php +++ b/pandora_console/mobile/include/ui.class.php @@ -1003,6 +1003,10 @@ class Ui $(document).ready(function () { dashboardLoadVC(settings); + if(settings.mobile_view_orientation_vc === false) { + $(".container-center").css("transform", "rotate(90deg)"); + $(".container-center").css("margin-top", "40px"); + } }); ' ); diff --git a/pandora_console/mobile/operation/visualmap.php b/pandora_console/mobile/operation/visualmap.php index 754afe9c0f..5ec1f6f25b 100644 --- a/pandora_console/mobile/operation/visualmap.php +++ b/pandora_console/mobile/operation/visualmap.php @@ -216,6 +216,7 @@ class Visualmap */ private function show_visualmap() { + global $config; $ui = Ui::getInstance(); $system = System::getInstance(); @@ -279,6 +280,13 @@ class Visualmap 'height' => $this->height, ]; + if ((bool) $config['mobile_view_orientation_vc'] === true) { + $size = [ + 'width' => $this->height, + 'height' => $this->width, + ]; + } + $ratio_t = $visualConsole->adjustToViewport($size, 'mobile'); $visualConsoleData = $visualConsole->toArray(); @@ -340,16 +348,17 @@ class Visualmap $settings = \json_encode( [ - 'props' => $visualConsoleData, - 'items' => $visualConsoleItems, - 'baseUrl' => ui_get_full_url('/', false, false, false), - 'page' => 'include/ajax/visual_console.ajax', - 'ratio' => $ratio_t, - 'size' => $size, - 'cellId' => $uniq, - 'uniq' => $uniq, - 'mobile' => true, - 'vcId' => $visualConsoleId, + 'props' => $visualConsoleData, + 'items' => $visualConsoleItems, + 'baseUrl' => ui_get_full_url('/', false, false, false), + 'page' => 'include/ajax/visual_console.ajax', + 'ratio' => $ratio_t, + 'size' => $size, + 'cellId' => $uniq, + 'uniq' => $uniq, + 'mobile' => true, + 'vcId' => $visualConsoleId, + 'mobile_view_orientation_vc' => (bool) !$config['mobile_view_orientation_vc'], ] ); From 0775b12caabf1285019c60f803782c698bae4fc5 Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 13 May 2022 14:23:48 +0200 Subject: [PATCH 028/174] Description and unit on discovery network snmp interfaces --- .../lib/PandoraFMS/DiscoveryServer.pm | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index fcc1c8ca47..72d7a9b014 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -713,7 +713,9 @@ sub PandoraFMS::Recon::Base::create_interface_modules($$) { 'plugin_user' => $self->{'task_data'}{'snmp_auth_user'}, 'plugin_pass' => $self->{'task_data'}{'snmp_auth_pass'}, 'snmp_community' => $community, - 'snmp_oid' => "$PandoraFMS::Recon::Base::IFOPERSTATUS.$if_index" + 'snmp_oid' => "$PandoraFMS::Recon::Base::IFOPERSTATUS.$if_index", + 'unit' => '' + } ); @@ -741,7 +743,9 @@ sub PandoraFMS::Recon::Base::create_interface_modules($$) { 'plugin_user' => $self->{'task_data'}{'snmp_auth_user'}, 'plugin_pass' => $self->{'task_data'}{'snmp_auth_pass'}, 'snmp_community' => $community, - 'snmp_oid' => "$PandoraFMS::Recon::Base::IFHCINOCTECTS.$if_index" + 'snmp_oid' => "$PandoraFMS::Recon::Base::IFHCINOCTECTS.$if_index", + 'unit' => safe_input('bytes/s') + } ); } else { @@ -766,7 +770,9 @@ sub PandoraFMS::Recon::Base::create_interface_modules($$) { 'plugin_user' => $self->{'task_data'}{'snmp_auth_user'}, 'plugin_pass' => $self->{'task_data'}{'snmp_auth_pass'}, 'snmp_community' => $community, - 'snmp_oid' => "$PandoraFMS::Recon::Base::IFINOCTECTS.$if_index" + 'snmp_oid' => "$PandoraFMS::Recon::Base::IFINOCTECTS.$if_index", + 'unit' => safe_input('bytes/s') + } ); } @@ -795,7 +801,9 @@ sub PandoraFMS::Recon::Base::create_interface_modules($$) { 'plugin_user' => $self->{'task_data'}{'snmp_auth_user'}, 'plugin_pass' => $self->{'task_data'}{'snmp_auth_pass'}, 'snmp_community' => $community, - 'snmp_oid' => "$PandoraFMS::Recon::Base::IFHCOUTOCTECTS.$if_index" + 'snmp_oid' => "$PandoraFMS::Recon::Base::IFHCOUTOCTECTS.$if_index", + 'unit' => safe_input('bytes/s') + } ); } else { @@ -820,7 +828,8 @@ sub PandoraFMS::Recon::Base::create_interface_modules($$) { 'plugin_user' => $self->{'task_data'}{'snmp_auth_user'}, 'plugin_pass' => $self->{'task_data'}{'snmp_auth_pass'}, 'snmp_community' => $community, - 'snmp_oid' => "$PandoraFMS::Recon::Base::IFOUTOCTECTS.$if_index" + 'snmp_oid' => "$PandoraFMS::Recon::Base::IFOUTOCTECTS.$if_index", + 'unit' => safe_input('bytes/s') } ); } @@ -1253,9 +1262,13 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($;$) { $id_tipo_modulo = get_module_id($self->{'dbh'}, $module->{'type'}) if is_empty($id_tipo_modulo); - my $description = safe_output($module->{'description'}); + my $description = safe_output($module->{'descripcion'}); $description = '' if is_empty($description); + my $unit = safe_output($module->{'unit'}); + $unit = '' if is_empty($unit); + + if (is_enabled($module->{'__module_component'})) { # Module from network component. delete $module->{'__module_component'}; @@ -1275,6 +1288,11 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($;$) { } else { # Create module - Direct. my $name = $module->{'name'}; + my $description = safe_output($module->{'descripcion'}); + + my $unit = safe_output($module->{'unit'}); + $unit = '' if is_empty($unit); + delete $module->{'name'}; delete $module->{'description'}; $agentmodule_id = pandora_create_module_from_hash( @@ -1286,7 +1304,8 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($;$) { 'nombre' => safe_input($name), 'descripcion' => safe_input($description), 'id_agente' => $agent_id, - 'ip_target' => $data->{'agent'}{'direccion'} + 'ip_target' => $data->{'agent'}{'direccion'}, + 'unit' => safe_input($unit) }, $self->{'dbh'} ); From c437b894a3b451d6ef2b505f2062f965ee044bfb Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Wed, 18 May 2022 12:55:10 +0200 Subject: [PATCH 029/174] fixed modal size configuration widgets pandora_enterprise#8827 --- pandora_console/include/functions_html.php | 4 +- .../include/javascript/pandora_dashboards.js | 38 ++++++++++++++----- .../include/lib/Dashboard/Manager.php | 19 ++++++++++ .../include/lib/Dashboard/Widget.php | 20 +++++++++- .../lib/Dashboard/Widgets/agent_module.php | 28 +++++++++++--- .../lib/Dashboard/Widgets/alerts_fired.php | 16 ++++++++ .../include/lib/Dashboard/Widgets/clock.php | 16 ++++++++ .../lib/Dashboard/Widgets/custom_graph.php | 16 ++++++++ .../lib/Dashboard/Widgets/events_list.php | 16 ++++++++ .../include/lib/Dashboard/Widgets/example.php | 16 ++++++++ .../Widgets/graph_module_histogram.php | 16 ++++++++ .../lib/Dashboard/Widgets/groups_status.php | 16 ++++++++ .../Dashboard/Widgets/maps_made_by_user.php | 16 ++++++++ .../lib/Dashboard/Widgets/maps_status.php | 16 ++++++++ .../lib/Dashboard/Widgets/module_icon.php | 16 ++++++++ .../lib/Dashboard/Widgets/module_status.php | 16 ++++++++ .../Dashboard/Widgets/module_table_value.php | 16 ++++++++ .../lib/Dashboard/Widgets/module_value.php | 18 ++++++++- .../lib/Dashboard/Widgets/monitor_health.php | 16 ++++++++ .../lib/Dashboard/Widgets/network_map.php | 16 ++++++++ .../include/lib/Dashboard/Widgets/post.php | 16 ++++++++ .../include/lib/Dashboard/Widgets/reports.php | 16 ++++++++ .../lib/Dashboard/Widgets/service_map.php | 21 ++++++++++ .../lib/Dashboard/Widgets/service_view.php | 16 ++++++++ .../lib/Dashboard/Widgets/single_graph.php | 16 ++++++++ .../lib/Dashboard/Widgets/sla_percent.php | 16 ++++++++ .../Dashboard/Widgets/system_group_status.php | 16 ++++++++ .../lib/Dashboard/Widgets/tactical.php | 16 ++++++++ .../lib/Dashboard/Widgets/tree_view.php | 16 ++++++++ .../include/lib/Dashboard/Widgets/url.php | 16 ++++++++ .../lib/Dashboard/Widgets/wux_transaction.php | 18 ++++++++- .../Widgets/wux_transaction_stats.php | 16 ++++++++ 32 files changed, 531 insertions(+), 19 deletions(-) diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 10539fae91..633e928852 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -1685,7 +1685,9 @@ function html_print_select_multiple_modules_filtered(array $data):string ); } - if ($data['mAgents'] !== null) { + if (empty($data['mAgents']) === false + && empty($data['mModuleGroup'] === false) + ) { $all_modules = get_modules_agents( $data['mModuleGroup'], explode(',', $data['mAgents']), diff --git a/pandora_console/include/javascript/pandora_dashboards.js b/pandora_console/include/javascript/pandora_dashboards.js index 6e5a87b169..03b7be02a7 100644 --- a/pandora_console/include/javascript/pandora_dashboards.js +++ b/pandora_console/include/javascript/pandora_dashboards.js @@ -266,7 +266,7 @@ function initialiceLayout(data) { }); $("#configure-widget-" + id).click(function() { - configurationWidget(id, widgetId); + getSizeModalConfiguration(id, widgetId); }); }, error: function(error) { @@ -275,6 +275,29 @@ function initialiceLayout(data) { }); } + function getSizeModalConfiguration(cellId, widgetId) { + $.ajax({ + method: "post", + url: data.url, + data: { + page: data.page, + method: "getSizeModalConfiguration", + dashboardId: data.dashboardId, + cellId: cellId, + widgetId: widgetId + }, + dataType: "json", + success: function(size) { + configurationWidget(cellId, widgetId, size); + }, + error: function(error) { + console.log(error); + return []; + } + }); + return false; + } + function saveLayout() { var items = $(".grid-stack > .grid-stack-item:visible") .map(function(i, el) { @@ -370,7 +393,7 @@ function initialiceLayout(data) { }); } - function configurationWidget(cellId, widgetId) { + function configurationWidget(cellId, widgetId, size) { load_modal({ target: $("#modal-config-widget"), form: "form-config-widget", @@ -388,12 +411,9 @@ function initialiceLayout(data) { dashboardId: data.dashboardId, widgetId: widgetId }, - width: - widgetId == 14 || widgetId == 2 || widgetId == 23 || widgetId == 16 - ? 750 - : 450, - maxHeight: 650, - minHeight: widgetId == 16 ? 450 : 400 + width: size.width, + maxHeight: size.height, + minHeight: size.height }, onsubmit: { page: data.page, @@ -710,7 +730,7 @@ function initialiceLayout(data) { }); $("#configure-widget-" + cellId).click(function() { - configurationWidget(cellId, widgetId); + getSizeModalConfiguration(cellId, widgetId); }); saveLayout(); diff --git a/pandora_console/include/lib/Dashboard/Manager.php b/pandora_console/include/lib/Dashboard/Manager.php index 33cd0a3c2c..56dc0b2caf 100644 --- a/pandora_console/include/lib/Dashboard/Manager.php +++ b/pandora_console/include/lib/Dashboard/Manager.php @@ -180,6 +180,7 @@ class Manager implements PublicLogin 'imageIconDashboardAjax', 'formSlides', 'callWidgetMethod', + 'getSizeModalConfiguration', ]; @@ -1524,4 +1525,22 @@ class Manager implements PublicLogin } + /** + * Size configuration modal (ajax only). + * + * @return void. + */ + public function getSizeModalConfiguration():void + { + $result = []; + $widget = $this->instanceWidget(); + $result = $widget->getSizeModalConfiguration(); + + echo json_encode($result); + + return; + + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widget.php b/pandora_console/include/lib/Dashboard/Widget.php index 320280718b..cf0aa9e74d 100644 --- a/pandora_console/include/lib/Dashboard/Widget.php +++ b/pandora_console/include/lib/Dashboard/Widget.php @@ -512,7 +512,9 @@ class Widget if (empty($values['background']) === true) { $values['background'] = '#ffffff'; - if ($config['style'] === 'pandora_black' && !is_metaconsole()) { + if ($config['style'] === 'pandora_black' + && is_metaconsole() === false + ) { $values['background'] = '#222222'; } } @@ -759,4 +761,20 @@ class Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration():array + { + $size = [ + 'width' => 400, + 'height' => 650, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/agent_module.php b/pandora_console/include/lib/Dashboard/Widgets/agent_module.php index dbc0c1dcf5..1a1d147f49 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/agent_module.php +++ b/pandora_console/include/lib/Dashboard/Widgets/agent_module.php @@ -285,12 +285,12 @@ class AgentModuleWidget extends Widget 'arguments' => [ 'type' => 'select_multiple_modules_filtered', 'uniqId' => $this->cellId, - 'mGroup' => $this->values['mGroup'], - 'mRecursion' => $this->values['mRecursion'], - 'mModuleGroup' => $this->values['mModuleGroup'], - 'mAgents' => $this->values['mAgents'], - 'mShowCommonModules' => $this->values['mShowCommonModules'], - 'mModules' => $this->values['mModules'], + 'mGroup' => (isset($this->values['mGroup']) === true) ? $this->values['mGroup'] : '', + 'mRecursion' => (isset($this->values['mRecursion']) === true) ? $this->values['mRecursion'] : '', + 'mModuleGroup' => (isset($this->values['mModuleGroup']) === true) ? $this->values['mModuleGroup'] : '', + 'mAgents' => (isset($this->values['mAgents']) === true) ? $this->values['mAgents'] : '', + 'mShowCommonModules' => (isset($this->values['mShowCommonModules']) === true) ? $this->values['mShowCommonModules'] : '', + 'mModules' => (isset($this->values['mModules']) === true) ? $this->values['mModules'] : '', 'mShowSelectedOtherGroups' => true, 'mReturnAllGroup' => $return_all_group, 'mMetaFields' => ((bool) is_metaconsole()), @@ -852,4 +852,20 @@ class AgentModuleWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 800, + 'height' => 600, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/alerts_fired.php b/pandora_console/include/lib/Dashboard/Widgets/alerts_fired.php index fdb5c3648a..ad9fcb0c2a 100755 --- a/pandora_console/include/lib/Dashboard/Widgets/alerts_fired.php +++ b/pandora_console/include/lib/Dashboard/Widgets/alerts_fired.php @@ -372,4 +372,20 @@ class AlertsFiredWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 370, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/clock.php b/pandora_console/include/lib/Dashboard/Widgets/clock.php index 5d90f0f863..d06e1c8958 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/clock.php +++ b/pandora_console/include/lib/Dashboard/Widgets/clock.php @@ -322,4 +322,20 @@ class ClockWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 300, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php b/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php index c2515d1088..cdb6075d51 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php +++ b/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php @@ -533,4 +533,20 @@ class CustomGraphWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 480, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/events_list.php b/pandora_console/include/lib/Dashboard/Widgets/events_list.php index e0c1bfe3cf..1a381db8af 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/events_list.php +++ b/pandora_console/include/lib/Dashboard/Widgets/events_list.php @@ -822,4 +822,20 @@ class EventsListWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 700, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/example.php b/pandora_console/include/lib/Dashboard/Widgets/example.php index 3a4ec40fb6..3281c4a660 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/example.php +++ b/pandora_console/include/lib/Dashboard/Widgets/example.php @@ -289,4 +289,20 @@ class WelcomeWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 250, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/graph_module_histogram.php b/pandora_console/include/lib/Dashboard/Widgets/graph_module_histogram.php index dba9035877..570f2ea8b2 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/graph_module_histogram.php +++ b/pandora_console/include/lib/Dashboard/Widgets/graph_module_histogram.php @@ -443,4 +443,20 @@ class GraphModuleHistogramWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 500, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/groups_status.php b/pandora_console/include/lib/Dashboard/Widgets/groups_status.php index af25b2c056..cfa4d99c8f 100755 --- a/pandora_console/include/lib/Dashboard/Widgets/groups_status.php +++ b/pandora_console/include/lib/Dashboard/Widgets/groups_status.php @@ -493,4 +493,20 @@ class GroupsStatusWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 300, + ]; + + return $size; + } + + } 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 7c874954cb..24ce8adc7c 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 @@ -530,4 +530,20 @@ class MapsMadeByUser extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 360, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/maps_status.php b/pandora_console/include/lib/Dashboard/Widgets/maps_status.php index 2f59a29f0a..3da581f2fc 100755 --- a/pandora_console/include/lib/Dashboard/Widgets/maps_status.php +++ b/pandora_console/include/lib/Dashboard/Widgets/maps_status.php @@ -400,4 +400,20 @@ class MapsStatusWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 450, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/module_icon.php b/pandora_console/include/lib/Dashboard/Widgets/module_icon.php index cb3d8086e8..a4ec3a09c6 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/module_icon.php +++ b/pandora_console/include/lib/Dashboard/Widgets/module_icon.php @@ -552,4 +552,20 @@ class ModuleIconWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 700, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/module_status.php b/pandora_console/include/lib/Dashboard/Widgets/module_status.php index 0a0fe65615..2c3c87cc24 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/module_status.php +++ b/pandora_console/include/lib/Dashboard/Widgets/module_status.php @@ -550,4 +550,20 @@ class ModuleStatusWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 700, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/module_table_value.php b/pandora_console/include/lib/Dashboard/Widgets/module_table_value.php index 0039768a30..d77a0cb9e2 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/module_table_value.php +++ b/pandora_console/include/lib/Dashboard/Widgets/module_table_value.php @@ -409,4 +409,20 @@ class ModuleTableValueWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 460, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/module_value.php b/pandora_console/include/lib/Dashboard/Widgets/module_value.php index b005863b24..05a74c1ef1 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/module_value.php +++ b/pandora_console/include/lib/Dashboard/Widgets/module_value.php @@ -378,7 +378,7 @@ class ModuleValueWidget extends Widget { global $config; - $output .= ''; + $output = ''; $id_agent = $this->values['agentId']; $id_group = agents_get_agent_group($id_agent); @@ -445,4 +445,20 @@ class ModuleValueWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 500, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/monitor_health.php b/pandora_console/include/lib/Dashboard/Widgets/monitor_health.php index c8a62feafa..e01ae72843 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/monitor_health.php +++ b/pandora_console/include/lib/Dashboard/Widgets/monitor_health.php @@ -349,4 +349,20 @@ class MonitorHealthWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 250, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/network_map.php b/pandora_console/include/lib/Dashboard/Widgets/network_map.php index c07e09758f..61a099f902 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/network_map.php +++ b/pandora_console/include/lib/Dashboard/Widgets/network_map.php @@ -490,4 +490,20 @@ class NetworkMapWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 470, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/post.php b/pandora_console/include/lib/Dashboard/Widgets/post.php index 584c1af782..e497568093 100755 --- a/pandora_console/include/lib/Dashboard/Widgets/post.php +++ b/pandora_console/include/lib/Dashboard/Widgets/post.php @@ -288,4 +288,20 @@ class PostWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 520, + 'height' => 520, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/reports.php b/pandora_console/include/lib/Dashboard/Widgets/reports.php index 8611665128..cf471c037a 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/reports.php +++ b/pandora_console/include/lib/Dashboard/Widgets/reports.php @@ -499,4 +499,20 @@ class ReportsWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 360, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/service_map.php b/pandora_console/include/lib/Dashboard/Widgets/service_map.php index a2122c6dca..b0230c89e9 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/service_map.php +++ b/pandora_console/include/lib/Dashboard/Widgets/service_map.php @@ -254,6 +254,9 @@ class ServiceMapWidget extends Widget $inputs = parent::getFormInputs(); $services_res = services_get_services(); + if ($services_res === false) { + $services_res = []; + } // If currently selected report is not included in fields array (it belongs to a group over which user has no permissions), then add it to fields array. // This is aimed to avoid overriding this value when a user with narrower permissions edits widget configuration. @@ -341,6 +344,8 @@ class ServiceMapWidget extends Widget $size = parent::getSize(); + $output = ''; + if (check_acl($config['id_user'], 0, 'AR') === 0) { $output .= '
'; $output .= \ui_print_error_message( @@ -461,4 +466,20 @@ class ServiceMapWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 300, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/service_view.php b/pandora_console/include/lib/Dashboard/Widgets/service_view.php index d838861659..aa77312a38 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/service_view.php +++ b/pandora_console/include/lib/Dashboard/Widgets/service_view.php @@ -468,4 +468,20 @@ class ServiceViewWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 300, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/single_graph.php b/pandora_console/include/lib/Dashboard/Widgets/single_graph.php index bc92ade1f8..3ab23e7e87 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/single_graph.php +++ b/pandora_console/include/lib/Dashboard/Widgets/single_graph.php @@ -406,4 +406,20 @@ class SingleGraphWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 480, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/sla_percent.php b/pandora_console/include/lib/Dashboard/Widgets/sla_percent.php index ae1434891e..33d89b7489 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/sla_percent.php +++ b/pandora_console/include/lib/Dashboard/Widgets/sla_percent.php @@ -494,4 +494,20 @@ class SLAPercentWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 550, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/system_group_status.php b/pandora_console/include/lib/Dashboard/Widgets/system_group_status.php index 57b4f90fb3..f0bb617a22 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/system_group_status.php +++ b/pandora_console/include/lib/Dashboard/Widgets/system_group_status.php @@ -634,4 +634,20 @@ class SystemGroupStatusWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 600, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/tactical.php b/pandora_console/include/lib/Dashboard/Widgets/tactical.php index 74d72d0c5c..3b60acaaea 100755 --- a/pandora_console/include/lib/Dashboard/Widgets/tactical.php +++ b/pandora_console/include/lib/Dashboard/Widgets/tactical.php @@ -494,4 +494,20 @@ class TacticalWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 400, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/tree_view.php b/pandora_console/include/lib/Dashboard/Widgets/tree_view.php index fe76b94ec0..095bd8dc0a 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/tree_view.php +++ b/pandora_console/include/lib/Dashboard/Widgets/tree_view.php @@ -726,4 +726,20 @@ class TreeViewWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 520, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/url.php b/pandora_console/include/lib/Dashboard/Widgets/url.php index 41a3420d0a..b0d4d7efd9 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/url.php +++ b/pandora_console/include/lib/Dashboard/Widgets/url.php @@ -298,4 +298,20 @@ class UrlWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 300, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/wux_transaction.php b/pandora_console/include/lib/Dashboard/Widgets/wux_transaction.php index 5026a240f5..3222c980d9 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/wux_transaction.php +++ b/pandora_console/include/lib/Dashboard/Widgets/wux_transaction.php @@ -176,7 +176,7 @@ class WuxWidget extends Widget // Must be configured before using. $this->configurationRequired = false; if (empty($this->options) === true) { - $this->configuration_required = true; + $this->configurationRequired = true; } $this->overflow_scrollbars = false; @@ -430,4 +430,20 @@ class WuxWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 360, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/wux_transaction_stats.php b/pandora_console/include/lib/Dashboard/Widgets/wux_transaction_stats.php index e75a0012d3..5acc972d32 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/wux_transaction_stats.php +++ b/pandora_console/include/lib/Dashboard/Widgets/wux_transaction_stats.php @@ -390,4 +390,20 @@ class WuxStatsWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 400, + ]; + + return $size; + } + + } From d0a04177c0fa7dc523255f6168222b16e8a3a046 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Wed, 18 May 2022 17:17:31 +0200 Subject: [PATCH 030/174] add treshold pdf pandora_enterprise#1419 --- .../reporting_builder.item_editor.php | 21 +++++++++++++++ .../godmode/reporting/reporting_builder.php | 6 +++++ .../include/ajax/custom_fields.php | 2 +- .../include/class/AgentWizard.class.php | 2 +- pandora_console/include/functions_api.php | 2 +- pandora_console/include/functions_graph.php | 10 +++---- .../include/functions_reporting.php | 6 +++++ .../include/graphs/flot/pandora.flot.js | 26 +++++++++---------- 8 files changed, 54 insertions(+), 21 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 724d695f6a..eff8d41220 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -135,6 +135,7 @@ $current_month = true; // Only avg is selected by default for the simple graphs. $fullscale = false; $percentil = false; +$image_threshold = false; $time_compare_overlapped = false; // Added for events items. @@ -307,6 +308,7 @@ switch ($action) { case 'simple_graph': $fullscale = isset($style['fullscale']) ? (bool) $style['fullscale'] : 0; $percentil = isset($style['percentil']) ? (bool) $style['percentil'] : 0; + $image_threshold = (isset($style['image_threshold']) === true) ? (bool) $style['image_threshold'] : false; $graph_render = $item['graph_render']; // The break hasn't be forgotten. case 'simple_baseline_graph': @@ -2501,6 +2503,23 @@ $class = 'databox filters'; + + + + + + + + + head = []; $table_modules->head[0] = __('Module name'); $table_modules->head[1] = __('Data'); - $table_modules->head[2] = __('Treshold'); + $table_modules->head[2] = __('Threshold'); $table_modules->head[3] = __('Current interval'); $table_modules->head[4] = __('Timestamp'); $table_modules->head[5] = __('Status'); diff --git a/pandora_console/include/class/AgentWizard.class.php b/pandora_console/include/class/AgentWizard.class.php index 1600aab4b6..36c5d36c75 100644 --- a/pandora_console/include/class/AgentWizard.class.php +++ b/pandora_console/include/class/AgentWizard.class.php @@ -1181,7 +1181,7 @@ class AgentWizard extends HTML $table->head[1] = ''.__('Server').''; $table->head[2] = ''.__('Type').''; $table->head[3] = ''.__('Description').''; - $table->head[4] = ''.__('Treshold').''; + $table->head[4] = ''.__('Threshold').''; $table->data = []; diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 71128946c5..8155e22415 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -14855,7 +14855,7 @@ function api_get_module_graph($id_module, $thrash2, $other, $thrash4) 'type_graph' => $config['type_module_charts'], 'fullscale' => false, 'return_img_base_64' => true, - 'image_treshold' => $graph_threshold, + 'image_threshold' => $graph_threshold, 'graph_font_size' => $graph_font_size, ]; diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index d9493a99b2..df7440754b 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -626,7 +626,7 @@ function grafico_modulo_sparse_data( * 'show_legend' => true, * 'show_overview' => true, * 'return_img_base_64' => false, - * 'image_treshold' => false, + * 'image_threshold' => false, * 'graph_combined' => false, * 'graph_render' => 0, * 'zoom' => 1, @@ -782,8 +782,8 @@ function grafico_modulo_sparse($params) $params['return_img_base_64'] = false; } - if (isset($params['image_treshold']) === false) { - $params['image_treshold'] = false; + if (isset($params['image_threshold']) === false) { + $params['image_threshold'] = false; } if (isset($params['graph_combined']) === false) { @@ -1305,8 +1305,8 @@ function graphic_combined_module( $params['return_img_base_64'] = false; } - if (isset($params['image_treshold']) === false) { - $params['image_treshold'] = false; + if (isset($params['image_threshold']) === false) { + $params['image_threshold'] = false; } if (isset($params['show_unknown']) === false) { diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 6bf29c1235..12ff161603 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -10157,6 +10157,11 @@ function reporting_simple_graph( $fullscale = (bool) $content['style']['fullscale']; } + $image_threshold = false; + if (isset($content['style']['image_threshold'])) { + $image_threshold = (bool) $content['style']['image_threshold']; + } + $return['chart'] = ''; // Get chart. @@ -10211,6 +10216,7 @@ function reporting_simple_graph( 'backgroundColor' => 'transparent', 'return_img_base_64' => true, 'graph_render' => $content['graph_render'], + 'image_threshold' => $image_threshold, ]; if ($only_image === false) { diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index bdd3aa3038..b30d9e487b 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -1003,7 +1003,7 @@ function pandoraFlotArea( var max_x = date_array["final_date"] * 1000; var type = parseInt(params.stacked); var show_legend = params.show_legend; - var image_treshold = params.image_treshold; + var image_threshold = params.image_threshold; var short_data = params.short_data != "" ? params.short_data : 3; var grid_color = params.grid_color; var background_color = params.backgroundColor; @@ -2198,7 +2198,7 @@ function pandoraFlotArea( } if (thresholded) { - var data_base_treshold = add_threshold( + var data_base_threshold = add_threshold( data_base, threshold_data, ranges.yaxis.from, @@ -2211,7 +2211,7 @@ function pandoraFlotArea( plot = $.plot( $("#" + graph_id), - data_base_treshold, + data_base_threshold, $.extend(true, {}, options, { grid: { borderWidth: 1, @@ -2597,7 +2597,7 @@ function pandoraFlotArea( $("#overview_" + graph_id).bind("mouseout", resetInteractivity); } - if (image_treshold) { + if (image_threshold) { var y_recal = plot.getAxes().yaxis.max; if (!thresholded) { // Recalculate the y axis @@ -2611,7 +2611,7 @@ function pandoraFlotArea( ); } - var datas_treshold = add_threshold( + var datas_threshold = add_threshold( data_base, threshold_data, plot.getAxes().yaxis.min, @@ -2624,7 +2624,7 @@ function pandoraFlotArea( plot = $.plot( $("#" + graph_id), - datas_treshold, + datas_threshold, $.extend(true, {}, options, { yaxis: { max: y_recal.max @@ -2758,7 +2758,7 @@ function pandoraFlotArea( ); } - datas_treshold = add_threshold( + datas_threshold = add_threshold( data_base, threshold_data, plot.getAxes().yaxis.min, @@ -2771,7 +2771,7 @@ function pandoraFlotArea( plot = $.plot( $("#" + graph_id), - datas_treshold, + datas_threshold, $.extend(true, {}, options, { yaxis: { min: max_draw["min"], @@ -3115,7 +3115,7 @@ function axis_thresholded( return y; } -//add treshold +//add threshold function add_threshold( data_base, threshold_data, @@ -3235,13 +3235,13 @@ function add_threshold( } }); - var extreme_treshold_array = []; + var extreme_threshold_array = []; var i = 0; var flag = true; $.each(threshold_array, function(index, value) { flag = true; - extreme_treshold_array[i] = { + extreme_threshold_array[i] = { below: value["max"], color: value["color"] }; @@ -3252,7 +3252,7 @@ function add_threshold( } }); if (flag) { - extreme_treshold_array[i] = { + extreme_threshold_array[i] = { below: value["min"], color: datas[0].color }; @@ -3260,7 +3260,7 @@ function add_threshold( } }); - datas[0].threshold = extreme_treshold_array; + datas[0].threshold = extreme_threshold_array; return datas; } From 2953bab0df23009d438d9d5a54abf8a899bea186 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 24 May 2022 09:55:37 +0200 Subject: [PATCH 031/174] #8999 Optimised delete agents in bulk --- .../godmode/massive/massive_delete_agents.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pandora_console/godmode/massive/massive_delete_agents.php b/pandora_console/godmode/massive/massive_delete_agents.php index e85a12486d..cc87efebed 100755 --- a/pandora_console/godmode/massive/massive_delete_agents.php +++ b/pandora_console/godmode/massive/massive_delete_agents.php @@ -140,7 +140,7 @@ function process_manage_delete($id_agents) } -$id_group = (int) get_parameter('id_group'); +$id_group = (is_metaconsole() === true) ? get_parameter('id_group', '') : (int) get_parameter('id_group'); $id_agents = get_parameter('id_agents'); $recursion = get_parameter('recursion'); $delete = (bool) get_parameter_post('delete'); @@ -282,15 +282,15 @@ $table->data[3][0] .= ''; -$agents = agents_get_group_agents( - array_keys(users_get_groups($config['id_user'], 'AW', false)), - ['disabled' => 2], - 'none', - false, - false, - is_metaconsole(), - '|' -); +$agents = []; +if (is_metaconsole() === false) { + $agents = agents_get_group_agents( + array_keys(users_get_groups($config['id_user'], 'AW', false)), + ['disabled' => 2], + 'none' + ); +} + $table->data[3][1] = html_print_select( $agents, From 8d04570989d86899699e1c3f9b1b9ae6d2d20e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Tue, 24 May 2022 10:59:41 +0200 Subject: [PATCH 032/174] Set new mode for manage properly the restarting of snmptrap process --- pandora_server/lib/PandoraFMS/SNMPServer.pm | 31 +++++++++++++-------- pandora_server/util/pandora_manage.pl | 17 ++++++++++- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/SNMPServer.pm b/pandora_server/lib/PandoraFMS/SNMPServer.pm index 492dfdfa60..581c1b441d 100644 --- a/pandora_server/lib/PandoraFMS/SNMPServer.pm +++ b/pandora_server/lib/PandoraFMS/SNMPServer.pm @@ -40,6 +40,7 @@ use PandoraFMS::ProducerConsumerServer; # Inherits from PandoraFMS::ProducerConsumerServer our @ISA = qw(PandoraFMS::ProducerConsumerServer); +our @EXPORT = qw(start_snmptrapd); # Global variables my @TaskQueue :shared; @@ -442,26 +443,29 @@ sub start_snmptrapd ($) { # Manual start of snmptrapd if ($config->{'snmp_trapd'} eq 'manual') { - logger ($config, "No SNMP trap daemon configured. Start snmptrapd manually.", 1); - print_message ($config, " [*] No SNMP trap daemon configured. Start snmptrapd manually.", 1); + my $noSNMPTrap = "No SNMP trap daemon configured. Start snmptrapd manually."; + logger ($config, $noSNMPTrap, 1); + print_message ($config, " [*] $noSNMPTrap", 1); if (! -f $config->{'snmp_logfile'}) { - logger ($config, "SNMP log file " . $config->{'snmp_logfile'} . " not found.", 1); - print_message ($config, " [E] SNMP log file " . $config->{'snmp_logfile'} . " not found.", 1); + my $noLogFile = "SNMP log file " . $config->{'snmp_logfile'} . " not found."; + logger ($config, $noLogFile, 1); + print_message ($config, " [E] $noLogFile", 1); return 1; } - + return 0; } - + if ( -e $pid_file && open (PIDFILE, $pid_file)) { my $pid = + 0; - close PIDFILE; + close PIDFILE; # Check if snmptrapd is running if ($snmptrapd_running = kill (0, $pid)) { - logger ($config, "snmptrapd (pid $pid) is already running, attempting to kill it...", 1); - print_message ($config, "snmptrapd (pid $pid) is already running, attempting to kill it...", 1); + my $alreadyRunning = "snmptrapd (pid $pid) is already running, attempting to kill it..."; + logger ($config, $alreadyRunning, 1); + print_message ($config, " [*] $alreadyRunning ", 1); kill (9, $pid); } } @@ -471,17 +475,20 @@ sub start_snmptrapd ($) { # Select agent-addr field of the PDU or PDU source address for V1 traps my $address_format = ($config->{'snmp_pdu_address'} eq '0' ? '%a' : '%b'); - + my $snmptrapd_args = ' -t -On -n' . $snmp_ignore_authfailure . ' -Lf ' . $config->{'snmp_logfile'} . ' -p ' . $pid_file; $snmptrapd_args .= ' --format1=SNMPv1[**]%4y-%02.2m-%l[**]%02.2h:%02.2j:%02.2k[**]' . $address_format . '[**]%N[**]%w[**]%W[**]%q[**]%v\\\n'; $snmptrapd_args .= ' --format2=SNMPv2[**]%4y-%02.2m-%l[**]%02.2h:%02.2j:%02.2k[**]%b[**]%v\\\n'; if (system ($config->{'snmp_trapd'} . $snmptrapd_args . " >$DEVNULL 2>&1") != 0) { - logger ($config, " [E] Could not start snmptrapd.", 1); - print_message ($config, " [E] Could not start snmptrapd.", 1); + my $showError = "Could not start snmptrapd."; + logger ($config, $showError, 1); + print_message ($config, " [E] $showError ", 1); return 1; } + print_message ($config, " [*] snmptrapd started and running.", 1); + return 0; } diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 26f0b847c7..57a4036875 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -231,6 +231,7 @@ sub help_screen{ print "\nTOOLS:\n\n" unless $param ne ''; help_screen_line('--exec_from_file', ' ', "Execute any CLI option \n\t with macros from CSV file"); help_screen_line('--create_snmp_trap', ' ', "Create a new trap definition. \n\tSeverity 0 (Maintenance), 1(Info) , 2 (Normal), 3 (Warning), 4 (Critical), 5 (Minor) and 6 (Major)"); + help_screen_line('--start_snmptrapd', '[no parameters needed]', "Start the snmptrap process or restart if it is running"); print "\nSETUP:\n\n" unless $param ne ''; help_screen_line('--set_event_storm_protection', '', "Enable (1) or disable (0) event \n\t storm protection"); @@ -279,7 +280,7 @@ sub api_call($$$;$$$$) { my $ua = new LWP::UserAgent; my $url = $pa_config->{"console_api_url"}; my $response = $ua->post($url, $params); - + if ($response->is_success) { $content = $response->decoded_content(); } @@ -1163,6 +1164,16 @@ sub cli_enable_group() { pandora_enable_group ($conf, $dbh, $id_group); } +############################################################################## +# Start snmptrap process. +# Related option: --start_snmptrapd +############################################################################## +sub cli_start_snmptrapd() { + use PandoraFMS::SNMPServer; + print_log "[INFO] Starting snmptrap process. \n"; + PandoraFMS::SNMPServer::start_snmptrapd(\%conf); +} + ############################################################################## # Create an agent. # Related option: --created_agent @@ -7505,6 +7516,10 @@ sub pandora_manage_main ($$$) { param_check($ltotal, 1); cli_enable_group(); } + elsif ($param eq '--start_snmptrapd') { + #param_check($ltotal, 0); + cli_start_snmptrapd(); + } elsif ($param eq '--create_agent') { param_check($ltotal, 8, 4); cli_create_agent(); From 3623849ce4495553fc7debc268dc1f6ce99edd72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Tue, 24 May 2022 11:04:29 +0200 Subject: [PATCH 033/174] Fix logrotate --- pandora_server/util/pandora_logrotate | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandora_server/util/pandora_logrotate b/pandora_server/util/pandora_logrotate index 3ac2623122..08d999d556 100644 --- a/pandora_server/util/pandora_logrotate +++ b/pandora_server/util/pandora_logrotate @@ -55,5 +55,8 @@ rotate 1 maxage 30 notifempty + postrotate + /usr/local/bin/pandora_manage /etc/pandora/pandora_server.conf --start_snmptrapd > /dev/null 2>/dev/null || true copytruncate + endscript } From fc7b4d8a119d2ee89adf2acb8d2684735a8e1682 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Wed, 25 May 2022 13:13:09 +0200 Subject: [PATCH 034/174] #8897 Fixed tdashboard name --- pandora_console/extras/mr/55.sql | 5 +++++ pandora_console/pandoradb.sql | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 pandora_console/extras/mr/55.sql diff --git a/pandora_console/extras/mr/55.sql b/pandora_console/extras/mr/55.sql new file mode 100644 index 0000000000..d9693047c1 --- /dev/null +++ b/pandora_console/extras/mr/55.sql @@ -0,0 +1,5 @@ +START TRANSACTION; + +ALTER TABLE `tdashboard` MODIFY `name` TEXT NOT NULL DEFAULT ''; + +COMMIT; \ No newline at end of file diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 29ec6e572b..49f5edb991 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -2578,7 +2578,7 @@ CREATE TABLE IF NOT EXISTS `tpolicy_group_agents` ( -- --------------------------------------------------------------------- CREATE TABLE IF NOT EXISTS `tdashboard` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - `name` VARCHAR(60) NOT NULL DEFAULT '', + `name` TEXT NOT NULL DEFAULT '', `id_user` VARCHAR(60) NOT NULL DEFAULT '', `id_group` INT NOT NULL DEFAULT 0, `active` TINYINT NOT NULL DEFAULT 0, From 0a99b608c5d04477b36a94f32b7fdb6552708ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Wed, 25 May 2022 17:53:58 +0200 Subject: [PATCH 035/174] Fix several issues with SNMP Alert view --- .../godmode/snmpconsole/snmp_alert.php | 782 ++++++++++-------- pandora_console/include/styles/pandora.css | 7 + 2 files changed, 449 insertions(+), 340 deletions(-) diff --git a/pandora_console/godmode/snmpconsole/snmp_alert.php b/pandora_console/godmode/snmpconsole/snmp_alert.php index 6829d445e1..35fcaf172c 100755 --- a/pandora_console/godmode/snmpconsole/snmp_alert.php +++ b/pandora_console/godmode/snmpconsole/snmp_alert.php @@ -1,8 +1,20 @@ __('Other'), ]; -// Form submitted -// ============= +// Form submitted. $update_alert = (bool) get_parameter('update_alert', false); $create_alert = (bool) get_parameter('create_alert', false); $save_alert = (bool) get_parameter('save_alert', false); $modify_alert = (bool) get_parameter('modify_alert', false); $delete_alert = (bool) get_parameter('delete_alert', false); $multiple_delete = (bool) get_parameter('multiple_delete', false); -$add_action = (bool) get_parameter('add_alert', 0); +$add_action = (bool) get_parameter('add_alert', false); $delete_action = get_parameter('delete_action', 0); $duplicate_alert = get_parameter('duplicate_alert', 0); -if ($add_action) { +if ($add_action === true) { $values['id_alert_snmp'] = (int) get_parameter('id_alert_snmp'); $values['alert_type'] = (int) get_parameter('alert_type'); $values[db_escape_key_identifier('al_field1')] = get_parameter('field1_value'); @@ -79,37 +91,41 @@ if ($delete_action) { } if ($update_alert || $modify_alert) { - ui_print_page_header( - __('SNMP Console').' » '.__('Update alert'), - 'images/op_snmp.png', - false, - 'snmp_alert_update_tab', - false - ); + $subTitle = __('Update alert'); + $helpString = 'snmp_alert_update_tab'; } else if ($create_alert || $save_alert) { - ui_print_page_header( - __('SNMP Console').' » '.__('Create alert'), - 'images/op_snmp.png', - false, - 'snmp_alert_overview_tab', - false - ); + $subTitle = __('Create alert'); + $helpString = 'snmp_alert_overview_tab'; } else { - ui_print_page_header( - __('SNMP Console').' » '.__('Alert overview'), - 'images/op_snmp.png', - false, - '', - false - ); + $subTitle = __('Alert overview'); + $helpString = ''; } +ui_print_standard_header( + $subTitle, + 'images/op_snmp.png', + false, + $helpString, + false, + [], + [ + [ + 'link' => '', + 'label' => __('Alerts'), + ], + [ + 'link' => '', + 'label' => __('SNMP Console'), + ], + ] +); + if ($save_alert || $modify_alert) { $id_as = (int) get_parameter('id_alert_snmp', -1); $source_ip = (string) get_parameter_post('source_ip'); $alert_type = (int) get_parameter_post('alert_type'); - // Event, e-mail + // Event, e-mail. $description = (string) get_parameter_post('description'); $oid = (string) get_parameter_post('oid'); $custom_value = (string) get_parameter_post('custom_value'); @@ -269,7 +285,7 @@ if ($save_alert || $modify_alert) { $result = db_process_sql_insert('talert_snmp', $values); - if (!$result) { + if ((bool) $result === false) { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, 'Fail try to create snmp alert' @@ -278,7 +294,10 @@ if ($save_alert || $modify_alert) { } else { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Create snmp alert #$result" + sprintf( + 'Create snmp alert #%s', + $result + ) ); ui_print_success_message(__('Successfully created')); } @@ -405,24 +424,29 @@ if ($save_alert || $modify_alert) { $result = db_process_sql($sql); - if (!$result) { + if ((bool) $result === false) { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Fail try to update snmp alert #$id_as" + sprintf( + 'Fail try to update snmp alert #%s', + $id_as + ) ); ui_print_error_message(__('There was a problem updating the alert')); } else { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Update snmp alert #$id_as" + sprintf( + 'Update snmp alert #%s', + $id_as + ) ); ui_print_success_message(__('Successfully updated')); } } } -// From variable init -// ================== +// From variable init. if ($update_alert || $duplicate_alert) { $id_as = (int) get_parameter('id_alert_snmp', -1); @@ -516,11 +540,11 @@ if ($update_alert || $duplicate_alert) { return; } } else if ($create_alert) { - // Variable init + // Variable init. $id_as = -1; $source_ip = ''; $alert_type = 1; - // Event, e-mail + // Event, e-mail. $description = ''; $oid = ''; $custom_value = ''; @@ -595,40 +619,46 @@ if ($update_alert || $duplicate_alert) { $group = 0; } -// Duplicate alert snmp +// Duplicate alert snmp. if ($duplicate_alert) { $values_duplicate = $alert; - if (!empty($values_duplicate)) { + if (empty($values_duplicate) === false) { unset($values_duplicate['id_as']); $result = db_process_sql_insert('talert_snmp', $values_duplicate); if (!$result) { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Fail try to duplicate snmp alert #$id_as" + sprintf( + 'Fail try to duplicate snmp alert #%s', + $id_as + ) ); ui_print_error_message(__('There was a problem duplicating the alert')); } else { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Duplicate snmp alert #$id_as" + sprintf( + 'Duplicate snmp alert #%s', + $id_as + ) ); ui_print_success_message(__('Successfully Duplicate')); } } else { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Fail try to duplicate snmp alert #$id_as" + sprintf( + 'Fail try to duplicate snmp alert #%s', + $id_as + ) ); ui_print_error_message(__('There was a problem duplicating the alert')); } } -// Header -// Alert Delete -// ============= if ($delete_alert) { - // Delete alert + // Delete alert. $alert_delete = (int) get_parameter_get('delete_alert', 0); $result = db_process_sql_delete( @@ -639,13 +669,19 @@ if ($delete_alert) { if ($result === false) { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Fail try to delete snmp alert #$alert_delete" + sprintf( + 'Fail try to delete snmp alert #%s', + $alert_delete + ) ); ui_print_error_message(__('There was a problem deleting the alert')); } else { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Delete snmp alert #$alert_delete" + sprintf( + 'Delete snmp alert #%s', + $alert_delete + ) ); ui_print_success_message(__('Successfully deleted')); } @@ -666,18 +702,24 @@ if ($multiple_delete) { if ($result !== false) { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Delete snmp alert #$alert_delete" + sprintf( + 'Delete snmp alert #%s', + $alert_delete + ) ); $count++; } else { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Fail try to delete snmp alert #$alert_delete" + sprintf( + 'Fail try to delete snmp alert #%s', + $alert_delete + ) ); } } - if ($count == $total) { + if ($count === $total) { ui_print_success_message( __('Successfully deleted alerts (%s / %s)', $count, $total) ); @@ -692,7 +734,7 @@ $user_groups = users_get_groups($config['id_user'], 'AR', true); $str_user_groups = ''; $i = 0; foreach ($user_groups as $id => $name) { - if ($i == 0) { + if ($i === 0) { $str_user_groups .= $id; } else { $str_user_groups .= ','.$id; @@ -701,10 +743,9 @@ foreach ($user_groups as $id => $name) { $i++; } -// Alert form +// Alert form. if ($create_alert || $update_alert) { - // if (isset ($_GET["update_alert"])) { - // the update_alert means the form should be displayed. If update_alert > 1 then an existing alert is updated + // The update_alert means the form should be displayed. If update_alert > 1 then an existing alert is updated. echo '
'; html_print_input_hidden('id_alert_snmp', $id_as); @@ -717,32 +758,39 @@ if ($create_alert || $update_alert) { html_print_input_hidden('modify_alert', 1); } - // SNMP alert filters + // SNMP alert filters. echo ''; - // Description - echo ''.''.''.''; + // Description. + echo ''; + echo ''; + echo ''; + echo ''; - // echo ''; - // OID - echo ''.''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Custom + // Custom. echo ''; + echo ''; + echo ''; - // SNMP Agent + // SNMP Agent. echo ''; + echo ''; + echo ''; $return_all_group = false; @@ -750,7 +798,7 @@ if ($create_alert || $update_alert) { $return_all_group = true; } - // Group + // Group. echo ''; + echo ''; + echo ''; - // Trap type + // Trap type. echo ''; + echo ''; + echo ''; - // Single value + // Single value. echo ''; + echo ''; + echo ''; - // Variable bindings/Data #1 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #2 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #3 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #4 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #5 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #6 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #7 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #8 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #9 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #10 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #11 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #12 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #13 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #14 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #15 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #16 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #17 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #18 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #19 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #20 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Alert fields + // Alert fields. $al = [ 'al_field1' => $al_field1, 'al_field2' => $al_field2, @@ -974,7 +1061,7 @@ if ($create_alert || $update_alert) { 'al_field20' => $al_field20, ]; - // Hidden div with help hint to fill with javascript + // Hidden div with help hint to fill with javascript. html_print_div(['id' => 'help_snmp_alert_hint', 'content' => ui_print_help_icon('snmp_alert_field1', true), 'hidden' => true]); for ($i = 1; $i <= $config['max_macro_fields']; $i++) { @@ -984,7 +1071,7 @@ if ($create_alert || $update_alert) { echo ''; } - // Max / Min alerts + // Max / Min alerts. echo ''; - // Time Threshold + // Time Threshold. echo ''; - // Priority + // Priority. echo ''; @@ -1048,10 +1135,11 @@ if ($create_alert || $update_alert) { echo "
'.__('Description').''; - html_print_textarea('description', 3, 2, $description, 'class="w400px"'); - echo '
'.__('Description').''; + html_print_textarea('description', 3, 2, $description, 'class="w400px"'); + echo '
' . __('Alert filters') . ui_print_help_icon("snmp_alert_filters", true) . '
'.__('Enterprise String').ui_print_help_tip(__('Matches substrings. End the string with $ for exact matches.'), true).''; + // OID. + echo '
'.__('Enterprise String').ui_print_help_tip(__('Matches substrings. End the string with $ for exact matches.'), true).''; html_print_input_text('oid', $oid, '', 50, 255); - echo '
'.__('Custom Value/OID'); echo ''; html_print_textarea('custom_value', 2, 2, $custom_value, 'class="w400px"'); - echo '
'.__('SNMP Agent').' (IP)'; html_print_input_text('source_ip', $source_ip, '', 20); - echo '
'.__('Group').''; echo '
'; html_print_select_groups( @@ -774,183 +822,222 @@ if ($create_alert || $update_alert) { false ); echo '
'; - echo '
'.__('Trap type').''; echo html_print_select($trap_types, 'trap_type', $trap_type, '', '', '', false, false, false); - echo '
'.__('Single value').''; html_print_input_text('single_value', $single_value, '', 20); - echo '
'.__('Variable bindings/Data').''; + // Variable bindings/Data #1. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_1', $order_1, '', 4); html_print_input_text('custom_oid_data_1', $custom_oid_data_1, '', 60); - echo '
'.__('Variable bindings/Data'); - // echo ui_print_help_icon ("snmp_alert_custom", true); - echo ''; + // Variable bindings/Data #2. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_2', $order_2, '', 4); html_print_input_text('custom_oid_data_2', $custom_oid_data_2, '', 60); - echo '
'.__('Variable bindings/Data'); - // echo ui_print_help_icon ("snmp_alert_custom", true); - echo ''; + // Variable bindings/Data #3. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_3', $order_3, '', 4); html_print_input_text('custom_oid_data_3', $custom_oid_data_3, '', 60); - echo '
'.__('Variable bindings/Data'); - // echo ui_print_help_icon ("snmp_alert_custom", true); - echo ''; + // Variable bindings/Data #4. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_4', $order_4, '', 4); html_print_input_text('custom_oid_data_4', $custom_oid_data_4, '', 60); - echo '
'.__('Variable bindings/Data'); - // echo ui_print_help_icon ("snmp_alert_custom", true); - echo ''; + // Variable bindings/Data #5. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_5', $order_5, '', 4); html_print_input_text('custom_oid_data_5', $custom_oid_data_5, '', 60); - echo '
'.__('Variable bindings/Data'); - // echo ui_print_help_icon ("snmp_alert_custom", true); - echo ''; + // Variable bindings/Data #6. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_6', $order_6, '', 4); html_print_input_text('custom_oid_data_6', $custom_oid_data_6, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #7. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_7', $order_7, '', 4); html_print_input_text('custom_oid_data_7', $custom_oid_data_7, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #8. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_8', $order_8, '', 4); html_print_input_text('custom_oid_data_8', $custom_oid_data_8, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #9. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_9', $order_9, '', 4); html_print_input_text('custom_oid_data_9', $custom_oid_data_9, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #10. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_10', $order_10, '', 4); html_print_input_text('custom_oid_data_10', $custom_oid_data_10, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #11. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_11', $order_11, '', 4); html_print_input_text('custom_oid_data_11', $custom_oid_data_11, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #12. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_12', $order_12, '', 4); html_print_input_text('custom_oid_data_12', $custom_oid_data_12, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #13. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_13', $order_13, '', 4); html_print_input_text('custom_oid_data_13', $custom_oid_data_13, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #14. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_14', $order_14, '', 4); html_print_input_text('custom_oid_data_14', $custom_oid_data_14, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #15. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_15', $order_15, '', 4); html_print_input_text('custom_oid_data_15', $custom_oid_data_15, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #16. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_16', $order_16, '', 4); html_print_input_text('custom_oid_data_16', $custom_oid_data_16, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #17. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_17', $order_17, '', 4); html_print_input_text('custom_oid_data_17', $custom_oid_data_17, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #18. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_18', $order_18, '', 4); html_print_input_text('custom_oid_data_18', $custom_oid_data_18, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #19. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_19', $order_19, '', 4); html_print_input_text('custom_oid_data_19', $custom_oid_data_19, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #20. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_20', $order_20, '', 4); html_print_input_text('custom_oid_data_20', $custom_oid_data_20, '', 60); - echo '
'.__('Min. number of alerts').''; html_print_input_text('min_alerts', $min_alerts, '', 3); @@ -992,7 +1079,7 @@ if ($create_alert || $update_alert) { html_print_input_text('max_alerts', $max_alerts, '', 3); echo '
'.__('Time threshold').''; $fields = []; @@ -1014,7 +1101,7 @@ if ($create_alert || $update_alert) { html_print_input_text('time_other', 0, '', 6); echo ' '.__('seconds').'
'.__('Priority').''; echo html_print_select(get_priorities(), 'priority', $priority, '', '', '0', false, false, false); echo '
"; echo '
'; + html_print_button(__('Back'), 'button_back', false, '', 'class="sub cancel margin-right-05"'); if ($id_as > 0) { - html_print_submit_button(__('Update'), 'submit', false, 'class="sub upd"', false); + html_print_submit_button(__('Update'), 'submit', false, 'class="sub upd"'); } else { - html_print_submit_button(__('Create'), 'submit', false, 'class="sub wand"', false); + html_print_submit_button(__('Create'), 'submit', false, 'class="sub wand"'); } echo '
'; @@ -1089,119 +1177,68 @@ if ($create_alert || $update_alert) { $form_filter .= '
'; $form_filter .= ''; - // echo "
"; ui_toggle($form_filter, __('Alert SNMP control filter'), __('Toggle filter(s)')); $filter = []; $offset = (int) get_parameter('offset'); $limit = (int) $config['block_size']; if ($filter_param) { - // Move the first page + // Move the first page. $offset = 0; - $url_pagination = 'index.php?'.'sec=snmpconsole&'.'sec2=godmode/snmpconsole/snmp_alert&'.'free_search='.$free_search.'&'.'trap_type_filter='.$trap_type_filter.'&'.'priority_filter='.$priority_filter; + $url_pagination = 'index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&free_search='.$free_search.'&trap_type_filter='.$trap_type_filter.'&priority_filter='.$priority_filter; } else { - $url_pagination = 'index.php?'.'sec=snmpconsole&'.'sec2=godmode/snmpconsole/snmp_alert&'.'free_search='.$free_search.'&'.'trap_type_filter='.$trap_type_filter.'&'.'priority_filter='.$priority_filter.'&'.'offset='.$offset; + $url_pagination = 'index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&free_search='.$free_search.'&trap_type_filter='.$trap_type_filter.'&priority_filter='.$priority_filter.'&offset='.$offset; } $where_sql = ''; - if (!empty($free_search)) { - switch ($config['dbtype']) { - case 'mysql': - case 'postgresql': - // $where_sql = ' 1 = 1'; - if ($trap_type_filter != SNMP_TRAP_TYPE_NONE) { - $where_sql .= ' AND `trap_type` = '.$trap_type_filter; - } - - if ($priority_filter != -1) { - $where_sql .= ' AND `priority` = '.$priority_filter; - } - - $where_sql .= " AND (`single_value` LIKE '%".$free_search."%' - OR `_snmp_f10_` LIKE '%".$free_search."%' - OR `_snmp_f9_` LIKE '%".$free_search."%' - OR `_snmp_f8_` LIKE '%".$free_search."%' - OR `_snmp_f7_` LIKE '%".$free_search."%' - OR `_snmp_f6_` LIKE '%".$free_search."%' - OR `_snmp_f5_` LIKE '%".$free_search."%' - OR `_snmp_f4_` LIKE '%".$free_search."%' - OR `_snmp_f3_` LIKE '%".$free_search."%' - OR `_snmp_f2_` LIKE '%".$free_search."%' - OR `_snmp_f1_` LIKE '%".$free_search."%' - OR `oid` LIKE '%".$free_search."%' - OR `custom_oid` LIKE '%".$free_search."%' - OR `agent` LIKE '%".$free_search."%' - OR `description` LIKE '%".$free_search."%')"; - break; - - case 'oracle': - // $where_sql = ' 1 = 1'; - if ($trap_type_filter != SNMP_TRAP_TYPE_NONE) { - $where_sql .= ' AND trap_type = '.$trap_type_filter; - } - - if ($priority_filter != -1) { - $where_sql .= ' AND priority = '.$priority_filter; - } - - $where_sql .= " AND (single_value LIKE '%".$free_search."%' - OR \"_snmp_f10_\" LIKE '%".$free_search."%' - OR \"_snmp_f9_\" LIKE '%".$free_search."%' - OR \"_snmp_f8_\" LIKE '%".$free_search."%' - OR \"_snmp_f7_\" LIKE '%".$free_search."%' - OR \"_snmp_f6_\" LIKE '%".$free_search."%' - OR \"_snmp_f5_\" LIKE '%".$free_search."%' - OR \"_snmp_f4_\" LIKE '%".$free_search."%' - OR \"_snmp_f3_\" LIKE '%".$free_search."%' - OR \"_snmp_f2_\" LIKE '%".$free_search."%' - OR \"_snmp_f1_\" LIKE '%".$free_search."%' - OR oid LIKE '%".$free_search."%' - OR custom_oid LIKE '%".$free_search."%' - OR agent LIKE '%".$free_search."%' - OR description LIKE '%".$free_search."%')"; - break; + if (empty($free_search) === false) { + if ($trap_type_filter != SNMP_TRAP_TYPE_NONE) { + $where_sql .= ' AND `trap_type` = '.$trap_type_filter; } + + if ($priority_filter != -1) { + $where_sql .= ' AND `priority` = '.$priority_filter; + } + + $where_sql .= " AND (`single_value` LIKE '%".$free_search."%' + OR `_snmp_f10_` LIKE '%".$free_search."%' + OR `_snmp_f9_` LIKE '%".$free_search."%' + OR `_snmp_f8_` LIKE '%".$free_search."%' + OR `_snmp_f7_` LIKE '%".$free_search."%' + OR `_snmp_f6_` LIKE '%".$free_search."%' + OR `_snmp_f5_` LIKE '%".$free_search."%' + OR `_snmp_f4_` LIKE '%".$free_search."%' + OR `_snmp_f3_` LIKE '%".$free_search."%' + OR `_snmp_f2_` LIKE '%".$free_search."%' + OR `_snmp_f1_` LIKE '%".$free_search."%' + OR `oid` LIKE '%".$free_search."%' + OR `custom_oid` LIKE '%".$free_search."%' + OR `agent` LIKE '%".$free_search."%' + OR `description` LIKE '%".$free_search."%')"; } - $count = db_get_value_sql( - "SELECT COUNT(*) - FROM talert_snmp WHERE id_group IN ($str_user_groups) ".$where_sql + $count = (int) db_get_value_sql( + 'SELECT COUNT(*) + FROM talert_snmp WHERE id_group IN ('.$str_user_groups.') '.$where_sql ); $result = []; - // Overview - if ($count == 0) { + // Overview. + if ($count === 0) { $result = []; ui_print_info_message(['no_close' => true, 'message' => __('There are no SNMP alerts') ]); } else { ui_pagination($count, $url_pagination); - switch ($config['dbtype']) { - case 'mysql': - case 'postgresql': - $where_sql .= ' LIMIT '.$limit.' OFFSET '.$offset; - $result = db_get_all_rows_sql( - "SELECT * - FROM talert_snmp - WHERE id_group IN ($str_user_groups) ".$where_sql - ); - break; - case 'oracle': - $sql = "SELECT * - FROM talert_snmp - WHERE id_group IN ($str_user_groups) ".$where_sql; - $set = []; - if (isset($offset) && isset($limit)) { - $set['limit'] = $limit; - $set['offset'] = $offset; - } - - $result = oracle_recode_query($sql, $set, 'AND', false); - break; - } + $where_sql .= ' LIMIT '.$limit.' OFFSET '.$offset; + $result = db_get_all_rows_sql( + 'SELECT * + FROM talert_snmp + WHERE id_group IN ('.$str_user_groups.') '.$where_sql + ); } $table = new stdClass(); @@ -1250,7 +1287,7 @@ if ($create_alert || $update_alert) { $data = []; $data[0] = $row['position']; - $url = 'index.php?'.'sec=snmpconsole&'.'sec2=godmode/snmpconsole/snmp_alert&'.'id_alert_snmp='.$row['id_as'].'&'.'update_alert=1'; + $url = 'index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&id_alert_snmp='.$row['id_as'].'&update_alert=1'; $data[1] = ''; $data[1] .= ''; @@ -1281,50 +1318,86 @@ if ($create_alert || $update_alert) { } $data[1] .= '
'; - - $data[2] = $row['agent']; $data[3] = $row['oid']; $data[4] = $row['custom_oid']; $data[5] = $row['description']; $data[6] = $row['times_fired']; - if (($row['last_fired'] != '1970-01-01 00:00:00') and ($row['last_fired'] != '01-01-1970 00:00:00')) { + if (($row['last_fired'] !== '1970-01-01 00:00:00') && ($row['last_fired'] !== '01-01-1970 00:00:00')) { $data[7] = ui_print_timestamp($row['last_fired'], true); } else { $data[7] = __('Never'); } - if (check_acl_restricted_all($config['id_user'], $row['id_group'], 'LW')) { - $data[8] = ''.html_print_image( - 'images/copy.png', - true, - [ - 'alt' => __('Duplicate'), - 'title' => __('Duplicate'), - ] - ).''.''.html_print_image( - 'images/config.png', - true, - [ - 'border' => '0', - 'alt' => __('Update'), - ] - ).''.''.html_print_image( - 'images/add.png', - true, - [ - 'title' => __('Add action'), - ] - ).''.''.html_print_image( - 'images/cross.png', - true, - [ - 'border' => '0', - 'alt' => __('Delete'), - ] - ).''; + $data[8] = ''; + $data[9] = ''; + if ((bool) check_acl_restricted_all($config['id_user'], $row['id_group'], 'LW') === true) { + $data[8] = html_print_anchor( + [ + 'href' => sprintf( + 'index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&duplicate_alert=1&id_alert_snmp=%s', + $row['id_as'] + ), + 'content' => html_print_image( + 'images/copy.png', + true, + [ + 'alt' => __('Duplicate'), + 'title' => __('Duplicate'), + ] + ), + ], + true + ); + $data[8] .= html_print_anchor( + [ + 'href' => sprintf( + 'index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&update_alert=1&id_alert_snmp=%s', + $row['id_as'] + ), + 'content' => html_print_image( + 'images/config.png', + true, + [ + 'alt' => __('Update'), + 'border' => 0, + ] + ), + ], + true + ); + $data[8] .= html_print_anchor( + [ + 'href' => sprintf( + 'javascript:show_add_action_snmp(\'%s\');"', + $row['id_as'] + ), + 'content' => html_print_image( + 'images/add.png', + true, + [ + 'title' => __('Add action'), + ] + ), + ], + true + ); + $data[8] .= html_print_anchor( + [ + 'href' => 'javascript: ', + 'content' => html_print_image( + 'images/cross.png', + true, + [ + 'title' => __('Delete action'), + ] + ), + 'onClick' => 'delete_snmp_alert('.$row['id_as'].')', + ], + true + ); $data[9] = html_print_checkbox_extended( 'delete_ids[]', @@ -1335,71 +1408,47 @@ if ($create_alert || $update_alert) { 'class="chk_delete"', true ); - } else { - $data[8] = ''; - $data[9] = ''; } $idx = count($table->data); - // The current index of the table is 1 less than the count of table data so we count before adding to table->data + // The current index of the table is 1 less than the count of table data so we count before adding to table->data. array_push($table->data, $data); $table->rowclass[$idx] = get_priority_class($row['priority']); } - // DIALOG ADD MORE ACTIONS + // DIALOG ADD MORE ACTIONS. echo '