diff --git a/pandora_console/extensions/module_groups.php b/pandora_console/extensions/module_groups.php index 69838c9fb5..9a4f66935c 100644 --- a/pandora_console/extensions/module_groups.php +++ b/pandora_console/extensions/module_groups.php @@ -128,43 +128,20 @@ function mainModuleGroups() { require_once($config['homedir'] . "/include/functions_users.php"); //The big query - switch ($config["dbtype"]) { - case "mysql": - $sql = "SELECT COUNT(id_agente) AS count, case utimestamp when 0 then 5 else estado end as estado - FROM tagente_estado - WHERE id_agente IN - (SELECT id_agente FROM tagente WHERE id_grupo = %d AND disabled IS FALSE) - AND id_agente_modulo IN - (SELECT id_agente_modulo - FROM tagente_modulo - WHERE id_module_group = %d AND disabled IS FALSE AND delete_pending IS FALSE) - GROUP BY estado"; - break; - case "postgresql": - $sql = "SELECT COUNT(id_agente) AS count, - case utimestamp when 0 then 5 else estado end as estado - FROM tagente_estado - WHERE id_agente IN - (SELECT id_agente FROM tagente WHERE id_grupo = %d AND disabled = 0) - AND id_agente_modulo IN - (SELECT id_agente_modulo - FROM tagente_modulo - WHERE id_module_group = %d AND disabled = 0 AND delete_pending = 0) - GROUP BY estado, utimestamp"; - break; - case "oracle": - $sql = "SELECT COUNT(id_agente) AS count, (case when utimestamp = 0 then 5 else estado end) AS estado - FROM tagente_estado - WHERE id_agente IN - (SELECT id_agente FROM tagente WHERE id_grupo = %d AND (disabled IS NOT NULL AND disabled <> 0)) - AND id_agente_modulo IN - (SELECT id_agente_modulo - FROM tagente_modulo - WHERE id_module_group = %d AND (disabled IS NOT NULL AND disabled <> 0) AND (delete_pending IS NOT NULL AND delete_pending <> 0)) - GROUP BY (case when utimestamp = 0 then 5 else estado end)"; - break; - } - + $sql = "SELECT COUNT(id_agente) AS count, case utimestamp when 0 then 5 else estado end as estado + FROM tagente_estado + WHERE id_agente IN + (SELECT id_agente + FROM tagente ta LEFT JOIN tagent_secondary_group tasg + ON ta.id_agente = tasg.id_agent + WHERE (ta.id_grupo = %d OR tasg.id_group = %d) AND disabled IS FALSE + ) + AND id_agente_modulo IN + (SELECT id_agente_modulo + FROM tagente_modulo + WHERE id_module_group = %d AND disabled IS FALSE AND delete_pending IS FALSE) + GROUP BY estado"; + ui_print_page_header (__("Combined table of agent group and module group"), "images/module_group.png", false, "", false, ''); ui_print_info_message ( array('no_close'=>true, 'message'=> @@ -207,7 +184,7 @@ function mainModuleGroups() { foreach ($modelGroups as $idModelGroup => $modelGroup) { $fired = false; - $query = sprintf($sql, $idAgentGroup, $idModelGroup); + $query = sprintf($sql, $idAgentGroup, $idAgentGroup, $idModelGroup); $rowsDB = db_get_all_rows_sql ($query); diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 43faeb3ca7..ad27ff87f0 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -258,10 +258,7 @@ if(!$new_agent){ } } - $groups = users_get_groups ($config["id_user"], "AR",false); -$agents = agents_get_group_agents (array_keys ($groups)); - $modules = db_get_all_rows_sql("SELECT id_agente_modulo as id_module, nombre as name FROM tagente_modulo WHERE id_agente = " . $id_parent); diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php index 670009bf2f..994b5a69ea 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,39 @@ 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(DISTINCT(tagente.id_agente)) + 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 + GROUP BY tagente.id_agente + 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 +434,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 +468,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 +516,7 @@ if ($agents !== false) { } echo '