Commit 151c5914 authored by Charlie Root's avatar Charlie Root

captive portal remove captiveportal_read_db and replaced with new model

parent e528090c
...@@ -236,15 +236,6 @@ function captiveportal_allowedhostname_configure() { ...@@ -236,15 +236,6 @@ function captiveportal_allowedhostname_configure() {
return $rules; return $rules;
} }
/* read captive portal DB into array */
function captiveportal_read_db($query = "") {
$cpdb = array();
throw Exception("TODO FIX code ");
return $cpdb;
}
// Unchanged // Unchanged
...@@ -952,21 +943,26 @@ function captiveportal_radius_stop_all() { ...@@ -952,21 +943,26 @@ function captiveportal_radius_stop_all() {
$radiusservers = captiveportal_get_radius_servers(); $radiusservers = captiveportal_get_radius_servers();
if (!empty($radiusservers)) { if (!empty($radiusservers)) {
$cpdb = captiveportal_read_db(); $cpdb = new Captiveportal\DB($cpzone);
foreach ($cpdb as $cpentry) {
if (empty($cpentry[11])) $clients = $cpdb->listClients(array());
$cpentry[11] = 'first';
if (!empty($radiusservers[$cpentry[11]])) { foreach ($clients as $cpentry) {
RADIUS_ACCOUNTING_STOP($cpentry[1], // ruleno if (empty($cpentry->radiusctx))
$cpentry[4], // username $cpentry->radiusctx = 'first';
$cpentry[5], // sessionid if (!empty($radiusservers[$cpentry->radiusctx])) {
$cpentry[0], // start time RADIUS_ACCOUNTING_STOP($cpentry->pipeno_in, // ruleno
$radiusservers[$cpentry[11]], $cpentry->username, // username
$cpentry[2], // clientip $cpentry->sessionid, // sessionid
$cpentry[3], // clientmac $cpentry->allow_time, // start time
$radiusservers[$cpentry->radiusctx],
$cpentry->ip, // clientip
$cpentry->mac, // clientmac
7); // Admin Reboot 7); // Admin Reboot
} }
} }
unset($cpdb);
} }
} }
......
...@@ -242,7 +242,6 @@ function voucher_expire($voucher_received) { ...@@ -242,7 +242,6 @@ function voucher_expire($voucher_received) {
// split into an array. Useful for multiple vouchers given // split into an array. Useful for multiple vouchers given
$a_vouchers_received = preg_split("/[\t\n\r ]+/s", $voucher_received); $a_vouchers_received = preg_split("/[\t\n\r ]+/s", $voucher_received);
$active_dirty = false; $active_dirty = false;
$unsetindexes = array();
// go through all received vouchers, check their valid and extract // go through all received vouchers, check their valid and extract
// Roll# and Ticket# using the external readvoucher binary // Roll# and Ticket# using the external readvoucher binary
...@@ -276,12 +275,13 @@ function voucher_expire($voucher_received) { ...@@ -276,12 +275,13 @@ function voucher_expire($voucher_received) {
captiveportal_syslog("{$voucher} ({$roll}/{$nr}) forced to expire"); captiveportal_syslog("{$voucher} ({$roll}/{$nr}) forced to expire");
/* Check if this voucher has any active sessions */ /* Check if this voucher has any active sessions */
$cpentry = captiveportal_read_db("WHERE username = '{$voucher}'"); $cpdb = new Captiveportal\DB($cpzone);
if (!empty($cpentry)) { if ($db->countClients(array("username"=>$voucher)) > 0 ) {
captiveportal_disconnect($cpentry,null,13); captiveportal_disconnect(array("username"=>$voucher),null,13);
captiveportal_logportalauth($cpentry[4],$cpentry[3],$cpentry[2],"FORCLY TERMINATING VOUCHER {$voucher} SESSION"); //TODO: fix logging (in disconnect?) captiveportal_logportalauth($cpentry[4],$cpentry[3],$cpentry[2],"FORCLY TERMINATING VOUCHER {$voucher} SESSION");
$unsetindexes[] = $cpentry[5];
} }
unset($cpdb);
} else } else
captiveportal_syslog("$voucher ($roll/$nr): not found on any registererd Roll"); captiveportal_syslog("$voucher ($roll/$nr): not found on any registererd Roll");
} else } else
...@@ -314,10 +314,6 @@ function voucher_expire($voucher_received) { ...@@ -314,10 +314,6 @@ function voucher_expire($voucher_received) {
unlock($voucherlck); unlock($voucherlck);
/* Write database */
if (!empty($unsetindexes))
captiveportal_remove_entries($unsetindexes);
return true; return true;
} }
......
...@@ -259,10 +259,17 @@ class DB { ...@@ -259,10 +259,17 @@ class DB {
* *
* @return mixed number of connected users/clients * @return mixed number of connected users/clients
*/ */
function countClients(){ function countClients($qryargs=array(),$operator="and"){
$query = "select count(*) cnt from captiveportal "; $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); $resultset->setFetchMode(\Phalcon\Db::FETCH_OBJ);
return $resultset->fetchAll()[0]->cnt; return $resultset->fetchAll()[0]->cnt;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment