- Improved _Redis_ authentication. Added support for password param, closed #897
This commit is contained in:
@@ -712,10 +712,19 @@ class Setup extends Controller {
|
||||
// collection of DSN specific $conf array (host, port, db,..)
|
||||
$dsnData = [];
|
||||
|
||||
/**
|
||||
* @param int $dbNum
|
||||
* @param string $tag
|
||||
* @return string
|
||||
*/
|
||||
$getDbLabel = function(int $dbNum, string $tag) : string {
|
||||
return '<i class="fas fa-fw fa-database"></i> db(' . $dbNum . ') : ' . $tag;
|
||||
};
|
||||
|
||||
/**
|
||||
* get client information for a Redis client
|
||||
* @param \Redis $client
|
||||
* @param array $conf
|
||||
* @param array $conf
|
||||
* @return array
|
||||
*/
|
||||
$getClientInfo = function(\Redis $client, array $conf) : array {
|
||||
@@ -739,7 +748,7 @@ class Setup extends Controller {
|
||||
$getClientStats = function(\Redis $client) use ($f3) : array {
|
||||
$redisStats = [];
|
||||
|
||||
if($client->isConnected()){
|
||||
if($client->isConnected() && !$client->getLastError()){
|
||||
$redisServerInfo = (array)$client->info('SERVER');
|
||||
$redisClientsInfo = (array)$client->info('CLIENTS');
|
||||
$redisMemoryInfo = (array)$client->info('MEMORY');
|
||||
@@ -812,14 +821,14 @@ class Setup extends Controller {
|
||||
* @param string $tag
|
||||
* @return array
|
||||
*/
|
||||
$getDatabaseStatus = function(\Redis $client, string $tag) : array {
|
||||
$getDatabaseStatus = function(\Redis $client, string $tag) use ($getDbLabel) : array {
|
||||
$redisDatabases = [];
|
||||
if($client->isConnected()){
|
||||
if($client->isConnected() && !$client->getLastError()){
|
||||
$dbNum = $client->getDbNum();
|
||||
$dbSize = $client->dbSize();
|
||||
$redisDatabases = [
|
||||
'db_' . $dbNum => [
|
||||
'label' => '<i class="fas fa-fw fa-database"></i> db(' . $dbNum . ') : ' . $tag,
|
||||
'label' => $getDbLabel($dbNum, $tag),
|
||||
'version' => $dbSize . ' keys',
|
||||
'check' => $dbSize > 0,
|
||||
'tooltip' => 'Keys in db(' . $dbNum . ')',
|
||||
@@ -847,23 +856,28 @@ class Setup extends Controller {
|
||||
* build (modify) $redisConfig with DNS $conf data
|
||||
* @param array $conf
|
||||
*/
|
||||
$buildRedisConfig = function(array $conf) use (&$redisConfig, $getClientInfo, $getClientStats, $getDatabaseStatus){
|
||||
$buildRedisConfig = function(array $conf) use (&$redisConfig, $getDbLabel, $getClientInfo, $getClientStats, $getDatabaseStatus){
|
||||
if($conf['type'] == 'redis'){
|
||||
// is Redis -> group all DNS by host:port
|
||||
$client = new \Redis();
|
||||
$uid = $conf['host'] . ':' . $conf['port'];
|
||||
|
||||
$client = new \Redis();
|
||||
try{
|
||||
$client->pconnect($conf['host'], $conf['port'], 0.3);
|
||||
if(!empty($conf['auth'])){
|
||||
$client->auth($conf['auth']);
|
||||
}
|
||||
|
||||
if(isset($conf['db'])) {
|
||||
$client->select($conf['db']);
|
||||
}
|
||||
|
||||
$conf['db'] = $client->getDbNum();
|
||||
}catch(\RedisException $e){
|
||||
// connection failed
|
||||
// connection failed, getLastError() is called further down
|
||||
}
|
||||
|
||||
if(!array_key_exists($uid = $conf['host'] . ':' . $conf['port'], $redisConfig)){
|
||||
if(!array_key_exists($uid, $redisConfig)){
|
||||
$redisConfig[$uid] = $getClientInfo($client, $conf);
|
||||
$redisConfig[$uid]['status'] = $getClientStats($client) + $getDatabaseStatus($client, $conf['tag']);
|
||||
}elseif(!array_key_exists($uidDb = 'db_' . $conf['db'], $redisConfig[$uid]['status'])){
|
||||
@@ -872,6 +886,13 @@ class Setup extends Controller {
|
||||
$redisConfig[$uid]['status'][$uidDb]['label'] .= '; ' . $conf['tag'];
|
||||
}
|
||||
|
||||
if($error = $client->getLastError()){
|
||||
$redisConfig[$uid]['errors'][] = [
|
||||
'label' => $getDbLabel((int)$conf['db'], $conf['tag']),
|
||||
'error' => $error
|
||||
];
|
||||
}
|
||||
|
||||
$client->close();
|
||||
}
|
||||
};
|
||||
@@ -903,6 +924,7 @@ class Setup extends Controller {
|
||||
'host' => $parts['host'],
|
||||
'port' => $parts['port'],
|
||||
'db' => !empty($params['database']) ? (int)$params['database'] : 0,
|
||||
'auth' => !empty($params['auth']) ? $params['auth'] : null,
|
||||
'tag' => 'SESSION'
|
||||
];
|
||||
$dsnData[] = $conf;
|
||||
|
||||
@@ -134,6 +134,9 @@ abstract class AbstractClient extends \Prefab {
|
||||
Config::REDIS_OPT_READ_TIMEOUT
|
||||
)
|
||||
){
|
||||
if(!empty($poolConfig['auth'])){
|
||||
$client->auth($poolConfig['auth']);
|
||||
}
|
||||
|
||||
if(isset($poolConfig['tag'])){
|
||||
$name = 'pathfinder|php|tag:' . strtolower($poolConfig['tag']) . '|pid:' . getmypid();
|
||||
|
||||
@@ -596,7 +596,7 @@ class Config extends \Prefab {
|
||||
if($matches = (bool)preg_match('/^(\w+)\h*=\h*(.+)/', strtolower(trim($dsn)), $parts)){
|
||||
$conf['type'] = $parts[1];
|
||||
if($conf['type'] == 'redis'){
|
||||
[$conf['host'], $conf['port'], $conf['db']] = explode(':', $parts[2]) + [1 => 6379, 2 => null];
|
||||
[$conf['host'], $conf['port'], $conf['db'], $conf['auth']] = explode(':', $parts[2]) + [1 => 6379, 2 => null, 3 => null];
|
||||
}elseif($conf['type'] == 'folder'){
|
||||
$conf['folder'] = $parts[2];
|
||||
}
|
||||
|
||||
@@ -963,6 +963,14 @@
|
||||
</check>
|
||||
</td>
|
||||
</tr>
|
||||
<repeat group="{{ @redisInformation.errors }}" value="{{ @redisError }}">
|
||||
<tr>
|
||||
<td colspan="2">{{ @redisError.label | raw}}: {{ @redisError.error }}</td>
|
||||
<td class="text-right"><kbd class="txt-color txt-color-danger">error</kbd></td>
|
||||
<td class="text-right"><i class="fas fa-fw fa-exclamation-triangle txt-color txt-color-danger"></i></td>
|
||||
</tr>
|
||||
{{ @tplCounter('increment', 'cache_danger') }}
|
||||
</repeat>
|
||||
<tr>
|
||||
<td style="padding: 0"></td>
|
||||
<td style="padding: 0"></td>
|
||||
|
||||
Reference in New Issue
Block a user