From e0270ffe59fb0073cbcfe70effbe35bea1452931 Mon Sep 17 00:00:00 2001 From: Lucas Cherifi Date: Thu, 24 Dec 2020 15:30:30 +0100 Subject: [PATCH] No expiration limits in stream mode --- src/ApiCache.php | 14 ++++++++++++-- src/RestClient.php | 2 +- src/templates/captcha.php | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ApiCache.php b/src/ApiCache.php index 449f0ae..7d3ec14 100644 --- a/src/ApiCache.php +++ b/src/ApiCache.php @@ -208,10 +208,20 @@ private static function parseDurationToSeconds(string $duration): int private function formatRemediationFromDecision(?array $decision): array { if (!$decision) { - return [Constants::REMEDIATION_BYPASS, time() + $this->cacheExpirationForCleanIp, 0]; + $duration = time() + $this->cacheExpirationForCleanIp; + if (!$this->liveMode) { + // In stream mode we considere an clean IP forever... until the next resync. + $duration = PHP_INT_MAX; + } + return [Constants::REMEDIATION_BYPASS, $duration, 0]; } - $duration = min($this->cacheExpirationForBadIp, self::parseDurationToSeconds($decision['duration'])); + $duration = self::parseDurationToSeconds($decision['duration']); + + // Don't set a max duration in stream mode to avoid bugs. Only the stream update has to change the cache state. + if ($this->liveMode) { + $duration = min($this->cacheExpirationForBadIp, $duration); + } return [ $decision['type'], // ex: ban, captcha diff --git a/src/RestClient.php b/src/RestClient.php index 47a15d2..904adfc 100644 --- a/src/RestClient.php +++ b/src/RestClient.php @@ -96,7 +96,7 @@ public function request( $this->logger->debug('', [ 'type' => 'HTTP CALL', - 'method' => $this->baseUri, + 'method' => $method, 'uri' => $this->baseUri.$endpoint, ]); diff --git a/src/templates/captcha.php b/src/templates/captcha.php index 9dfd6c0..b96e471 100644 --- a/src/templates/captcha.php +++ b/src/templates/captcha.php @@ -45,7 +45,7 @@ function displayCaptchaTemplate(bool $error, string $captchaImageSrc, string $ca

Please complete the security check.

captcha to fill -

refresh image

+

refresh image