home *** CD-ROM | disk | FTP | other *** search
/ Freelog 70 / Freelog070.iso / Internet / EasyPHP / easyphp1-8_setup.exe / {app} / phpmyadmin / libraries / auth / cookie.auth.lib.php < prev    next >
Encoding:
PHP Script  |  2004-11-30  |  24.1 KB  |  631 lines

  1. <?php
  2. /* $Id: cookie.auth.lib.php,v 2.23 2004/11/30 16:12:39 lem9 Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. // +--------------------------------------------------------------------------+
  6. // | Set of functions used to run cookie based authentication.                |
  7. // | Thanks to Piotr Roszatycki <d3xter at users.sourceforge.net> and         |
  8. // | Dan Wilson who built this patch for the Debian package.                  |
  9. // +--------------------------------------------------------------------------+
  10.  
  11.  
  12. if (!isset($coming_from_common)) {
  13.    exit;
  14. }
  15.  
  16. // Gets the default font sizes
  17. PMA_setFontSizes();
  18. // Defines the cookie path and whether the server is using https or not
  19. $pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']);
  20. $cookie_path   = substr($pma_uri_parts['path'], 0, strrpos($pma_uri_parts['path'], '/'));
  21. $is_https      = (isset($pma_uri_parts['scheme']) && $pma_uri_parts['scheme'] == 'https') ? 1 : 0;
  22. $current_time  = time();
  23.  
  24. // Uses faster mcrypt library if available
  25. // (Note: mcrypt.lib.php needs $cookie_path and $is_https)
  26. // TODO: try to load mcrypt?
  27. if (function_exists('mcrypt_encrypt')) {
  28.     require_once('./libraries/mcrypt.lib.php');
  29. } else {
  30.     require_once('./libraries/blowfish.php');
  31. }
  32.  
  33. /**
  34.  * Sorts available languages by their true names
  35.  *
  36.  * @param   array   the array to be sorted
  37.  * @param   mixed   a required parameter
  38.  *
  39.  * @return  the sorted array
  40.  *
  41.  * @access  private
  42.  */
  43. function PMA_cookie_cmp(&$a, $b)
  44. {
  45.     return (strcmp($a[1], $b[1]));
  46. } // end of the 'PMA_cmp()' function
  47.  
  48.  
  49. /**
  50.  * Displays authentication form
  51.  *
  52.  * @global  string    the font face to use
  53.  * @global  string    the default font size to use
  54.  * @global  string    the big font size to use
  55.  * @global  array     the list of servers settings
  56.  * @global  array     the list of available translations
  57.  * @global  string    the current language
  58.  * @global  integer   the current server id
  59.  * @global  string    the currect charset for MySQL
  60.  * @global  array     the array of cookie variables if register_globals is
  61.  *                    off
  62.  *
  63.  * @return  boolean   always true (no return indeed)
  64.  *
  65.  * @access  public
  66.  */
  67. function PMA_auth()
  68. {
  69.     global $right_font_family, $font_size, $font_bigger;
  70.     global $cfg, $available_languages;
  71.     global $lang, $server, $convcharset;
  72.     global $conn_error;
  73.  
  74.     // Tries to get the username from cookie whatever are the values of the
  75.     // 'register_globals' and the 'variables_order' directives if last login
  76.     // should be recalled, else skip the IE autocomplete feature.
  77.     if ($cfg['LoginCookieRecall']) {
  78.         // username
  79.         // do not try to use pma_cookie_username as it was encoded differently
  80.         // in previous versions and would produce an undefined offset in blowfish
  81.         if (!empty($_COOKIE) && isset($_COOKIE['pma_cookie_username-' . $server])) {
  82.             $default_user = $_COOKIE['pma_cookie_username-' . $server];
  83.         }
  84.         $decrypted_user = isset($default_user) ? PMA_blowfish_decrypt($default_user, $GLOBALS['cfg']['blowfish_secret']) : '';
  85.         $pos = strrpos($decrypted_user, ':');
  86.         $default_user = substr($decrypted_user, 0, $pos);
  87.         // server name
  88.         if (!empty($GLOBALS['pma_cookie_servername'])) {
  89.             $default_server = $GLOBALS['pma_cookie_servername'];
  90.         }
  91.         else if (!empty($_COOKIE) && isset($_COOKIE['pma_cookie_servername-' . $server])) {
  92.             $default_server = $_COOKIE['pma_cookie_servername-' . $server];
  93.         }
  94.         if (isset($default_server) && get_magic_quotes_gpc()) {
  95.             $default_server = stripslashes($default_server);
  96.         }
  97.  
  98.         $autocomplete     = '';
  99.     }
  100.     else {
  101.         $default_user     = '';
  102.         $autocomplete     = ' autocomplete="off"';
  103.     }
  104.  
  105.     $cell_align = ($GLOBALS['text_dir'] == 'ltr') ? 'left' : 'right';
  106.  
  107.     // Defines the charset to be used
  108.     header('Content-Type: text/html; charset=' . $GLOBALS['charset']);
  109.  
  110.     require_once('./libraries/select_theme.lib.php');
  111.     // Defines the "item" image depending on text direction
  112.     $item_img = $GLOBALS['pmaThemeImage'] . 'item_ltr.png';
  113.  
  114.     // Title
  115.     ?>
  116. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  117.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  118. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $GLOBALS['available_languages'][$GLOBALS['lang']][2]; ?>" lang="<?php echo $GLOBALS['available_languages'][$GLOBALS['lang']][2]; ?>" dir="<?php echo $GLOBALS['text_dir']; ?>">
  119.  
  120. <head>
  121. <title>phpMyAdmin <?php echo PMA_VERSION; ?></title>
  122. <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $GLOBALS['charset']; ?>" />
  123. <script language="JavaScript" type="text/javascript">
  124. <!--
  125.     /* added 2004-06-10 by Michael Keck
  126.      *       we need this for Backwards-Compatibility and resolving problems
  127.      *       with non DOM browsers, which may have problems with css 2 (like NC 4)
  128.     */
  129.     var isDOM      = (typeof(document.getElementsByTagName) != 'undefined'
  130.                       && typeof(document.createElement) != 'undefined')
  131.                    ? 1 : 0;
  132.     var isIE4      = (typeof(document.all) != 'undefined'
  133.                       && parseInt(navigator.appVersion) >= 4)
  134.                    ? 1 : 0;
  135.     var isNS4      = (typeof(document.layers) != 'undefined')
  136.                    ? 1 : 0;
  137.     var capable    = (isDOM || isIE4 || isNS4)
  138.                    ? 1 : 0;
  139.     // Uggly fix for Opera and Konqueror 2.2 that are half DOM compliant
  140.     if (capable) {
  141.         if (typeof(window.opera) != 'undefined') {
  142.             var browserName = ' ' + navigator.userAgent.toLowerCase();
  143.             if ((browserName.indexOf('konqueror 7') == 0)) {
  144.                 capable = 0;
  145.             }
  146.         } else if (typeof(navigator.userAgent) != 'undefined') {
  147.             var browserName = ' ' + navigator.userAgent.toLowerCase();
  148.             if ((browserName.indexOf('konqueror') > 0) && (browserName.indexOf('konqueror/3') == 0)) {
  149.                 capable = 0;
  150.             }
  151.         } // end if... else if...
  152.     } // end if
  153.     document.writeln('<link rel="stylesheet" type="text/css" href="<?php echo defined('PMA_PATH_TO_BASEDIR') ? PMA_PATH_TO_BASEDIR : './'; ?>css/phpmyadmin.css.php?lang=<?php echo $GLOBALS['available_languages'][$GLOBALS['lang']][2]; ?>&js_frame=right&js_isDOM=' + isDOM + '" />');
  154. //-->
  155. </script>
  156. <noscript>
  157.     <link rel="stylesheet" type="text/css" href="<?php echo defined('PMA_PATH_TO_BASEDIR') ? PMA_PATH_TO_BASEDIR : './'; ?>css/phpmyadmin.css.php?lang=<?php echo $GLOBALS['available_languages'][$GLOBALS['lang']][2]; ?>&js_frame=right" />
  158. </noscript>
  159.  
  160. <base href="<?php echo $cfg['PmaAbsoluteUri']; ?>" />
  161. <script language="javascript" type="text/javascript">
  162. <!--
  163. // show login form in top frame
  164. if (top != self) {
  165.     window.top.location.href=location;
  166. }
  167. //-->
  168. </script>
  169. </head>
  170.  
  171. <body bgcolor="<?php echo $cfg['RightBgColor']; ?>">
  172.  
  173. <?php include('./config.header.inc.php'); ?>
  174.  
  175. <center>
  176. <a href="http://www.phpmyadmin.net" target="_blank"><?php
  177.     $logo_image = $GLOBALS['pmaThemeImage'] . 'logo_right.png';
  178.     if (@file_exists($logo_image)) {
  179.         echo '<img src="' . $logo_image . '" id="imLogo" name="imLogo" alt="phpMyAdmin" border="0" />';
  180.     } else {
  181.         echo '<img name="imLogo" id="imLogo" src="' . $GLOBALS['pmaThemeImage'] . 'pma_logo.png' . '" '
  182.            . 'border="0" width="88" height="31" alt="phpMyAdmin" />';
  183.     }
  184. ?></a>
  185. <h2><?php echo sprintf($GLOBALS['strWelcome'], ' phpMyAdmin ' . PMA_VERSION); ?></h2>
  186.     <?php
  187.     // Displays the languages form
  188.     if (empty($cfg['Lang'])) {
  189.         echo "\n";
  190.         ?>
  191. <!-- Language selection -->
  192. <form method="post" action="index.php" target="_top">
  193.     <input type="hidden" name="server" value="<?php echo $server; ?>" />
  194.     <table border="0" cellpadding="3" cellspacing="0">
  195.         <tr>
  196.             <td><b>Language: </b></td>
  197.             <td>
  198.     <select name="lang" dir="ltr" onchange="this.form.submit();">
  199.         <?php
  200.         echo "\n";
  201.  
  202.         uasort($available_languages, 'PMA_cookie_cmp');
  203.         foreach ($available_languages AS $id => $tmplang) {
  204.             $lang_name = ucfirst(substr(strrchr($tmplang[0], '|'), 1));
  205.             if ($lang == $id) {
  206.                 $selected = ' selected="selected"';
  207.             } else {
  208.                 $selected = '';
  209.             }
  210.             echo '        ';
  211.             echo '<option value="' . $id . '"' . $selected . '>' . $lang_name . ' (' . $id . ')</option>' . "\n";
  212.         } // end while
  213.         ?>
  214.     </select>
  215.     <input type="submit" value="<?php echo $GLOBALS['strGo']; ?>" />
  216.             </td>
  217.         </tr>
  218.         <?php
  219.     }
  220.     echo "\n\n";
  221.  
  222.     // Displays the warning message and the login form
  223.  
  224.     if ($GLOBALS['cfg']['blowfish_secret']=='') {
  225.     ?>
  226.         <tr><td colspan="2" height="5"></td></tr>
  227.         <tr>
  228.             <th colspan="2" align="left" class="tblHeadError">
  229.                 <div class="errorhead"><?php echo $GLOBALS['strError']; ?></div>
  230.             </th>
  231.         </tr>
  232.         <tr>
  233.             <td class="tblError" colspan="2" align="left"><?php echo $GLOBALS['strSecretRequired']; ?></td>
  234.         </tr>
  235. <?php
  236.         include('./config.footer.inc.php');
  237.         echo '        </table>' . "\n"
  238.            . '    </form>' . "\n"
  239.            . '    </body>' . "\n"
  240.            . '</html>';
  241.         exit();
  242.     }
  243. ?>
  244.     </table>
  245. </form>
  246. <br />
  247. <!-- Login form -->
  248. <form method="post" action="index.php" name="login_form"<?php echo $autocomplete; ?> target="_top">
  249.     <table cellpadding="3" cellspacing="0">
  250.       <tr>
  251.         <th align="left" colspan="2" class="tblHeaders" style="font-size: 14px; font-weight: bold;"><?php echo $GLOBALS['strLogin']; ?></th>
  252.     </tr>
  253.     <tr>
  254.         <td align="center" colspan="2" bgcolor="<?php echo $GLOBALS['cfg']['BgcolorOne']; ?>"><?php echo '(' . $GLOBALS['strCookiesRequired'] . ')'; ?></td>
  255.     </tr>
  256. <?php if ($GLOBALS['cfg']['AllowArbitraryServer']) { ?>
  257.     <tr>
  258.         <td align="right" bgcolor="<?php echo $GLOBALS['cfg']['BgcolorOne']; ?>"><b><?php echo $GLOBALS['strLogServer']; ?>: </b></td>
  259.         <td align="<?php echo $cell_align; ?>" bgcolor="<?php echo $GLOBALS['cfg']['BgcolorOne']; ?>">
  260.             <input type="text" name="pma_servername" value="<?php echo (isset($default_server) ? $default_server : ''); ?>" size="24" class="textfield" onfocus="this.select()" />
  261.         </td>
  262.     </tr>
  263. <?php } ?>
  264.     <tr>
  265.         <td align="right" bgcolor="<?php echo $GLOBALS['cfg']['BgcolorOne']; ?>"><b><?php echo $GLOBALS['strLogUsername']; ?> </b></td>
  266.         <td align="<?php echo $cell_align; ?>" bgcolor="<?php echo $GLOBALS['cfg']['BgcolorOne']; ?>">
  267.             <input type="text" name="pma_username" value="<?php echo (isset($default_user) ? $default_user : ''); ?>" size="24" class="textfield" onfocus="this.select()" />
  268.         </td>
  269.     </tr>
  270.     <tr>
  271.         <td align="right" bgcolor="<?php echo $GLOBALS['cfg']['BgcolorOne']; ?>"><b><?php echo $GLOBALS['strLogPassword']; ?> </b></td>
  272.         <td align="<?php echo $cell_align; ?>" bgcolor="<?php echo $GLOBALS['cfg']['BgcolorOne']; ?>">
  273.             <input type="password" name="pma_password" value="" size="24" class="textfield" onfocus="this.select()" />
  274.         </td>
  275.     </tr>
  276.     <?php
  277.     if (count($cfg['Servers']) > 1) {
  278.         echo "\n";
  279.         ?>
  280.     <tr>
  281.         <td align="right" bgcolor="<?php echo $GLOBALS['cfg']['BgcolorOne']; ?>"><b><?php echo $GLOBALS['strServerChoice']; ?>: </b></td>
  282.         <td align="<?php echo $cell_align; ?>" bgcolor="<?php echo $GLOBALS['cfg']['BgcolorOne']; ?>">
  283.             <select name="server"
  284.             <?php
  285.             if ($GLOBALS['cfg']['AllowArbitraryServer']) {
  286.                 echo ' onchange="document.forms[\'login_form\'].elements[\'pma_servername\'].value = \'\'" ';
  287.             }
  288.             ?>
  289.             >
  290.         <?php
  291.         echo "\n";
  292.         // Displays the MySQL servers choice
  293.         foreach ($cfg['Servers'] AS $key => $val) {
  294.             if (!empty($val['host']) || $val['auth_type'] == 'arbitrary') {
  295.                 echo '                <option value="' . $key . '"';
  296.                 if (!empty($server) && ($server == $key)) {
  297.                     echo ' selected="selected"';
  298.                 }
  299.                 echo '>';
  300.                 if ($val['verbose'] != '') {
  301.                     echo $val['verbose'];
  302.                 } elseif ($val['auth_type'] == 'arbitrary') {
  303.                     echo $GLOBALS['strArbitrary'];
  304.                 } else {
  305.                     echo $val['host'];
  306.                     if (!empty($val['port'])) {
  307.                         echo ':' . $val['port'];
  308.                     }
  309.                     // loic1: skip this because it's not a so good idea to
  310.                     //        display sockets used to everybody
  311.                     // if (!empty($val['socket']) && PMA_PHP_INT_VERSION >= 30010) {
  312.                     //     echo ':' . $val['socket'];
  313.                     // }
  314.                 }
  315.                 // loic1: if 'only_db' is an array and there is more than one
  316.                 //        value, displaying such informations may not be a so
  317.                 //        good idea
  318.                 if (!empty($val['only_db'])) {
  319.                     echo ' - ' . (is_array($val['only_db']) ? implode(', ', $val['only_db']) : $val['only_db']);
  320.                 }
  321.                 if (!empty($val['user']) && ($val['auth_type'] == 'basic')) {
  322.                     echo '  (' . $val['user'] . ')';
  323.                 }
  324.                 echo ' </option>' . "\n";
  325.             } // end if (!empty($val['host']))
  326.         } // end while
  327.         ?>
  328.             </select>
  329.         </td>
  330.     </tr>
  331.         <?php
  332.     } // end if (server choice)
  333.     echo "\n";
  334.     if (!empty($conn_error)) {
  335.         echo '<tr><td colspan="2" height="5"></td></tr>';
  336.         echo '<tr><th colspan="2" align="left" class="tblHeadError"><div class="errorhead">' . $GLOBALS['strError'] . '</div></th></tr>' . "\n";
  337.         echo '<tr><td colspan="2" align="left" class="tblError">'. $conn_error . '</td></tr>' . "\n";
  338.     }
  339.     ?>
  340.     <tr>
  341.         <td colspan="2" align="right">
  342.     <?php
  343.     if (count($cfg['Servers']) == 1) {
  344.         echo '    <input type="hidden" name="server" value="' . $server . '" />';
  345.     }
  346.     echo "\n";
  347.     ?>
  348.             <input type="hidden" name="lang" value="<?php echo $lang; ?>" />
  349.             <input type="hidden" name="convcharset" value="<?php echo $convcharset; ?>" />
  350.     <?php
  351.     if (isset($GLOBALS['db'])) {
  352.         echo '            <input type="hidden" name="db" value="' . htmlspecialchars($GLOBALS['db']) . '" />' . "\n";
  353.     }
  354.     ?>
  355.             <input type="submit" value="<?php echo $GLOBALS['strLogin']; ?>" id="buttonYes" />
  356.         </td>
  357.     </tr>
  358.     </table>
  359. </form>
  360. </center>
  361.  
  362. <script type="text/javascript" language="javascript">
  363. <!--
  364. var uname = document.forms['login_form'].elements['pma_username'];
  365. var pword = document.forms['login_form'].elements['pma_password'];
  366. if (uname.value == '') {
  367.     uname.focus();
  368. } else {
  369.     pword.focus();
  370. }
  371. //-->
  372. </script>
  373.  
  374. <?php include('./config.footer.inc.php'); ?>
  375.  
  376. </body>
  377.  
  378. </html>
  379.     <?php
  380.     exit();
  381.  
  382.     return TRUE;
  383. } // end of the 'PMA_auth()' function
  384.  
  385.  
  386. /**
  387.  * Gets advanced authentication settings
  388.  *
  389.  * @global  string    the username if register_globals is on
  390.  * @global  string    the password if register_globals is on
  391.  * @global  array     the array of cookie variables if register_globals is
  392.  *                    off
  393.  * @global  string    the servername sent by the login form
  394.  * @global  string    the username sent by the login form
  395.  * @global  string    the password sent by the login form
  396.  * @global  string    the username of the user who logs out
  397.  * @global  boolean   whether the login/password pair is grabbed from a
  398.  *                    cookie or not
  399.  *
  400.  * @return  boolean   whether we get authentication settings or not
  401.  *
  402.  * @access  public
  403.  */
  404. function PMA_auth_check()
  405. {
  406.     global $PHP_AUTH_USER, $PHP_AUTH_PW, $pma_auth_server;
  407.     global $pma_servername, $pma_username, $pma_password, $old_usr, $server;
  408.     global $from_cookie;
  409.  
  410.     // Initialization
  411.     $PHP_AUTH_USER = $PHP_AUTH_PW = '';
  412.     $from_cookie   = FALSE;
  413.     $from_form     = FALSE;
  414.  
  415.     // The user wants to be logged out -> delete password cookie
  416.     if (!empty($old_usr)) {
  417.         setcookie('pma_cookie_password-' . $server, '', 0, $GLOBALS['cookie_path'], '' , $GLOBALS['is_https']);
  418.     }
  419.  
  420.     // The user just logged in
  421.     else if (!empty($pma_username)) {
  422.         $PHP_AUTH_USER = $pma_username;
  423.         $PHP_AUTH_PW   = (empty($pma_password)) ? '' : $pma_password;
  424.         if ($GLOBALS['cfg']['AllowArbitraryServer']) {
  425.             $pma_auth_server = $pma_servername;
  426.         }
  427.         $from_form     = TRUE;
  428.     }
  429.  
  430.     // At the end, try to set the $PHP_AUTH_USER & $PHP_AUTH_PW variables
  431.     // from cookies whatever are the values of the 'register_globals' and
  432.     // the 'variables_order' directives
  433.     else {
  434.         if ($GLOBALS['cfg']['AllowArbitraryServer']) {
  435.             // servername
  436.             if (!empty($pma_cookie_servername)) {
  437.                 $pma_auth_server = $pma_cookie_servername;
  438.                 $from_cookie   = TRUE;
  439.             }
  440.             else if (!empty($_COOKIE) && isset($_COOKIE['pma_cookie_servername-' . $server])) {
  441.                 $pma_auth_server = $_COOKIE['pma_cookie_servername-' . $server];
  442.                 $from_cookie   = TRUE;
  443.             }
  444.         }
  445.  
  446.         // username
  447.         if (!empty($_COOKIE) && isset($_COOKIE['pma_cookie_username-' . $server])) {
  448.             $PHP_AUTH_USER = $_COOKIE['pma_cookie_username-' . $server];
  449.             $from_cookie   = TRUE;
  450.         }
  451.         $decrypted_user = PMA_blowfish_decrypt($PHP_AUTH_USER, $GLOBALS['cfg']['blowfish_secret']);
  452.         $pos = strrpos($decrypted_user, ':');
  453.         $PHP_AUTH_USER = substr($decrypted_user, 0, $pos);
  454.         $decrypted_time = (int)substr($decrypted_user, $pos + 1);
  455.  
  456.         // User inactive too long
  457.         if ($decrypted_time > 0 && $decrypted_time < $GLOBALS['current_time'] - $GLOBALS['cfg']['LoginCookieValidity']) {
  458.             // Display an error message only if the inactivity has lasted
  459.             // less than 4 times the timeout value. This is to avoid
  460.             // alerting users with a error after "much" time has passed,
  461.             // for example next morning.
  462.             if ($decrypted_time > $GLOBALS['current_time'] - ($GLOBALS['cfg']['LoginCookieValidity'] * 4)) {
  463.                 $GLOBALS['no_activity'] = TRUE;
  464.                 PMA_auth_fails();
  465.             }
  466.             return FALSE;
  467.         }
  468.  
  469.         // password
  470.         if (!empty($pma_cookie_password)) {
  471.             $PHP_AUTH_PW   = $pma_cookie_password;
  472.         }
  473.         else if (!empty($_COOKIE) && isset($_COOKIE['pma_cookie_password-' . $server])) {
  474.             $PHP_AUTH_PW   = $_COOKIE['pma_cookie_password-' . $server];
  475.         }
  476.         else {
  477.             $from_cookie   = FALSE;
  478.         }
  479.         $PHP_AUTH_PW = PMA_blowfish_decrypt($PHP_AUTH_PW, $GLOBALS['cfg']['blowfish_secret'] . $decrypted_time);
  480.  
  481.         if ($PHP_AUTH_PW == "\xff(blank)") {
  482.             $PHP_AUTH_PW   = '';
  483.         }
  484.     }
  485.  
  486.     // Returns whether we get authentication settings or not
  487.     if (!$from_cookie && !$from_form) {
  488.         return FALSE;
  489.     } elseif ($from_cookie) {
  490.         return TRUE;
  491.     } else {
  492.         // we don't need to strip here, it is done in grab_globals
  493.         return TRUE;
  494.     }
  495. } // end of the 'PMA_auth_check()' function
  496.  
  497.  
  498. /**
  499.  * Set the user and password after last checkings if required
  500.  *
  501.  * @global  array     the valid servers settings
  502.  * @global  integer   the id of the current server
  503.  * @global  array     the current server settings
  504.  * @global  string    the current username
  505.  * @global  string    the current password
  506.  * @global  boolean   whether the login/password pair has been grabbed from
  507.  *                    a cookie or not
  508.  *
  509.  * @return  boolean   always true
  510.  *
  511.  * @access  public
  512.  */
  513. function PMA_auth_set_user()
  514. {
  515.     global $cfg, $server;
  516.     global $PHP_AUTH_USER, $PHP_AUTH_PW, $pma_auth_server;
  517.     global $from_cookie;
  518.  
  519.     // Ensures valid authentication mode, 'only_db', bookmark database and
  520.     // table names and relation table name are used
  521.     if ($cfg['Server']['user'] != $PHP_AUTH_USER) {
  522.         $servers_cnt = count($cfg['Servers']);
  523.         for ($i = 1; $i <= $servers_cnt; $i++) {
  524.             if (isset($cfg['Servers'][$i])
  525.                 && ($cfg['Servers'][$i]['host'] == $cfg['Server']['host'] && $cfg['Servers'][$i]['user'] == $PHP_AUTH_USER)) {
  526.                 $server        = $i;
  527.                 $cfg['Server'] = $cfg['Servers'][$i];
  528.                 break;
  529.             }
  530.         } // end for
  531.     } // end if
  532.  
  533.     $pma_server_changed = FALSE;
  534.     if ($GLOBALS['cfg']['AllowArbitraryServer']
  535.             && isset($pma_auth_server) && !empty($pma_auth_server)
  536.             && ($cfg['Server']['host'] != $pma_auth_server)
  537.             ) {
  538.         $cfg['Server']['host'] = $pma_auth_server;
  539.         $pma_server_changed = TRUE;
  540.     }
  541.     $cfg['Server']['user']     = $PHP_AUTH_USER;
  542.     $cfg['Server']['password'] = $PHP_AUTH_PW;
  543.  
  544.     // Name and password cookies needs to be refreshed each time
  545.     // Duration = one month for username
  546.     setcookie('pma_cookie_username-' . $server,
  547.         PMA_blowfish_encrypt($cfg['Server']['user'] . ':' . $GLOBALS['current_time'],
  548.             $GLOBALS['cfg']['blowfish_secret']),
  549.         time() + (60 * 60 * 24 * 30),
  550.         $GLOBALS['cookie_path'], '',
  551.         $GLOBALS['is_https']);
  552.  
  553.     // Duration = till the browser is closed for password (we don't want this to be saved)
  554.     setcookie('pma_cookie_password-' . $server,
  555.         PMA_blowfish_encrypt(!empty($cfg['Server']['password']) ? $cfg['Server']['password'] : "\xff(blank)",
  556.             $GLOBALS['cfg']['blowfish_secret'] . $GLOBALS['current_time']),
  557.         0,
  558.         $GLOBALS['cookie_path'], '',
  559.         $GLOBALS['is_https']);
  560.  
  561.     // Set server cookies if required (once per session) and, in this case, force
  562.     // reload to ensure the client accepts cookies
  563.     if (!$from_cookie) {
  564.         if ($GLOBALS['cfg']['AllowArbitraryServer']) {
  565.             if (isset($pma_auth_server) && !empty($pma_auth_server) && $pma_server_changed) {
  566.                 // Duration = one month for serverrname
  567.                 setcookie('pma_cookie_servername-' . $server,
  568.                     $cfg['Server']['host'],
  569.                     time() + (60 * 60 * 24 * 30),
  570.                     $GLOBALS['cookie_path'], '',
  571.                     $GLOBALS['is_https']);
  572.             } else {
  573.                 // Delete servername cookie
  574.                 setcookie('pma_cookie_servername-' . $server, '', 0, $GLOBALS['cookie_path'], '' , $GLOBALS['is_https']);
  575.             }
  576.         }
  577.  
  578.         // loic1: workaround against a IIS 5.0 bug
  579.         // lem9: here, PMA_sendHeaderLocation() has not yet been defined,
  580.         //       so use the workaround
  581.         if (empty($GLOBALS['SERVER_SOFTWARE'])) {
  582.             if (isset($_SERVER) && !empty($_SERVER['SERVER_SOFTWARE'])) {
  583.                 $GLOBALS['SERVER_SOFTWARE'] = $_SERVER['SERVER_SOFTWARE'];
  584.             }
  585.         } // end if
  586.         if (!empty($GLOBALS['SERVER_SOFTWARE']) && $GLOBALS['SERVER_SOFTWARE'] == 'Microsoft-IIS/5.0') {
  587.             header('Refresh: 0; url=' . $cfg['PmaAbsoluteUri'] . 'index.php?' . PMA_generate_common_url('', '', '&'));
  588.         }
  589.         else {
  590.             header('Location: ' . $cfg['PmaAbsoluteUri'] . 'index.php?' . PMA_generate_common_url('', '', '&'));
  591.         }
  592.         exit();
  593.     } // end if
  594.  
  595.     return TRUE;
  596. } // end of the 'PMA_auth_set_user()' function
  597.  
  598.  
  599. /**
  600.  * User is not allowed to login to MySQL -> authentication failed
  601.  *
  602.  * @return  boolean   always true (no return indeed)
  603.  *
  604.  * @access  public
  605.  */
  606. function PMA_auth_fails()
  607. {
  608. global $conn_error, $server;
  609.  
  610.     // Deletes password cookie and displays the login form
  611.     setcookie('pma_cookie_password-' . $server, '', 0, $GLOBALS['cookie_path'], '' , $GLOBALS['is_https']);
  612.  
  613.     if (isset($GLOBALS['allowDeny_forbidden']) && $GLOBALS['allowDeny_forbidden']) {
  614.         $conn_error = $GLOBALS['strAccessDenied'];
  615.     } else if (isset($GLOBALS['no_activity']) && $GLOBALS['no_activity']) {
  616.         $conn_error = sprintf($GLOBALS['strNoActivity'],$GLOBALS['cfg']['LoginCookieValidity']);  
  617.     } else if (PMA_DBI_getError()) {
  618.         $conn_error = PMA_DBI_getError();
  619.     } else if (isset($php_errormsg)) {
  620.         $conn_error = $php_errormsg;
  621.     } else {
  622.         $conn_error = $GLOBALS['strCannotLogin'];
  623.     }
  624.  
  625.     PMA_auth();
  626.  
  627.     return TRUE;
  628. } // end of the 'PMA_auth_fails()' function
  629.  
  630. ?>
  631.