@@ -45,14 +45,14 @@ private function getCacheAdapterInstance(): AbstractAdapter
45
45
return $ this ->cacheAdapter ;
46
46
}
47
47
48
- $ cacheSystem = $ this ->getSettings ('cache_system ' );
48
+ $ cacheSystem = $ this ->getStringSettings ('cache_system ' );
49
49
switch ($ cacheSystem ) {
50
50
case Constants::CACHE_SYSTEM_PHPFS :
51
- $ this ->cacheAdapter = new PhpFilesAdapter ('' , 0 , $ this ->getSettings ('fs_cache_path ' ));
51
+ $ this ->cacheAdapter = new PhpFilesAdapter ('' , 0 , $ this ->getStringSettings ('fs_cache_path ' ));
52
52
break ;
53
53
54
54
case Constants::CACHE_SYSTEM_MEMCACHED :
55
- $ memcachedDsn = $ this ->getSettings ('memcached_dsn ' );
55
+ $ memcachedDsn = $ this ->getStringSettings ('memcached_dsn ' );
56
56
if (empty ($ memcachedDsn )) {
57
57
throw new BouncerException ('The selected cache technology is Memcached. ' .
58
58
' Please set a Memcached DSN or select another cache technology. ' );
@@ -62,7 +62,7 @@ private function getCacheAdapterInstance(): AbstractAdapter
62
62
break ;
63
63
64
64
case Constants::CACHE_SYSTEM_REDIS :
65
- $ redisDsn = $ this ->getSettings ('redis_dsn ' );
65
+ $ redisDsn = $ this ->getStringSettings ('redis_dsn ' );
66
66
if (empty ($ redisDsn )) {
67
67
throw new BouncerException ('The selected cache technology is Redis. ' .
68
68
' Please set a Redis DSN or select another cache technology. ' );
@@ -95,17 +95,17 @@ public function getBouncerInstance(): Bouncer
95
95
96
96
// Parse options.
97
97
98
- if (empty ($ this ->getSettings ('api_url ' ))) {
98
+ if (empty ($ this ->getStringSettings ('api_url ' ))) {
99
99
throw new BouncerException ('Bouncer enabled but no API URL provided ' );
100
100
}
101
- if (empty ($ this ->getSettings ('api_key ' ))) {
101
+ if (empty ($ this ->getStringSettings ('api_key ' ))) {
102
102
throw new BouncerException ('Bouncer enabled but no API key provided ' );
103
103
}
104
- $ isStreamMode = $ this ->getSettings ('stream_mode ' );
105
- $ cleanIpCacheDuration = (int ) $ this ->getSettings ('clean_ip_cache_duration ' );
106
- $ badIpCacheDuration = (int ) $ this ->getSettings ('bad_ip_cache_duration ' );
107
- $ fallbackRemediation = $ this ->getSettings ('fallback_remediation ' );
108
- $ bouncingLevel = $ this ->getSettings ('bouncing_level ' );
104
+ $ isStreamMode = $ this ->getStringSettings ('stream_mode ' );
105
+ $ cleanIpCacheDuration = (int ) $ this ->getStringSettings ('clean_ip_cache_duration ' );
106
+ $ badIpCacheDuration = (int ) $ this ->getStringSettings ('bad_ip_cache_duration ' );
107
+ $ fallbackRemediation = $ this ->getStringSettings ('fallback_remediation ' );
108
+ $ bouncingLevel = $ this ->getStringSettings ('bouncing_level ' );
109
109
110
110
// Init Bouncer instance
111
111
@@ -125,31 +125,31 @@ public function getBouncerInstance(): Bouncer
125
125
126
126
// Instanciate the bouncer
127
127
try {
128
- $ cacheAdapter = $ this ->getCacheAdapterInstance ();
129
- } catch (Symfony \ Component \ Cache \ Exception \ InvalidArgumentException $ e ) {
128
+ $ this -> cacheAdapter = $ this ->getCacheAdapterInstance ();
129
+ } catch (InvalidArgumentException $ e ) {
130
130
throw new BouncerException ($ e ->getMessage ());
131
131
}
132
132
133
133
$ apiUserAgent = 'Standalone CrowdSec PHP Bouncer/ ' .Constants::VERSION ;
134
134
135
- $ this ->bouncer = new Bouncer ($ cacheAdapter , $ this ->logger );
135
+ $ this ->bouncer = new Bouncer ($ this -> cacheAdapter , $ this ->logger );
136
136
$ this ->bouncer ->configure ([
137
- 'api_key ' => $ this ->getSettings ('api_key ' ),
138
- 'api_url ' => $ this ->getSettings ('api_url ' ),
137
+ 'api_key ' => $ this ->getStringSettings ('api_key ' ),
138
+ 'api_url ' => $ this ->getStringSettings ('api_url ' ),
139
139
'api_user_agent ' => $ apiUserAgent ,
140
140
'live_mode ' => !$ isStreamMode ,
141
141
'max_remediation_level ' => $ maxRemediationLevel ,
142
142
'fallback_remediation ' => $ fallbackRemediation ,
143
143
'cache_expiration_for_clean_ip ' => $ cleanIpCacheDuration ,
144
144
'cache_expiration_for_bad_ip ' => $ badIpCacheDuration ,
145
- ], $ cacheAdapter );
145
+ ], $ this -> cacheAdapter );
146
146
147
147
return $ this ->bouncer ;
148
148
}
149
149
150
150
public function initLogger (): void
151
151
{
152
- $ this ->initLoggerHelper ($ this ->getSettings ('log_directory_path ' ), 'php_standalone_bouncer ' );
152
+ $ this ->initLoggerHelper ($ this ->getStringSettings ('log_directory_path ' ), 'php_standalone_bouncer ' );
153
153
}
154
154
155
155
/**
@@ -187,34 +187,34 @@ public function getHttpMethod(): string
187
187
public function getCaptchaWallOptions (): array
188
188
{
189
189
return [
190
- 'hide_crowdsec_mentions ' => (bool ) $ this ->getSettings ('hide_mentions ' ),
190
+ 'hide_crowdsec_mentions ' => (bool ) $ this ->getStringSettings ('hide_mentions ' ),
191
191
'color ' => [
192
192
'text ' => [
193
- 'primary ' => htmlspecialchars_decode ($ this ->getSettings ('theme_color_text_primary ' ), \ENT_QUOTES ),
194
- 'secondary ' => htmlspecialchars_decode ($ this ->getSettings ('theme_color_text_secondary ' ), \ENT_QUOTES ),
195
- 'button ' => htmlspecialchars_decode ($ this ->getSettings ('theme_color_text_button ' ), \ENT_QUOTES ),
196
- 'error_message ' => htmlspecialchars_decode ($ this ->getSettings ('theme_color_text_error_message ' ), \ENT_QUOTES ),
193
+ 'primary ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_color_text_primary ' ), \ENT_QUOTES ),
194
+ 'secondary ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_color_text_secondary ' ), \ENT_QUOTES ),
195
+ 'button ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_color_text_button ' ), \ENT_QUOTES ),
196
+ 'error_message ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_color_text_error_message ' ), \ENT_QUOTES ),
197
197
],
198
198
'background ' => [
199
- 'page ' => htmlspecialchars_decode ($ this ->getSettings ('theme_color_background_page ' ), \ENT_QUOTES ),
200
- 'container ' => htmlspecialchars_decode ($ this ->getSettings ('theme_color_background_container ' ), \ENT_QUOTES ),
201
- 'button ' => htmlspecialchars_decode ($ this ->getSettings ('theme_color_background_button ' ), \ENT_QUOTES ),
202
- 'button_hover ' => htmlspecialchars_decode ($ this ->getSettings ('theme_color_background_button_hover ' ), \ENT_QUOTES ),
199
+ 'page ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_color_background_page ' ), \ENT_QUOTES ),
200
+ 'container ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_color_background_container ' ), \ENT_QUOTES ),
201
+ 'button ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_color_background_button ' ), \ENT_QUOTES ),
202
+ 'button_hover ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_color_background_button_hover ' ), \ENT_QUOTES ),
203
203
],
204
204
],
205
205
'text ' => [
206
206
'captcha_wall ' => [
207
- 'tab_title ' => htmlspecialchars_decode ($ this ->getSettings ('theme_text_captcha_wall_tab_title ' ), \ENT_QUOTES ),
208
- 'title ' => htmlspecialchars_decode ($ this ->getSettings ('theme_text_captcha_wall_title ' ), \ENT_QUOTES ),
209
- 'subtitle ' => htmlspecialchars_decode ($ this ->getSettings ('theme_text_captcha_wall_subtitle ' ), \ENT_QUOTES ),
210
- 'refresh_image_link ' => htmlspecialchars_decode ($ this ->getSettings ('theme_text_captcha_wall_refresh_image_link ' ), \ENT_QUOTES ),
211
- 'captcha_placeholder ' => htmlspecialchars_decode ($ this ->getSettings ('theme_text_captcha_wall_captcha_placeholder ' ), \ENT_QUOTES ),
212
- 'send_button ' => htmlspecialchars_decode ($ this ->getSettings ('theme_text_captcha_wall_send_button ' ), \ENT_QUOTES ),
213
- 'error_message ' => htmlspecialchars_decode ($ this ->getSettings ('theme_text_captcha_wall_error_message ' ), \ENT_QUOTES ),
214
- 'footer ' => htmlspecialchars_decode ($ this ->getSettings ('theme_text_captcha_wall_footer ' ), \ENT_QUOTES ),
207
+ 'tab_title ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_text_captcha_wall_tab_title ' ), \ENT_QUOTES ),
208
+ 'title ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_text_captcha_wall_title ' ), \ENT_QUOTES ),
209
+ 'subtitle ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_text_captcha_wall_subtitle ' ), \ENT_QUOTES ),
210
+ 'refresh_image_link ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_text_captcha_wall_refresh_image_link ' ), \ENT_QUOTES ),
211
+ 'captcha_placeholder ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_text_captcha_wall_captcha_placeholder ' ), \ENT_QUOTES ),
212
+ 'send_button ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_text_captcha_wall_send_button ' ), \ENT_QUOTES ),
213
+ 'error_message ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_text_captcha_wall_error_message ' ), \ENT_QUOTES ),
214
+ 'footer ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_text_captcha_wall_footer ' ), \ENT_QUOTES ),
215
215
],
216
216
],
217
- 'custom_css ' => $ this ->getSettings ('theme_custom_css ' ),
217
+ 'custom_css ' => $ this ->getStringSettings ('theme_custom_css ' ),
218
218
];
219
219
}
220
220
@@ -224,29 +224,29 @@ public function getCaptchaWallOptions(): array
224
224
public function getBanWallOptions (): array
225
225
{
226
226
return [
227
- 'hide_crowdsec_mentions ' => (bool ) $ this ->getSettings ('hide_mentions ' ),
227
+ 'hide_crowdsec_mentions ' => (bool ) $ this ->getStringSettings ('hide_mentions ' ),
228
228
'color ' => [
229
229
'text ' => [
230
- 'primary ' => htmlspecialchars_decode ($ this ->getSettings ('theme_color_text_primary ' ), \ENT_QUOTES ),
231
- 'secondary ' => htmlspecialchars_decode ($ this ->getSettings ('theme_color_text_secondary ' ), \ENT_QUOTES ),
232
- 'error_message ' => htmlspecialchars_decode ($ this ->getSettings ('theme_color_text_error_message ' ), \ENT_QUOTES ),
230
+ 'primary ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_color_text_primary ' ), \ENT_QUOTES ),
231
+ 'secondary ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_color_text_secondary ' ), \ENT_QUOTES ),
232
+ 'error_message ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_color_text_error_message ' ), \ENT_QUOTES ),
233
233
],
234
234
'background ' => [
235
- 'page ' => htmlspecialchars_decode ($ this ->getSettings ('theme_color_background_page ' ), \ENT_QUOTES ),
236
- 'container ' => htmlspecialchars_decode ($ this ->getSettings ('theme_color_background_container ' ), \ENT_QUOTES ),
237
- 'button ' => htmlspecialchars_decode ($ this ->getSettings ('theme_color_background_button ' ), \ENT_QUOTES ),
238
- 'button_hover ' => htmlspecialchars_decode ($ this ->getSettings ('theme_color_background_button_hover ' ), \ENT_QUOTES ),
235
+ 'page ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_color_background_page ' ), \ENT_QUOTES ),
236
+ 'container ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_color_background_container ' ), \ENT_QUOTES ),
237
+ 'button ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_color_background_button ' ), \ENT_QUOTES ),
238
+ 'button_hover ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_color_background_button_hover ' ), \ENT_QUOTES ),
239
239
],
240
240
],
241
241
'text ' => [
242
242
'ban_wall ' => [
243
- 'tab_title ' => htmlspecialchars_decode ($ this ->getSettings ('theme_text_ban_wall_tab_title ' ), \ENT_QUOTES ),
244
- 'title ' => htmlspecialchars_decode ($ this ->getSettings ('theme_text_ban_wall_title ' ), \ENT_QUOTES ),
245
- 'subtitle ' => htmlspecialchars_decode ($ this ->getSettings ('theme_text_ban_wall_subtitle ' ), \ENT_QUOTES ),
246
- 'footer ' => htmlspecialchars_decode ($ this ->getSettings ('theme_text_ban_wall_footer ' ), \ENT_QUOTES ),
243
+ 'tab_title ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_text_ban_wall_tab_title ' ), \ENT_QUOTES ),
244
+ 'title ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_text_ban_wall_title ' ), \ENT_QUOTES ),
245
+ 'subtitle ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_text_ban_wall_subtitle ' ), \ENT_QUOTES ),
246
+ 'footer ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_text_ban_wall_footer ' ), \ENT_QUOTES ),
247
247
],
248
248
],
249
- 'custom_css ' => htmlspecialchars_decode ($ this ->getSettings ('theme_custom_css ' ), \ENT_QUOTES ),
249
+ 'custom_css ' => htmlspecialchars_decode ($ this ->getStringSettings ('theme_custom_css ' ), \ENT_QUOTES ),
250
250
];
251
251
}
252
252
@@ -255,7 +255,7 @@ public function getBanWallOptions(): array
255
255
*/
256
256
public function getTrustForwardedIpBoundsList (): array
257
257
{
258
- return $ this ->getSettings ('trust_ip_forward_array ' );
258
+ return $ this ->getArraySettings ('trust_ip_forward_array ' );
259
259
}
260
260
261
261
/**
@@ -307,16 +307,12 @@ public function getPostedVariable(string $name): ?string
307
307
*/
308
308
public function shouldBounceCurrentIp (): bool
309
309
{
310
- // Don't bounce favicon calls.
311
- if ('/favicon.ico ' === $ _SERVER ['REQUEST_URI ' ]) {
312
- return false ;
313
- }
314
- if (!$ this ->isConfigValid ()) {
315
- // We bounce only if plugin config is valid
310
+ // Don't bounce favicon calls or when the config is invalid.
311
+ if ('/favicon.ico ' === $ _SERVER ['REQUEST_URI ' ] || !$ this ->isConfigValid ()) {
316
312
return false ;
317
313
}
318
314
319
- $ bouncingDisabled = (Constants::BOUNCING_LEVEL_DISABLED === $ this ->getSettings ('bouncing_level ' ));
315
+ $ bouncingDisabled = (Constants::BOUNCING_LEVEL_DISABLED === $ this ->getStringSettings ('bouncing_level ' ));
320
316
if ($ bouncingDisabled ) {
321
317
return false ;
322
318
}
@@ -381,19 +377,19 @@ public function isConfigValid(): bool
381
377
{
382
378
$ issues = ['errors ' => [], 'warnings ' => []];
383
379
384
- $ bouncingLevel = $ this ->getSettings ('bouncing_level ' );
380
+ $ bouncingLevel = $ this ->getStringSettings ('bouncing_level ' );
385
381
$ shouldBounce = (Constants::BOUNCING_LEVEL_DISABLED !== $ bouncingLevel );
386
382
387
383
if ($ shouldBounce ) {
388
- $ apiUrl = $ this ->getSettings ('api_url ' );
384
+ $ apiUrl = $ this ->getStringSettings ('api_url ' );
389
385
if (empty ($ apiUrl )) {
390
386
$ issues ['errors ' ][] = [
391
387
'type ' => 'INCORRECT_API_URL ' ,
392
388
'message ' => 'Bouncer enabled but no API URL provided ' ,
393
389
];
394
390
}
395
391
396
- $ apiKey = $ this ->getSettings ('api_key ' );
392
+ $ apiKey = $ this ->getStringSettings ('api_key ' );
397
393
if (empty ($ apiKey )) {
398
394
$ issues ['errors ' ][] = [
399
395
'type ' => 'INCORRECT_API_KEY ' ,
0 commit comments