Skip to content

Commit 06801b6

Browse files
Merge pull request #127 from julienloizelet/feat/remove-standalone-code
Feat/remove standalone code
2 parents 92003da + 3b4358d commit 06801b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1414
-3534
lines changed

.github/workflows/test-suite.yml

Lines changed: 4 additions & 305 deletions
Large diffs are not rendered by default.

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ The [public API](https://semver.org/spec/v2.0.0.html#spec-item-1) of this librar
99

1010
---
1111

12-
## [?.?.?](https://github.com/crowdsecurity/php-cs-bouncer/releases/tag/v?.?.?) - ?.?.?
13-
[_Compare with previous release_](https://github.com/crowdsecurity/php-cs-bouncer/compare/v1.4.0...v?.?.?)
12+
## [2.0.0](https://github.com/crowdsecurity/php-cs-bouncer/releases/tag/v2.0.0) - 2023-04-13
13+
[_Compare with previous release_](https://github.com/crowdsecurity/php-cs-bouncer/compare/v1.4.0...v2.0.0)
1414

1515

1616
### Changed
17+
1718
- Update `gregwar/captcha` from `1.1.9` to `1.2.0` and remove some override fixes
1819

20+
### Removed
21+
22+
- Remove all code about standalone bouncer
23+
1924
---
2025

2126

docs/DEVELOPER.md

Lines changed: 7 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ For a quick start, follow the below steps.
6969

7070
#### DDEV installation
7171

72-
This project is fully compatible with DDEV 1.21.4, and it is recommended to use this specific version.
7372
For the DDEV installation, please follow the [official instructions](https://ddev.readthedocs.io/en/stable/users/install/ddev-installation/).
7473

7574

@@ -208,7 +207,7 @@ Finally, run
208207

209208
```bash
210209
ddev exec BOUNCER_KEY=your-bouncer-key AGENT_TLS_PATH=/var/www/html/cfssl LAPI_URL=https://crowdsec:8080
211-
MEMCACHED_DSN=memcached://memcached:11211 REDIS_DSN=redis://redis:6379 /usr/bin/php ./my-code/crowdsec-bouncer-lib/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./my-code/crowdsec-bouncer-lib/tests/Integration/IpVerificationTest.php
210+
MEMCACHED_DSN=memcached://memcached:11211 REDIS_DSN=redis://redis:6379 /usr/bin/php ./my-code/crowdsec-bouncer-lib/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./my-code/crowdsec-bouncer-lib/tests/Integration/AbstractBouncerTest.php
212211
```
213212

214213
For geolocation Unit Test, you should first put 2 free MaxMind databases in the `tests` folder : `GeoLite2-City.mmdb`
@@ -222,70 +221,12 @@ ddev exec BOUNCER_KEY=your-bouncer-key AGENT_TLS_PATH=/var/www/html/cfssl LAPI_U
222221
MEMCACHED_DSN=memcached://memcached:11211 REDIS_DSN=redis://redis:6379 /usr/bin/php ./my-code/crowdsec-bouncer-lib/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./my-code/crowdsec-bouncer-lib/tests/Integration/GeolocationTest.php
223222
```
224223

225-
**N.B.**: If you want to test with `curl` instead of `file_get_contents` calls to LAPI, you have to add `USE_CURL=1` in
226-
the previous commands.
227224

228225
**N.B**.: If you want to test with `tls` authentification, you have to add `BOUNCER_TLS_PATH` environment variable
229226
and specify the path where you store certificates and keys. For example:
230227

231228
```bash
232-
ddev exec USE_CURL=1 AGENT_TLS_PATH=/var/www/html/cfssl BOUNCER_TLS_PATH=/var/www/html/cfssl LAPI_URL=https://crowdsec:8080 MEMCACHED_DSN=memcached://memcached:11211 REDIS_DSN=redis://redis:6379 /usr/bin/php ./my-code/crowdsec-bouncer-lib/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./my-code/crowdsec-bouncer-lib/tests/Integration/IpVerificationTest.php
233-
```
234-
235-
236-
#### Auto-prepend mode (standalone mode)
237-
238-
Before using the bouncer in a standalone mode (i.e. with an auto-prepend directive), you should copy the [`scripts/auto-prepend/settings.example.php`](../scripts/auto-prepend/settings.example.php) file to a `scripts/auto-prepend/settings.php` and edit it depending on your needs.
239-
240-
Then, to configure the Nginx service in order that it uses an auto-prepend directive pointing to the [`scripts/auto-prepend/bounce.php`](../scripts/auto-prepend/bounce.php) script, please run the following command from the `.ddev` folder:
241-
242-
```bash
243-
ddev crowdsec-prepend-nginx
244-
```
245-
246-
With that done, every access to your ddev url (i.e. `https://phpXX.ddev.site` where `XX` is your php version) will be bounce.
247-
248-
For example, you should try to browse the following url:
249-
250-
```
251-
https://phpXX.ddev.site/my-code/crowdsec-bouncer-lib/scripts/public/protected-page.php
252-
```
253-
254-
#### End-to-end tests
255-
256-
In auto-prepend mode, you can run some end-to-end tests.
257-
258-
We are using a Jest/Playwright Node.js stack to launch a suite of end-to-end tests.
259-
260-
Tests code is in the `tests/end-to-end` folder. You should have to `chmod +x` the scripts you will find in `tests/end-to-end/__scripts__`.
261-
262-
263-
```
264-
cd crowdsec-bouncer-project
265-
cp -r .ddev/okaeli-add-on/custom_files/crowdsec/cfssl/* cfssl
266-
```
267-
268-
Then you can use the `run-test.sh` script to run the tests:
269-
270-
- the first parameter specifies if you want to run the test on your machine (`host`) or in the
271-
docker containers (`docker`). You can also use `ci` if you want to have the same behavior as in GitHub action.
272-
- the second parameter list the test files you want to execute. If empty, all the test suite will be launched.
273-
274-
For example:
275-
276-
./run-tests.sh host "./__tests__/1-live-mode.js"
277-
./run-tests.sh docker "./__tests__/1-live-mode.js"
278-
./run-tests.sh host
279-
280-
Before testing with the `docker` or `ci` parameter, you have to install all the required dependencies in the playwright container with this command :
281-
282-
./test-init.sh
283-
284-
If you want to test with the `host` parameter, you will have to install manually all the required dependencies:
285-
286-
```bash
287-
yarn --cwd ./tests/end-to-end --force
288-
yarn global add cross-env
229+
ddev exec USE_CURL=1 AGENT_TLS_PATH=/var/www/html/cfssl BOUNCER_TLS_PATH=/var/www/html/cfssl LAPI_URL=https://crowdsec:8080 MEMCACHED_DSN=memcached://memcached:11211 REDIS_DSN=redis://redis:6379 /usr/bin/php ./my-code/crowdsec-bouncer-lib/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./my-code/crowdsec-bouncer-lib/tests/Integration/AbstractBouncerTest.php
289230
```
290231

291232
#### Coding standards
@@ -331,13 +272,13 @@ ddev phpmd ./my-code/crowdsec-bouncer-lib/tools/coding-standards phpmd/rulesets.
331272
To use [PHP Code Sniffer](https://github.com/squizlabs/PHP_CodeSniffer) tools, you can run:
332273

333274
```bash
334-
ddev phpcs ./my-code/crowdsec-bouncer-lib/tools/coding-standards my-code/crowdsec-php-lib/src PSR12
275+
ddev phpcs ./my-code/crowdsec-bouncer-lib/tools/coding-standards my-code/crowdsec-bouncer-lib/src PSR12
335276
```
336277

337278
and:
338279

339280
```bash
340-
ddev phpcbf ./my-code/crowdsec-php-lib/tools/coding-standards my-code/crowdsec-php-lib/src PSR12
281+
ddev phpcbf ./my-code/crowdsec-bouncer-lib/tools/coding-standards my-code/crowdsec-bouncer-lib/src PSR12
341282
```
342283

343284

@@ -346,7 +287,7 @@ ddev phpcbf ./my-code/crowdsec-php-lib/tools/coding-standards my-code/crowdsec-
346287
To use [PSALM](https://github.com/vimeo/psalm) tools, you can run:
347288

348289
```bash
349-
ddev psalm ./my-code/crowdsec-php-lib/tools/coding-standards ./my-code/crowdsec-php-lib/tools/coding-standards/psalm
290+
ddev psalm ./my-code/crowdsec-bouncer-lib/tools/coding-standards ./my-code/crowdsec-bouncer-lib/tools/coding-standards/psalm
350291
```
351292

352293
##### PHP Unit Code coverage
@@ -360,7 +301,7 @@ ddev xdebug
360301

361302
To generate a html report, you can run:
362303
```bash
363-
ddev exec XDEBUG_MODE=coverage BOUNCER_KEY=your-bouncer-key AGENT_TLS_PATH=/var/www/html/cfssl LAPI_URL=https://crowdsec:8080 REDIS_DSN=redis://redis:6379 MEMCACHED_DSN=memcached://memcached:11211 /usr/bin/php ./my-code/crowdsec-php-lib/tools/coding-standards/vendor/bin/phpunit --configuration ./my-code/crowdsec-php-lib/tools/coding-standards/phpunit/phpunit.xml
304+
ddev exec XDEBUG_MODE=coverage BOUNCER_KEY=your-bouncer-key AGENT_TLS_PATH=/var/www/html/cfssl LAPI_URL=https://crowdsec:8080 REDIS_DSN=redis://redis:6379 MEMCACHED_DSN=memcached://memcached:11211 /usr/bin/php ./my-code/crowdsec-bouncer-lib/tools/coding-standards/vendor/bin/phpunit --configuration ./my-code/crowdsec-bouncer-lib/tools/coding-standards/phpunit/phpunit.xml
364305

365306
```
366307

@@ -371,7 +312,7 @@ If you want to generate a text report in the same folder:
371312

372313
```bash
373314
ddev exec XDEBUG_MODE=coverage BOUNCER_KEY=your-bouncer-key LAPI_URL=https://crowdsec:8080
374-
MEMCACHED_DSN=memcached://memcached:11211 REDIS_DSN=redis://redis:6379 /usr/bin/php ./my-code/crowdsec-php-lib/tools/coding-standards/vendor/bin/phpunit --configuration ./my-code/crowdsec-php-lib/tools/coding-standards/phpunit/phpunit.xml --coverage-text=./my-code/crowdsec-php-lib/tools/coding-standards/phpunit/code-coverage/report.txt
315+
MEMCACHED_DSN=memcached://memcached:11211 REDIS_DSN=redis://redis:6379 /usr/bin/php ./my-code/crowdsec-bouncer-lib/tools/coding-standards/vendor/bin/phpunit --configuration ./my-code/crowdsec-bouncer-lib/tools/coding-standards/phpunit/phpunit.xml --coverage-text=./my-code/crowdsec-bouncer-lib/tools/coding-standards/phpunit/code-coverage/report.txt
375316
```
376317

377318
#### Generate CrowdSec tools and settings on start
@@ -434,72 +375,6 @@ the max number of keys to dump:
434375
- `delete <mykey>`: Delete a key
435376

436377

437-
## Example scripts
438-
439-
You will find some php scripts in the `scripts` folder.
440-
441-
**N.B**. : If you are not using DDEV, you can replace all `ddev exec php ` by `php` and specify the right script paths.
442-
443-
### Clear cache script
444-
445-
To clear your LAPI cache, you can use the [`clear-php`](../scripts/clear-cache.php) script:
446-
447-
```bash
448-
ddev exec php my-code/crowdsec-php-lib/scripts/clear-cache.php <BOUNCER_KEY>
449-
```
450-
451-
### Full Live mode example
452-
453-
This example demonstrates how the PHP Lib works with cache when you are using the live mode.
454-
455-
We will use here the [`standalone-check-ip-live.php`](../scripts/standalone-check-ip-live.php).
456-
457-
#### Set up the context
458-
459-
Start the containers:
460-
461-
```bash
462-
ddev start
463-
```
464-
465-
Then get a bouncer API key by copying the result of:
466-
467-
```bash
468-
ddev create-bouncer
469-
```
470-
471-
#### Get the remediation the clean IP "1.2.3.4"
472-
473-
Try with the `standalone-check-ip-live.php` file:
474-
475-
476-
```bash
477-
ddev exec php my-code/crowdsec-php-lib/scripts/standalone-check-ip-live.php 1.2.3.4 <YOUR_BOUNCER_KEY>
478-
```
479-
480-
#### Now ban range 1.2.3.4 to 1.2.3.7 for 12h
481-
482-
```bash
483-
ddev exec -s crowdsec cscli decisions add --range 1.2.3.4/30 --duration 12h --type ban
484-
```
485-
486-
#### Clear cache and get the new remediation
487-
488-
Clear the cache:
489-
490-
```bash
491-
ddev exec php my-code/crowdsec-php-lib/scripts/clear-cache.php <YOUR_BOUNCER_KEY>
492-
```
493-
494-
One more time, get the remediation for the IP "1.2.3.4":
495-
496-
```bash
497-
ddev exec php my-code/crowdsec-php-lib/scripts/standalone-check-ip-live.php 1.2.3.4 <YOUR_BOUNCER_KEY>
498-
```
499-
500-
This is a ban (and cache miss) as you can see in your terminal logs.
501-
502-
503378
## Discover the CrowdSec LAPI
504379

505380
This library interacts with a CrowdSec agent that you have installed on an accessible server.

0 commit comments

Comments
 (0)