Skip to content

Commit b9e98b1

Browse files
feat(geolocation): Handle cache key for different scopes (Ip and country)
1 parent 58cb9a1 commit b9e98b1

12 files changed

+426
-81
lines changed

docs/ddev.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,32 @@ and:
258258

259259
```
260260
ddev phpcbf ./my-own-modules/crowdsec-php-lib/vendor/bin/phpcs my-own-modules/crowdsec-php-lib/src
261-
```
261+
```
262+
263+
264+
### Auto prepend mode
265+
266+
Before using the bouncer in a standalone mode (i.e. with an auto-prepend directive), you should copy the
267+
`examples/auto-prepend/settings.example.php` file to a `examples/auto-prepend/settings.php` and edit it depending on
268+
your needs.
269+
270+
And you need also to have functional php website sources under your `php-project-sources` folder. For a quick test,
271+
you could just create a `php-project-sources/index.php` with the following content;
272+
```php
273+
<?php
274+
275+
echo "This is HOMEPAGE";
276+
```
277+
278+
Then, to configure the Nginx service in order that it uses an auto-prepend directive pointing to the
279+
`examples/auto-prepend/scripts/bounce-via-auto-prepend.php` script, please run the
280+
following command from the `.ddev` folder:
281+
282+
```
283+
ddev crowdsec-prepend-nginx
284+
285+
```
286+
287+
288+
With that done, every access to your ddev url (i.e. `https://phpXX.ddev.site` where `XX` is your php version) will
289+
be bounce

examples/auto-prepend/scripts/bounce-via-auto-prepend.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
use CrowdSecBouncer\StandAloneBounce;
77

88
$bounce = new StandAloneBounce();
9-
$bounce->setDebug($crowdSecStandaloneBouncerConfig['debug_mode']);
10-
$bounce->setDisplayErrors($crowdSecStandaloneBouncerConfig['display_errors']);
9+
10+
$bounce->setDebug($crowdSecStandaloneBouncerConfig['debug_mode']??false);
11+
$bounce->setDisplayErrors($crowdSecStandaloneBouncerConfig['display_errors'] ?? false);
1112
$bounce->init($crowdSecStandaloneBouncerConfig);
1213
$bounce->safelyBounce();

examples/auto-prepend/scripts/cron-refresh-decisions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use CrowdSecBouncer\StandAloneBounce;
77

88
$bounce = new StandAloneBounce();
9+
$bounce->setDebug($crowdSecStandaloneBouncerConfig['debug_mode']??false);
10+
$bounce->setDisplayErrors($crowdSecStandaloneBouncerConfig['display_errors'] ?? false);
911
$bounce->init($crowdSecStandaloneBouncerConfig);
1012
$bouncer = $bounce->getBouncerInstance();
1113
$bouncer->refreshBlocklistCache();

examples/auto-prepend/settings.example.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
$crowdSecStandaloneBouncerConfig = [
66
'api_url' => 'http://url-to-your-lapi:8080', // [FILL ME] Set the LAPI URL here. Example in the docker-compose dev context, use http://crowdsec:8080
77
'api_key' => '...', // [FILL ME] Set a bouncer key here
8-
'debug_mode' => false, // [FILL ME] Set to true to stop the process and display errors if any
8+
'debug_mode' => false, // [FILL ME] Set to true to enable debug log
9+
'display_errors' => false, // [FILL ME] Set to true to stop the process and display errors if any
910
'log_directory_path' => __DIR__.'/.logs', // [FILL ME] Important note: be sur this path won't be publicly accessible!
1011
'fs_cache_path' => __DIR__.'/.cache', // [FILL ME] Important note: be sur this path won't be publicly accessible!
1112

@@ -48,4 +49,15 @@
4849
'theme_text_ban_wall_subtitle' => 'This page is protected against cyber attacks and your IP has been banned by our system.',
4950
'theme_text_ban_wall_footer' => '',
5051
'theme_custom_css' => '',
52+
53+
'geolocation' => [
54+
'save_in_session' => true, // Set to true to avoid multiple call to the geolocation database
55+
'test_public_ip' => '210.249.74.42', // Only if you test on a local network (docker, etc.)
56+
'enabled' => true, // Set to true if you want to geo-localize IP
57+
'type' => 'maxmind', // At this moment, only 'maxmind' type is available
58+
'maxmind' => [ // MaxMind settings
59+
'database_type' => 'city', // You can set 'city' or 'country'
60+
'database_path' => '/var/www/html/GeoLite2-City.mmdb' // Absolute path to the MaxMind database
61+
]
62+
]
5163
];

0 commit comments

Comments
 (0)