Skip to content

Commit f334b05

Browse files
Merge pull request #125 from julienloizelet/fix/memcached-test-connection
Fix/memcached test connection
2 parents de6e917 + e195ad9 commit f334b05

Some content is hidden

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

41 files changed

+781
-593
lines changed

.distignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
/vendor/crowdsec/bouncer/phpstan.neon
2222
/vendor/crowdsec/bouncer/.github
2323
/vendor/crowdsec/.bouncer-key
24-
.gitignore
2524
.composer.json
2625
.composer.lock
2726
*.sh
@@ -31,6 +30,5 @@ CHANGELOG.md
3130
composer.json
3231
composer.lock
3332
/logs/**
34-
**/*Test.php
3533
.distignore
3634
.gitignore

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77

8+
## [2.0.1](https://github.com/crowdsecurity/cs-wordpress-bouncer/releases/tag/v2.0.1) - 2023-02-14
9+
[_Compare with previous release_](https://github.com/crowdsecurity/cs-wordpress-bouncer/compare/v2.0.0...v2.0.1)
10+
11+
### Fixed
12+
- Fix missing `TwigTest.php` in release zip that broke captcha and ban walls
13+
- Fix bad memcached dsn check
14+
- Fix clean and bad ip resync values when disabling stream mode
15+
16+
17+
---
18+
819
## [2.0.0](https://github.com/crowdsecurity/cs-wordpress-bouncer/releases/tag/v2.0.0) - 2023-02-09
920
[_Compare with previous release_](https://github.com/crowdsecurity/cs-wordpress-bouncer/compare/v1.11.0...v2.0.0)
1021

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020
},
2121
"require": {
22-
"crowdsec/bouncer": "^1.0.0",
22+
"crowdsec/bouncer": "^1.0.1",
2323
"symfony/polyfill-mbstring": "1.20.0",
2424
"symfony/service-contracts": "2.4.1"
2525
},

composer.lock

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crowdsec.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Plugin URI: https://github.com/crowdsecurity/cs-wordpress-bouncer
55
* Description: Safer Together. Protect your WordPress application with CrowdSec.
66
* Tags: crowdsec-bouncer, wordpress, security, firewall, captcha, ip-scanner, ip-blocker, ip-blocking, ip-address, ip-database, ip-range-check, crowdsec, ban-hosts, ban-management, anti-hacking, hacker-protection, captcha-image, captcha-generator, captcha-generation, captcha-service
7-
* Version: 2.0.0
7+
* Version: 2.0.1
88
* Author: CrowdSec
99
* Author URI: https://www.crowdsec.net/
1010
* Github: https://github.com/crowdsecurity/cs-wordpress-bouncer
@@ -13,7 +13,7 @@
1313
* Requires PHP: 7.2
1414
* Requires at least: 4.9
1515
* Tested up to: 6.1
16-
* Stable tag: 2.0.0
16+
* Stable tag: 2.0.1
1717
* Text Domain: crowdsec-wp
1818
* First release: 2021.
1919
*/

inc/Constants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Constants extends LibConstants
2020
public const LOG_BASE_PATH = __DIR__ . '/../logs/';
2121
public const CACHE_PATH = __DIR__ . '/../.cache';
2222
public const CONFIG_PATH = __DIR__ . '/standalone-settings.php';
23-
public const VERSION = 'v2.0.0';
23+
public const VERSION = 'v2.0.1';
2424
public const GEOLOCATION_DIR = __DIR__ . '/../geolocation';
2525
public const TLS_DIR = __DIR__ . '/../tls';
2626
}

