mirror of
https://github.com/lucaspalomodevelop/opnsense-core.git
synced 2026-03-13 00:07:27 +00:00
captive portal remove captiveportal_read_db and replaced with new model
This commit is contained in:
parent
e528090c12
commit
151c59149f
@ -236,15 +236,6 @@ function captiveportal_allowedhostname_configure() {
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/* read captive portal DB into array */
|
||||
function captiveportal_read_db($query = "") {
|
||||
$cpdb = array();
|
||||
|
||||
throw Exception("TODO FIX code ");
|
||||
|
||||
return $cpdb;
|
||||
}
|
||||
|
||||
// Unchanged
|
||||
|
||||
|
||||
@ -952,21 +943,26 @@ function captiveportal_radius_stop_all() {
|
||||
|
||||
$radiusservers = captiveportal_get_radius_servers();
|
||||
if (!empty($radiusservers)) {
|
||||
$cpdb = captiveportal_read_db();
|
||||
foreach ($cpdb as $cpentry) {
|
||||
if (empty($cpentry[11]))
|
||||
$cpentry[11] = 'first';
|
||||
if (!empty($radiusservers[$cpentry[11]])) {
|
||||
RADIUS_ACCOUNTING_STOP($cpentry[1], // ruleno
|
||||
$cpentry[4], // username
|
||||
$cpentry[5], // sessionid
|
||||
$cpentry[0], // start time
|
||||
$radiusservers[$cpentry[11]],
|
||||
$cpentry[2], // clientip
|
||||
$cpentry[3], // clientmac
|
||||
$cpdb = new Captiveportal\DB($cpzone);
|
||||
|
||||
$clients = $cpdb->listClients(array());
|
||||
|
||||
foreach ($clients as $cpentry) {
|
||||
if (empty($cpentry->radiusctx))
|
||||
$cpentry->radiusctx = 'first';
|
||||
if (!empty($radiusservers[$cpentry->radiusctx])) {
|
||||
RADIUS_ACCOUNTING_STOP($cpentry->pipeno_in, // ruleno
|
||||
$cpentry->username, // username
|
||||
$cpentry->sessionid, // sessionid
|
||||
$cpentry->allow_time, // start time
|
||||
$radiusservers[$cpentry->radiusctx],
|
||||
$cpentry->ip, // clientip
|
||||
$cpentry->mac, // clientmac
|
||||
7); // Admin Reboot
|
||||
}
|
||||
}
|
||||
|
||||
unset($cpdb);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -242,7 +242,6 @@ function voucher_expire($voucher_received) {
|
||||
// split into an array. Useful for multiple vouchers given
|
||||
$a_vouchers_received = preg_split("/[\t\n\r ]+/s", $voucher_received);
|
||||
$active_dirty = false;
|
||||
$unsetindexes = array();
|
||||
|
||||
// go through all received vouchers, check their valid and extract
|
||||
// Roll# and Ticket# using the external readvoucher binary
|
||||
@ -276,12 +275,13 @@ function voucher_expire($voucher_received) {
|
||||
captiveportal_syslog("{$voucher} ({$roll}/{$nr}) forced to expire");
|
||||
|
||||
/* Check if this voucher has any active sessions */
|
||||
$cpentry = captiveportal_read_db("WHERE username = '{$voucher}'");
|
||||
if (!empty($cpentry)) {
|
||||
captiveportal_disconnect($cpentry,null,13);
|
||||
captiveportal_logportalauth($cpentry[4],$cpentry[3],$cpentry[2],"FORCLY TERMINATING VOUCHER {$voucher} SESSION");
|
||||
$unsetindexes[] = $cpentry[5];
|
||||
$cpdb = new Captiveportal\DB($cpzone);
|
||||
if ($db->countClients(array("username"=>$voucher)) > 0 ) {
|
||||
captiveportal_disconnect(array("username"=>$voucher),null,13);
|
||||
//TODO: fix logging (in disconnect?) captiveportal_logportalauth($cpentry[4],$cpentry[3],$cpentry[2],"FORCLY TERMINATING VOUCHER {$voucher} SESSION");
|
||||
}
|
||||
|
||||
unset($cpdb);
|
||||
} else
|
||||
captiveportal_syslog("$voucher ($roll/$nr): not found on any registererd Roll");
|
||||
} else
|
||||
@ -314,10 +314,6 @@ function voucher_expire($voucher_received) {
|
||||
|
||||
unlock($voucherlck);
|
||||
|
||||
/* Write database */
|
||||
if (!empty($unsetindexes))
|
||||
captiveportal_remove_entries($unsetindexes);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -259,10 +259,17 @@ class DB {
|
||||
*
|
||||
* @return mixed number of connected users/clients
|
||||
*/
|
||||
function countClients(){
|
||||
function countClients($qryargs=array(),$operator="and"){
|
||||
$query = "select count(*) cnt from captiveportal ";
|
||||
$qry_tag = "where " ;
|
||||
foreach ( $qryargs as $fieldname => $fieldvalue ){
|
||||
if ( array_key_exists($fieldname,$this->captiveportal_types) ){
|
||||
$query .= $qry_tag . $fieldname." = "." :".$fieldname." ";
|
||||
$qry_tag = " ".$operator." ";
|
||||
}
|
||||
}
|
||||
|
||||
$resultset = $this->handle->query($query, array(), $this->captiveportal_types);
|
||||
$resultset = $this->handle->query($query, $qryargs, $this->captiveportal_types);
|
||||
$resultset->setFetchMode(\Phalcon\Db::FETCH_OBJ);
|
||||
|
||||
return $resultset->fetchAll()[0]->cnt;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user