diff --git a/index.php b/index.php index 01cc32d..b21551e 100644 --- a/index.php +++ b/index.php @@ -1,139 +1,150 @@ - - - - Simple Babelweb + + + + Simple Babelweb + + + + -table { - font-family: monospace, sans-serif; - border-collapse: collapse; -} + $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); -td, th { - border: 1px solid #fddddd; - text-align: left; - padding: 1px; - padding-right: 10px; -} + # dump anfordern + socket_write($sock, $msg, strlen($msg)); -tr:nth-child(even) { - background-color: #dddddd; -} - - - - -

Simple Babelweb

- $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], + ); + } -$data = explode(PHP_EOL, $read); + foreach ($neighbour as $temp) { + $tempdata = explode(" ", $temp); + $output['neighbours'][] = array( + 'neighbour' => $tempdata[2], + 'address' => $tempdata[4], + 'interface' => $tempdata[6], + 'reach' => $tempdata[8], + 'rxcost' => $tempdata[10], + 'txcost' => $tempdata[12], + 'rtt' => $tempdata[14], + 'rttcost' => $tempdata[16], + 'cost' => $tempdata[18], + ); + } -echo ""; -for($i = 0; $i < count($data); ++$i) { - if ($data[$i] == "ok"){ - break; -} - echo ""; -} -echo "
$data[$i]
"; + foreach ($xroute as $temp) { + $tempdata = explode(" ", $temp); + $output['xroutes'][] = array( + 'prefix' => $tempdata[2], + 'from' => $tempdata[4], + 'metric' => $tempdata[6], + ); + } -# dump anfordern -socket_write($sock,$msg,strlen($msg)); + if($_REQUEST['format'] == 'json') { echo json_encode($output); } + else { + # Ausgabe + echo "

Simple Babelweb

"; + echo ""; + foreach($output['data'] as $temp) { echo ""; } + echo "
$temp
"; -# Daten einlesen -$interface = array(); -$neighbour = array(); -$xroute = array(); + echo "

Interfaces

"; + echo ' + + + + + + '; + foreach($output['interfaces'] as $interface) { + echo ""; + foreach($interface as $temp) { echo ""; } + echo ""; + } + echo "
Interfaceupipv6ipv4
$temp
"; -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; - } -} + echo "

Neighbours

"; + echo ' + + + + + + + + + + + '; + foreach($output['neighbours'] as $neighbour) { + echo ""; + foreach($neighbour as $temp) { echo ""; } + echo ""; + } + echo "
neighbouraddressinterfacereachrxcosttxcostrttrttcostcost
$temp
"; -socket_close($sock); - -# Ausgabe -echo "

Interfaces

"; -echo ' - - - - - - '; - -for($n = 0; $n < count($interface); ++$n){ - $data = explode(" ", $interface[$n]); - echo ""; - for($i = 2; $i < count($data); $i+=2) { - echo ""; - } - echo ""; -} -echo "
Interfaceupipv6ipv4
$data[$i]
"; - -echo "

Neighbours

"; -echo ' - - - - - - - - - - - '; - -for($n = 0; $n < count($neighbour); ++$n){ - $data = explode(" ", $neighbour[$n]); - echo ""; - for($i = 2; $i < count($data); $i+=2) { - echo ""; - } - echo ""; -} -echo "
neighbouraddressinterfacereachrxcosttxcostrttrttcostcost
$data[$i]
"; - - -echo "

Redistributed routes

"; -echo ' - - - - - '; - -for($n = 0; $n < count($xroute); ++$n){ - $data = explode(" ", $xroute[$n]); - echo ""; - for($i = 4; $i < count($data); $i+=2) { - echo ""; - } - echo ""; -} -echo "
prefixfrommetric
$data[$i]
"; -?> - - + echo "

Redistributed routes

"; + echo ' + + + + + '; + foreach($output['xroutes'] as $xroute) { + echo ""; + foreach($xroute as $temp) { echo ""; } + echo ""; + } + echo "
prefixfrommetric
$temp
"; + } + ?> + + \ No newline at end of file