You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: inc/admin/advanced-settings.php
+90-38Lines changed: 90 additions & 38 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,6 @@
1
1
<?php
2
2
3
+
useCrowdSecBouncer\BouncerException;
3
4
useCrowdSecBouncer\Constants;
4
5
5
6
functionadminAdvancedSettings()
@@ -20,24 +21,26 @@ function adminAdvancedSettings()
20
21
unscheduleBlocklistRefresh();
21
22
}, '
22
23
<p>With the stream mode, every decision is retrieved in an asynchronous way. 3 advantages: <br> 1) Inivisible latency when loading pages<br> 2) The IP verifications works even if your CrowdSec is not reachable.<br> 3) The API can never be overloaded by the WordPress traffic</p>
23
-
<p>Note: This method has one limit: for maximum 60 seconds, all the new decisions may not be taken into account.</p>'.
24
-
(get_option("crowdsec_stream_mode") ?
24
+
<p>Note: This method has one limit: for maximum 60 seconds, all the new decisions may not be taken into account.</p>'.
add_settings_error("Resync decisions each", "crowdsec_error", 'The "Resync decisions each" value should be more than 60sec (WP_CRON_LOCK_TIMEOUT). We just reset the frequency to 60 seconds.');
34
+
add_settings_error('Resync decisions each', 'crowdsec_error', 'The "Resync decisions each" value should be more than 60sec (WP_CRON_LOCK_TIMEOUT). We just reset the frequency to 60 seconds.');
35
+
34
36
return$input;
35
37
}
36
38
37
39
// Update wp-cron schedule.
38
-
if ((bool)get_option("crowdsec_stream_mode")) {
40
+
if ((bool)get_option('crowdsec_stream_mode')) {
39
41
scheduleBlocklistRefresh();
40
42
}
43
+
41
44
return$input;
42
45
}, ' seconds. <p>Our advice is 60 seconds (according to WP_CRON_LOCK_TIMEOUT).</p>', '...', 'width: 115px;', 'number');
43
46
@@ -46,67 +49,115 @@ function adminAdvancedSettings()
46
49
********************/
47
50
48
51
add_settings_section('crowdsec_admin_advanced_cache', 'Caching configuration <input style="margin-left: 7px;margin-top: -3px;" type="button" value="Clear now" class="button button-secondary button-small" onclick="if (confirm(\'Are you sure you want to completely clear the cache?\')) document.getElementById(\'crowdsec_ation_clear_cache\').submit();">', function () {
49
-
?>
52
+
?>
50
53
<p>Polish the decisions cache settings by selecting the best technology or the cache durations best suited to your use.</p>
51
54
<?php
52
55
}, 'crowdsec_advanced_settings');
53
56
57
+
// Field "crowdsec_redis_dsn"
58
+
addFieldString('crowdsec_redis_dsn', 'Redis DSN<br>(if applicable)', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_cache', function ($input) {
59
+
// TODO P1 block remove if cache set to redis
60
+
// TODO P1 Display an error in all sections (settings and advanced) when a cache config can not work.
61
+
return$input;
62
+
}, '<p>Fill in this field only if you have chosen the Redis cache.<br>Example of DSN: redis://localhost:6379.', 'redis://...', '');
63
+
64
+
// Field "crowdsec_memcached_dsn"
65
+
addFieldString('crowdsec_memcached_dsn', 'Memcached DSN<br>(if applicable)', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_cache', function ($input) {
66
+
// TODO P1 block remove if cache set to memcached
67
+
// TODO P1 Display an error in all sections (settings and advanced) when a cache config can not work.
68
+
return$input;
69
+
}, '<p>Fill in this field only if you have chosen the Memcached cache.<br>Example of DSN: memcached://localhost:11211.', 'memcached://...', '');
70
+
54
71
// Field "crowdsec_cache_system"
55
72
addFieldSelect('crowdsec_cache_system', 'Technology', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_cache', function ($input) {
56
73
if (!in_array($input, [CROWDSEC_CACHE_SYSTEM_PHPFS, CROWDSEC_CACHE_SYSTEM_REDIS, CROWDSEC_CACHE_SYSTEM_MEMCACHED])) {
$message = __('Cache system changed. Previous cache data has been cleared.');
64
-
65
-
// Update wp-cron schedule if stream mode is enabled
66
-
if ((bool)get_option("crowdsec_stream_mode")) {
67
-
$bouncer = getBouncerInstance($input); // Reload bouncer instance with the new cache system
68
-
$result = $bouncer->warmBlocklistCacheUp();
69
-
$message .= __(' As the stream mode is enabled, the cache has just been warmed up, ' . ($result > 0 ? 'there are now ' . $result . ' decisions' : 'there is now ' . $result . ' decision') . ' in cache.');
//Update wp-cron schedule if stream mode is enabled
119
+
if ((bool) get_option('crowdsec_stream_mode')) {
120
+
$bouncer = getBouncerInstance($input); // Reload bouncer instance with the new cache system
121
+
$result = $bouncer->warmBlocklistCacheUp();
122
+
$message = __('As the stream mode is enabled, the cache has just been warmed up, '.($result > 0 ? 'there are now '.$result.' decisions' : 'there is now '.$result.' decision').' in cache.');
}, ' seconds. <p>The duration (in seconds) between re-asking LAPI about an already checked clean IP.<br>Minimum 1 second.', '...', 'width: 115px;', 'number');
103
152
104
153
// Field "crowdsec_bad_ip_cache_duration"
105
154
addFieldString('crowdsec_bad_ip_cache_duration', 'Recheck bad IPs each', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_cache', function ($input) {
106
-
if ((int)$input <= 0) {
107
-
add_settings_error("Recheck bad IPs each", "crowdsec_error", "Recheck bad IPs each: Minimum is 1 second.");
108
-
return"1";
155
+
if ((int) $input <= 0) {
156
+
add_settings_error('Recheck bad IPs each', 'crowdsec_error', 'Recheck bad IPs each: Minimum is 1 second.');
157
+
158
+
return'1';
109
159
}
160
+
110
161
return$input;
111
162
}, ' seconds. <p>The duration (in seconds) between re-asking LAPI about an already checked bad IP.<br>Minimum 1 second.', '...', 'width: 115px;', 'number');
112
163
@@ -115,7 +166,7 @@ function adminAdvancedSettings()
115
166
**************************/
116
167
117
168
add_settings_section('crowdsec_admin_advanced_remediations', 'Remediations', function () {
118
-
echo"Configuration some details about remediations.";
169
+
echo'Configuration some details about remediations.';
119
170
}, 'crowdsec_advanced_settings');
120
171
121
172
// Field "crowdsec_fallback_remediation"
@@ -126,8 +177,9 @@ function adminAdvancedSettings()
126
177
addFieldSelect('crowdsec_fallback_remediation', 'Fallback to', 'crowdsec_plugin_advanced_settings', 'crowdsec_advanced_settings', 'crowdsec_admin_advanced_remediations', function ($input) {
127
178
if (!in_array($input, Constants::ORDERED_REMEDIATIONS)) {
128
179
$input = CROWDSEC_BOUNCING_LEVEL_DISABLED;
129
-
add_settings_error("Fallback to", "crowdsec_error", "Fallback to: Incorrect Fallback selected.");
180
+
add_settings_error('Fallback to', 'crowdsec_error', 'Fallback to: Incorrect Fallback selected.');
130
181
}
182
+
131
183
return$input;
132
184
}, '<p>Which remediation to apply when CrowdSec advises unhandled remediation.</p>', $choice);
0 commit comments