inc/admin/advanced-settings.php

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ function adminAdvancedSettings()
2323
$bouncer = new Bouncer($configs);
2424
$bouncer->clearCache();
2525
$refresh = $bouncer->refreshBlocklistCache();
26-
$result = $refresh['new']??0;
27-
$message = __('As the stream mode is enabled, the cache has just been refreshed, '.($result > 1 ? 'there are now '.$result.' decisions' : 'there is now '.$result.' decision').' in cache.');
26+
$new = $refresh['new']??0;
27+
$deleted = $refresh['deleted']??0;
28+
$message = __('As the stream mode is enabled, the cache has just been refreshed. New decision(s): '.$new.'. Deleted decision(s): '. $deleted);
2829
AdminNotice::displaySuccess($message);
2930
scheduleBlocklistRefresh();
3031
}, function () {
@@ -54,11 +55,9 @@ function adminAdvancedSettings()
5455
$bouncer = new Bouncer($configs);
5556
$bouncer->clearCache();
5657
$refresh = $bouncer->refreshBlocklistCache();
57-
$result = $refresh['new']??0;
58-
$message = __('As the stream mode refresh duration changed, the cache has just been refreshed, ' .
59-
($result > 1 ? 'there are now '.$result.' decisions' : 'there is now '.$result.' decision')
60-
. ' in cache.'
61-
);
58+
$new = $refresh['new']??0;
59+
$deleted = $refresh['deleted']??0;
60+
$message = __('As the stream mode refresh duration changed, the cache has just been refreshed. New decision(s): '.$new.'. Deleted decision(s): '. $deleted);
6261
AdminNotice::displaySuccess($message);
6362
scheduleBlocklistRefresh();
6463
}
@@ -170,8 +169,9 @@ function adminAdvancedSettings()
170169
// system
171170
$bouncer->clearCache();
172171
$result = $bouncer->refreshBlocklistCache();
173-
$count = $result['new'];
174-
$message .= __('As the stream mode is enabled, the cache has just been refreshed, '.($count > 1 ? 'there are now '.$count.' decisions' : 'there is now '.$count.' decision').' in cache.');
172+
$new = $result['new']??0;
173+
$deleted = $result['deleted']??0;
174+
$message = __('As the stream mode is enabled, the cache has just been refreshed. New decision(s): '.$new.'. Deleted decision(s): '. $deleted);
175175
AdminNotice::displaySuccess($message);
176176
scheduleBlocklistRefresh();
177177
}
@@ -190,24 +190,34 @@ function adminAdvancedSettings()
190190

191191
// Field "crowdsec_clean_ip_cache_duration"
192192
addFieldString('crowdsec_clean_ip_cache_duration', 'Recheck clean IPs each<br>(live mode only)', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_cache', function ($input) {
193-
if (!get_option('crowdsec_stream_mode') && (int) $input <= 0) {
194-
add_settings_error('Recheck clean IPs each', 'crowdsec_error', 'Recheck clean IPs each: Minimum is 1 second.');
193+
if(!empty($input)){
194+
if (!get_option('crowdsec_stream_mode') && (int) $input <= 0) {
195+
add_settings_error('Recheck clean IPs each', 'crowdsec_error', 'Recheck clean IPs each: Minimum is 1 second.');
195196

196-
return '1';
197+
return '1';
198+
}
199+
200+
return (int) $input > 0 ? (int) $input : 1 ;
197201
}
202+
$saved = (int) get_option('crowdsec_clean_ip_cache_duration');
203+
return $saved > 0 ? $saved : 1;
198204

199-
return (int) $input > 0 ? (int) $input : 1 ;
200205
}, ' seconds. <p>The duration between re-asking Local API about an already checked clean IP.<br>Minimum 1 second.<br> Note that this setting can not be apply in stream mode.', '...', 'width: 115px;', 'number', (bool) get_option('crowdsec_stream_mode'));
201206

