mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-09-26 11:29:12 +02:00
#9021 Added offspring check
This commit is contained in:
parent
1e430f2f73
commit
79e7753cc8
@ -523,7 +523,6 @@ if (enterprise_installed()) {
|
|||||||
$table_adv_cascade .= $cps_html;
|
$table_adv_cascade .= $cps_html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$table_adv_parent = '<div class="label_select"><label class="input_label">'.__('Parent').'</label>';
|
$table_adv_parent = '<div class="label_select"><label class="input_label">'.__('Parent').'</label>';
|
||||||
$params = [];
|
$params = [];
|
||||||
$params['return'] = true;
|
$params['return'] = true;
|
||||||
@ -536,6 +535,11 @@ $params['value'] = db_get_value('alias', 'tagente', 'id_agente', $id_parent);
|
|||||||
$params['selectbox_id'] = 'cascade_protection_module';
|
$params['selectbox_id'] = 'cascade_protection_module';
|
||||||
$params['javascript_is_function_select'] = true;
|
$params['javascript_is_function_select'] = true;
|
||||||
$params['cascade_protection'] = true;
|
$params['cascade_protection'] = true;
|
||||||
|
if ($id_agente !== 0) {
|
||||||
|
// Deletes the agent's offspring.
|
||||||
|
$params['delete_offspring_agents'] = $id_agente;
|
||||||
|
}
|
||||||
|
|
||||||
$table_adv_parent .= '<div class="label_simple_items">';
|
$table_adv_parent .= '<div class="label_simple_items">';
|
||||||
$table_adv_parent .= ui_print_agent_autocomplete_input($params);
|
$table_adv_parent .= ui_print_agent_autocomplete_input($params);
|
||||||
if (enterprise_installed()) {
|
if (enterprise_installed()) {
|
||||||
|
@ -86,6 +86,8 @@ if ($search_agents && (!is_metaconsole() || $force_local)) {
|
|||||||
$addedItems = json_decode($addedItems);
|
$addedItems = json_decode($addedItems);
|
||||||
$all = (string) get_parameter('all', 'all');
|
$all = (string) get_parameter('all', 'all');
|
||||||
|
|
||||||
|
$delete_offspring_agents = (int) get_parameter('delete_offspring_agents', 0);
|
||||||
|
|
||||||
if ($addedItems != null) {
|
if ($addedItems != null) {
|
||||||
foreach ($addedItems as $item) {
|
foreach ($addedItems as $item) {
|
||||||
echo $item."|\n";
|
echo $item."|\n";
|
||||||
@ -111,21 +113,9 @@ if ($search_agents && (!is_metaconsole() || $force_local)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
// Get agents for only the alias
|
// Get agents for only the alias.
|
||||||
$filter_alias = $filter;
|
$filter_alias = $filter;
|
||||||
switch ($config['dbtype']) {
|
$filter_alias[] = '(UPPER(alias) LIKE "%'.$string.'%")';
|
||||||
case 'mysql':
|
|
||||||
$filter_alias[] = '(UPPER(alias) LIKE "%'.$string.'%")';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'postgresql':
|
|
||||||
$filter_alias[] = '(UPPER(alias) LIKE \'%'.$string.'%\')';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'oracle':
|
|
||||||
$filter_alias[] = '(UPPER(alias) LIKE UPPER(\'%'.$string.'%\'))';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$agents = agents_get_agents($filter_alias, ['id_agente', 'nombre', 'direccion', 'alias']);
|
$agents = agents_get_agents($filter_alias, ['id_agente', 'nombre', 'direccion', 'alias']);
|
||||||
if ($agents !== false) {
|
if ($agents !== false) {
|
||||||
@ -142,19 +132,7 @@ if ($search_agents && (!is_metaconsole() || $force_local)) {
|
|||||||
|
|
||||||
// Get agents for only the name.
|
// Get agents for only the name.
|
||||||
$filter_agents = $filter;
|
$filter_agents = $filter;
|
||||||
switch ($config['dbtype']) {
|
$filter_agents[] = '(UPPER(alias) NOT LIKE "%'.$string.'%" AND UPPER(nombre) LIKE "%'.$string.'%")';
|
||||||
case 'mysql':
|
|
||||||
$filter_agents[] = '(UPPER(alias) NOT LIKE "%'.$string.'%" AND UPPER(nombre) LIKE "%'.$string.'%")';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'postgresql':
|
|
||||||
$filter_agents[] = '(UPPER(alias) NOT LIKE \'%'.$string.'%\' AND UPPER(nombre) LIKE \'%'.$string.'%\')';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'oracle':
|
|
||||||
$filter_agents[] = '(UPPER(alias) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(nombre) LIKE UPPER(\'%'.$string.'%\'))';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$agents = agents_get_agents($filter_agents, ['id_agente', 'nombre', 'direccion', 'alias']);
|
$agents = agents_get_agents($filter_agents, ['id_agente', 'nombre', 'direccion', 'alias']);
|
||||||
if ($agents !== false) {
|
if ($agents !== false) {
|
||||||
@ -169,21 +147,9 @@ if ($search_agents && (!is_metaconsole() || $force_local)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get agents for only the address
|
// Get agents for only the address.
|
||||||
$filter_address = $filter;
|
$filter_address = $filter;
|
||||||
switch ($config['dbtype']) {
|
$filter_address[] = '(UPPER(alias) NOT LIKE "%'.$string.'%" AND UPPER(nombre) NOT LIKE "%'.$string.'%" AND UPPER(direccion) LIKE "%'.$string.'%")';
|
||||||
case 'mysql':
|
|
||||||
$filter_address[] = '(UPPER(alias) NOT LIKE "%'.$string.'%" AND UPPER(nombre) NOT LIKE "%'.$string.'%" AND UPPER(direccion) LIKE "%'.$string.'%")';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'postgresql':
|
|
||||||
$filter_address[] = '(UPPER(alias) NOT LIKE \'%'.$string.'%\' AND UPPER(nombre) NOT LIKE \'%'.$string.'%\' AND UPPER(direccion) LIKE \'%'.$string.'%\')';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'oracle':
|
|
||||||
$filter_address[] = '(UPPER(alias) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(nombre) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(direccion) LIKE UPPER(\'%'.$string.'%\'))';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$agents = agents_get_agents($filter_address, ['id_agente', 'nombre', 'direccion', 'alias']);
|
$agents = agents_get_agents($filter_address, ['id_agente', 'nombre', 'direccion', 'alias']);
|
||||||
if ($agents !== false) {
|
if ($agents !== false) {
|
||||||
@ -198,21 +164,9 @@ if ($search_agents && (!is_metaconsole() || $force_local)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get agents for only the description
|
// Get agents for only the description.
|
||||||
$filter_description = $filter;
|
$filter_description = $filter;
|
||||||
switch ($config['dbtype']) {
|
$filter_description[] = '(UPPER(alias) NOT LIKE "%'.$string.'%" AND UPPER(nombre) NOT LIKE "%'.$string.'%" AND UPPER(direccion) NOT LIKE "%'.$string.'%" AND UPPER(comentarios) LIKE "%'.$string.'%")';
|
||||||
case 'mysql':
|
|
||||||
$filter_description[] = '(UPPER(alias) NOT LIKE "%'.$string.'%" AND UPPER(nombre) NOT LIKE "%'.$string.'%" AND UPPER(direccion) NOT LIKE "%'.$string.'%" AND UPPER(comentarios) LIKE "%'.$string.'%")';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'postgresql':
|
|
||||||
$filter_description[] = '(UPPER(alias) NOT LIKE \'%'.$string.'%\' AND UPPER(nombre) NOT LIKE \'%'.$string.'%\' AND UPPER(direccion) NOT LIKE \'%'.$string.'%\' AND UPPER(comentarios) LIKE \'%'.$string.'%\')';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'oracle':
|
|
||||||
$filter_description[] = '(UPPER(alias) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(nombre) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(direccion) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(comentarios) LIKE UPPER(\'%'.$string.'%\'))';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$agents = agents_get_agents($filter_description, ['id_agente', 'nombre', 'direccion', 'alias']);
|
$agents = agents_get_agents($filter_description, ['id_agente', 'nombre', 'direccion', 'alias']);
|
||||||
if ($agents !== false) {
|
if ($agents !== false) {
|
||||||
@ -227,6 +181,18 @@ if ($search_agents && (!is_metaconsole() || $force_local)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (empty($data) === false && $delete_offspring_agents !== 0) {
|
||||||
|
// Gets offspring and deletes them, including himself.
|
||||||
|
$agents_offspring = agents_get_offspring($delete_offspring_agents);
|
||||||
|
if (empty($agents_offspring) === false) {
|
||||||
|
foreach ($data as $key => $value) {
|
||||||
|
if (isset($agents_offspring[$value['id']]) === true) {
|
||||||
|
unset($data[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
echo json_encode($data);
|
echo json_encode($data);
|
||||||
return;
|
return;
|
||||||
} else if ($search_agents && is_metaconsole()) {
|
} else if ($search_agents && is_metaconsole()) {
|
||||||
|
@ -4268,3 +4268,30 @@ function get_status_data_agent_modules($id_group, $agents=[], $modules=[])
|
|||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function agents_get_offspring(int $id_agent)
|
||||||
|
{
|
||||||
|
$return = [];
|
||||||
|
// Get parent.
|
||||||
|
$agents = db_get_all_rows_filter(
|
||||||
|
'tagente',
|
||||||
|
[
|
||||||
|
'id_parent' => $id_agent,
|
||||||
|
'disabled' => 0,
|
||||||
|
],
|
||||||
|
'id_agente'
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($agents !== false) {
|
||||||
|
foreach ($agents as $agent) {
|
||||||
|
if ((int) $agent['id_agente'] !== 0) {
|
||||||
|
$return += agents_get_offspring((int) $agent['id_agente']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$return += [$id_agent => 0];
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
@ -1469,22 +1469,22 @@ function api_set_update_agent($id_agent, $thrash2, $other, $thrash3)
|
|||||||
// Check parameters.
|
// Check parameters.
|
||||||
if ($idGroup == 0) {
|
if ($idGroup == 0) {
|
||||||
$agent_update_error = __('The agent could not be modified. For security reasons, use a group other than 0.');
|
$agent_update_error = __('The agent could not be modified. For security reasons, use a group other than 0.');
|
||||||
returnError('generic error', $agent_update_error);
|
returnError($agent_update_error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$server_name = db_get_value_sql('SELECT name FROM tserver WHERE BINARY name LIKE "'.$nameServer.'"');
|
$server_name = db_get_value_sql('SELECT name FROM tserver WHERE BINARY name LIKE "'.$nameServer.'"');
|
||||||
if ($alias == '' && $alias_as_name === 0) {
|
if ($alias == '' && $alias_as_name === 0) {
|
||||||
returnError('alias_not_specified', 'No agent alias specified');
|
returnError('No agent alias specified');
|
||||||
return;
|
return;
|
||||||
} else if (db_get_value_sql('SELECT id_grupo FROM tgrupo WHERE id_grupo = '.$idGroup) === false) {
|
} else if (db_get_value_sql('SELECT id_grupo FROM tgrupo WHERE id_grupo = '.$idGroup) === false) {
|
||||||
returnError('id_grupo_not_exist', 'The group doesn`t exist.');
|
returnError('The group doesn`t exist.');
|
||||||
return;
|
return;
|
||||||
} else if (db_get_value_sql('SELECT id_os FROM tconfig_os WHERE id_os = '.$idOS) === false) {
|
} else if (db_get_value_sql('SELECT id_os FROM tconfig_os WHERE id_os = '.$idOS) === false) {
|
||||||
returnError('id_os_not_exist', 'The OS doesn`t exist.');
|
returnError('The OS doesn`t exist.');
|
||||||
return;
|
return;
|
||||||
} else if ($server_name === false) {
|
} else if ($server_name === false) {
|
||||||
returnError('server_not_exist', 'The '.get_product_name().' Server doesn`t exist.');
|
returnError('The '.get_product_name().' Server doesn`t exist.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1525,6 +1525,14 @@ function api_set_update_agent($id_agent, $thrash2, $other, $thrash3)
|
|||||||
returnError('The user cannot access to parent agent.');
|
returnError('The user cannot access to parent agent.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$agents_offspring = agents_get_offspring($id_agent);
|
||||||
|
if (empty($agents_offspring) === false) {
|
||||||
|
if (isset($agents_offspring[$idParent]) === true) {
|
||||||
|
returnError('The parent cannot be a offspring');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$values_old = db_get_row_filter(
|
$values_old = db_get_row_filter(
|
||||||
@ -1751,6 +1759,14 @@ function api_set_update_agent_field($id_agent, $use_agent_alias, $params)
|
|||||||
returnError('The user cannot access to parent agent.');
|
returnError('The user cannot access to parent agent.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$agents_offspring = agents_get_offspring($id_agent);
|
||||||
|
if (empty($agents_offspring) === false) {
|
||||||
|
if (isset($agents_offspring[$data]) === true) {
|
||||||
|
returnError('The parent cannot be a offspring');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -5448,6 +5448,10 @@ function ui_print_agent_autocomplete_input($parameters)
|
|||||||
'q' => 'term',
|
'q' => 'term',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (isset($parameters['delete_offspring_agents']) === true) {
|
||||||
|
$javascript_change_ajax_params_original['delete_offspring_agents'] = $parameters['delete_offspring_agents'];
|
||||||
|
}
|
||||||
|
|
||||||
if (!$metaconsole_enabled) {
|
if (!$metaconsole_enabled) {
|
||||||
$javascript_change_ajax_params_original['force_local'] = 1;
|
$javascript_change_ajax_params_original['force_local'] = 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user