Skip to content

Commit

Permalink
Merge pull request #125 from julienloizelet/fix/memcached-test-connec…
Browse files Browse the repository at this point in the history
…tion

Fix/memcached test connection
  • Loading branch information
julienloizelet authored Feb 14, 2023
2 parents de6e917 + e195ad9 commit f334b05
Show file tree
Hide file tree
Showing 41 changed files with 781 additions and 593 deletions.
2 changes: 0 additions & 2 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
/vendor/crowdsec/bouncer/phpstan.neon
/vendor/crowdsec/bouncer/.github
/vendor/crowdsec/.bouncer-key
.gitignore
.composer.json
.composer.lock
*.sh
Expand All @@ -31,6 +30,5 @@ CHANGELOG.md
composer.json
composer.lock
/logs/**
**/*Test.php
.distignore
.gitignore
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [2.0.1](https://github.com/crowdsecurity/cs-wordpress-bouncer/releases/tag/v2.0.1) - 2023-02-14
[_Compare with previous release_](https://github.com/crowdsecurity/cs-wordpress-bouncer/compare/v2.0.0...v2.0.1)

### Fixed
- Fix missing `TwigTest.php` in release zip that broke captcha and ban walls
- Fix bad memcached dsn check
- Fix clean and bad ip resync values when disabling stream mode


---

## [2.0.0](https://github.com/crowdsecurity/cs-wordpress-bouncer/releases/tag/v2.0.0) - 2023-02-09
[_Compare with previous release_](https://github.com/crowdsecurity/cs-wordpress-bouncer/compare/v1.11.0...v2.0.0)

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
},
"require": {
"crowdsec/bouncer": "^1.0.0",
"crowdsec/bouncer": "^1.0.1",
"symfony/polyfill-mbstring": "1.20.0",
"symfony/service-contracts": "2.4.1"
},
Expand Down
52 changes: 26 additions & 26 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crowdsec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin URI: https://github.com/crowdsecurity/cs-wordpress-bouncer
* Description: Safer Together. Protect your WordPress application with CrowdSec.
* 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
* Version: 2.0.0
* Version: 2.0.1
* Author: CrowdSec
* Author URI: https://www.crowdsec.net/
* Github: https://github.com/crowdsecurity/cs-wordpress-bouncer
Expand All @@ -13,7 +13,7 @@
* Requires PHP: 7.2
* Requires at least: 4.9
* Tested up to: 6.1
* Stable tag: 2.0.0
* Stable tag: 2.0.1
* Text Domain: crowdsec-wp
* First release: 2021.
*/
Expand Down
2 changes: 1 addition & 1 deletion inc/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Constants extends LibConstants
public const LOG_BASE_PATH = __DIR__ . '/../logs/';
public const CACHE_PATH = __DIR__ . '/../.cache';
public const CONFIG_PATH = __DIR__ . '/standalone-settings.php';
public const VERSION = 'v2.0.0';
public const VERSION = 'v2.0.1';
public const GEOLOCATION_DIR = __DIR__ . '/../geolocation';
public const TLS_DIR = __DIR__ . '/../tls';
}
46 changes: 28 additions & 18 deletions inc/admin/advanced-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ function adminAdvancedSettings()
$bouncer = new Bouncer($configs);
$bouncer->clearCache();
$refresh = $bouncer->refreshBlocklistCache();
$result = $refresh['new']??0;
$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.');
$new = $refresh['new']??0;
$deleted = $refresh['deleted']??0;
$message = __('As the stream mode is enabled, the cache has just been refreshed. New decision(s): '.$new.'. Deleted decision(s): '. $deleted);
AdminNotice::displaySuccess($message);
scheduleBlocklistRefresh();
}, function () {
Expand Down Expand Up @@ -54,11 +55,9 @@ function adminAdvancedSettings()
$bouncer = new Bouncer($configs);
$bouncer->clearCache();
$refresh = $bouncer->refreshBlocklistCache();
$result = $refresh['new']??0;
$message = __('As the stream mode refresh duration changed, the cache has just been refreshed, ' .
($result > 1 ? 'there are now '.$result.' decisions' : 'there is now '.$result.' decision')
. ' in cache.'
);
$new = $refresh['new']??0;
$deleted = $refresh['deleted']??0;
$message = __('As the stream mode refresh duration changed, the cache has just been refreshed. New decision(s): '.$new.'. Deleted decision(s): '. $deleted);
AdminNotice::displaySuccess($message);
scheduleBlocklistRefresh();
}
Expand Down Expand Up @@ -170,8 +169,9 @@ function adminAdvancedSettings()
// system
$bouncer->clearCache();
$result = $bouncer->refreshBlocklistCache();
$count = $result['new'];
$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.');
$new = $result['new']??0;
$deleted = $result['deleted']??0;
$message = __('As the stream mode is enabled, the cache has just been refreshed. New decision(s): '.$new.'. Deleted decision(s): '. $deleted);
AdminNotice::displaySuccess($message);
scheduleBlocklistRefresh();
}
Expand All @@ -190,24 +190,34 @@ function adminAdvancedSettings()

