and |
// | Dan Wilson who builds this patch for the Debian package. |
// +--------------------------------------------------------------------------+
if (!defined('PMA_COOKIE_AUTH_INCLUDED')) {
define('PMA_COOKIE_AUTH_INCLUDED', 1);
/**
* Sorts available languages by their true names
*
* @param array the array to be sorted
* @param mixed a required parameter
*
* @return the sorted array
*
* @access private
*/
function PMA_cookie_cmp(&$a, $b)
{
return (strcmp($a[1], $b[1]));
} // end of the 'PMA_cmp()' function
/**
* Displays authentication form
*
* @global string the font face to use
* @global string the default font size to use
* @global string the big font size to use
* @global array the list of servers settings
* @global array the list of available translations
* @global string the current language
* @global integer the current server id
* @global array the array of cookie variables if register_globals is
* off
*
* @return boolean always true (no return indeed)
*
* @access public
*/
function PMA_auth()
{
global $right_font_family, $font_size, $font_bigger;
global $cfgServers, $available_languages;
global $lang, $server;
global $HTTP_COOKIE_VARS;
// Tries to get the username from cookie whatever are the values of the
// 'register_globals' and the 'variables_order' directives
if (!empty($GLOBALS['pma_cookie_username'])) {
$default_user = $GLOBALS['pma_cookie_username'];
}
else if (!empty($_COOKIE) && isset($_COOKIE['pma_cookie_username'])) {
$default_user = $_COOKIE['pma_cookie_username'];
}
else if (!empty($HTTP_COOKIE_VARS) && isset($HTTP_COOKIE_VARS['pma_cookie_username'])) {
$default_user = $HTTP_COOKIE_VARS['pma_cookie_username'];
}
$cell_align = ($GLOBALS['text_dir'] == 'ltr') ? 'left' : 'right';
// Title
?>
delete password cookie
if (!empty($old_usr)) {
setcookie('pma_cookie_password', '');
}
// The user just logged in
else if (!empty($pma_username)) {
$PHP_AUTH_USER = $pma_username;
$PHP_AUTH_PW = (empty($pma_password)) ? '' : $pma_password;
}
// At the end, try to set the $PHP_AUTH_USER & $PHP_AUTH_PW variables
// from cookies whatever are the values of the 'register_globals' and
// the 'variables_order' directives
else {
if (!empty($pma_cookie_username)) {
$PHP_AUTH_USER = $pma_cookie_username;
}
else if (!empty($_COOKIE) && isset($_COOKIE['pma_cookie_username'])) {
$PHP_AUTH_USER = $_COOKIE['pma_cookie_username'];
}
else if (!empty($HTTP_COOKIE_VARS) && isset($HTTP_COOKIE_VARS['pma_cookie_username'])) {
$PHP_AUTH_USER = $HTTP_COOKIE_VARS['pma_cookie_username'];
}
if (!empty($pma_cookie_password)) {
$PHP_AUTH_PW = $pma_cookie_password;
$from_cookie = TRUE;
}
else if (!empty($_COOKIE) && isset($_COOKIE['pma_cookie_password'])) {
$PHP_AUTH_PW = $_COOKIE['pma_cookie_password'];
$from_cookie = TRUE;
}
else if (!empty($HTTP_COOKIE_VARS) && isset($HTTP_COOKIE_VARS['pma_cookie_password'])) {
$PHP_AUTH_PW = $HTTP_COOKIE_VARS['pma_cookie_password'];
$from_cookie = TRUE;
}
}
// Returns whether we get authentication settings or not
if (empty($PHP_AUTH_USER)) {
return FALSE;
} else {
if (get_magic_quotes_gpc()) {
$PHP_AUTH_USER = stripslashes($PHP_AUTH_USER);
$PHP_AUTH_PW = stripslashes($PHP_AUTH_PW);
}
return TRUE;
}
} // end of the 'PMA_auth_check()' function
/**
* Set the user and password after last checkings if required
*
* @global array the valid servers settings
* @global integer the id of the current server
* @global array the current server settings
* @global string the current username
* @global string the current password
* @global boolean whether the login/password pair has been grabbed from
* a cookie or not
*
* @return boolean always true
*
* @access public
*/
function PMA_auth_set_user()
{
global $cfgServers, $server, $cfgServer;
global $PHP_AUTH_USER, $PHP_AUTH_PW;
global $from_cookie;
// Ensures the valid 'only_db' setting is used
if ($cfgServer['user'] != $PHP_AUTH_USER) {
$servers_cnt = count($cfgServers);
for ($i = 1; $i <= $servers_cnt; $i++) {
if (isset($cfgServers[$i])
&& ($cfgServers[$i]['host'] == $cfgServer['host'] && $cfgServers[$i]['user'] == $PHP_AUTH_USER)) {
$server = $i;
$cfgServer = $cfgServers[$i];
break;
}
} // end for
} // end if
$cfgServer['user'] = $PHP_AUTH_USER;
$cfgServer['password'] = $PHP_AUTH_PW;
// Set cookies if required (once per session)
if (!$from_cookie) {
// Duration = one month for username
setcookie('pma_cookie_username', $cfgServer['user'], time() + (60 * 60 * 24 * 30));
// Duration = till the browser is closed for password
setcookie('pma_cookie_password', $cfgServer['password']);
}
return TRUE;
} // end of the 'PMA_auth_set_user()' function
/**
* User is not allowed to login to MySQL -> authentication failed
*
* @return boolean always true (no return indeed)
*
* @access public
*/
function PMA_auth_fails()
{
// Deletes password cookie and displays the login form
setcookie('pma_cookie_password', '');
PMA_auth();
return TRUE;
} // end of the 'PMA_auth()' function
} // $__PMA_COOKIE_AUTH_LIB__
?>