From 47b3491f3ac376caae5fa4fcad02ea398930890b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horva=CC=81th=20Ma=CC=81te=CC=81?= Date: Thu, 5 Jul 2018 23:50:24 +0200 Subject: [PATCH] Redis-custom-pass --- .devilbox/www/config.php | 8 +++++++- .devilbox/www/include/lib/container/Redis.php | 3 +++ docker-compose.yml | 6 ++++++ env-example | 5 +++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.devilbox/www/config.php b/.devilbox/www/config.php index 0c9f6850..d6579a74 100644 --- a/.devilbox/www/config.php +++ b/.devilbox/www/config.php @@ -128,7 +128,13 @@ function loadClass($class) { case 'Redis': loadFile($class, $cnt_dir); - $_LOADED_LIBS[$class] = \devilbox\Redis::getInstance($GLOBALS['REDIS_HOST_NAME']); + if(loadClass('Helper')->getEnv('REDIS_ROOT_PASSWORD') == ''){ + $_LOADED_LIBS[$class] = \devilbox\Redis::getInstance($GLOBALS['REDIS_HOST_NAME']); + }else{ + $_LOADED_LIBS[$class] = \devilbox\Redis::getInstance($GLOBALS['REDIS_HOST_NAME'], array( + 'pass' => loadClass('Helper')->getEnv('REDIS_ROOT_PASSWORD'), + )); + } break; case 'Memcd': diff --git a/.devilbox/www/include/lib/container/Redis.php b/.devilbox/www/include/lib/container/Redis.php index 6d2334f9..e58e000e 100644 --- a/.devilbox/www/include/lib/container/Redis.php +++ b/.devilbox/www/include/lib/container/Redis.php @@ -44,6 +44,9 @@ class Redis extends BaseClass implements BaseInterface $this->setConnectErrno(1); //loadClass('Logger')->error($this->_connect_error); } else { + if(array_key_exists('pass', $data)){ + $redis->auth($data['pass']); + } $redis->set('devilbox-version', $GLOBALS['DEVILBOX_VERSION'].' ('.$GLOBALS['DEVILBOX_DATE'].')'); $this->_redis = $redis; } diff --git a/docker-compose.yml b/docker-compose.yml index 41547f63..bfb63296 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -394,6 +394,12 @@ services: # ------------------------------------------------------------ redis: image: redis:${REDIS_SERVER:-3.2} + + # REDIS CUSTOM PASSWORD SETUP + #comment out the following 3 lines if you want to set a custom redis password, also set the redis pass variable in .env + #command: redis-server --requirepass ${REDIS_ROOT_PASSWORD} + #environment: + # - ALLOW_EMPTY_PASSWORD=yes ports: # [local-machine:]local-port:docker-port diff --git a/env-example b/env-example index d2956599..c333afe2 100644 --- a/env-example +++ b/env-example @@ -541,6 +541,11 @@ HOST_PORT_PGSQL=5432 ### HOST_PORT_REDIS=6379 +### +### Comment out to set the redis custom password also, in docker-compose.yml comment out the REDIS CUSTOM PASSWORD SETUP section +### +#REDIS_ROOT_PASSWORD=root + ################################################################################