Commit f4f6b83b authored by Ad Schellevis's avatar Ad Schellevis

captive portal fixes

parent 5cfb7ab3
...@@ -104,8 +104,9 @@ function portal_allow($clientip,$clientmac,$username,$password = null, $attribut ...@@ -104,8 +104,9 @@ function portal_allow($clientip,$clientmac,$username,$password = null, $attribut
global $cpzone ,$type,$g; global $cpzone ,$type,$g;
// Ensure we create an array if we are missing attributes // Ensure we create an array if we are missing attributes
if (!is_array($attributes)) if (!is_array($attributes)) {
$attributes = array(); $attributes = array();
}
// handle // handle
$dwfaultbw_up = isset($config['captiveportal'][$cpzone]['bwdefaultup']) ? $config['captiveportal'][$cpzone]['bwdefaultup'] : 0; $dwfaultbw_up = isset($config['captiveportal'][$cpzone]['bwdefaultup']) ? $config['captiveportal'][$cpzone]['bwdefaultup'] : 0;
......
...@@ -58,7 +58,7 @@ class CPClient { ...@@ -58,7 +58,7 @@ class CPClient {
/** /**
* link to shell object * link to shell object
* @var \Core\Shell * @var Core\Shell
*/ */
private $shell = null; private $shell = null;
...@@ -71,10 +71,10 @@ class CPClient { ...@@ -71,10 +71,10 @@ class CPClient {
* @param $ip * @param $ip
* @param string $message * @param string $message
*/ */
private function logportalauth($user,$mac,$ip,$status,$message=""){ private function logportalauth($cpzonename, $user, $mac, $ip, $status, $message=""){
$message = trim($message); $message = trim($message);
$message = "{$status}: {$user}, {$mac}, {$ip}, {$message}"; $message = "Zone : {$cpzonename} {$status}: {$user}, {$mac}, {$ip}, {$message}";
$logger = new \Phalcon\Logger\Adapter\Syslog("logportalauth", array( $logger = new \Phalcon\Logger\Adapter\Syslog("logportalauth", array(
'option' => LOG_PID, 'option' => LOG_PID,
...@@ -83,6 +83,7 @@ class CPClient { ...@@ -83,6 +83,7 @@ class CPClient {
$logger->info($message); $logger->info($message);
} }
/** /**
* Request new pipeno * Request new pipeno
* @return int * @return int
...@@ -134,13 +135,30 @@ class CPClient { ...@@ -134,13 +135,30 @@ class CPClient {
} }
} }
/**
* load accounting rules into ruleset, used for reinitialisation of the ruleset.
* triggers add_accounting() for all active clients in all zones
*/
private function loadAccounting()
{
foreach ($this->config->object()->captiveportal->children() as $cpzonename => $zone)
{
$db = new DB($cpzonename);
foreach ($db->listClients(array()) as $client)
{
$this->add_accounting($zone->zoneid, $client->ip) ;
}
unset($db);
}
}
/** /**
* *
* @param $zoneid * @param $zoneid
* @param $ip * @param $ip
*/ */
public function add_accounting($zoneid,$ip){ public function add_accounting($zoneid,$ip){
// TODO: check speed, this might need some improvement // TODO: check processing speed, this might need some improvement
// check if our ip is already in the list and collect first free rule number to place it there if necessary // check if our ip is already in the list and collect first free rule number to place it there if necessary
$shell_output=array(); $shell_output=array();
$this->shell->exec("/sbin/ipfw show",false,false,$shell_output); $this->shell->exec("/sbin/ipfw show",false,false,$shell_output);
...@@ -227,7 +245,7 @@ class CPClient { ...@@ -227,7 +245,7 @@ class CPClient {
*/ */
function __construct() { function __construct() {
// Request handle to configuration // Request handle to configuration
$this->config = \Core\Config::getInstance(); $this->config = Core\Config::getInstance();
// generate new ruleset // generate new ruleset
$this->rules = new Rules(); $this->rules = new Rules();
// keep a link to the shell object // keep a link to the shell object
...@@ -246,6 +264,9 @@ class CPClient { ...@@ -246,6 +264,9 @@ class CPClient {
// update tables // update tables
$this->update(); $this->update();
// after reinit all accounting rules are vanished, reapply them for active sessions
$this->loadAccounting();
} }
/** /**
...@@ -552,7 +573,7 @@ class CPClient { ...@@ -552,7 +573,7 @@ class CPClient {
$this->reset_bandwidth($pipeno_in,$bw_down); $this->reset_bandwidth($pipeno_in,$bw_down);
// log // log
$this->logportalauth($username,$clientmac,$clientip,$status="LOGIN"); $this->logportalauth($cpzonename, $username, $clientmac, $clientip, $status="LOGIN");
// cleanup // cleanup
unset($db); unset($db);
...@@ -576,7 +597,6 @@ class CPClient { ...@@ -576,7 +597,6 @@ class CPClient {
} }
} }
/** /**
* flush zone (null flushes all zones) * flush zone (null flushes all zones)
* @param null $zone * @param null $zone
...@@ -633,7 +653,7 @@ class CPClient { ...@@ -633,7 +653,7 @@ class CPClient {
if (is_numeric($client->session_timeout) && $client->session_timeout > 0 ) { if (is_numeric($client->session_timeout) && $client->session_timeout > 0 ) {
if (((time() - $client->allow_time) / 60) > $client->session_timeout) { if (((time() - $client->allow_time) / 60) > $client->session_timeout) {
$this->disconnect($cpzonename, $client->sessionid); $this->disconnect($cpzonename, $client->sessionid);
$this->logportalauth($client->username,$client->mac,$client->ip,$status="SESSION TIMEOUT"); $this->logportalauth($cpzonename, $client->username, $client->mac, $client->ip, $status="SESSION TIMEOUT");
continue; continue;
} }
} }
...@@ -642,7 +662,7 @@ class CPClient { ...@@ -642,7 +662,7 @@ class CPClient {
if (is_numeric($client->idle_timeout) && $client->idle_timeout > 0 && $idle_time > 0) { if (is_numeric($client->idle_timeout) && $client->idle_timeout > 0 && $idle_time > 0) {
if ($idle_time > $client->idle_timeout) { if ($idle_time > $client->idle_timeout) {
$this->disconnect($cpzonename, $client->sessionid); $this->disconnect($cpzonename, $client->sessionid);
$this->logportalauth($client->username,$client->mac,$client->ip,$status="IDLE TIMEOUT"); $this->logportalauth($cpzonename, $client->username, $client->mac, $client->ip, $status="IDLE TIMEOUT");
continue; continue;
} }
} }
...@@ -650,7 +670,7 @@ class CPClient { ...@@ -650,7 +670,7 @@ class CPClient {
// disconnect on session terminate time // disconnect on session terminate time
if ( is_numeric($client->session_terminate_time) && $client->session_terminate_time > 0 && $client->session_terminate_time < time()) { if ( is_numeric($client->session_terminate_time) && $client->session_terminate_time > 0 && $client->session_terminate_time < time()) {
$this->disconnect($cpzonename, $client->sessionid); $this->disconnect($cpzonename, $client->sessionid);
$this->logportalauth($client->username,$client->mac,$client->ip,$status="TERMINATE TIME REACHED"); $this->logportalauth($cpzonename, $client->username, $client->mac, $client->ip, $status="TERMINATE TIME REACHED");
continue; continue;
} }
} }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
namespace OPNsense\CaptivePortal; namespace OPNsense\CaptivePortal;
use OPNsense\Core;
/** /**
* Class Rules * Class Rules
...@@ -59,7 +60,7 @@ class Rules { ...@@ -59,7 +60,7 @@ class Rules {
function __construct() function __construct()
{ {
// Request handle to configuration // Request handle to configuration
$this->config = \Core\Config::getInstance(); $this->config = Core\Config::getInstance();
} }
...@@ -130,6 +131,8 @@ class Rules { ...@@ -130,6 +131,8 @@ class Rules {
$this->rules[] = "#========================================================================================================="; $this->rules[] = "#=========================================================================================================";
foreach( $this->config->object()->interfaces->children() as $interface => $content ){ foreach( $this->config->object()->interfaces->children() as $interface => $content ){
if ( $interface != "wan" && $content->ipaddr != "dhcp" ){ if ( $interface != "wan" && $content->ipaddr != "dhcp" ){
// only keep state of dns traffic to prevent dns resolver failures
$this->rules[] = "add ".$rulenum++." allow udp from any to ".$content->ipaddr." dst-port 53 keep-state in";
$this->rules[] = "add ".$rulenum++." allow ip from any to { 255.255.255.255 or ".$content->ipaddr." } in"; $this->rules[] = "add ".$rulenum++." allow ip from any to { 255.255.255.255 or ".$content->ipaddr." } in";
$this->rules[] = "add ".$rulenum++." allow ip from { 255.255.255.255 or ".$content->ipaddr." } to any out"; $this->rules[] = "add ".$rulenum++." allow ip from { 255.255.255.255 or ".$content->ipaddr." } to any out";
$this->rules[] = "add ".$rulenum++." allow icmp from { 255.255.255.255 or ".$content->ipaddr." } to any out icmptypes 0"; $this->rules[] = "add ".$rulenum++." allow icmp from { 255.255.255.255 or ".$content->ipaddr." } to any out icmptypes 0";
......
...@@ -200,7 +200,7 @@ $mac_man = load_mac_manufacturer_table(); ...@@ -200,7 +200,7 @@ $mac_man = load_mac_manufacturer_table();
<td class="listr" colspan="2"></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->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> <a href="?zone=<?=$cpzone;?>&amp;order=<?=$_GET['order'];?>&amp;showact=<?=htmlspecialchars($_GET['showact']);?>&amp;act=del&amp;id=<?=$cpent->sessionid;?>" 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