Permalink
Browse files

Session management

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1173 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent 12d2c6d commit 5f8361920190869d36bafe193c4dff8650140064 jakubvrana committed Oct 6, 2009
Showing with 11 additions and 5 deletions.
  1. +7 −4 adminer/include/auth.inc.php
  2. +3 −0 adminer/include/design.inc.php
  3. +1 −1 adminer/include/functions.inc.php
@@ -1,14 +1,13 @@
<?php
$ignore = array("server", "username", "password");
-$session_name = session_name();
if (isset($_POST["server"])) {
session_regenerate_id(); // defense against session fixation
$_SESSION["usernames"][$_POST["server"]] = $_POST["username"];
$_SESSION["passwords"][$_POST["server"]] = $_POST["password"];
$_SESSION["tokens"][$_POST["server"]] = rand(1, 1e6); // defense against cross-site request forgery
if (count($_POST) == count($ignore)) {
- $location = ((string) $_GET["server"] === $_POST["server"] ? remove_from_uri() : preg_replace('~^[^?]*/([^?]*).*~', '\\1', $_SERVER["REQUEST_URI"]) . (strlen($_POST["server"]) ? '?server=' . urlencode($_POST["server"]) : ''));
- if (!isset($_COOKIE[$session_name])) {
+ $location = ((string) $_GET["server"] === $_POST["server"] ? remove_from_uri() : preg_replace('~^([^?]*).*~', '\\1', $_SERVER["REQUEST_URI"]) . (strlen($_POST["server"]) ? '?server=' . urlencode($_POST["server"]) : ''));
+ if (!isset($_COOKIE[session_name()])) {
$location .= (strpos($location, "?") === false ? "?" : "&") . SID;
}
redirect($location);
@@ -32,9 +31,13 @@
function auth_error($exception = null) {
global $ignore, $connection, $adminer;
+ $session_name = session_name();
$username = $_SESSION["usernames"][$_GET["server"]];
unset($_SESSION["usernames"][$_GET["server"]]);
- page_header(lang('Login'), (isset($username) ? h($exception ? $exception->getMessage() : (is_string($connection) ? $connection : lang('Invalid credentials.'))) : (isset($_POST["server"]) ? lang('Session support must be enabled.') : ($_POST ? lang('Session expired, please login again.') : ""))), null);
+ page_header(lang('Login'), (isset($username) ? h($exception ? $exception->getMessage() : (is_string($connection) ? $connection : lang('Invalid credentials.')))
+ : (!$_COOKIE[$session_name] && $_GET[$session_name] && ini_get("session.use_only_cookies") ? lang('Session support must be enabled.')
+ : (($_COOKIE[$session_name] || $_GET[$session_name]) && !isset($_SESSION["passwords"]) ? lang('Session expired, please login again.')
+ : ""))), null);
echo "<form action='' method='post'>\n";
$adminer->loginForm($username);
echo "<p>\n";
@@ -44,6 +44,9 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
echo "<div class='message'>" . implode("</div>\n<div class='message'>", $_SESSION["messages"]) . "</div>\n";
$_SESSION["messages"] = array();
}
+ if (!$_POST && !isset($_SESSION["passwords"])) { // used in auth
+ $_SESSION["passwords"] = array();
+ }
$databases = &$_SESSION["databases"][$_GET["server"]];
if (strlen(DB) && $databases && !in_array(DB, $databases, true)) {
$databases = null;
@@ -266,7 +266,7 @@ function queries($query = null) {
*/
function remove_from_uri($param = "") {
$param = "($param|" . session_name() . ")";
- return preg_replace("~\\?$param=[^&]*&~", '?', preg_replace("~\\?$param=[^&]*\$|&$param=[^&]*~", '', $_SERVER["REQUEST_URI"]));
+ return substr(preg_replace("~([?&])$param=[^&]*&~", '\\1', "$_SERVER[REQUEST_URI]&"), 0, -1);
}
/** Generate page number for pagination

0 comments on commit 5f83619

Please sign in to comment.