home *** CD-ROM | disk | FTP | other *** search
/ PCNet 2006 April / PCnet 2006-06.4.iso / shareware / nmsetup.exe / WebServer / web / _loginutils.php < prev    next >
Encoding:
PHP Script  |  2006-05-01  |  3.8 KB  |  119 lines

  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // <!--Copyright (c) 2005 Pure Networks Inc.  All rights reserved.-->
  4. ////////////////////////////////////////////////////////////////////////////////
  5. //
  6. // Build: 3.0.6121.0 (Stable)
  7. // $Revision: #1 $
  8. //
  9.  
  10. // Predefined Login Failure Lockout Business Logic
  11.     // Failure Count is number of allowed failures before lock goes into effect
  12.     // Failure Time is the time in seconds that the Failures must occur in to create a lock
  13.     // Lockout Time is the time in seconds that the lock is in effect
  14.     
  15.     // Single IP Lock Values
  16.     $iSingleIpFailureCount  =   10;
  17.     $iSingleIpFailureTime   =   60;
  18.     $iSingleIpLockoutTime   =   300;
  19.     
  20.     // Multi IP Lock Values
  21.     $iMultiIpFailureCount  =   20;
  22.     $iMultiIpFailureTime   =   60;
  23.     $iMultiIpLockoutTime   =   1800;
  24.  
  25. function isLockedOut()
  26. {
  27.     if (getLockedOutState($_SERVER['REMOTE_ADDR']) || getLockedOutState("0.0.0.0"))
  28.     {
  29.         return true;
  30.     }
  31.     else
  32.     {
  33.         return false;
  34.     }
  35. }
  36.  
  37. function getLockedOutState($sIpAddress)
  38. {
  39.     global $iMultiIpFailureCount, $iMultiIpFailureTime, $iMultiIpLockoutTime, $iSingleIpFailureCount, $iSingleIpFailureTime, $iSingleIpLockoutTime;
  40.     $bReturn = false;
  41.     // get the proper Failure Time, FailureCount, and LockoutTime
  42.     switch ($sIpAddress)
  43.     {
  44.         case "0.0.0.0":
  45.             $iFailureCount  =   $iMultiIpFailureCount;
  46.             $iFailureTime   =   $iMultiIpFailureTime;
  47.             $iLockoutTime   =   $iMultiIpLockoutTime;
  48.             break;
  49.         default:
  50.             $iFailureCount  =   $iSingleIpFailureCount;
  51.             $iFailureTime   =   $iSingleIpFailureTime;
  52.             $iLockoutTime   =   $iSingleIpLockoutTime;
  53.     }
  54.     
  55.     $arIpArray = getSerializedProperty("iplock");
  56.     $sSecondsDiff = strtotime(date('m/d/Y H:i:s')) - strtotime($arIpArray[$sIpAddress]['time']);
  57.     if (($sSecondsDiff < $iLockoutTime) && ($arIpArray[$sIpAddress]['count'] >= $iFailureCount) )
  58.     {
  59.         $bReturn = true;
  60.     }
  61.  
  62.     return $bReturn;
  63. }
  64.  
  65. function updateLockoutCount()
  66. {
  67.     // get the lockout info if it exists
  68.     $arIpArray = getSerializedProperty("iplock");
  69.     
  70.     // First let's set the single IP counts
  71.     $arIpArray = setLockoutCount($_SERVER['REMOTE_ADDR'], $arIpArray);
  72.     // Now let's set the multi IP counts
  73.     $arIpArray = setLockoutCount("0.0.0.0", $arIpArray);
  74.     
  75.     // save the lockout info
  76.     setSerializedProperty("iplock", $arIpArray);
  77. }
  78.  
  79. function setLockoutCount($sIpAddress, $arIpArray)
  80. {
  81.     global $iMultiIpFailureCount, $iMultiIpFailureTime, $iMultiIpLockoutTime, $iSingleIpFailureCount, $iSingleIpFailureTime, $iSingleIpLockoutTime;
  82.  
  83.     // get the proper Failure Time
  84.     switch ($sIpAddress)
  85.     {
  86.         case "0.0.0.0":
  87.             $iFailureCount  =   $iMultiIpFailureCount;
  88.             $iFailureTime   =   $iMultiIpFailureTime;
  89.             break;
  90.         default:
  91.             $iFailureCount  =   $iSingleIpFailureCount;
  92.             $iFailureTime   =   $iSingleIpFailureTime;
  93.     }
  94.  
  95.     if (isset($arIpArray[$sIpAddress]))
  96.     {
  97.         $sSecondsDiff = strtotime(date('m/d/Y H:i:s')) - strtotime($arIpArray[$sIpAddress]['time']);
  98.         if ($sSecondsDiff < $iFailureTime)
  99.         {
  100.             $arIpArray[$sIpAddress]['count'] = $arIpArray[$sIpAddress]['count'] + 1;
  101.         }
  102.         else
  103.         {
  104.             if (!isLockedOut())
  105.             {
  106.                 $arIpArray[$sIpAddress]['count'] = 1;
  107.                 $arIpArray[$sIpAddress]['time'] = date('m/d/Y H:i:s');
  108.             }
  109.         }
  110.     }
  111.     else
  112.     {
  113.         $arIpArray[$sIpAddress]['count'] = 1;
  114.         $arIpArray[$sIpAddress]['time'] = date('m/d/Y H:i:s');
  115.     }
  116.  
  117.     return $arIpArray;
  118. }
  119. ?>