@@ -25,7 +25,7 @@ function getCrowdSecLoggerInstance(): Logger
2525
2626 $ loggerLevel = WP_DEBUG ? Logger::DEBUG : Logger::INFO ;
2727 $ logger = new Logger ('wp_bouncer ' );
28- $ fileHandler = new RotatingFileHandler (__DIR__ . ' /../logs/crowdsec.log ' , 0 , $ loggerLevel );
28+ $ fileHandler = new RotatingFileHandler (CROWDSEC_LOG_PATH , 0 , $ loggerLevel );
2929
3030 // Set custom readble logger for WP_DEBUG=1
3131 if (WP_DEBUG ) {
@@ -36,29 +36,45 @@ function getCrowdSecLoggerInstance(): Logger
3636 return $ logger ;
3737}
3838
39+ /** @var AbstractAdapter|null */
40+ $ crowdSecCacheAdapterInstance = null ;
41+
3942function getCacheAdapterInstance (string $ forcedCacheSystem = null ): AbstractAdapter
4043{
44+ // Singleton for this function
45+
46+ global $ crowdSecCacheAdapterInstance ;
47+ if (!$ forcedCacheSystem && $ crowdSecCacheAdapterInstance ) {
48+ return $ crowdSecCacheAdapterInstance ;
49+ }
50+
4151 $ cacheSystem = $ forcedCacheSystem ?: esc_attr (get_option ('crowdsec_cache_system ' ));
4252 switch ($ cacheSystem ) {
4353 case CROWDSEC_CACHE_SYSTEM_PHPFS :
44- return new PhpFilesAdapter ('' , 0 , __DIR__ .'/.cache ' );
54+ $ crowdSecCacheAdapterInstance = new PhpFilesAdapter ('' , 0 , CROWDSEC_CACHE_PATH );
55+ break ;
4556
4657 case CROWDSEC_CACHE_SYSTEM_MEMCACHED :
4758 $ memcachedDsn = esc_attr (get_option ('crowdsec_memcached_dsn ' ));
4859 if (empty ($ memcachedDsn )) {
49- throw new WordpressCrowdSecBouncerException ('Memcached selected but no DSN provided. ' );
60+ throw new WordpressCrowdSecBouncerException ('The selected cache technology is Memcached. ' .
61+ ' Please set a Memcached DSN or select another cache technology. ' );
5062 }
5163
52- return new MemcachedAdapter (MemcachedAdapter::createConnection ($ memcachedDsn ));
64+ $ crowdSecCacheAdapterInstance = new MemcachedAdapter (MemcachedAdapter::createConnection ($ memcachedDsn ));
65+ break ;
5366
5467 case CROWDSEC_CACHE_SYSTEM_REDIS :
5568 $ redisDsn = esc_attr (get_option ('crowdsec_redis_dsn ' ));
5669 if (empty ($ redisDsn )) {
57- throw new WordpressCrowdSecBouncerException ('Redis selected but no DSN provided. ' );
70+ throw new WordpressCrowdSecBouncerException ('The selected cache technology is Redis. ' .
71+ ' Please set a Redis DSN or select another cache technology. ' );
5872 }
5973
60- return new RedisAdapter (RedisAdapter::createConnection ($ redisDsn ));
74+ $ crowdSecCacheAdapterInstance = new RedisAdapter (RedisAdapter::createConnection ($ redisDsn ));
75+ break ;
6176 }
77+ return $ crowdSecCacheAdapterInstance ;
6278}
6379
6480$ crowdSecBouncer = null ;
@@ -91,6 +107,9 @@ function getBouncerInstance(string $forcedCacheSystem = null): Bouncer
91107 // Init Bouncer instance
92108
93109 switch ($ bouncingLevel ) {
110+ case CROWDSEC_BOUNCING_LEVEL_DISABLED :
111+ $ maxRemediationLevel = Constants::REMEDIATION_BYPASS ;
112+ break ;
94113 case CROWDSEC_BOUNCING_LEVEL_FLEX :
95114 $ maxRemediationLevel = Constants::REMEDIATION_CAPTCHA ;
96115 break ;
0 commit comments