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 { ...@@ -142,7 +142,7 @@ class CPClient {
$this->shell->exec("/sbin/ipfw -f ".$ruleset_filename); $this->shell->exec("/sbin/ipfw -f ".$ruleset_filename);
// update tables // update tables
$this->update_config(); $this->update();
} }
/** /**
......
...@@ -218,15 +218,15 @@ class DB { ...@@ -218,15 +218,15 @@ class DB {
} }
} }
/** /**
* get captive portal clients * get captive portal clients
* @param Array() $args * @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 // construct query, only parse fields defined by $this->captiveportal_types
$qry_tag = "where " ; $qry_tag = "where " ;
$query = "select * from captiveportal "; $query = "select * from captiveportal ";
$query_order_by = "" ;
foreach ( $qryargs as $fieldname => $fieldvalue ){ foreach ( $qryargs as $fieldname => $fieldvalue ){
if ( array_key_exists($fieldname,$this->captiveportal_types) ){ if ( array_key_exists($fieldname,$this->captiveportal_types) ){
$query .= $qry_tag . $fieldname." = "." :".$fieldname." "; $query .= $qry_tag . $fieldname." = "." :".$fieldname." ";
...@@ -234,12 +234,41 @@ class DB { ...@@ -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 = $this->handle->query($query, $qryargs, $this->captiveportal_types);
$resultset->setFetchMode(\Phalcon\Db::FETCH_OBJ); $resultset->setFetchMode(\Phalcon\Db::FETCH_OBJ);
return $resultset->fetchAll(); 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 * list all fixed ip addresses for this zone
* *
...@@ -279,7 +308,6 @@ class DB { ...@@ -279,7 +308,6 @@ class DB {
$this->handle->execute("delete from captiveportal_ip where ip =:ip ", array("ip"=>$ip),$this->captiveportal_ip_types); $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 * list all passthru mac addresses for this zone
* *
...@@ -299,7 +327,6 @@ class DB { ...@@ -299,7 +327,6 @@ class DB {
return $result; return $result;
} }
/** /**
* insert new passthru mac address * insert new passthru mac address
* @param $mac physical address * @param $mac physical address
......
...@@ -93,7 +93,10 @@ $main_buttons = array( ...@@ -93,7 +93,10 @@ $main_buttons = array(
?> ?>
</td> </td>
<td class="listr" ondblclick="document.location='services_captiveportal.php?zone=<?=$cpzone;?>';"> <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>
<td class="listbg" ondblclick="document.location='services_captiveportal.php?zone=<?=$cpzone;?>';"> <td class="listbg" ondblclick="document.location='services_captiveportal.php?zone=<?=$cpzone;?>';">
<?=htmlspecialchars($cpitem['descr']);?>&nbsp; <?=htmlspecialchars($cpitem['descr']);?>&nbsp;
......
...@@ -80,22 +80,26 @@ function clientcmp($a, $b) { ...@@ -80,22 +80,26 @@ function clientcmp($a, $b) {
} }
if (!empty($cpzone)) { if (!empty($cpzone)) {
$cpdb = captiveportal_read_db(); $cpdb_handle = new Captiveportal\DB("test");//$cpzone);
if ($_GET['order']) { if ($_GET['order']) {
if ($_GET['order'] == "ip") if ($_GET['order'] == "ip")
$order = 2; $order = "ip";
else if ($_GET['order'] == "mac") else if ($_GET['order'] == "mac")
$order = 3; $order = "mac";
else if ($_GET['order'] == "user") else if ($_GET['order'] == "user")
$order = 4; $order = "username";
else if ($_GET['order'] == "lastact") else if ($_GET['order'] == "lastact")
$order = 5; $order = "";
else
$order = 0;
usort($cpdb, "clientcmp");
} }
$cpdb = $cpdb_handle->listClients(array(),"and",array($order) ) ;
}
else {
$cpdb = array() ;
} }
// Load MAC-Manufacturer table // Load MAC-Manufacturer table
$mac_man = load_mac_manufacturer_table(); $mac_man = load_mac_manufacturer_table();
...@@ -157,12 +161,12 @@ $mac_man = load_mac_manufacturer_table(); ...@@ -157,12 +161,12 @@ $mac_man = load_mac_manufacturer_table();
</form> </form>
<?php } else echo $a_cp[$cpzone]['zone']; ?> <?php } else echo $a_cp[$cpzone]['zone']; ?>
</td> </td>
<td colspan="3" width="50%"></td> <td colspan="6" width="50%"></td>
</tr> </tr>
<tr><td colspan="5"><br /></td></tr> <tr><td colspan="6"><br /></td></tr>
<?php if (!empty($cpzone)): ?> <?php if (!empty($cpzone)): ?>
<tr> <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>
<tr> <tr>
<td class="listhdrr"><a href="?zone=<?=$cpzone?>&amp;order=ip&amp;showact=<?=htmlspecialchars($_GET['showact']);?>"><?=gettext("IP address");?></a></td> <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(); ...@@ -178,10 +182,10 @@ $mac_man = load_mac_manufacturer_table();
</tr> </tr>
<?php foreach ($cpdb as $cpent): ?> <?php foreach ($cpdb as $cpent): ?>
<tr> <tr>
<td class="listlr"><?=$cpent[2];?></td> <td class="listlr"><?=$cpent->ip;?></td>
<td class="listr"> <td class="listr">
<?php <?php
$mac=trim($cpent[3]); $mac=trim($cpent->mac);
if (!empty($mac)) { if (!empty($mac)) {
$mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]); $mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
print htmlentities($mac); print htmlentities($mac);
...@@ -189,16 +193,18 @@ $mac_man = load_mac_manufacturer_table(); ...@@ -189,16 +193,18 @@ $mac_man = load_mac_manufacturer_table();
} }
?>&nbsp; ?>&nbsp;
</td> </td>
<td class="listr"><?=htmlspecialchars($cpent[4]);?>&nbsp;</td> <td class="listr"><?=htmlspecialchars($cpent->username);?>&nbsp;</td>
<td class="listr"><?=htmlspecialchars(date("m/d/Y H:i:s", $cpent[0]));?></td> <td class="listr"><?=htmlspecialchars(date("m/d/Y H:i:s", $cpent->allow_time));?></td>
<?php if ($_GET['showact']): <?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> <td class="listr"><?php if ($last_act != 0) echo htmlspecialchars(date("m/d/Y H:i:s", $last_act));?></td>
<?php else: ?> <?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; ?> <?php endif; ?>
<td valign="middle" class="list nowrap"> <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> </td>
</tr> </tr>
<?php endforeach; endif; ?> <?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