Skip to content

Commit de06658

Browse files
feat(metrics): Allow sending remediation metrics to blaas (#171)
* feat(blaas): Allow usage metrics for Blaas * feat(blaas): Remove reset remediation metrics feature
1 parent aea9d8b commit de06658

File tree

11 files changed

+27
-111
lines changed

11 files changed

+27
-111
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
---
88

9+
## [2.13.0](https://github.com/crowdsecurity/cs-wordpress-bouncer/releases/tag/v2.13.0) - 2025-12-12
10+
[_Compare with previous release_](https://github.com/crowdsecurity/cs-wordpress-bouncer/compare/v2.12.0...v2.13.0)
11+
12+
### Changed
13+
14+
- Allow sending remediation metrics even with BLaaS LAPI
15+
16+
### Removed
17+
18+
- Remove "Reset remediation metrics" feature previously added for BLaaS LAPI
19+
20+
21+
---
22+
23+
924
## [2.12.0](https://github.com/crowdsecurity/cs-wordpress-bouncer/releases/tag/v2.12.0) - 2025-12-05
1025
[_Compare with previous release_](https://github.com/crowdsecurity/cs-wordpress-bouncer/compare/v2.11.1...v2.12.0)
1126

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: security, captcha, ip-blocker, crowdsec, hacker-protection, appsec
7-
* Version: 2.12.0
7+
* Version: 2.13.0
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.9
16-
* Stable tag: 2.12.0
16+
* Stable tag: 2.13.0
1717
* Text Domain: crowdsec-wp
1818
* First release: 2021.
1919
*/

docs/DEVELOPER.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -457,16 +457,8 @@ Before publishing a new release, there are some manual steps to take:
457457

458458
Then, you have to [run the action manually from the GitHub repository](https://github.com/crowdsecurity/cs-wordpress-bouncer/actions/workflows/release.yml)
459459

460-
461460
Alternatively, you could use the [GitHub CLI](https://github.com/cli/cli):
462-
- create a draft release:
463-
```
464-
gh workflow run release.yml -f tag_name=vx.y.z -f draft=true
465-
```
466-
- publish a prerelease:
467-
```
468-
gh workflow run release.yml -f tag_name=vx.y.z -f prerelease=true
469-
```
461+
470462
- publish a release:
471463
```
472464
gh workflow run release.yml -f tag_name=vx.y.z

docs/USER_GUIDE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ note the following:
141141

142142
- The Authentication type must be "Bouncer API key"
143143
- Stream mode must be enabled (see Communication mode with the Local API in [Advanced settings](#advanced-settings)).
144-
- Remediation Metrics cannot be sent (see Remediation Metrics in [Advanced settings](#advanced-settings)).
145144
- AppSec component cannot be used (see Appsec Component in [Advanced settings](#advanced-settings))
146145

147146
***

inc/Admin/advanced-settings.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,6 @@ function crowdsec_multi_save_advanced_settings()
163163
// Field "crowdsec_usage_metrics"
164164
addFieldCheckbox('crowdsec_usage_metrics', 'Enable Remediation Metrics', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_usage_metrics', function () {
165165
// Usage metrics push just activated.
166-
$lapiUrl = is_multisite() ? get_site_option('crowdsec_api_url') : get_option('crowdsec_api_url');
167-
if (0 === strpos($lapiUrl, Constants::BAAS_URL)) {
168-
AdminNotice::displayError('Pushing remediation metrics with a Block as a Service LAPI ('.esc_html
169-
($lapiUrl).') is not supported. ');
170-
return false;
171-
}
172166
scheduleUsageMetricsPush();
173167
return true;
174168
}, function () {
@@ -182,7 +176,7 @@ function crowdsec_multi_save_advanced_settings()
182176
<div id="usage-metrics-report">
183177
<p>'.displayBouncerMetricsInAdminPage().'</p>
184178
</div>
185-
' .displayPushMetricsInAdminPage($isUsageMetricsEnabled).displayResetMetricsInAdminPage()
179+
' .displayPushMetricsInAdminPage($isUsageMetricsEnabled)
186180
);
187181

188182

inc/Admin/init.php

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -121,27 +121,6 @@ function pushBouncerMetricsInAdminPage()
121121
}
122122
}
123123

124-
function resetBouncerMetricsInAdminPage()
125-
{
126-
try {
127-
$configs = getDatabaseConfigs();
128-
$bouncer = new Bouncer($configs);
129-
$bouncer->resetUsageMetrics();
130-
AdminNotice::displaySuccess(__('CrowdSec remediation metrics have been reset successfully.'));
131-
} catch (Exception $e) {
132-
if(isset($bouncer) && $bouncer->getLogger()) {
133-
$bouncer->getLogger()->error('', [
134-
'type' => 'WP_EXCEPTION_WHILE_RESETTING_USAGE_METRICS',
135-
'message' => $e->getMessage(),
136-
'code' => $e->getCode(),
137-
'file' => $e->getFile(),
138-
'line' => $e->getLine(),
139-
]);
140-
}
141-
AdminNotice::displayError('Technical error while resetting remediation metrics: '.$e->getMessage());
142-
}
143-
}
144-
145124
function displayBouncerMetricsInAdminPage()
146125
{
147126
try {
@@ -263,43 +242,11 @@ function displayBouncerMetricsInAdminPage()
263242
}
264243
}
265244

266-
267-
function displayResetMetricsInAdminPage()
268-
{
269-
try {
270-
$configs = getDatabaseConfigs();
271-
$bouncer = new Bouncer($configs);
272-
if ($bouncer->hasBaasUri()) {
273-
return '<p><input id="crowdsec_reset_usage_metrics" style="margin-right:10px" type="button" value="Reset remediation metrics now" class="button button-secondary button-small" onclick="document.getElementById(\'crowdsec_action_reset_usage_metrics\').submit();"></p>';
274-
}
275-
276-
return '';
277-
}
278-
catch (Exception $e) {
279-
if (isset($bouncer) && $bouncer->getLogger()) {
280-
$bouncer->getLogger()->error('', [
281-
'type' => 'WP_EXCEPTION_WHILE_DISPLAYING_RESET_METRICS',
282-
'message' => $e->getMessage(),
283-
'code' => $e->getCode(),
284-
'file' => $e->getFile(),
285-
'line' => $e->getLine(),
286-
]);
287-
}
288-
289-
AdminNotice::displayError('Technical error while displaying reset metrics button: ' . esc_html($e->getMessage()));
290-
return '';
291-
}
292-
293-
}
294-
295245
function displayPushMetricsInAdminPage($isPushEnabled = false)
296246
{
297247
try {
298248
$configs = getDatabaseConfigs();
299249
$bouncer = new Bouncer($configs);
300-
if($bouncer->hasBaasUri()) {
301-
return '';
302-
}
303250
if( $isPushEnabled) {
304251
return '<p><input id="crowdsec_push_usage_metrics" style="margin-right:10px" type="button" value="Push remediation metrics now" class="button button-secondary button-small" onclick="document.getElementById(\'crowdsec_action_push_usage_metrics\').submit();"></p>';
305252
}
@@ -440,15 +387,6 @@ function testGeolocationInAdminPage($ip)
440387
header("Location: {$_SERVER['HTTP_REFERER']}");
441388
exit(0);
442389
});
443-
add_action('admin_post_crowdsec_reset_usage_metrics', function () {
444-
if (
445-
!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'crowdsec_reset_usage_metrics')) {
446-
die('This link expired.');
447-
}
448-
resetBouncerMetricsInAdminPage();
449-
header("Location: {$_SERVER['HTTP_REFERER']}");
450-
exit(0);
451-
});
452390
add_action('admin_post_crowdsec_prune_cache', function () {
453391
if (
454392
!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'crowdsec_prune_cache')) {

inc/Admin/settings.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ function crowdsec_multi_save_settings()
7777
$message .= '<br><b>Please note the following: </b><ul>';
7878
$message .= '<li>- The Authentication type must be "Bouncer API key".</li>';
7979
$message .= '<li>- Stream mode must be enabled (see Communication mode with the Local API in Advanced Settings).</li>';
80-
$message .= '<li>- Usage Metrics cannot be sent (see Usage Metrics in Advanced Settings).</li>';
8180
$message .= '<li>- AppSec component cannot be used (see Appsec Component in Advanced Settings).</li>';
8281
$message .= '</ul>';
8382
AdminNotice::displayWarning($message);

inc/Constants.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ class Constants extends LibConstants
2121
public const BOUNCER_NAME = 'wordpress-bouncer';
2222
public const DEFAULT_BASE_FILE_PATH = __DIR__ . '/../../../../wp-content/uploads/crowdsec/';
2323
public const STANDALONE_CONFIG_PATH = __DIR__ . '/standalone-settings.php';
24-
public const VERSION = 'v2.12.0';
24+
public const VERSION = 'v2.13.0';
2525
}

inc/templates/advanced-settings.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,6 @@ function updateDsnDisplay () {
137137
<form action="<?php echo admin_url('admin-post.php'); ?>" method="post" id="crowdsec_action_push_usage_metrics">
138138
<input type="hidden" name="action" value="crowdsec_push_usage_metrics">
139139
<input type="hidden" name="nonce" value="<?php echo wp_create_nonce('crowdsec_push_usage_metrics'); ?>">
140-
</form>
141-
<form action="<?php echo admin_url('admin-post.php'); ?>" method="post"
142-
id="crowdsec_action_reset_usage_metrics">
143-
<input type="hidden" name="action" value="crowdsec_reset_usage_metrics">
144-
<input type="hidden" name="nonce" value="<?php echo wp_create_nonce('crowdsec_reset_usage_metrics'); ?>">
145140
</form>
146141
</div>
147142
<p style="padding-top:15px">

readme.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Donate link: https://crowdsec.net/
44
Tags: security, captcha, ip-blocker, crowdsec, hacker-protection
55
Requires at least: 4.9
66
Tested up to: 6.9
7-
Stable tag: 2.12.0
7+
Stable tag: 2.13.0
88
Requires PHP: 7.2
99
License: MIT
1010
License URI: https://opensource.org/licenses/MIT
@@ -63,6 +63,10 @@ Multiple ways you can use the plugin
6363

6464
== Changelog ==
6565

66+
= 2.13 (2025-12-12) =
67+
68+
- Allow sending remediation metrics even with a Blocklist as a Service (BLaaS) LAPI
69+
6670
= 2.12 (2025-12-05) =
6771

6872
- Remove Blocklist as a Service (BLaaS) subscription button

0 commit comments

Comments
 (0)