<?php
include_once 'functions.php';
if($_POST){
addmachine($_POST['newm']);
if(isset($_POST['delm'])){
if(is_array($_POST['delm'])){
foreach($_POST['delm'] as $mid=>$val){
delMachine($mid);
}
}
}
}
$machines=get_machines_from_db();
$js="";
$out="";
?>
<html>
<head>
<script type="text/javascript" src="site.js"></script>
<link rel="stylesheet" href="site.css" type="text/css" />
</head>
<body>
<form method='post' action='./'>
<table class="main" align="center" rules="rows" >
<?php if($is_admin): ?>
<tr>
<td colspan='7'>
<? include 'addmachine.php' ?>
</td>
</tr>
<? endif ?>
<tr>
<td class='thead'>Machine</td>
<td class='thead'>Protocol</td>
<td class='thead'>Port</td>
<td class='thead'>Status</td>
<td class='thead'>Action</td>
<td class='thead'>Connect</td>
<?php if($is_admin): ?>
<td class='thead'>Delete</td>
<?php endif ?>
</tr>
<? foreach($machines as $mid=>$machine): ?>
<tr style="border-bottom:solid thin black">
<td rowspan="<?php echo count($machine['services']); ?>" style="text-align:left;font-weight:bold;font-size:small">
<?php echo "<a href='edit.php?machine=".$machine['id']."'>".$machine['display']."</a>"; ?>
<a href="scp://<?php echo $machine['user']."@".$machine['host'].":".$machine['ssh_port']; ?>"><img src='winscp.jpg' width='30' height='30' /></a>
<br/> <? echo $machine['host']; ?>
</td>
<?php if(isset($machine['services'])): ?>
<?php foreach ($machine['services'] as $name=>$service): ?>
<? $id=$service['id']; ?>
<? $js .= "var xmlhttp".$service['id']."=GetXmlHttpObject()\n"; ?>
<? $js .= "var xmlhttp_a".$service['id']."=GetXmlHttpObject()\n"; ?>
<? $js .= "checkService(".$service['id'].",false)\n"; ?>
<td class='display-proto'><?php echo $service['protocol']; ?></td>
<td class='display'><?php echo $service['port']; ?></td>
<td class='status' id='<?php echo $id."-status";?>'><img src='processing.gif' width='100' height='30'></img></td>
<td class='status' id='<?php echo $id."-action";?>'></td>
<td class='status' style='text-align:left'>
<?php if($service['protocol']=='http'): ?>
<a href="http://<?php echo $machine['host'].":".$service['port'];?>" target="_blank"><img src='text_html.png' width='30' height='30' /></a>
</td>
<?php endif ?>
<?php if($is_admin): ?>
<td style="text-align:center"><input type="checkbox" name="delm[<?php echo $machine['id']; ?>]"/>"
<?php endif ?>
</tr>
<?php endforeach ?>
<?php endif ?>
<?php endforeach ?>
<tr>
<td colspan='5'><input type='submit' value='Update' /></td>
</tr>
</table>
</form>
<script type="text/javascript">
<?php echo $js;?>
</script>
</body>
</html>