<?php
include ($_SERVER["DOCUMENT_ROOT"]."/Site/checkadmin.php");
include ($_SERVER["DOCUMENT_ROOT"]."/Admin/Modules/VPNconfig/config.inc");
include ($_SERVER["DOCUMENT_ROOT"]."/Admin/Modules/VPNconfig/include/functions.inc");
include ($_SERVER["DOCUMENT_ROOT"]."/Admin/Modules/VPNconfig/include/openvpn-functions.inc");
include ($_SERVER["DOCUMENT_ROOT"]."/Admin/Modules/VPNconfig/include/openssl-functions.inc");
openvpn_load_server_conf ();
if (!isset ($openvpn['Server'])) html_error ("The OpenVPN server has no configuration file");
openvpn_load_status ();
if (!isset ($openvpn['Server']['Title'])) html_error ("The OpenVPN server has no status file");
openssl_load_database ();
?>
<table border="0" cellspacing="0" cellpadding="0">
<colgroup>
    <col width="200">
    <col>
</colgroup>
<tr>
    <td valign="top" width="200">
    	<table border="0" cellpadding="10" cellspacing="0">
			<tr>
				<td style="border-top:1px groove black; border-bottom:1px groove black;border-left:1px groove black;border-right:1px groove black;">
					<b>Server Status</b>
				</td>
			</tr>
			<tr>
				<td style="border-right:1px groove black; border-left:1px groove black;">
					The OpenVPN server version is <b><font color="darkgreen"><?php echo $openvpn['Server']['Title'];?></font></b><br>
				</td>
			</tr>
			<tr>
				<td style="border-right:1px groove black; border-left:1px groove black;">
					The last status was recorded at <b><font color="darkgreen"><?php echo $openvpn['Server']['DateTime'];?> </font></b>
				</td>
			</tr>
			<tr>
				<td style="border-right:1px groove black; border-left:1px groove black;" nowrap width="5%">
					<?php echo ''; 
						if ($openvpn['Client'] == 0)	
							echo 'No clients connected</b>'; 
						elseif ($openvpn['Client'] == 1)
							echo 'Connected	<b><font color="darkgreen">1</font></b> client'; 
						elseif ($openvpn['Client'] > 1) 
						{
							echo 'Connected <b><font color="darkgreen">'; 
							echo count($openvpn['Client']); 
							echo '</font></b> clients';
						}?>
				</td>
			</tr>
			<tr>
				<td style="border-right:1px groove black; border-bottom:1px groove black; border-left:1px groove black;">
					OpenSSL has <b><font color="darkgreen">
					<?php 
						if (count($openssl['Database']) == 0)
							echo 'no certificates</font></b>'; 
						elseif (count($openssl['Database']) == 1)
						{
							echo '1</font></b> <a href="'; 
							echo $moduleurl; 
							echo '&uebergabe=3">certificate</a>'; 
						}
						elseif (count($openssl['Database']) > 1)
						{
							echo ''; 
							echo count($openssl['Database']);
							echo '</font></b> <a href="'; 
							echo $moduleurl; 
							echo '&uebergabe=3">certificates</a>'; 
						}?>
					</b>
				</td>
			</tr>
		</table>			
	</td>
	<td valign="top">
		<table border="0" width="90%" cellspacing="0" cellpadding="4" align="center">
			<tr valign="top">
 				<td style="border-bottom:1px groove gray; border-top:1px groove gray" bgcolor="#DDFFCC"><b>#</b></td>
				<td style="border-bottom:1px groove gray; border-top:1px groove gray" nowrap><b>Common Name</td>
			 	<td style="border-bottom:1px groove gray; border-top:1px groove gray" nowrap><b>Connected since</td>
				<td style="border-bottom:1px groove gray; border-top:1px groove gray" nowrap><b>Connected Time</td>
			 	<td style="border-bottom:1px groove gray; border-top:1px groove gray" nowrap><b>Virtual Address</b></td>
			 	<td style="border-bottom:1px groove gray; border-top:1px groove gray" nowrap><b>Real Address</b></td>
			 	<td style="border-bottom:1px groove gray; border-top:1px groove gray" nowrap><b>Upload</b></td>
			 	<td style="border-bottom:1px groove gray; border-top:1px groove gray" nowrap><b>Download</b></td>
			</tr>
			<?php
			$count = 0;
			foreach ($openvpn['Client'] as $client)
			{
				$count++;
				echo '<tr>
						<td>'.$count.'</td>
						<td>'.$client["CN"].'</td>
						<td>'.$client["SINCE"].'</td>
						<td>'.$client["Seconds_Ago"].'</td>
						<td>'.$client["VIRTADDR"].'</td>
						<td>'.$client["REALADDR"].'</td>
						<td>'.$client["BYTESRCV"].'</td>
						<td>'.$client["BYTESSND"].'</td>
					  </tr>';
			}
			?>
		</table>
	</td>
</tr>
</table>
