NetworkMap class

Former-commit-id: 1c5d4f55853928052482f42aca2900d8964929ad
This commit is contained in:
fbsanchez 2019-03-20 17:22:06 +01:00
parent 9b68e7d04e
commit 05c03d2d46
2 changed files with 107 additions and 245 deletions

View File

@ -15,6 +15,8 @@ if (! check_acl($config['id_user'], 0, 'AW')) {
ui_require_css_file('discovery'); ui_require_css_file('discovery');
ui_print_page_header(__('Discovery'), '', false, '', true);
/** /**
* Mask class names. * Mask class names.

View File

@ -1072,268 +1072,127 @@ class NetworkMap
$relations = $this->graph['relations']; $relations = $this->graph['relations'];
$segregation_links = []; $cleaned = [];
$index = 0; $rel_map = [];
$index2 = 0;
$index3 = 0;
$index4 = 0;
foreach ($relations as $rel) {
if (($rel['parent_type'] == NODE_AGENT) && ($rel['child_type'] == NODE_AGENT)) {
$segregation_links['aa'][$index] = $rel;
$index++;
} else if (($rel['parent_type'] == NODE_MODULE) && ($rel['child_type'] == NODE_MODULE)) {
$segregation_links['mm'][$index2] = $rel;
$index2++;
} else if (($rel['parent_type'] == NODE_GENERIC) && ($rel['child_type'] == NODE_GENERIC)) {
$segregation_links['ff'][$index4] = $rel;
$index4++;
} else {
$segregation_links['am'][$index3] = $rel;
$index3++;
}
}
$final_links = [];
// ----------------------------------------------------------------
// --------------------- Clean duplicate links --------------------
// ----------------------------------------------------------------
$duplicated = false;
$index_to_del = 0;
$index = 0;
if (isset($segregation_links['aa']) === true
&& is_array($segregation_links['aa']) === true
) {
foreach ($segregation_links['aa'] as $link) {
foreach ($segregation_links['aa'] as $link2) {
if ($link['id_parent'] == $link2['id_child']
&& $link['id_child'] == $link2['id_parent']
) {
/*
XXX: Verify
* enterprise_hook(
* 'delete_link',
* [$segregation_links['aa'][$index_to_del]]
* );
*/
unset($segregation_links['aa'][$index_to_del]);
}
$index_to_del++;
}
$final_links['aa'][$index] = $link;
$index++;
$duplicated = false;
$index_to_del = 0;
}
}
$duplicated = false;
$index_to_del = 0;
$index2 = 0;
if (isset($segregation_links['mm']) === true
&& is_array($segregation_links['mm']) === true
) {
foreach ($segregation_links['mm'] as $link) {
foreach ($segregation_links['mm'] as $link2) {
if ($link['id_parent'] == $link2['id_child']
&& $link['id_child'] == $link2['id_parent']
) {
/*
XXX: Verify
* enterprise_hook(
* 'delete_link',
* [$segregation_links['mm'][$index_to_del]]
* );
*/
unset($segregation_links['mm'][$index_to_del]);
}
$index_to_del++;
}
$final_links['mm'][$index2] = $link;
$index2++;
$duplicated = false;
$index_to_del = 0;
}
}
$duplicated = false;
$index_to_del = 0;
$index3 = 0;
if (isset($segregation_links['ff']) === true
&& is_array($segregation_links['ff']) === true
) {
foreach ($segregation_links['ff'] as $link) {
foreach ($segregation_links['ff'] as $link2) {
if ($link['id_parent'] == $link2['id_child']
&& $link['id_child'] == $link2['id_parent']
) {
/*
XXX: Verify
* enterprise_hook(
* 'delete_link',
* [$segregation_links['ff'][$index_to_del]]
* );
*/
unset($segregation_links['ff'][$index_to_del]);
}
$index_to_del++;
}
$final_links['ff'][$index3] = $link;
$index3++;
$duplicated = false;
$index_to_del = 0;
}
}
$final_links['am'] = $segregation_links['am'];
/* /*
---------------------------------------------------------------- * Relation map:
----------------- AA, AM and MM links management --------------- * id_child.'_'.id_parent => [
------------------ Priority: ----------------------------------- * 'priority' (0,1)
-------------------- 1 -> MM (module - module) ----------------- * 'relation_index'
-------------------- 2 -> AM (agent - module) ------------------ * ]
-------------------- 3 -> AA (agent - agent) ------------------- */
----------------------------------------------------------------
*/
$final_links2 = []; foreach ($relations as $index => $rel) {
$index = 0; /*
$l3_link = []; * AA, AM and MM links management
$agent1 = 0; * Priority:
$agent2 = 0; * 1 -> MM (module - module)
* 1 -> AM (agent - module)
* 0 -> AA (agent - agent)
*/
if (isset($final_links['mm']) === true $id_parent = $rel['id_parent'];
&& is_array($final_links['mm']) === true $id_child = $rel['id_child'];
) { $rel_type = $rel['child_type'].'_'.$rel['parent_type'];
foreach ($final_links['mm'] as $rel_mm) {
$module_parent = $rel_mm['id_parent_source_data'];
$module_children = $rel_mm['id_child_source_data'];
$agent1 = (int) agents_get_agent_id_by_module_id(
$module_parent
);
$agent2 = (int) agents_get_agent_id_by_module_id(
$module_children
);
foreach ($final_links['aa'] as $key => $rel_aa) {
$l3_link = $rel_aa;
$id_p_source_data = (int) $rel_aa['id_parent_source_data'];
$id_c_source_data = (int) $rel_aa['id_child_source_data'];
if ((($id_p_source_data == $agent1)
&& ($id_c_source_data == $agent2))
|| (($id_p_source_data == $agent2)
&& ($id_c_source_data == $agent1))
) {
enterprise_hook(
'delete_link',
[$final_links['aa'][$key]]
);
unset($final_links['aa'][$key]); $valid = 0;
$key = -1;
if ($rel['parent_type'] == NODE_MODULE
&& $rel['child_type'] == NODE_MODULE
) {
// Module information available.
$priority = 1;
$valid = 1;
if (is_array($rel_map[$id_child.'_'.$id_parent])) {
// Already defined.
$key = $id_child.'_'.$id_parent;
$data = $rel_map[$id_child.'_'.$id_parent];
if ($priority > $data['priority']) {
unset($rel[$data['index']]);
} else {
$valid = 0;
} }
} }
}
}
$final_links2['aa'] = $final_links['aa']; if (is_array($rel_map[$id_parent.'_'.$id_child])) {
$final_links2['mm'] = $final_links['mm']; // Already defined.
$final_links2['am'] = $final_links['am']; $key = $id_parent.'_'.$id_child;
$final_links2['ff'] = $final_links['ff']; $data = $rel_map[$id_parent.'_'.$id_child];
if ($priority > $data['priority']) {
$same_m = []; unset($rel[$data['index']]);
$index = 0; } else {
if (isset($final_links2['am']) === true $valid = 0;
&& is_array($final_links2['am']) === true
) {
foreach ($final_links2['am'] as $rel_am) {
foreach ($final_links2['am'] as $rel_am2) {
if (($rel_am['id_child_source_data'] == $rel_am2['id_child_source_data'])
&& ($rel_am['id_parent_source_data'] != $rel_am2['id_parent_source_data'])
) {
$same_m[$index]['rel'] = $rel_am2;
$same_m[$index]['agent_parent'] = $rel_am['id_parent_source_data'];
$index++;
} }
} }
}
}
$final_links3 = []; if ($valid == 1) {
$index = 0; $rel_map[$id_parent.'_'.$id_child] = [
$l3_link = []; 'index' => $index,
$have_l3 = false; 'priority' => $priority,
if (isset($final_links2['aa']) === true ];
&& is_array($final_links2['aa']) === true }
) { } else if ($rel['parent_type'] == NODE_AGENT
foreach ($final_links2['aa'] as $key => $rel_aa) { && $rel['child_type'] == NODE_AGENT
$l3_link = $rel_aa; ) {
foreach ($same_m as $rel_am) { // Module information not available.
if ((($rel_aa['id_parent_source_data'] == $rel_am['parent']['id_parent_source_data']) $priority = 0;
&& ($rel_aa['id_child_source_data'] == $rel_am['rel']['id_parent_source_data'])) $valid = 1;
|| (($rel_aa['id_child_source_data'] == $rel_am['parent']['id_parent_source_data'])
&& ($rel_aa['id_parent_source_data'] == $rel_am['rel']['id_parent_source_data']))
) {
enterprise_hook(
'delete_link',
[$final_links2['aa'][$key]]
);
unset($final_links2['aa'][$key]); if (is_array($rel_map[$id_child.'_'.$id_parent])) {
// Already defined.
$key = $id_child.'_'.$id_parent;
$data = $rel_map[$id_child.'_'.$id_parent];
if ($priority > $data['priority']) {
unset($rel[$data['index']]);
} else {
$valid = 0;
} }
} }
if (is_array($rel_map[$id_parent.'_'.$id_child])) {
// Already defined.
$key = $id_parent.'_'.$id_child;
$data = $rel_map[$id_parent.'_'.$id_child];
if ($priority > $data['priority']) {
unset($rel[$data['index']]);
} else {
$valid = 0;
}
}
if ($valid == 1) {
$rel_map[$id_parent.'_'.$id_child] = [
'index' => $index,
'priority' => $priority,
];
}
} else if ($rel['parent_type'] == NODE_MODULE
&& $rel['child_type'] == NODE_AGENT
) {
// Module information not available.
$priority = 1;
$valid = 1;
} else if ($rel['parent_type'] == NODE_AGENT
&& $rel['child_type'] == NODE_MODULE
) {
// Module information not available.
$priority = 1;
$valid = 1;
} else {
// Pandora & generic links are always accepted.
$valid = 1;
}
if ($valid === 1) {
$cleaned[] = $rel;
} }
} }
$final_links3['aa'] = $final_links2['aa']; $this->graph['relations'] = $cleaned;
$final_links3['mm'] = $segregation_links['mm'];
$final_links3['am'] = $segregation_links['am'];
$final_links3['ff'] = $final_links2['ff'];
$cleaned_links = [];
if (isset($final_links3['aa']) === true
&& is_array($final_links3['aa']) === true
) {
foreach ($final_links3['aa'] as $link) {
$cleaned_links[] = $link;
}
}
if (isset($final_links3['am']) === true
&& is_array($final_links3['am']) === true
) {
foreach ($final_links3['am'] as $link) {
$cleaned_links[] = $link;
}
}
if (isset($final_links3['mm']) === true
&& is_array($final_links3['mm']) === true
) {
foreach ($final_links3['mm'] as $link) {
$cleaned_links[] = $link;
}
}
if (isset($final_links3['ff']) === true
&& is_array($final_links3['ff']) === true
) {
foreach ($final_links3['ff'] as $link) {
$cleaned_links[] = $link;
}
}
$this->graph['relations'] = $cleaned_links;
} }
@ -3040,6 +2899,7 @@ class NetworkMap
$minimap_display = ''; $minimap_display = '';
if ($this->mapOptions['pure']) { if ($this->mapOptions['pure']) {
$minimap_display = 'none'; $minimap_display = 'none';
$minimap_display = '';
} }
$networkmap = $this->map; $networkmap = $this->map;