New feature: Add groups to policies
This commit is contained in:
parent
c13644951f
commit
f0e43e252c
|
@ -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;
|
|
@ -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,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 .
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue