$parent_id) { $graph .= create_edge ($node, $parent_id); } // Define edges for orphan nodes foreach (array_keys($orphans) as $node) { $graph .= create_edge ('0', $node); } // Close graph $graph .= close_graph (); return $graph; } // Returns an edge definition function create_edge ($head, $tail) { $edge = $head.' -- '.$tail.'[color="#BDBDBD", headclip=false, tailclip=false];'; return $edge; } // Returns a node definition function create_node ($agent, $simple = 0, $font_size = 10) { $sql = sprintf ('SELECT COUNT(tagente_modulo.id_agente) FROM tagente_estado, tagente_modulo WHERE tagente_modulo.id_agente = %d AND tagente_modulo.id_tipo_modulo in (2, 6, 9, 18, 21, 100) AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente_estado.estado = 1', $agent['id_agente']); $bad_modules = get_db_sql ($sql); // Set node status if ($bad_modules) { $status_color = '#FF1D1D'; } else { $status_color = '#8DFF1D'; } // Check for alert $sql = sprintf ('SELECT COUNT(talerta_agente_modulo.id_aam) FROM talerta_agente_modulo, tagente_modulo, tagente WHERE tagente.id_agente = %d AND tagente.disabled = 0 AND tagente.id_agente = tagente_modulo.id_agente AND tagente_modulo.disabled = 0 AND tagente_modulo.id_agente_modulo = talerta_agente_modulo.id_agente_modulo AND talerta_agente_modulo.times_fired > 0 ', $agent['id_agente']); $alert_modules = get_db_sql ($sql); if ($alert_modules) $status_color = '#FFE308'; // Short name $name = strtolower ($agent["nombre"]); if (strlen ($name) > 16) $name = substr ($name, 0, 16); if ($simple == 0){ // Set node icon if (file_exists ('images/networkmap/'.$agent['id_os'].'.png')) { $img_node = 'images/networkmap/'.$agent['id_os'].'.png'; } else { $img_node = 'images/networkmap/0.png'; } $node = $agent['id_agente'].' [ color="'.$status_color.'", fontsize='.$font_size.', style="filled", fixedsize=true, width=0.40, height=0.40, label=<
'.$name.'
>, shape="ellipse", URL="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$agent['id_agente'].'", tooltip="ajax.php?page=operation/agentes/ver_agente&get_agent_status_tooltip=1&id_agent='.$agent['id_agente'].'"];'; } else { $node = $agent['id_agente'] . ' [ color="' . $status_color . '", fontsize='.$font_size.', style="filled", fixedsize=true, width=0.20, height=0.20, label="", tooltip="ajax.php?page=operation/agentes/ver_agente&get_agent_status_tooltip=1&id_agent='.$agent['id_agente'].'"];'; } return $node; } // Returns the definition of the central module function create_pandora_node ($name, $font_size = 10) { global $simple; $img = ''; $name = ''.$name.''; $label = ''.$img.$name.'
'; if ($simple == 1){ $label = ""; } $node = '0 [ color="#364D1F", fontsize='.$font_size.', style="filled", fixedsize=true, width=0.8, height=0.6, label=<'.$label.'>, shape="ellipse", URL="index.php?sec=estado&sec2=operation/agentes/estado_grupo" ];'; return $node; } // Opens a group definition function open_group ($id) { $img = 'images/'.dame_grupo_icono ($id).'.png'; $name = get_group_name ($id); $group = 'subgraph cluster_' . $id . ' { style=filled; color=darkolivegreen3; label=<
'.$name.'
>; tooltip="'.$name.'"; URL="index.php?sec=estado&sec2=operation/agentes/estado_agente&group_id=' . $id . '";'; return $group; } // Closes a group definition function close_group () { return '}'; } // Opens a graph definition function open_graph () { global $config, $layout, $nooverlap, $pure, $zoom, $ranksep, $font_size; $overlap = 'compress'; $size_x = 8; $size_y = 5.4; $size = ''; if ($layout == 'radial') $overlap = 'true'; if ($layout == 'flat' || $layout == 'radial' || $layout == 'spring1' || $layout == "spring2") if ($nooverlap != '') $overlap = 'scalexy'; if ($pure == 1 && $zoom > 1 ) { $size_x *= $zoom; $size_y *= $zoom; } $size = $size_x . ',' . $size_y; // BEWARE: graphwiz DONT use single ('), you need double (") $head = "graph networkmap { labeljust=l; margin=0; "; if ($nooverlap != '') { $head .= "overlap=\"$overlap\";"; $head .= "ranksep=\"$ranksep\";"; $head .= "outputorder=edgesfirst;"; } $head .= "ratio=fill;"; $head .= "root=0;"; $head .= "size=\"$size\";"; return $head; } // Closes a graph definition function close_graph () { return '}'; } // Returns the filter used to achieve the desired layout function set_filter () { global $layout; switch($layout) { case 'flat': return 'dot'; case 'radial': return 'twopi'; case 'circular': return 'circo'; case 'spring1': return 'neato'; case 'spring2': return 'fdp'; default: return 'twopi'; } } /* Main code */ // Load variables $layout = (string) get_parameter ('layout', 'radial'); $nooverlap = (boolean) get_parameter ('nooverlap', 0); $pure = (int) get_parameter ('pure'); $zoom = (float) get_parameter ('zoom'); $ranksep = (float) get_parameter ('ranksep', 2.5); $simple = (boolean) get_parameter ('simple', 0); $regen = (boolean) get_parameter ('regen',1); // Always regen by default $font_size = (int) get_parameter ('font_size', 12); echo '

