Merge pull request #7 from ChristianDresel/master

Einrückungen komplett auf Tabs umgestellt
This commit is contained in:
Robert Langhammer 2018-08-18 21:16:44 +02:00 committed by GitHub
commit be7dfbe0a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 217 additions and 233 deletions

450
index.php
View File

@ -1,265 +1,249 @@
<!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 = shell_exec('grep local-port /etc/babeld.conf | cut -d" " -f 2'); $port = shell_exec('grep local-port /etc/babeld.conf | cut -d" " -f 2');
$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(); $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; } if (preg_match("/\broute\b/", $read)){ $route[] = $read; }
if (preg_match("/ok/", $read)){ break 1; } if (preg_match("/ok/", $read)){ break 1; }
} }
socket_close($sock); 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) {
$tempdata = explode(" ", $temp);
$output['neighbours'][] = array(
'address' => $tempdata[4],
'interface' => $tempdata[6],
'reach' => $tempdata[8],
'rxcost' => $tempdata[10],
'txcost' => $tempdata[12],
'rtt' => $tempdata[14],
'rttcost' => $tempdata[16],
'cost' => $tempdata[18],
);
}
foreach ($neighbour as $temp) { foreach ($xroute as $temp) {
$tempdata = explode(" ", $temp); $tempdata = explode(" ", $temp);
$output['neighbours'][] = array( $output['xroutes'][] = array(
'address' => $tempdata[4], 'prefix' => $tempdata[4],
'interface' => $tempdata[6], 'metric' => $tempdata[8],
'reach' => $tempdata[8], );
'rxcost' => $tempdata[10], }
'txcost' => $tempdata[12],
'rtt' => $tempdata[14],
'rttcost' => $tempdata[16],
'cost' => $tempdata[18],
);
}
foreach ($xroute as $temp) { foreach ($route as $temp) {
$tempdata = explode(" ", $temp); $tempdata = explode(" ", $temp);
$output['xroutes'][] = array( $output['routes'][] = array(
'prefix' => $tempdata[4], 'target' => $tempdata[4],
'metric' => $tempdata[8], 'installed' => $tempdata[8],
); 'via' => $tempdata[16],
} 'interface' => $tempdata[18],
'metric' => $tempdata[12],
foreach ($route as $temp) { 'destid' => $tempdata[10],
$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); } if($_REQUEST['format'] == 'json') {
else { echo json_encode($output); }
# Ausgabe else {
echo "<h1>Simple Babelweb</h1>"; # Ausgabe
echo "<table>"; echo "<h1>Simple Babelweb</h1>";
foreach($output['data'] as $temp) { echo "<tr><td>$temp</td></tr>"; } echo "<table>";
echo "</table>"; foreach($output['data'] as $temp) { echo "<tr><td>$temp</td></tr>"; }
echo "</table>";
echo "<H2>Interfaces</H2>"; echo "<H2>Interfaces</H2>";
echo '<table> echo '<table>
<tr> <tr>
<th>Interface</th> <th>Interface</th>
<th>up</th> <th>up</th>
<th>ipv6</th> <th>ipv6</th>
<th>ipv4</th> <th>ipv4</th>
</tr>'; </tr>';
foreach($output['interfaces'] as $interface) { foreach($output['interfaces'] as $interface) {
echo "<tr>"; echo "<tr>";
foreach($interface as $temp) { echo "<td>$temp</td>"; } foreach($interface as $temp) { echo "<td>$temp</td>"; }
echo "</tr>"; echo "</tr>";
} }
echo "</table>"; echo "</table>";
echo "<H2>Neighbours</H2>";
echo "<H2>Neighbours</H2>"; echo '<table>
echo '<table> <tr>
<tr> <th>address</th>
<th>address</th> <th>interface</th>
<th>interface</th> <th>reach</th>
<th>reach</th> <th>rxcost</th>
<th>rxcost</th> <th>txcost</th>
<th>txcost</th> <th>rtt</th>
<th>rtt</th> <th>rttcost</th>
<th>rttcost</th> <th>cost</th>
<th>cost</th> </tr>';
</tr>'; foreach($output['neighbours'] as $neighbour) {
foreach($output['neighbours'] as $neighbour) { echo "<tr>";
echo "<tr>"; foreach($neighbour as $temp) { echo "<td>$temp</td>"; }
foreach($neighbour as $temp) { echo "<td>$temp</td>"; } echo "</tr>";
echo "</tr>"; }
} echo "</table>";
echo "</table>"; echo "<H2>Redistributed routes</H2>";
echo '<table>
echo "<H2>Redistributed routes</H2>"; <tr>
echo '<table> <th>prefix</th>
<tr> <th>metric</th>
<th>prefix</th> </tr>';
<th>metric</th> foreach($output['xroutes'] as $xroute) {
</tr>'; echo "<tr>";
foreach($output['xroutes'] as $xroute) { foreach($xroute as $temp) { echo "<td>$temp</td>"; }
echo "<tr>"; echo "</tr>";
foreach($xroute as $temp) { echo "<td>$temp</td>"; } }
echo "</tr>"; echo "</table>";
} if($_REQUEST['routes'] == '1') {
echo "</table>"; echo "<H2>routes</H2>";
if($_REQUEST['routes'] == '1') { echo '<table>
<tr>
echo "<H2>routes</H2>"; <th>target</th>
echo '<table> <th>installed</th>
<tr> <th>via</th>
<th>target</th> <th>device</th>
<th>installed</th> <th>metric</th>
<th>via</th> <th>Destination ID</th>
<th>device</th> </tr>';
<th>metric</th> foreach($output['routes'] as $route) {
<th>Destination ID</th> echo "<tr>";
</tr>'; foreach($route as $temp) { echo "<td>$temp</td>"; }
foreach($output['routes'] as $route) { echo "</tr>";
echo "<tr>"; }
foreach($route as $temp) { echo "<td>$temp</td>"; } echo "</table>";
echo "</tr>"; }
}
echo "</table>";
}
if($_REQUEST['v4table'] == '1') { if($_REQUEST['v4table'] == '1') {
echo "<H2>ipv4 routing table</H2>";
echo "<H2>ipv4 routing table</H2>"; echo '<table>';
echo '<table>';
$v4routen = shell_exec('ip r s t $(grep import-table /etc/babeld.conf | cut -f2 -d" ")'); $v4routen = shell_exec('ip r s t $(grep import-table /etc/babeld.conf | cut -f2 -d" ")');
$v4route = explode(PHP_EOL, $v4routen); $v4route = explode(PHP_EOL, $v4routen);
for($i = 0; $i < count($v4route); ++$i) { for($i = 0; $i < count($v4route); ++$i) {
echo "<tr>"; echo "<tr>";
$line = explode(" ", $v4route[$i]); $line = explode(" ", $v4route[$i]);
for($n = 0; $n < 5; ++$n) { for($n = 0; $n < 5; ++$n) {
if ($n == 0) if ($n == 0) {
{ echo '<td><a href="'.$_SERVER["PHP_SELF"].'/?ip='.$line[$n].'">'.$line[$n].'</a></td>';
echo '<td><a href="'.$_SERVER["PHP_SELF"].'/?ip='.$line[$n].'">'.$line[$n].'</a></td>'; }
} else {
else echo '<td>'.$line[$n].'</td>';
{ }
echo '<td>'.$line[$n].'</td>';
}
} }
echo "</tr>"; echo "</tr>";
} }
echo "</table>";
echo "</table>"; }
}
if($_REQUEST['v6table'] == '1') {
if($_REQUEST['v6table'] == '1') { echo "<H2>ipv6 routing table</H2>";
echo '<table>';
echo "<H2>ipv6 routing table</H2>";
echo '<table>';
$v6routen = shell_exec('ip -6 r s t $(grep import-table /etc/babeld.conf | cut -f2 -d" ")'); $v6routen = shell_exec('ip -6 r s t $(grep import-table /etc/babeld.conf | cut -f2 -d" ")');
$v6route = explode(PHP_EOL, $v6routen); $v6route = explode(PHP_EOL, $v6routen);
for($i = 0; $i < count($v6route); ++$i) { for($i = 0; $i < count($v6route); ++$i) {
echo "<tr>"; echo "<tr>";
$line = explode(" ", $v6route[$i]); $line = explode(" ", $v6route[$i]);
for($n = 0; $n < 8; ++$n) { for($n = 0; $n < 8; ++$n) {
if ($n == 0) if ($n == 0) {
{ echo '<td><a href="'.$_SERVER["PHP_SELF"].'/?ip='.$line[$n].'">'.$line[$n].'</a></td>';
echo '<td><a href="'.$_SERVER["PHP_SELF"].'/?ip='.$line[$n].'">'.$line[$n].'</a></td>';
}
else
{
echo '<td>'.$line[$n].'</td>';
}
} }
echo "</tr>"; else {
} echo '<td>'.$line[$n].'</td>';
}
}
echo "</tr>";
}
echo "</table>"; echo "</table>";
} }
if($_GET['ip'] != '') { if($_GET['ip'] != '') {
echo '<H2>Wege zu '.$_GET["ip"].'</H2>'; echo '<H2>Wege zu '.$_GET["ip"].'</H2>';
echo '<table> echo '<table>
<tr> <tr>
<th>target</th> <th>target</th>
<th>installed</th> <th>installed</th>
<th>via</th> <th>via</th>
<th>device</th> <th>device</th>
<th>metric</th> <th>metric</th>
<th>Destination ID</th> <th>Destination ID</th>
</tr>'; </tr>';
foreach($output['routes'] as $route) { foreach($output['routes'] as $route) {
if ($route['target'] == $_GET['ip']) if ($route['target'] == $_GET['ip'])
{ {
echo "<tr>"; echo "<tr>";
foreach($route as $temp) { echo "<td>$temp</td>"; } foreach($route as $temp) { echo "<td>$temp</td>"; }
echo "</tr>"; echo "</tr>";
} }
} }
echo "</table>"; echo "</table>";
} }
}
?>
} <br>
?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<br> <button type="submit" name="routes" value="1">show all babel routes</button>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <button type="submit" name="v4table" value="1">show import/export table ipv4</button>
<button type="submit" name="routes" value="1">show all babel routes</button> <button type="submit" name="v6table" value="1">show import/export table ipv6</button>
<button type="submit" name="v4table" value="1">show import/export table ipv4</button> </form>
<button type="submit" name="v6table" value="1">show import/export table ipv6</button> </body>
</form>
</body>
</html> </html>