@@ -66,11 +66,16 @@ For a quick start, follow the below steps.
6666
6767#### DDEV installation
6868
69- Please follow the [ official instructions] ( https://ddev.readthedocs.io/en/stable/#installation ) . On a Linux
70- distribution, this should be as simple as
71-
72- sudo apt-get install linuxbrew-wrapper
73- brew tap drud/ddev && brew install ddev
69+ This project is fully compatible with DDEV 1.18.2 and it is recommended to use this specific version.
70+ For the DDEV installation, please follow the [ official instructions] ( https://ddev.readthedocs.io/en/stable/#installation ) .
71+ On a Linux distribution, you can run:
72+ ```
73+ sudo apt-get -qq update
74+ sudo apt-get -qq -y install libnss3-tools
75+ curl -LO https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh
76+ bash install_ddev.sh v1.18.2
77+ rm install_ddev.sh
78+ ```
7479
7580
7681#### Prepare DDEV PHP environment
@@ -165,6 +170,27 @@ Run:
165170ddev composer update --working-dir ./my-own-modules/crowdsec-php-lib
166171```
167172
173+ #### Find IP of your docker services
174+
175+ In most cases, you will test to bounce your current IP. As we are running on a docker stack, this is the local host IP.
176+
177+ To find it, just run:
178+
179+ ```
180+ ddev find-ip
181+ ```
182+
183+ You will have to know also the IP of the ` ddev-router ` container as it acts as a proxy, and you should set it in the
184+ ` trust_ip_forward_array ` setting.
185+
186+ To find this IP, just run:
187+
188+ ```
189+ ddev find-ip ddev-router
190+ ```
191+
192+
193+
168194#### Unit test
169195
170196First, create a bouncer and keep the result key.
@@ -201,12 +227,12 @@ ddev exec BOUNCER_KEY=your-bouncer-key LAPI_URL=http://crowdsec:8080 /usr/bin/p
201227#### Auto-prepend mode (standalone mode)
202228
203229Before using the bouncer in a standalone mode (i.e. with an auto-prepend directive), you should copy the
204- ` examples /auto-prepend/settings.example.php` file to a ` examples /auto-prepend/settings.php ` and edit it depending on
205- your needs.
230+ [ ` scripts /auto-prepend/settings.example.php` ] ( ../scripts/auto-prepend/settings.example.php ) file to a `scripts /auto-prepend/settings.
231+ php` and edit it depending on your needs.
206232
207233
208234Then, to configure the Nginx service in order that it uses an auto-prepend directive pointing to the
209- ` examples /auto-prepend/scripts/bounce-via- auto-prepend.php` script, please run the
235+ [ ` scripts /auto-prepend/bounce.php ` ] ( ../ scripts/auto-prepend/bounce .php) script, please run the
210236following command from the ` .ddev ` folder:
211237
212238``` bash
@@ -219,7 +245,7 @@ be bounce.
219245For example, you should try to browse the following url:
220246
221247```
222- https://phpXX.ddev.site/my-own-modules/crowdsec-php-lib/examples/auto-prepend /public/protected-page.php
248+ https://phpXX.ddev.site/my-own-modules/crowdsec-php-lib/scripts /public/protected-page.php
223249```
224250
225251#### End-to-end tests
@@ -304,7 +330,7 @@ ddev phpcbf ./my-own-modules/crowdsec-php-lib/vendor/bin/phpcs my-own-modules/cr
304330
305331We use a post-start DDEV hook to:
306332- Create a bouncer
307- - Set bouncer key, api url and other needed values in the ` examples /auto-prepend/settings.php` file (useful to test
333+ - Set bouncer key, api url and other needed values in the ` scripts /auto-prepend/settings.php` file (useful to test
308334 standalone mode).
309335- Create a watcher that we use in end-to-end tests
310336
@@ -323,25 +349,25 @@ ddev restart
323349> - the cap remediation level
324350> - how to get the logged events
325351
326- You will find some php scripts in the ` examples ` folder.
352+ You will find some php scripts in the ` scripts ` folder.
327353
328354** N.B** : If you are not using DDEV, you can replace all ` ddev exec php ` by ` php ` and specify the right script paths.
329355
330356### Check IP script
331357
332- The ` check-ip ` script will get the remediation (` bypass ` , ` captcha ` or ` ban ` ) for some IP.
358+ The [ ` check-ip ` ] ( ../scripts/check-ip.php ) script will get the remediation (` bypass ` , ` captcha ` or ` ban ` ) for some IP.
333359
334360To run this script, you have to know your bouncer key ` <BOUNCER_KEY> ` and run
335361``` bash
336- ddev exec php my-own-modules/crowdsec-php-lib/examples /check-ip.php < IP> < BOUNCER_KEY>
362+ ddev exec php my-own-modules/crowdsec-php-lib/scripts /check-ip.php < IP> < BOUNCER_KEY>
337363```
338364
339365As a reminder, your bouncer key is returned by the ` ddev create-bouncer ` command.
340366
341367For example, run the php script:
342368
343369``` bash
344- ddev exec php my-own-modules/crowdsec-php-lib/examples /check-ip.php 1.2.3.4 < BOUNCER_KEY>
370+ ddev exec php my-own-modules/crowdsec-php-lib/scripts /check-ip.php 1.2.3.4 < BOUNCER_KEY>
345371```
346372
347373As your CrowdSec instance contains no decisions, you received the result "bypass".
@@ -355,7 +381,7 @@ ddev exec -s crowdsec cscli decisions add --range 1.2.3.4/30 --duration 4h --typ
355381Now, if you run the php script against the ` 1.2.3.4 ` IP:
356382
357383``` bash
358- ddev exec php my-own-modules/crowdsec-php-lib/examples /check-ip.php 1.2.3.4 < BOUNCER_KEY>
384+ ddev exec php my-own-modules/crowdsec-php-lib/scripts /check-ip.php 1.2.3.4 < BOUNCER_KEY>
359385```
360386
361387LAPI will advise you to ban this IP as it's within the 1.2.3.4/30 range.
@@ -380,7 +406,7 @@ $bouncer->configure([
380406Now if you call one more time:
381407
382408``` bash
383- ddev exec php my-own-modules/crowdsec-php-lib/examples /check-ip.php 1.2.3.4 < BOUNCER_KEY>
409+ ddev exec php my-own-modules/crowdsec-php-lib/scripts /check-ip.php 1.2.3.4 < BOUNCER_KEY>
384410```
385411
386412The library will cap the value to ` captcha ` level.
@@ -443,24 +469,24 @@ $cacheAdapter = new MemcachedAdapter(MemcachedAdapter::createConnection('memcach
443469You will still be able to verify IPs, but the cache system will be more efficient.
444470
445471``` bash
446- ddev exec php my-own-modules/crowdsec-php-lib/examples /check-ip.php 1.2.3.4 < BOUNCER_KEY>
472+ ddev exec php my-own-modules/crowdsec-php-lib/scripts /check-ip.php 1.2.3.4 < BOUNCER_KEY>
447473```
448474
449475> Note: You can try more cache systems but we did not test them for now (Apcu, Filesystem, Doctrine, Couchbase, Pdo). The [ full list is here] ( https://symfony.com/doc/current/components/cache.html#available-cache-adapters ) .
450476
451477### Clear cache script
452478
453- To clear your LAPI cache, you can use the ` clear-php ` script:
479+ To clear your LAPI cache, you can use the [ ` clear-php ` ] ( ../scripts/clear-cache.php ) script:
454480
455481``` bash
456- ddev exec php my-own-modules/crowdsec-php-lib/examples /clear-cache.php < BOUNCER_KEY>
482+ ddev exec php my-own-modules/crowdsec-php-lib/scripts /clear-cache.php < BOUNCER_KEY>
457483```
458484
459485### Full Live mode example
460486
461487This example demonstrates how the PHP Lib works with cache when you are using the live mode.
462488
463- Let's get started and follow the guide!
489+ We will use here the [ ` full-example-live-mode.php ` ] ( ../scripts/full-example-live-mode.php ) .
464490
465491#### Set up the context
466492
@@ -482,7 +508,7 @@ Try with the `full-example-live-mode.php` file:
482508
483509
484510` ` ` bash
485- ddev exec php my-own-modules/crowdsec-php-lib/examples/live-mode /full-example-live-mode.php < YOUR_BOUNCER_KEY> 1.2.3.4 http://crowdsec:8080
511+ ddev exec php my-own-modules/crowdsec-php-lib/scripts /full-example-live-mode.php < YOUR_BOUNCER_KEY> 1.2.3.4 http://crowdsec:8080
486512` ` `
487513
488514# ### Simulate LAPI down by using a bad url
@@ -491,7 +517,7 @@ If you run this script twice, LAPI will not be called, the cache system will rel
491517You can this behaviour by testing with a bad LAPI url.
492518
493519` ` ` bash
494- ddev exec php my-own-modules/crowdsec-php-lib/examples/live-mode /full-example-live-mode.php < YOUR_BOUNCER_KEY> 1.2.3.4 http://crowdsec:BAD
520+ ddev exec php my-own-modules/crowdsec-php-lib/scripts /full-example-live-mode.php < YOUR_BOUNCER_KEY> 1.2.3.4 http://crowdsec:BAD
495521` ` `
496522
497523As you can see, you can check the API event if LAPI is down. This is because of the caching system.
@@ -507,13 +533,13 @@ ddev exec -s crowdsec cscli decisions add --range 1.2.3.4/30 --duration 12h --ty
507533Clear the cache:
508534
509535` ` ` bash
510- ddev exec php my-own-modules/crowdsec-php-lib/examples /clear-cache.php < YOUR_BOUNCER_KEY>
536+ ddev exec php my-own-modules/crowdsec-php-lib/scripts /clear-cache.php < YOUR_BOUNCER_KEY>
511537` ` `
512538
513539One more time, get the remediation for the IP " 1.2.3.4" :
514540
515541` ` ` bash
516- ddev exec php my-own-modules/crowdsec-php-lib/examples/live-mode /full-example-live-mode.php < YOUR_BOUNCER_KEY> 1.2.3.4 http://crowdsec:8080
542+ ddev exec php my-own-modules/crowdsec-php-lib/scripts /full-example-live-mode.php < YOUR_BOUNCER_KEY> 1.2.3.4 http://crowdsec:8080
517543` ` `
518544
519545This is a ban (and cache miss) as you can see in your terminal logs.
0 commit comments