Commit efb08f92 authored by Charlie Root's avatar Charlie Root

Captive portal merge code into old code...

parent 72dbc473
This diff is collapsed.
......@@ -142,7 +142,7 @@ class CPClient {
$this->shell->exec("/sbin/ipfw -f ".$ruleset_filename);
// update tables
$this->update_config();
$this->update();
}
/**
......
......@@ -218,15 +218,15 @@ class DB {
}
}
/**
* get captive portal clients
* @param Array() $args
*/
function listClients($qryargs,$operator="and"){
function listClients($qryargs,$operator="and",$order_by=null){
// construct query, only parse fields defined by $this->captiveportal_types
$qry_tag = "where " ;
$query = "select * from captiveportal ";
$query_order_by = "" ;
foreach ( $qryargs as $fieldname => $fieldvalue ){
if ( array_key_exists($fieldname,$this->captiveportal_types) ){
$query .= $qry_tag . $fieldname." = "." :".$fieldname." ";
......@@ -234,12 +234,41 @@ class DB {
}
}
// apply ordering to result, validate fields
if (is_array($order_by)){
foreach ( $order_by as $fieldname ){
if ( is_array($order_by) && in_array($fieldname,$order_by) ) {
if ($query_order_by != "") {
$query_order_by .= " , ";
}
$query_order_by .= $fieldname;
}
}
}
if ( $query_order_by != "" ) $query .= " order by " . $query_order_by;
$resultset = $this->handle->query($query, $qryargs, $this->captiveportal_types);
$resultset->setFetchMode(\Phalcon\Db::FETCH_OBJ);
return $resultset->fetchAll();
}
/**
*
* @return mixed number of connected users/clients
*/
function countClients(){
$query = "select count(*) cnt from captiveportal ";
$resultset = $this->handle->query($query, array(), $this->captiveportal_types);
$resultset->setFetchMode(\Phalcon\Db::FETCH_OBJ);
return $resultset->fetchAll()[0]->cnt;
}
/**
* list all fixed ip addresses for this zone
*
......@@ -279,7 +308,6 @@ class DB {
$this->handle->execute("delete from captiveportal_ip where ip =:ip ", array("ip"=>$ip),$this->captiveportal_ip_types);
}
/**
* list all passthru mac addresses for this zone
*
......@@ -299,7 +327,6 @@ class DB {
return $result;
}
/**
* insert new passthru mac address
* @param $mac physical address
......
......@@ -93,7 +93,10 @@ $main_buttons = array(
?>
</td>
<td class="listr" ondblclick="document.location='services_captiveportal.php?zone=<?=$cpzone;?>';">
<?=count(captiveportal_read_db());?>
<?php
$cpdb = new Captiveportal\DB($cpzone) ;
echo $cpdb->countClients() ;
?>
</td>
<td class="listbg" ondblclick="document.location='services_captiveportal.php?zone=<?=$cpzone;?>';">
<?=htmlspecialchars($cpitem['descr']);?>&nbsp;
......
......@@ -80,22 +80,26 @@ function clientcmp($a, $b) {
}
if (!empty($cpzone)) {
$cpdb = captiveportal_read_db();
$cpdb_handle = new Captiveportal\DB("test");//$cpzone);
if ($_GET['order']) {
if ($_GET['order'] == "ip")
$order = 2;
$order = "ip";
else if ($_GET['order'] == "mac")
$order = 3;
$order = "mac";
else if ($_GET['order'] == "user")
$order = 4;
$order = "username";
else if ($_GET['order'] == "lastact")
$order = 5;
else
$order = 0;
usort($cpdb, "clientcmp");
$order = "";
}
$cpdb = $cpdb_handle->listClients(array(),"and",array($order) ) ;
}
else {
$cpdb = array() ;
}
// Load MAC-Manufacturer table
$mac_man = load_mac_manufacturer_table();
......@@ -157,12 +161,12 @@ $mac_man = load_mac_manufacturer_table();
</form>
<?php } else echo $a_cp[$cpzone]['zone']; ?>
</td>
<td colspan="3" width="50%"></td>
<td colspan="6" width="50%"></td>
</tr>
<tr><td colspan="5"><br /></td></tr>
<tr><td colspan="6"><br /></td></tr>
<?php if (!empty($cpzone)): ?>
<tr>
<td colspan="5" valign="top" class="listtopic"><?=gettext("Captiveportal status");?></td>
<td colspan="7" valign="top" class="listtopic"><?=gettext("Captiveportal status");?></td>
</tr>
<tr>
<td class="listhdrr"><a href="?zone=<?=$cpzone?>&amp;order=ip&amp;showact=<?=htmlspecialchars($_GET['showact']);?>"><?=gettext("IP address");?></a></td>
......@@ -178,10 +182,10 @@ $mac_man = load_mac_manufacturer_table();
</tr>
<?php foreach ($cpdb as $cpent): ?>
<tr>
<td class="listlr"><?=$cpent[2];?></td>
<td class="listlr"><?=$cpent->ip;?></td>
<td class="listr">
<?php
$mac=trim($cpent[3]);
$mac=trim($cpent->mac);
if (!empty($mac)) {
$mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
print htmlentities($mac);
......@@ -189,16 +193,18 @@ $mac_man = load_mac_manufacturer_table();
}
?>&nbsp;
</td>
<td class="listr"><?=htmlspecialchars($cpent[4]);?>&nbsp;</td>
<td class="listr"><?=htmlspecialchars(date("m/d/Y H:i:s", $cpent[0]));?></td>
<td class="listr"><?=htmlspecialchars($cpent->username);?>&nbsp;</td>
<td class="listr"><?=htmlspecialchars(date("m/d/Y H:i:s", $cpent->allow_time));?></td>
<?php if ($_GET['showact']):
$last_act = captiveportal_get_last_activity($cpent[2], $cpent[3]); ?>
//$last_act = captiveportal_get_last_activity($cpent->ip, $cpent->mac);
$last_act=0;
?>
<td class="listr"><?php if ($last_act != 0) echo htmlspecialchars(date("m/d/Y H:i:s", $last_act));?></td>
<?php else: ?>
<td class="listr" colspan="2"><?=htmlspecialchars(date("m/d/Y H:i:s", $cpent[0]));?></td>
<td class="listr" colspan="2"></td>
<?php endif; ?>
<td valign="middle" class="list nowrap">
<a href="?zone=<?=$cpzone;?>&amp;order=<?=$_GET['order'];?>&amp;showact=<?=htmlspecialchars($_GET['showact']);?>&amp;act=del&amp;id=<?=$cpent[5];?>" onclick="return confirm('<?=gettext("Do you really want to disconnect this client?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" title="<?=gettext("Disconnect");?>"></a>
<a href="?zone=<?=$cpzone;?>&amp;order=<?=$_GET['order'];?>&amp;showact=<?=htmlspecialchars($_GET['showact']);?>&amp;act=del&amp;id=<?=$cpent->username;?>" onclick="return confirm('<?=gettext("Do you really want to disconnect this client?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" title="<?=gettext("Disconnect");?>"></a>
</td>
</tr>
<?php endforeach; endif; ?>
......
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