$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) { $sql = sprintf ('SELECT COUNT(*) 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'; } // Short name $name = strtolower ($agent["nombre"]); if (strlen ($name) > 12) $name = substr ($name, 0, 12); 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=9, 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=7, 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) { $node = '0 [ color="#364D1F", fontsize=10, style="filled", fixedsize=true, width=0.8, height=0.6, label=<
'.$name.'
>, shape="ellipse", tooltip="'.$name.'", 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 = dame_nombre_grupo($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; $overlap = 'compress'; $size_x = 8; $size_y = 5.4; $size = ''; if ($layout == "") $layout = "radial"; if ($layout == 'radial') $overlap = 'true'; if (($layout == 'flat') OR ($layout == 'spring1') OR ($layout == "spring2")) if ($nooverlap != '') $overlap = 'scalexy'; if ($pure == 1 && $zoom > 1 && $zoom <= 3) { $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 .= "ranksep=\"$ranksep\";"; $head .= "outputorder=edgesfirst; overlap=\"$overlap\"; ratio=fill; root=0; 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'); $nooverlap = (boolean) get_parameter ('nooverlap'); $pure = (int) get_parameter ('pure'); $zoom = (float) get_parameter ('zoom'); $ranksep = (float) get_parameter ('ranksep', 2.5); $simple = (int) get_parameter ('simple', 0); // Login check $id_user = $_SESSION["id_usuario"]; global $REMOTE_ADDR; if (comprueba_login() != 0) { audit_db($id_user, $REMOTE_ADDR, "ACL Violation", "Trying to access node graph builder"); include("general/noaccess.php"); exit; } if ((give_acl($id_user, 0, "AR") != 1 ) && (dame_admin($id_user) !=1 )) { audit_db($id_user, $REMOTE_ADDR, "ACL Violation", "Trying to access node graph builder"); include("general/noaccess.php"); exit; } echo '

'.lang_string ('ag_title').' > '.lang_string("Network Map").' '; if ($pure == 1) { echo ''; } else { echo ''; } echo '

'; // Layout selection $layout_array = array ('radial' => 'radial', 'circular' => 'circular', 'spring1' => 'spring 1', 'spring2' => 'spring 2', 'flat' => 'flat'); 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 ''; } //echo ' Display groups '; echo ''; echo '
' . lang_string('Layout') . '  '; print_select ($layout_array, 'layout', $layout, '', '', ''); echo '' . lang_string('No Overlap') . '  '; print_checkbox ('nooverlap', 'nooverlap', $nooverlap); echo '' . lang_string('Simple') . '  '; print_checkbox ('simple', '1', $simple); echo '' . lang_string('Zoom') . '  '; print_select ($zoom_array, 'zoom', $zoom, '', '', ''); echo ''; echo ''; echo '
'; echo '
'; // Set filter $filter = set_filter(); // Generate dot file $graph = generate_dot($simple); // Generate image and map $cmd = "echo " . escapeshellarg($graph) . " | $filter -Tcmapx -o".$config["attachment_store"]."/networkmap.map -Tpng -o".$config["attachment_store"]."/networkmap.png"; $result = system ($cmd); if ($result !== false) { if (! file_exists ($config["attachment_store"]."/networkmap.map")) { echo '

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

'; echo $result; return; } echo ''; include $config["attachment_store"]."/networkmap.map"; } else { echo '

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

'; echo $result; return; } ?>