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

Former-commit-id: f8f9668a14818a01b811a73052e2e7e82e9a8c7a
This commit is contained in:
tatiana.llorente@artica.es 2019-01-09 16:20:24 +01:00
parent 561579580e
commit 6f65c9876f
4 changed files with 37 additions and 4 deletions

View File

@ -228,7 +228,9 @@ if($new_agent){
} }
$table->data[2][0] = __('IP Address'); $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) { if ($id_agente) {
$table->data[2][1] .= '    '; $table->data[2][1] .= '    ';

View File

@ -81,6 +81,7 @@ $alias_as_name = 0;
$direccion_agente = get_parameter('direccion', ''); $direccion_agente = get_parameter('direccion', '');
$direccion_agente = trim(io_safe_output($direccion_agente)); $direccion_agente = trim(io_safe_output($direccion_agente));
$direccion_agente = io_safe_input($direccion_agente); $direccion_agente = io_safe_input($direccion_agente);
$unique_ip = 0;
$intervalo = SECONDS_5MINUTES; $intervalo = SECONDS_5MINUTES;
$ff_interval = 0; $ff_interval = 0;
$quiet_module = 0; $quiet_module = 0;
@ -160,6 +161,7 @@ if ($create_agent) {
$alias = (string) get_parameter_post("alias",''); $alias = (string) get_parameter_post("alias",'');
$alias_as_name = (int) get_parameter_post("alias_as_name", 0); $alias_as_name = (int) get_parameter_post("alias_as_name", 0);
$direccion_agente = (string) get_parameter_post("direccion",''); $direccion_agente = (string) get_parameter_post("direccion",'');
$unique_ip = (int) get_parameter_post("unique_ip", 0);
//safe_output only validate ip //safe_output only validate ip
$direccion_agente = trim(io_safe_output($direccion_agente)); $direccion_agente = trim(io_safe_output($direccion_agente));
@ -214,7 +216,12 @@ if ($create_agent) {
$nombre_agente = $alias; $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 ( $id_agente = db_process_sql_insert (
'tagente', 'tagente',
array ( array (
@ -304,6 +311,9 @@ if ($create_agent) {
if($exists_alias){ if($exists_alias){
$agent_creation_error = __('Could not be created, because name already exists'); $agent_creation_error = __('Could not be created, because name already exists');
} }
elseif($exists_ip){
$agent_creation_error = __('Could not be created, because IP already exists');
}
} }
} }
} }
@ -712,6 +722,7 @@ if ($update_agent) { // if modified some agent paramenter
$alias = str_replace('`','‘',(string) get_parameter_post ("alias", "")); $alias = str_replace('`','‘',(string) get_parameter_post ("alias", ""));
$alias_as_name = (int) get_parameter_post ('alias_as_name', 0); $alias_as_name = (int) get_parameter_post ('alias_as_name', 0);
$direccion_agente = (string) get_parameter_post ("direccion", ''); $direccion_agente = (string) get_parameter_post ("direccion", '');
$unique_ip = (int) get_parameter_post ('unique_ip', 0);
//safe_output only validate ip //safe_output only validate ip
$direccion_agente = trim(io_safe_output($direccion_agente)); $direccion_agente = trim(io_safe_output($direccion_agente));
@ -795,9 +806,18 @@ if ($update_agent) { // if modified some agent paramenter
ui_print_error_message(__('No agent alias specified')); ui_print_error_message(__('No agent alias specified'));
//If there is an agent with the same name, but a different ID //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) { if ($grupo <= 0) {
ui_print_error_message(__('The group id %d is incorrect.', $grupo)); ui_print_error_message(__('The group id %d is incorrect.', $grupo));
} }
elseif($exists_ip){
ui_print_error_message(__('Duplicate main IP address'));
}
else { else {
//If different IP is specified than previous, add the IP //If different IP is specified than previous, add the IP
if ($direccion_agente != '' && if ($direccion_agente != '' &&

View File

@ -230,6 +230,11 @@ $table->data[38][0] = __('Set alias as name by default in agent creation');
$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] = __('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[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 '<form id="form_setup" method="post" action="index.php?sec=gsetup&sec2=godmode/setup/setup&amp;section=general&amp;pure='.$config['pure'].'">';
echo "<fieldset>"; echo "<fieldset>";

View File

@ -204,10 +204,12 @@ function config_update_config () {
$error_update[] = __('Identification_reminder'); $error_update[] = __('Identification_reminder');
if (!config_update_value ('include_agents', (bool)get_parameter('include_agents'))) if (!config_update_value ('include_agents', (bool)get_parameter('include_agents')))
$error_update[] = __('Include_agents'); $error_update[] = __('Include_agents');
if (!config_update_value ('alias_as_name', get_parameter('alias_as_name'))) if (!config_update_value ('alias_as_name', get_parameter('alias_as_name')))
$error_update[] = __('alias_as_name'); $error_update[] = __('alias_as_name');
if (!config_update_value ('auditdir', get_parameter('auditdir'))) if (!config_update_value ('auditdir', get_parameter('auditdir')))
$error_update[] = __('Audit log directory'); $error_update[] = __('Audit log directory');
if (!config_update_value ('unique_ip', get_parameter('unique_ip')))
$error_update[] = __('unique_ip');
break; break;
case 'enterprise': case 'enterprise':
if (isset($config['enterprise_installed']) && $config['enterprise_installed'] == 1) { if (isset($config['enterprise_installed']) && $config['enterprise_installed'] == 1) {
@ -1123,6 +1125,10 @@ function config_process_config () {
config_update_value ('limit_parameters_massive', ini_get("max_input_vars") / 2); 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 *Parse the ACL IP list for access API
*/ */