mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-29 16:55:05 +02:00
Merge branch '713-Asignar-políticas-a-grupos-dev' into 'develop'
713 asignar políticas a grupos dev See merge request !667
This commit is contained in:
commit
ef0e6a2093
@ -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 '';
|
||||
|
||||
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;
|
@ -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`
|
||||
-- ---------------------------------------------------------------------
|
||||
|
@ -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 .
|
||||
|
@ -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
|
||||
|
@ -1196,6 +1196,10 @@ function api_set_update_agent($id_agent, $thrash2, $other, $thrash3) {
|
||||
$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,
|
||||
@ -1217,6 +1221,40 @@ function api_set_update_agent($id_agent, $thrash2, $other, $thrash3) {
|
||||
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)));
|
||||
}
|
||||
@ -1340,6 +1378,18 @@ function api_set_new_agent($thrash1, $thrash2, $other, $thrash3) {
|
||||
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));
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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`
|
||||
-- ---------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user