Merge branch '1316-new-empty-networkmaps-dev' into 'develop'

Added empty networkmap functions

See merge request artica/pandorafms!999
This commit is contained in:
vgilc 2017-11-15 15:53:38 +01:00
commit d4fdb9d23c
2 changed files with 415 additions and 165 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,116 @@ 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'];
$style['id_networkmap'] = $node['networkmap'];
$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'),
@ -212,7 +322,6 @@ function networkmap_process_networkmap($id = 0) {
$style['width'] = $node['width'];
$style['height'] = $node['height'];
$style['label'] = $node['text'];
$style['id_networkmap'] = $node['networkmap'];
$nodes_and_relations['nodes'][$index]['style'] = json_encode($style);
$index++;
@ -273,6 +382,8 @@ function networkmap_process_networkmap($id = 0) {
array('id' => $id));
}
}
return $nodes_and_relations;
}
@ -557,7 +668,7 @@ function networkmap_links_to_js_links($relations, $nodes_graph) {
$item['arrow_end'] = 'module';
$item['status_end'] = modules_get_agentmodule_status((int)$id_target_module, false, false, null);
$item['id_module_end'] = (int)$id_target_module;
$text_end = modules_get_agentmodule_name((int)$id_target_module);
$text_end = io_safe_output(modules_get_agentmodule_name((int)$id_target_module));
if (preg_match ("/(.+)_ifOperStatus$/" , (string)$text_end, $matches)) {
if ($matches[1]) {
$item['text_end'] = $matches[1];
@ -568,7 +679,7 @@ function networkmap_links_to_js_links($relations, $nodes_graph) {
$item['arrow_start'] = 'module';
$item['status_start'] = modules_get_agentmodule_status((int)$id_source_module, false, false, null);
$item['id_module_start'] = (int)$id_source_module;
$text_start = modules_get_agentmodule_name((int)$id_source_module);
$text_start = io_safe_output(modules_get_agentmodule_name((int)$id_source_module));
if (preg_match ("/(.+)_ifOperStatus$/" , (string)$text_start, $matches)) {
if ($matches[1]) {
$item['text_start'] = $matches[1];
@ -883,6 +994,7 @@ function networkmap_loadfile($id = 0, $file = '',
modules_get_agentmodule_agent($ids[$node_id]['id_module']);
$text = modules_get_agentmodule_name($data['id_module']);
$text = io_safe_output($text);
$text = ui_print_truncate_text($text,
'agent_medium', false, true, false,
'...', false);
@ -893,6 +1005,7 @@ function networkmap_loadfile($id = 0, $file = '',
$data['id_agent'] = $ids[$node_id]['id_agent'];
$text = agents_get_alias($ids[$node_id]['id_agent']);
$text = io_safe_output($text);
$text = ui_print_truncate_text($text,
'agent_medium', false, true, false,
'...', false);
@ -982,7 +1095,7 @@ function duplicate_networkmap($id) {
$values = db_get_row('tmap', 'id', $id);
unset($values['id']);
$free_name = false;
$values['name'] = io_safe_input(__('Copy of ')) . $values['name'];
$values['name'] = io_safe_input(__('Copy of ') . io_safe_output($values['name']));
$count = 1;
while (!$free_name) {
$exist = db_get_row_filter('tmap', array('name' => $values['name']));

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
@ -547,6 +675,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;