Kicking a user from Captive Portal using PHP



  • I have a piece of code attached to the captive portal index.php file which logs a users IP, MAC and their name / email as entered on the captive portal screen.  I then have a PHP script which displays these logs day by day.  If the log entry is obviously fake, I have a button to click which puts a warning up on the captive portal screen the next time they authenticate, 5 warnings and then their MAC is banned for 3 days.

    All this is done with a little bit of PHP coding and a log file which contains an associative array such as
    $warnings[$clientmac] = "timestamp|warnqty|warnactive";

    When I click the "warn" button, I would also like to forcibly kick the user from the captive portal to force re-authentication.  Before I delve deeply into the code, does anyone know of a PHP function to call to achieve this?  Looking at the querystring of the URL pfsenseIP://status_captiveportal?order=&showact=&act=del&id=5041fe647c9c7 - The ID has no bearing to the MAC I don't believe?  Where is this ID taken from?

    Any info would be great!



  • Ok,

    I have this bit of code which works to turn a MAC into the ID, and assume there wont be issues in using that to get the ID?

    //error_reporting(0);
    
    $ourmac = $_GET["mac"];
    $oursid = "";
    
    require("captiveportal.inc");
    
    if (file_exists("{$g['vardb_path']}/captiveportal.db")) {
    	$captiveportallck = lock('captiveportaldb');
    	$cpcontents = file("/var/db/captiveportal.db", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    	unlock($captiveportallck);	
    }
    
    foreach ($cpcontents as $cpcontent) {
    	$cpent = explode(",", $cpcontent);
    	if($cpent[3] == $ourmac){
    	  $oursid = $cpent[5];
     	  break;
    	}
    }	
    
    echo "The SID is: $oursid";
    exit;
    ?>
    

    And I can then use:

    captiveportal_disconnect_client($oursid);

    to kick a client?


Log in to reply