home *** CD-ROM | disk | FTP | other *** search
- <?php
- ////////////////////////////////////////////////////////////////////////////////
- // <!--Copyright (c) 2005 Pure Networks Inc. All rights reserved.-->
- ////////////////////////////////////////////////////////////////////////////////
- //
- // Build: 3.0.6121.0 (Stable)
- // $Revision: #1 $
- //
-
- // Predefined Login Failure Lockout Business Logic
- // Failure Count is number of allowed failures before lock goes into effect
- // Failure Time is the time in seconds that the Failures must occur in to create a lock
- // Lockout Time is the time in seconds that the lock is in effect
-
- // Single IP Lock Values
- $iSingleIpFailureCount = 10;
- $iSingleIpFailureTime = 60;
- $iSingleIpLockoutTime = 300;
-
- // Multi IP Lock Values
- $iMultiIpFailureCount = 20;
- $iMultiIpFailureTime = 60;
- $iMultiIpLockoutTime = 1800;
-
- function isLockedOut()
- {
- if (getLockedOutState($_SERVER['REMOTE_ADDR']) || getLockedOutState("0.0.0.0"))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- function getLockedOutState($sIpAddress)
- {
- global $iMultiIpFailureCount, $iMultiIpFailureTime, $iMultiIpLockoutTime, $iSingleIpFailureCount, $iSingleIpFailureTime, $iSingleIpLockoutTime;
- $bReturn = false;
- // get the proper Failure Time, FailureCount, and LockoutTime
- switch ($sIpAddress)
- {
- case "0.0.0.0":
- $iFailureCount = $iMultiIpFailureCount;
- $iFailureTime = $iMultiIpFailureTime;
- $iLockoutTime = $iMultiIpLockoutTime;
- break;
- default:
- $iFailureCount = $iSingleIpFailureCount;
- $iFailureTime = $iSingleIpFailureTime;
- $iLockoutTime = $iSingleIpLockoutTime;
- }
-
- $arIpArray = getSerializedProperty("iplock");
- $sSecondsDiff = strtotime(date('m/d/Y H:i:s')) - strtotime($arIpArray[$sIpAddress]['time']);
- if (($sSecondsDiff < $iLockoutTime) && ($arIpArray[$sIpAddress]['count'] >= $iFailureCount) )
- {
- $bReturn = true;
- }
-
- return $bReturn;
- }
-
- function updateLockoutCount()
- {
- // get the lockout info if it exists
- $arIpArray = getSerializedProperty("iplock");
-
- // First let's set the single IP counts
- $arIpArray = setLockoutCount($_SERVER['REMOTE_ADDR'], $arIpArray);
- // Now let's set the multi IP counts
- $arIpArray = setLockoutCount("0.0.0.0", $arIpArray);
-
- // save the lockout info
- setSerializedProperty("iplock", $arIpArray);
- }
-
- function setLockoutCount($sIpAddress, $arIpArray)
- {
- global $iMultiIpFailureCount, $iMultiIpFailureTime, $iMultiIpLockoutTime, $iSingleIpFailureCount, $iSingleIpFailureTime, $iSingleIpLockoutTime;
-
- // get the proper Failure Time
- switch ($sIpAddress)
- {
- case "0.0.0.0":
- $iFailureCount = $iMultiIpFailureCount;
- $iFailureTime = $iMultiIpFailureTime;
- break;
- default:
- $iFailureCount = $iSingleIpFailureCount;
- $iFailureTime = $iSingleIpFailureTime;
- }
-
- if (isset($arIpArray[$sIpAddress]))
- {
- $sSecondsDiff = strtotime(date('m/d/Y H:i:s')) - strtotime($arIpArray[$sIpAddress]['time']);
- if ($sSecondsDiff < $iFailureTime)
- {
- $arIpArray[$sIpAddress]['count'] = $arIpArray[$sIpAddress]['count'] + 1;
- }
- else
- {
- if (!isLockedOut())
- {
- $arIpArray[$sIpAddress]['count'] = 1;
- $arIpArray[$sIpAddress]['time'] = date('m/d/Y H:i:s');
- }
- }
- }
- else
- {
- $arIpArray[$sIpAddress]['count'] = 1;
- $arIpArray[$sIpAddress]['time'] = date('m/d/Y H:i:s');
- }
-
- return $arIpArray;
- }
- ?>