'.$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'] != '') {
echo 'Wege zu '.$_GET["ip"].'
';
echo '
target |
installed |
via |
device |
metric |
Destination ID |
';
foreach($output['routes'] as $route) {
if ($route['target'] == $_GET['ip']) {
echo "";
foreach($route as $temp) { echo "$temp | "; }
echo "
";
}
}
echo "
";
}
if (empty($_GET)) {
echo "Interfaces
";
echo '
Interface |
up |
ipv6 |
ipv4 |
';
foreach($output['interfaces'] as $interface) {
echo "";
foreach($interface as $temp) { echo "$temp | "; }
echo "
";
}
echo "
";
echo "Neighbours
";
echo '
address |
interface |
reach |
rxcost |
txcost |
rtt |
rttcost |
cost |
';
foreach($output['neighbours'] as $neighbour) {
echo "";
foreach($neighbour as $temp) { echo "$temp | "; }
echo "
";
}
echo "
";
echo "Redistributed routes
";
echo '
prefix |
metric |
';
foreach($output['xroutes'] as $xroute) {
echo "";
foreach($xroute as $temp) { echo "$temp | "; }
echo "
";
}
echo "
";
}
if($_GET['routes'] == '1') {
echo "routes
";
echo '
target |
installed |
via |
device |
metric |
Destination ID |
';
foreach($output['routes'] as $route) {
$set=0;
echo "";
foreach($route as $temp) {
if ($set == 0) {
echo ''.$temp.' | ';
$set=1;
}
else {
echo "$temp | ";
}
}
echo "
";
}
echo "
";
}
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 ''.$line[$n].' | ';
}
else {
echo ''.$line[$n].' | ';
}
}
echo "
";
}
echo "
";
}
if($_GET['v6table'] == '1') {
echo "ipv6 routing table
";
echo '
Destination |
Source Specific |
via |
Device |
proto |
Kernelmetric |
';
$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 ''.$destination[0].' | ';
echo ''.$source[1].' | ';
echo ''.$via[1].' | ';
echo ''.$device[1].' | ';
echo ''.$proto[1].' | ';
echo ''.$metric[1].' | ';
echo "
";
}
echo "
";
}
if($_GET['lg'] == '1') {
?>
";
echo shell_exec('ping '.$ip.' -c 3');
echo "
Traceroute $ip
";
echo shell_exec('traceroute '.$ip.'');
echo "
Aktuelle Route:";
echo shell_exec('ip route get '.$ip.'');
echo "
";
} else {
echo("This is not a valid IP address");
}
}
}
?>