Merge branch '2708-API-metaconsola-function-get_agent-no-devuelve-nada' into 'develop'

Added code for function api_get_agent_alias for the API of the metaconsole - #2708

See merge request artica/pandorafms!1816
This commit is contained in:
vgilc 2018-10-25 12:11:16 +02:00
commit 4b317b573b
2 changed files with 24 additions and 13 deletions

View File

@ -28,13 +28,14 @@ require_once($config['homedir'] . '/include/functions_users.php');
* *
* @param int $id_agent The agent id. * @param int $id_agent The agent id.
* @param boolean $show_disabled Show the agent found althought it is disabled. By default false. * @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. * @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( $agent = db_get_value_filter(
'id_agente', 'id_agente',
'tagente', $force_meta ? 'tmetaconsole_agent' : 'tagente',
array('id_agente' => $id_agent, 'disabled' => !$show_disabled) array('id_agente' => $id_agent, 'disabled' => !$show_disabled)
); );
@ -2729,17 +2730,18 @@ function agents_count_agents_filter ($filter = array(), $access = "AR") {
* *
* @param int Id agent * @param int Id agent
* @param string ACL access bit * @param string ACL access bit
* @param boolean $force_meta
* *
* @return True if user has access, false if user has not permissions and * @return True if user has access, false if user has not permissions and
* null if id agent does not exist * 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; 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 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 otherwise
return null; return null;
} }

View File

@ -9279,18 +9279,27 @@ function api_get_agent_id($trash1, $trash2, $data, $returnType) {
* Agent alias for a given id * Agent alias for a given id
* *
* @param int $id_agent * @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 // http://localhost/pandora_console/include/api.php?op=get&op2=agent_alias&id=1&apipass=1234&user=admin&pass=pandora
function api_get_agent_alias($id_agent, $trash1, $trash2, $returnType) { // http://localhost/pandora_console/enterprise/meta/include/api.php?op=get&op2=agent_alias&id=1&id2=1&apipass=1234&user=admin&pass=pandora
if (defined ('METACONSOLE')) { function api_get_agent_alias($id_agent, $id_node, $trash1, $returnType) {
return; $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 $sql = sprintf('SELECT alias
FROM tagente FROM ' . $table_agent_alias . '
WHERE id_agente = %d', $id_agent); WHERE id_agente = %d', $id_agent);
$value = db_get_value_sql($sql); $value = db_get_value_sql($sql);
@ -11481,10 +11490,10 @@ function api_get_cluster_items ($cluster_id){
// AUX FUNCTIONS // 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; 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 === true) return true;
if ($check_agent === false || !check_acl($config['id_user'], 0, $access)) { if ($check_agent === false || !check_acl($config['id_user'], 0, $access)) {