@@ -66,11 +66,16 @@ For a quick start, follow the below steps.
66
66
67
67
#### DDEV installation
68
68
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
+ ```
74
79
75
80
76
81
#### Prepare DDEV PHP environment
@@ -165,6 +170,27 @@ Run:
165
170
ddev composer update --working-dir ./my-own-modules/crowdsec-php-lib
166
171
```
167
172
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
+
168
194
#### Unit test
169
195
170
196
First, 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
201
227
#### Auto-prepend mode (standalone mode)
202
228
203
229
Before 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.
206
232
207
233
208
234
Then, 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
210
236
following command from the ` .ddev ` folder:
211
237
212
238
``` bash
@@ -219,7 +245,7 @@ be bounce.
219
245
For example, you should try to browse the following url:
220
246
221
247
```
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
223
249
```
224
250
225
251
#### End-to-end tests
@@ -304,7 +330,7 @@ ddev phpcbf ./my-own-modules/crowdsec-php-lib/vendor/bin/phpcs my-own-modules/cr
304
330
305
331
We use a post-start DDEV hook to:
306
332
- 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
308
334
standalone mode).
309
335
- Create a watcher that we use in end-to-end tests
310
336
@@ -323,25 +349,25 @@ ddev restart
323
349
> - the cap remediation level
324
350
> - how to get the logged events
325
351
326
- You will find some php scripts in the ` examples ` folder.
352
+ You will find some php scripts in the ` scripts ` folder.
327
353
328
354
** N.B** : If you are not using DDEV, you can replace all ` ddev exec php ` by ` php ` and specify the right script paths.
329
355
330
356
### Check IP script
331
357
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.
333
359
334
360
To run this script, you have to know your bouncer key ` <BOUNCER_KEY> ` and run
335
361
``` 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>
337
363
```
338
364
339
365
As a reminder, your bouncer key is returned by the ` ddev create-bouncer ` command.
340
366
341
367
For example, run the php script:
342
368
343
369
``` 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>
345
371
```
346
372
347
373
As 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
355
381
Now, if you run the php script against the ` 1.2.3.4 ` IP:
356
382
357
383
``` 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>
359
385
```
360
386
361
387
LAPI will advise you to ban this IP as it's within the 1.2.3.4/30 range.
@@ -380,7 +406,7 @@ $bouncer->configure([
380
406
Now if you call one more time:
381
407
382
408
``` 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>
384
410
```
385
411
386
412
The library will cap the value to ` captcha ` level.
@@ -443,24 +469,24 @@ $cacheAdapter = new MemcachedAdapter(MemcachedAdapter::createConnection('memcach
443
469
You will still be able to verify IPs, but the cache system will be more efficient.
444
470
445
471
``` 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>
447
473
```
448
474
449
475
> 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 ) .
450
476
451
477
### Clear cache script
452
478
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:
454
480
455
481
``` 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>
457
483
```
458
484
459
485
### Full Live mode example
460
486
461
487
This example demonstrates how the PHP Lib works with cache when you are using the live mode.
462
488
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 ) .
464
490
465
491
#### Set up the context
466
492
@@ -482,7 +508,7 @@ Try with the `full-example-live-mode.php` file:
482
508
483
509
484
510
` ` ` 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
486
512
` ` `
487
513
488
514
# ### 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
491
517
You can this behaviour by testing with a bad LAPI url.
492
518
493
519
` ` ` 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
495
521
` ` `
496
522
497
523
As 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
507
533
Clear the cache:
508
534
509
535
` ` ` 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>
511
537
` ` `
512
538
513
539
One more time, get the remediation for the IP " 1.2.3.4" :
514
540
515
541
` ` ` 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
517
543
` ` `
518
544
519
545
This is a ban (and cache miss) as you can see in your terminal logs.
0 commit comments