Ejemplo n.º 1
0
 public static function bounce()
 {
     if (isset($_GET['bouncer-challenge'])) {
         self::challenge();
         return;
     }
     $identity = self::identity();
     if (empty($identity) || empty($identity['id'])) {
         return;
     }
     $request = self::request();
     // Analyse Identity
     list($identity, $result) = self::analyse($identity, $request);
     // Log Connection
     self::log($identity, $request, $result);
     // Set Bouncer Cookie
     if (empty($_COOKIE['bouncer-identity']) || $_COOKIE['bouncer-identity'] != $identity['id']) {
         setcookie('bouncer-identity', $identity['id'], time() + 60 * 60 * 24 * 365, '/');
     }
     // Process
     list($status, $score) = $result;
     switch ($status) {
         case self::BAD:
             $throttle = rand(1000 * 1000, 2000 * 1000);
             self::$_throttle = $throttle;
             usleep($throttle);
             static::unavailable();
             break;
         case self::SUSPICIOUS:
             $throttle = rand(500 * 1000, 2000 * 1000);
             self::$_throttle = $throttle;
             usleep($throttle);
             break;
         case self::NEUTRAL:
             if ($identity['type'] == Bouncer::ROBOT) {
                 $throttle = rand(250 * 1000, 1000 * 1000);
                 self::$_throttle = $throttle;
                 usleep($throttle);
             }
             break;
         case self::NICE:
         default:
             break;
     }
     // End
     register_shutdown_function(array('Bouncer', 'end'));
 }