Friends, how are you? Again making a query through your forum. I'm trying to make a simple captive portal with iptables and PHP however I can not make it work. I explained, I currently have a server in bridge mode, and in this redirect the traffic that goes to port 80 to port 8081 of another server, who shows a page and gives the option to continue for the client to follow his navigation. This last one does not work for me. By redirecting receipt in an index.html that is as follows:
<?php
//VARIABLES CONEXION BD
$host = "dbserver";
$user = "usuariodb";
$pwd = "passworddb";
$db="basededatos";
$ipserv= "127.0.0.1:8081";
$dom = $_SERVER['HTTP_HOST'];
$rest = $_SERVER['REQUEST_URI'];
$url_completa = "http://" . $dom . $rest;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$ip_address = $_SERVER['REMOTE_ADDR'];
//CONEXION A BASE DE DATOS
$link = mysql_connect( $host, $user, $pwd ) or die( "Error al conectar" . mysql_error() );
mysql_select_db($db) or die ("La base de datos no existe");
//Consulta Base de datos para obtener MAC en base a la IP
$sql = "select mac from clie left join clientes ON cr_clid = id where iprouter = '".$ip_address."'";
echo "consulta $sql \n";
//GUARDANDO VARIABLES Y RESULTADOS CONSULTA
$mac=mysql_query($sql);
$var1 = "sudo iptables -t nat -D PREROUTING -m mac --mac-source ".$mac." -p tcp -j DNAT --to-destination ".$ipserv."";
shell_exec($var1);
header("Location: '".$url_completa."'");
} else {
?>
<html>
<body style="padding: 0em 1em;">
<h1 style="overflow: hidden;"><img style="float:right;">¡Aviso de Corte! </h1>
<p>Si estas viendo esto, es debido a que tu cuenta esta proxima a vencer, evita la suspension de tu servicio cancelando anticipadamente, asi evitaras perder acceso a tu informacion y cobros por corte y reposicion. </p>
<form method="POST">
<p>Gracias por preferirnos para continuar con su navegacion normalmente por favor pulse en el boton
<input type="submit" value="Continuar" /></p>
</form>
</body>
</html>";
<?php
}
?>
Pressing continue does not take any action, and should at least redirect to the domain you were trying to navigate. Can someone give me a hand?