202207
// Field "crowdsec_bad_ip_cache_duration"
203208
addFieldString('crowdsec_bad_ip_cache_duration', 'Recheck bad IPs each<br>(live mode only)', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_cache', function ($input) {
204-
if (!get_option('crowdsec_stream_mode') && (int) $input <= 0) {
205-
add_settings_error('Recheck bad IPs each', 'crowdsec_error', 'Recheck bad IPs each: Minimum is 1 second.');
209+
if(!empty($input)) {
210+
if (!get_option('crowdsec_stream_mode') && !empty($input) && (int)$input <= 0) {
211+
add_settings_error('Recheck bad IPs each', 'crowdsec_error', 'Recheck bad IPs each: Minimum is 1 second.');
212+
213+
return '1';
214+
}
206215

207-
return '1';
216+
return (int)$input > 0 ? (int)$input : 1;
208217
}
218+
$saved = (int) get_option('crowdsec_bad_ip_cache_duration');
219+
return $saved > 0 ? $saved : 1;
209220

210-
return (int) $input > 0 ? (int) $input : 1 ;
211221
}, ' seconds. <p>The duration between re-asking Local API about an already checked bad IP.<br>Minimum 1 second.<br> Note that this setting can not be apply in stream mode.', '...', 'width: 115px;', 'number', (bool) get_option('crowdsec_stream_mode'));
212222

213223
// Field "crowdsec_captcha_cache_duration"
@@ -350,7 +360,7 @@ function convertInlineIpRangesToComparableIpBounds(string $inlineIpRanges): arra
350360
return Constants::CACHE_EXPIRATION_FOR_GEO;
351361
}
352362

353-
return (int) $input >= 0 ? (int) $input : Constants::CACHE_EXPIRATION_FOR_CAPTCHA ;
363+
return (int) $input;
354364
}, ' seconds. <p>The lifetime of cached country geolocation result for some IP.<br>Default: '
355365
.Constants::CACHE_EXPIRATION_FOR_GEO.'.<br>Set 0 to disable caching', Constants::CACHE_EXPIRATION_FOR_GEO,
356366
'width: 115px;', 'number');

inc/admin/init.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ function clearBouncerCacheInAdminPage()
4545
// In stream mode, immediatelly warm the cache up.
4646
if (get_option('crowdsec_stream_mode')) {
4747
$refresh = $bouncer->refreshBlocklistCache();
48-
$result = $refresh['new']??0;
49-
$message .= __(' As the stream mode is enabled, the cache has just been refreshed, '.($result > 1 ? 'there are now '.$result.' decisions' : 'there is now '.$result.' decision').' in cache.');
48+
$new = $refresh['new']??0;
49+
$deleted = $refresh['deleted']??0;
50+
$message .= __(' As the stream mode is enabled, the cache has just been refreshed. New decision(s): '.$new.'. Deleted decision(s): '. $deleted);
5051
}
5152

5253
AdminNotice::displaySuccess($message);
@@ -77,7 +78,10 @@ function refreshBouncerCacheInAdminPage()
7778
$configs = getDatabaseConfigs();
7879
$bouncer = new Bouncer($configs);
7980
$result = $bouncer->refreshBlocklistCache();
80-
AdminNotice::displaySuccess(__(' The cache has just been refreshed ('.($result['new'] > 0 ? $result['new'].' new decisions' : $result['new'].' new decision').', '.$result['deleted'].' deleted).'));
81+
$new = $result['new']??0;
82+
$deleted = $result['deleted']??0;
83+
$message = __('The cache has just been refreshed. New decision(s): '.$new.'. Deleted decision(s): '. $deleted);
84+
AdminNotice::displaySuccess($message);
8185
}
8286
} catch (BouncerException $e) {
8387
if(isset($bouncer) && $bouncer->getLogger()) {

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Donate link: https://crowdsec.net/
44
Tags: crowdsec-bouncer, wordpress, security, firewall, captcha, ip-scanner, ip-blocker, ip-blocking, ip-address, ip-database, ip-range-check, crowdsec, ban-hosts, ban-management, anti-hacking, hacker-protection, captcha-image, captcha-generator, captcha-generation, captcha-service
55
Requires at least: 4.9
66
Tested up to: 6.1
7-
Stable tag: 2.0.0
7+
Stable tag: 2.0.1
88
Requires PHP: 7.2
99
License: MIT
1010
License URI: https://opensource.org/licenses/MIT

0 commit comments

Comments
 (0)