Merge branch 'ent-6099-bug-al-duplicar-modulo' into 'develop'

resolved error with duplucated modules

See merge request artica/pandorafms!3357
This commit is contained in:
Daniel Rodriguez 2020-08-07 09:42:08 +02:00
commit ef73e7a73c
1 changed files with 235 additions and 65 deletions

View File

@ -24,7 +24,16 @@ require_once $config['homedir'].'/include/functions_modules.php';
require_once $config['homedir'].'/include/functions_agents.php';
require_once $config['homedir'].'/include/functions_servers.php';
$search_string = io_safe_output(urldecode(trim(get_parameter('search_string', ''))));
$search_string = io_safe_output(
urldecode(
trim(
get_parameter(
'search_string',
''
)
)
)
);
global $policy_page;
@ -32,17 +41,27 @@ if (!isset($policy_page)) {
$policy_page = false;
}
// Search string filter form
echo '<form id="create_module_type" method="post" action="'.$url.'">';
echo '<table width="100%" cellpadding="2" cellspacing="2" class="databox filters" >';
echo "<tr><td class='datos' style='width:20%; font-weight: bold;'>";
echo __('Search').' '.html_print_input_text(
'search_string',
$search_string,
'',
15,
255,
true
);
html_print_input_hidden('search', 1);
// Search string filter form.
if (($policy_page) || (isset($agent))) {
echo '<form id="" method="post" action="">';
} else {
echo '<form id="create_module_type" method="post" action="'.$url.'">';
}
echo '<table width="100%" cellpadding="2" cellspacing="2" class="databox filters" >';
echo "<tr><td class='datos' style='width:20%; font-weight: bold;'>";
echo __('Search').' '.html_print_input_text('search_string', $search_string, '', 15, 255, true);
html_print_input_hidden('search', 1);
echo '</td>';
echo "<td class='datos' style='width:10%'>";
html_print_submit_button(__('Filter'), 'filter', false, 'class="sub search"');
@ -50,38 +69,38 @@ echo '</td>';
echo "<td class='datos' style='width:10%'></td>";
echo '</form>';
// Check if there is at least one server of each type available to assign that
// kind of modules. If not, do not show server type in combo
// kind of modules. If not, do not show server type in combo.
$network_available = db_get_sql(
'SELECT count(*)
FROM tserver
WHERE server_type = 1'
);
// POSTGRESQL AND ORACLE COMPATIBLE
// POSTGRESQL AND ORACLE COMPATIBLE.
$wmi_available = db_get_sql(
'SELECT count(*)
FROM tserver
WHERE server_type = 6'
);
// POSTGRESQL AND ORACLE COMPATIBLE
// POSTGRESQL AND ORACLE COMPATIBLE.
$plugin_available = db_get_sql(
'SELECT count(*)
FROM tserver
WHERE server_type = 4'
);
// POSTGRESQL AND ORACLE COMPATIBLE
// POSTGRESQL AND ORACLE COMPATIBLE.
$prediction_available = db_get_sql(
'SELECT count(*)
FROM tserver
WHERE server_type = 5'
);
// POSTGRESQL AND ORACLE COMPATIBLE
// Development mode to use all servers
// POSTGRESQL AND ORACLE COMPATIBLE.
// Development mode to use all servers.
if ($develop_bypass || is_metaconsole()) {
$network_available = 1;
$wmi_available = 1;
$plugin_available = 1;
// FIXME when prediction predictions server modules can be configured
// on metaconsole
// FIXME when prediction predictions server modules can be configured.
// on metaconsole.
$prediction_available = is_metaconsole() ? 0 : 1;
}
@ -140,7 +159,7 @@ if (($policy_page) || (isset($agent))) {
}
if ($show_creation) {
// Create module/type combo
// Create module/type combo.
echo '<form id="create_module_type" method="post" action="'.$url.'">';
if (!$policy_page) {
echo '<td class="datos" style="font-weight: bold; width:20%;">';
@ -151,13 +170,33 @@ if (($policy_page) || (isset($agent))) {
$checked = false;
}
html_print_checkbox('status_hierachy_mode', '', $checked, false, false, 'onChange=change_mod_filter();');
html_print_checkbox(
'status_hierachy_mode',
'',
$checked,
false,
false,
'onChange=change_mod_filter();'
);
echo '</td>';
}
echo '<td class="datos" style="font-weight: bold; width:20%;">';
echo __('<p>Type</p>');
html_print_select($modules, 'moduletype', '', '', '', '', false, false, false, '', false, 'max-width:300px;');
html_print_select(
$modules,
'moduletype',
'',
'',
'',
'',
false,
false,
false,
'',
false,
'max-width:300px;'
);
html_print_input_hidden('edit_module', 1);
echo '</td>';
echo '<td class="datos" style="width:10%;">';
@ -212,7 +251,13 @@ if ($multiple_delete) {
}
enterprise_include_once('include/functions_config_agents.php');
enterprise_hook('config_agents_delete_module_in_conf', [modules_get_agentmodule_agent($id_agent_module_del), modules_get_agentmodule_name($id_agent_module_del)]);
enterprise_hook(
'config_agents_delete_module_in_conf',
[
modules_get_agentmodule_agent($id_agent_module_del),
modules_get_agentmodule_name($id_agent_module_del),
]
);
$error = 0;
@ -220,7 +265,12 @@ if ($multiple_delete) {
// error. NOTICE that we don't delete all data here, just marking for deletion
// and delete some simple data.
$status = '';
$agent_id_of_module = db_get_value('id_agente', 'tagente_modulo', 'id_agente_modulo', (int) $id_agent_module_del);
$agent_id_of_module = db_get_value(
'id_agente',
'tagente_modulo',
'id_agente_modulo',
(int) $id_agent_module_del
);
if (db_process_sql(
"UPDATE tagente_modulo
@ -235,7 +285,7 @@ if ($multiple_delete) {
) {
$error++;
} else {
// Set flag to update module status count
// Set flag to update module status count.
if ($agent_id_of_module !== false) {
db_process_sql(
'UPDATE tagente
@ -286,32 +336,48 @@ if ($multiple_delete) {
break;
}
// Trick to detect if we are deleting a synthetic module (avg or arithmetic)
// If result is empty then module doesn't have this type of submodules
$ops_json = enterprise_hook('modules_get_synthetic_operations', [$id_agent_module_del]);
// Trick to detect if we are deleting a synthetic module (avg or arithmetic).
// If result is empty then module doesn't have this type of submodules.
$ops_json = enterprise_hook(
'modules_get_synthetic_operations',
[$id_agent_module_del]
);
$result_ops_synthetic = json_decode($ops_json);
if (!empty($result_ops_synthetic)) {
$result = enterprise_hook('modules_delete_synthetic_operations', [$id_agent_module_del]);
$result = enterprise_hook(
'modules_delete_synthetic_operations',
[$id_agent_module_del]
);
if ($result === false) {
$error++;
}
} //end if
else {
$result_components = enterprise_hook('modules_get_synthetic_components', [$id_agent_module_del]);
} else {
$result_components = enterprise_hook(
'modules_get_synthetic_components',
[$id_agent_module_del]
);
$count_components = 1;
if (!empty($result_components)) {
// Get number of components pending to delete to know when it's needed to update orders
// Get number of components pending to delete to know when it's needed to update orders.
$num_components = count($result_components);
$last_target_module = 0;
foreach ($result_components as $id_target_module) {
// Detects change of component or last component to update orders
if (($count_components == $num_components) or ($last_target_module != $id_target_module)) {
// Detects change of component or last component to update orders.
if (($count_components == $num_components) || ($last_target_module != $id_target_module)
) {
$update_orders = true;
} else {
$update_orders = false;
}
$result = enterprise_hook('modules_delete_synthetic_operations', [$id_target_module, $id_agent_module_del, $update_orders]);
$result = enterprise_hook(
'modules_delete_synthetic_operations',
[
$id_target_module,
$id_agent_module_del,
$update_orders,
]
);
if ($result === false) {
$error++;
}
@ -323,7 +389,7 @@ if ($multiple_delete) {
}
// Check for errors
// Check for errors.
if ($error != 0) {
} else {
$count_correct_delete_modules++;
@ -509,7 +575,7 @@ switch ($sortField) {
}
// Build the order sql
// Build the order sql.
if (!empty($order)) {
$order_sql = ' ORDER BY ';
}
@ -525,7 +591,7 @@ foreach ($order as $ord) {
$order_sql .= $ord['field'].' '.$ord['order'];
}
// Get limit and offset parameters
// Get limit and offset parameters.
$limit = (int) $config['block_size'];
$offset = (int) get_parameter('offset');
@ -559,9 +625,15 @@ $where = sprintf('delete_pending = 0 AND id_agente = %s', $id_agente);
$search_string_entities = io_safe_input($search_string);
$basic_where = sprintf("(nombre LIKE '%%%s%%' OR nombre LIKE '%%%s%%' OR descripcion LIKE '%%%s%%' OR descripcion LIKE '%%%s%%') AND", $search_string, $search_string_entities, $search_string, $search_string_entities);
$basic_where = sprintf(
"(nombre LIKE '%%%s%%' OR nombre LIKE '%%%s%%' OR descripcion LIKE '%%%s%%' OR descripcion LIKE '%%%s%%') AND",
$search_string,
$search_string_entities,
$search_string,
$search_string_entities
);
// Tags acl
// Tags acl.
$agent_tags = tags_get_user_applied_agent_tags($id_agente);
if ($agent_tags !== true) {
$where_tags = ' AND ttag_module.id_tag IN ('.implode(',', $agent_tags).')';
@ -619,7 +691,7 @@ if ($modules === false) {
return;
}
// Prepare pagination
// Prepare pagination.
$url = '?'.'sec=gagente&'.'tab=module&'.'sec2=godmode/agentes/configurar_agente&'.'id_agente='.$id_agente.'&'.'sort_field='.$sortField.'&'.'&sort='.$sort.'&'.'search_string='.urlencode($search_string);
if ($paginate_module) {
@ -635,17 +707,48 @@ $table = new stdClass();
$table->width = '100%';
$table->class = 'info_table';
$table->head = [];
$table->head['checkbox'] = html_print_checkbox('all_delete', 0, false, true, false);
$table->head[0] = __('Name').ui_get_sorting_arrows($url_name.'up', $url_name.'down', $selectNameUp, $selectNameDown);
$table->head['checkbox'] = html_print_checkbox(
'all_delete',
0,
false,
true,
false
);
$table->head[0] = __('Name').ui_get_sorting_arrows(
$url_name.'up',
$url_name.'down',
$selectNameUp,
$selectNameDown
);
// The access to the policy is granted only with AW permission
if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK && check_acl($config['id_user'], $agent['id_grupo'], 'AW')) {
// The access to the policy is granted only with AW permission.
if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK && check_acl(
$config['id_user'],
$agent['id_grupo'],
'AW'
)
) {
$table->head[1] = "<span title='".__('Policy')."'>".__('P.').'</span>';
}
$table->head[2] = "<span title='".__('Server')."'>".__('S.').'</span>'.ui_get_sorting_arrows($url_server.'up', $url_server.'down', $selectServerUp, $selectServerDown);
$table->head[3] = __('Type').ui_get_sorting_arrows($url_type.'up', $url_type.'down', $selectTypeUp, $selectTypeDown);
$table->head[4] = __('Interval').ui_get_sorting_arrows($url_interval.'up', $url_interval.'down', $selectIntervalUp, $selectIntervalDown);
$table->head[2] = "<span title='".__('Server')."'>".__('S.').'</span>'.ui_get_sorting_arrows(
$url_server.'up',
$url_server.'down',
$selectServerUp,
$selectServerDown
);
$table->head[3] = __('Type').ui_get_sorting_arrows(
$url_type.'up',
$url_type.'down',
$selectTypeUp,
$selectTypeDown
);
$table->head[4] = __('Interval').ui_get_sorting_arrows(
$url_interval.'up',
$url_interval.'down',
$selectIntervalUp,
$selectIntervalDown
);
$table->head[5] = __('Description');
$table->head[6] = __('Status');
$table->head[7] = __('Warn');
@ -690,7 +793,16 @@ if ($checked) {
}
foreach ($modules as $module) {
if (! check_acl_one_of_groups($config['id_user'], $all_groups, 'AW') && ! check_acl_one_of_groups($config['id_user'], $all_groups, 'AD')) {
if (! check_acl_one_of_groups(
$config['id_user'],
$all_groups,
'AW'
) && ! check_acl_one_of_groups(
$config['id_user'],
$all_groups,
'AD'
)
) {
continue;
}
@ -712,7 +824,9 @@ foreach ($modules as $module) {
if (!$checked) {
if ($module['id_module_group'] != $last_modulegroup) {
$last_modulegroup = $module['id_module_group'];
$data[0] = '<strong>'.modules_get_modulegroup_name($last_modulegroup).'</strong>';
$data[0] = '<strong>'.modules_get_modulegroup_name(
$last_modulegroup
).'</strong>';
$i = array_push($table->data, $data);
$table->rowstyle[($i - 1)] = 'text-align: center';
$table->rowclass[($i - 1)] = 'datos3';
@ -727,14 +841,23 @@ foreach ($modules as $module) {
}
if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) {
$data['checkbox'] = html_print_checkbox('id_delete[]', $module['id_agente_modulo'], false, true);
$data['checkbox'] = html_print_checkbox(
'id_delete[]',
$module['id_agente_modulo'],
false,
true
);
}
$data[0] = '';
if (isset($module['deep']) && ($module['deep'] != 0)) {
$data[0] .= str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $module['deep']);
$data[0] .= html_print_image('images/icono_escuadra.png', true, ['style' => 'padding-bottom: inherit;']).'&nbsp;&nbsp;';
$data[0] .= html_print_image(
'images/icono_escuadra.png',
true,
['style' => 'padding-bottom: inherit;']
).'&nbsp;&nbsp;';
}
if ($module['quiet']) {
@ -754,17 +877,38 @@ foreach ($modules as $module) {
}
if ($module['disabled']) {
$data[0] .= '<em class="disabled_module">'.ui_print_truncate_text($module['nombre'], 'module_medium', false, true, true, '[&hellip;]', 'font-size: 7.2pt').'</em>';
$data[0] .= '<em class="disabled_module">'.ui_print_truncate_text(
$module['nombre'],
'module_medium',
false,
true,
true,
'[&hellip;]',
'font-size: 7.2pt'
).'</em>';
} else {
$data[0] .= ui_print_truncate_text($module['nombre'], 'module_medium', false, true, true, '[&hellip;]', 'font-size: 7.2pt');
$data[0] .= ui_print_truncate_text(
$module['nombre'],
'module_medium',
false,
true,
true,
'[&hellip;]',
'font-size: 7.2pt'
);
}
if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) {
$data[0] .= '</a>';
}
// The access to the policy is granted only with AW permission
if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK && check_acl($config['id_user'], $agent['id_grupo'], 'AW')) {
// The access to the policy is granted only with AW permission.
if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK && check_acl(
$config['id_user'],
$agent['id_grupo'],
'AW'
)
) {
$policyInfo = policies_info_module_policy($module['id_agente_modulo']);
if ($policyInfo === false) {
$data[1] = '';
@ -798,17 +942,27 @@ foreach ($modules as $module) {
}
}
// Module type (by server type )
// Module type (by server type ).
$data[2] = '';
if ($module['id_modulo'] > 0) {
$data[2] = servers_show_type($module['id_modulo']);
}
$module_status = db_get_row('tagente_estado', 'id_agente_modulo', $module['id_agente_modulo']);
$module_status = db_get_row(
'tagente_estado',
'id_agente_modulo',
$module['id_agente_modulo']
);
modules_get_status($module['id_agente_modulo'], $module_status['estado'], $module_status['datos'], $status, $title);
modules_get_status(
$module['id_agente_modulo'],
$module_status['estado'],
$module_status['datos'],
$status,
$title
);
// This module is initialized ? (has real data)
// This module is initialized ? (has real data).
if ($status == STATUS_MODULE_NO_DATA) {
$data[2] .= html_print_image(
'images/error.png',
@ -817,13 +971,13 @@ foreach ($modules as $module) {
);
}
// Module type (by data type)
// Module type (by data type).
$data[3] = '';
if ($type) {
$data[3] = ui_print_moduletype_icon($type, true);
}
// Module interval
// Module interval.
if ($module['module_interval']) {
$data[4] = human_time_description_raw($module['module_interval']);
} else {
@ -831,12 +985,23 @@ foreach ($modules as $module) {
}
if ($module['id_modulo'] == MODULE_DATA && $module['id_policy_module'] != 0) {
$data[4] .= ui_print_help_tip(__('The policy modules of data type will only update their intervals when policy is applied.'), true);
$data[4] .= ui_print_help_tip(
__('The policy modules of data type will only update their intervals when policy is applied.'),
true
);
}
$data[5] = ui_print_truncate_text($module['descripcion'], 'description', false);
$data[5] = ui_print_truncate_text(
$module['descripcion'],
'description',
false
);
$data[6] = ui_print_status_image($status, htmlspecialchars($title), true);
$data[6] = ui_print_status_image(
$status,
htmlspecialchars($title),
true
);
// MAX / MIN values.
if ($module['id_tipo_modulo'] != 25) {
@ -884,7 +1049,7 @@ foreach ($modules as $module) {
);
$data[8] .= '</a> ';
// Make a data normalization
// Make a data normalization.
if (isset($numericModules[$type])) {
if ($numericModules[$type] === true) {
$data[8] .= '<a href="index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&id_agente='.$id_agente.'&tab=module&fix_module='.$module['id_agente_modulo'].'" onClick="if (!confirm(\' '.__('Are you sure?').'\')) return false;">';
@ -904,7 +1069,7 @@ foreach ($modules as $module) {
$data[8] .= '&nbsp;&nbsp;';
}
// create network component action
// Create network component action.
if ((is_user_admin($config['id_user']))
&& ($module['id_modulo'] == MODULE_NETWORK)
) {
@ -927,7 +1092,7 @@ foreach ($modules as $module) {
}
if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) {
// Delete module
// Delete module.
$data[9] = '<a href="index.php?sec=gagente&tab=module&sec2=godmode/agentes/configurar_agente&id_agente='.$id_agente.'&delete_module='.$module['id_agente_modulo'].'"
onClick="if (!confirm(\' '.__('Are you sure?').'\')) return false;">';
$data[9] .= html_print_image(
@ -959,7 +1124,12 @@ html_print_table($table);
if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW')) {
echo '<div class="action-buttons" style="width: '.$table->width.'">';
html_print_input_hidden('multiple_delete', 1);
html_print_submit_button(__('Delete'), 'multiple_delete', false, 'class="sub delete"');
html_print_submit_button(
__('Delete'),
'multiple_delete',
false,
'class="sub delete"'
);
echo '</div>';
echo '</form>';
}