= '10000000000') { $info = 'color=red3 style="setlinewidth(6)"'; } elseif ($link['ifSpeed'] >= '1000000000') { $info = 'color=lightblue style="setlinewidth(4)"'; } elseif ($link['ifSpeed'] >= '100000000') { $info = 'color=lightgrey style="setlinewidth(2)"'; } elseif ($link['ifSpeed'] >= '10000000') { $info = 'style="setlinewidth(1)"'; } else { $info = 'style="setlinewidth(1)"'; } $src = $device['hostname']; if ($anon) { $src = md5($src); } if ($remote_port_id) { $dst = dbFetchCell('SELECT `hostname` FROM `devices` AS D, `ports` AS I WHERE I.port_id = ? AND D.device_id = I.device_id', [$remote_port_id]); $dst_host = dbFetchCell('SELECT D.device_id FROM `devices` AS D, `ports` AS I WHERE I.port_id = ? AND D.device_id = I.device_id', [$remote_port_id]); } else { unset($dst_host); $dst = $link['remote_hostname']; } if ($anon) { $dst = md5($dst); $src = md5($src); } $sif = cleanPort(dbFetchRow('SELECT * FROM ports WHERE `port_id` = ?', [$link['local_port_id']]), $device); if ($remote_port_id) { $dif = cleanPort(dbFetchRow('SELECT * FROM ports WHERE `port_id` = ?', [$link['remote_port_id']])); } else { $dif['label'] = $link['remote_port']; $dif['port_id'] = $link['remote_hostname'] . '/' . $link['remote_port']; } if ($where == '') { if (! $ifdone[$dst][$dif['port_id']] && ! $ifdone[$src][$sif['port_id']]) { $map .= "\"$src\" -> \"" . $dst . "\" [weight=500000, arrowsize=0, len=0];\n"; } $ifdone[$src][$sif['port_id']] = 1; } else { $map .= '"' . $sif['port_id'] . '" [label="' . $sif['label'] . '", fontsize=12, fillcolor=lightblue, URL="' . Config::get('base_url') . '/device/device=' . $device['device_id'] . "/tab=port/port=$local_port_id/\"]\n"; if (! $ifdone[$src][$sif['port_id']]) { $map .= "\"$src\" -> \"" . $sif['port_id'] . "\" [weight=500000, arrowsize=0, len=0];\n"; $ifdone[$src][$sif['port_id']] = 1; } if ($dst_host) { $map .= "\"$dst\" [URL=\"" . Config::get('base_url') . "/device/device=$dst_host/tab=neighbours/selection=map/\", fontsize=20, shape=box3d]\n"; } else { $map .= "\"$dst\" [ fontsize=20 shape=box3d]\n"; } if ($dst_host == $device['device_id'] || $where == '') { $map .= '"' . $dif['port_id'] . '" [label="' . $dif['label'] . '", fontsize=12, fillcolor=lightblue, URL="' . Config::get('base_url') . "/device/device=$dst_host/tab=port/port=$remote_port_id/\"]\n"; } else { $map .= '"' . $dif['port_id'] . '" [label="' . $dif['label'] . ' ", fontsize=12, fillcolor=lightgray'; if ($dst_host) { $map .= ', URL="' . Config::get('base_url') . "/device/device=$dst_host/tab=port/port=$remote_port_id/\""; } $map .= "]\n"; } if (! $ifdone[$dst][$dif['port_id']]) { $map .= '"' . $dif['port_id'] . "\" -> \"$dst\" [weight=500000, arrowsize=0, len=0];\n"; $ifdone[$dst][$dif['port_id']] = 1; } $map .= '"' . $sif['port_id'] . '" -> "' . $dif['port_id'] . "\" [weight=1, arrowhead=normal, arrowtail=normal, len=2, $info] \n"; } } } $done = 0; } } } $map .= "\n};"; if ($_GET['debug'] == 1) { echo '
$map'; exit(); } switch ($_GET['format']) { case 'svg': break; case 'png': $_GET['format'] = 'png:gd'; break; case 'dot': echo $map; exit(); default: $_GET['format'] = 'png:gd'; } if ($links > 30) { // Unflatten if there are more than 10 links. beyond that it gets messy $maptool = Config::get('dot'); } else { $maptool = Config::get('dot'); } if ($where == '') { $maptool = Config::get('sfdp') . ' -Gpack -Goverlap=prism -Gcharset=latin1 -Gsize=20,20'; $maptool = Config::get('dot'); } $descriptorspec = [0 => ['pipe', 'r'], 1 => ['pipe', 'w']]; $mapfile = Config::get('temp_dir') . '/' . strgen() . '.png'; $process = proc_open($maptool . ' -T' . $_GET['format'], $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:gd') { header('Content-type: image/png'); } elseif ($_GET['format'] == 'svg') { header('Content-type: image/svg+xml'); $img = str_replace(' '; } }