From d25f3c2750eefe3c49b3473dea9581e0e4ce529c Mon Sep 17 00:00:00 2001 From: Dennis Eisold Date: Fri, 29 Dec 2017 23:45:10 +0100 Subject: [PATCH 1/4] added json output --- index.php | 285 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 158 insertions(+), 127 deletions(-) diff --git a/index.php b/index.php index 01cc32d..d2813ab 100644 --- a/index.php +++ b/index.php @@ -1,139 +1,170 @@ - - - - Simple Babelweb + + + + Simple Babelweb - + -td, th { - border: 1px solid #fddddd; - text-align: left; - padding: 1px; - padding-right: 10px; -} + + - - - -

Simple Babelweb

- $interface, + 'neighbour' => $neighbour, + 'xroute' => $xroute, + )); + socket_close($sock); -echo ""; -for($i = 0; $i < count($data); ++$i) { - if ($data[$i] == "ok"){ - break; -} - echo ""; -} -echo "
$data[$i]
"; + foreach ($interface as $temp) { + $tempdata = explode(" ", $temp); + $output['interfaces'][] = array( + 'interface' => $tempdata[2], + 'up' => $tempdata[4], + 'ipv6' => $tempdata[6], + 'ipv4' => $tempdata[8], + ); + } -# dump anfordern -socket_write($sock,$msg,strlen($msg)); + 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], + ); + } -# Daten einlesen -$interface = array(); -$neighbour = array(); -$xroute = array(); + foreach ($xroute as $temp) { + $tempdata = explode(" ", $temp); + $output['xroutes'][] = array( + 'prefix' => $tempdata[2], + 'from' => $tempdata[4], + 'metric' => $tempdata[6], + ); + } -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($_REQUEST['format'] == 'json') { + echo json_encode($output); + } + else { + # Ausgabe + echo "

Simple Babelweb

"; + echo ""; + for($i = 0; $i < count($data); ++$i) { + if ($data[$i] == "ok") { + break; + } + echo ""; + } + echo "
$data[$i]
"; -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 "

Interfaces

"; + echo ' + + + + + + '; + foreach($output['interfaces'] as $interface) { + echo "". + "". + "". + ""; + } + echo "
Interfaceupipv6ipv4
".$interface['interface']."".$interface['up']."".$interface['ipv6']."".$interface['ipv4']."
"; + echo "

Neighbours

"; + echo ' + + + + + + + + + + + '; + foreach($output['neighbours'] as $neighbour) { + echo "". + "". + "". + "". + "". + "". + "". + "". + ""; + } + echo "
neighbouraddressinterfacereachrxcosttxcostrttrttcostcost
".$neighbour['neighbour']."".$neighbour['address']."".$neighbour['interface']."".$neighbour['reach']."".$neighbour['rxcost']."".$neighbour['txcost']."".$neighbour['rtt']."".$neighbour['rttcost']."".$neighbour['cost']."
"; + echo "

Redistributed routes

"; + echo ' + + + + + '; + foreach($output['xroutes'] as $xroute) { + echo "". + "". + ""; + } + echo "
prefixfrommetric
".$xroute['prefix']."".$xroute['from']."".$xroute['metric']."
"; + } + ?> + + From 9ec1e3f63d0dc243293b236e87355907554fb452 Mon Sep 17 00:00:00 2001 From: Dennis Eisold Date: Fri, 29 Dec 2017 23:48:35 +0100 Subject: [PATCH 2/4] deleted trash lines --- index.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/index.php b/index.php index d2813ab..9e5388c 100644 --- a/index.php +++ b/index.php @@ -55,11 +55,6 @@ break 1; } } - $json = json_encode(array( - 'interface' => $interface, - 'neighbour' => $neighbour, - 'xroute' => $xroute, - )); socket_close($sock); foreach ($interface as $temp) { From fc0e788ee194d71fafe9d3317d5297fb82c2a627 Mon Sep 17 00:00:00 2001 From: Dennis Eisold Date: Sat, 30 Dec 2017 00:08:54 +0100 Subject: [PATCH 3/4] minified html --- index.php | 112 ++++++++++++++++++++++++------------------------------ 1 file changed, 50 insertions(+), 62 deletions(-) diff --git a/index.php b/index.php index 9e5388c..14f529a 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,6 @@ Simple Babelweb - - $data[0], + 'version' => $data[1], + 'host' => $data[2], + 'id' => $data[3], + ); + foreach ($interface as $temp) { $tempdata = explode(" ", $temp); $output['interfaces'][] = array( @@ -91,19 +88,15 @@ ); } - if($_REQUEST['format'] == 'json') { - echo json_encode($output); - } + if($_REQUEST['format'] == 'json') { echo json_encode($output); } else { # Ausgabe echo "

Simple Babelweb

"; echo ""; - for($i = 0; $i < count($data); ++$i) { - if ($data[$i] == "ok") { - break; - } - echo ""; - } + echo ""; + echo ""; + echo ""; + echo ""; echo "
$data[$i]
".$output['data']['name']."
".$output['data']['version']."
".$output['data']['host']."
".$output['data']['id']."
"; echo "

Interfaces

"; @@ -115,51 +108,46 @@ ipv4 '; foreach($output['interfaces'] as $interface) { - echo "".$interface['interface']."". - "".$interface['up']."". - "".$interface['ipv6']."". - "".$interface['ipv4'].""; + echo ""; + foreach($interface as $temp) { echo "$temp"; } + echo ""; } echo ""; + echo "

Neighbours

"; - echo ' - - - - - - - - - - - '; + echo '
neighbouraddressinterfacereachrxcosttxcostrttrttcostcost
+ + + + + + + + + + + '; foreach($output['neighbours'] as $neighbour) { - echo "". - "". - "". - "". - "". - "". - "". - "". - ""; + echo ""; + foreach($neighbour as $temp) { echo ""; } + echo ""; } echo "
neighbouraddressinterfacereachrxcosttxcostrttrttcostcost
".$neighbour['neighbour']."".$neighbour['address']."".$neighbour['interface']."".$neighbour['reach']."".$neighbour['rxcost']."".$neighbour['txcost']."".$neighbour['rtt']."".$neighbour['rttcost']."".$neighbour['cost']."
$temp
"; + echo "

Redistributed routes

"; - echo ' - - - - - '; + echo '
prefixfrommetric
+ + + + + '; foreach($output['xroutes'] as $xroute) { - echo "". - "". - ""; + echo ""; + foreach($xroute as $temp) { echo ""; } + echo ""; } echo "
prefixfrommetric
".$xroute['prefix']."".$xroute['from']."".$xroute['metric']."
$temp
"; } ?> - + \ No newline at end of file From 4850c1099422f1e64aefa1212d62b55d8666c7e3 Mon Sep 17 00:00:00 2001 From: Dennis Eisold Date: Sat, 30 Dec 2017 00:14:55 +0100 Subject: [PATCH 4/4] minified html --- index.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/index.php b/index.php index 14f529a..b21551e 100644 --- a/index.php +++ b/index.php @@ -93,10 +93,7 @@ # Ausgabe echo "

Simple Babelweb

"; echo ""; - echo ""; - echo ""; - echo ""; - echo ""; + foreach($output['data'] as $temp) { echo ""; } echo "
".$output['data']['name']."
".$output['data']['version']."
".$output['data']['host']."
".$output['data']['id']."
$temp
"; echo "

Interfaces

";