diff --git a/pandora_console/extras/mr/4.sql b/pandora_console/extras/mr/4.sql new file mode 100644 index 0000000000..828b770c90 --- /dev/null +++ b/pandora_console/extras/mr/4.sql @@ -0,0 +1,17 @@ +START TRANSACTION; + +alter table tusuario add autorefresh_white_list text not null default ''; +ALTER TABLE tserver_export MODIFY name varchar(600) BINARY NOT NULL default ''; + +CREATE TABLE IF NOT EXISTS `tpolicy_groups` ( + `id` int(10) unsigned NOT NULL auto_increment, + `id_policy` int(10) unsigned default '0', + `id_group` int(10) unsigned default '0', + `policy_applied` tinyint(1) unsigned default '0', + `pending_delete` tinyint(1) unsigned default '0', + `last_apply_utimestamp` int(10) unsigned NOT NULL default 0, + PRIMARY KEY (`id`), + UNIQUE (`id_policy`, `id_group`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +COMMIT; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index 588a68da48..6b2577e051 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -181,6 +181,20 @@ CREATE TABLE IF NOT EXISTS `tpolicy_agents` ( UNIQUE (`id_policy`, `id_agent`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- ----------------------------------------------------- +-- Table `tpolicy_groups` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tpolicy_groups` ( + `id` int(10) unsigned NOT NULL auto_increment, + `id_policy` int(10) unsigned default '0', + `id_group` int(10) unsigned default '0', + `policy_applied` tinyint(1) unsigned default '0', + `pending_delete` tinyint(1) unsigned default '0', + `last_apply_utimestamp` int(10) unsigned NOT NULL default 0, + PRIMARY KEY (`id`), + UNIQUE (`id_policy`, `id_group`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + -- --------------------------------------------------------------------- -- Table `tdashboard` -- --------------------------------------------------------------------- diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 5e965d2348..f86ba0849e 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -239,12 +239,14 @@ if ($create_agent) { $agent_created_ok = true; - $tpolicy_group = db_get_sql("SELECT id_policy FROM tpolicy_groups + $tpolicy_group_old = db_get_all_rows_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)); + + if($tpolicy_group_old){ + foreach ($tpolicy_group_old as $key => $old_group) { + db_process_sql_insert ('tpolicy_agents', + array('id_policy' => $old_group['id_policy'], 'id_agent' => $id_agente)); + } } $info = 'Name: ' . $nombre_agente . @@ -782,6 +784,10 @@ if ($update_agent) { // if modified some agent paramenter $values['update_module_count'] = 1; // Force an update of the agent cache. } + $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); + $result = db_process_sql_update ('tagente', $values, array ('id_agente' => $id_agente)); if ($result === false) { ui_print_error_message( @@ -795,28 +801,20 @@ 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_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'])); - } + 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); @@ -834,7 +832,6 @@ if ($update_agent) { // if modified some agent paramenter array ('id_agent' => $id_agente, 'id_policy' => $value['id_policy'])); } } - } $info = 'Group: ' . $grupo . ' Interval: ' . $intervalo . diff --git a/pandora_console/godmode/massive/massive_edit_agents.php b/pandora_console/godmode/massive/massive_edit_agents.php index 647b1f3226..802dc67e6b 100755 --- a/pandora_console/godmode/massive/massive_edit_agents.php +++ b/pandora_console/godmode/massive/massive_edit_agents.php @@ -149,51 +149,41 @@ if ($update_agents) { 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); + $tpolicy_group_old = db_get_all_rows_sql("SELECT id_policy FROM tpolicy_groups + WHERE id_group = ".$group_old); - if($tpolicy_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 = ".$tpolicy_group_old . " AND id_agent =" .$id_agent); - + WHERE id_policy = ".$value['id_policy'] . " 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)); + array ('id_agent' => $id_agent, 'id_policy' => $value['id_policy'])); } - } - - $tpolicy_group_new = db_get_sql("SELECT id_policy FROM tpolicy_groups - WHERE id_group = ".$values['id_grupo']); + } + + $tpolicy_group_new = db_get_all_rows_sql("SELECT id_policy FROM tpolicy_groups + WHERE id_group = ".$values['id_grupo']); - if($tpolicy_group_new){ + if($tpolicy_group_new){ + foreach ($tpolicy_group_new as $key => $value) { $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){ + WHERE id_policy = ".$value['id_policy'] . " AND id_agent =" .$id_agent); + + if(!$tpolicy_agents_new){ + db_process_sql_insert ('tpolicy_agents', + array('id_policy' => $value['id_policy'], 'id_agent' => $id_agent)); + } else { $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)); + array ('id_agent' => $id_agent, 'id_policy' => $value['id_policy'])); } } - + } } - - // 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 diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 89fb8843da..657807e533 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -1195,7 +1195,11 @@ function api_set_update_agent($id_agent, $thrash2, $other, $thrash3) { else { $cascadeProtectionModule = 0; } - + + $group_old = db_get_sql("SELECT id_grupo FROM tagente WHERE id_agente =" .$id_agent); + $tpolicy_group_old = db_get_all_rows_sql("SELECT id_policy FROM tpolicy_groups + WHERE id_group = ".$group_old); + $return = db_process_sql_update('tagente', array('alias' => $alias, 'direccion' => $ip, @@ -1216,6 +1220,40 @@ function api_set_update_agent($id_agent, $thrash2, $other, $thrash3) { // register ip for this agent in 'taddress' agents_add_address ($id_agent, $ip); } + + if($return){ + 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_agent); + + if($tpolicy_agents_old){ + $result2 = db_process_sql_update ('tpolicy_agents', + array('pending_delete' => 1), + array ('id_agent' => $id_agent, 'id_policy' => $value['id_policy'])); + } + } + } + + $tpolicy_group = db_get_all_rows_sql("SELECT id_policy FROM tpolicy_groups + WHERE id_group = ".$idGroup); + + 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_agent); + + if(!$tpolicy_agents){ + db_process_sql_insert ('tpolicy_agents', + array('id_policy' => $value['id_policy'], 'id_agent' => $id_agent)); + } else { + $result3 = db_process_sql_update ('tpolicy_agents', + array('pending_delete' => 0), + array ('id_agent' => $id_agent, 'id_policy' => $value['id_policy'])); + } + } + } + } returnData('string', array('type' => 'string', 'data' => (int)((bool)$return))); @@ -1339,7 +1377,19 @@ function api_set_new_agent($thrash1, $thrash2, $other, $thrash3) { // register ip for this agent in 'taddress' agents_add_address ($idAgente, $ip); } - + + if($idGroup && !empty($idAgente)){ + $tpolicy_group_old = db_get_all_rows_sql("SELECT id_policy FROM tpolicy_groups + WHERE id_group = ".$idGroup); + + if($tpolicy_group_old){ + foreach ($tpolicy_group_old as $key => $old_group) { + db_process_sql_insert ('tpolicy_agents', + array('id_policy' => $old_group['id_policy'], 'id_agent' => $idAgente)); + } + } + } + returnData('string', array('type' => 'string', 'data' => $idAgente)); } diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 797660534c..c374170c36 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -404,7 +404,7 @@ function html_print_select_groups($id_user = false, $privilege = "AR", foreach ($include_groups as $value) { $field[$value] = $fields[$value]; } - $fields = $field; + $fields = array_intersect($fields, $field); } if ($strict_user) { diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 471b64e048..d8749dc075 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -2482,7 +2482,6 @@ CREATE TABLE IF NOT EXISTS `tpolicy_queue` ( `id` int(10) unsigned NOT NULL auto_increment, `id_policy` int(10) unsigned NOT NULL default '0', `id_agent` int(10) unsigned NOT NULL default '0', - `id_group` int(10) unsigned NOT NULL default '0', `operation` varchar(15) default '', `progress` int(10) unsigned NOT NULL default '0', `end_utimestamp` int(10) unsigned NOT NULL default 0,