Merge branch 'ent-7184-duplicate-web-server-module' into 'develop'

Ent 7184 duplicate web server module

Closes pandora_enterprise#7184

See merge request artica/pandorafms!3978
This commit is contained in:
Daniel Rodriguez 2021-05-10 09:08:09 +00:00
commit d878fdfdb8
2 changed files with 66 additions and 45 deletions

View File

@ -1,22 +1,32 @@
<?php <?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2021 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 Lesser General Public License
// as published by the Free Software Foundation; 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
// GNU General Public License for more details.
/** /**
* @package Include * Functions for modules.
* @subpackage Modules *
* @category Functions script.
* @package Pandora FMS
* @subpackage Modules.
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2021 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 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
* GNU General Public License for more details.
* ============================================================================
*/ */
// Begin.
require_once $config['homedir'].'/include/functions_agents.php'; require_once $config['homedir'].'/include/functions_agents.php';
require_once $config['homedir'].'/include/functions_users.php'; require_once $config['homedir'].'/include/functions_users.php';
require_once $config['homedir'].'/include/functions_tags.php'; require_once $config['homedir'].'/include/functions_tags.php';
@ -567,7 +577,7 @@ function modules_update_agent_module(
* Creates a module in an agent. * Creates a module in an agent.
* *
* @param integer $id_agent Agent id. * @param integer $id_agent Agent id.
* @param integer $name Module name id. * @param string $name Module name id.
* @param array $values Extra values for the module. * @param array $values Extra values for the module.
* @param boolean $disableACL Disable the ACL checking, for default false. * @param boolean $disableACL Disable the ACL checking, for default false.
* @param mixed $tags Array with tag's ids or false. * @param mixed $tags Array with tag's ids or false.
@ -575,35 +585,36 @@ function modules_update_agent_module(
* @return New module id if the module was created. False if not. * @return New module id if the module was created. False if not.
*/ */
function modules_create_agent_module( function modules_create_agent_module(
$id_agent, int $id_agent,
$name, string $name,
$values=false, array $values=[],
$disableACL=false, bool $disableACL=false,
$tags=false $tags=false
) { ) {
global $config; global $config;
if (!$disableACL) { if ((bool) $disableACL === false) {
if (!users_is_admin() && (empty($id_agent) if ((bool) users_is_admin() === false
|| !users_access_to_agent($id_agent, 'AW')) && (empty($id_agent) === true
|| users_access_to_agent($id_agent, 'AW') === false)
) { ) {
return false; return false;
} }
} }
if (empty($name)) { if (empty($name) === true) {
return ERR_INCOMPLETE; return ERR_INCOMPLETE;
} }
// Check for non valid characters in module name. // Check for non valid characters in module name.
if (mb_ereg_match('[\xc2\xa1\xc2\xbf\xc3\xb7\xc2\xba\xc2\xaa]', io_safe_output($name)) !== false) { if (mb_ereg_match(
'[\xc2\xa1\xc2\xbf\xc3\xb7\xc2\xba\xc2\xaa]',
io_safe_output($name)
) !== false
) {
return ERR_GENERIC; return ERR_GENERIC;
} }
if (! is_array($values)) {
$values = [];
}
$values['nombre'] = $name; $values['nombre'] = $name;
$values['id_agente'] = (int) $id_agent; $values['id_agente'] = (int) $id_agent;
@ -616,29 +627,39 @@ function modules_create_agent_module(
] ]
); );
if ($exists) { if ($exists === true) {
return ERR_EXIST; return ERR_EXIST;
} }
// Encrypt passwords. // Encrypt passwords.
if (isset($values['plugin_pass'])) { if (isset($values['plugin_pass']) === true) {
// Avoid two times encryption // Avoid two times encryption.
$plugin_pass = io_safe_output($values['plugin_pass']); $plugin_pass = io_safe_output($values['plugin_pass']);
$values['plugin_pass'] = io_input_password($plugin_pass); $values['plugin_pass'] = io_input_password($plugin_pass);
} }
// Encrypt SNMPv3 passwords. // Encrypt SNMPv3 passwords.
if (isset($values['id_tipo_modulo']) && ($values['id_tipo_modulo'] >= 15 if (isset($values['id_tipo_modulo']) === true
&& $values['id_tipo_modulo'] <= 18) && ((int) $values['id_tipo_modulo'] >= MODULE_TYPE_REMOTE_SNMP
&& isset($values['tcp_send']) && ($values['tcp_send'] == 3) && (int) $values['id_tipo_modulo'] <= MODULE_TYPE_REMOTE_SNMP_PROC)
&& isset($values['custom_string_2']) && isset($values['tcp_send']) === true
&& ((int) $values['tcp_send'] === 3)
&& isset($values['custom_string_2']) === true
) { ) {
$values['custom_string_2'] = io_input_password( $values['custom_string_2'] = io_input_password(
$values['custom_string_2'] $values['custom_string_2']
); );
} }
// Only for Web server modules.
if (isset($values['id_tipo_modulo']) === true
&& ($values['id_tipo_modulo'] >= MODULE_TYPE_WEB_ANALYSIS
&& $values['id_tipo_modulo'] <= MODULE_TYPE_WEB_CONTENT_STRING)
) {
$values['debug_content'] = io_safe_input($values['debug_content']);
}
$id_agent_module = db_process_sql_insert('tagente_modulo', $values); $id_agent_module = db_process_sql_insert('tagente_modulo', $values);
if ($id_agent_module === false) { if ($id_agent_module === false) {
@ -646,7 +667,7 @@ function modules_create_agent_module(
} }
$return_tag = true; $return_tag = true;
if (($tags !== false) || (empty($tags))) { if (($tags !== false) || (empty($tags) === true)) {
$return_tag = tags_insert_module_tag($id_agent_module, $tags); $return_tag = tags_insert_module_tag($id_agent_module, $tags);
} }
@ -659,10 +680,10 @@ function modules_create_agent_module(
return ERR_DB; return ERR_DB;
} }
if (isset($values['id_tipo_modulo']) if (isset($values['id_tipo_modulo']) === true
&& ($values['id_tipo_modulo'] == 21 && ((int) $values['id_tipo_modulo'] === MODULE_TYPE_ASYNC_PROC
|| $values['id_tipo_modulo'] == 22 || (int) $values['id_tipo_modulo'] === MODULE_TYPE_ASYNC_DATA
|| $values['id_tipo_modulo'] == 23) || (int) $values['id_tipo_modulo'] === MODULE_TYPE_ASYNC_STRING)
) { ) {
// Async modules start in normal status. // Async modules start in normal status.
$status = AGENT_MODULE_STATUS_NORMAL; $status = AGENT_MODULE_STATUS_NORMAL;
@ -706,8 +727,8 @@ function modules_create_agent_module(
} }
// Update module status count if the module is not created disabled. // Update module status count if the module is not created disabled.
if ((!isset($values['disabled']) || $values['disabled'] == 0) && $values['id_modulo'] > 0) { if (isset($values['disabled']) === false || (int) $values['disabled'] === 0) {
if ($status == 0) { if ((int) $status === AGENT_MODULE_STATUS_NORMAL) {
db_process_sql( db_process_sql(
'UPDATE tagente 'UPDATE tagente
SET total_count=total_count+1, normal_count=normal_count+1 SET total_count=total_count+1, normal_count=normal_count+1
@ -2362,7 +2383,7 @@ function modules_get_agentmodule_data_for_humans($module)
} }
} else { } else {
$data_macro = modules_get_unit_macro($module['datos'], $module['unit']); $data_macro = modules_get_unit_macro($module['datos'], $module['unit']);
if ($data_macro) { if ($data_macro !== false) {
$salida = $data_macro; $salida = $data_macro;
} else { } else {
$salida = ui_print_module_string_value( $salida = ui_print_module_string_value(