summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErmal <eri@pfsense.org>2011-06-13 12:34:00 +0000
committerErmal <eri@pfsense.org>2011-06-13 12:34:00 +0000
commitb09c2d86a1f019ff22448109615e11655f12690b (patch)
treeeab661fc6244a32efa807cfa074f08f282543203
parent48de5a1069b5f18e14a606a3b9ac65b22896b04e (diff)
downloadpfsense-b09c2d86a1f019ff22448109615e11655f12690b.zip
pfsense-b09c2d86a1f019ff22448109615e11655f12690b.tar.gz
Do not call time() uselessly every time for each entry. Instead just snapshot it and use it in calculations. This helps performance and useless paranoic time fetching since every 60 seconds the code will be executed again.
-rw-r--r--etc/inc/captiveportal.inc23
1 files changed, 16 insertions, 7 deletions
diff --git a/etc/inc/captiveportal.inc b/etc/inc/captiveportal.inc
index 413e3bc..b0cbf14 100644
--- a/etc/inc/captiveportal.inc
+++ b/etc/inc/captiveportal.inc
@@ -653,6 +653,12 @@ function captiveportal_prune_old() {
*/
$unsetindexes = array();
$voucher_needs_sync = false;
+ /*
+ * Snapshot the time here to use for calculation to speed up the process.
+ * If something is missed next run will catch it!
+ */
+ $pruning_time = time();
+ $stop_time = $pruning_time;
foreach ($cpdb as $cpentry) {
$timedout = false;
@@ -660,7 +666,7 @@ function captiveportal_prune_old() {
/* hard timeout? */
if ($timeout) {
- if ((time() - $cpentry[0]) >= $timeout) {
+ if (($pruning_time - $cpentry[0]) >= $timeout) {
$timedout = true;
$term_cause = 5; // Session-Timeout
}
@@ -668,7 +674,7 @@ function captiveportal_prune_old() {
/* Session-Terminate-Time */
if (!$timedout && !empty($cpentry[9])) {
- if (time() >= $cpentry[9]) {
+ if ($pruning_time >= $cpentry[9]) {
$timedout = true;
$term_cause = 5; // Session-Timeout
}
@@ -683,7 +689,7 @@ function captiveportal_prune_old() {
* We "fix" this by setting lastact to the login timestamp.
*/
$lastact = $lastact ? $lastact : $cpentry[0];
- if ($lastact && ((time() - $lastact) >= $uidletimeout)) {
+ if ($lastact && (($pruning_time - $lastact) >= $uidletimeout)) {
$timedout = true;
$term_cause = 4; // Idle-Timeout
$stop_time = $lastact; // Entry added to comply with WISPr
@@ -692,7 +698,7 @@ function captiveportal_prune_old() {
/* if vouchers are configured, activate session timeouts */
if (!$timedout && isset($config['voucher']['enable'])) {
- if (time() >= ($cpentry[0] + $cpentry[7])) {
+ if ($pruning_time >= ($cpentry[0] + $cpentry[7])) {
$timedout = true;
$term_cause = 5; // Session-Timeout
$voucher_needs_sync = true;
@@ -701,7 +707,7 @@ function captiveportal_prune_old() {
/* if radius session_timeout is enabled and the session_timeout is not null, then check if the user should be logged out */
if (!$timedout && isset($config['captiveportal']['radiussession_timeout']) && !empty($cpentry[7])) {
- if (time() >= ($cpentry[0] + $cpentry[7])) {
+ if ($pruning_time >= ($cpentry[0] + $cpentry[7])) {
$timedout = true;
$term_cause = 5; // Session-Timeout
}
@@ -1615,6 +1621,9 @@ function portal_allow($clientip,$clientmac,$username,$password = null, $attribut
}
}
+ /* Snaphost the timestamp */
+ $allow_time = time();
+
foreach ($cpdb as $sid => $cpentry) {
/* on the same ip */
if($cpentry[2] == $clientip) {
@@ -1625,7 +1634,7 @@ function portal_allow($clientip,$clientmac,$username,$password = null, $attribut
elseif (($attributes['voucher']) && ($username != 'unauthenticated') && ($cpentry[4] == $username)) {
// user logged in with an active voucher. Check for how long and calculate
// how much time we can give him (voucher credit - used time)
- $remaining_time = $cpentry[0] + $cpentry[7] - time();
+ $remaining_time = $cpentry[0] + $cpentry[7] - $allow_time;
if ($remaining_time < 0) // just in case.
$remaining_time = 0;
@@ -1719,7 +1728,7 @@ function portal_allow($clientip,$clientmac,$username,$password = null, $attribut
/* encode password in Base64 just in case it contains commas */
$bpassword = base64_encode($password);
- $cpdb[] = array(time(), $ruleno, $clientip, $clientmac, $username, $sessionid, $bpassword,
+ $cpdb[] = array($allow_time, $ruleno, $clientip, $clientmac, $username, $sessionid, $bpassword,
$attributes['session_timeout'], $attributes['idle_timeout'], $attributes['session_terminate_time']);
/* rewrite information to database */
OpenPOWER on IntegriCloud