diff --git a/pandora_console/extras/mr/4.sql b/pandora_console/extras/mr/4.sql index 75428b2ea3..f189cbce3c 100644 --- a/pandora_console/extras/mr/4.sql +++ b/pandora_console/extras/mr/4.sql @@ -1,2 +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 ''; \ No newline at end of file +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; \ No newline at end of file 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 16b67d8e28..46a6a08a06 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 e2e63b6e62..c804ddc22c 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -239,6 +239,16 @@ if ($create_agent) { $agent_created_ok = true; + $tpolicy_group_old = db_get_all_rows_sql("SELECT id_policy FROM tpolicy_groups + WHERE id_group = ".$grupo); + + 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 . ' IP: ' . $direccion_agente . ' Group: ' . $grupo . @@ -774,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( @@ -788,6 +802,38 @@ if ($update_agent) { // if modified some agent paramenter enterprise_hook('config_agents_update_config_interval', array($id_agente, $intervalo)); } + 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'])); + } + } + } + + $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 . ' ID OS: ' . $id_os . ' Disabled: ' . $disabled . diff --git a/pandora_console/godmode/massive/massive_edit_agents.php b/pandora_console/godmode/massive/massive_edit_agents.php index facdf18b54..802dc67e6b 100755 --- a/pandora_console/godmode/massive/massive_edit_agents.php +++ b/pandora_console/godmode/massive/massive_edit_agents.php @@ -139,9 +139,51 @@ 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_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_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_new = db_get_all_rows_sql("SELECT id_policy FROM tpolicy_groups + WHERE id_group = ".$values['id_grupo']); + + if($tpolicy_group_new){ + foreach ($tpolicy_group_new as $key => $value) { + $tpolicy_agents_new= db_get_sql("SELECT * FROM tpolicy_agents + 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' => $value['id_policy'])); + } + } + } + } } // Update Custom Fields diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index ccadee5349..55828d1d94 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 e7836a358c..3de688c84a 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -385,13 +385,28 @@ function html_print_select_groups($id_user = false, $privilege = "AR", $nothing = '', $nothing_value = 0, $return = false, $multiple = false, $sort = true, $class = '', $disabled = false, $style = false, $option_style = false, $id_group = false, - $keys_field = 'id_grupo', $strict_user = false) { + $keys_field = 'id_grupo', $strict_user = false, $delete_groups = false , $include_groups = false) { global $config; $fields = users_get_groups_for_select($id_user, $privilege, $returnAllGroup, true, $id_group, $keys_field); + + if ($delete_groups && is_array($delete_groups)){ + foreach ($delete_groups as $value) { + unset($fields[$value]); + } + } + + if (is_array($include_groups)){ + $field = array(); + foreach ($include_groups as $value) { + $field[$value] = $fields[$value]; + } + $fields = array_intersect($fields, $field); + } + if ($strict_user) { $fields = users_get_strict_mode_groups($config['id_user'], $returnAllGroup); } diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 9733792280..d176f252dc 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -2168,6 +2168,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` -- ---------------------------------------------------------------------