Skip to content

Commit

Permalink
No expiration limits in stream mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mobula9 committed Dec 24, 2020
1 parent 44741cf commit e0270ff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/ApiCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/RestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function request(

$this->logger->debug('', [
'type' => 'HTTP CALL',
'method' => $this->baseUri,
'method' => $method,
'uri' => $this->baseUri.$endpoint,
]);

Expand Down
2 changes: 1 addition & 1 deletion src/templates/captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function displayCaptchaTemplate(bool $error, string $captchaImageSrc, string $ca
<p class="desc">Please complete the security check.</p>

<img src="<?php echo $captchaImageSrc; ?>" alt="captcha to fill" />
<p><small><a href="#" onclick="newImage()">refresh image</a></small></p>
<p><small><a id="refresh_link" href="#" onclick="newImage()">refresh image</a></small></p>

<form method="post" id="captcha" action="<?php echo $captchaResolutionFormUrl; ?>">
<input type="text" name="phrase" placeholder="Type here..." autofocus autocomplete="off" />
Expand Down

0 comments on commit e0270ff

Please sign in to comment.