New networmaps in progress... (Fixed open map with interfaces)

This commit is contained in:
Arturo Gonzalez 2016-09-27 11:43:57 +02:00
parent 446063dd51
commit 30d30df548
2 changed files with 119 additions and 45 deletions

View File

@ -1302,29 +1302,6 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
// Create void statistics array // Create void statistics array
$stats = array(); $stats = array();
// Create nodes
foreach ($nodes as $node_id => $node) {
if ($center > 0 && ! networkmap_is_descendant ($node_id, $center, $parents)) {
unset ($parents[$node_id]);
unset ($orphans[$node_id]);
unset ($nodes[$node_id]);
continue;
}
switch ($node['type']) {
case 'agent':
$graph .= networkmap_create_agent_node($node, $simple,
$font_size, $cut_names, $relative) . "\n\t\t";
$stats['agents'][] = $node['id_agente'];
break;
case 'module':
$graph .= networkmap_create_module_node($node, $simple,
$font_size) . "\n\t\t";
$stats['modules'][] = $node['id_agente_modulo'];
break;
}
}
if ($l2_network || $old_mode) { if ($l2_network || $old_mode) {
$count = 0; $count = 0;
$group_nodes = 10; $group_nodes = 10;
@ -1355,6 +1332,29 @@ function networkmap_generate_dot ($pandora_name, $group = 0,
} }
} }
// Create nodes
foreach ($nodes as $node_id => $node) {
if ($center > 0 && ! networkmap_is_descendant ($node_id, $center, $parents)) {
unset ($parents[$node_id]);
unset ($orphans[$node_id]);
unset ($nodes[$node_id]);
continue;
}
switch ($node['type']) {
case 'agent':
$graph .= networkmap_create_agent_node($node, $simple,
$font_size, $cut_names, $relative) . "\n\t\t";
$stats['agents'][] = $node['id_agente'];
break;
case 'module':
$graph .= networkmap_create_module_node($node, $simple,
$font_size) . "\n\t\t";
$stats['modules'][] = $node['id_agente_modulo'];
break;
}
}
// Define edges // Define edges
foreach ($parents as $node => $parent_id) { foreach ($parents as $node => $parent_id) {
// Verify that the parent is in the graph // Verify that the parent is in the graph

View File

@ -171,6 +171,7 @@ function networkmap_process_networkmap($id = 0) {
unlink($filename_plain); unlink($filename_plain);
$nodes_and_relations = array(); $nodes_and_relations = array();
$nodes_and_relations['l2_network'] = $l2_network_interfaces;
if (enterprise_installed()) { if (enterprise_installed()) {
enterprise_include_once("include/functions_pandora_networkmap.php"); enterprise_include_once("include/functions_pandora_networkmap.php");
@ -189,7 +190,7 @@ function networkmap_process_networkmap($id = 0) {
$style['height'] = $node['height']; $style['height'] = $node['height'];
$style['label'] = $node['text']; $style['label'] = $node['text'];
$nodes_and_relations['nodes'][$index]['style'] = json_encode($style); $nodes_and_relations['nodes'][$index]['style'] = json_encode($style);
if ($node['type'] == 'agent') { if (($node['type'] == 'agent') || ($node['type'] == '')) {
$nodes_and_relations['nodes'][$index]['source_data'] = $node['id_agent']; $nodes_and_relations['nodes'][$index]['source_data'] = $node['id_agent'];
$nodes_and_relations['nodes'][$index]['type'] = 0; $nodes_and_relations['nodes'][$index]['type'] = 0;
} }
@ -205,15 +206,56 @@ function networkmap_process_networkmap($id = 0) {
$nodes_and_relations['relations'] = array(); $nodes_and_relations['relations'] = array();
foreach ($relation_nodes as $relation) { foreach ($relation_nodes as $relation) {
$nodes_and_relations['relations'][$index]['id_map'] = $id; $nodes_and_relations['relations'][$index]['id_map'] = $id;
$nodes_and_relations['relations'][$index]['id_parent'] = $relation['id_parent'];
$nodes_and_relations['relations'][$index]['id_child'] = $relation['id_child']; if ($l2_network_interfaces) {
$nodes_and_relations['relations'][$index]['parent_type'] = $relation['parent_type']; if (($relation['parent_type'] == 'agent') || ($relation['parent_type'] == '')) {
$nodes_and_relations['relations'][$index]['child_type'] = $relation['child_type']; $nodes_and_relations['relations'][$index]['id_parent'] = $relation['id_parent'];
$nodes_and_relations['relations'][$index]['parent_type'] = 0;
}
else if ($relation['parent_type'] == 'module') {
$nodes_and_relations['relations'][$index]['id_parent'] = $nodes[$relation['id_parent']]['id_module'];
$nodes_and_relations['relations'][$index]['parent_type'] = 1;
}
if (($relation['child_type'] == 'agent') || ($relation['child_type'] == '')) {
$nodes_and_relations['relations'][$index]['id_child'] = $relation['id_child'];
$nodes_and_relations['relations'][$index]['child_type'] = 0;
}
else if ($relation['child_type'] == 'module') {
$nodes_and_relations['relations'][$index]['id_child'] = $nodes[$relation['id_child']]['id_module'];
$nodes_and_relations['relations'][$index]['child_type'] = 1;
}
}
else {
$nodes_and_relations['relations'][$index]['id_parent'] = $nodes[$relation['id_parent']]['id_agent'];
$nodes_and_relations['relations'][$index]['id_child'] = $nodes[$relation['id_child']]['id_agent'];
if (($relation['parent_type'] == 'agent') || ($relation['parent_type'] == '')) {
$nodes_and_relations['relations'][$index]['parent_type'] = 0;
}
else if ($relation['parent_type'] == 'module') {
$nodes_and_relations['relations'][$index]['parent_type'] = 1;
}
if (($relation['child_type'] == 'agent') || ($relation['child_type'] == '')) {
$nodes_and_relations['relations'][$index]['child_type'] = 0;
}
else if ($relation['child_type'] == 'module') {
$nodes_and_relations['relations'][$index]['child_type'] = 1;
}
}
$index++; $index++;
} }
$index = 0;
foreach ($nodes_and_relations['relations'] as $relation) {
if ($relation['id_parent'] == -1) {
$nodes_and_relations['relations'][$index]['id_parent'] = 0;
}
$index++;
}
$center = array('x' => 500, 'y' => 500); $center = array('x' => 500, 'y' => 500);
} }
$networkmap['center_x'] = $center['x']; $networkmap['center_x'] = $center['x'];
$networkmap['center_y'] = $center['y']; $networkmap['center_y'] = $center['y'];
db_process_sql_update('tmap', db_process_sql_update('tmap',
@ -407,13 +449,19 @@ function networkmap_clean_relations_for_js(&$relations) {
while (!$cleaned); while (!$cleaned);
} }
function networkmap_links_to_js_links($relations, $nodes_graph) { function networkmap_links_to_js_links($relations, $nodes_graph, $l2_network = false) {
$return = array(); $return = array();
foreach ($relations as $relation) { foreach ($relations as $relation) {
if (($relation['parent_type'] == 1) && ($relation['child_type'] == 1)) { if (($relation['parent_type'] == 1) && ($relation['child_type'] == 1)) {
$id_module1 = $relation['id_agent_parent']; if (enterprise_installed()) {
$id_module2 = $relation['id_agent_child']; $id_module1 = $relation['id_agent_parent'];
$id_module2 = $relation['id_agent_child'];
}
else {
$id_module1 = $relation['id_parent'];
$id_module2 = $relation['id_child'];
}
$id_agent1 = agents_get_agent_id_by_module_id($id_module1); $id_agent1 = agents_get_agent_id_by_module_id($id_module1);
$id_agent2 = agents_get_agent_id_by_module_id($id_module2); $id_agent2 = agents_get_agent_id_by_module_id($id_module2);
foreach ($nodes_graph as $node) { foreach ($nodes_graph as $node) {
@ -446,12 +494,20 @@ function networkmap_links_to_js_links($relations, $nodes_graph) {
} }
} }
else { else {
foreach ($nodes_graph as $node) { if (($relation['parent_type'] == 1) && ($relation['child_type'] == 1)) {
if ($node['id_agent'] == $relation['id_parent']) { $id_target_a = agents_get_agent_id_by_module_id($relation['id_parent']);
$id_target = $node['id_agent']; $id_source_a = agents_get_agent_id_by_module_id($relation['id_child']);
} $id_target = $relation['id_parent'];
else if ($node['id_agent'] == $relation['id_child']) { $id_source = $relation['id_child'];
$id_source = $node['id_agent']; }
else {
foreach ($nodes_graph as $node) {
if ($node['id_agent'] == $relation['id_parent']) {
$id_target_a = $node['id_agent'];
}
else if ($node['id_agent'] == $relation['id_child']) {
$id_source_a = $node['id_agent'];
}
} }
} }
} }
@ -512,11 +568,29 @@ function networkmap_links_to_js_links($relations, $nodes_graph) {
} }
} }
else { else {
if ($node['id'] == $relation['id_parent']) { if ($l2_network) {
$item['target'] = $node['id']; $agent1 = agents_get_agent_id_by_module_id($relation['id_parent']);
$agent2 = agents_get_agent_id_by_module_id($relation['id_child']);
if (($node['id_agent'] == $agent1) && ($node['id_module'] == "")) {
$item['target'] = $node['id'];
}
else if (($node['id_agent'] == $agent2) && ($node['id_module'] == "")) {
$item['source'] = $node['id'];
}
} }
else if ($node['id'] == $relation['id_child']) { else {
$item['source'] = $node['id']; $agent1 = $relation['id_parent'];
$agent2 = $relation['id_child'];
if ($agent1 == 0) {
$item['target'] = 0;
}
else if (($node['id_agent'] == $agent1) && ($node['id_module'] == "")) {
$item['target'] = $node['id'];
}
if (($node['id_agent'] == $agent2) && ($node['id_module'] == "")) {
$item['source'] = $node['id'];
}
} }
} }
} }
@ -616,7 +690,7 @@ function networkmap_write_js_array($id, $nodes_and_relations = array()) {
//interfaces //interfaces
networkmap_clean_relations_for_js($relations); networkmap_clean_relations_for_js($relations);
$links_js = networkmap_links_to_js_links($relations, $nodes_graph); $links_js = networkmap_links_to_js_links($relations, $nodes_graph, $nodes_and_relations['l2_network']);
foreach ($links_js as $link_js) { foreach ($links_js as $link_js) {
if ($link_js['target'] == -1) if ($link_js['target'] == -1)