Skip to content

Commit

Permalink
Show the outport redirection in getvminfo
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Jan 21, 2016
1 parent 250c5ec commit cbbee08
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 8 deletions.
2 changes: 1 addition & 1 deletion create_tar.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

VERSION=1.4.0
VERSION=1.4.2

if [ ! -d dist ]
then
Expand Down
63 changes: 58 additions & 5 deletions format.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,59 @@ function createDownloadLink(anchorSelector, str, fileName){
return $res;
}

function getOutPorts($radl) {
$pos = 0;
$res = array();
while ($pos !== false) {
$ini = strpos($radl, "network", $pos);
$ini = strpos($radl, "(", $ini)+1;
$fin = strpos($radl, ")", $ini+1);

$parts = explode(" and", substr($radl, $ini, $fin-$ini));

$i = 0;
$public = false;
$ports = "";
foreach ($parts as $comp)
{
$tok = explode(" = ", $comp);
$key = trim($tok[0]);
$value = "";

if (count($tok) > 1) {
$value = str_replace("'","",trim($tok[1]));
}

if ($key == 'outbound')
$public = true;
else if ($key == 'outports')
$ports = $value;
}

if ($public and strlen($ports) > 0) {
$port_parts = explode(",", $ports);
foreach ($port_parts as $port_pair) {
$port_pair_parts = explode("-", $port_pair);
if (count($port_pair_parts)>1 and $port_pair_parts[0] != $port_pair_parts[1]) {
$res[$port_pair_parts[0]] = $port_pair_parts[1];
}
}
}

$pos = strpos($radl, "network", $pos+1);
}

return $res;
}

function formatOutPorts($outports){
$res = "";
foreach ($outports as $src => $dest) {
$res = $res . $src . " => " . $dest . "<br>\n";
}
return $res;
}

function parseRADL($radl) {
// TODO: esto habria que hacerlo mejor
$ini = strpos($radl, "system");
Expand Down Expand Up @@ -153,11 +206,11 @@ function parseRADL($radl) {
$res[trim($tok[0])] = trim($tok[1]);
} else {
$tok = explode(" = ", $comp);
if (count($tok) > 1) {
$res[trim($tok[0])] = str_replace("'","",trim($tok[1]));
} else {
$res[trim($tok[0])] = "";
}
if (count($tok) > 1) {
$res[trim($tok[0])] = str_replace("'","",trim($tok[1]));
} else {
$res[trim($tok[0])] = "";
}
}

$i++;
Expand Down
20 changes: 18 additions & 2 deletions getvminfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
header('Location: error.php?msg=' + urlencode($res));
} else {
$radl_tokens = parseRADL($res);
$outports = getOutPorts($res);
?>
<!DOCTYPE HTML>
<html>
Expand Down Expand Up @@ -103,20 +104,35 @@ function confirm_delete(url, id) {
<tr>
<td style="width:10px;background:#777;"><img src="images/icon_state.png"></td>
<th style="width:90px; background:#777;padding-left:0px;">State</th>
<td style="text-align:left; padding-left:20px; font-weight:bold;background:#CCC;"><?php echo formatState($radl_tokens['state']);?></td>
<td colspan="3" style="text-align:left; padding-left:20px; font-weight:bold;background:#CCC;"><?php echo formatState($radl_tokens['state']);?></td>
</tr>
<tr>
<td style="width:10px;background:#777;"><img src="images/icon_deploy.png"></td>
<th style="width:90px; background:#777;padding-left:0px;">Deployment</th>
<td style="text-align:left; padding-left:20px;font-weight:bold;background:#CCC;"><?php echo formatCloud($radl_tokens);?>
<td colspan="3" style="text-align:left; padding-left:20px;font-weight:bold;background:#CCC;"><?php echo formatCloud($radl_tokens);?>
</td>
</tr>

<tr>
<td style="width:10px;background:#777;"><img src="images/icon_ip.png"></td>
<th style="width:90px; background:#777;padding-left:0px;">IPs</th>
<?php
if (count($outports) > 0) {
?>
<td style="text-align:left; padding-left:20px;font-weight:bold;background:#CCC;"><?php echo formatIPs($radl_tokens);?></td>
<th style="width:90px; background:#777;padding-left:0px;">Ports</th>
<td style="text-align:left; padding-left:20px;font-weight:bold;background:#CCC;"><?php echo formatOutPorts($outports);?></td>
<?php
} else {
?>
<td colspan="3" style="text-align:left; padding-left:20px;font-weight:bold;background:#CCC;"><?php echo formatIPs($radl_tokens);?></td>
<?php
}
?>
</tr>



</tbody>
</table>

Expand Down

0 comments on commit cbbee08

Please sign in to comment.