home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / libraries / auth / cookie.auth.lib.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  20.2 KB  |  610 lines

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4.  * Set of functions used to run cookie based authentication.
  5.  * Thanks to Piotr Roszatycki <d3xter at users.sourceforge.net> and
  6.  * Dan Wilson who built this patch for the Debian package.
  7.  *
  8.  * @version $Id: cookie.auth.lib.php 11326 2008-06-17 21:32:48Z lem9 $
  9.  */
  10.  
  11. if (! defined('PHPMYADMIN')) {
  12.     exit;
  13. }
  14.  
  15. if (function_exists('mcrypt_encrypt') || PMA_dl('mcrypt')) {
  16.     /**
  17.      * Uses faster mcrypt library if available
  18.      */
  19.     require_once './libraries/mcrypt.lib.php';
  20. } else {
  21.     require_once './libraries/blowfish.php';
  22.     /**
  23.      * display warning in main.php
  24.      */
  25.     define('PMA_WARN_FOR_MCRYPT', 1);
  26. }
  27.  
  28.  
  29. /**
  30.  * Displays authentication form
  31.  *
  32.  * this function MUST exit/quit the application
  33.  *
  34.  * @uses    $GLOBALS['server']
  35.  * @uses    $GLOBALS['PHP_AUTH_USER']
  36.  * @uses    $GLOBALS['pma_auth_server']
  37.  * @uses    $GLOBALS['text_dir']
  38.  * @uses    $GLOBALS['pmaThemeImage']
  39.  * @uses    $GLOBALS['charset']
  40.  * @uses    $GLOBALS['target']
  41.  * @uses    $GLOBALS['db']
  42.  * @uses    $GLOBALS['table']
  43.  * @uses    $GLOBALS['PMA_errors']
  44.  * @uses    $GLOBALS['convcharset']
  45.  * @uses    $GLOBALS['lang']
  46.  * @uses    $GLOBALS['strWelcome']
  47.  * @uses    $GLOBALS['strSecretRequired']
  48.  * @uses    $GLOBALS['strError']
  49.  * @uses    $GLOBALS['strLogin']
  50.  * @uses    $GLOBALS['strLogServer']
  51.  * @uses    $GLOBALS['strLogUsername']
  52.  * @uses    $GLOBALS['strLogPassword']
  53.  * @uses    $GLOBALS['strServerChoice']
  54.  * @uses    $GLOBALS['strGo']
  55.  * @uses    $GLOBALS['strCookiesRequired']
  56.  * @uses    $GLOBALS['strPmaDocumentation']
  57.  * @uses    $GLOBALS['pmaThemeImage']
  58.  * @uses    $cfg['Servers']
  59.  * @uses    $cfg['LoginCookieRecall']
  60.  * @uses    $cfg['Lang']
  61.  * @uses    $cfg['Server']
  62.  * @uses    $cfg['ReplaceHelpImg']
  63.  * @uses    $cfg['blowfish_secret']
  64.  * @uses    $cfg['AllowArbitraryServer']
  65.  * @uses    $_COOKIE
  66.  * @uses    $_REQUEST['old_usr']
  67.  * @uses    PMA_sendHeaderLocation()
  68.  * @uses    PMA_select_language()
  69.  * @uses    PMA_select_server()
  70.  * @uses    PMA_VERSION
  71.  * @uses    file_exists()
  72.  * @uses    sprintf()
  73.  * @uses    count()
  74.  * @uses    htmlspecialchars()
  75.  * @uses    is_array()
  76.  * @global  string    the last connection error
  77.  *
  78.  * @access  public
  79.  */
  80. function PMA_auth()
  81. {
  82.     global $conn_error;
  83.  
  84.     /* Perform logout to custom URL */
  85.     if (! empty($_REQUEST['old_usr'])
  86.      && ! empty($GLOBALS['cfg']['Server']['LogoutURL'])) {
  87.         PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['LogoutURL']);
  88.         exit;
  89.     }
  90.  
  91.     if ($GLOBALS['cfg']['LoginCookieRecall']) {
  92.         $default_user   = $GLOBALS['PHP_AUTH_USER'];
  93.         $default_server = $GLOBALS['pma_auth_server'];
  94.         $autocomplete   = '';
  95.     } else {
  96.         $default_user   = '';
  97.         $default_server = '';
  98.         // skip the IE autocomplete feature.
  99.         $autocomplete   = ' autocomplete="off"';
  100.     }
  101.  
  102.     $cell_align = ($GLOBALS['text_dir'] == 'ltr') ? 'left' : 'right';
  103.  
  104.     // Defines the charset to be used
  105.     header('Content-Type: text/html; charset=' . $GLOBALS['charset']);
  106.     // Defines the "item" image depending on text direction
  107.     $item_img = $GLOBALS['pmaThemeImage'] . 'item_' . $GLOBALS['text_dir'] . '.png';
  108.  
  109.     /* HTML header */
  110.     $page_title = 'phpMyAdmin ' . PMA_VERSION;
  111.     require './libraries/header_meta_style.inc.php';
  112.     ?>
  113. <script type="text/javascript">
  114. //<![CDATA[
  115. // show login form in top frame
  116. if (top != self) {
  117.     window.top.location.href=location;
  118. }
  119. //]]>
  120. </script>
  121. </head>
  122.  
  123. <body class="loginform">
  124.  
  125.     <?php
  126.     if (file_exists('./config.header.inc.php')) {
  127.           require './config.header.inc.php';
  128.     }
  129.     ?>
  130.  
  131. <div class="container">
  132. <a href="http://www.phpmyadmin.net" target="_blank" class="logo"><?php
  133.     $logo_image = $GLOBALS['pmaThemeImage'] . 'logo_right.png';
  134.     if (@file_exists($logo_image)) {
  135.         echo '<img src="' . $logo_image . '" id="imLogo" name="imLogo" alt="phpMyAdmin" border="0" />';
  136.     } else {
  137.         echo '<img name="imLogo" id="imLogo" src="' . $GLOBALS['pmaThemeImage'] . 'pma_logo.png' . '" '
  138.            . 'border="0" width="88" height="31" alt="phpMyAdmin" />';
  139.     }
  140.     ?></a>
  141. <h1>
  142.     <?php
  143.     echo sprintf($GLOBALS['strWelcome'],
  144.         '<bdo dir="ltr" xml:lang="en">' . $page_title . '</bdo>');
  145.     ?>
  146. </h1>
  147.     <?php
  148.  
  149.     // Show error message
  150.     if (! empty($conn_error)) {
  151.         echo '<div class="error"><h1>' . $GLOBALS['strError'] . '</h1>' . "\n";
  152.         echo $conn_error . '</div>' . "\n";
  153.     }
  154.  
  155.     // Displays the languages form
  156.     if (empty($GLOBALS['cfg']['Lang'])) {
  157.         require_once './libraries/display_select_lang.lib.php';
  158.         PMA_select_language(true);
  159.     }
  160.  
  161.     // Displays the warning message and the login form
  162.     if (empty($GLOBALS['cfg']['blowfish_secret'])) {
  163.         ?>
  164.         <div class="error"><h1><?php echo $GLOBALS['strError']; ?></h1>
  165.             <?php echo $GLOBALS['strSecretRequired']; ?>
  166.         </div>
  167.         <?php
  168.         echo '</div>' . "\n";
  169.         if (file_exists('./config.footer.inc.php')) {
  170.             require './config.footer.inc.php';
  171.         }
  172.         echo '</body></html>';
  173.         exit;
  174.     }
  175.     ?>
  176. <br />
  177. <!-- Login form -->
  178. <form method="post" action="index.php" name="login_form"<?php echo $autocomplete; ?> target="_top" class="login">
  179.     <fieldset>
  180.     <legend>
  181. <?php 
  182.     echo $GLOBALS['strLogin']; 
  183.     echo '<a href="./Documentation.html" target="documentation" ' .
  184.         'title="' . $GLOBALS['strPmaDocumentation'] . '">';
  185.     if ($GLOBALS['cfg']['ReplaceHelpImg']) {
  186.         echo '<img class="icon" src="' . $GLOBALS['pmaThemeImage'] . 'b_help.png" width="11" height="11" alt="' . $GLOBALS['strPmaDocumentation'] . '" />';
  187.     } else {
  188.         echo '(*)';
  189.     }
  190.     echo '</a>';
  191. ?>
  192. </legend>
  193.  
  194. <?php if ($GLOBALS['cfg']['AllowArbitraryServer']) { ?>
  195.         <div class="item">
  196.             <label for="input_servername"><?php echo $GLOBALS['strLogServer']; ?></label>
  197.             <input type="text" name="pma_servername" id="input_servername" value="<?php echo htmlspecialchars($default_server); ?>" size="24" class="textfield" />
  198.         </div>
  199. <?php } ?>
  200.         <div class="item">
  201.             <label for="input_username"><?php echo $GLOBALS['strLogUsername']; ?></label>
  202.             <input type="text" name="pma_username" id="input_username" value="<?php echo htmlspecialchars($default_user); ?>" size="24" class="textfield" />
  203.         </div>
  204.         <div class="item">
  205.             <label for="input_password"><?php echo $GLOBALS['strLogPassword']; ?></label>
  206.             <input type="password" name="pma_password" id="input_password" value="" size="24" class="textfield" />
  207.         </div>
  208.     <?php
  209.     if (count($GLOBALS['cfg']['Servers']) > 1) {
  210.         ?>
  211.         <div class="item">
  212.             <label for="select_server"><?php echo $GLOBALS['strServerChoice']; ?>:</label>
  213.             <select name="server" id="select_server"
  214.         <?php
  215.         if ($GLOBALS['cfg']['AllowArbitraryServer']) {
  216.             echo ' onchange="document.forms[\'login_form\'].elements[\'pma_servername\'].value = \'\'" ';
  217.         }
  218.         echo '>';
  219.  
  220.         require_once './libraries/select_server.lib.php';
  221.         PMA_select_server(false, false);
  222.  
  223.         echo '</select></div>';
  224.     } else {
  225.         echo '    <input type="hidden" name="server" value="' . $GLOBALS['server'] . '" />';
  226.     } // end if (server choice)
  227.     ?>
  228.     </fieldset>
  229.     <fieldset class="tblFooters">
  230.         <input value="<?php echo $GLOBALS['strGo']; ?>" type="submit" />
  231.         <input type="hidden" name="lang" value="<?php echo $GLOBALS['lang']; ?>" />
  232.         <input type="hidden" name="convcharset" value="<?php echo htmlspecialchars($GLOBALS['convcharset'], ENT_QUOTES); ?>" />
  233.     <?php
  234.     if (!empty($GLOBALS['target'])) {
  235.         echo '            <input type="hidden" name="target" value="' . htmlspecialchars($GLOBALS['target']) . '" />' . "\n";
  236.     }
  237.     if (!empty($GLOBALS['db'])) {
  238.         echo '            <input type="hidden" name="db" value="' . htmlspecialchars($GLOBALS['db']) . '" />' . "\n";
  239.     }
  240.     if (!empty($GLOBALS['table'])) {
  241.         echo '            <input type="hidden" name="table" value="' . htmlspecialchars($GLOBALS['table']) . '" />' . "\n";
  242.     }
  243.     ?>
  244.     </fieldset>
  245. </form>
  246.     <?php
  247.     // show the "Cookies required" message only if cookies are disabled
  248.     // (we previously tried to set some cookies)
  249.     if (empty($_COOKIE)) {
  250.         echo '<div class="notice">' . $GLOBALS['strCookiesRequired'] . '</div>' . "\n";
  251.     }
  252.     if (! empty($GLOBALS['PMA_errors']) && is_array($GLOBALS['PMA_errors'])) {
  253.         foreach ($GLOBALS['PMA_errors'] as $error) {
  254.             echo '<div class="error">' . $error . '</div>' . "\n";
  255.         }
  256.     }
  257.     // the warning is also displayed on main page but show it also here,
  258.     // because on some PHP versions running on 64-bit, the blowfish library
  259.     // does not work and this would prevent login
  260.     if (defined('PMA_WARN_FOR_MCRYPT')) {
  261.         echo '<div class="warning">' . PMA_sanitize(sprintf($GLOBALS['strCantLoad'], 'mcrypt')) . '</div>' . "\n";
  262.     }
  263.     ?>
  264. </div>
  265. <script type="text/javascript">
  266. // <![CDATA[
  267. function PMA_focusInput()
  268. {
  269.     var input_username = document.getElementById('input_username');
  270.     var input_password = document.getElementById('input_password');
  271.     if (input_username.value == '') {
  272.         input_username.focus();
  273.     } else {
  274.         input_password.focus();
  275.     }
  276. }
  277.  
  278. window.setTimeout('PMA_focusInput()', 500);
  279. // ]]>
  280. </script>
  281. </body>
  282. </html>
  283.     <?php
  284.     if (file_exists('./config.footer.inc.php')) {
  285.          require './config.footer.inc.php';
  286.     }
  287.     exit;
  288. } // end of the 'PMA_auth()' function
  289.  
  290.  
  291. /**
  292.  * Gets advanced authentication settings
  293.  *
  294.  * this function DOES NOT check authentication - it just checks/provides
  295.  * authentication credentials required to connect to the MySQL server
  296.  * usally with PMA_DBI_connect()
  297.  *
  298.  * it returns false if there is missing something - which usally leads to
  299.  * PMA_auth() which displays login form
  300.  *
  301.  * it returns true if all seems ok which usally leads to PMA_auth_set_user()
  302.  *
  303.  * it directly switches to PMA_auth_fails() if user inactivity timout is reached
  304.  *
  305.  * @todo    AllowArbitraryServer on does not imply that the user wnats an
  306.  *          arbitrary server, or? so we should also check if this is filled and
  307.  *          not only if allowed
  308.  * @uses    $GLOBALS['PHP_AUTH_USER']
  309.  * @uses    $GLOBALS['PHP_AUTH_PW']
  310.  * @uses    $GLOBALS['no_activity']
  311.  * @uses    $GLOBALS['server']
  312.  * @uses    $GLOBALS['from_cookie']
  313.  * @uses    $GLOBALS['pma_auth_server']
  314.  * @uses    $cfg['blowfish_secret']
  315.  * @uses    $cfg['AllowArbitraryServer']
  316.  * @uses    $cfg['LoginCookieValidity']
  317.  * @uses    $cfg['Servers']
  318.  * @uses    $_REQUEST['old_usr'] from logout link
  319.  * @uses    $_REQUEST['pma_username'] from login form
  320.  * @uses    $_REQUEST['pma_password'] from login form
  321.  * @uses    $_REQUEST['pma_servername'] from login form
  322.  * @uses    $_COOKIE
  323.  * @uses    $_SESSION['last_access_time']
  324.  * @uses    PMA_removeCookie()
  325.  * @uses    PMA_blowfish_decrypt()
  326.  * @uses    PMA_auth_fails()
  327.  * @uses    time()
  328.  *
  329.  * @return  boolean   whether we get authentication settings or not
  330.  *
  331.  * @access  public
  332.  */
  333. function PMA_auth_check()
  334. {
  335.     // Initialization
  336.     /**
  337.      * @global $GLOBALS['pma_auth_server'] the user provided server to connect to
  338.      */
  339.     $GLOBALS['pma_auth_server'] = '';
  340.  
  341.     $GLOBALS['PHP_AUTH_USER'] = $GLOBALS['PHP_AUTH_PW'] = '';
  342.     $GLOBALS['from_cookie'] = false;
  343.  
  344.     // avoid an error in mcrypt
  345.     if (empty($GLOBALS['cfg']['blowfish_secret'])) {
  346.         return false;
  347.     }
  348.  
  349.     if (defined('PMA_CLEAR_COOKIES')) {
  350.         foreach($GLOBALS['cfg']['Servers'] as $key => $val) {
  351.             PMA_removeCookie('pmaPass-' . $key);
  352.             PMA_removeCookie('pmaServer-' . $key);
  353.             PMA_removeCookie('pmaUser-' . $key);
  354.         }
  355.         return false;
  356.     }
  357.  
  358.     if (! empty($_REQUEST['old_usr'])) {
  359.         // The user wants to be logged out 
  360.         // -> delete his choices that were stored in session 
  361.         session_destroy(); 
  362.         // -> delete password cookie(s)
  363.         if ($GLOBALS['cfg']['LoginCookieDeleteAll']) {
  364.             foreach($GLOBALS['cfg']['Servers'] as $key => $val) {
  365.                 PMA_removeCookie('pmaPass-' . $key);
  366.                 if (isset($_COOKIE['pmaPass-' . $key])) {
  367.                     unset($_COOKIE['pmaPass-' . $key]);
  368.                 }
  369.             }
  370.         } else {
  371.             PMA_removeCookie('pmaPass-' . $GLOBALS['server']);
  372.             if (isset($_COOKIE['pmaPass-' . $GLOBALS['server']])) {
  373.                 unset($_COOKIE['pmaPass-' . $GLOBALS['server']]);
  374.             }
  375.         }
  376.     }
  377.  
  378.     if (! empty($_REQUEST['pma_username'])) {
  379.         // The user just logged in
  380.         $GLOBALS['PHP_AUTH_USER'] = $_REQUEST['pma_username'];
  381.         $GLOBALS['PHP_AUTH_PW']   = empty($_REQUEST['pma_password']) ? '' : $_REQUEST['pma_password'];
  382.         if ($GLOBALS['cfg']['AllowArbitraryServer'] && isset($_REQUEST['pma_servername'])) {
  383.             $GLOBALS['pma_auth_server'] = $_REQUEST['pma_servername'];
  384.         }
  385.         return true;
  386.     }
  387.  
  388.     // At the end, try to set the $GLOBALS['PHP_AUTH_USER']
  389.     // and $GLOBALS['PHP_AUTH_PW'] variables from cookies
  390.  
  391.     // servername
  392.     if ($GLOBALS['cfg']['AllowArbitraryServer']
  393.      && ! empty($_COOKIE['pmaServer-' . $GLOBALS['server']])) {
  394.         $GLOBALS['pma_auth_server'] = $_COOKIE['pmaServer-' . $GLOBALS['server']];
  395.     }
  396.  
  397.     // username
  398.     if (empty($_COOKIE['pmaUser-' . $GLOBALS['server']])) {
  399.         return false;
  400.     }
  401.  
  402.     $GLOBALS['PHP_AUTH_USER'] = PMA_blowfish_decrypt(
  403.         $_COOKIE['pmaUser-' . $GLOBALS['server']],
  404.         $GLOBALS['cfg']['blowfish_secret']);
  405.  
  406.     // user was never logged in since session start
  407.     if (empty($_SESSION['last_access_time'])) {
  408.         return false;
  409.     }
  410.  
  411.     // User inactive too long
  412.     if ($_SESSION['last_access_time'] < time() - $GLOBALS['cfg']['LoginCookieValidity']) {
  413.         $GLOBALS['no_activity'] = true;
  414.         PMA_auth_fails();
  415.         exit;
  416.     }
  417.  
  418.     // password
  419.     if (empty($_COOKIE['pmaPass-' . $GLOBALS['server']])) {
  420.         return false;
  421.     }
  422.  
  423.     $GLOBALS['PHP_AUTH_PW'] = PMA_blowfish_decrypt(
  424.         $_COOKIE['pmaPass-' . $GLOBALS['server']],
  425.         $GLOBALS['cfg']['blowfish_secret'] /* . $_SESSION['last_access_time'] */);
  426.  
  427.     if ($GLOBALS['PHP_AUTH_PW'] == "\xff(blank)") {
  428.         $GLOBALS['PHP_AUTH_PW'] = '';
  429.     }
  430.  
  431.     $GLOBALS['from_cookie'] = true;
  432.  
  433.     return true;
  434. } // end of the 'PMA_auth_check()' function
  435.  
  436.  
  437. /**
  438.  * Set the user and password after last checkings if required
  439.  *
  440.  * @uses    $GLOBALS['PHP_AUTH_USER']
  441.  * @uses    $GLOBALS['PHP_AUTH_PW']
  442.  * @uses    $GLOBALS['server']
  443.  * @uses    $GLOBALS['from_cookie']
  444.  * @uses    $GLOBALS['pma_auth_server']
  445.  * @uses    $cfg['Server']
  446.  * @uses    $cfg['AllowArbitraryServer']
  447.  * @uses    $cfg['blowfish_secret']
  448.  * @uses    $cfg['LoginCookieStore']
  449.  * @uses    $cfg['PmaAbsoluteUri']
  450.  * @uses    $_SESSION['last_access_time']
  451.  * @uses    PMA_COMING_FROM_COOKIE_LOGIN
  452.  * @uses    PMA_setCookie()
  453.  * @uses    PMA_blowfish_encrypt()
  454.  * @uses    PMA_removeCookie()
  455.  * @uses    PMA_sendHeaderLocation()
  456.  * @uses    time()
  457.  * @uses    define()
  458.  * @return  boolean   always true
  459.  *
  460.  * @access  public
  461.  */
  462. function PMA_auth_set_user()
  463. {
  464.     global $cfg;
  465.  
  466.     // Ensures valid authentication mode, 'only_db', bookmark database and
  467.     // table names and relation table name are used
  468.     if ($cfg['Server']['user'] != $GLOBALS['PHP_AUTH_USER']) {
  469.         foreach ($cfg['Servers'] as $idx => $current) {
  470.             if ($current['host'] == $cfg['Server']['host']
  471.              && $current['port'] == $cfg['Server']['port']
  472.              && $current['socket'] == $cfg['Server']['socket']
  473.              && $current['ssl'] == $cfg['Server']['ssl']
  474.              && $current['connect_type'] == $cfg['Server']['connect_type']
  475.              && $current['user'] == $GLOBALS['PHP_AUTH_USER']) {
  476.                 $GLOBALS['server'] = $idx;
  477.                 $cfg['Server']     = $current;
  478.                 break;
  479.             }
  480.         } // end foreach
  481.     } // end if
  482.  
  483.     $pma_server_changed = false;
  484.     if ($GLOBALS['cfg']['AllowArbitraryServer']
  485.      && ! empty($GLOBALS['pma_auth_server'])
  486.      && $cfg['Server']['host'] != $GLOBALS['pma_auth_server']) {
  487.         $cfg['Server']['host'] = $GLOBALS['pma_auth_server'];
  488.         $pma_server_changed = true;
  489.     }
  490.     $cfg['Server']['user']     = $GLOBALS['PHP_AUTH_USER'];
  491.     $cfg['Server']['password'] = $GLOBALS['PHP_AUTH_PW'];
  492.  
  493.     $_SESSION['last_access_time'] = time();
  494.  
  495.     // Name and password cookies needs to be refreshed each time
  496.     // Duration = one month for username
  497.     PMA_setCookie('pmaUser-' . $GLOBALS['server'],
  498.         PMA_blowfish_encrypt($cfg['Server']['user'],
  499.             $GLOBALS['cfg']['blowfish_secret']));
  500.  
  501.     // Duration = as configured
  502.     PMA_setCookie('pmaPass-' . $GLOBALS['server'],
  503.         PMA_blowfish_encrypt(!empty($cfg['Server']['password']) ? $cfg['Server']['password'] : "\xff(blank)",
  504.             $GLOBALS['cfg']['blowfish_secret'] /* . $_SESSION['last_access_time'] */),
  505.         null,
  506.         $GLOBALS['cfg']['LoginCookieStore']);
  507.  
  508.     // Set server cookies if required (once per session) and, in this case, force
  509.     // reload to ensure the client accepts cookies
  510.     if (! $GLOBALS['from_cookie']) {
  511.         if ($GLOBALS['cfg']['AllowArbitraryServer']) {
  512.             if (! empty($GLOBALS['pma_auth_server'])) {
  513.                 // Duration = one month for serverrname
  514.                 PMA_setCookie('pmaServer-' . $GLOBALS['server'], $cfg['Server']['host']);
  515.             } else {
  516.                 // Delete servername cookie
  517.                 PMA_removeCookie('pmaServer-' . $GLOBALS['server']);
  518.             }
  519.         }
  520.  
  521.         // URL where to go:
  522.         $redirect_url = $cfg['PmaAbsoluteUri'] . 'index.php';
  523.  
  524.         // any parameters to pass?
  525.         $url_params = array();
  526.         if (strlen($GLOBALS['db'])) {
  527.             $url_params['db'] = $GLOBALS['db'];
  528.         }
  529.         if (strlen($GLOBALS['table'])) {
  530.             $url_params['table'] = $GLOBALS['table'];
  531.         }
  532.         // Language change from the login panel needs to be remembered
  533.         if (! empty($GLOBALS['lang'])) {
  534.             $url_params['lang'] = $GLOBALS['lang'];
  535.         }
  536.         // any target to pass?
  537.         if (! empty($GLOBALS['target']) && $GLOBALS['target'] != 'index.php') {
  538.             $url_params['target'] = $GLOBALS['target'];
  539.         }
  540.  
  541.         /**
  542.          * whether we come from a fresh cookie login
  543.          */
  544.         define('PMA_COMING_FROM_COOKIE_LOGIN', true);
  545.         PMA_sendHeaderLocation($redirect_url . PMA_generate_common_url($url_params, '&'));
  546.         exit();
  547.     } // end if
  548.  
  549.     return true;
  550. } // end of the 'PMA_auth_set_user()' function
  551.  
  552.  
  553. /**
  554.  * User is not allowed to login to MySQL -> authentication failed
  555.  *
  556.  * prepares error message and switches to PMA_auth() which display the error
  557.  * and the login form
  558.  *
  559.  * this function MUST exit/quit the application,
  560.  * currently doen by call to PMA_auth()
  561.  *
  562.  * @todo    $php_errormsg is invalid here!? it will never be set in this scope
  563.  * @uses    $GLOBALS['server']
  564.  * @uses    $GLOBALS['allowDeny_forbidden']
  565.  * @uses    $GLOBALS['strAccessDenied']
  566.  * @uses    $GLOBALS['strNoActivity']
  567.  * @uses    $GLOBALS['strCannotLogin']
  568.  * @uses    $GLOBALS['no_activity']
  569.  * @uses    $cfg['LoginCookieValidity']
  570.  * @uses    PMA_removeCookie()
  571.  * @uses    PMA_getenv()
  572.  * @uses    PMA_DBI_getError()
  573.  * @uses    PMA_sanitize()
  574.  * @uses    PMA_auth()
  575.  * @uses    sprintf()
  576.  * @uses    basename()
  577.  * @access  public
  578.  */
  579. function PMA_auth_fails()
  580. {
  581.     global $conn_error;
  582.  
  583.     // Deletes password cookie and displays the login form
  584.     PMA_removeCookie('pmaPass-' . $GLOBALS['server']);
  585.  
  586.     if (! empty($GLOBALS['allowDeny_forbidden'])) {
  587.         $conn_error = $GLOBALS['strAccessDenied'];
  588.     } elseif (! empty($GLOBALS['no_activity'])) {
  589.         $conn_error = sprintf($GLOBALS['strNoActivity'], $GLOBALS['cfg']['LoginCookieValidity']);
  590.         // Remember where we got timeout to return on same place
  591.         if (PMA_getenv('SCRIPT_NAME')) {
  592.             $GLOBALS['target'] = basename(PMA_getenv('SCRIPT_NAME'));
  593.             // avoid "missing parameter: field" on re-entry
  594.             if ('tbl_alter.php' == $GLOBALS['target']) {
  595.                 $GLOBALS['target'] = 'tbl_structure.php';
  596.             }
  597.         }
  598.     } elseif (PMA_DBI_getError()) {
  599.         $conn_error = PMA_sanitize(PMA_DBI_getError());
  600.     } elseif (isset($php_errormsg)) {
  601.         $conn_error = $php_errormsg;
  602.     } else {
  603.         $conn_error = $GLOBALS['strCannotLogin'];
  604.     }
  605.  
  606.     PMA_auth();
  607. } // end of the 'PMA_auth_fails()' function
  608.  
  609. ?>
  610.