<?php
include_once ("../core/config.php");
$UTENTE = login();
$DIRITTI = diritti('Admin');
view_top();
$FW_conf = carica_conf ("Firewall");

if (isset($_POST['utenza'])) {
	$utenza 		= 	$_POST['utenza'];
	list($tipo, $ip) 	= 	explode(" ", $_POST['ip']);

	$query = "	INSERT INTO
				firewall_vpn
			SET
				utenza = '$utenza',
				ip = '$ip',
				tipo = '$tipo',
				data = NOW(),
				attivo = 1
	";
	$res = mysql_query( $query, $DB_ID );
}

$query = "	SELECT
			ip
		FROM
			firewall_vpn
";
$res_ip = mysql_query( $query, $DB_ID );
while( $row = mysql_fetch_assoc( $res_ip) ) { $listaip[] = $row['ip']; }

$tabella = new html (0,"90%",array(3,3,2,15,2,15,2,15,0));
?>
<form name="" method="post">
	<tr>
		<td rowspan=2 colspan=2 class="spazioh"><input type="image" src="<?php print $CONF['base_url'] ?>/img/addresource.png" border="0" alt="Inserisci" /></td>
		<td rowspan=2 class="spaziov"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="descrizione">Utenza</td>
		<td rowspan=2 class="spaziov"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="descrizione">Accesso VPN</td>
		<td rowspan=2 colspan=3 class="spaziov"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
	</tr>
	<tr>
		<td class="colip"><input type="text" size="14" name="utenza"></td>
		<td class="colip">
			<select name="ip">
				<option value="" selected="selected">---</option>
<?php for ($i = ip2long($FW_conf['OVPN_min']); $i <= ip2long($FW_conf['OVPN_max']); $i++ ) { 
	if (in_array(long2ip($i), $listaip) ) continue; ?>
				<option value="OpenVPN <?php print long2ip($i) ?>">OpenVPN <?php print long2ip($i) ?></option>
<?php } 
for ($i = ip2long($FW_conf['PPTP_min']); $i <= ip2long($FW_conf['PPTP_max']); $i++ ) { 
	if (in_array(long2ip($i), $listaip) ) continue; ?>
				<option value="PPTP <?php print long2ip($i) ?>">PPTP <?php print long2ip($i) ?></option>
<?php } ?>
			</select>
		</td>
	</tr>
</form>
<?php
$tabella->riga();
$query = "	SELECT 
			id,
			utenza,
			tipo,
			ip,
			DATE_FORMAT(data, '%d.%m.%Y %H:%i:%s') AS data,
			attivo
		FROM 
			firewall_vpn
		ORDER BY
			utenza
	";

$res = mysql_query( $query, $DB_ID );
while ($dato = mysql_fetch_array ( $res )) {
?>
	<tr>
		<td rowspan=2 class="col3btn">
<?php	if ($dato['attivo']) { ?>
		<a href="firewall_gest.php?azione=vpn_down&id=<?php print $dato['id']?>"><img src="<?php print $CONF['base_url'] ?>/img/attivo.gif" ALT="VPN attiva" TITLE="VPN attiva"></a>
<?php	} else { ?>
		<a href="firewall_gest.php?azione=vpn_up&id=<?php print $dato['id']?>"><img src="<?php print $CONF['base_url'] ?>/img/non_attivo.gif" ALT="VPN non attiva" TITLE="VPN non attiva"></a>
<?php	} ?>
		</td>
		<td rowspan=2 class="spazioh"><a href="firewall_gest.php?azione=vpn_rm&id=<?php print $dato['id']?>"><img src="<?php print $CONF['base_url'] ?>/img/trash.png"></a></td>
		<td rowspan=2 class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td rowspan=2 class="descrizione"><?php print $dato['utenza'] ?></td>
		<td rowspan=2 class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td class="descrizione"><?php print $dato['tipo'] ?></td>
		<td rowspan=2 class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		<td rowspan=2 class="descrizione"><?php print $dato['data'] ?></td>
		<td rowspan=2 class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
		</td>
	</tr>
	<tr>
		<td class="textl"><?php print $dato['ip'] ?></td>
	</tr>
<?php
$tabella->riga();
} 
$tabella->close();
view_footer(); 
?>
