Skip to content

Commit d0db1b0

Browse files
Merge pull request #121 from julienloizelet/feat/add-more-logs
Feat/add more logs
2 parents c508c19 + d5de928 commit d0db1b0

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ The public API of this library consists of all public or protected methods, prop
1111

1212
---
1313

14+
## [1.1.0](https://github.com/crowdsecurity/php-cs-bouncer/releases/tag/v1.1.0) - 2023-02-16
15+
[_Compare with previous release_](https://github.com/crowdsecurity/php-cs-bouncer/compare/v1.0.1...v1.1.0)
16+
17+
### Changed
18+
- Add more log messages during bouncing process
19+
20+
---
21+
1422
## [1.0.1](https://github.com/crowdsecurity/php-cs-bouncer/releases/tag/v1.0.1) - 2023-02-10
1523
[_Compare with previous release_](https://github.com/crowdsecurity/php-cs-bouncer/compare/v1.0.0...v1.0.1)
1624

src/AbstractBouncer.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ public function bounceCurrentIp(): void
8484
$forcedTestIp = $this->getConfig('forced_test_ip');
8585
$ip = $forcedTestIp ?: $this->getRemoteIp();
8686
$ip = $this->handleForwardedFor($ip, $this->configs);
87+
$this->logger->info('Bouncing current IP', [
88+
'ip' => $ip,
89+
]);
8790
$remediation = $this->getRemediationForIp($ip);
8891
$this->handleRemediation($remediation, $ip);
8992
}
@@ -356,9 +359,15 @@ protected function handleRemediation(string $remediation, string $ip): void
356359
{
357360
switch ($remediation) {
358361
case Constants::REMEDIATION_CAPTCHA:
362+
$this->logger->debug('Will display a captcha wall', [
363+
'ip' => $ip,
364+
]);
359365
$this->handleCaptchaRemediation($ip);
360366
break;
361367
case Constants::REMEDIATION_BAN:
368+
$this->logger->debug('Will display a ban wall', [
369+
'ip' => $ip,
370+
]);
362371
$this->handleBanRemediation();
363372
break;
364373
case Constants::REMEDIATION_BYPASS:
@@ -454,11 +463,19 @@ private function capRemediationLevel(string $remediation): string
454463
$maxRemediationLevel,
455464
$orderedRemediations
456465
);
466+
$finalRemediation = $remediation;
457467
if ($currentIndex < $maxIndex) {
458-
return $orderedRemediations[$maxIndex];
468+
$finalRemediation = $orderedRemediations[$maxIndex];
469+
$this->logger->debug('Original remediation has been capped', [
470+
'origin' => $remediation,
471+
'final' => $finalRemediation
472+
]);
459473
}
474+
$this->logger->info('Final remediation', [
475+
'remediation' => $finalRemediation,
476+
]);
460477

461-
return $remediation;
478+
return $finalRemediation;
462479
}
463480

464481
/**
@@ -614,6 +631,9 @@ private function handleCaptchaRemediation(string $ip): void
614631
if (null === $cachedCaptchaVariables['has_to_be_resolved']) {
615632
// Set up the first captcha remediation.
616633
$mustResolve = true;
634+
$this->logger->debug('First captcha resolution', [
635+
'ip' => $ip,
636+
]);
617637
$this->initCaptchaResolution($ip);
618638
}
619639

src/Constants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Constants extends RemConstants
3939
/** @var string Path for html templates folder (e.g. ban and captcha wall) */
4040
public const TEMPLATES_DIR = __DIR__ . "/templates";
4141
/** @var string The last version of this library */
42-
public const VERSION = 'v1.0.1';
42+
public const VERSION = 'v1.1.0';
4343
/** @var string The "disabled" x-forwarded-for setting */
4444
public const X_FORWARDED_DISABLED = 'no_forward';
4545
}

0 commit comments

Comments
 (0)