Commit bb55bc37 authored by Ad Schellevis's avatar Ad Schellevis

tracker + captive portal fixes

parent 8a396a64
...@@ -99,7 +99,7 @@ class CPClient { ...@@ -99,7 +99,7 @@ class CPClient {
$ipfw_tables = $this->rules->getAuthUsersTables($zoneid); $ipfw_tables = $this->rules->getAuthUsersTables($zoneid);
if ( sizeof($db_clients) > 0 ){ if ( sizeof($db_clients) > 0 ){
if ($db_clients->ip != null ) { if ($db_clients[0]->ip != null ) {
// only handle disconnect if we can find a client in our database // only handle disconnect if we can find a client in our database
$exec_commands[] = "/sbin/ipfw table " . $ipfw_tables["in"] . " delete " . $db_clients[0]->ip; $exec_commands[] = "/sbin/ipfw table " . $ipfw_tables["in"] . " delete " . $db_clients[0]->ip;
$exec_commands[] = "/sbin/ipfw table " . $ipfw_tables["out"] . " delete " . $db_clients[0]->ip; $exec_commands[] = "/sbin/ipfw table " . $ipfw_tables["out"] . " delete " . $db_clients[0]->ip;
...@@ -153,6 +153,36 @@ class CPClient { ...@@ -153,6 +153,36 @@ class CPClient {
} }
} }
/**
* list (ipfw) accounting information
* @return array (key = hosts ip)
*/
public function list_accounting($ipaddr=null){
$filter_cmd = "";
$result = array();
$shell_output = array();
if ( $ipaddr != null ) $filter_cmd =" | /usr/bin/grep ' " . $ipaddr ." '" ;
if ( $this->shell->exec("/sbin/ipfw -aT list ".$filter_cmd,false,false,$shell_output) == 0 ){
foreach( $shell_output as $line) {
if (strpos($line, ' count ip from') !== false) {
$parts = preg_split('/\s+/', $line);
if (count($parts) > 8 && $parts[7] != 'any' and strlen($parts[7]) > 5) {
$result[$parts[7]] = array(
"last_accessed" => (int)$parts[3],
"idle_time" => time() - (int)$parts[3],
"out_packets" => (int)$parts[1],
"in_packets" => (int)$parts[2]
);
}
}
}
}
return $result;
}
/** /**
* Constructor * Constructor
*/ */
...@@ -383,6 +413,8 @@ class CPClient { ...@@ -383,6 +413,8 @@ class CPClient {
} }
/** /**
* unlock host for captiveportal use
*
* @param string $cpzonename * @param string $cpzonename
* @param string $clientip * @param string $clientip
* @param string $clientmac * @param string $clientmac
...@@ -541,6 +573,46 @@ class CPClient { ...@@ -541,6 +573,46 @@ class CPClient {
} }
} }
/**
* cleanup portal sessions
*/
function portal_cleanup_sessions(){
$acc_list = $this->list_accounting();
foreach($this->config->object()->captiveportal->children() as $cpzonename => $zoneobj){
$db = new DB($cpzonename);
$clients = $db->listClients(array(),null, null);
foreach($clients as $client ){
$idle_time = 0;
if ( array_key_exists ( $client->ip ,$acc_list ) ){
$idle_time = $acc_list[$client->ip];
}
// if session timeout is reached, disconnect
if ( $client->session_timeout != "" ){
if ( ((time() - $client->allow_time)/60) > $client->session_timeout ){
$this->disconnect($cpzonename,$client->sessionid);
continue;
}
}
// disconnect session if idle timeout is reached
if ( $client->idle_timeout != "" && $idle_time > 0 ){
if ( $idle_time > $client->idle_timeout ){
$this->disconnect($cpzonename,$client->sessionid);
continue;
}
}
}
unset($db);
}
unset ($acc_list);
}
} }
...@@ -296,6 +296,7 @@ include("head.inc"); ...@@ -296,6 +296,7 @@ include("head.inc");
$filterlog = conv_log_filter($filter_logfile, $nentries, $nentries + 100, $filterfieldsarray); $filterlog = conv_log_filter($filter_logfile, $nentries, $nentries + 100, $filterfieldsarray);
else else
$filterlog = conv_log_filter($filter_logfile, $nentries, $nentries + 100, $filtertext, $interfacefilter); $filterlog = conv_log_filter($filter_logfile, $nentries, $nentries + 100, $filtertext, $interfacefilter);
?> ?>
<tr> <tr>
<td colspan="<?=$config['syslog']['filterdescriptions']==="1"?7:6?>" class="listtopic"> <td colspan="<?=$config['syslog']['filterdescriptions']==="1"?7:6?>" class="listtopic">
......
...@@ -232,7 +232,6 @@ if (isset($id) && $a_filter[$id]) { ...@@ -232,7 +232,6 @@ if (isset($id) && $a_filter[$id]) {
if (!isset($_GET['dup']) || !is_numericint($_GET['dup'])) if (!isset($_GET['dup']) || !is_numericint($_GET['dup']))
$pconfig['associated-rule-id'] = $a_filter[$id]['associated-rule-id']; $pconfig['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
$pconfig['tracker'] = $a_filter[$id]['tracker'];
} else { } else {
/* defaults */ /* defaults */
...@@ -608,7 +607,6 @@ if ($_POST) { ...@@ -608,7 +607,6 @@ if ($_POST) {
$filterent = array(); $filterent = array();
$filterent['id'] = $_POST['ruleid']>0?$_POST['ruleid']:''; $filterent['id'] = $_POST['ruleid']>0?$_POST['ruleid']:'';
$filterent['tracker'] = empty($_POST['tracker']) ? (int)microtime(true) : $_POST['tracker'];
$filterent['type'] = $_POST['type']; $filterent['type'] = $_POST['type'];
if (isset($_POST['interface'] )) if (isset($_POST['interface'] ))
...@@ -1747,7 +1745,6 @@ include("head.inc"); ...@@ -1747,7 +1745,6 @@ include("head.inc");
<input type="button" class="btn btn-default" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" /> <input type="button" class="btn btn-default" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
<?php if (isset($id) && $a_filter[$id]): ?> <?php if (isset($id) && $a_filter[$id]): ?>
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" /> <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
<input name="tracker" type="hidden" value="<?=htmlspecialchars($pconfig['tracker']);?>">
<?php endif; ?> <?php endif; ?>
<input name="after" type="hidden" value="<?=htmlspecialchars($after);?>" /> <input name="after" type="hidden" value="<?=htmlspecialchars($after);?>" />
</td> </td>
......
...@@ -189,7 +189,7 @@ function format_log_line(row) { ...@@ -189,7 +189,7 @@ function format_log_line(row) {
?> ?>
<tr class="<?=$evenRowClass?>"> <tr class="<?=$evenRowClass?>">
<td class="listMRlr nowrap" align="center"> <td class="listMRlr nowrap" align="center">
<a href="#" onclick="javascript:getURL('diag_logs_filter.php?getrulenum=<?php echo "{$filterent['rulenum']},{$filterent['tracker']},{$filterent['act']}"; ?>', outputrule);"> <a href="#" onclick="javascript:getURL('diag_logs_filter.php?getrulenum=<?php echo "{$filterent['rulenum']},{$filterent['act']}"; ?>', outputrule);">
<img border="0" src="<?php echo find_action_image($filterent['act']);?>" width="11" height="11" alt="<?php echo $filterent['act'];?>" title="<?php echo $filterent['act'];?>" /> <img border="0" src="<?php echo find_action_image($filterent['act']);?>" width="11" height="11" alt="<?php echo $filterent['act'];?>" title="<?php echo $filterent['act'];?>" />
</a> </a>
</td> </td>
......
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