diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php index 670009bf2f..5b97384cb4 100644 --- a/pandora_console/godmode/agentes/modificar_agente.php +++ b/pandora_console/godmode/agentes/modificar_agente.php @@ -343,6 +343,7 @@ if($os != 0){ $search_sql .= " AND id_os = " . $os; } +$user_groups_to_sql = ""; // Show only selected groups if ($ag_group > 0) { $ag_groups = array(); @@ -350,100 +351,38 @@ if ($ag_group > 0) { 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 %s - LIMIT %d, %d', - implode (",", $ag_groups), $search_sql, $order['field'],$order['order'], $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 %s - LIMIT %d OFFSET %d', - implode (",", $ag_groups), $search_sql, $order['field'],$order['order'], $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 %s', - implode (",", $ag_groups), $search_sql, $order['field'],$order['order'], $order['field2'], $order['order']); - $sql = oracle_recode_query ($sql, $set); - break; - } - - $sql_total = sprintf ('SELECT COUNT(*) - FROM tagente - WHERE id_grupo IN (%s) - %s', - implode (",", $ag_groups), $search_sql); - $total_agents = db_get_sql ($sql_total); -} -else { + $user_groups_to_sql = implode (",", $ag_groups); +} 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 %s - LIMIT %d, %d', - implode (',', array_keys ($user_groups)), - $search_sql, $order['field'],$order['order'], $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 %s - LIMIT %d OFFSET %d', - implode (',', array_keys ($user_groups)), - $search_sql, $order['field'],$order['order'], $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 %s', - implode (',', array_keys ($user_groups)), - $search_sql, $order['field'],$order['order'], $order['field2'], $order['order']); - $sql = oracle_recode_query ($sql, $set); - break; - } + $user_groups_to_sql = implode (',', array_keys ($user_groups)); } +$sql = sprintf ('SELECT COUNT(*) + FROM tagente LEFT JOIN tagent_secondary_group tasg + ON tagente.id_agente = tasg.id_agent + WHERE (tagente.id_grupo IN (%s) OR tasg.id_group IN (%s)) + %s', + $user_groups_to_sql, $user_groups_to_sql, + $search_sql); + +$total_agents = db_get_sql ($sql); + +$sql = sprintf ('SELECT * + FROM tagente LEFT JOIN tagent_secondary_group tasg + ON tagente.id_agente = tasg.id_agent + WHERE (tagente.id_grupo IN (%s) OR tasg.id_group IN (%s)) + %s + ORDER BY %s %s, %s %s + LIMIT %d, %d', + $user_groups_to_sql, $user_groups_to_sql, + $search_sql, + $order['field'], $order['order'], $order['field2'], $order['order'], + $offset, $config["block_size"]); + $agents = db_get_all_rows_sql ($sql); // Delete rnum row generated by oracle_recode_query() function @@ -494,13 +433,15 @@ if ($agents !== false) { } /* End Update tagente.remote 0/1 with remote agent function return */ - - $id_grupo = $agent["id_grupo"]; - + + $all_groups = agents_get_all_groups_agent($agent["id_agente"], $agent["id_grupo"]); + $check_aw = check_acl_one_of_groups ($config["id_user"], $all_groups, "AW"); + $check_ad = check_acl_one_of_groups ($config["id_user"], $all_groups, "AD"); + $cluster = db_get_row_sql('select id from tcluster where id_agent = '.$agent['id_agente']); - - if (! check_acl ($config["id_user"], $id_grupo, "AW", $agent['id_agente']) && ! check_acl ($config["id_user"], $id_grupo, "AD", $agent['id_agente'])) - continue; + + // Do not show the agent if there is not enough permissions + if (!$check_aw && !$check_ad) continue; if ($color == 1) { $tdcolor = "datos"; @@ -526,7 +467,7 @@ if ($agents !== false) { echo ''; echo ""; - if (check_acl ($config["id_user"], $agent["id_grupo"], "AW")) { + if ($check_aw) { $main_tab = 'main'; } else { @@ -574,7 +515,7 @@ if ($agents !== false) { } echo '