Allow connecting to different drivers in login-servers

This commit is contained in:
Jakub Vrana 2018-02-22 12:38:22 +01:00
parent cd503f6a0d
commit 3410836c12
5 changed files with 32 additions and 44 deletions

View file

@ -119,11 +119,11 @@ class Adminer {
function loginForm() { function loginForm() {
global $drivers; global $drivers;
echo "<table cellspacing='0'>\n"; echo "<table cellspacing='0'>\n";
echo $this->loginFormField('driver', '<tr><th>' . lang('System') . '<td>' . html_select("auth[driver]", $drivers, DRIVER) . "\n"); echo $this->loginFormField('driver', '<tr><th>' . lang('System') . '<td>', html_select("auth[driver]", $drivers, DRIVER) . "\n");
echo $this->loginFormField('server', '<tr><th>' . lang('Server') . '<td><input name="auth[server]" value="' . h(SERVER) . '" title="hostname[:port]" placeholder="localhost" autocapitalize="off">' . "\n"); echo $this->loginFormField('server', '<tr><th>' . lang('Server') . '<td>', '<input name="auth[server]" value="' . h(SERVER) . '" title="hostname[:port]" placeholder="localhost" autocapitalize="off">' . "\n");
echo $this->loginFormField('username', '<tr><th>' . lang('Username') . '<td><input name="auth[username]" id="username" value="' . h($_GET["username"]) . '" autocapitalize="off">' . script("focus(qs('#username'));")); echo $this->loginFormField('username', '<tr><th>' . lang('Username') . '<td>', '<input name="auth[username]" id="username" value="' . h($_GET["username"]) . '" autocapitalize="off">' . script("focus(qs('#username'));"));
echo $this->loginFormField('password', '<tr><th>' . lang('Password') . '<td><input type="password" name="auth[password]">' . "\n"); echo $this->loginFormField('password', '<tr><th>' . lang('Password') . '<td>', '<input type="password" name="auth[password]">' . "\n");
echo $this->loginFormField('db', '<tr><th>' . lang('Database') . '<td><input name="auth[db]" value="' . h($_GET["db"]) . '" autocapitalize="off">' . "\n"); echo $this->loginFormField('db', '<tr><th>' . lang('Database') . '<td>', '<input name="auth[db]" value="' . h($_GET["db"]) . '" autocapitalize="off">' . "\n");
echo "</table>\n"; echo "</table>\n";
echo "<p><input type='submit' value='" . lang('Login') . "'>\n"; echo "<p><input type='submit' value='" . lang('Login') . "'>\n";
echo checkbox("auth[permanent]", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n"; echo checkbox("auth[permanent]", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n";
@ -132,10 +132,11 @@ class Adminer {
/** Get login form field /** Get login form field
* @param string * @param string
* @param string HTML * @param string HTML
* @param string HTML
* @return string * @return string
*/ */
function loginFormField($name, $default) { function loginFormField($name, $heading, $value) {
return $default; return $heading . $value;
} }
/** Authorize the user /** Authorize the user

View file

@ -72,15 +72,15 @@ class Adminer {
function loginForm() { function loginForm() {
echo "<table cellspacing='0'>\n"; echo "<table cellspacing='0'>\n";
echo $this->loginFormField('username', '<tr><th>' . lang('Username') . '<td><input type="hidden" name="auth[driver]" value="server"><input name="auth[username]" id="username" value="' . h($_GET["username"]) . '" autocapitalize="off">' . script("focus(qs('#username'));")); echo $this->loginFormField('username', '<tr><th>' . lang('Username') . '<td>', '<input type="hidden" name="auth[driver]" value="server"><input name="auth[username]" id="username" value="' . h($_GET["username"]) . '" autocapitalize="off">' . script("focus(qs('#username'));"));
echo $this->loginFormField('password', '<tr><th>' . lang('Password') . '<td><input type="password" name="auth[password]">' . "\n"); echo $this->loginFormField('password', '<tr><th>' . lang('Password') . '<td>', '<input type="password" name="auth[password]">' . "\n");
echo "</table>\n"; echo "</table>\n";
echo "<p><input type='submit' value='" . lang('Login') . "'>\n"; echo "<p><input type='submit' value='" . lang('Login') . "'>\n";
echo checkbox("auth[permanent]", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n"; echo checkbox("auth[permanent]", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n";
} }
function loginFormField($name, $default) { function loginFormField($name, $heading, $value) {
return $default; return $heading . $value;
} }
function login($login, $password) { function login($login, $password) {

View file

@ -21,9 +21,9 @@ class AdminerLoginOtp {
} }
} }
function loginFormField($name, $default) { function loginFormField($name, $heading, $value) {
if ($name == 'password') { if ($name == 'password') {
return $default return $heading . $value
. "<tr><th><acronym title='One Time Password' lang='en'>OTP</acronym>" . "<tr><th><acronym title='One Time Password' lang='en'>OTP</acronym>"
. "<td><input type='number' name='auth[otp]' value='" . h($_SESSION["otp"]) . "' size='6' autocomplete='off'>\n" . "<td><input type='number' name='auth[otp]' value='" . h($_SESSION["otp"]) . "' size='6' autocomplete='off'>\n"
; ;

View file

@ -8,48 +8,35 @@
*/ */
class AdminerLoginServers { class AdminerLoginServers {
/** @access protected */ /** @access protected */
var $servers, $driver; var $servers;
/** Set supported servers /** Set supported servers
* @param array array($domain) or array($domain => $description) or array($category => array()) * @param array array($description => array("server" => , "driver" => "server|pgsql|sqlite|..."))
* @param string
*/ */
function __construct($servers, $driver = "server") { function __construct($servers) {
$this->servers = $servers; $this->servers = $servers;
$this->driver = $driver; if ($_POST["auth"]) {
$key = $_POST["auth"]["server"];
$_POST["auth"]["driver"] = $this->servers[$key]["driver"];
}
} }
function serverName($server) { function credentials() {
return h($this->servers[$server]); return array($this->servers[SERVER]["server"], $_GET["username"], get_password());
} }
function login($login, $password) { function login($login, $password) {
// check if server is allowed if (!$this->servers[SERVER]) {
foreach ($this->servers as $key => $val) { return false;
$servers = $val;
if (!is_array($val)) {
$servers = array($key => $val);
}
foreach ($servers as $k => $v) {
if ((is_string($k) ? $k : $v) == SERVER) {
return;
}
}
} }
return false;
} }
function loginForm() { function loginFormField($name, $heading, $value) {
?> if ($name == 'driver') {
<table cellspacing="0"> return '';
<tr><th><?php echo lang('Server'); ?><td><input type="hidden" name="auth[driver]" value="<?php echo $this->driver; ?>"><select name="auth[server]"><?php echo optionlist($this->servers, SERVER); ?></select> } elseif ($name == 'server') {
<tr><th><?php echo lang('Username'); ?><td><input id="username" name="auth[username]" value="<?php echo h($_GET["username"]); ?>"> return $heading . "<select name='auth[server]'>" . optionlist(array_keys($this->servers), SERVER) . "</select>\n";
<tr><th><?php echo lang('Password'); ?><td><input type="password" name="auth[password]"> }
</table>
<p><input type="submit" value="<?php echo lang('Login'); ?>">
<?php
echo checkbox("auth[permanent]", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n";
return true;
} }
} }

View file

@ -160,7 +160,7 @@ class AdminerPlugin extends Adminer {
return $this->_applyPlugin(__FUNCTION__, $args); return $this->_applyPlugin(__FUNCTION__, $args);
} }
function loginFormField($name, $default) { function loginFormField($name, $heading, $value) {
$args = func_get_args(); $args = func_get_args();
return $this->_applyPlugin(__FUNCTION__, $args); return $this->_applyPlugin(__FUNCTION__, $args);
} }