' . html_print_image ("images/operation.png", true, array ("title" =>__('View'))) . ''; $viewtab['operation'] = true; $viewtab['active'] = false; $onheader = array('view' => $viewtab); // Header ui_print_page_header (__('Agents defined in Pandora'), "images/agent_mc.png", false, "", true, $onheader); // Perform actions $agent_to_delete = (int)get_parameter('borrar_agente'); $enable_agent = (int)get_parameter('enable_agent'); $disable_agent = (int)get_parameter('disable_agent'); $result = null; if ($agent_to_delete) { $id_agente = $agent_to_delete; $agent_name = agents_get_name ($id_agente); $id_grupo = agents_get_agent_group($id_agente); if (check_acl ($config["id_user"], $id_grupo, "AW")) { $id_agentes[0] = $id_agente; $result = agents_delete_agent($id_agentes); } else { // NO permissions. db_pandora_audit("ACL Violation", "Trying to delete agent \'$agent_name\'"); require ("general/noaccess.php"); exit; } ui_print_result_message($result, __('Success deleted agent.'), __('Could not be deleted.')); if (enterprise_installed()) { // Check if the remote config file still exist if (isset ($config["remote_config"])) { enterprise_include_once('include/functions_config_agents.php'); if (enterprise_hook('config_agents_has_remote_configuration', array($id_agente))) { ui_print_error_message(__('Maybe the files conf or md5 could not be deleted')); } } } } if ($enable_agent) { $result = db_process_sql_update('tagente', array('disabled' => 0), array('id_agente' => $enable_agent)); if ($result) { db_pandora_audit("Agent management", 'Enable ' . $enable_agent); } else { db_pandora_audit("Agent management", 'Fail to enable ' . $enable_agent); } ui_print_result_message ($result, __('Successfully enabled'), __('Could not be enabled')); } if ($disable_agent) { $result = db_process_sql_update('tagente', array('disabled' => 1), array('id_agente' => $disable_agent)); if ($result) { db_pandora_audit("Agent management", 'Disable ' . $disable_agent); } else { db_pandora_audit("Agent management", 'Fail to disable ' . $disable_agent); } ui_print_result_message ($result, __('Successfully disabled'), __('Could not be disabled')); } echo ""; echo ""; echo "
"; echo __('Group') . ' '; $own_info = get_user_info($config['id_user']); if (!$own_info['is_admin'] && !check_acl ($config['id_user'], 0, "PM")) $return_all_group = false; else $return_all_group = true; html_print_select_groups(false, "AR", $return_all_group, "ag_group", $ag_group, 'this.form.submit();', '', 0, false, false, true, '', false, 'width:100px;'); echo ""; echo __('Recursion') . ' '; html_print_checkbox ("recursion", 1, $recursion, false, false, 'this.form.submit()'); echo ""; echo __('Search') . ' '; html_print_input_text ("search", $search, '', 12); echo ""; echo ""; echo ""; echo ""; echo "
"; echo '
'; echo '
'; html_print_input_hidden ('new_agent', 1); html_print_submit_button (__('Create agent'), 'crt-1', false, 'class="sub next"'); echo "
"; echo "
"; $selected = 'border: 1px solid black;'; $selectNameUp = ''; $selectNameDown = ''; $selectOsUp = ''; $selectOsDown = ''; $selectGroupUp = ''; $selectGroupDown = ''; switch ($sortField) { case 'name': switch ($sort) { case 'up': $selectNameUp = $selected; $order = array('field' => 'nombre COLLATE utf8_general_ci', 'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'ASC'); break; case 'down': $selectNameDown = $selected; $order = array('field' => 'nombre COLLATE utf8_general_ci', 'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'DESC'); break; } break; case 'os': switch ($sort) { case 'up': $selectOsUp = $selected; $order = array('field' => 'id_os', 'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'ASC'); break; case 'down': $selectOsDown = $selected; $order = array('field' => 'id_os', 'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'DESC'); break; } break; case 'group': switch ($sort) { case 'up': $selectGroupUp = $selected; $order = array('field' => 'id_grupo', 'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'ASC'); break; case 'down': $selectGroupDown = $selected; $order = array('field' => 'id_grupo', 'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'DESC'); break; } break; default: $selectNameUp = $selected; $selectNameDown = ''; $selectOsUp = ''; $selectOsDown = ''; $selectGroupUp = ''; $selectGroupDown = ''; $order = array('field' => 'nombre COLLATE utf8_general_ci', 'field2' => 'nombre COLLATE utf8_general_ci', 'order' => 'ASC'); break; } $search_sql = ''; if ($search != "") { $search_sql = " AND ( nombre COLLATE utf8_general_ci LIKE '%$search%' OR direccion LIKE '%$search%') "; } // Show only selected groups if ($ag_group > 0) { $sql = sprintf ('SELECT COUNT(*) FROM tagente WHERE id_grupo = %d %s', $ag_group, $search_sql); $total_agents = db_get_sql ($sql); $ag_groups = array(); $ag_groups = (array)$ag_group; if ($recursion) { $ag_groups = groups_get_id_recursive($ag_group, true); } switch ($config["dbtype"]) { case "mysql": $sql = sprintf ('SELECT * FROM tagente WHERE id_grupo IN (%s) %s ORDER BY %s, %s %s LIMIT %d, %d', implode (",", $ag_groups), $search_sql, $order['field'], $order['field2'], $order['order'], $offset, $config["block_size"]); break; case "postgresql": $sql = sprintf ('SELECT * FROM tagente WHERE id_grupo IN (%s) %s ORDER BY %s, %s %s LIMIT %d OFFSET %d', implode (",", $ag_groups), $search_sql, $order['field'], $order['field2'], $order['order'], $config["block_size"], $offset); break; case "oracle": $set = array (); $set['limit'] = $config["block_size"]; $set['offset'] = $offset; $sql = sprintf ('SELECT * FROM tagente WHERE id_grupo IN (%s) %s ORDER BY %s, %s %s', implode (",", $ag_groups), $search_sql, $order['field'], $order['field2'], $order['order']); $sql = oracle_recode_query ($sql, $set); break; } } else { // Admin user get ANY group, even if they doesnt exist if (check_acl ($config['id_user'], 0, "PM")) { $sql = sprintf ('SELECT COUNT(*) FROM tagente WHERE 1=1 %s', $search_sql); $total_agents = db_get_sql ($sql); switch ($config["dbtype"]) { case "mysql": $sql = sprintf ('SELECT * FROM tagente WHERE 1=1 %s ORDER BY %s, %s %s LIMIT %d, %d', $search_sql, $order['field'], $order['field2'], $order['order'], $offset, $config["block_size"]); break; case "postgresql": $sql = sprintf ('SELECT * FROM tagente WHERE 1=1 %s ORDER BY %s, %s %s LIMIT %d OFFSET %d', $search_sql, $order['field'], $order['field2'], $order['order'], $config["block_size"], $offset); break; case "oracle": $set = array (); $set['limit'] = $config["block_size"]; $set['offset'] = $offset; $sql = sprintf ('SELECT * FROM tagente WHERE 1=1 %s ORDER BY %s, %s %s', $search_sql, $order['field'], $order['field2'], $order['order']); $sql = oracle_recode_query ($sql, $set); break; } } else { // Concatenate AW and AD permisions to get all the possible groups where the user can manage $user_groupsAW = users_get_groups ($config['id_user'], 'AW'); $user_groupsAD = users_get_groups ($config['id_user'], 'AD'); $user_groups = $user_groupsAW + $user_groupsAD; $sql = sprintf ('SELECT COUNT(*) FROM tagente WHERE id_grupo IN (%s) %s', implode (',', array_keys ($user_groups)), $search_sql); $total_agents = db_get_sql ($sql); switch ($config["dbtype"]) { case "mysql": $sql = sprintf ('SELECT * FROM tagente WHERE id_grupo IN (%s) %s ORDER BY %s, %s %s LIMIT %d, %d', implode (',', array_keys ($user_groups)), $search_sql, $order['field'], $order['field2'], $order['order'], $offset, $config["block_size"]); break; case "postgresql": $sql = sprintf ('SELECT * FROM tagente WHERE id_grupo IN (%s) %s ORDER BY %s, %s %s LIMIT %d OFFSET %d', implode (',', array_keys ($user_groups)), $search_sql, $order['field'], $order['field2'], $order['order'], $config["block_size"], $offset); break; case "oracle": $set = array (); $set['limit'] = $config["block_size"]; $set['offset'] = $offset; $sql = sprintf ('SELECT * FROM tagente WHERE id_grupo IN (%s) %s ORDER BY %s, %s %s', implode (',', array_keys ($user_groups)), $search_sql, $order['field'], $order['field2'], $order['order']); $sql = oracle_recode_query ($sql, $set); break; } } } $agents = db_get_all_rows_sql ($sql); // Delete rnum row generated by oracle_recode_query() function if (($config['dbtype'] == 'oracle') && ($agents !== false)) { for ($i=0; $i < count($agents); $i++) { unset($agents[$i]['rnum']); } } // Prepare pagination ui_pagination ($total_agents, "index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&group_id=$ag_group&recursion=$recursion&search=$search&sort_field=$sortField&sort=$sort", $offset); if ($agents !== false) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $color=1; $rowPair = true; $iterator = 0; foreach ($agents as $agent) { $id_grupo = $agent["id_grupo"]; if (! check_acl ($config["id_user"], $id_grupo, "AW", $agent['id_agente']) && ! check_acl ($config["id_user"], $id_grupo, "AD", $agent['id_agente'])) continue; if ($color == 1) { $tdcolor = "datos"; $color = 0; } else { $tdcolor = "datos2"; $color = 1; } if ($rowPair) $rowclass = 'rowPair'; else $rowclass = 'rowOdd'; $rowPair = !$rowPair; $iterator++; // Agent name echo ""; echo ""; // Operating System icon echo ""; // Group icon and name echo ""; // Description echo ""; // Action //When there is only one element in page it's necesary go back page. if ((count($agents) == 1) && ($offset >= $config["block_size"])) $offsetArg = $offset - $config["block_size"]; else $offsetArg = $offset; echo ""; } echo "
".__('Agent name') . ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectNameUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectNameDown)) . ''; echo "".__('R')."".__('OS'). ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectOsUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectOsDown)) . ''; echo "".__('Group'). ' ' . '' . html_print_image("images/sort_up.png", true, array("style" => $selectGroupUp)) . '' . '' . html_print_image("images/sort_down.png", true, array("style" => $selectGroupDown)) . ''; echo "" . __('Description') . "" . __('Actions') . "
"; if ($agent["disabled"]) { echo ""; } echo ''; echo ""; if ($agent['quiet']) { html_print_image("images/dot_green.disabled.png", false, array("border" => '0', "title" => __('Quiet'), "alt" => "")); echo " "; } if (check_acl ($config["id_user"], $agent["id_grupo"], "AW")) { $main_tab = 'main'; } else { $main_tab = 'module'; } echo "" . ui_print_truncate_text($agent["nombre"], 'agent_medium', true, true, true, '[…]', 'font-size: 7pt') . ""; echo ""; if ($agent["disabled"]) { ui_print_help_tip(__('Disabled')); echo ""; } echo ''; echo ""; // Has remote configuration ? if (enterprise_installed()) { enterprise_include_once('include/functions_config_agents.php'); if (config_agents_has_remote_configuration($agent["id_agente"])) { echo ""; echo html_print_image("images/application_edit.png", true, array("align" => 'middle', "title" => __('Edit remote config'))); echo ""; } } echo ""; ui_print_os_icon ($agent["id_os"], false); echo "" . ui_print_group_icon ($id_grupo, true)."" . ui_print_truncate_text($agent["comentarios"], 'description', true, true, true, '[…]', 'font-size: 6.5pt;').""; if ($agent['disabled']) { echo "". html_print_image('images/lightbulb_off.png', true, array('alt' => __('Enable agent'), 'title' => __('Enable agent'))) .""; } else { echo "". html_print_image('images/lightbulb.png', true, array('alt' => __('Disable agent'), 'title' => __('Disable agent'))) .""; } if (check_acl ($config["id_user"], $agent["id_grupo"], "AW")) { echo "  '; echo html_print_image('images/cross.png', true, array("border" => '0')) . ""; } echo "
"; ui_pagination ($total_agents, "index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&group_id=$ag_group&search=$search&sort_field=$sortField&sort=$sort", $offset); echo "
"; } else { echo "
" . __('There are no defined agents') . "
"; echo " 
"; } if (check_acl ($config["id_user"], 0, "AW")) { // Create agent button echo '
'; echo '
'; html_print_input_hidden ('new_agent', 1); html_print_submit_button (__('Create agent'), 'crt-2', false, 'class="sub next"'); echo "
"; echo '
'; } echo "
"; ?>