Add button to show all routes

Signed-off-by: Robert Langhammer <rlanghammer@web.de>
This commit is contained in:
Robert Langhammer 2018-01-27 14:48:12 +01:00
parent 07fe5b0a6e
commit e0038266df
1 changed files with 171 additions and 133 deletions

304
index.php
View File

@ -1,147 +1,185 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<title>Simple Babelweb</title> <title>Simple Babelweb</title>
<style> <style>
table { table {
font-family: monospace, sans-serif; font-family: monospace, sans-serif;
border-collapse: collapse; border-collapse: collapse;
} }
td, th { td, th {
border: 1px solid #fddddd; border: 1px solid #fddddd;
text-align: left; text-align: left;
padding: 1px; padding: 1px;
padding-right: 10px; padding-right: 10px;
} }
tr:nth-child(even) { tr:nth-child(even) {
background-color: #dddddd; background-color: #dddddd;
} }
</style> </style>
</head> </head>
<body> <body>
<?php <?php
error_reporting(0); error_reporting(0);
$addr = "::1"; $addr = "::1";
$port = "33123"; $port = "33123";
$msg = "dump\r\n"; $msg = "dump\r\n";
$sock = socket_create(AF_INET6, SOCK_STREAM, 0) or die("Cannot create socket"); $sock = socket_create(AF_INET6, SOCK_STREAM, 0) or die("Cannot create socket");
socket_connect($sock, $addr, $port) or die("Cannot connect to socket"); socket_connect($sock, $addr, $port) or die("Cannot connect to socket");
$read = socket_read($sock, 1024); $read = socket_read($sock, 1024);
$data = explode(PHP_EOL, $read); $data = explode(PHP_EOL, $read);
# dump anfordern # dump anfordern
socket_write($sock, $msg, strlen($msg)); socket_write($sock, $msg, strlen($msg));
# Daten einlesen # Daten einlesen
$interface = array(); $interface = array();
$neighbour = array(); $neighbour = array();
$xroute = array(); $xroute = array();
$route= array();
while (1) { while (1) {
$read = socket_read($sock, 1024, PHP_NORMAL_READ); $read = socket_read($sock, 1024, PHP_NORMAL_READ);
if (preg_match("/interface\b/", $read)) { $interface[] = $read; } if (preg_match("/interface\b/", $read)) { $interface[] = $read; }
if (preg_match("/neighbour\b/", $read)) { $neighbour[] = $read; } if (preg_match("/neighbour\b/", $read)) { $neighbour[] = $read; }
if (preg_match("/xroute\b/", $read)) { $xroute[] = $read; } if (preg_match("/xroute\b/", $read)) { $xroute[] = $read; }
if (preg_match("/\broute\b/", $read)){ break 1; } # if (preg_match("/\broute\b/", $read)){ break 1; }
} if (preg_match("/\broute\b/", $read)){ $route[] = $read; }
socket_close($sock); if (preg_match("/ok/", $read)){ break 1; }
}
socket_close($sock);
$output['data'] = array( $output['data'] = array(
'name' => $data[0], 'name' => $data[0],
'version' => $data[1], 'version' => $data[1],
'host' => $data[2], 'host' => $data[2],
'id' => $data[3], 'id' => $data[3],
); );
foreach ($interface as $temp) { foreach ($interface as $temp) {
$tempdata = explode(" ", $temp); $tempdata = explode(" ", $temp);
$output['interfaces'][] = array( $output['interfaces'][] = array(
'interface' => $tempdata[2], 'interface' => $tempdata[2],
'up' => $tempdata[4], 'up' => $tempdata[4],
'ipv6' => $tempdata[6], 'ipv6' => $tempdata[6],
'ipv4' => $tempdata[8], 'ipv4' => $tempdata[8],
); );
} }
foreach ($neighbour as $temp) { foreach ($neighbour as $temp) {
$tempdata = explode(" ", $temp); $tempdata = explode(" ", $temp);
$output['neighbours'][] = array( $output['neighbours'][] = array(
'address' => $tempdata[4], 'address' => $tempdata[4],
'interface' => $tempdata[6], 'interface' => $tempdata[6],
'reach' => $tempdata[8], 'reach' => $tempdata[8],
'rxcost' => $tempdata[10], 'rxcost' => $tempdata[10],
'txcost' => $tempdata[12], 'txcost' => $tempdata[12],
'rtt' => $tempdata[14], 'rtt' => $tempdata[14],
'rttcost' => $tempdata[16], 'rttcost' => $tempdata[16],
'cost' => $tempdata[18], 'cost' => $tempdata[18],
); );
} }
foreach ($xroute as $temp) { foreach ($xroute as $temp) {
$tempdata = explode(" ", $temp); $tempdata = explode(" ", $temp);
$output['xroutes'][] = array( $output['xroutes'][] = array(
'prefix' => $tempdata[4], 'prefix' => $tempdata[4],
'metric' => $tempdata[8], 'metric' => $tempdata[8],
); );
} }
if($_REQUEST['format'] == 'json') { echo json_encode($output); } foreach ($route as $temp) {
else { $tempdata = explode(" ", $temp);
# Ausgabe $output['routes'][] = array(
echo "<h1>Simple Babelweb</h1>"; 'target' => $tempdata[4],
echo "<table>"; 'installed' => $tempdata[8],
foreach($output['data'] as $temp) { echo "<tr><td>$temp</td></tr>"; } 'via' => $tempdata[16],
echo "</table>"; 'interface' => $tempdata[18],
'metric' => $tempdata[12],
);
}
echo "<H2>Interfaces</H2>";
echo '<table>
<tr>
<th>Interface</th>
<th>up</th>
<th>ipv6</th>
<th>ipv4</th>
</tr>';
foreach($output['interfaces'] as $interface) {
echo "<tr>";
foreach($interface as $temp) { echo "<td>$temp</td>"; }
echo "</tr>";
}
echo "</table>";
echo "<H2>Neighbours</H2>"; if($_REQUEST['format'] == 'json') { echo json_encode($output); }
echo '<table> else {
<tr> # Ausgabe
<th>address</th> echo "<h1>Simple Babelweb</h1>";
<th>interface</th> echo "<table>";
<th>reach</th> foreach($output['data'] as $temp) { echo "<tr><td>$temp</td></tr>"; }
<th>rxcost</th> echo "</table>";
<th>txcost</th>
<th>rtt</th>
<th>rttcost</th>
<th>cost</th>
</tr>';
foreach($output['neighbours'] as $neighbour) {
echo "<tr>";
foreach($neighbour as $temp) { echo "<td>$temp</td>"; }
echo "</tr>";
}
echo "</table>";
echo "<H2>Redistributed routes</H2>"; echo "<H2>Interfaces</H2>";
echo '<table> echo '<table>
<tr> <tr>
<th>prefix</th> <th>Interface</th>
<th>metric</th> <th>up</th>
</tr>'; <th>ipv6</th>
foreach($output['xroutes'] as $xroute) { <th>ipv4</th>
echo "<tr>"; </tr>';
foreach($xroute as $temp) { echo "<td>$temp</td>"; } foreach($output['interfaces'] as $interface) {
echo "</tr>"; echo "<tr>";
} foreach($interface as $temp) { echo "<td>$temp</td>"; }
echo "</table>"; echo "</tr>";
} }
?> echo "</table>";
</body>
echo "<H2>Neighbours</H2>";
echo '<table>
<tr>
<th>address</th>
<th>interface</th>
<th>reach</th>
<th>rxcost</th>
<th>txcost</th>
<th>rtt</th>
<th>rttcost</th>
<th>cost</th>
</tr>';
foreach($output['neighbours'] as $neighbour) {
echo "<tr>";
foreach($neighbour as $temp) { echo "<td>$temp</td>"; }
echo "</tr>";
}
echo "</table>";
echo "<H2>Redistributed routes</H2>";
echo '<table>
<tr>
<th>prefix</th>
<th>metric</th>
</tr>';
foreach($output['xroutes'] as $xroute) {
echo "<tr>";
foreach($xroute as $temp) { echo "<td>$temp</td>"; }
echo "</tr>";
}
echo "</table>";
if($_REQUEST['routes'] == '1') {
echo "<H2>routes</H2>";
echo '<table>
<tr>
<th>target</th>
<th>installed</th>
<th>via</th>
<th>device</th>
<th>metric</th>
</tr>';
foreach($output['routes'] as $route) {
echo "<tr>";
foreach($route as $temp) { echo "<td>$temp</td>"; }
echo "</tr>";
}
echo "</table>";
}
}
?>
<br>
<form action="index.php" method="post">
<button type="submit" name="routes" value="1">show all routes</button>
</form>
</body>
</html> </html>