From 3410836c122462caf2c8ad28b07d2347c2607137 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Thu, 22 Feb 2018 12:38:22 +0100 Subject: [PATCH] Allow connecting to different drivers in login-servers --- adminer/include/adminer.inc.php | 15 ++++++----- editor/include/adminer.inc.php | 8 +++--- plugins/login-otp.php | 4 +-- plugins/login-servers.php | 47 ++++++++++++--------------------- plugins/plugin.php | 2 +- 5 files changed, 32 insertions(+), 44 deletions(-) diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index ba332f91..56345db8 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -119,11 +119,11 @@ class Adminer { function loginForm() { global $drivers; echo "\n"; - echo $this->loginFormField('driver', '
' . lang('System') . '' . html_select("auth[driver]", $drivers, DRIVER) . "\n"); - echo $this->loginFormField('server', '
' . lang('Server') . '' . "\n"); - echo $this->loginFormField('username', '
' . lang('Username') . '' . script("focus(qs('#username'));")); - echo $this->loginFormField('password', '
' . lang('Password') . '' . "\n"); - echo $this->loginFormField('db', '
' . lang('Database') . '' . "\n"); + echo $this->loginFormField('driver', '
' . lang('System') . '', html_select("auth[driver]", $drivers, DRIVER) . "\n"); + echo $this->loginFormField('server', '
' . lang('Server') . '', '' . "\n"); + echo $this->loginFormField('username', '
' . lang('Username') . '', '' . script("focus(qs('#username'));")); + echo $this->loginFormField('password', '
' . lang('Password') . '', '' . "\n"); + echo $this->loginFormField('db', '
' . lang('Database') . '', '' . "\n"); echo "
\n"; echo "

\n"; echo checkbox("auth[permanent]", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n"; @@ -132,10 +132,11 @@ class Adminer { /** Get login form field * @param string * @param string HTML + * @param string HTML * @return string */ - function loginFormField($name, $default) { - return $default; + function loginFormField($name, $heading, $value) { + return $heading . $value; } /** Authorize the user diff --git a/editor/include/adminer.inc.php b/editor/include/adminer.inc.php index 9e374130..316c8635 100644 --- a/editor/include/adminer.inc.php +++ b/editor/include/adminer.inc.php @@ -72,15 +72,15 @@ class Adminer { function loginForm() { echo "\n"; - echo $this->loginFormField('username', '
' . lang('Username') . '' . script("focus(qs('#username'));")); - echo $this->loginFormField('password', '
' . lang('Password') . '' . "\n"); + echo $this->loginFormField('username', '
' . lang('Username') . '', '' . script("focus(qs('#username'));")); + echo $this->loginFormField('password', '
' . lang('Password') . '', '' . "\n"); echo "
\n"; echo "

\n"; echo checkbox("auth[permanent]", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n"; } - function loginFormField($name, $default) { - return $default; + function loginFormField($name, $heading, $value) { + return $heading . $value; } function login($login, $password) { diff --git a/plugins/login-otp.php b/plugins/login-otp.php index 4beddc08..c6015f4b 100644 --- a/plugins/login-otp.php +++ b/plugins/login-otp.php @@ -21,9 +21,9 @@ class AdminerLoginOtp { } } - function loginFormField($name, $default) { + function loginFormField($name, $heading, $value) { if ($name == 'password') { - return $default + return $heading . $value . "OTP" . "\n" ; diff --git a/plugins/login-servers.php b/plugins/login-servers.php index 30bc5107..d4a789f0 100644 --- a/plugins/login-servers.php +++ b/plugins/login-servers.php @@ -8,48 +8,35 @@ */ class AdminerLoginServers { /** @access protected */ - var $servers, $driver; + var $servers; /** Set supported servers - * @param array array($domain) or array($domain => $description) or array($category => array()) - * @param string + * @param array array($description => array("server" => , "driver" => "server|pgsql|sqlite|...")) */ - function __construct($servers, $driver = "server") { + function __construct($servers) { $this->servers = $servers; - $this->driver = $driver; + if ($_POST["auth"]) { + $key = $_POST["auth"]["server"]; + $_POST["auth"]["driver"] = $this->servers[$key]["driver"]; + } } - function serverName($server) { - return h($this->servers[$server]); + function credentials() { + return array($this->servers[SERVER]["server"], $_GET["username"], get_password()); } function login($login, $password) { - // check if server is allowed - foreach ($this->servers as $key => $val) { - $servers = $val; - if (!is_array($val)) { - $servers = array($key => $val); - } - foreach ($servers as $k => $v) { - if ((is_string($k) ? $k : $v) == SERVER) { - return; - } - } + if (!$this->servers[SERVER]) { + return false; } - return false; } - function loginForm() { - ?> - -
-
"> -
-
-

-" . optionlist(array_keys($this->servers), SERVER) . "\n"; + } } } diff --git a/plugins/plugin.php b/plugins/plugin.php index 5a5af671..7e3c8dca 100644 --- a/plugins/plugin.php +++ b/plugins/plugin.php @@ -160,7 +160,7 @@ class AdminerPlugin extends Adminer { return $this->_applyPlugin(__FUNCTION__, $args); } - function loginFormField($name, $default) { + function loginFormField($name, $heading, $value) { $args = func_get_args(); return $this->_applyPlugin(__FUNCTION__, $args); }