#!/usr/local/bin/php -f
<?php

/*
 * cp_disconnect [sessionid=sessionid] [ip=ip]
 *
 */

$ip = $sessionid = null;

array_shift($argv);
foreach ($argv as $arg) {
	list($name, $value) = explode('=', $arg, 2);
	switch($name) {
		case 'ip':
			$ip=$value;
			break;
		case 'sessionid':
			$sessionid=$value;
			break;
		default:
			exit(1); // bad option
	}
}

if ( $ip != null ) {
	// search sessionid from ip
	require_once("captiveportal.inc");
	$cpdb = captiveportal_read_db();
	foreach ($cpdb as $cpentry) {
		if ($cpentry[2] == $ip) {
			$sessionid = $cpentry[5];
			break;
		}
	}
}

if ( $sessionid == null ) {
	// no sessionid (already disconnected ?)
	exit(2);
}

require_once("captiveportal.inc");
captiveportal_disconnect_client($sessionid);

?>
