From 3dc57f8a8ce732305fc2ac606cfe28770fd40ad0 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 6 Apr 2022 14:29:24 +0200 Subject: [PATCH 001/126] 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 ab9557c681c329cc741e36bf7dc3a0f594583d36 Mon Sep 17 00:00:00 2001
From: "alejandro.campos@artica.es" 
Date: Thu, 21 Apr 2022 18:09:26 +0200
Subject: [PATCH 002/126] 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 1a8a90a82f464490cd8c30b9d51347c36325d5ac Mon Sep 17 00:00:00 2001
From: Rafael 
Date: Mon, 25 Apr 2022 20:22:42 +0200
Subject: [PATCH 003/126] 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 5c029effdb47dadd83015540979c6fe7f74f29e1 Mon Sep 17 00:00:00 2001
From: "alejandro.campos@artica.es" 
Date: Thu, 28 Apr 2022 11:51:48 +0200
Subject: [PATCH 004/126] 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 9fd4e415c0f1911d579bb5e0d8d2057d843b4f60 Mon Sep 17 00:00:00 2001
From: Daniel Maya 
Date: Tue, 3 May 2022 10:02:39 +0200
Subject: [PATCH 005/126] #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 e685cf729473fafd334283af2342be28d1442d44 Mon Sep 17 00:00:00 2001
From: Calvo 
Date: Wed, 4 May 2022 18:42:56 +0200
Subject: [PATCH 006/126] 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 007/126] 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 008/126] #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 009/126] 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 010/126] 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 5c789125f2b561017a7fab325da91764eb8cf462 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Mon, 9 May 2022 12:40:36 +0200 Subject: [PATCH 011/126] 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 15d92d5cd6c8ecfac04dfaf645f5dc215386d151 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Wed, 11 May 2022 13:51:16 +0200 Subject: [PATCH 012/126] #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 013/126] 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 014/126] 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 015/126] 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 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 016/126] 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 017/126] 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 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 018/126] 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 '