Store database to permanent login

This commit is contained in:
Jakub Vrana 2012-09-08 21:29:16 -07:00
parent 741c073c95
commit a0d00cf732
3 changed files with 16 additions and 8 deletions

View file

@ -801,7 +801,10 @@ DROP PROCEDURE adminer_alter;
echo "<p id='logins' onmouseover='menuOver(this, event);' onmouseout='menuOut(this);'>\n";
$first = false;
}
echo "<a href='" . h(auth_url($driver, $server, $username)) . "'>($drivers[$driver]) " . h($username . ($server != "" ? "@$server" : "")) . "</a><br>\n";
$dbs = $_SESSION["db"][$driver][$server][$username];
foreach (($dbs ? array_keys($dbs) : array("")) as $db) {
echo "<a href='" . h(auth_url($driver, $server, $username, $db)) . "'>($drivers[$driver]) " . h($username . ($server != "" ? "@$server" : "") . ($db != "" ? " - $db" : "")) . "</a><br>\n";
}
}
}
}

View file

@ -18,8 +18,9 @@ $auth = $_POST["auth"];
if ($auth) {
session_regenerate_id(); // defense against session fixation
$_SESSION["pwds"][$auth["driver"]][$auth["server"]][$auth["username"]] = $auth["password"];
$_SESSION["db"][$auth["driver"]][$auth["server"]][$auth["username"]][$auth["db"]] = true;
if ($auth["permanent"]) {
$key = base64_encode($auth["driver"]) . "-" . base64_encode($auth["server"]) . "-" . base64_encode($auth["username"]);
$key = base64_encode($auth["driver"]) . "-" . base64_encode($auth["server"]) . "-" . base64_encode($auth["username"]) . "-" . base64_encode($auth["db"]);
$private = $adminer->permanentLogin();
$permanent[$key] = "$key:" . base64_encode($private ? encrypt_string($auth["password"], $private) : "");
cookie("adminer_permanent", implode(" ", $permanent));
@ -38,7 +39,7 @@ if ($auth) {
page_footer("db");
exit;
} else {
foreach (array("pwds", "dbs", "queries") as $key) {
foreach (array("pwds", "db", "dbs", "queries") as $key) {
set_session($key, null);
}
unset_permanent();
@ -49,18 +50,21 @@ if ($auth) {
$private = $adminer->permanentLogin(); // try to decode even if not set
foreach ($permanent as $key => $val) {
list(, $cipher) = explode(":", $val);
list($driver, $server, $username) = array_map('base64_decode', explode("-", $key));
list($driver, $server, $username, $db) = array_map('base64_decode', explode("-", $key));
$_SESSION["pwds"][$driver][$server][$username] = decrypt_string(base64_decode($cipher), $private);
$_SESSION["db"][$driver][$server][$username][$db] = true;
}
}
function unset_permanent() {
global $permanent;
$key = base64_encode(DRIVER) . "-" . base64_encode(SERVER) . "-" . base64_encode($_GET["username"]);
if ($permanent[$key]) {
unset($permanent[$key]);
cookie("adminer_permanent", implode(" ", $permanent));
foreach ($permanent as $key => $val) {
list($driver, $server, $username) = array_map('base64_decode', explode("-", $key));
if ($driver == DRIVER && $server == SERVER && $db == $_GET["username"]) {
unset($permanent[$key]);
}
}
cookie("adminer_permanent", implode(" ", $permanent));
}
function auth_error($exception = null) {

View file

@ -4,6 +4,7 @@ Edit strings with \n in textarea
Time out long running database list and select count
Use VALUES() in INSERT+UPDATE export
Style logout button as link
Store selected database to permanent login
Ctrl+click and Shift+click on button opens form to a blank window
Switch language by POST
Compress translations