diff --git a/pandora_console/include/ajax/agent.php b/pandora_console/include/ajax/agent.php index 73c4660511..c8ad9e3791 100644 --- a/pandora_console/include/ajax/agent.php +++ b/pandora_console/include/ajax/agent.php @@ -185,12 +185,6 @@ if ($search_agents && ((!defined('METACONSOLE')) || $force_local)) { return; } elseif ($search_agents && ($config['metaconsole'] == 1) && defined('METACONSOLE')) { - $servers = db_get_all_rows_sql ("SELECT * - FROM tmetaconsole_setup - WHERE disabled = 0"); - if (!isset($servers)) { - return; - } $id_agent = (int) get_parameter ('id_agent'); $string = (string) get_parameter ('q'); /* q is what autocomplete plugin gives */ @@ -204,7 +198,7 @@ elseif ($search_agents && ($config['metaconsole'] == 1) && defined('METACONSOLE' } } - $filter = array (); + $filter = array(); if ($id_group != -1) { if ($id_group == 0) { @@ -217,90 +211,63 @@ elseif ($search_agents && ($config['metaconsole'] == 1) && defined('METACONSOLE' } } - $data = array(); - foreach ($servers as $server) { - if (metaconsole_load_external_db ($server) != NOERR) { - continue; - } + if (!empty($id_agent)) { + $filter['id_agente'] = $id_agent; + } + + if (!empty($string)) { + $search_filters = array(); //Get agents for only the name. - $filter_agents = $filter; switch ($config['dbtype']) { case "mysql": - $filter_agents[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%")'; + //Get agents for only the name. + $search_filters[] = "(nombre COLLATE utf8_general_ci LIKE '%$string%')"; + //Get agents for only the address + $search_filters[] = "(direccion LIKE '%$string%')"; + //Get agents for only the description + $search_filters[] = "(comentarios LIKE '%$string%')"; break; case "postgresql": - $filter_agents[] = '(nombre LIKE \'%'.$string.'%\')'; + //Get agents for only the name. + $search_filters[] = "(nombre LIKE '%$string%')"; + //Get agents for only the address + $search_filters[] = "(direccion LIKE '%$string%')"; + //Get agents for only the description + $search_filters[] = "(comentarios LIKE '%$string%')"; break; case "oracle": - $filter_agents[] = '(UPPER(nombre) LIKE UPPER(\'%'.$string.'%\')'; + //Get agents for only the name. + $search_filters[] = "(UPPER(nombre) LIKE UPPER('%$string%')"; + //Get agents for only the address + $search_filters[] = "(UPPER(direccion) LIKE UPPER('%$string%'))"; + //Get agents for only the description + $search_filters[] = "(UPPER(comentarios) LIKE UPPER('%$string%'))"; break; } - $agents = agents_get_agents($filter_agents, array ('id_agente', 'nombre', 'direccion')); - if ($agents !== false) { - foreach ($agents as $agent) { - $data[] = array('id' => $agent['id_agente'], - 'name' => io_safe_output($agent['nombre']), - 'ip' => io_safe_output($agent['direccion']), - 'filter' => 'agent', - 'id_server' => $server['id']); - } - } - //Get agents for only the address - $filter_address = $filter; - switch ($config['dbtype']) { - case "mysql": - $filter_address[] = '(nombre COLLATE utf8_general_ci NOT LIKE "%'.$string.'%" AND direccion LIKE "%'.$string.'%")'; - break; - case "postgresql": - $filter_address[] = '(nombre NOT LIKE \'%'.$string.'%\' AND direccion LIKE \'%'.$string.'%\')'; - break; - case "oracle": - $filter_address[] = '(UPPER(nombre) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(direccion) LIKE UPPER(\'%'.$string.'%\'))'; - break; - } - $agents = agents_get_agents($filter_address, array ('id_agente', 'nombre', 'direccion')); - if ($agents !== false) { - foreach ($agents as $agent) { - $data[] = array('id' => $agent['id_agente'], - 'name' => io_safe_output($agent['nombre']), - 'ip' => io_safe_output($agent['direccion']), - 'filter' => 'address', - 'id_server' => $server['id']); - } - } + $search_filters_str = implode($search_filters, ' OR '); - //Get agents for only the description - $filter_description = $filter; - switch ($config['dbtype']) { - case "mysql": - $filter_description[] = - '(nombre COLLATE utf8_general_ci NOT LIKE "%'.$string.'%" AND direccion NOT LIKE "%'.$string.'%" AND comentarios LIKE "%'.$string.'%")'; - break; - case "postgresql": - $filter_description[] = - '(nombre NOT LIKE \'%'.$string.'%\' AND direccion NOT LIKE \'%'.$string.'%\' AND comentarios LIKE \'%'.$string.'%\')'; - break; - case "oracle": - $filter_description[] = - '(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, - array ('id_agente', 'nombre', 'direccion')); - if ($agents !== false) { - foreach ($agents as $agent) { - $data[] = array('id' => $agent['id_agente'], - 'name' => io_safe_output($agent['nombre']), - 'ip' => io_safe_output($agent['direccion']), - 'filter' => 'description', - 'id_server' => $server['id']); - } - } - //Restore db connection - metaconsole_restore_db(); + if (!empty($search_filters_str)) + $filter[] = "($search_filters_str)"; + } + $fields = array( + 'id_tagente AS id_agente', 'nombre', + 'direccion', 'id_tmetaconsole_setup AS id_server' + ); + $agents = db_get_all_rows_filter('tmetaconsole_agent', $filter, $fields); + + $data = array(); + + if ($agents !== false) { + foreach ($agents as $agent) { + $data[] = array('id' => $agent['id_agente'], + 'name' => io_safe_output($agent['nombre']), + 'ip' => io_safe_output($agent['direccion']), + 'filter' => 'description', + 'id_server' => $agent['id_server']); + } } echo json_encode($data); diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index 6f143e1bc1..572348659d 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -423,6 +423,9 @@ if (is_ajax ()) { ($filter != '' ? $filter : false), $indexed); } + if (empty($agent_modules)) + $agent_modules = array(); + foreach ($agent_modules as $key => $module) { $agent_modules[$key]['nombre'] = io_safe_output($module['nombre']); } @@ -438,28 +441,24 @@ if (is_ajax ()) { if ($get_agent_status_tooltip) { $id_agent = (int) get_parameter ('id_agent'); - $metaconsole = (bool)get_parameter('metaconsole', false); - $id_server = (int)get_parameter('id_server', 0); //Metaconsole + $metaconsole = (bool) get_parameter('metaconsole', false); + $id_server = (int) get_parameter('id_server', 0); //Metaconsole $server = null; if ($metaconsole) { - $strict_user = (bool) db_get_value('strict_acl', 'tusuario', 'id_user', $config['id_user']); - $server = db_get_row('tmetaconsole_setup', 'id', $id_server); + $filter = array(); + if (!empty($id_agent)) + $filter['id_tagente'] = $id_agent; + if (!empty($id_server)) + $filter['id_tmetaconsole_setup'] = $id_server; - if (metaconsole_connect($server) != NOERR) { - return; - } - - $agent = db_get_row ('tagente', 'id_agente', $id_agent); - - metaconsole_restore_db(); + $agent = db_get_row_filter('tmetaconsole_agent', $filter); } else { $agent = db_get_row ('tagente', 'id_agente', $id_agent); } - - + if ($agent === false) { return; } echo '