'.__('Pandora Agents').' > '.__('Network Map').' '; if ($pure == 1) { echo ''; } else { echo ''; } echo '

'; // Layout selection $layout_array = array ( 'circular' => 'circular', 'radial' => 'radial', 'spring1' => 'spring 1', 'spring2' => 'spring 2', 'flat' => 'flat'); echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; if ($pure == "1") { // Zoom $zoom_array = array ( '1' => 'x1', '1.2' => 'x2', '1.6' => 'x3', '2' => 'x4', '2.5' => 'x5', '5' => 'x10', ); echo ''; } if ($nooverlap == 1){ echo ""; } echo ""; //echo ' Display groups '; echo ''; echo '
' . __('Layout') . '  '; print_select ($layout_array, 'layout', $layout, '', '', ''); echo '' . __('No Overlap') . '  '; print_checkbox ('nooverlap', '1', $nooverlap); echo '' . __('Simple') . '  '; print_checkbox ('simple', '1', $simple); echo '' . __('Regenerate') . '  '; print_checkbox ('regen', '1', $regen); echo '' . __('Zoom') . '  '; print_select ($zoom_array, 'zoom', $zoom, '', '', ''); echo '"; echo __('Distance between nodes') . '  '; print_input_text ('ranksep', $ranksep, $alt = 'Separation between elements in the map (in Non-overlap mode)', 3, 4, 0); echo ""; echo __('Font') . '  '; print_input_text ('font_size', $font_size, $alt = 'Font size (in pt)', 3, 4, 0); echo "'; echo ''; echo '
'; // Set filter $filter = set_filter (); // Generate dot file $graph = generate_dot ($simple, $font_size); // Generate image and map // If image was generated just a few minutes ago, then don't regenerate (it takes long) unless regen checkbox is set $filename_map = $config["attachment_store"]."/networkmap_".$layout; $filename_img = "attachment/networkmap_".$layout."_".$font_size; $filename_dot = $config["attachment_store"]."/networkmap_".$layout; if ($simple) { $filename_map .= "_simple"; $filename_img .= "_simple"; $filename_dot .= "_simple"; } if ($nooverlap) { $filename_map .= "_nooverlap"; $filename_img .= "_nooverlap"; $filename_dot .= "_nooverlap"; } $filename_map .= ".map"; $filename_img .= ".png"; $filename_dot .= ".dot"; if ($regen != 1 && file_exists ($filename_img) && filemtime ($filename_img) > get_system_time () - 300) { $result = true; } else { $fh = fopen ($filename_dot, 'w'); if ($fh === false) { $result = false; break; } fwrite ($fh, $graph); $cmd = "$filter -Tcmapx -o".$filename_map." -Tpng -o".$filename_img." ".$filename_dot; $result = system ($cmd); fclose ($fh); unlink ($filename_dot); } if ($result !== false) { if (! file_exists ($filename_map)) { echo '

'.__('Map could not be generated').'

'; echo $result; echo "
Apparently something went wrong reading the output.
Is ".$filter." (usually part of GraphViz) installed and able to be executed by the webserver?"; echo "
Is ".$config["attachment_store"]." writeable by the webserver?"; return; } echo ''; include ($filename_map); } else { echo '

'.__('Map could not be generated').'

'; echo $result; echo "
Apparently something went wrong executing the command."; echo "
Is ".$filter." (usually part of GraphViz) and echo installed and able to be executed by the webserver?"; echo "
Is your webserver restricted from executing command line tools through the system() call (PHP Safe Mode or SELinux)"; return; } ?>