My project :
I'm trying to do a captive portal to share the Internet connection but the client have to agree the user agreement first. After that he can have the Internet connection if he stays on the portal page.
Issue :
My issue is to check if the client is still on my page to provide to him the connection.
For this, I try to add his MAC address as an exception in my iptables every 10 sec because I flush all MAC exception every 15s (except if the @MAC is more than twice, I let one).
My folder contains :
index.php (the main page where everything is displayed) and mac.php (where I add the exceptions for @MAC)
My mac.php :
<?php
$ipAddress=$_SERVER['REMOTE_ADDR'];
$macAddr=false;
$arp=`arp -a $ipAddress`;
$lines=explode(" ", $arp);
$macAddr=$lines[3];
echo exec("sudo /sbin/iptables -t nat -I PREROUTING -m mac --mac-source $macAddr -j ACCEPT");
echo exec("sudo /sbin/iptables -I FORWARD -m mac --mac-source $macAddr -j ACCEPT");
?>
I already try to this in my index.php :
<script>
setInterval(
(function () {
$("#mac").load("mac.php");
}), 10000);
</script>
<div id="mac"></div>
and this :
<script>
setInterval(
(function () {
$("#mac").load("mac.php #mac");
}), 10000);
</script>
<div id="mac">
<?php
$ipAddress=$_SERVER['REMOTE_ADDR'];
$macAddr=false;
$arp=`arp -a $ipAddress`;
$lines=explode(" ", $arp);
$macAddr=$lines[3];
echo exec("sudo /sbin/iptables -t nat -I PREROUTING -m mac --mac-source $macAddr -j ACCEPT");
echo exec("sudo /sbin/iptables -I FORWARD -m mac --mac-source $macAddr -j ACCEPT");
?>
</div>
And I already tried other alternatives like :
- to put the the 2 last lines of mac.php in mac.php called with an argument ($macAddr) and to call mac.php with an argument
The only way that works from now is to refresh the page every 10s. But as you may know, it is not the best way...
I'm working an a Linux system.
Thanks for your help