Skip to content

Commit 0edf1dc

Browse files
feat(admin): Modify admin message and cache flow
1 parent c0b43a0 commit 0edf1dc

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

inc/admin/advanced-settings.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function adminAdvancedSettings()
2424
$bouncer->clearCache();
2525
$refresh = $bouncer->refreshBlocklistCache();
2626
$result = $refresh['new']??0;
27-
$message = __('As the stream mode is enabled, the cache has just been refreshed, '.($result > 0 ? 'there are now '.$result.' decisions' : 'there is now '.$result.' decision').' in cache.');
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.');
2828
AdminNotice::displaySuccess($message);
2929
scheduleBlocklistRefresh();
3030
}, function () {
@@ -55,8 +55,10 @@ function adminAdvancedSettings()
5555
$bouncer->clearCache();
5656
$refresh = $bouncer->refreshBlocklistCache();
5757
$result = $refresh['new']??0;
58-
$message = __('As the stream mode refresh duration changed, the cache has just been refreshed, '.($result >
59-
0 ? 'there are now '.$result.' decisions' : 'there is now '.$result.' decision').' in cache.');
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+
);
6062
AdminNotice::displaySuccess($message);
6163
scheduleBlocklistRefresh();
6264
}
@@ -166,9 +168,10 @@ function adminAdvancedSettings()
166168
try {
167169
if (get_option('crowdsec_stream_mode') && !$error) {
168170
// system
171+
$bouncer->clearCache();
169172
$result = $bouncer->refreshBlocklistCache();
170173
$count = $result['new'];
171-
$message .= __('As the stream mode is enabled, the cache has just been refreshed, '.($count > 0 ? 'there are now '.$count.' decisions' : 'there is now '.$count.' decision').' in cache.');
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.');
172175
AdminNotice::displaySuccess($message);
173176
scheduleBlocklistRefresh();
174177
}
@@ -281,7 +284,7 @@ function convertInlineIpRangesToComparableIpBounds(string $inlineIpRanges): arra
281284
}
282285
$comparableIpBoundsList = convertInlineIpRangesToComparableIpBounds($input);
283286
update_option('crowdsec_trust_ip_forward_array', $comparableIpBoundsList);
284-
AdminNotice::displaySuccess('Ips with XFF to trust successfully saved.');
287+
AdminNotice::displaySuccess('IPs with X-Forwarded-For to trust successfully saved.');
285288
} catch (BouncerException $e) {
286289
update_option('crowdsec_trust_ip_forward_array', []);
287290
add_settings_error('Trust these CDN IPs', 'crowdsec_error', 'Trust these CDN IPs: Invalid IP List format.');
@@ -363,11 +366,11 @@ function convertInlineIpRangesToComparableIpBounds(string $inlineIpRanges): arra
363366

364367
// Field "crowdsec_debug_mode"
365368
addFieldCheckbox('crowdsec_debug_mode', 'Enable debug mode', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_debug', function () {}, function () {}, '
366-
<p>Should not be used in production.<br>When this mode is enabled, a debug.log file will be written in the <i>wp-content/plugins/crowdsec/logs</i> folder.</p>');
369+
<p>Should not be used in production.<br>When this mode is enabled, a <i>debug.log</i> file will be written in the <i>wp-content/plugins/crowdsec/logs</i> folder.</p>');
367370

368371
// Field "crowdsec_disable_prod_log"
369372
addFieldCheckbox('crowdsec_disable_prod_log', 'Disable prod log', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_debug', function () {}, function () {}, '
370-
<p>By default, a prod.log file will be written in the <i>wp-content/plugins/crowdsec/logs</i> folder.<br>You can disable this log here.</p>');
373+
<p>By default, a <i>prod.log</i> file will be written in the <i>wp-content/plugins/crowdsec/logs</i> folder.<br>You can disable this log here.</p>');
371374

372375
/*******************************
373376
** Section "Display errors" **
@@ -379,7 +382,7 @@ function convertInlineIpRangesToComparableIpBounds(string $inlineIpRanges): arra
379382

380383
// Field "crowdsec_display_errors"
381384
addFieldCheckbox('crowdsec_display_errors', 'Enable errors display', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_display_errors', function () {}, function () {}, '
382-
<p>Do not use in production. When this mode is enabled, you will see every unexpected bouncing errors in the browser.</p>');
385+
<p><strong>Do not use in production.</strong> When this mode is enabled, you will see every unexpected bouncing errors in the browser.</p>');
383386

384387
/*******************************
385388
** Section "Test mode" **

inc/admin/init.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function clearBouncerCacheInAdminPage()
4646
if (get_option('crowdsec_stream_mode')) {
4747
$refresh = $bouncer->refreshBlocklistCache();
4848
$result = $refresh['new']??0;
49-
$message .= __(' As the stream mode is enabled, the cache has just been refreshed, '.($result > 0 ? 'there are now '.$result.' decisions' : 'there is now '.$result.' decision').' in cache.');
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.');
5050
}
5151

5252
AdminNotice::displaySuccess($message);

0 commit comments

Comments
 (0)