📄 cookie.auth.lib.php
字号:
* not only if allowed * @uses $GLOBALS['PHP_AUTH_USER'] * @uses $GLOBALS['PHP_AUTH_PW'] * @uses $GLOBALS['no_activity'] * @uses $GLOBALS['server'] * @uses $GLOBALS['from_cookie'] * @uses $GLOBALS['pma_auth_server'] * @uses $cfg['blowfish_secret'] * @uses $cfg['AllowArbitraryServer'] * @uses $cfg['LoginCookieValidity'] * @uses $cfg['Servers'] * @uses $_REQUEST['old_usr'] from logout link * @uses $_REQUEST['pma_username'] from login form * @uses $_REQUEST['pma_password'] from login form * @uses $_REQUEST['pma_servername'] from login form * @uses $_COOKIE * @uses $_SESSION['last_access_time'] * @uses PMA_removeCookie() * @uses PMA_blowfish_decrypt() * @uses PMA_auth_fails() * @uses time() * * @return boolean whether we get authentication settings or not * * @access public */function PMA_auth_check(){ // Initialization /** * @global $GLOBALS['pma_auth_server'] the user provided server to connect to */ $GLOBALS['pma_auth_server'] = ''; $GLOBALS['PHP_AUTH_USER'] = $GLOBALS['PHP_AUTH_PW'] = ''; $GLOBALS['from_cookie'] = false; // avoid an error in mcrypt if (empty($GLOBALS['cfg']['blowfish_secret'])) { return false; } if (defined('PMA_CLEAR_COOKIES')) { foreach($GLOBALS['cfg']['Servers'] as $key => $val) { PMA_removeCookie('pmaPass-' . $key); PMA_removeCookie('pmaServer-' . $key); PMA_removeCookie('pmaUser-' . $key); } return false; } if (! empty($_REQUEST['old_usr'])) { // The user wants to be logged out // -> delete his choices that were stored in session session_destroy(); // -> delete password cookie(s) if ($GLOBALS['cfg']['LoginCookieDeleteAll']) { foreach($GLOBALS['cfg']['Servers'] as $key => $val) { PMA_removeCookie('pmaPass-' . $key); if (isset($_COOKIE['pmaPass-' . $key])) { unset($_COOKIE['pmaPass-' . $key]); } } } else { PMA_removeCookie('pmaPass-' . $GLOBALS['server']); if (isset($_COOKIE['pmaPass-' . $GLOBALS['server']])) { unset($_COOKIE['pmaPass-' . $GLOBALS['server']]); } } } if (! empty($_REQUEST['pma_username'])) { // The user just logged in $GLOBALS['PHP_AUTH_USER'] = $_REQUEST['pma_username']; $GLOBALS['PHP_AUTH_PW'] = empty($_REQUEST['pma_password']) ? '' : $_REQUEST['pma_password']; if ($GLOBALS['cfg']['AllowArbitraryServer'] && isset($_REQUEST['pma_servername'])) { $GLOBALS['pma_auth_server'] = $_REQUEST['pma_servername']; } return true; } // At the end, try to set the $GLOBALS['PHP_AUTH_USER'] // and $GLOBALS['PHP_AUTH_PW'] variables from cookies // servername if ($GLOBALS['cfg']['AllowArbitraryServer'] && ! empty($_COOKIE['pmaServer-' . $GLOBALS['server']])) { $GLOBALS['pma_auth_server'] = $_COOKIE['pmaServer-' . $GLOBALS['server']]; } // username if (empty($_COOKIE['pmaUser-' . $GLOBALS['server']])) { return false; } $GLOBALS['PHP_AUTH_USER'] = PMA_blowfish_decrypt( $_COOKIE['pmaUser-' . $GLOBALS['server']], $GLOBALS['cfg']['blowfish_secret']); // user was never logged in since session start if (empty($_SESSION['last_access_time'])) { return false; } // User inactive too long if ($_SESSION['last_access_time'] < time() - $GLOBALS['cfg']['LoginCookieValidity']) { $GLOBALS['no_activity'] = true; PMA_auth_fails(); exit; } // password if (empty($_COOKIE['pmaPass-' . $GLOBALS['server']])) { return false; } $GLOBALS['PHP_AUTH_PW'] = PMA_blowfish_decrypt( $_COOKIE['pmaPass-' . $GLOBALS['server']], $GLOBALS['cfg']['blowfish_secret'] /* . $_SESSION['last_access_time'] */); if ($GLOBALS['PHP_AUTH_PW'] == "\xff(blank)") { $GLOBALS['PHP_AUTH_PW'] = ''; } $GLOBALS['from_cookie'] = true; return true;} // end of the 'PMA_auth_check()' function/** * Set the user and password after last checkings if required * * @uses $GLOBALS['PHP_AUTH_USER'] * @uses $GLOBALS['PHP_AUTH_PW'] * @uses $GLOBALS['server'] * @uses $GLOBALS['from_cookie'] * @uses $GLOBALS['pma_auth_server'] * @uses $cfg['Server'] * @uses $cfg['AllowArbitraryServer'] * @uses $cfg['blowfish_secret'] * @uses $cfg['LoginCookieStore'] * @uses $cfg['PmaAbsoluteUri'] * @uses $_SESSION['last_access_time'] * @uses PMA_COMING_FROM_COOKIE_LOGIN * @uses PMA_setCookie() * @uses PMA_blowfish_encrypt() * @uses PMA_removeCookie() * @uses PMA_sendHeaderLocation() * @uses time() * @uses define() * @return boolean always true * * @access public */function PMA_auth_set_user(){ global $cfg; // Ensures valid authentication mode, 'only_db', bookmark database and // table names and relation table name are used if ($cfg['Server']['user'] != $GLOBALS['PHP_AUTH_USER']) { foreach ($cfg['Servers'] as $idx => $current) { if ($current['host'] == $cfg['Server']['host'] && $current['port'] == $cfg['Server']['port'] && $current['socket'] == $cfg['Server']['socket'] && $current['ssl'] == $cfg['Server']['ssl'] && $current['connect_type'] == $cfg['Server']['connect_type'] && $current['user'] == $GLOBALS['PHP_AUTH_USER']) { $GLOBALS['server'] = $idx; $cfg['Server'] = $current; break; } } // end foreach } // end if $pma_server_changed = false; if ($GLOBALS['cfg']['AllowArbitraryServer'] && ! empty($GLOBALS['pma_auth_server']) && $cfg['Server']['host'] != $GLOBALS['pma_auth_server']) { $cfg['Server']['host'] = $GLOBALS['pma_auth_server']; $pma_server_changed = true; } $cfg['Server']['user'] = $GLOBALS['PHP_AUTH_USER']; $cfg['Server']['password'] = $GLOBALS['PHP_AUTH_PW']; $_SESSION['last_access_time'] = time(); // Name and password cookies needs to be refreshed each time // Duration = one month for username PMA_setCookie('pmaUser-' . $GLOBALS['server'], PMA_blowfish_encrypt($cfg['Server']['user'], $GLOBALS['cfg']['blowfish_secret'])); // Duration = as configured PMA_setCookie('pmaPass-' . $GLOBALS['server'], PMA_blowfish_encrypt(!empty($cfg['Server']['password']) ? $cfg['Server']['password'] : "\xff(blank)", $GLOBALS['cfg']['blowfish_secret'] /* . $_SESSION['last_access_time'] */), null, $GLOBALS['cfg']['LoginCookieStore']); // Set server cookies if required (once per session) and, in this case, force // reload to ensure the client accepts cookies if (! $GLOBALS['from_cookie']) { if ($GLOBALS['cfg']['AllowArbitraryServer']) { if (! empty($GLOBALS['pma_auth_server'])) { // Duration = one month for serverrname PMA_setCookie('pmaServer-' . $GLOBALS['server'], $cfg['Server']['host']); } else { // Delete servername cookie PMA_removeCookie('pmaServer-' . $GLOBALS['server']); } } // URL where to go: $redirect_url = $cfg['PmaAbsoluteUri'] . 'index.php'; // any parameters to pass? $url_params = array(); if (strlen($GLOBALS['db'])) { $url_params['db'] = $GLOBALS['db']; } if (strlen($GLOBALS['table'])) { $url_params['table'] = $GLOBALS['table']; } // Language change from the login panel needs to be remembered if (! empty($GLOBALS['lang'])) { $url_params['lang'] = $GLOBALS['lang']; } // any target to pass? if (! empty($GLOBALS['target']) && $GLOBALS['target'] != 'index.php') { $url_params['target'] = $GLOBALS['target']; } /** * whether we come from a fresh cookie login */ define('PMA_COMING_FROM_COOKIE_LOGIN', true); PMA_sendHeaderLocation($redirect_url . PMA_generate_common_url($url_params, '&')); exit(); } // end if return true;} // end of the 'PMA_auth_set_user()' function/** * User is not allowed to login to MySQL -> authentication failed * * prepares error message and switches to PMA_auth() which display the error * and the login form * * this function MUST exit/quit the application, * currently doen by call to PMA_auth() * * @todo $php_errormsg is invalid here!? it will never be set in this scope * @uses $GLOBALS['server'] * @uses $GLOBALS['allowDeny_forbidden'] * @uses $GLOBALS['strAccessDenied'] * @uses $GLOBALS['strNoActivity'] * @uses $GLOBALS['strCannotLogin'] * @uses $GLOBALS['no_activity'] * @uses $cfg['LoginCookieValidity'] * @uses PMA_removeCookie() * @uses PMA_getenv() * @uses PMA_DBI_getError() * @uses PMA_sanitize() * @uses PMA_auth() * @uses sprintf() * @uses basename() * @access public */function PMA_auth_fails(){ global $conn_error; // Deletes password cookie and displays the login form PMA_removeCookie('pmaPass-' . $GLOBALS['server']); if (! empty($GLOBALS['allowDeny_forbidden'])) { $conn_error = $GLOBALS['strAccessDenied']; } elseif (! empty($GLOBALS['no_activity'])) { $conn_error = sprintf($GLOBALS['strNoActivity'], $GLOBALS['cfg']['LoginCookieValidity']); // Remember where we got timeout to return on same place if (PMA_getenv('SCRIPT_NAME')) { $GLOBALS['target'] = basename(PMA_getenv('SCRIPT_NAME')); // avoid "missing parameter: field" on re-entry if ('tbl_alter.php' == $GLOBALS['target']) { $GLOBALS['target'] = 'tbl_structure.php'; } } } elseif (PMA_DBI_getError()) { $conn_error = PMA_sanitize(PMA_DBI_getError()); } elseif (isset($php_errormsg)) { $conn_error = $php_errormsg; } else { $conn_error = $GLOBALS['strCannotLogin']; } PMA_auth();} // end of the 'PMA_auth_fails()' function?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -