Skip to content

Commit a9ac080

Browse files
Merge pull request #81 from julienloizelet/fix/boolean-parameter
fix(captcha): Fix displayCaptchaWall function and handle some retro-c…
2 parents b09d9e9 + 4ad0d14 commit a9ac080

File tree

8 files changed

+34
-15
lines changed

8 files changed

+34
-15
lines changed

.github/workflows/test-suite.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Test suite
22
on:
3-
pull_request:
3+
push:
44
branches:
55
- main
66
paths-ignore:
@@ -113,6 +113,7 @@ jobs:
113113
run: |
114114
cd ${{ github.workspace }}
115115
cp .ddev/custom_files/phpinfo.php my-own-modules/crowdsec-php-lib/scripts/public/phpinfo.php
116+
curl -v https://${{ env.PHP_VERSION_CODE }}.ddev.site/my-own-modules/crowdsec-php-lib/scripts/public/phpinfo.php
116117
PREPENDVERIF=$(curl https://${{ env.PHP_VERSION_CODE }}.ddev.site/my-own-modules/crowdsec-php-lib/scripts/public/phpinfo.php | grep -o -E "auto_prepend_file=(.*)php(.*)" | sed 's/<\/tr>//g; s/<\/td>//g;' | tr '\n' '#')
117118
if [[ $PREPENDVERIF == "auto_prepend_file=/var/www/html/my-own-modules/crowdsec-php-lib/scripts/auto-prepend/bounce.php#auto_prepend_file=/var/www/html/my-own-modules/crowdsec-php-lib/scripts/auto-prepend/bounce.php#" ]]
118119
then

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77

8+
## [0.20.1] - 2022-04-07
9+
10+
### Added
11+
- Handle old lib version (`< 0.14.0`) settings values retro-compatibility for Standalone bouncer
12+
### Fixed
13+
- Fix `AbstractBounce:displayCaptchaWall` function
14+
815

916
## [0.20.0] - 2022-03-31
1017

@@ -15,7 +22,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1522
## [0.19.0] - 2022-03-24
1623

1724
### Added
18-
1925
- Add `excluded_uris` configuration to exclude some uris (was hardcoded to `/favicon.ico`)
2026

2127
### Changed

docs/DEVELOPER.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ For a quick start, follow the below steps.
6767

6868
#### DDEV installation
6969

70-
This project is fully compatible with DDEV 1.18.2 and it is recommended to use this specific version.
70+
This project is fully compatible with DDEV 1.19.1, and it is recommended to use this specific version.
7171
For the DDEV installation, please follow the [official instructions](https://ddev.readthedocs.io/en/stable/#installation).
7272
On a Linux distribution, you can run:
7373
```
7474
sudo apt-get -qq update
7575
sudo apt-get -qq -y install libnss3-tools
7676
curl -LO https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh
77-
bash install_ddev.sh v1.18.2
77+
bash install_ddev.sh v1.19.1
7878
rm install_ddev.sh
7979
```
8080

scripts/auto-prepend/bounce.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
/**
33
* This script is aimed to be called by an auto-prepend directive
44
* @see docs/USER_GUIDE.md
5+
* @var $crowdSecStandaloneBouncerConfig
56
*/
67
require_once __DIR__ . '/../../vendor/autoload.php';
78
require_once __DIR__ . '/settings.php';
89

910
use CrowdSecBouncer\StandaloneBounce;
1011

11-
12-
1312
$bounce = new StandaloneBounce();
13+
// Retro compatibility with crowdsec php lib < 0.14.0
14+
if(isset($crowdSecStandaloneBouncerConfig['bouncing_level']) && $crowdSecStandaloneBouncerConfig['bouncing_level'] === 'normal_boucing'){
15+
$crowdSecStandaloneBouncerConfig['bouncing_level'] = 'normal_bouncing';
16+
}elseif($crowdSecStandaloneBouncerConfig['bouncing_level'] === 'flex_boucing'){
17+
$crowdSecStandaloneBouncerConfig['bouncing_level'] = 'flex_bouncing';
18+
}
1419

15-
/** @var $crowdSecStandaloneBouncerConfig */
1620
$bounce->safelyBounce($crowdSecStandaloneBouncerConfig);

scripts/auto-prepend/refresh-cache.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22
/**
33
* This script is aimed to be called by an auto-prepend directive
44
* @see docs/USER_GUIDE.md
5+
* @var $crowdSecStandaloneBouncerConfig
56
*/
67
require_once __DIR__ . '/../../vendor/autoload.php';
78
require_once __DIR__ . '/settings.php';
89

910
use CrowdSecBouncer\StandaloneBounce;
1011

1112
$bounce = new StandaloneBounce();
13+
// Retro compatibility with crowdsec php lib < 0.14.0
14+
if(isset($crowdSecStandaloneBouncerConfig['bouncing_level']) && $crowdSecStandaloneBouncerConfig['bouncing_level'] === 'normal_boucing'){
15+
$crowdSecStandaloneBouncerConfig['bouncing_level'] = 'normal_bouncing';
16+
}elseif($crowdSecStandaloneBouncerConfig['bouncing_level'] === 'flex_boucing'){
17+
$crowdSecStandaloneBouncerConfig['bouncing_level'] = 'flex_bouncing';
18+
}
1219

13-
/** @var $crowdSecStandaloneBouncerConfig */
1420
$bouncer = $bounce->init($crowdSecStandaloneBouncerConfig);
1521
$bouncer->refreshBlocklistCache();
16-
echo 'Cache has been refreshed';
22+
echo 'Cache has been refreshed';

src/AbstractBounce.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ protected function displayCaptchaWall()
175175
{
176176
$options = $this->getCaptchaWallOptions();
177177
$body = Bouncer::getCaptchaHtmlTemplate(
178-
$this->getSessionVariable('crowdsec_captcha_resolution_failed'),
179-
$this->getSessionVariable('crowdsec_captcha_inline_image'),
178+
(bool) $this->getSessionVariable('crowdsec_captcha_resolution_failed'),
179+
(string) $this->getSessionVariable('crowdsec_captcha_inline_image'),
180180
'',
181181
$options
182182
);

src/Bouncer.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,11 @@ public static function getAccessForbiddenHtmlTemplate(array $config): string
145145
* Returns a default "CrowdSec Captcha" HTML template to display to a web browser using a captchable IP.
146146
* The input $config should match the TemplateConfiguration input format.
147147
*
148-
* @param array $config An array of template configuration parameters
149-
*
150-
* @return string The HTML compiled template
148+
* @param bool $error
149+
* @param string $captchaImageSrc
150+
* @param string $captchaResolutionFormUrl
151+
* @param array $config
152+
* @return string
151153
*/
152154
public static function getCaptchaHtmlTemplate(bool $error, string $captchaImageSrc, string $captchaResolutionFormUrl, array $config): string
153155
{

src/Constants.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Constants
2020
public const DEFAULT_LAPI_URL = 'http://localhost:8080';
2121

2222
/** @var string The last version of this library */
23-
public const VERSION = 'v0.20.0';
23+
public const VERSION = 'v0.20.1';
2424

2525
/** @var string The user agent used to send request to LAPI */
2626
public const BASE_USER_AGENT = 'PHP CrowdSec Bouncer/'.self::VERSION;

0 commit comments

Comments
 (0)