// Field "crowdsec_clean_ip_cache_duration"
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) {
if (!get_option('crowdsec_stream_mode') && (int) $input <= 0) {
add_settings_error('Recheck clean IPs each', 'crowdsec_error', 'Recheck clean IPs each: Minimum is 1 second.');
if(!empty($input)){
if (!get_option('crowdsec_stream_mode') && (int) $input <= 0) {
add_settings_error('Recheck clean IPs each', 'crowdsec_error', 'Recheck clean IPs each: Minimum is 1 second.');

return '1';
return '1';
}

return (int) $input > 0 ? (int) $input : 1 ;
}
$saved = (int) get_option('crowdsec_clean_ip_cache_duration');
return $saved > 0 ? $saved : 1;

return (int) $input > 0 ? (int) $input : 1 ;
}, ' 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'));

// Field "crowdsec_bad_ip_cache_duration"
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) {
if (!get_option('crowdsec_stream_mode') && (int) $input <= 0) {
add_settings_error('Recheck bad IPs each', 'crowdsec_error', 'Recheck bad IPs each: Minimum is 1 second.');
if(!empty($input)) {
if (!get_option('crowdsec_stream_mode') && !empty($input) && (int)$input <= 0) {
add_settings_error('Recheck bad IPs each', 'crowdsec_error', 'Recheck bad IPs each: Minimum is 1 second.');

return '1';
}

return '1';
return (int)$input > 0 ? (int)$input : 1;
}
$saved = (int) get_option('crowdsec_bad_ip_cache_duration');
return $saved > 0 ? $saved : 1;

return (int) $input > 0 ? (int) $input : 1 ;
}, ' 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'));

// Field "crowdsec_captcha_cache_duration"
Expand Down Expand Up @@ -350,7 +360,7 @@ function convertInlineIpRangesToComparableIpBounds(string $inlineIpRanges): arra
return Constants::CACHE_EXPIRATION_FOR_GEO;
}

return (int) $input >= 0 ? (int) $input : Constants::CACHE_EXPIRATION_FOR_CAPTCHA ;
return (int) $input;
}, ' seconds. <p>The lifetime of cached country geolocation result for some IP.<br>Default: '
.Constants::CACHE_EXPIRATION_FOR_GEO.'.<br>Set 0 to disable caching', Constants::CACHE_EXPIRATION_FOR_GEO,
'width: 115px;', 'number');
Expand Down
10 changes: 7 additions & 3 deletions inc/admin/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ function clearBouncerCacheInAdminPage()
// In stream mode, immediatelly warm the cache up.
if (get_option('crowdsec_stream_mode')) {
$refresh = $bouncer->refreshBlocklistCache();
$result = $refresh['new']??0;
$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.');
$new = $refresh['new']??0;
$deleted = $refresh['deleted']??0;
$message .= __(' As the stream mode is enabled, the cache has just been refreshed. New decision(s): '.$new.'. Deleted decision(s): '. $deleted);
}

AdminNotice::displaySuccess($message);
Expand Down Expand Up @@ -77,7 +78,10 @@ function refreshBouncerCacheInAdminPage()
$configs = getDatabaseConfigs();
$bouncer = new Bouncer($configs);
$result = $bouncer->refreshBlocklistCache();
AdminNotice::displaySuccess(__(' The cache has just been refreshed ('.($result['new'] > 0 ? $result['new'].' new decisions' : $result['new'].' new decision').', '.$result['deleted'].' deleted).'));
$new = $result['new']??0;
$deleted = $result['deleted']??0;
$message = __('The cache has just been refreshed. New decision(s): '.$new.'. Deleted decision(s): '. $deleted);
AdminNotice::displaySuccess($message);
}
} catch (BouncerException $e) {
if(isset($bouncer) && $bouncer->getLogger()) {
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://crowdsec.net/
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
Requires at least: 4.9
Tested up to: 6.1
Stable tag: 2.0.0
Stable tag: 2.0.1
Requires PHP: 7.2
License: MIT
License URI: https://opensource.org/licenses/MIT
Expand Down
Loading

0 comments on commit f334b05

Please sign in to comment.