Merge branch '1744-Opción-para-validar-que-la-ip-de-un-agente-sea-unica' into 'develop'

Added option in setup for unique main IP in agents - #1744

Closes pandora_enterprise#1744

See merge request artica/pandorafms!2114

Former-commit-id: 77e1bbae9a1a60bc51739d98948ca8af5d183f78
This commit is contained in:
Alejandro Fraguas 2019-02-18 12:16:20 +01:00
commit 01b8649812
4 changed files with 34 additions and 3 deletions

View File

@ -236,7 +236,7 @@ if ($new_agent) {
}
$table->data[2][0] = __('IP Address');
$table->data[2][1] = html_print_input_text('direccion', $direccion_agente, '', 16, 100, true);
$table->data[2][1] = html_print_input_text('direccion', $direccion_agente, '', 16, 100, true).html_print_checkbox('unique_ip', 1, $config['unique_ip'], true).__('Unique IP').ui_print_help_tip(__('Set the primary IP address as the unique IP, preventing the same primary IP address from being used in more than one agent'), true);
if ($id_agente) {
$table->data[2][1] .= '    ';

View File

@ -81,6 +81,7 @@ $alias_as_name = 0;
$direccion_agente = get_parameter('direccion', '');
$direccion_agente = trim(io_safe_output($direccion_agente));
$direccion_agente = io_safe_input($direccion_agente);
$unique_ip = 0;
$intervalo = SECONDS_5MINUTES;
$ff_interval = 0;
$quiet_module = 0;
@ -161,6 +162,7 @@ if ($create_agent) {
$alias = (string) get_parameter_post('alias', '');
$alias_as_name = (int) get_parameter_post('alias_as_name', 0);
$direccion_agente = (string) get_parameter_post('direccion', '');
$unique_ip = (int) get_parameter_post('unique_ip', 0);
// safe_output only validate ip
$direccion_agente = trim(io_safe_output($direccion_agente));
@ -216,7 +218,12 @@ if ($create_agent) {
$nombre_agente = $alias;
}
if (!$exists_alias) {
if ($unique_ip && $direccion_agente != '') {
$sql = 'SELECT direccion FROM tagente WHERE direccion = "'.$direccion_agente.'"';
$exists_ip = db_get_row_sql($sql);
}
if (!$exists_alias && !$exists_ip) {
$id_agente = db_process_sql_insert(
'tagente',
[
@ -326,6 +333,8 @@ if ($create_agent) {
$agent_creation_error = __('Could not be created');
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');
}
}
}
@ -758,6 +767,7 @@ if ($update_agent) {
$alias = str_replace('`', '‘', (string) get_parameter_post('alias', ''));
$alias_as_name = (int) get_parameter_post('alias_as_name', 0);
$direccion_agente = (string) get_parameter_post('direccion', '');
$unique_ip = (int) get_parameter_post('unique_ip', 0);
// safe_output only validate ip
$direccion_agente = trim(io_safe_output($direccion_agente));
@ -860,8 +870,15 @@ if ($update_agent) {
// If there is an agent with the same name, but a different ID
}
if ($unique_ip && $direccion_agente != '') {
$sql = 'SELECT direccion FROM tagente WHERE direccion = "'.$direccion_agente.'"';
$exists_ip = db_get_row_sql($sql);
}
if ($grupo <= 0) {
ui_print_error_message(__('The group id %d is incorrect.', $grupo));
} else if ($exists_ip) {
ui_print_error_message(__('Duplicate main IP address'));
} else {
// If different IP is specified than previous, add the IP
if ($direccion_agente != ''

View File

@ -269,7 +269,13 @@ $table->data[37][0] = __('Audit log directory').ui_print_help_tip(__('Directory
$table->data[37][1] = html_print_input_text('auditdir', io_safe_output($config['auditdir']), '', 30, 100, true);
$table->data[38][0] = __('Set alias as name by default in agent creation');
$table->data[38][1] = html_print_checkbox_toogle_switch('alias_as_name', 1, $config['alias_as_name'], true);
$table->data[38][1] = __('Yes').'&nbsp;&nbsp;&nbsp;'.html_print_radio_button('alias_as_name', 1, '', $config['alias_as_name'], true).'&nbsp;&nbsp;';
$table->data[38][1] .= __('No').'&nbsp;&nbsp;&nbsp;'.html_print_radio_button('alias_as_name', 0, '', $config['alias_as_name'], true);
$table->data[39][0] = __('Unique IP').ui_print_help_tip(__('Set the primary IP address as the unique IP, preventing the same primary IP address from being used in more than one agent'), true);
$table->data[39][1] = __('Yes').'&nbsp;&nbsp;&nbsp;'.html_print_radio_button('unique_ip', 1, '', $config['unique_ip'], true).'&nbsp;&nbsp;';
$table->data[39][1] .= __('No').'&nbsp;&nbsp;&nbsp;'.html_print_radio_button('unique_ip', 0, '', $config['unique_ip'], true);
echo '<form id="form_setup" method="post" action="index.php?sec=gsetup&sec2=godmode/setup/setup&amp;section=general&amp;pure='.$config['pure'].'">';
echo '<fieldset>';

View File

@ -294,6 +294,10 @@ function config_update_config()
if (!config_update_value('auditdir', get_parameter('auditdir'))) {
$error_update[] = __('Audit log directory');
}
if (!config_update_value('unique_ip', get_parameter('unique_ip'))) {
$error_update[] = __('unique_ip');
}
break;
case 'enterprise':
@ -1657,6 +1661,10 @@ function config_process_config()
config_update_value('limit_parameters_massive', (ini_get('max_input_vars') / 2));
}
if (!isset($config['unique_ip'])) {
config_update_value('unique_ip', 0);
}
/*
*Parse the ACL IP list for access API
*/