diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 45c72b2b83..5691750c69 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -28,13 +28,14 @@ require_once($config['homedir'] . '/include/functions_users.php'); * * @param int $id_agent The agent id. * @param boolean $show_disabled Show the agent found althought it is disabled. By default false. + * @param boolean $force_meta * * @return boolean The result to check if the agent is in the DB. */ -function agents_check_agent_exists($id_agent, $show_disabled = true) { +function agents_check_agent_exists($id_agent, $show_disabled = true, $force_meta = false) { $agent = db_get_value_filter( 'id_agente', - 'tagente', + $force_meta ? 'tmetaconsole_agent' : 'tagente', array('id_agente' => $id_agent, 'disabled' => !$show_disabled) ); @@ -2735,17 +2736,18 @@ function agents_count_agents_filter ($filter = array(), $access = "AR") { * * @param int Id agent * @param string ACL access bit + * @param boolean $force_meta * * @return True if user has access, false if user has not permissions and * null if id agent does not exist */ -function agents_check_access_agent ($id_agent, $access = "AR") { +function agents_check_access_agent ($id_agent, $access = "AR", $force_meta = false) { global $config; - if (users_access_to_agent($id_agent, $access)) return true; + if (users_access_to_agent($id_agent, $access, false, $force_meta)) return true; // If agent exist return false - if (agents_check_agent_exists($id_agent)) return false; + if (agents_check_agent_exists($id_agent, true, $force_meta)) return false; // Return null otherwise return null; } diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 189cc4203b..ca08e773c0 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -9186,18 +9186,27 @@ function api_get_agent_id($trash1, $trash2, $data, $returnType) { * Agent alias for a given id * * @param int $id_agent + * @param int $id_node Only for metaconsole + * @param $thrash1 Don't use. + * @param $returnType * **/ -// http://localhost/pandora_console/include/api.php?op=get&op2=agent_name&id=1&apipass=1234&user=admin&pass=pandora -function api_get_agent_alias($id_agent, $trash1, $trash2, $returnType) { - if (defined ('METACONSOLE')) { - return; +// http://localhost/pandora_console/include/api.php?op=get&op2=agent_alias&id=1&apipass=1234&user=admin&pass=pandora +// http://localhost/pandora_console/enterprise/meta/include/api.php?op=get&op2=agent_alias&id=1&id2=1&apipass=1234&user=admin&pass=pandora +function api_get_agent_alias($id_agent, $id_node, $trash1, $returnType) { + $table_agent_alias = 'tagente'; + $force_meta=false; + + if (is_metaconsole()) { + $table_agent_alias = 'tmetaconsole_agent'; + $force_meta = true; + $id_agent = db_get_value_sql("SELECT id_agente FROM tmetaconsole_agent WHERE id_tagente = $id_agent AND id_tmetaconsole_setup = $id_node"); } - if (!util_api_check_agent_and_print_error($id_agent, $returnType)) return; + if (!util_api_check_agent_and_print_error($id_agent, $returnType, 'AR', $force_meta)) return; $sql = sprintf('SELECT alias - FROM tagente + FROM ' . $table_agent_alias . ' WHERE id_agente = %d', $id_agent); $value = db_get_value_sql($sql); @@ -11383,10 +11392,10 @@ function api_get_cluster_items ($cluster_id){ // AUX FUNCTIONS ///////////////////////////////////////////////////////////////////// -function util_api_check_agent_and_print_error($id_agent, $returnType, $access = "AR") { +function util_api_check_agent_and_print_error($id_agent, $returnType, $access = "AR", $force_meta = false) { global $config; - $check_agent = agents_check_access_agent($id_agent, $access); + $check_agent = agents_check_access_agent($id_agent, $access, $force_meta); if ($check_agent === true) return true; if ($check_agent === false || !check_acl($config['id_user'], 0, $access)) {