From c13644951f4e14b74b0ae50e1da9dc382052589d Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Mon, 17 Jul 2017 09:22:28 +0200 Subject: [PATCH] update agent --- .../godmode/agentes/configurar_agente.php | 49 +++++++++++++++++ .../godmode/massive/massive_edit_agents.php | 52 +++++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 4484e6a1ba..5e965d2348 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -239,6 +239,14 @@ if ($create_agent) { $agent_created_ok = true; + $tpolicy_group = db_get_sql("SELECT id_policy FROM tpolicy_groups + WHERE id_group = ".$grupo); + + if($tpolicy_group){ + db_process_sql_insert ('tpolicy_agents', + array('id_policy' => $tpolicy_group, 'id_agent' => $id_agente)); + } + $info = 'Name: ' . $nombre_agente . ' IP: ' . $direccion_agente . ' Group: ' . $grupo . @@ -787,6 +795,47 @@ if ($update_agent) { // if modified some agent paramenter if ($old_interval != $intervalo) { enterprise_hook('config_agents_update_config_interval', array($id_agente, $intervalo)); } + + if($grupo){ + $group_old = db_get_sql("SELECT id_grupo FROM tagente WHERE id_agente =" .$id_agente); + + $tpolicy_group_old = db_get_all_rows_sql("SELECT id_policy FROM tpolicy_groups + WHERE id_group = ".$group_old); + + if($tpolicy_group_old){ + foreach ($tpolicy_group_old as $key => $value) { + $tpolicy_agents_old= db_get_sql("SELECT * FROM tpolicy_agents + WHERE id_policy = ".$value['id_policy'] . " AND id_agent =" .$id_agente); + + if($tpolicy_agents_old){ + $result2 = db_process_sql_update ('tpolicy_agents', + array('pending_delete' => 1), + array ('id_agent' => $id_agente, 'id_policy' => $value['id_policy'])); + } + } + } + } + + //pruebassssss + $tpolicy_group = db_get_all_rows_sql("SELECT id_policy FROM tpolicy_groups + WHERE id_group = ".$grupo); + + if($tpolicy_group){ + foreach ($tpolicy_group as $key => $value) { + $tpolicy_agents= db_get_sql("SELECT * FROM tpolicy_agents + WHERE id_policy = ".$value['id_policy'] . " AND id_agent =" .$id_agente); + + if(!$tpolicy_agents){ + db_process_sql_insert ('tpolicy_agents', + array('id_policy' => $value['id_policy'], 'id_agent' => $id_agente)); + } else { + $result3 = db_process_sql_update ('tpolicy_agents', + array('pending_delete' => 0), + array ('id_agent' => $id_agente, 'id_policy' => $value['id_policy'])); + } + } + + } $info = 'Group: ' . $grupo . ' Interval: ' . $intervalo . ' Comments: ' . $comentarios . ' Mode: ' . $modo . diff --git a/pandora_console/godmode/massive/massive_edit_agents.php b/pandora_console/godmode/massive/massive_edit_agents.php index facdf18b54..647b1f3226 100755 --- a/pandora_console/godmode/massive/massive_edit_agents.php +++ b/pandora_console/godmode/massive/massive_edit_agents.php @@ -139,9 +139,61 @@ if ($update_agents) { isset($values['id_grupo'])) { $values['update_module_count'] = 1; // Force an update of the agent cache. } + $group_old = false; + if($values['id_grupo']){ + $group_old = db_get_sql("SELECT id_grupo FROM tagente WHERE id_agente =" .$id_agent); + } + $result = db_process_sql_update ('tagente', $values, array ('id_agente' => $id_agent)); + + if($group_old || $result){ + $tpolicy_group_old = db_get_sql("SELECT id_policy FROM tpolicy_groups + WHERE id_group = ".$group_old); + + if($tpolicy_group_old){ + $tpolicy_agents_old= db_get_sql("SELECT * FROM tpolicy_agents + WHERE id_policy = ".$tpolicy_group_old . " AND id_agent =" .$id_agent); + + if($tpolicy_agents_old){ + $result2 = db_process_sql_update ('tpolicy_agents', + array('pending_delete' => 1), + array ('id_agent' => $id_agent, 'id_policy' => $tpolicy_group_old)); + } + + } + + $tpolicy_group_new = db_get_sql("SELECT id_policy FROM tpolicy_groups + WHERE id_group = ".$values['id_grupo']); + + if($tpolicy_group_new){ + $tpolicy_agents_new= db_get_sql("SELECT * FROM tpolicy_agents + WHERE id_policy = ".$tpolicy_group_new . " AND id_agent =" .$id_agent); + + if($tpolicy_agents_new){ + $result3 = db_process_sql_update ('tpolicy_agents', + array('pending_delete' => 0), + array ('id_agent' => $id_agent, 'id_policy' => $tpolicy_group_new)); + } else { + db_process_sql_insert ('tpolicy_agents', + array('id_policy' => $tpolicy_group_new, 'id_agent' => $id_agent)); + } + } + + } + + // if($values['id_grupo'] || $result){ + // $tpolicy_agents= db_get_sql("SELECT * FROM tpolicy_agents + // WHERE id_policy = ".$tpolicy_group . " AND id_agent =" .$id_agente); + // + // $tpolicy_group = db_get_sql("SELECT id_policy FROM tpolicy_groups + // WHERE id_group = ".$values['id_grupo']); + // if ($tpolicy_group){ + // + // } + // } + } // Update Custom Fields