]> git.joonet.de Git - adminer.git/commitdiff
List authentications
authorJakub Vrana <jakub@vrana.cz>
Thu, 6 May 2010 12:21:22 +0000 (14:21 +0200)
committerJakub Vrana <jakub@vrana.cz>
Thu, 6 May 2010 12:21:22 +0000 (14:21 +0200)
adminer/include/adminer.inc.php
adminer/include/auth.inc.php
adminer/include/functions.inc.php
editor/include/adminer.inc.php

index e14b7eda673b01336ced4d49fd4766506cbe59d6..9bed3601e698f2f63d80c3f995494123caa9fb91 100644 (file)
@@ -483,7 +483,7 @@ document.getElementById('username').focus();
        * @return null
        */
        function navigation($missing) {
-               global $VERSION, $connection, $token, $driver;
+               global $VERSION, $connection, $token, $driver, $drivers;
                ?>
 <h1>
 <a href="http://www.adminer.org/" id="h1"><?php echo $this->name(); ?></a>
@@ -491,7 +491,22 @@ document.getElementById('username').focus();
 <a href="http://www.adminer.org/#download" id="version"><?php echo (version_compare($VERSION, $_COOKIE["adminer_version"]) < 0 ? h($_COOKIE["adminer_version"]) : ""); ?></a>
 </h1>
 <?php
-               if ($missing != "auth") {
+               if ($missing == "auth") {
+                       $first = true;
+                       foreach ((array) $_SESSION["passwords"] as $key => $servers) { // $driver is global variable
+                               foreach ($servers as $server => $usernames) {
+                                       foreach ($usernames as $username => $password) {
+                                               if (isset($password)) {
+                                                       if ($first) {
+                                                               echo "<p>\n";
+                                                               $first = false;
+                                                       }
+                                                       echo "<a href='" . h(auth_url($key, $server, $username)) . "'>($drivers[$key]) " . h($username . ($server != "" ? "@$server" : "")) . "</a><br>\n";
+                                               }
+                                       }
+                               }
+                       }
+               } else {
                        $databases = get_databases();
                        ?>
 <form action="" method="post">
index 6bf8af108b9c242505710ea95c9d7032654e47f2..1440f8a54be72df3c1ae9dadde5cf34db3bc99e8 100644 (file)
@@ -28,13 +28,7 @@ if (isset($_POST["server"])) {
                || SERVER != $_POST["server"]
                || $_GET["username"] !== $_POST["username"] // "0" == "00"
        ) {
-               preg_match('~([^?]*)\\??(.*)~', remove_from_uri(implode("|", array_keys($drivers)) . "|username|" . session_name()), $match);
-               redirect("$match[1]?"
-                       . (SID ? SID . "&" : "")
-                       . ($_POST["driver"] != "server" || $_POST["server"] != "" ? urlencode($_POST["driver"]) . "=" . urlencode($_POST["server"]) . "&" : "")
-                       . "username=" . urlencode($_POST["username"])
-                       . ($match[2] ? "&$match[2]" : "")
-               );
+               redirect(auth_url($_POST["driver"], $_POST["server"], $_POST["username"]));
        }
 } elseif ($_POST["logout"]) {
        if ($token && $_POST["token"] != $token) {
@@ -67,9 +61,10 @@ function auth_error($exception = null) {
                if (($_COOKIE[$session_name] || $_GET[$session_name]) && !$token) {
                        $error = lang('Session expired, please login again.');
                } else {
-                       $password = get_session("passwords");
+                       $password = &get_session("passwords");
                        if (isset($password)) {
                                $error = h($exception ? $exception->getMessage() : (is_string($connection) ? $connection : lang('Invalid credentials.')));
+                               $password = null;
                        }
                }
        }
index f7a30a71b12fb3bc96181a075548ab05e473a523..37a4d6beb4c03610361277806361ee5ea48ab771 100644 (file)
@@ -285,6 +285,23 @@ function set_session($key, $val) {
        $_SESSION[$key][DRIVER][SERVER][$_GET["username"]] = $val; // used also in auth.inc.php
 }
 
+/** Get authenticated URL
+* @param string
+* @param string
+* @param string
+* @return string
+*/
+function auth_url($driver, $server, $username) {
+       global $drivers;
+       preg_match('~([^?]*)\\??(.*)~', remove_from_uri(implode("|", array_keys($drivers)) . "|username|" . session_name()), $match);
+       return "$match[1]?"
+               . (SID ? SID . "&" : "")
+               . ($driver != "server" || $server != "" ? urlencode($driver) . "=" . urlencode($server) . "&" : "")
+               . "username=" . urlencode($username)
+               . ($match[2] ? "&$match[2]" : "")
+       ;
+}
+
 /** Send Location header and exit
 * @param string null to only set a message
 * @param string
index accf18797fdda367b6137d1b913fafd93c05cf1e..3c18971c5975723491d6c2fea5f9e4791d5b0d20 100644 (file)
@@ -447,7 +447,18 @@ ORDER BY ORDINAL_POSITION");
 <a href="http://www.adminer.org/editor/#download" id="version"><?php echo (version_compare($VERSION, $_COOKIE["adminer_version"]) < 0 ? h($_COOKIE["adminer_version"]) : ""); ?></a>
 </h1>
 <?php
-               if ($missing != "auth") {
+               if ($missing == "auth") {
+                       $first = true;
+                       foreach ((array) $_SESSION["passwords"]["server"][""] as $username => $password) {
+                               if (isset($password)) {
+                                       if ($first) {
+                                               echo "<p>\n";
+                                               $first = false;
+                                       }
+                                       echo "<a href='" . h(auth_url("server", "", $username)) . "'>" . h($username) . "</a><br>\n";
+                               }
+                       }
+               } else {
                        ?>
 <form action="" method="post">
 <p class="logout">