forked from freifunk-franken/simple-babelweb
Einrückungen komplett auf Tabs umgestellt
Signed-off-by: Christian Dresel <fff@chrisi01.de>
This commit is contained in:
parent
cede2d67d0
commit
6d136b4f67
446
index.php
446
index.php
|
@ -1,265 +1,249 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Simple Babelweb</title>
|
||||
<style>
|
||||
table {
|
||||
font-family: monospace, sans-serif;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
td, th {
|
||||
border: 1px solid #fddddd;
|
||||
text-align: left;
|
||||
padding: 1px;
|
||||
padding-right: 10px;
|
||||
}
|
||||
tr:nth-child(even) {
|
||||
background-color: #dddddd;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
error_reporting(0);
|
||||
$addr = "::1";
|
||||
$port = shell_exec('grep local-port /etc/babeld.conf | cut -d" " -f 2');
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Simple Babelweb</title>
|
||||
<style>
|
||||
table {
|
||||
font-family: monospace, sans-serif;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
td, th {
|
||||
border: 1px solid #fddddd;
|
||||
text-align: left;
|
||||
padding: 1px;
|
||||
padding-right: 10px;
|
||||
}
|
||||
tr:nth-child(even) {
|
||||
background-color: #dddddd;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
error_reporting(0);
|
||||
$addr = "::1";
|
||||
$port = shell_exec('grep local-port /etc/babeld.conf | cut -d" " -f 2');
|
||||
|
||||
$msg = "dump\r\n";
|
||||
$sock = socket_create(AF_INET6, SOCK_STREAM, 0) or die("Cannot create socket");
|
||||
socket_connect($sock, $addr, $port) or die("Cannot connect to socket");
|
||||
$read = socket_read($sock, 1024);
|
||||
$data = explode(PHP_EOL, $read);
|
||||
$msg = "dump\r\n";
|
||||
$sock = socket_create(AF_INET6, SOCK_STREAM, 0) or die("Cannot create socket");
|
||||
socket_connect($sock, $addr, $port) or die("Cannot connect to socket");
|
||||
$read = socket_read($sock, 1024);
|
||||
$data = explode(PHP_EOL, $read);
|
||||
|
||||
# dump anfordern
|
||||
socket_write($sock, $msg, strlen($msg));
|
||||
# dump anfordern
|
||||
socket_write($sock, $msg, strlen($msg));
|
||||
|
||||
# Daten einlesen
|
||||
$interface = array();
|
||||
$neighbour = array();
|
||||
$xroute = array();
|
||||
$route= array();
|
||||
# Daten einlesen
|
||||
$interface = array();
|
||||
$neighbour = array();
|
||||
$xroute = array();
|
||||
$route= array();
|
||||
|
||||
while (1) {
|
||||
$read = socket_read($sock, 1024, PHP_NORMAL_READ);
|
||||
if (preg_match("/interface\b/", $read)) { $interface[] = $read; }
|
||||
if (preg_match("/neighbour\b/", $read)) { $neighbour[] = $read; }
|
||||
if (preg_match("/xroute\b/", $read)) { $xroute[] = $read; }
|
||||
# if (preg_match("/\broute\b/", $read)){ break 1; }
|
||||
if (preg_match("/\broute\b/", $read)){ $route[] = $read; }
|
||||
if (preg_match("/ok/", $read)){ break 1; }
|
||||
}
|
||||
socket_close($sock);
|
||||
while (1) {
|
||||
$read = socket_read($sock, 1024, PHP_NORMAL_READ);
|
||||
if (preg_match("/interface\b/", $read)) { $interface[] = $read; }
|
||||
if (preg_match("/neighbour\b/", $read)) { $neighbour[] = $read; }
|
||||
if (preg_match("/xroute\b/", $read)) { $xroute[] = $read; }
|
||||
#if (preg_match("/\broute\b/", $read)){ break 1; }
|
||||
if (preg_match("/\broute\b/", $read)){ $route[] = $read; }
|
||||
if (preg_match("/ok/", $read)){ break 1; }
|
||||
}
|
||||
socket_close($sock);
|
||||
|
||||
$output['data'] = array(
|
||||
'name' => $data[0],
|
||||
'version' => $data[1],
|
||||
'host' => $data[2],
|
||||
'id' => $data[3],
|
||||
);
|
||||
$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 ($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) {
|
||||
$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) {
|
||||
$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 ($xroute as $temp) {
|
||||
$tempdata = explode(" ", $temp);
|
||||
$output['xroutes'][] = array(
|
||||
'prefix' => $tempdata[4],
|
||||
'metric' => $tempdata[8],
|
||||
);
|
||||
}
|
||||
|
||||
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],
|
||||
);
|
||||
}
|
||||
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 "<h1>Simple Babelweb</h1>";
|
||||
echo "<table>";
|
||||
foreach($output['data'] as $temp) { echo "<tr><td>$temp</td></tr>"; }
|
||||
echo "</table>";
|
||||
|
||||
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>";
|
||||
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>
|
||||
<th>Destination ID</th>
|
||||
</tr>';
|
||||
foreach($output['routes'] as $route) {
|
||||
echo "<tr>";
|
||||
foreach($route as $temp) { echo "<td>$temp</td>"; }
|
||||
echo "</tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
}
|
||||
if($_REQUEST['format'] == 'json') {
|
||||
echo json_encode($output); }
|
||||
else {
|
||||
# Ausgabe
|
||||
echo "<h1>Simple Babelweb</h1>";
|
||||
echo "<table>";
|
||||
foreach($output['data'] as $temp) { echo "<tr><td>$temp</td></tr>"; }
|
||||
echo "</table>";
|
||||
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>";
|
||||
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>
|
||||
<th>Destination ID</th>
|
||||
</tr>';
|
||||
foreach($output['routes'] as $route) {
|
||||
echo "<tr>";
|
||||
foreach($route as $temp) { echo "<td>$temp</td>"; }
|
||||
echo "</tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
}
|
||||
|
||||
|
||||
if($_REQUEST['v4table'] == '1') {
|
||||
|
||||
echo "<H2>ipv4 routing table</H2>";
|
||||
echo '<table>';
|
||||
if($_REQUEST['v4table'] == '1') {
|
||||
echo "<H2>ipv4 routing table</H2>";
|
||||
echo '<table>';
|
||||
$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 "<tr>";
|
||||
$line = explode(" ", $v4route[$i]);
|
||||
for($n = 0; $n < 5; ++$n) {
|
||||
if ($n == 0)
|
||||
{
|
||||
echo '<td><a href="'.$_SERVER["PHP_SELF"].'/?ip='.$line[$n].'">'.$line[$n].'</a></td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
echo '<td>'.$line[$n].'</td>';
|
||||
}
|
||||
|
||||
if ($n == 0) {
|
||||
echo '<td><a href="'.$_SERVER["PHP_SELF"].'/?ip='.$line[$n].'">'.$line[$n].'</a></td>';
|
||||
}
|
||||
else {
|
||||
echo '<td>'.$line[$n].'</td>';
|
||||
}
|
||||
}
|
||||
echo "</tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
}
|
||||
|
||||
echo "</table>";
|
||||
}
|
||||
|
||||
if($_REQUEST['v6table'] == '1') {
|
||||
|
||||
echo "<H2>ipv6 routing table</H2>";
|
||||
echo '<table>';
|
||||
if($_REQUEST['v6table'] == '1') {
|
||||
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" ")');
|
||||
$v6route = explode(PHP_EOL, $v6routen);
|
||||
for($i = 0; $i < count($v6route); ++$i) {
|
||||
echo "<tr>";
|
||||
$line = explode(" ", $v6route[$i]);
|
||||
for($n = 0; $n < 8; ++$n) {
|
||||
if ($n == 0)
|
||||
{
|
||||
echo '<td><a href="'.$_SERVER["PHP_SELF"].'/?ip='.$line[$n].'">'.$line[$n].'</a></td>';
|
||||
}
|
||||
else
|
||||
{
|
||||
echo '<td>'.$line[$n].'</td>';
|
||||
}
|
||||
|
||||
if ($n == 0) {
|
||||
echo '<td><a href="'.$_SERVER["PHP_SELF"].'/?ip='.$line[$n].'">'.$line[$n].'</a></td>';
|
||||
}
|
||||
else {
|
||||
echo '<td>'.$line[$n].'</td>';
|
||||
}
|
||||
echo "</tr>";
|
||||
}
|
||||
echo "</tr>";
|
||||
}
|
||||
|
||||
echo "</table>";
|
||||
}
|
||||
if($_GET['ip'] != '') {
|
||||
echo '<H2>Wege zu '.$_GET["ip"].'</H2>';
|
||||
echo '<table>
|
||||
<tr>
|
||||
<th>target</th>
|
||||
<th>installed</th>
|
||||
<th>via</th>
|
||||
<th>device</th>
|
||||
<th>metric</th>
|
||||
<th>Destination ID</th>
|
||||
</tr>';
|
||||
foreach($output['routes'] as $route) {
|
||||
if ($route['target'] == $_GET['ip'])
|
||||
{
|
||||
echo "<tr>";
|
||||
foreach($route as $temp) { echo "<td>$temp</td>"; }
|
||||
echo "</tr>";
|
||||
}
|
||||
}
|
||||
echo "</table>";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
<br>
|
||||
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
|
||||
<button type="submit" name="routes" value="1">show all babel routes</button>
|
||||
<button type="submit" name="v4table" value="1">show import/export table ipv4</button>
|
||||
<button type="submit" name="v6table" value="1">show import/export table ipv6</button>
|
||||
</form>
|
||||
|
||||
</body>
|
||||
echo "</table>";
|
||||
}
|
||||
if($_GET['ip'] != '') {
|
||||
echo '<H2>Wege zu '.$_GET["ip"].'</H2>';
|
||||
echo '<table>
|
||||
<tr>
|
||||
<th>target</th>
|
||||
<th>installed</th>
|
||||
<th>via</th>
|
||||
<th>device</th>
|
||||
<th>metric</th>
|
||||
<th>Destination ID</th>
|
||||
</tr>';
|
||||
foreach($output['routes'] as $route) {
|
||||
if ($route['target'] == $_GET['ip'])
|
||||
{
|
||||
echo "<tr>";
|
||||
foreach($route as $temp) { echo "<td>$temp</td>"; }
|
||||
echo "</tr>";
|
||||
}
|
||||
}
|
||||
echo "</table>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
<br>
|
||||
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
|
||||
<button type="submit" name="routes" value="1">show all babel routes</button>
|
||||
<button type="submit" name="v4table" value="1">show import/export table ipv4</button>
|
||||
<button type="submit" name="v6table" value="1">show import/export table ipv6</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue
Block a user