Revision b09c2d86
Added by Ermal LUÇI about 14 years ago
etc/inc/captiveportal.inc | ||
---|---|---|
653 | 653 |
*/ |
654 | 654 |
$unsetindexes = array(); |
655 | 655 |
$voucher_needs_sync = false; |
656 |
/* |
|
657 |
* Snapshot the time here to use for calculation to speed up the process. |
|
658 |
* If something is missed next run will catch it! |
|
659 |
*/ |
|
660 |
$pruning_time = time(); |
|
661 |
$stop_time = $pruning_time; |
|
656 | 662 |
foreach ($cpdb as $cpentry) { |
657 | 663 |
|
658 | 664 |
$timedout = false; |
... | ... | |
660 | 666 |
|
661 | 667 |
/* hard timeout? */ |
662 | 668 |
if ($timeout) { |
663 |
if ((time() - $cpentry[0]) >= $timeout) {
|
|
669 |
if (($pruning_time - $cpentry[0]) >= $timeout) {
|
|
664 | 670 |
$timedout = true; |
665 | 671 |
$term_cause = 5; // Session-Timeout |
666 | 672 |
} |
... | ... | |
668 | 674 |
|
669 | 675 |
/* Session-Terminate-Time */ |
670 | 676 |
if (!$timedout && !empty($cpentry[9])) { |
671 |
if (time() >= $cpentry[9]) {
|
|
677 |
if ($pruning_time >= $cpentry[9]) {
|
|
672 | 678 |
$timedout = true; |
673 | 679 |
$term_cause = 5; // Session-Timeout |
674 | 680 |
} |
... | ... | |
683 | 689 |
* We "fix" this by setting lastact to the login timestamp. |
684 | 690 |
*/ |
685 | 691 |
$lastact = $lastact ? $lastact : $cpentry[0]; |
686 |
if ($lastact && ((time() - $lastact) >= $uidletimeout)) {
|
|
692 |
if ($lastact && (($pruning_time - $lastact) >= $uidletimeout)) {
|
|
687 | 693 |
$timedout = true; |
688 | 694 |
$term_cause = 4; // Idle-Timeout |
689 | 695 |
$stop_time = $lastact; // Entry added to comply with WISPr |
... | ... | |
692 | 698 |
|
693 | 699 |
/* if vouchers are configured, activate session timeouts */ |
694 | 700 |
if (!$timedout && isset($config['voucher']['enable'])) { |
695 |
if (time() >= ($cpentry[0] + $cpentry[7])) {
|
|
701 |
if ($pruning_time >= ($cpentry[0] + $cpentry[7])) {
|
|
696 | 702 |
$timedout = true; |
697 | 703 |
$term_cause = 5; // Session-Timeout |
698 | 704 |
$voucher_needs_sync = true; |
... | ... | |
701 | 707 |
|
702 | 708 |
/* if radius session_timeout is enabled and the session_timeout is not null, then check if the user should be logged out */ |
703 | 709 |
if (!$timedout && isset($config['captiveportal']['radiussession_timeout']) && !empty($cpentry[7])) { |
704 |
if (time() >= ($cpentry[0] + $cpentry[7])) {
|
|
710 |
if ($pruning_time >= ($cpentry[0] + $cpentry[7])) {
|
|
705 | 711 |
$timedout = true; |
706 | 712 |
$term_cause = 5; // Session-Timeout |
707 | 713 |
} |
... | ... | |
1615 | 1621 |
} |
1616 | 1622 |
} |
1617 | 1623 |
|
1624 |
/* Snaphost the timestamp */ |
|
1625 |
$allow_time = time(); |
|
1626 |
|
|
1618 | 1627 |
foreach ($cpdb as $sid => $cpentry) { |
1619 | 1628 |
/* on the same ip */ |
1620 | 1629 |
if($cpentry[2] == $clientip) { |
... | ... | |
1625 | 1634 |
elseif (($attributes['voucher']) && ($username != 'unauthenticated') && ($cpentry[4] == $username)) { |
1626 | 1635 |
// user logged in with an active voucher. Check for how long and calculate |
1627 | 1636 |
// how much time we can give him (voucher credit - used time) |
1628 |
$remaining_time = $cpentry[0] + $cpentry[7] - time();
|
|
1637 |
$remaining_time = $cpentry[0] + $cpentry[7] - $allow_time;
|
|
1629 | 1638 |
if ($remaining_time < 0) // just in case. |
1630 | 1639 |
$remaining_time = 0; |
1631 | 1640 |
|
... | ... | |
1719 | 1728 |
|
1720 | 1729 |
/* encode password in Base64 just in case it contains commas */ |
1721 | 1730 |
$bpassword = base64_encode($password); |
1722 |
$cpdb[] = array(time(), $ruleno, $clientip, $clientmac, $username, $sessionid, $bpassword,
|
|
1731 |
$cpdb[] = array($allow_time, $ruleno, $clientip, $clientmac, $username, $sessionid, $bpassword,
|
|
1723 | 1732 |
$attributes['session_timeout'], $attributes['idle_timeout'], $attributes['session_terminate_time']); |
1724 | 1733 |
|
1725 | 1734 |
/* rewrite information to database */ |
Also available in: Unified diff
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.