diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 3ddea77d0f..9ccc3a5b85 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2013-06-25 Miguel de Dios + + * godmode/agentes/configurar_agente.php, + include/functions_agents.php: fixed the operations with the ip or + ips adress of agent. + + MERGED FROM THE BRANCH PANDORA_4_0 + 2013-06-25 Miguel de Dios * godmode/menu.php: fixed the default value for refresh in the diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index d5ec2cfdc9..aa14daad77 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -297,7 +297,7 @@ if ($id_agente) { if ($inventorytab == -1) $inventorytab = ""; - + $has_remote_conf = enterprise_hook('config_agents_has_remote_configuration',array($id_agente)); if ($has_remote_conf === true) { @@ -377,6 +377,7 @@ if ($id_agente) { 'alert' => $alerttab); } + //Extensions tabs foreach ($config['extensions'] as $extension) { if (isset($extension['extension_god_tab']) && check_acl ($config["id_user"], $group, "AW", $id_agente)) { $image = $extension['extension_god_tab']['icon']; @@ -526,13 +527,19 @@ if ($update_agent) { // if modified some agent paramenter $direccion_agente = trim(io_safe_output($direccion_agente)); $direccion_agente = io_safe_input($direccion_agente); $address_list = (string) get_parameter_post ("address_list", ''); - if ($address_list != $direccion_agente && $direccion_agente == agents_get_address ($id_agente) && $address_list != agents_get_address ($id_agente)) { + + if ($address_list != $direccion_agente && + $direccion_agente == agents_get_address ($id_agente) && + $address_list != agents_get_address ($id_agente)) { + //If we selected another IP in the drop down list to be 'primary': // a) field is not the same as selectbox // b) field has not changed from current IP // c) selectbox is not the current IP - if ($address_list != 0) + + if (!empty($address_list)) { $direccion_agente = $address_list; + } } $grupo = (int) get_parameter_post ("grupo", 0); $intervalo = (int) get_parameter_post ("intervalo", SECONDS_5MINUTES); @@ -567,7 +574,7 @@ if ($update_agent) { // if modified some agent paramenter if ($old_value === false) { // Create custom field if not exist db_process_sql_insert ('tagent_custom_data', - array('id_field' => $key,'id_agent' => $id_agente, 'description' => $value)); + array('id_field' => $key,'id_agent' => $id_agente, 'description' => $value)); } else { db_process_sql_update ('tagent_custom_data', @@ -592,10 +599,12 @@ if ($update_agent) { // if modified some agent paramenter agents_add_address ($id_agente, $direccion_agente); } + $action_delete_ip = (bool)get_parameter('delete_ip', false); //If IP is set for deletion, delete first - if (isset ($_POST["delete_ip"])) { + if ($action_delete_ip) { $delete_ip = get_parameter_post ("address_list"); - agents_delete_address ($id_agente, $delete_ip); + + $direccion_agente = agents_delete_address($id_agente, $delete_ip); } $result = db_process_sql_update ('tagente', @@ -635,6 +644,7 @@ if ($update_agent) { // if modified some agent paramenter ui_print_success_message (__('Successfully updated')); db_pandora_audit("Agent management", "Updated agent $nombre_agente", false, false, $info); + } } } @@ -800,6 +810,7 @@ if ($update_module || $create_module) { $plugin_pass = (int) get_parameter ('plugin_pass'); else $plugin_pass = (string) get_parameter ('plugin_pass'); + $plugin_parameter = (string) get_parameter ('plugin_parameter'); } diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index fea9669390..23ab844dcb 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -95,6 +95,7 @@ function agents_create_agent ($name, $id_group, $interval, $ip_address, $values // Create address for this agent in taddress agents_add_address ($id_agent, $ip_address); + db_pandora_audit ("Agent management", "New agent '$name' created"); return $id_agent; @@ -202,6 +203,7 @@ function agents_get_alerts_simple ($id_agent = false, $filter = '', $options = f $selectText = 'COUNT(talert_template_modules.id) AS count'; } + $sql = sprintf ("SELECT %s FROM talert_template_modules INNER JOIN tagente_modulo t2 @@ -914,6 +916,7 @@ function agents_get_modules ($id_agent = null, $details = false, $filter = false // user can read the agents. // ================================================================= if ($id_agent === null) { + $sql = "SELECT id_agente FROM tagente WHERE id_grupo IN (" . implode(',', $id_groups) . ")"; @@ -937,6 +940,7 @@ function agents_get_modules ($id_agent = null, $details = false, $filter = false $id_agent = safe_int ($id_agent, 1); } + $where = "( 1 = ( SELECT is_admin @@ -1333,23 +1337,35 @@ function agents_delete_address ($id_agent, $ip_address) { $sql = sprintf ("SELECT id_ag FROM taddress_agent, taddress - WHERE taddress_agent.id_a = taddress.id_a AND ip = '%s' - AND id_agent = %d", $ip_address, $id_agent); + WHERE taddress_agent.id_a = taddress.id_a + AND ip = '%s' + AND id_agent = %d", $ip_address, $id_agent); $id_ag = db_get_sql ($sql); if ($id_ag !== false) { db_process_sql_delete('taddress_agent', array('id_ag' => $id_ag)); } + $agent_name = agents_get_name($id_agent, ""); db_pandora_audit("Agent management", "Deleted IP $ip_address from agent '$agent_name'"); // Need to change main address? - if (agents_get_address ($id_agent) == $ip_address) { + if (agents_get_address($id_agent) == $ip_address) { $new_ips = agents_get_addresses ($id_agent); + if (empty($new_ips)) { + $new_ip = ''; + } + else { + $new_ip = reset($new_ips); + } + // Change main address in agent to first one in the list - db_process_sql_update('tagente', array('direccion' => current ($new_ips)), + db_process_sql_update('tagente', + array('direccion' => $new_ip), array('id_agente' => $id_agent)); + + return $new_ip; } } @@ -1681,6 +1697,7 @@ function agents_delete_agent ($id_agents, $disableACL = false) { break; } + if ($error) { return false; }