'.$file.''); } $file_handle = fopen($file, 'r'); $set=0; $i=0; while (1) { $line = fgets($file_handle); if ($i <= 5) { $data[] = $line; $i++; } if (preg_match("/interface\b/", $line)) { $interface[] = $line; } if (preg_match("/neighbour\b/", $line)) { $neighbour[] = $line; } if (preg_match("/xroute\b/", $line)) { $xroute[] = $line; } #if (preg_match("/\broute\b/", $read)){ break 1; } if (preg_match("/\broute\b/", $line)){ $route[] = $line; } if (preg_match("/ok/", $line)){ $set++; } if ($set == 2) { break; } } fclose($file_handle); $output['data'] = array( 'name' => $data[0], 'version' => $data[1], 'host' => $data[2], 'id' => $data[3], ); foreach ($interface as $temp) { $tempdata = explode(" ", $temp); $output['interfaces'][] = array( 'interface' => $tempdata[2], 'up' => $tempdata[4], 'ipv6' => $tempdata[6], 'ipv4' => $tempdata[8], ); } foreach ($neighbour as $temp) { $address=explode(" ",strstr($temp,"address")); $interface=explode(" ",strstr($temp,"if")); $reach=explode(" ",strstr($temp,"reach")); $rxcost=explode(" ",strstr($temp,"rxcost")); $txcost=explode(" ",strstr($temp,"txcost")); $rtt=explode(" ",strstr($temp,"rtt")); $rttcost=explode(" ",strstr($temp,"rttcost")); $cost=explode(" ",strstr($temp,"cost")); $output['neighbours'][] = array( 'address' => $address[1], 'interface' => $interface[1], 'reach' => $reach[1], 'rxcost' => $rxcost[1], 'txcost' => $txcost[1], 'rtt' => $rtt[1], 'rttcost' => $rttcost[1], 'cost' => $cost[1], ); } foreach ($xroute as $temp) { $tempdata = explode(" ", $temp); $output['xroutes'][] = array( 'prefix' => $tempdata[4], 'metric' => $tempdata[8], ); } foreach ($route as $temp) { $tempdata = explode(" ", $temp); $output['routes'][] = array( 'target' => $tempdata[4], 'installed' => $tempdata[8], 'via' => $tempdata[16], 'interface' => $tempdata[18], 'metric' => $tempdata[12], 'destid' => $tempdata[10], ); } if($_REQUEST['format'] == 'json') { echo json_encode($output); } else { # Ausgabe echo "

Simple Babelweb

"; ?>

Babel information

"; echo 'Quellcode Simple Babelweb'; foreach($output['data'] as $temp) { echo "$temp"; } echo ""; if($_GET['ip'] != '') { $ipaddr = $_GET['ip']; if ( preg_match("#/#", $ipaddr) == 0) { if ( preg_match("#:#", $ipaddr) == 0) { $ipaddr = $ipaddr . "/32"; } else { $ipaddr = $ipaddr . "/128"; } } echo '

Wege zu '.$ipaddr.'

'; echo ''; foreach($output['routes'] as $route) { if ($route['target'] == $ipaddr) { echo ""; foreach($route as $temp) { echo ""; } echo ""; } } echo "
target installed via device metric Destination ID
$temp
"; } if (empty($_GET)) { echo "

Interfaces

"; echo ''; foreach($output['interfaces'] as $interface) { echo ""; foreach($interface as $temp) { echo ""; } echo ""; } echo "
Interface up ipv6 ipv4
$temp
"; echo "

Neighbours

"; echo ''; foreach($output['neighbours'] as $neighbour) { echo ""; foreach($neighbour as $temp) { echo ""; } echo ""; } echo "
address interface reach rxcost txcost rtt rttcost cost
$temp
"; echo "

Redistributed routes

"; echo ''; foreach($output['xroutes'] as $xroute) { echo ""; foreach($xroute as $temp) { echo ""; } echo ""; } echo "
prefix metric
$temp
"; } if($_GET['routes'] == '1') { echo "

routes

"; echo ''; foreach($output['routes'] as $route) { $set=0; echo ""; foreach($route as $temp) { if ($set == 0) { echo ''; $set=1; } else { echo ""; } } echo ""; } echo "
target installed via device metric Destination ID
'.$temp.'$temp
"; } if($_GET['v4table'] == '1') { echo "

ipv4 routing table

"; echo ''; $v4routen = shell_exec('ip r s t $(grep import-table /etc/babeld.conf | cut -f2 -d" ")'); $v4route = explode(PHP_EOL, $v4routen); for($i = 0; $i < count($v4route); ++$i) { echo ""; $line = explode(" ", $v4route[$i]); for($n = 0; $n < 5; ++$n) { if ($n == 0) { echo ''; } else { echo ''; } } echo ""; } echo "
'.$line[$n].''.$line[$n].'
"; } if($_GET['v6table'] == '1') { echo "

ipv6 routing table

"; echo ''; $v6routen = shell_exec('ip -6 r s t $(grep import-table /etc/babeld.conf | cut -f2 -d" ")'); $v6route = explode(PHP_EOL, $v6routen); for($i = 0; $i < count($v6route); ++$i) { echo ""; $destination=explode(" ", $v6route[$i]); $source=explode(" ", strstr($v6route[$i],"from")); $via=explode(" ", strstr($v6route[$i],"via")); $device=explode(" ", strstr($v6route[$i],"dev")); $proto=explode(" ", strstr($v6route[$i],"proto")); $metric=explode(" ", strstr($v6route[$i],"metric")); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ""; } echo "
Destination Source Specific via Device proto Kernelmetric
'.$destination[0].''.$source[1].''.$via[1].''.$device[1].''.$proto[1].''.$metric[1].'
"; } if($_GET['lg'] == '1') { ?>
IP Adresse (v4 und v6):
";
					echo shell_exec('ping '.$ip.' -c 3 -W2');
					echo "
Traceroute $ip
";
					echo shell_exec('traceroute -w2 '.$ip.'');
					echo "
Aktuelle Route:
";
					echo shell_exec('ip route get '.$ip.'');
					echo "
"; } else { echo("This is not a valid IP address"); } } } ?>