Skip to content

Commit

Permalink
Merge pull request #121 from julienloizelet/feat/add-more-logs
Browse files Browse the repository at this point in the history
Feat/add more logs
  • Loading branch information
julienloizelet authored Feb 16, 2023
2 parents c508c19 + d5de928 commit d0db1b0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ The public API of this library consists of all public or protected methods, prop

---

## [1.1.0](https://github.com/crowdsecurity/php-cs-bouncer/releases/tag/v1.1.0) - 2023-02-16
[_Compare with previous release_](https://github.com/crowdsecurity/php-cs-bouncer/compare/v1.0.1...v1.1.0)

### Changed
- Add more log messages during bouncing process

---

## [1.0.1](https://github.com/crowdsecurity/php-cs-bouncer/releases/tag/v1.0.1) - 2023-02-10
[_Compare with previous release_](https://github.com/crowdsecurity/php-cs-bouncer/compare/v1.0.0...v1.0.1)

Expand Down
24 changes: 22 additions & 2 deletions src/AbstractBouncer.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public function bounceCurrentIp(): void
$forcedTestIp = $this->getConfig('forced_test_ip');
$ip = $forcedTestIp ?: $this->getRemoteIp();
$ip = $this->handleForwardedFor($ip, $this->configs);
$this->logger->info('Bouncing current IP', [
'ip' => $ip,
]);
$remediation = $this->getRemediationForIp($ip);
$this->handleRemediation($remediation, $ip);
}
Expand Down Expand Up @@ -356,9 +359,15 @@ protected function handleRemediation(string $remediation, string $ip): void
{
switch ($remediation) {
case Constants::REMEDIATION_CAPTCHA:
$this->logger->debug('Will display a captcha wall', [
'ip' => $ip,
]);
$this->handleCaptchaRemediation($ip);
break;
case Constants::REMEDIATION_BAN:
$this->logger->debug('Will display a ban wall', [
'ip' => $ip,
]);
$this->handleBanRemediation();
break;
case Constants::REMEDIATION_BYPASS:
Expand Down Expand Up @@ -454,11 +463,19 @@ private function capRemediationLevel(string $remediation): string
$maxRemediationLevel,
$orderedRemediations
);
$finalRemediation = $remediation;
if ($currentIndex < $maxIndex) {
return $orderedRemediations[$maxIndex];
$finalRemediation = $orderedRemediations[$maxIndex];
$this->logger->debug('Original remediation has been capped', [
'origin' => $remediation,
'final' => $finalRemediation
]);
}
$this->logger->info('Final remediation', [
'remediation' => $finalRemediation,
]);

return $remediation;
return $finalRemediation;
}

/**
Expand Down Expand Up @@ -614,6 +631,9 @@ private function handleCaptchaRemediation(string $ip): void
if (null === $cachedCaptchaVariables['has_to_be_resolved']) {
// Set up the first captcha remediation.
$mustResolve = true;
$this->logger->debug('First captcha resolution', [
'ip' => $ip,
]);
$this->initCaptchaResolution($ip);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Constants extends RemConstants
/** @var string Path for html templates folder (e.g. ban and captcha wall) */
public const TEMPLATES_DIR = __DIR__ . "/templates";
/** @var string The last version of this library */
public const VERSION = 'v1.0.1';
public const VERSION = 'v1.1.0';
/** @var string The "disabled" x-forwarded-for setting */
public const X_FORWARDED_DISABLED = 'no_forward';
}

0 comments on commit d0db1b0

Please sign in to comment.