diff --git a/pandora_console/include/functions_pandora_networkmap.php b/pandora_console/include/functions_pandora_networkmap.php index 8e261b2695..9bb47e301b 100644 --- a/pandora_console/include/functions_pandora_networkmap.php +++ b/pandora_console/include/functions_pandora_networkmap.php @@ -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); @@ -95,182 +95,293 @@ function networkmap_process_networkmap($id = 0) { } $nodes_and_relations = array(); - + if (enterprise_installed() && ($numNodes > 0)) { $nodes_and_relations = get_structure_nodes($id); } else { - // Generate dot file - $graph = networkmap_generate_dot (__('Pandora FMS'), - $id_group, - $simple, - $font_size, - $layout, - $nooverlap, - $zoom, - $ranksep, - $center, - $regen, - $pure, - $id, - $show_snmp_modules, - false, //cut_names - true, // relative - '', - $ip_mask, - $dont_show_subgroups, - false, - null, - $old_mode); - - 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"; + 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 (); - file_put_contents($filename_dot, $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"; - 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"; + file_put_contents($filename_dot, $graph); - $cmd = "$filter -Tplain -o " . $filename_plain . " " . - $filename_dot; - break; - } + 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"; - system ($cmd); - - unlink($filename_dot); - - $nodes = networkmap_loadfile($id, $filename_plain, - $relation_nodes, $graph); - - unlink($filename_plain); + $cmd = "$filter -Tplain -o " . $filename_plain . " " . + $filename_dot; + break; + } - //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; + 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'), + $id_group, + $simple, + $font_size, + $layout, + $nooverlap, + $zoom, + $ranksep, + $center, + $regen, + $pure, + $id, + $show_snmp_modules, + false, //cut_names + true, // relative + '', + $ip_mask, + $dont_show_subgroups, + false, + null, + $old_mode); + + 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(); + $index = 0; + foreach ($relation_nodes as $relation) { + $nodes_and_relations['relations'][$index]['id_map'] = $id; + + if (($relation['parent_type'] == 'agent') || ($relation['parent_type'] == '')) { + $nodes_and_relations['relations'][$index]['id_parent'] = $relation['id_parent']; + $nodes_and_relations['relations'][$index]['id_parent_source_data'] = $nodes[$relation['id_parent']]['id_agent']; + $nodes_and_relations['relations'][$index]['parent_type'] = 0; + } + else if ($relation['parent_type'] == 'module') { + $nodes_and_relations['relations'][$index]['id_parent'] = $relation['id_parent']; + $nodes_and_relations['relations'][$index]['id_parent_source_data'] = $nodes[$relation['id_parent']]['id_module']; + $nodes_and_relations['relations'][$index]['parent_type'] = 1; + } + else { + $nodes_and_relations['relations'][$index]['id_parent'] = $relation['id_parent']; + $nodes_and_relations['relations'][$index]['id_child_source_data'] = -2; + $nodes_and_relations['relations'][$index]['parent_type'] = 3; + } + + if (($relation['child_type'] == 'agent') || ($relation['child_type'] == '')) { + $nodes_and_relations['relations'][$index]['id_child'] = $relation['id_child']; + $nodes_and_relations['relations'][$index]['id_child_source_data'] = $nodes[$relation['id_child']]['id_agent']; + $nodes_and_relations['relations'][$index]['child_type'] = 0; + } + else if ($relation['child_type'] == 'module') { + $nodes_and_relations['relations'][$index]['id_child'] = $relation['id_child']; + $nodes_and_relations['relations'][$index]['id_child_source_data'] = $nodes[$relation['id_child']]['id_module']; + $nodes_and_relations['relations'][$index]['child_type'] = 1; + } + else { + $nodes_and_relations['relations'][$index]['id_child'] = $relation['id_child']; + $nodes_and_relations['relations'][$index]['id_child_source_data'] = -2; + $nodes_and_relations['relations'][$index]['child_type'] = 3; + } + + $index++; + } + + if (enterprise_installed()) { + enterprise_include_once("include/functions_pandora_networkmap.php"); + save_generate_nodes($id, $nodes_and_relations); + } + + $pandorafms_node = $nodes_and_relations['nodes'][0]; + $center = array('x' => $pandorafms_node['x'], 'y' => $pandorafms_node['y']); + + $networkmap['center_x'] = $center['x']; + $networkmap['center_y'] = $center['y']; + db_process_sql_update('tmap', + array('center_x' => $networkmap['center_x'], 'center_y' => $networkmap['center_y']), + array('id' => $id)); } - $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(); - $index = 0; - foreach ($relation_nodes as $relation) { - $nodes_and_relations['relations'][$index]['id_map'] = $id; - - if (($relation['parent_type'] == 'agent') || ($relation['parent_type'] == '')) { - $nodes_and_relations['relations'][$index]['id_parent'] = $relation['id_parent']; - $nodes_and_relations['relations'][$index]['id_parent_source_data'] = $nodes[$relation['id_parent']]['id_agent']; - $nodes_and_relations['relations'][$index]['parent_type'] = 0; - } - else if ($relation['parent_type'] == 'module') { - $nodes_and_relations['relations'][$index]['id_parent'] = $relation['id_parent']; - $nodes_and_relations['relations'][$index]['id_parent_source_data'] = $nodes[$relation['id_parent']]['id_module']; - $nodes_and_relations['relations'][$index]['parent_type'] = 1; - } - else { - $nodes_and_relations['relations'][$index]['id_parent'] = $relation['id_parent']; - $nodes_and_relations['relations'][$index]['id_child_source_data'] = -2; - $nodes_and_relations['relations'][$index]['parent_type'] = 3; - } - - if (($relation['child_type'] == 'agent') || ($relation['child_type'] == '')) { - $nodes_and_relations['relations'][$index]['id_child'] = $relation['id_child']; - $nodes_and_relations['relations'][$index]['id_child_source_data'] = $nodes[$relation['id_child']]['id_agent']; - $nodes_and_relations['relations'][$index]['child_type'] = 0; - } - else if ($relation['child_type'] == 'module') { - $nodes_and_relations['relations'][$index]['id_child'] = $relation['id_child']; - $nodes_and_relations['relations'][$index]['id_child_source_data'] = $nodes[$relation['id_child']]['id_module']; - $nodes_and_relations['relations'][$index]['child_type'] = 1; - } - else { - $nodes_and_relations['relations'][$index]['id_child'] = $relation['id_child']; - $nodes_and_relations['relations'][$index]['id_child_source_data'] = -2; - $nodes_and_relations['relations'][$index]['child_type'] = 3; - } - - $index++; - } - - if (enterprise_installed()) { - enterprise_include_once("include/functions_pandora_networkmap.php"); - save_generate_nodes($id, $nodes_and_relations); - } - - $pandorafms_node = $nodes_and_relations['nodes'][0]; - $center = array('x' => $pandorafms_node['x'], 'y' => $pandorafms_node['y']); - - $networkmap['center_x'] = $center['x']; - $networkmap['center_y'] = $center['y']; - db_process_sql_update('tmap', - array('center_x' => $networkmap['center_x'], 'center_y' => $networkmap['center_y']), - 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'])); diff --git a/pandora_console/operation/agentes/pandora_networkmap.php b/pandora_console/operation/agentes/pandora_networkmap.php index 2dfb2bf256..4c8eb13af2 100644 --- a/pandora_console/operation/agentes/pandora_networkmap.php +++ b/pandora_console/operation/agentes/pandora_networkmap.php @@ -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 ""; echo ""; + + if (enterprise_installed()) { + echo "