Skip to content

Commit 8d41671

Browse files
feat(geolcation): Update docs and modify admin test part
1 parent 5e79548 commit 8d41671

File tree

8 files changed

+95
-7
lines changed

8 files changed

+95
-7
lines changed

docs/USER_GUIDE.md

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ These configurations are divided in three main parts : `CrowdSec`, `Theme custom
6565

6666
#### General settings
6767

68-
In the `CrowdSec` part, you will set your connection details and refine bouncing according to your needs.
68+
In the `CrowdSec` part, you will set your connection details and refine bouncing according to your needs. You will
69+
also be able to test your settings.
6970

7071
![Connection details](images/screenshots/config-connection.jpg)
7172

@@ -98,7 +99,9 @@ If enabled, the admin is not bounced.
9899

99100
***
100101

101-
`Test your settings`
102+
![Setting tests](images/screenshots/config-test-your-settings.jpg)
103+
104+
`Test your settings → Test bouncing`
102105

103106
Click the "Test bouncing" button and the configured bouncer will try to get the remediation (bypass, captcha or ban)
104107
for
@@ -109,6 +112,13 @@ This test allows you to know if your connection, bouncing and cache settings are
109112

110113
***
111114

115+
`Test your settings → Test geolocation`
116+
117+
Click the "Test geolocation" button to try getting country for the IP entered in the text field.
118+
119+
This test allows you to know if your geolocation settings are correct.
120+
121+
112122

113123
#### Theme customization
114124

@@ -124,7 +134,7 @@ In the `Theme customization` part, you can modify texts and colors of ban and ca
124134
#### Advanced settings
125135

126136
In the `Advanced` part, you can enable/disable the stream mode, choose your cache system for your CrowdSec
127-
LAPI, handle your remediation policy and adjust some debug and log parameters.
137+
LAPI, handle your remediation policy, manage geolocation feature, adjust some debug parameters and testing parameters.
128138

129139
![Communication mode](images/screenshots/config-communication-mode.jpg)
130140

@@ -192,6 +202,14 @@ we store in cache some values in order to know if he has to resolve or not the c
192202

193203
Minimum 1 second. Default: 86400 seconds.
194204

205+
***
206+
207+
`Caching configuration → Geolocation cache lifetime`
208+
209+
The lifetime of cached country geolocation result for some IP.
210+
211+
Minimum 1 second. Default: 86400 seconds.
212+
195213

196214
***
197215

@@ -215,6 +233,50 @@ If you use a CDN, a reverse proxy or a load balancer, it is possible to indicate
215233

216234
Enable if you want to hide CrowdSec mentions on the Ban and Captcha walls.
217235

236+
237+
***
238+
239+
![Geolocation](images/screenshots/config-geolocation.jpg)
240+
241+
***
242+
243+
`Geolocation → Enable geolocation feature`
244+
245+
Enable if you want to use also CrowdSec country scoped decisions.
246+
If enabled, bounced IP will be geolocalized and the final remediation will take into account any country related decision.
247+
248+
***
249+
250+
`Geolocation → Geolocation type`
251+
252+
253+
For now, only `Maxmind database` type is allowed
254+
255+
***
256+
257+
`Geolocation → MaxMind database type`
258+
259+
Choose between `Country` and `City`.
260+
261+
262+
***
263+
264+
`Geolocation → Path to the MaxMind database`
265+
266+
Relative path from `wp-content/plugins/cs-wordpress-bouncer/geolocation` folder.
267+
268+
***
269+
270+
`Geolocation → Save geolocalized country in cache`
271+
272+
Enabling this will avoid multiple call to the geolocation system (e.g. MaxMind database)
273+
If enabled, the geolocalized country associated to the IP will be saved in cache.
274+
See the `Geolocation cache lifetime` setting above to set the lifetime of this result.
275+
276+
***
277+
278+
279+
218280
![Debug](images/screenshots/config-debug.jpg)
219281

220282
***
@@ -235,6 +297,27 @@ When this mode is enabled, you will see every unexpected bouncing errors in the
235297
Should be disabled in production.
236298

237299

300+
***
301+
302+
![Test](images/screenshots/config-test.jpg)
303+
304+
***
305+
306+
307+
`Test settings → Forced test IP`
308+
309+
This Ip will be used instead of the current detected browser IP.
310+
**Must be empty in production.**
311+
312+
***
313+
314+
`Test settings → Forced test X-Forwarded-For IP`
315+
316+
This Ip will be used instead of the current X-Forwarded-For Ip if any.
317+
**Must be empty in production.**
318+
319+
320+
238321
### Auto Prepend File mode
239322

240323
By default, this extension will bounce every web requests that pass through the classical process of WordPress core loading.
20.7 KB
Loading
-30.1 KB
Loading
79.9 KB
Loading
34.1 KB
Loading
37.9 KB
Loading

inc/admin/advanced-settings.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,17 @@ function adminAdvancedSettings()
197197
}, ' seconds. <p>The lifetime of cached captcha flow for some IP. <br>If a user has to interact with a captcha wall, we store in cache some values in order to know if he has to resolve or not the captcha again.<br>Minimum 1 second. Default: '.Constants::CACHE_EXPIRATION_FOR_CAPTCHA.'.', Constants::CACHE_EXPIRATION_FOR_CAPTCHA, 'width: 115px;', 'number');
198198

199199
// Field "crowdsec_geolocation_cache_duration"
200-
addFieldString('crowdsec_geolocation_cache_duration', 'Geolocation cache duration', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_cache', function ($input) {
200+
addFieldString('crowdsec_geolocation_cache_duration', 'Geolocation cache lifetime', 'crowdsec_plugin_advanced_settings',
201+
'crowdsec_advanced_settings', 'crowdsec_admin_advanced_cache', function ($input) {
201202
if ( (int) $input <= 0) {
202203
add_settings_error('Geolocation cache duration', 'crowdsec_error', 'Geolocation cache duration: Minimum is 1 second.');
203204

204205
return Constants::CACHE_EXPIRATION_FOR_GEO;
205206
}
206207

207208
return (int) $input > 0 ? (int) $input : Constants::CACHE_EXPIRATION_FOR_CAPTCHA ;
208-
}, ' seconds. <p>The lifetime of cached country geolocation result for some IP.<br>Minimum 1 second. Default: '.Constants::CACHE_EXPIRATION_FOR_GEO.'.', Constants::CACHE_EXPIRATION_FOR_GEO, 'width: 115px;', 'number');
209+
}, ' seconds. <p>The lifetime of cached country geolocation result for some IP.<br>Minimum 1 second. Default: '
210+
.Constants::CACHE_EXPIRATION_FOR_GEO.'.<br>See the <i>Geolocation</i> settings below to enable geolocalized country result save.', Constants::CACHE_EXPIRATION_FOR_GEO, 'width: 115px;', 'number');
209211

210212

211213
/***************************
@@ -327,7 +329,7 @@ function convertInlineIpRangesToComparableIpBounds(string $inlineIpRanges): arra
327329

328330
addFieldCheckbox('crowdsec_geolocation_save_result', 'Save geolocalized country in cache', 'crowdsec_plugin_advanced_settings',
329331
'crowdsec_advanced_settings', 'crowdsec_admin_advanced_geolocation', function () {}, function () {}, '
330-
<p>Enabling this will avoid multiple call to the geolocation system (e.g. MaxMind database)</p> If enabled, the geolocalized country associated to the IP will be saved in cache.<br>See the <i>Geolocation cache duration</i> setting above to set the lifetime of this result.');
332+
<p>Enabling this will avoid multiple call to the geolocation system (e.g. MaxMind database)</p> If enabled, the geolocalized country associated to the IP will be saved in cache.<br>See the <i>Geolocation cache lifetime</i> setting above to set the lifetime of this result.');
331333

332334

333335
/*******************************
@@ -368,7 +370,7 @@ function convertInlineIpRangesToComparableIpBounds(string $inlineIpRanges): arra
368370
}, '<p>This Ip will be used instead of the current detected browser IP: '.$_SERVER['REMOTE_ADDR'].'.<br><strong>Must be empty in production.</strong></p>',
369371
'1.2.3.4', '');
370372

371-
addFieldString('crowdsec_forced_test_forwarded_ip', 'Forced test X-Forwrded-For IP', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_test', function ($input) {
373+
addFieldString('crowdsec_forced_test_forwarded_ip', 'Forced test X-Forwarded-For IP', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_test', function ($input) {
372374
return $input;
373375
}, '<p>This Ip will be used instead of the current X-Forwarded-For Ip if any.<br><strong>Must be empty in production.</strong></p>',
374376
'1.2.3.4', '');

inc/admin/init.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ function testBouncerConnexionInAdminPage($ip)
128128
function testGeolocationInAdminPage($ip)
129129
{
130130
try {
131+
if (!get_option('crowdsec_geolocation_maxmind_database_path')) {
132+
throw new BouncerException("Maxmind database path can not be empty");
133+
}
131134
$settings = getDatabaseSettings();
132135
$bouncer = getBouncerInstance($settings);
133136
$geolocationConfig = $settings['geolocation'];

0 commit comments

Comments
 (0)