<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Server status</title>
<style>
td.rood			{ border: 0px solid #000000; background: #FF2501; color: #000000; font-family: "verdana"; font-size: 11pt;  text-align: center; height: 25px;}
td.groen			{ border: 0px solid #000000; background: #07FD1E; color: #000000; font-family: "verdana"; font-size: 11pt;  text-align: center; height: 25px;}
body			{ background: #D6D3D2; color: #D6D3D2; font-family: "verdana"; font-size: 10pt; cursor: default;  text-align: center; z-index: -1;}
p				{ color: #000000; font-family: "verdana"; font-size: 10pt; cursor: default; }
a:link,visited,acive		{ color: #000000; font-family: "verdana"; font-size: 11pt; text-decoration: none; }
a:hover			{ color: #000000; font-family: "verdana"; font-size: 11pt; text-decoration: underline;}
table			{ color: #0312D5; font-family: "verdana"; font-size: 11pt; border: 1px solid #000000;}
tr.tit		{ background: #FFD50F; color: #000000; font-family: "verdana"; font-size: 10pt; border: 1px solid #000000;  text-align: center;}
input.text 		{ background: #FFD50Fl color: #00000; font-family: "verdana"; }


</style>
<META HTTP-EQUIV="Refresh" CONTENT="900;URL=server.php">
</head>
<body>
<?PHP
set_time_limit(120);
$cfg['server'] 		= 'server.txt';
$cfg['eigenserv'] 	= 'servers.txt';
$cfg['switch']		= 'switch.txt';
$cfg['switchrest']	= 'switchrest.txt';
function add($addr,$naam,$bestand) { // server toevoegen
//==========================
$fp = fopen($bestand,'a+'); // open
$get = fgets($fp,filesize($bestand)+1024); // data halen
//========================== variables
$var = (filesize($bestand) < 5) ? '' : '|';
$post = $var.$addr.','.$naam;
// ================ schrijven
if(is_writable($bestand)) { // kan hij schrijven?
if(fwrite($fp,$post)) { // scrhijven
return true;
} else { return false; } // fout als hij niet schrijft
} else { return false; } // fout als hij niet kan schrijven
fclose($fp);
clearstatcache();
}
// status functie
function status($ip) {
ob_start();
$last_line = system('ping '.$ip.' -n 1');
$out = ob_get_contents();
ob_end_clean();
if(preg_match_all('{Packets:(.+?),(.+?),(.+?),(.+?)}',$out,$all)) {
$ex = explode("=",$all[2][0]);
$ex1 = explode("=",$all[3][0]);
	if($ex[1] == '1') {
		return true;
	} else {
		return false;
	}
}
}
//---------
function open($bes) {
$op = file_get_contents($bes);
$explode = explode("|",$op);
foreach($explode as $name) {
$expl = explode(",",$name);
if(status($expl[0])) { $rg = 'groen'; } else { $rg = 'rood'; }
$var[$expl[0]] = $rg.','.$expl[1];
}
return $var;
}
if($_GET['x'] == 'add') {
echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'?x=add">';
echo '<table width=300><tr><td><b>Server toevoegen</b></td></tr></table>';
if(isset($_POST['submit'])) {
if(!empty($_POST['ip'])) {
$explode = explode(".",$_POST['ip']);
if(count($explode) == 4) {
$naam = (!empty($_POST['naam'])) ? $_POST['naam'] : $_POST['ip'];
if($_POST['type'] == 0) {
$bes = $cfg['eigenserv'];
} elseif($_POST['type'] == 1) {
$bes = $cfg['server'];
} elseif($_POST['type'] == 2) {
$bes = $cfg['switch'];
} else {
$bes = $cfg['switchrest'];
}
if(add($_POST['ip'],$naam,$bes)) {
echo "<table width='300'><tr><td>".$_POST['ip']." is toegevoegt</td></tr></table>";
}
} else 
echo "<table width='300'><tr><td>U hebt geen geldig ip adres ingevult</td></tr></table>";
} else 
echo "<table width='300'><tr><td>U hebt geen ip ingevult</td></tr></table>";
}
echo '<table width=300><tr><td>Ip:</td><td><input type="text" name="ip" value="'.$_REQUEST['ip'].'"></td></tr><tr><td>Naam:</td><td><input type="text" name="naam"></td></tr>';
echo "<tr><td>Type:</td><td><select name='type'><option name='0'>Eigen servers</option><option name='1'>Server</option><option name='2'>Switch zwolle</option><option name='3'>Switch rest</option></select></td></tr>";
echo '<tr><td></td><td><input type="submit" name="submit" value="Toevoegen"></td></tr>';
echo "<tr><td></td><td style='text-align: right;'><a style='font-size: 9px;' href='javascript:window.close()'>Close</a></td></tr>";
echo '</table>';
} else {
//--------------------------------
echo "<table width='100%' style='font-size: 20pt; text-align: center; 
'><tr><td><strong>Servers</strong></td></tr></table>";
echo "<table width='100%' cellspacing=1 cellpadding=0><tr class='tit'><td>Servers</td></tr></table>";
echo "<table width='100%'><tr>";
$open = open($cfg['server']);
$i=0;
foreach($open as $line => $ip) {
$expl = explode(",",$ip);
echo "<td class=".$expl[0]." width='20%'><a target='_new' href='http://".$line."'>".$expl[1]."</a></td>";
$i++;
	if($i == 5) {
echo "</tr><tr>";
$i=0;
	}
}
echo "</tr></table>";

echo "<table width='100%' cellspacing=1 cellpadding=0><tr class='tit'><td>Switch zwolle</td></tr></table>";
echo "<table width='100%'><tr>";
$open = open($cfg['switch']);
$i=0;
foreach($open as $line => $ip) {
$expl = explode(",",$ip);
echo "<td class=".$expl[0]." width='25%'><a target='_new' href='http://".$line."'>".$expl[1]."</a></td>";
$i++;
	if($i == 4) {
echo "</tr><tr>";
$i=0;
	}
}
echo "</tr></table>";
//-------------------- rest
echo "<table width='100%' cellspacing=1 cellpadding=0><tr class='tit'><td>Switch  rest</td></tr></table>";
echo "<table width='100%'><tr>";
$open = open($cfg['switchrest']);
$i=0;
foreach($open as $line => $ip) {
$expl = explode(",",$ip);
echo "<td class=".$expl[0]." width='20%'><a target='_new' href='http://".$line."'>".$expl[1]."</a></td>";
$i++;
	if($i == 5) {
echo "</tr><tr>";
$i=0;
	}
}
echo "</tr></table>";
//============  servers
$open = open($cfg['eigenserv']);
if(count($open)  > 1) {
echo "<table width='100%'><tr><td><b>Eigen toegevoegde servers</b></td></tr></table>";
echo "<table width='100%'><tr>";
$i=0;
foreach($open as $line => $ip) {
$expl = explode(",",$ip);
echo "<td class=".$expl[0]." width='25%'><a target='_new' href='http://".$line."'>".$expl[1]."</a></td>";
$i++;
	if($i == 4) {
echo "</tr><tr>";
$i=0;
	}
}
echo "</tr>";
}
//--------------------------------
echo "<tr><td></td><td></td><td></td><td align='right'><a href='#' onclick=\"javascript:window.open('server.php?x=add','Ip toevoegen','width=320,height=160,scrollbars=no,toolbar=no,location=no')\">Ip toevoegen</a></td></tr></table>";
}
?> 