@@ -29,7 +29,12 @@ public function init(array $crowdSecConfig): bool
2929 return true ;
3030 }
3131
32- protected function getSettings (string $ name )
32+ protected function getStringSettings (string $ name ): string
33+ {
34+ return $ this ->settings [$ name ];
35+ }
36+
37+ protected function getArraySettings (string $ name ): array
3338 {
3439 return $ this ->settings [$ name ];
3540 }
@@ -49,22 +54,22 @@ protected function specialcharsDecodeEntQuotes(string $value)
4954 */
5055 public function getBouncerInstance (): Bouncer
5156 {
52- $ apiUrl = $ this ->escape ($ this ->getSettings ('crowdsec_api_url ' ));
53- $ apiKey = $ this ->escape ($ this ->getSettings ('crowdsec_api_key ' ));
54- $ isStreamMode = !empty ($ this ->getSettings ('crowdsec_stream_mode ' ));
55- $ cleanIpCacheDuration = (int ) $ this ->getSettings ('crowdsec_clean_ip_cache_duration ' );
56- $ badIpCacheDuration = (int ) $ this ->getSettings ('crowdsec_bad_ip_cache_duration ' );
57- $ fallbackRemediation = $ this ->escape ($ this ->getSettings ('crowdsec_fallback_remediation ' ));
58- $ bouncingLevel = $ this ->escape ($ this ->getSettings ('crowdsec_bouncing_level ' ));
57+ $ apiUrl = $ this ->escape ($ this ->getStringSettings ('crowdsec_api_url ' ));
58+ $ apiKey = $ this ->escape ($ this ->getStringSettings ('crowdsec_api_key ' ));
59+ $ isStreamMode = !empty ($ this ->getStringSettings ('crowdsec_stream_mode ' ));
60+ $ cleanIpCacheDuration = (int ) $ this ->getStringSettings ('crowdsec_clean_ip_cache_duration ' );
61+ $ badIpCacheDuration = (int ) $ this ->getStringSettings ('crowdsec_bad_ip_cache_duration ' );
62+ $ fallbackRemediation = $ this ->escape ($ this ->getStringSettings ('crowdsec_fallback_remediation ' ));
63+ $ bouncingLevel = $ this ->escape ($ this ->getStringSettings ('crowdsec_bouncing_level ' ));
5964 $ crowdSecBouncerUserAgent = CROWDSEC_BOUNCER_USER_AGENT ;
6065 $ crowdSecLogPath = CROWDSEC_LOG_PATH ;
6166 $ crowdSecDebugLogPath = CROWDSEC_DEBUG_LOG_PATH ;
6267
6368 $ this ->logger = getStandAloneCrowdSecLoggerInstance ($ crowdSecLogPath , $ this ->debug , $ crowdSecDebugLogPath );
6469
65- $ cacheSystem = $ this ->escape ($ this ->getSettings ('crowdsec_cache_system ' ));
66- $ memcachedDsn = $ this ->escape ($ this ->getSettings ('crowdsec_memcached_dsn ' ));
67- $ redisDsn = $ this ->escape ($ this ->getSettings ('crowdsec_redis_dsn ' ));
70+ $ cacheSystem = $ this ->escape ($ this ->getStringSettings ('crowdsec_cache_system ' ));
71+ $ memcachedDsn = $ this ->escape ($ this ->getStringSettings ('crowdsec_memcached_dsn ' ));
72+ $ redisDsn = $ this ->escape ($ this ->getStringSettings ('crowdsec_redis_dsn ' ));
6873 $ fsCachePath = CROWDSEC_CACHE_PATH ;
6974
7075 $ this ->bouncer = getBouncerInstanceStandAlone ($ apiUrl , $ apiKey , $ isStreamMode , $ cleanIpCacheDuration , $ badIpCacheDuration , $ fallbackRemediation , $ bouncingLevel , $ crowdSecBouncerUserAgent , $ this ->logger , $ cacheSystem , $ memcachedDsn , $ redisDsn , $ fsCachePath );
@@ -107,34 +112,34 @@ public function getHttpMethod(): string
107112 public function getCaptchaWallOptions (): array
108113 {
109114 return [
110- 'hide_crowdsec_mentions ' => (bool ) $ this ->getSettings ('crowdsec_hide_mentions ' ),
115+ 'hide_crowdsec_mentions ' => (bool ) $ this ->getStringSettings ('crowdsec_hide_mentions ' ),
111116 'color ' => [
112117 'text ' => [
113- 'primary ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_color_text_primary ' )),
114- 'secondary ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_color_text_secondary ' )),
115- 'button ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_color_text_button ' )),
116- 'error_message ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_color_text_error_message ' )),
118+ 'primary ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_color_text_primary ' )),
119+ 'secondary ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_color_text_secondary ' )),
120+ 'button ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_color_text_button ' )),
121+ 'error_message ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_color_text_error_message ' )),
117122 ],
118123 'background ' => [
119- 'page ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_color_background_page ' )),
120- 'container ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_color_background_container ' )),
121- 'button ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_color_background_button ' )),
122- 'button_hover ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_color_background_button_hover ' )),
124+ 'page ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_color_background_page ' )),
125+ 'container ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_color_background_container ' )),
126+ 'button ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_color_background_button ' )),
127+ 'button_hover ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_color_background_button_hover ' )),
123128 ],
124129 ],
125130 'text ' => [
126131 'captcha_wall ' => [
127- 'tab_title ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_text_captcha_wall_tab_title ' )),
128- 'title ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_text_captcha_wall_title ' )),
129- 'subtitle ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_text_captcha_wall_subtitle ' )),
130- 'refresh_image_link ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_text_captcha_wall_refresh_image_link ' )),
131- 'captcha_placeholder ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_text_captcha_wall_captcha_placeholder ' )),
132- 'send_button ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_text_captcha_wall_send_button ' )),
133- 'error_message ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_text_captcha_wall_error_message ' )),
134- 'footer ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_text_captcha_wall_footer ' )),
132+ 'tab_title ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_text_captcha_wall_tab_title ' )),
133+ 'title ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_text_captcha_wall_title ' )),
134+ 'subtitle ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_text_captcha_wall_subtitle ' )),
135+ 'refresh_image_link ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_text_captcha_wall_refresh_image_link ' )),
136+ 'captcha_placeholder ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_text_captcha_wall_captcha_placeholder ' )),
137+ 'send_button ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_text_captcha_wall_send_button ' )),
138+ 'error_message ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_text_captcha_wall_error_message ' )),
139+ 'footer ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_text_captcha_wall_footer ' )),
135140 ],
136141 ],
137- 'custom_css ' => $ this ->getSettings ('crowdsec_theme_custom_css ' ),
142+ 'custom_css ' => $ this ->getStringSettings ('crowdsec_theme_custom_css ' ),
138143 ];
139144 }
140145
@@ -144,29 +149,29 @@ public function getCaptchaWallOptions(): array
144149 public function getBanWallOptions (): array
145150 {
146151 return [
147- 'hide_crowdsec_mentions ' => (bool ) $ this ->getSettings ('crowdsec_hide_mentions ' ),
152+ 'hide_crowdsec_mentions ' => (bool ) $ this ->getStringSettings ('crowdsec_hide_mentions ' ),
148153 'color ' => [
149154 'text ' => [
150- 'primary ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_color_text_primary ' )),
151- 'secondary ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_color_text_secondary ' )),
152- 'error_message ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_color_text_error_message ' )),
155+ 'primary ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_color_text_primary ' )),
156+ 'secondary ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_color_text_secondary ' )),
157+ 'error_message ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_color_text_error_message ' )),
153158 ],
154159 'background ' => [
155- 'page ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_color_background_page ' )),
156- 'container ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_color_background_container ' )),
157- 'button ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_color_background_button ' )),
158- 'button_hover ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_color_background_button_hover ' )),
160+ 'page ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_color_background_page ' )),
161+ 'container ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_color_background_container ' )),
162+ 'button ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_color_background_button ' )),
163+ 'button_hover ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_color_background_button_hover ' )),
159164 ],
160165 ],
161166 'text ' => [
162167 'ban_wall ' => [
163- 'tab_title ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_text_ban_wall_tab_title ' )),
164- 'title ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_text_ban_wall_title ' )),
165- 'subtitle ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_text_ban_wall_subtitle ' )),
166- 'footer ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_text_ban_wall_footer ' )),
168+ 'tab_title ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_text_ban_wall_tab_title ' )),
169+ 'title ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_text_ban_wall_title ' )),
170+ 'subtitle ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_text_ban_wall_subtitle ' )),
171+ 'footer ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_text_ban_wall_footer ' )),
167172 ],
168173 ],
169- 'custom_css ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getSettings ('crowdsec_theme_custom_css ' )),
174+ 'custom_css ' => $ this ->specialcharsDecodeEntQuotes ($ this ->getStringSettings ('crowdsec_theme_custom_css ' )),
170175 ];
171176 }
172177
@@ -175,7 +180,7 @@ public function getBanWallOptions(): array
175180 */
176181 public function getTrustForwardedIpBoundsList (): array
177182 {
178- return $ this ->getSettings ('crowdsec_trust_ip_forward_array ' );
183+ return $ this ->getArraySettings ('crowdsec_trust_ip_forward_array ' );
179184 }
180185
181186 /**
@@ -233,11 +238,11 @@ public function shouldBounceCurrentIp(): bool
233238 }
234239
235240 // Don't bounce if standalone mode is enable and we are not in a auto_prepend_file context.
236- if ((bool ) $ this ->getSettings ('crowdsec_standalone_mode ' ) && !defined ('CROWDSEC_STANDALONE_RUNNING_CONTEXT ' )) {
241+ if ((bool ) $ this ->getStringSettings ('crowdsec_standalone_mode ' ) && !defined ('CROWDSEC_STANDALONE_RUNNING_CONTEXT ' )) {
237242 return false ;
238243 }
239244
240- $ shouldNotBounceWpAdmin = !empty ($ this ->getSettings ('crowdsec_public_website_only ' ));
245+ $ shouldNotBounceWpAdmin = !empty ($ this ->getStringSettings ('crowdsec_public_website_only ' ));
241246 // when the "crowdsec_public_website_only" is disabled...
242247 if ($ shouldNotBounceWpAdmin ) {
243248 // In standalone context, is_admin() does not work. So we check admin section with another method.
@@ -271,7 +276,7 @@ public function shouldBounceCurrentIp(): bool
271276 return false ;
272277 }
273278
274- $ bouncingDisabled = (Constants::BOUNCING_LEVEL_DISABLED === $ this ->escape ($ this ->getSettings ('crowdsec_bouncing_level ' )));
279+ $ bouncingDisabled = (Constants::BOUNCING_LEVEL_DISABLED === $ this ->escape ($ this ->getStringSettings ('crowdsec_bouncing_level ' )));
275280 if ($ bouncingDisabled ) {
276281 return false ;
277282 }
@@ -336,19 +341,19 @@ public function isConfigValid(): bool
336341 {
337342 $ issues = ['errors ' => [], 'warnings ' => []];
338343
339- $ bouncingLevel = $ this ->escape ($ this ->getSettings ('crowdsec_bouncing_level ' ));
344+ $ bouncingLevel = $ this ->escape ($ this ->getStringSettings ('crowdsec_bouncing_level ' ));
340345 $ shouldBounce = (Constants::BOUNCING_LEVEL_DISABLED !== $ bouncingLevel );
341346
342347 if ($ shouldBounce ) {
343- $ apiUrl = $ this ->escape ($ this ->getSettings ('crowdsec_api_url ' ));
348+ $ apiUrl = $ this ->escape ($ this ->getStringSettings ('crowdsec_api_url ' ));
344349 if (empty ($ apiUrl )) {
345350 $ issues ['errors ' ][] = [
346351 'type ' => 'INCORRECT_API_URL ' ,
347352 'message ' => 'Bouncer enabled but no API URL provided ' ,
348353 ];
349354 }
350355
351- $ apiKey = $ this ->escape ($ this ->getSettings ('crowdsec_api_key ' ));
356+ $ apiKey = $ this ->escape ($ this ->getStringSettings ('crowdsec_api_key ' ));
352357 if (empty ($ apiKey )) {
353358 $ issues ['errors ' ][] = [
354359 'type ' => 'INCORRECT_API_KEY ' ,
@@ -357,9 +362,9 @@ public function isConfigValid(): bool
357362 }
358363
359364 try {
360- $ cacheSystem = $ this ->escape ($ this ->getSettings ('crowdsec_cache_system ' ));
361- $ memcachedDsn = $ this ->escape ($ this ->getSettings ('crowdsec_memcached_dsn ' ));
362- $ redisDsn = $ this ->escape ($ this ->getSettings ('crowdsec_redis_dsn ' ));
365+ $ cacheSystem = $ this ->escape ($ this ->getStringSettings ('crowdsec_cache_system ' ));
366+ $ memcachedDsn = $ this ->escape ($ this ->getStringSettings ('crowdsec_memcached_dsn ' ));
367+ $ redisDsn = $ this ->escape ($ this ->getStringSettings ('crowdsec_redis_dsn ' ));
363368 $ fsCachePath = CROWDSEC_CACHE_PATH ;
364369 getCacheAdapterInstanceStandAlone ($ cacheSystem , $ memcachedDsn , $ redisDsn , $ fsCachePath );
365370 } catch (WordpressCrowdSecBouncerException $ e ) {
0 commit comments