]> git.joonet.de Git - adminer.git/commitdiff
Allow connecting to different drivers in login-servers
authorJakub Vrana <jakub@vrana.cz>
Thu, 22 Feb 2018 11:38:22 +0000 (12:38 +0100)
committerJakub Vrana <jakub@vrana.cz>
Thu, 22 Feb 2018 11:38:22 +0000 (12:38 +0100)
adminer/include/adminer.inc.php
editor/include/adminer.inc.php
plugins/login-otp.php
plugins/login-servers.php
plugins/plugin.php

index ba332f91058034d503de64734eb495c4a626d92c..56345db8be1dffb6f92f6aaca06b493d9d1c6a7d 100644 (file)
@@ -119,11 +119,11 @@ class Adminer {
        function loginForm() {
                global $drivers;
                echo "<table cellspacing='0'>\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('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('db', '<tr><th>' . lang('Database') . '<td><input name="auth[db]" value="' . h($_GET["db"]) . '" autocapitalize="off">' . "\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('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('db', '<tr><th>' . lang('Database') . '<td>', '<input name="auth[db]" value="' . h($_GET["db"]) . '" autocapitalize="off">' . "\n");
                echo "</table>\n";
                echo "<p><input type='submit' value='" . lang('Login') . "'>\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
index 9e37413025356ed39c8e54228018bc481e30803f..316c863555659f0848b32279c57718e50dab674c 100644 (file)
@@ -72,15 +72,15 @@ class Adminer {
 
        function loginForm() {
                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('password', '<tr><th>' . lang('Password') . '<td><input type="password" name="auth[password]">' . "\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('password', '<tr><th>' . lang('Password') . '<td>', '<input type="password" name="auth[password]">' . "\n");
                echo "</table>\n";
                echo "<p><input type='submit' value='" . lang('Login') . "'>\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) {
index 4beddc085cc1a9aa34264bfd2fd772a91f2ea222..c6015f4b0ba4913c5a81dcaaf2afff958adcea52 100644 (file)
@@ -21,9 +21,9 @@ class AdminerLoginOtp {
                }
        }
        
-       function loginFormField($name, $default) {
+       function loginFormField($name, $heading, $value) {
                if ($name == 'password') {
-                       return $default
+                       return $heading . $value
                                . "<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"
                        ;
index 30bc5107a6f0db573af879a00777491dee28eab5..d4a789f01c31a83f6cdb1840d78d39bb5dc494fd 100644 (file)
@@ -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() {
-               ?>
-<table cellspacing="0">
-<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>
-<tr><th><?php echo lang('Username'); ?><td><input id="username" name="auth[username]" value="<?php echo h($_GET["username"]); ?>">
-<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;
+       function loginFormField($name, $heading, $value) {
+               if ($name == 'driver') {
+                       return '';
+               } elseif ($name == 'server') {
+                       return $heading . "<select name='auth[server]'>" . optionlist(array_keys($this->servers), SERVER) . "</select>\n";
+               }
        }
        
 }
index 5a5af671e4bb56045e72d8ec9e5e06791ed6361a..7e3c8dca715d3fbab555bc090f092131ade5e90a 100644 (file)
@@ -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);
        }