cacheUnset() публичный статический Метод

Removes cached information from the session
public static cacheUnset ( string $var ) : void
$var string variable name
Результат void
Пример #1
0
 /**
  * Gets advanced authentication settings
  *
  * this function DOES NOT check authentication - it just checks/provides
  * authentication credentials required to connect to the MySQL server
  * usually with $GLOBALS['dbi']->connect()
  *
  * it returns false if something is missing - which usually leads to
  * auth() which displays login form
  *
  * it returns true if all seems ok which usually leads to auth_set_user()
  *
  * it directly switches to authFails() if user inactivity timeout is reached
  *
  * @return boolean   whether we get authentication settings or not
  */
 public function authCheck()
 {
     global $conn_error;
     // 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;
     if (!empty($_REQUEST['pma_username'])) {
         // Verify Captcha if it is required.
         if (!empty($GLOBALS['cfg']['CaptchaLoginPrivateKey']) && !empty($GLOBALS['cfg']['CaptchaLoginPublicKey'])) {
             if (!empty($_POST["g-recaptcha-response"])) {
                 include_once 'libraries/plugins/auth/recaptcha/autoload.php';
                 $reCaptcha = new ReCaptcha($GLOBALS['cfg']['CaptchaLoginPrivateKey']);
                 // verify captcha status.
                 $resp = $reCaptcha->verify($_POST["g-recaptcha-response"], $_SERVER["REMOTE_ADDR"]);
                 // Check if the captcha entered is valid, if not stop the login.
                 if ($resp == null || !$resp->isSuccess()) {
                     $conn_error = __('Entered captcha is wrong, try again!');
                     return false;
                 }
             } else {
                 $conn_error = __('Please enter correct captcha!');
                 return false;
             }
         }
         // The user just logged in
         $GLOBALS['PHP_AUTH_USER'] = PMA_sanitizeMySQLUser($_REQUEST['pma_username']);
         $GLOBALS['PHP_AUTH_PW'] = empty($_REQUEST['pma_password']) ? '' : $_REQUEST['pma_password'];
         if ($GLOBALS['cfg']['AllowArbitraryServer'] && isset($_REQUEST['pma_servername'])) {
             if ($GLOBALS['cfg']['ArbitraryServerRegexp']) {
                 $parts = explode(' ', $_REQUEST['pma_servername']);
                 if (count($parts) == 2) {
                     $tmp_host = $parts[0];
                 } else {
                     $tmp_host = $_REQUEST['pma_servername'];
                 }
                 $match = preg_match($GLOBALS['cfg']['ArbitraryServerRegexp'], $tmp_host);
                 if (!$match) {
                     $conn_error = __('You are not allowed to log in to this MySQL server!');
                     return false;
                 }
             }
             $GLOBALS['pma_auth_server'] = PMA_sanitizeMySQLHost($_REQUEST['pma_servername']);
         }
         PMA_secureSession();
         return true;
     }
     // At the end, try to set the $GLOBALS['PHP_AUTH_USER']
     // and $GLOBALS['PHP_AUTH_PW'] variables from cookies
     // check cookies
     if (empty($_COOKIE['pmaUser-' . $GLOBALS['server']])) {
         return false;
     }
     $GLOBALS['PHP_AUTH_USER'] = $this->cookieDecrypt($_COOKIE['pmaUser-' . $GLOBALS['server']], $this->_getEncryptionSecret());
     // user was never logged in since session start
     if (empty($_SESSION['last_access_time'])) {
         return false;
     }
     // User inactive too long
     $last_access_time = time() - $GLOBALS['cfg']['LoginCookieValidity'];
     if ($_SESSION['last_access_time'] < $last_access_time) {
         Util::cacheUnset('is_create_db_priv');
         Util::cacheUnset('is_reload_priv');
         Util::cacheUnset('db_to_create');
         Util::cacheUnset('dbs_where_create_table_allowed');
         Util::cacheUnset('dbs_to_test');
         Util::cacheUnset('db_priv');
         Util::cacheUnset('col_priv');
         Util::cacheUnset('table_priv');
         Util::cacheUnset('proc_priv');
         $GLOBALS['no_activity'] = true;
         $this->authFails();
         if (!defined('TESTSUITE')) {
             exit;
         } else {
             return false;
         }
     }
     // check password cookie
     if (empty($_COOKIE['pmaAuth-' . $GLOBALS['server']])) {
         return false;
     }
     $auth_data = json_decode($this->cookieDecrypt($_COOKIE['pmaAuth-' . $GLOBALS['server']], $this->_getSessionEncryptionSecret()), true);
     if (!is_array($auth_data) || !isset($auth_data['password'])) {
         return false;
     }
     $GLOBALS['PHP_AUTH_PW'] = $auth_data['password'];
     if ($GLOBALS['cfg']['AllowArbitraryServer'] && !empty($auth_data['server'])) {
         $GLOBALS['pma_auth_server'] = $auth_data['server'];
     }
     $GLOBALS['from_cookie'] = true;
     return true;
 }
 /**
  * Gets advanced authentication settings
  *
  * this function DOES NOT check authentication - it just checks/provides
  * authentication credentials required to connect to the MySQL server
  * usually with $GLOBALS['dbi']->connect()
  *
  * it returns false if something is missing - which usually leads to
  * auth() which displays login form
  *
  * it returns true if all seems ok which usually leads to auth_set_user()
  *
  * it directly switches to authFails() if user inactivity timeout is reached
  *
  * @return boolean   whether we get authentication settings or not
  */
 public function authCheck()
 {
     global $conn_error;
     // 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;
     // BEGIN Swekey Integration
     if (!Swekey_Auth_check()) {
         return false;
     }
     // END Swekey Integration
     if (defined('PMA_CLEAR_COOKIES')) {
         foreach ($GLOBALS['cfg']['Servers'] as $key => $val) {
             $GLOBALS['PMA_Config']->removeCookie('pmaPass-' . $key);
             $GLOBALS['PMA_Config']->removeCookie('pmaServer-' . $key);
             $GLOBALS['PMA_Config']->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
         // according to the PHP manual we should do this before the destroy:
         //$_SESSION = array();
         if (!defined('TESTSUITE')) {
             session_destroy();
         }
         // -> delete password cookie(s)
         if ($GLOBALS['cfg']['LoginCookieDeleteAll']) {
             foreach ($GLOBALS['cfg']['Servers'] as $key => $val) {
                 $GLOBALS['PMA_Config']->removeCookie('pmaPass-' . $key);
                 if (isset($_COOKIE['pmaPass-' . $key])) {
                     unset($_COOKIE['pmaPass-' . $key]);
                 }
             }
         } else {
             $GLOBALS['PMA_Config']->removeCookie('pmaPass-' . $GLOBALS['server']);
             if (isset($_COOKIE['pmaPass-' . $GLOBALS['server']])) {
                 unset($_COOKIE['pmaPass-' . $GLOBALS['server']]);
             }
         }
     }
     if (!empty($_REQUEST['pma_username'])) {
         // Verify Captcha if it is required.
         if (!empty($GLOBALS['cfg']['CaptchaLoginPrivateKey']) && !empty($GLOBALS['cfg']['CaptchaLoginPublicKey'])) {
             if (!empty($_POST["g-recaptcha-response"])) {
                 include_once 'libraries/plugins/auth/recaptcha/autoload.php';
                 $reCaptcha = new ReCaptcha($GLOBALS['cfg']['CaptchaLoginPrivateKey']);
                 // verify captcha status.
                 $resp = $reCaptcha->verify($_POST["g-recaptcha-response"], $_SERVER["REMOTE_ADDR"]);
                 // Check if the captcha entered is valid, if not stop the login.
                 if ($resp == null || !$resp->isSuccess()) {
                     $conn_error = __('Entered captcha is wrong, try again!');
                     return false;
                 }
             } else {
                 $conn_error = __('Please enter correct captcha!');
                 return false;
             }
         }
         // 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'])) {
             if ($GLOBALS['cfg']['ArbitraryServerRegexp']) {
                 $parts = explode(' ', $_REQUEST['pma_servername']);
                 if (count($parts) == 2) {
                     $tmp_host = $parts[0];
                 } else {
                     $tmp_host = $_REQUEST['pma_servername'];
                 }
                 $match = preg_match($GLOBALS['cfg']['ArbitraryServerRegexp'], $tmp_host);
                 if (!$match) {
                     $conn_error = __('You are not allowed to log in to this MySQL server!');
                     return false;
                 }
             }
             $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']];
     }
     // check cookies
     if (empty($_COOKIE['pmaUser-' . $GLOBALS['server']]) || empty($_COOKIE['pma_iv-' . $GLOBALS['server']])) {
         return false;
     }
     $GLOBALS['PHP_AUTH_USER'] = $this->cookieDecrypt($_COOKIE['pmaUser-' . $GLOBALS['server']], $this->_getEncryptionSecret());
     // user was never logged in since session start
     if (empty($_SESSION['last_access_time'])) {
         return false;
     }
     // User inactive too long
     $last_access_time = time() - $GLOBALS['cfg']['LoginCookieValidity'];
     if ($_SESSION['last_access_time'] < $last_access_time) {
         Util::cacheUnset('is_create_db_priv');
         Util::cacheUnset('is_reload_priv');
         Util::cacheUnset('db_to_create');
         Util::cacheUnset('dbs_where_create_table_allowed');
         Util::cacheUnset('dbs_to_test');
         $GLOBALS['no_activity'] = true;
         $this->authFails();
         if (!defined('TESTSUITE')) {
             exit;
         } else {
             return false;
         }
     }
     // check password cookie
     if (empty($_COOKIE['pmaPass-' . $GLOBALS['server']])) {
         return false;
     }
     $GLOBALS['PHP_AUTH_PW'] = $this->cookieDecrypt($_COOKIE['pmaPass-' . $GLOBALS['server']], $this->_getSessionEncryptionSecret());
     if ($GLOBALS['PHP_AUTH_PW'] == "ÿ(blank)") {
         $GLOBALS['PHP_AUTH_PW'] = '';
     }
     $GLOBALS['from_cookie'] = true;
     return true;
 }