From 21dd508e53ea80b97ec89f6cfbed47821773cade Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Thu, 22 Sep 2016 10:27:35 +0200 Subject: [PATCH 01/24] Changed name by alias. Ticket #74. --- .../godmode/agentes/agent_manager.php | 106 ++++++++++-------- .../godmode/agentes/configurar_agente.php | 41 ++++--- .../godmode/agentes/modificar_agente.php | 14 ++- pandora_console/include/ajax/agent.php | 34 +++++- pandora_console/include/functions_ui.php | 21 +++- .../operation/agentes/estado_agente.php | 6 +- .../agentes/estado_generalagente.php | 8 +- .../operation/agentes/ver_agente.php | 3 +- .../operation/search_agents.getdata.php | 10 +- pandora_console/operation/search_agents.php | 6 +- pandora_console/operation/search_modules.php | 5 +- pandora_console/pandoradb.sql | 1 + 12 files changed, 164 insertions(+), 91 deletions(-) diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 2b51cac09e..02516b80d1 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -150,22 +150,27 @@ $table->style[0] = 'font-weight: bold; width: 150px;'; $table->data = array (); $table->align[2] = 'center'; +html_debug($alias); +if(!$new_agent && $alias != ''){ + $table->data[0][0] = __('Agent name') . + ui_print_help_tip (__("The agent's name must be the same as the one defined at the console"), true); + $table->data[0][1] = html_print_input_text ('agente', $nombre_agente, '', 50, 100,true); -$table->data[0][0] = __('Agent name') . - ui_print_help_tip (__("The agent's name must be the same as the one defined at the console"), true); -$table->data[0][1] = html_print_input_text ('agente', $nombre_agente, '', 50, 100,true); + $table->data[0][2] = __('QR Code Agent view'); -$table->data[0][2] = __('QR Code Agent view'); + if ($id_agente) { -if ($id_agente) { - - $table->data[0][1] .= " " . __("ID") . "  $id_agente  "; - $table->data[0][1] .= '  '; - $table->data[0][1] .= html_print_image ("images/zoom.png", - true, array ("border" => 0, "title" => __('Agent detail'))); - $table->data[0][1] .= ''; + $table->data[0][1] .= " " . __("ID") . "  $id_agente  "; + $table->data[0][1] .= '  '; + $table->data[0][1] .= html_print_image ("images/zoom.png", + true, array ("border" => 0, "title" => __('Agent detail'))); + $table->data[0][1] .= ''; + } } + + + // Remote configuration available if (!$new_agent) { if (isset($filename)) { @@ -197,17 +202,21 @@ if (!$new_agent) { if (!$new_agent) { $table->data[0][1] .= "  " . html_print_image('images/cross.png', true, array('title' => __("Delete agent"))) . ""; } +$table->data[1][0] = __('Alias'); +$table->data[1][1] = html_print_input_text ('alias', $alias, '', 50, 100, true); -$table->data[1][0] = __('IP Address'); -$table->data[1][1] = html_print_input_text ('direccion', $direccion_agente, '', 16, 100, true); + + +$table->data[2][0] = __('IP Address'); +$table->data[2][1] = html_print_input_text ('direccion', $direccion_agente, '', 16, 100, true); if ($id_agente) { - $table->data[1][1] .= '    '; - + $table->data[2][1] .= '    '; + $ip_all = agents_get_addresses ($id_agente); - - $table->data[1][1] .= html_print_select ($ip_all, "address_list", $direccion_agente, '', '', 0, true); - $table->data[1][1] .= " ". html_print_checkbox ("delete_ip", 1, false, true).__('Delete selected'); + + $table->data[2][1] .= html_print_select ($ip_all, "address_list", $direccion_agente, '', '', 0, true); + $table->data[2][1] .= " ". html_print_checkbox ("delete_ip", 1, false, true).__('Delete selected'); } ?> @@ -217,66 +226,69 @@ if ($id_agente) { } rowspan[1][2] = 3; -if ($id_agente) { - $table->data[1][2] = - ""; -} -else { - $table->data[1][2] = __("Only it is show when
the agent is saved."); +if(!$new_agent){ + $table->rowspan[2][2] = 3; + if ($id_agente) { + $table->data[2][2] = + ""; + } + else { + $table->data[2][2] = __("Only it is show when
the agent is saved."); + } } + $groups = users_get_groups ($config["id_user"], "AR",false); $agents = agents_get_group_agents (array_keys ($groups)); -$table->data[2][0] = __('Parent'); +$table->data[3][0] = __('Parent'); $params = array(); $params['return'] = true; $params['show_helptip'] = true; $params['input_name'] = 'id_parent'; $params['value'] = agents_get_name ($id_parent); -$table->data[2][1] = ui_print_agent_autocomplete_input($params); +$table->data[3][1] = ui_print_agent_autocomplete_input($params); -$table->data[2][1] .= html_print_checkbox ("cascade_protection", 1, $cascade_protection, true).__('Cascade protection'). " " . ui_print_help_icon("cascade_protection", true); +$table->data[3][1] .= html_print_checkbox ("cascade_protection", 1, $cascade_protection, true).__('Cascade protection'). " " . ui_print_help_icon("cascade_protection", true); -$table->data[3][0] = __('Group'); -$table->data[3][1] = html_print_select_groups(false, "AR", false, 'grupo', $grupo, '', '', 0, true); -$table->data[3][1] .= ' '; -$table->data[3][1] .= ui_print_group_icon ($grupo, true); -$table->data[3][1] .= ''; +$table->data[4][0] = __('Group'); +$table->data[4][1] = html_print_select_groups(false, "AR", false, 'grupo', $grupo, '', '', 0, true); +$table->data[4][1] .= ' '; +$table->data[4][1] .= ui_print_group_icon ($grupo, true); +$table->data[4][1] .= ''; -$table->data[4][0] = __('Interval'); +$table->data[5][0] = __('Interval'); -$table->data[4][1] = html_print_extended_select_for_time ('intervalo', $intervalo, '', '', '0', 10, true); +$table->data[5][1] = html_print_extended_select_for_time ('intervalo', $intervalo, '', '', '0', 10, true); if ($intervalo < SECONDS_5MINUTES) { - $table->data[4][1] .= clippy_context_help("interval_agent_min"); + $table->data[5][1] .= clippy_context_help("interval_agent_min"); } -$table->data[5][0] = __('OS'); -$table->data[5][1] = html_print_select_from_sql ('SELECT id_os, name FROM tconfig_os', +$table->data[6][0] = __('OS'); +$table->data[6][1] = html_print_select_from_sql ('SELECT id_os, name FROM tconfig_os', 'id_os', $id_os, '', '', '0', true); -$table->data[5][1] .= ' '; -$table->data[5][1] .= ui_print_os_icon ($id_os, false, true); -$table->data[5][1] .= ''; +$table->data[6][1] .= ' '; +$table->data[6][1] .= ui_print_os_icon ($id_os, false, true); +$table->data[6][1] .= ''; // Network server $servers = servers_get_names(); if (!array_key_exists($server_name, $servers)) { $server_Name = 0; //Set the agent have not server. } -$table->data[6][0] = __('Server'); +$table->data[7][0] = __('Server'); if ($new_agent) { //Set first server by default. $servers_get_names = servers_get_names(); $array_keys_servers_get_names = array_keys($servers_get_names); $server_name = reset($array_keys_servers_get_names); } -$table->data[6][1] = html_print_select (servers_get_names (), +$table->data[7][1] = html_print_select (servers_get_names (), 'server_name', $server_name, '', __('None'), 0, true). ' ' . ui_print_help_icon ('agent_server', true); // Description -$table->data[7][0] = __('Description'); -$table->data[7][1] = html_print_input_text ('comentarios', $comentarios, +$table->data[8][0] = __('Description'); +$table->data[8][1] = html_print_input_text ('comentarios', $comentarios, '', 45, 200, true); html_print_table ($table); @@ -531,5 +543,7 @@ ui_require_jquery_file('bgiframe'); echo ui_get_full_url('index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=' . $id_agente); ?>", "#qr_code_agent_view", 128, 128); + $("#text-agente").prop('disabled', true); + }); diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 4f526745ed..a20e82e6d1 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -73,6 +73,7 @@ $campo_3 = ""; $maximo = 0; $minimo = 0; $nombre_agente = ""; +$alias = ""; $direccion_agente = get_parameter('direccion', ''); $direccion_agente = trim(io_safe_output($direccion_agente)); $direccion_agente = io_safe_input($direccion_agente); @@ -146,7 +147,8 @@ $module_macros = array (); // Create agent if ($create_agent) { - $nombre_agente = (string) get_parameter_post("agente",''); + $nombre_agente = md5($alias . $direccion_agente); + $alias = (string) get_parameter_post("alias",''); $direccion_agente = (string) get_parameter_post("direccion",''); $direccion_agente = trim(io_safe_output($direccion_agente)); $direccion_agente = io_safe_input($direccion_agente); @@ -177,18 +179,19 @@ if ($create_agent) { } // Check if agent exists (BUG WC-50518-2) - if ($nombre_agente == "") { - $agent_creation_error = __('No agent name specified'); + if ($alias == "") { + $agent_creation_error = __('No agent alias specified'); $agent_created_ok = 0; } - elseif (agents_get_agent_id ($nombre_agente)) { + /*elseif (agents_get_agent_id ($nombre_agente)) { $agent_creation_error = __('There is already an agent in the database with this name'); $agent_created_ok = 0; - } + }*/ else { $id_agente = db_process_sql_insert ('tagente', array ('nombre' => $nombre_agente, + 'alias' => $alias, 'direccion' => $direccion_agente, 'id_grupo' => $grupo, 'intervalo' => $intervalo, @@ -237,7 +240,7 @@ if ($create_agent) { ' Quiet: ' . (int)$quiet; db_pandora_audit("Agent management", - "Created agent $nombre_agente", false, true, $info); + "Created agent $alias", false, true, $info); } else { $id_agente = 0; @@ -550,10 +553,9 @@ if ($id_agente) { default: break; } - - ui_print_page_header ( - agents_get_name ($id_agente) . ' ' . $tab_description, - "images/setup.png", false, $help_header , true, $onheader); + $agent = db_get_row ('tagente', 'id_agente', $id_agente); + ui_print_page_header ($agent["nombre"], + "images/setup.png", false, $help_header , true, $onheader,$agent["alias"] . ' ' . $tab_description); } else { // Create agent @@ -637,6 +639,7 @@ $update_agent = (bool) get_parameter ('update_agent'); if ($update_agent) { // if modified some agent paramenter $id_agente = (int) get_parameter_post ("id_agente"); $nombre_agente = str_replace('`','‘',(string) get_parameter_post ("agente", "")); + $alias = str_replace('`','‘',(string) get_parameter_post ("alias", "")); $direccion_agente = (string) get_parameter_post ("direccion", ''); $direccion_agente = trim(io_safe_output($direccion_agente)); $direccion_agente = io_safe_input($direccion_agente); @@ -700,14 +703,14 @@ if ($update_agent) { // if modified some agent paramenter } //Verify if there is another agent with the same name but different ID - if ($nombre_agente == "") { - ui_print_error_message(__('No agent name specified')); + if ($alias == "") { + ui_print_error_message(__('No agent alias specified')); //If there is an agent with the same name, but a different ID } - elseif (agents_get_agent_id ($nombre_agente) > 0 && + /*elseif (agents_get_agent_id ($nombre_agente) > 0 && agents_get_agent_id ($nombre_agente) != $id_agente) { ui_print_error_message(__('There is already an agent in the database with this name')); - } + }*/ else { //If different IP is specified than previous, add the IP if ($direccion_agente != '' && @@ -727,7 +730,7 @@ if ($update_agent) { // if modified some agent paramenter 'id_parent' => $id_parent, 'id_os' => $id_os, 'modo' => $modo, - 'nombre' => $nombre_agente, + 'alias' => $alias, 'direccion' => $direccion_agente, 'id_grupo' => $grupo, 'intervalo' => $intervalo, @@ -771,8 +774,8 @@ if ($update_agent) { // if modified some agent paramenter enterprise_hook ('update_agent', array ($id_agente)); ui_print_success_message (__('Successfully updated')); db_pandora_audit("Agent management", - "Updated agent $nombre_agente", false, false, $info); - + "Updated agent $alias", false, false, $info); + } } } @@ -797,6 +800,10 @@ if ($id_agente) { $intervalo = $agent["intervalo"]; // Define interval in seconds $nombre_agente = $agent["nombre"]; + $alias = $agent["alias"]; + if(empty ($alias)){ + $alias = $nombre_agente; + } $direccion_agente = $agent["direccion"]; $grupo = $agent["id_grupo"]; $ultima_act = $agent["ultimo_contacto"]; diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php index c310f3e30c..738e90a835 100644 --- a/pandora_console/godmode/agentes/modificar_agente.php +++ b/pandora_console/godmode/agentes/modificar_agente.php @@ -276,6 +276,7 @@ if ($search != "") { $search_sql .= ")"; }else{ $search_sql = " AND ( nombre " . $order_collation . " + LIKE '%$search%' OR alias " . $order_collation . " LIKE '%$search%') "; } } @@ -369,7 +370,7 @@ else { FROM tagente WHERE 1=1 %s - ORDER BY %s %s %s LIMIT %d OFFSET %d', $search_sql, $order['field'], $order['field2'], + ORDER BY %s %s, %s %s LIMIT %d OFFSET %d', $search_sql, $order['field'],$order['order'], $order['field2'], $order['order'], $config["block_size"], $offset); break; case "oracle": @@ -380,7 +381,7 @@ else { FROM tagente WHERE 1=1 %s - ORDER BY %s %s %s', $search_sql, $order['field'], $order['field2'], $order['order']); + ORDER BY %s %s, %s %s', $search_sql, $order['field'],$order['order'], $order['field2'], $order['order']); $sql = oracle_recode_query ($sql, $set); break; } @@ -515,11 +516,14 @@ if ($agents !== false) { else { $main_tab = 'module'; } - - echo "" . - ui_print_truncate_text($agent["nombre"], 'agent_medium', true, true, true, '[…]', 'font-size: 7pt') . + ''.$agent["alias"].'' . ""; echo ""; if ($agent["disabled"]) { diff --git a/pandora_console/include/ajax/agent.php b/pandora_console/include/ajax/agent.php index d4850e3322..2dcf81755b 100644 --- a/pandora_console/include/ajax/agent.php +++ b/pandora_console/include/ajax/agent.php @@ -113,11 +113,12 @@ if ($search_agents && (!is_metaconsole() || $force_local)) { $filter_agents[] = '(UPPER(nombre) LIKE UPPER(\'%'.$string.'%\'))'; break; } - $agents = agents_get_agents($filter_agents, array ('id_agente', 'nombre', 'direccion')); + $agents = agents_get_agents($filter_agents, array ('id_agente', 'nombre', 'direccion','alias')); if ($agents !== false) { foreach ($agents as $agent) { $data[] = array('id' => $agent['id_agente'], 'name' => io_safe_output($agent['nombre']), + 'alias' => io_safe_output($agent['alias']), 'ip' => io_safe_output($agent['direccion']), 'filter' => 'agent'); } @@ -136,11 +137,12 @@ if ($search_agents && (!is_metaconsole() || $force_local)) { $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')); + $agents = agents_get_agents($filter_address, array ('id_agente', 'nombre', 'direccion', 'alias')); if ($agents !== false) { foreach ($agents as $agent) { $data[] = array('id' => $agent['id_agente'], 'name' => io_safe_output($agent['nombre']), + 'alias' => io_safe_output($agent['alias']), 'ip' => io_safe_output($agent['direccion']), 'filter' => 'address'); } @@ -159,16 +161,40 @@ if ($search_agents && (!is_metaconsole() || $force_local)) { $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')); + $agents = agents_get_agents($filter_description, array ('id_agente', 'nombre', 'direccion', 'alias')); if ($agents !== false) { foreach ($agents as $agent) { $data[] = array('id' => $agent['id_agente'], 'name' => io_safe_output($agent['nombre']), + 'alias' => io_safe_output($agent['alias']), 'ip' => io_safe_output($agent['direccion']), 'filter' => 'description'); } } - + + //Get agents for only the alias + $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 NOT LIKE "%'.$string.'%" AND alias LIKE "%'.$string.'%")'; + break; + case "postgresql": + $filter_description[] = '(nombre NOT LIKE \'%'.$string.'%\' AND direccion NOT LIKE \'%'.$string.'%\' AND comentarios NOT LIKE \'%'.$string.'%\' AND alias LIKE \'%'.$string.'%\')'; + break; + case "oracle": + $filter_description[] = '(UPPER(nombre) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(direccion) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(comentarios) NOT LIKE UPPER(\'%'.$string.'%\') AND UPPER(alias) LIKE UPPER(\'%'.$string.'%\'))'; + break; + } + $agents = agents_get_agents($filter_description, array ('id_agente', 'nombre', 'direccion', 'alias')); + if ($agents !== false) { + foreach ($agents as $agent) { + $data[] = array('id' => $agent['id_agente'], + 'name' => io_safe_output($agent['nombre']), + 'alias' => io_safe_output($agent['alias']), + 'ip' => io_safe_output($agent['direccion']), + 'filter' => 'alias'); + } + } echo json_encode($data); return; } diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index dbc498a8d0..36764908e0 100755 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -2383,7 +2383,7 @@ function ui_get_full_url ($url = '', $no_proxy = false, $add_name_php_file = fal * @return string Header HTML */ -function ui_print_page_header ($title, $icon = "", $return = false, $help = "", $godmode = false, $options = "",$modal = false, $message = "") { +function ui_print_page_header ($title, $icon = "", $return = false, $help = "", $godmode = false, $options = "", $alias = "") { $title = io_safe_input_html($title); if (($icon == "") && ($godmode == true)) { $icon = "images/gm_setup.png"; @@ -2409,8 +2409,13 @@ function ui_print_page_header ($title, $icon = "", $return = false, $help = "", $buffer .= '