From 8f0181616ebde5dfd8af24421be21ff3730d7bee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 14 Dec 2015 14:01:19 +0100 Subject: [PATCH] Allow to sepcify more db servers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #7 Signed-off-by: Michal Čihař --- README.md | 1 + config.inc.php | 48 +++++++++++++++++++++++++++++------------------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 55353ec..d338cc4 100644 --- a/README.md +++ b/README.md @@ -50,4 +50,5 @@ docker-compose up -d * ``PMA_ARBITRARY`` - when set to 1 connection to the arbitrary server will be allowed * ``PMA_HOST`` - define address/host name of the MySQL server * ``PMA_PORT`` - define port of the MySQL server +* ``PMA_HOSTS`` - define comma separated list of address/host names of the MySQL servers * ``PMA_USER`` and ``PMA_PASSWORD`` - define username to use for config authentication method diff --git a/config.inc.php b/config.inc.php index 9e580e0..d5760eb 100644 --- a/config.inc.php +++ b/config.inc.php @@ -7,26 +7,36 @@ if (isset($_ENV['PMA_ARBITRARY']) && $_ENV['PMA_ARBITRARY'] === '1') { $cfg['AllowArbitraryServer'] = true; } -/* First server */ -$i = 0; -$i++; -if (isset($_ENV['PMA_HOST'])) { - $cfg['Servers'][$i]['host'] = $_ENV['PMA_HOST']; -} else { - $cfg['Servers'][$i]['host'] = 'db'; +/* Figure out hosts */ + +/* Fallback to default linked */ +$hosts = array('db'); + +/* Set by environment */ +if (!empty($_ENV['PMA_HOST'])) { + $hosts = array($_ENV['PMA_HOST']); +} elseif (!empty($_ENV['PMA_HOSTS'])) { + $hosts = explode(',', $_ENV['PMA_HOSTS']); } -if (isset($_ENV['PMA_PORT'])) { - $cfg['Servers'][$i]['port'] = $_ENV['PMA_PORT']; + +/* Server settings */ +for ($i = 1; isset($hosts[$i - 1]); $i++) { + $cfg['Servers'][$i]['host'] = $hosts[$i - 1]; + if (isset($_ENV['PMA_PORT'])) { + $cfg['Servers'][$i]['port'] = $_ENV['PMA_PORT']; + } + if (isset($_ENV['PMA_USER']) && isset($_ENV['PMA_PASSWORD'])) { + $cfg['Servers'][$i]['auth_type'] = 'config'; + $cfg['Servers'][$i]['user'] = $_ENV['PMA_USER']; + $cfg['Servers'][$i]['password'] = $_ENV['PMA_PASSWORD']; + } else { + $cfg['Servers'][$i]['auth_type'] = 'cookie'; + } + $cfg['Servers'][$i]['connect_type'] = 'tcp'; + $cfg['Servers'][$i]['compress'] = false; + $cfg['Servers'][$i]['AllowNoPassword'] = true; } -if (isset($_ENV['PMA_USER']) && isset($_ENV['PMA_PASSWORD'])) { - $cfg['Servers'][$i]['auth_type'] = 'config'; - $cfg['Servers'][$i]['user'] = $_ENV['PMA_USER']; - $cfg['Servers'][$i]['password'] = $_ENV['PMA_PASSWORD']; -} else { - $cfg['Servers'][$i]['auth_type'] = 'cookie'; -} -$cfg['Servers'][$i]['connect_type'] = 'tcp'; -$cfg['Servers'][$i]['compress'] = false; -$cfg['Servers'][$i]['AllowNoPassword'] = true; + +/* Uploads setup */ $cfg['UploadDir'] = ''; $cfg['SaveDir'] = '';