From e87e9b5a02645008e694168b67c31e707aa8c8c3 Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Sat, 8 Oct 2011 23:49:24 +0000 Subject: [PATCH] i win. fucking graphviz. git-svn-id: http://www.observium.org/svn/observer/trunk@2673 61d68cd4-352d-0410-923a-c4978735b2b8 --- html/map.php | 35 +++++++++++++++++++++++---------- html/pages/device/ports.inc.php | 3 ++- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/html/map.php b/html/map.php index 8614113449..7736562ca8 100755 --- a/html/map.php +++ b/html/map.php @@ -39,14 +39,16 @@ if (isset($_GET['device'])) { $where = "WHERE device_id = ".mres($_GET['device'] if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format'])) { - $map = "digraph G { sep=0.01; size=\"12,5.5\"; pack=100; bgcolor=transparent; splines=true; overlap=scale; concentrate=0; epsilon=0.001; rankdir=0; - node [ fontname=\"helvetica\", fontstyle=bold, style=filled, color=white, fillcolor=lightgrey, overlap=false;]; - edge [ bgcolor=white; fontname=\"helvetica\"; fontstyle=bold; arrowhead=dot; arrowtail=dot]; - graph [bgcolor=transparent;];\n\n"; + $map = 'digraph G { sep=0.01; size="12,5.5"; pack=100; bgcolor=transparent; splines=true; overlap=scale; concentrate=0; epsilon=0.001; rankdir=0; + node [ fontname="helvetica", fontstyle=bold, style=filled, color=white, fillcolor=lightgrey, overlap=false]; + edge [ bgcolor=white, fontname="helvetica", fontstyle=bold, arrowhead=dot, arrowtail=dot]; + graph [bgcolor=transparent]; + +'; if (!$_SESSION['authenticated']) { - $map .= "\"Not authenticated\" [fontsize=20 fillcolor=\"lightblue\" URL=\"/\" shape=box3d]\n"; + $map .= "\"Not authenticated\" [fontsize=20 fillcolor=\"lightblue\", URL=\"/\" shape=box3d]\n"; } else { @@ -58,7 +60,7 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format'])) if (count($links)) { - $map .= "\"".$device['hostname']."\" [fontsize=20 fillcolor=\"lightblue\" URL=\"{$config['base_url']}/device/device=".$device['device_id']."/tab=map/\" shape=box3d]\n"; + $map .= "\"".$device['hostname']."\" [fontsize=20, fillcolor=\"lightblue\", URL=\"{$config['base_url']}/device/device=".$device['device_id']."/tab=map/\" shape=box3d]\n"; } foreach ($links as $link) @@ -107,7 +109,7 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format'])) $dif['interface_id'] = $link['remote_hostname'] . $link['remote_port']; } - $map .= "\"" . $sif['interface_id'] . "\" [label=\"" . $sif['label'] . "\", fontsize=12, fillcolor=lightblue URL=\"{$config['base_url']}/device/device=".$device['device_id']."/port/$local_interface_id/\"]\n"; + $map .= "\"" . $sif['interface_id'] . "\" [label=\"" . $sif['label'] . "\", fontsize=12, fillcolor=lightblue, URL=\"{$config['base_url']}/device/device=".$device['device_id']."/port/$local_interface_id/\"]\n"; if (!$ifdone[$src][$sif['interface_id']]) { $map .= "\"$src\" -> \"" . $sif['interface_id'] . "\" [weight=500000, arrowsize=0, len=0];\n"; @@ -115,7 +117,7 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format'])) } if ($dst_host) { - $map .= "\"$dst\" [URL=\"{$config['base_url']}/device/device=$dst_host/tab=map/\" fontsize=20 shape=box3d]\n"; + $map .= "\"$dst\" [URL=\"{$config['base_url']}/device/device=$dst_host/tab=map/\", fontsize=20, shape=box3d]\n"; } else { $map .= "\"$dst\" [ fontsize=20 shape=box3d]\n"; } @@ -143,7 +145,10 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format'])) $map .= " };"; - if ($_GET['debug'] == 1) { echo("
$map
");exit(); } +# if ($_GET['debug'] == 1) +# { +# echo("
$map
");exit(); +# } switch ($_GET['format']) { @@ -163,7 +168,17 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format'])) if ($where == '') { $maptool = $config['sdfp'] . ' -Gpack -Gcharset=latin1 -Gsize=200,200'; } - $img = shell_exec("echo \"".addslashes($map)."\" | $maptool -T".$_GET['format'].""); + $descriptorspec = array(0 => array("pipe", "r"),1 => array("pipe", "w") ); + $process = proc_open('/usr/bin/dot -Tsvg',$descriptorspec,$pipes); + + if (is_resource($process)) { + fwrite($pipes[0], "$map"); + fclose($pipes[0]); + while (! feof($pipes[1])) {$img .= fgets($pipes[1]);} + fclose($pipes[1]); + $return_value = proc_close($process); + } + if ($_GET['format'] == "png") { header("Content-type: image/".$_GET['format']); diff --git a/html/pages/device/ports.inc.php b/html/pages/device/ports.inc.php index 2387ca7228..e45a389915 100644 --- a/html/pages/device/ports.inc.php +++ b/html/pages/device/ports.inc.php @@ -4,7 +4,8 @@ if ($vars['view'] == 'graphs' || $vars['view'] == 'minigraphs') { if (isset($vars['graph'])) { $graph_type = "port_" . $vars['graph']; } else { $graph_type = "port_bits"; } } -if (!$vars['view']) { $vars['view'] = "basic"; } + +if (!$vars['view']) { $vars['view'] = $config['ports_page_default']; } $link_array = array('page' => 'device', 'device' => $device['device_id'],