diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 47cacfcdd0..4c5f3ffe75 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,13 @@ +2013-07-25 Miguel de Dios + + * include/javascript/d3.v3.js: removed some changes. + + * include/functions_networkmap.php, + operation/agentes/networkmap.dinamic.php, + operation/agentes/networkmap.php: first version of dinamic view + for networkmap. It needs implement tooltip and of course fix + the new bugs. + 2013-07-25 Sergio Martin * godmode/alerts/configure_alert_template.php: Fix alert diff --git a/pandora_console/include/functions_networkmap.php b/pandora_console/include/functions_networkmap.php index 25ccad385d..42cc5da934 100644 --- a/pandora_console/include/functions_networkmap.php +++ b/pandora_console/include/functions_networkmap.php @@ -46,6 +46,189 @@ function networkmap_is_descendant ($node, $ascendant, $parents) { return networkmap_is_descendant ($parents[$node], $ascendant, $parents); } + +function networkmap_print_jsdata($graph, $js_tags = true) { + if ($js_tags) { + echo ""; + } +} + +function networkmap_generate_hash($pandora_name, $group = 0, + $simple = 0, $font_size = 12, $layout = 'radial', $nooverlap = 0, + $zoom = 1, $ranksep = 2.5, $center = 0, $regen = 1, $pure = 0, + $id_networkmap = 0, $show_snmp_modules = 0, $cut_names = true, + $relative = false, $text_filter = '') { + + $graph = networkmap_generate_dot($pandora_name, $group, + $simple, $font_size, $layout, $nooverlap, $zoom, $ranksep, + $center, $regen, $pure, $id_networkmap, $show_snmp_modules, + $cut_names, $relative, $text_filter); html_debug_print($graph, true); + + $return = array(); + if (!empty($graph)) { + $graph = str_replace("\r", "\n", $graph); + $graph = str_replace("\n", " ", $graph); + + //Removed the head + preg_match("/graph networkmap {(.*)}/", $graph, $matches); + $graph = $matches[1]; + + + //Get the lines and nodes + $tokens = preg_split("/; /", $graph); + foreach ($tokens as $token) { + if (empty($token)) { + continue; + } + + //Ignore the head rests. + if (preg_match("/(.+)\s*\[(.*)\]/", $token) != 0) { + $items[] = $token; + } + } + + $lines = $nodes = array(); + foreach ($items as $item) { + $matches = null; + preg_match("/(.+)\s*\[(.*)\]/", $item, $matches); + if (empty($matches)) + continue; + + $id_item = trim($matches[1]); + $content_item = trim($matches[2]); + + //Check if is a edge or node + if (strstr($id_item, "--") !== false) { + //edge + $lines[$id_item] = $content_item; + } + else { + //node + $id_item = (int)$id_item; + $nodes[$id_item] = $content_item; + } + } + + + foreach($nodes as $key => $node) { + if ($key != 0) { + //Get label + $matches = null; + preg_match("/label=(.*),/", $node, $matches); + $label = $matches[1]; + $matches = null; + preg_match("/\\(.*?)\<\/TD\>\<\/TR\>/", + $label, $matches); + $label = str_replace($matches[0], '', $label); + $matches = null; + preg_match("/\\(.*?)\<\/TD\>\<\/TR\>/", + $label, $matches); + $label = $matches[1]; + + //Get color + $matches = null; + preg_match("/color=\"([^\"]*)/", $node, $matches); + $color = $matches[1]; + + //Get tooltip + $matches = null; + preg_match("/tooltip=\"([^\"]*)/", $node, $matches); + $tooltip = $matches[1]; + + //Get URL + $matches = null; + preg_match("/URL=\"([^\"]*)/", $node, $matches); + $url = $matches[1]; + + $return['nodes'][$key]['label'] = $label; + $return['nodes'][$key]['color'] = $color; + $return['nodes'][$key]['tooltip'] = $tooltip; + $return['nodes'][$key]['url'] = $url; + } + else { + //Get tooltip + $matches = null; + preg_match("/tooltip=\"([^\"]*)/", $node, $matches); + $tooltip = $matches[1]; + + //Get URL + $matches = null; + preg_match("/URL=\"([^\"]*)/", $node, $matches); + $url = $matches[1]; + + $return['nodes'][$key]['label'] = "Pandora FMS"; + $return['nodes'][$key]['color'] = "#7EBE3F"; + $return['nodes'][$key]['tooltip'] = $tooltip; + $return['nodes'][$key]['url'] = $url; + } + } + ksort($return['nodes']); + + foreach($lines as $key => $line) { + $data = array(); + + $points = explode(' -- ', $key); + $data['source'] = (int) $points[0]; + $data['target'] = (int) $points[1]; + $return['lines'][] = $data; + } + + //html_debug_print($graph, true); + + } + + return $return; +} + // Generate a dot graph definition for graphviz function networkmap_generate_dot ($pandora_name, $group = 0, $simple = 0, $font_size = 12, $layout = 'radial', $nooverlap = 0, @@ -180,7 +363,7 @@ function networkmap_generate_dot ($pandora_name, $group = 0, foreach ($parents as $node => $parent_id) { // Verify that the parent is in the graph if (isset ($nodes[$parent_id])) { - $graph .= networkmap_create_edge ($node, $parent_id, $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, 'operation/agentes/networkmap', 'topology', $id_networkmap); + $graph .= networkmap_create_edge ($parent_id, $node , $layout, $nooverlap, $pure, $zoom, $ranksep, $simple, $regen, $font_size, $group, 'operation/agentes/networkmap', 'topology', $id_networkmap); } else { $orphans[$node] = 1; @@ -1062,11 +1245,17 @@ function networkmap_get_networkmaps ($id_user = '', $type = '', $optgrouped = tr switch ($config["dbtype"]) { case "mysql": - $networkmaps_raw = db_get_all_rows_filter ('tnetwork_map', 'id_user = "'.$id_user.'"'.$type_cond.' ORDER BY type DESC, name ASC', array('id_networkmap','name', 'type')); + $networkmaps_raw = db_get_all_rows_filter( + 'tnetwork_map', 'id_user = "' . $id_user . '" ' . + $type_cond . ' ORDER BY type DESC, name ASC', + array('id_networkmap','name', 'type')); break; case "postgresql": case "oracle": - $networkmaps_raw = db_get_all_rows_filter ('tnetwork_map', 'id_user = \''.$id_user.'\' '.$type_cond.' ORDER BY type DESC, name ASC', array('id_networkmap','name', 'type')); + $networkmaps_raw = db_get_all_rows_filter( + 'tnetwork_map', 'id_user = \'' . $id_user . '\' ' . + $type_cond . ' ORDER BY type DESC, name ASC', + array('id_networkmap','name', 'type')); break; } @@ -1082,7 +1271,8 @@ function networkmap_get_networkmaps ($id_user = '', $type = '', $optgrouped = tr 'optgroup' => $networkmapitem['type']); } else { - $networkmaps[$networkmapitem['id_networkmap']] = $networkmapitem['name']; + $networkmaps[$networkmapitem['id_networkmap']] = + $networkmapitem['name']; } } @@ -1135,6 +1325,7 @@ function networkmap_get_types () { $networkmap_types['topology'] = __('Create a new topology map'); $networkmap_types['groups'] = __('Create a new group map'); + $networkmap_types['dinamic'] = __('Create a new dinamic map'); if ($is_enterprise !== ENTERPRISE_NOT_HOOK) { $enterprise_types = enterprise_hook('policies_get_networkmap_types'); @@ -1157,6 +1348,7 @@ function networkmap_get_filter_types () { $networkmap_types['topology'] = __('Topology'); $networkmap_types['groups'] = __('Group'); + $networkmap_types['dinamic'] = __('Dinamic'); if ($is_enterprise !== ENTERPRISE_NOT_HOOK) { $enterprise_types = enterprise_hook('policies_get_networkmap_filter_types'); diff --git a/pandora_console/include/javascript/d3.v3.js b/pandora_console/include/javascript/d3.v3.js index 4bc840f7d0..72c8edf34f 100644 --- a/pandora_console/include/javascript/d3.v3.js +++ b/pandora_console/include/javascript/d3.v3.js @@ -1152,7 +1152,7 @@ d3 = function() { return d3.rebind(drag, event, "on"); }; d3.behavior.zoom = function() { - var translate = [ 0, 0 ], zoom_levels = null, translate0, scale = 1, distance0, scale0, scaleExtent = d3_behavior_zoomInfinity, event = d3_eventDispatch(zoom, "zoom"), x0, x1, y0, y1, touchtime; + var translate = [ 0, 0 ], translate0, scale = 1, distance0, scale0, scaleExtent = d3_behavior_zoomInfinity, event = d3_eventDispatch(zoom, "zoom"), x0, x1, y0, y1, touchtime; function zoom() { this.on("mousedown.zoom", mousedown).on("mousemove.zoom", mousemove).on(d3_behavior_zoomWheel + ".zoom", mousewheel).on("dblclick.zoom", dblclick).on("touchstart.zoom", touchstart).on("touchmove.zoom", touchmove).on("touchend.zoom", touchstart); } @@ -1211,34 +1211,36 @@ d3 = function() { return (y - translate[1]) / scale; }).map(y0.invert)); } - - zoom.setScale = function(v) { + + zoom.setScale = function(v) { scale = v; } - zoom.setTranslate = function(v) { + zoom.setTranslate = function(v) { translate = v; } - zoom.getTranslate = function() { + zoom.getTranslate = function() { return translate; } - - zoom.convertLevelsToScale = function(i) { + + zoom.convertLevelsToScale = function(i) { min = Math.pow(2, (-360 * i) * .002) * 1; max = Math.pow(2, (360 * i) * .002) * 1; return [min, max]; } - - zoom.getZoomLevel = function(x, y) { + + zoom.getZoomLevel = function(x, y) { if (typeof(x) == 'undefined') { + x = 0; //Get center } if (typeof(y) == 'undefined') { + y = 0; //Get center } - zoom_levels = []; + var zoom_levels = []; if (!translate0) translate0 = location([x, y]); diff --git a/pandora_console/operation/agentes/networkmap.dinamic.php b/pandora_console/operation/agentes/networkmap.dinamic.php new file mode 100755 index 0000000000..21c9287f61 --- /dev/null +++ b/pandora_console/operation/agentes/networkmap.dinamic.php @@ -0,0 +1,192 @@ +'; +echo '
'; +?> + + \ No newline at end of file diff --git a/pandora_console/operation/agentes/networkmap.php b/pandora_console/operation/agentes/networkmap.php index b2a5b32711..bfc7b76f6e 100644 --- a/pandora_console/operation/agentes/networkmap.php +++ b/pandora_console/operation/agentes/networkmap.php @@ -251,6 +251,9 @@ switch ($activeTab) { case 'policies': $title = __('Policies view'); break; + case 'dinamic': + $title = __('Dinamic view'); + break; } if (!empty($name)) { @@ -307,8 +310,12 @@ if ($activeTab == 'topology') { $table->data[0][] = __('Show interfaces') . ' ' . html_print_checkbox ('show_snmp_modules', '1', $show_snmp_modules, true); } -$table->data[0][] = __('Layout') . ' ' . - html_print_select ($layout_array, 'layout', $layout, '', '', '', true); + +if ($activeTab != 'dinamic') { + $table->data[0][] = __('Layout') . ' ' . + html_print_select ($layout_array, 'layout', $layout, '', '', '', true); +} + if ($activeTab == 'groups') { $depth_levels = array( 'all' => __('All'), @@ -327,8 +334,10 @@ if ($activeTab == 'policies') { html_print_select ($depth_levels, 'depth', $depth, '', '', '', true, false, false); } -$table->data[1][] = __('No Overlap') . ' ' . - html_print_checkbox ('nooverlap', '1', $nooverlap, true); +if ($activeTab != 'dinamic') { + $table->data[1][] = __('No Overlap') . ' ' . + html_print_checkbox ('nooverlap', '1', $nooverlap, true); +} if (($activeTab == 'groups' || $activeTab == 'policies') && $depth == 'all') { @@ -342,11 +351,16 @@ if (($activeTab == 'groups' || $activeTab == 'policies') && } } } -$table->data[1][] = __('Simple') . ' ' . - html_print_checkbox ('simple', '1', $simple, true); -$table->data[1][] = __('Regenerate') . ' ' . - html_print_checkbox ('regen', '1', $regen, true); +if ($activeTab != 'dinamic') { + $table->data[1][] = __('Simple') . ' ' . + html_print_checkbox ('simple', '1', $simple, true); +} + +if ($activeTab != 'dinamic') { + $table->data[1][] = __('Regenerate') . ' ' . + html_print_checkbox ('regen', '1', $regen, true); +} if ($pure == "1") { // Zoom @@ -368,8 +382,12 @@ if ($nooverlap == 1) { $table->data[1][] = __('Distance between nodes') . ' ' . html_print_input_text ('ranksep', $ranksep, __('Separation between elements in the map (in Non-overlap mode)'), 3, 4, true); } -$table->data[1][] = __('Font') . ' ' . - html_print_input_text ('font_size', $font_size, $alt = 'Font size (in pt)', 2, 4, true); + +if ($activeTab != 'dinamic') { + $table->data[1][] = __('Font') . ' ' . + html_print_input_text ('font_size', $font_size, $alt = 'Font size (in pt)', 2, 4, true); +} + $table->data[2][] = __('Free text for search (*):') . ' ' . html_print_input_text('text_filter', $text_filter, '', 30, 100, true); if ($activeTab == 'groups') { @@ -397,6 +415,9 @@ if ($id_networkmap != 0) { case 'policies': require_once(ENTERPRISE_DIR . '/operation/policies/networkmap.policies.php'); break; + case 'dinamic': + require_once('operation/agentes/networkmap.dinamic.php'); + break; default: case 'topology': require_once('operation/agentes/networkmap.topology.php');