Added empty networkmap functions

This commit is contained in:
Arturo Gonzalez 2017-10-31 13:17:51 +01:00
parent 4e672cc758
commit 1a04e6085a
2 changed files with 409 additions and 161 deletions

View File

@ -43,7 +43,7 @@ function networkmap_process_networkmap($id = 0) {
$networkmap = db_get_row_filter('tmap',
array('id' => $id));
$filter = json_decode($networkmap['filter'], true);
$map_filter = json_decode($networkmap['filter'], true);
$pure = (int)get_parameter('pure', 0);
@ -99,6 +99,115 @@ function networkmap_process_networkmap($id = 0) {
if (enterprise_installed() && ($numNodes > 0)) {
$nodes_and_relations = get_structure_nodes($id);
}
else {
if ($map_filter['empty_map']) {
// Open Graph
$graph = networkmap_open_graph ($layout, $nooverlap, $pure, $zoom,
$ranksep, $font_size, null);
$graph .= networkmap_create_pandora_node (__('Pandora FMS'), $font_size, $simple);
$graph .= networkmap_close_graph ();
switch (PHP_OS) {
case "WIN32":
case "WINNT":
case "Windows":
$filename_dot = sys_get_temp_dir() . "\\networkmap_" . $filter;
break;
default:
$filename_dot = sys_get_temp_dir() . "/networkmap_" . $filter;
break;
}
if ($simple) {
$filename_dot .= "_simple";
}
if ($nooverlap) {
$filename_dot .= "_nooverlap";
}
$filename_dot .= "_" . $id . ".dot";
file_put_contents($filename_dot, $graph);
switch (PHP_OS) {
case "WIN32":
case "WINNT":
case "Windows":
$filename_plain = sys_get_temp_dir() . "\\plain.txt";
$cmd = io_safe_output($config['graphviz_bin_dir'] . "\\$filter.exe -Tplain -o " . $filename_plain . " " .
$filename_dot);
break;
default:
$filename_plain = sys_get_temp_dir() . "/plain.txt";
$cmd = "$filter -Tplain -o " . $filename_plain . " " .
$filename_dot;
break;
}
system ($cmd);
unlink($filename_dot);
$nodes = networkmap_loadfile($id, $filename_plain,
$relation_nodes, $graph);
unlink($filename_plain);
//Set the position of modules
foreach ($nodes as $key => $node) {
if ($node['type'] == 'module') {
//Search the agent of this module for to get the
//position
foreach ($nodes as $key2 => $node2) {
if ($node2['id_agent'] != 0 && $node2['type'] == 'agent') {
if ($node2['id_agent'] == $node['id_agent']) {
$nodes[$key]['coords'][0] =
$nodes[$key2]['coords'][0] + $node['height'] / 2;
$nodes[$key]['coords'][1] =
$nodes[$key2]['coords'][1] + $node['width'] / 2;
}
}
}
}
}
$nodes_and_relations['nodes'] = array();
$index = 0;
foreach ($nodes as $key => $node) {
$nodes_and_relations['nodes'][$index]['id_map'] = $id;
$nodes_and_relations['nodes'][$index]['x'] = (int)$node['coords'][0];
$nodes_and_relations['nodes'][$index]['y'] = (int)$node['coords'][1];
if (($node['type'] == 'agent') || ($node['type'] == '')) {
$nodes_and_relations['nodes'][$index]['source_data'] = $node['id_agent'];
$nodes_and_relations['nodes'][$index]['type'] = 0;
}
else {
$nodes_and_relations['nodes'][$index]['source_data'] = $node['id_module'];
$nodes_and_relations['nodes'][$index]['id_agent'] = $node['id_agent'];
$nodes_and_relations['nodes'][$index]['type'] = 1;
}
$style = array();
$style['shape'] = 'circle';
$style['image'] = $node['image'];
$style['width'] = $node['width'];
$style['height'] = $node['height'];
$style['label'] = $node['text'];
$nodes_and_relations['nodes'][$index]['style'] = json_encode($style);
$index++;
}
$nodes_and_relations['relations'] = array();
if (enterprise_installed()) {
enterprise_include_once("include/functions_pandora_networkmap.php");
save_generate_nodes($id, $nodes_and_relations);
}
}
else {
// Generate dot file
$graph = networkmap_generate_dot (__('Pandora FMS'),
@ -272,6 +381,8 @@ function networkmap_process_networkmap($id = 0) {
array('id' => $id));
}
}
return $nodes_and_relations;
}

View File

@ -33,10 +33,138 @@ include_once("include/functions_pandora_networkmap.php");
$new_networkmap = (bool) get_parameter('new_networkmap', false);
$save_networkmap = (bool) get_parameter('save_networkmap', false);
$save_empty_networkmap = (bool) get_parameter('save_empty_networkmap', false);
$update_empty_networkmap = (bool) get_parameter('save_empty_networkmap', false);
$update_networkmap = (bool) get_parameter('update_networkmap', false);
$copy_networkmap = (bool) get_parameter('copy_networkmap', false);
$delete = (bool) get_parameter('delete', false);
$tab = (string) get_parameter('tab', 'list');
$new_empty_networkmap = get_parameter('new_empty_networkmap', false);
if (enterprise_installed()) {
if ($new_empty_networkmap) {
if ($networkmaps_write || $networkmaps_manage) {
require ($config["homedir"]."/enterprise/godmode/agentes/pandora_networkmap_empty.editor.php");
require('pandora_networkmap_empty.editor.php');
return;
}
}
if ($save_empty_networkmap) {
$id_group = (int) get_parameter('id_group', 0);
// ACL for the network map
// $networkmap_read = check_acl ($config['id_user'], $id_group, "MR");
$networkmap_write = check_acl ($config['id_user'], $id_group, "MW");
$networkmap_manage = check_acl ($config['id_user'], $id_group, "MM");
if (!$networkmap_write && !$networkmap_manage) {
db_pandora_audit("ACL Violation",
"Trying to access networkmap");
require ("general/noaccess.php");
return;
}
$name = (string) get_parameter('name', '');
// Default size values
$width = 4000;
$height = 4000;
$method = (string) get_parameter('method', 'fdp');
$dont_show_subgroups = 0;
$node_radius = (int)get_parameter('node_radius', 40);
$description = get_parameter('description', '');
$values = array();
$values['name'] = $name;
$values['id_group'] = $id_group;
$values['source_period'] = 60;
$values['width'] = $width;
$values['height'] = $height;
$values['id_user'] = $config['id_user'];
$values['description'] = $description;
$values['source'] = 0;
$values['source_data'] = $id_group;
if (!$networkmap_write && !$networkmap_manage) {
db_pandora_audit("ACL Violation",
"Trying to access networkmap");
require ("general/noaccess.php");
return;
}
$filter = array();
$filter['dont_show_subgroups'] = $dont_show_subgroups;
$filter['node_radius'] = $node_radius;
$filter['empty_map'] = 1;
$values['filter'] = json_encode($filter);
$result = false;
if (!empty($name)) {
$result = db_process_sql_insert('tmap',
$values);
}
$result_txt = ui_print_result_message($result,
__('Succesfully created'), __('Could not be created'), '',
true);
// Force the tab = 'list'
$tab = "list";
}
else if ($update_empty_networkmap) {
$id_group = (int) get_parameter('id_group', 0);
// ACL for the new network map
$networkmap_write_new = check_acl ($config['id_user'], $id_group, "MW");
$networkmap_manage_new = check_acl ($config['id_user'], $id_group, "MM");
if (!$networkmap_write && !$networkmap_manage) {
db_pandora_audit("ACL Violation",
"Trying to access networkmap");
require ("general/noaccess.php");
return;
}
$name = (string) get_parameter('name', '');
$recon_task_id = (int) get_parameter(
'recon_task_id', 0);
$source = (string)get_parameter('source', 'group');
$values = array();
$values['name'] = $name;
$values['id_group'] = $id_group;
$values['generation_method'] = 4;
$description = get_parameter('description', '');
$values['description'] = $description;
$dont_show_subgroups = 0;
$node_radius = (int)get_parameter('node_radius', 40);
$row = db_get_row('tmap', 'id', $id);
$filter = json_decode($row['filter'], true);
$filter['dont_show_subgroups'] = $dont_show_subgroups;
$filter['node_radius'] = $node_radius;
$values['filter'] = json_encode($filter);
$result = false;
if (!empty($name)) {
$result = db_process_sql_update('tmap',
$values, array('id' => $id));
}
$result_txt = ui_print_result_message($result,
__('Succesfully updated'), __('Could not be updated'), '',
true);
}
}
$result_txt = '';
// The networkmap doesn't exist yet
@ -546,6 +674,15 @@ switch ($tab) {
html_print_submit_button (__('Create networkmap'), 'crt', false, 'class="sub next" style="float: right;"');
echo "</form>";
echo "</div>";
if (enterprise_installed()) {
echo "<div style='width: " . $table->width . "; margin-top: 5px;'>";
echo '<form method="post" action="index.php?sec=network&amp;sec2=operation/agentes/pandora_networkmap">';
html_print_input_hidden ('new_empty_networkmap', 1);
html_print_submit_button (__('Create empty networkmap'), 'crt', false, 'class="sub next" style="float: right; margin-right:20px;"');
echo "</form>";
echo "</div>";
}
}
break;