[ Index ]
 

Code source de phpMyAdmin 2.10.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/libraries/auth/ -> signon.auth.lib.php (source)

   1  <?php
   2  /* $Id: signon.auth.lib.php 9486 2006-10-03 13:12:35Z nijel $ */
   3  // vim: expandtab sw=4 ts=4 sts=4:
   4  
   5  // +--------------------------------------------------------------------------+
   6  // | Set of functions used to run single signon authentication.               |
   7  // +--------------------------------------------------------------------------+
   8  
   9  
  10  /**
  11   * Displays authentication form
  12   *
  13   * @global  string    the font face to use in case of failure
  14   * @global  string    the default font size to use in case of failure
  15   * @global  string    the big font size to use in case of failure
  16   *
  17   * @return  boolean   always true (no return indeed)
  18   *
  19   * @access  public
  20   */
  21  function PMA_auth() {
  22      if (empty($GLOBALS['cfg']['Server']['SignonURL'])) {
  23          PMA_sendHeaderLocation('error.php?error=' . urlencode('You must set SignonURL!'));
  24      } elseif (!empty($_REQUEST['old_usr']) && !empty($GLOBALS['cfg']['Server']['LogoutURL'])) {
  25          /* Perform logout to custom URL */
  26          PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['LogoutURL']);
  27      } else {
  28          PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['SignonURL']);
  29      }
  30      exit();
  31  } // end of the 'PMA_auth()' function
  32  
  33  
  34  /**
  35   * Gets advanced authentication settings
  36   *
  37   * @global  string    the username if register_globals is on
  38   * @global  string    the password if register_globals is on
  39   * @global  array     the array of server variables if register_globals is
  40   *                    off
  41   * @global  array     the array of environment variables if register_globals
  42   *                    is off
  43   * @global  string    the username for the ? server
  44   * @global  string    the password for the ? server
  45   * @global  string    the username for the WebSite Professional server
  46   * @global  string    the password for the WebSite Professional server
  47   * @global  string    the username of the user who logs out
  48   *
  49   * @return  boolean   whether we get authentication settings or not
  50   *
  51   * @access  public
  52   */
  53  function PMA_auth_check()
  54  {
  55      global $PHP_AUTH_USER, $PHP_AUTH_PW;
  56      
  57      /* Session name */
  58      $session_name = $GLOBALS['cfg']['Server']['SignonSession'];
  59  
  60      /* Are we requested to do logout? */
  61      $do_logout = !empty($_REQUEST['old_usr']);
  62  
  63      /* Does session exist? */
  64      if (isset($_COOKIE[$session_name])) {
  65          /* End current session */
  66          $old_session = session_name();
  67          $old_id = session_id();
  68          session_write_close();
  69  
  70          /* Load single signon session */
  71          session_name($session_name); 
  72          session_id($_COOKIE[$session_name]);
  73          session_start();
  74  
  75          /* Grab credentials if they exist */
  76          if (isset($_SESSION['PMA_single_signon_user'])) {
  77              if ($do_logout) {
  78                  $PHP_AUTH_USER = '';
  79              } else {
  80                  $PHP_AUTH_USER = $_SESSION['PMA_single_signon_user'];
  81              }
  82          }
  83          if (isset($_SESSION['PMA_single_signon_password'])) {
  84              if ($do_logout) {
  85                  $PHP_AUTH_PW = '';
  86              } else {
  87                  $PHP_AUTH_PW = $_SESSION['PMA_single_signon_password'];
  88              }
  89          }
  90          /* Also get token as it is needed to access subpages */
  91          if (isset($_SESSION['PMA_single_signon_token'])) {
  92              /* No need to care about token on logout */
  93              $pma_token = $_SESSION['PMA_single_signon_token'];
  94          }
  95  
  96          /* End single signon session */
  97          session_write_close();
  98  
  99          /* Restart phpMyAdmin session */
 100          session_name($old_session);
 101          if (!empty($old_id)) {
 102              session_id($old_id);
 103          }
 104          session_start();
 105  
 106          /* Restore our token */
 107          if (!empty($pma_token)) { 
 108              $_SESSION[' PMA_token '] = $pma_token;
 109          }
 110      }
 111  
 112      // Returns whether we get authentication settings or not
 113      if (empty($PHP_AUTH_USER)) {
 114          return false;
 115      } else {
 116          return true;
 117      }
 118  } // end of the 'PMA_auth_check()' function
 119  
 120  
 121  /**
 122   * Set the user and password after last checkings if required
 123   *
 124   * @global  array     the valid servers settings
 125   * @global  integer   the id of the current server
 126   * @global  array     the current server settings
 127   * @global  string    the current username
 128   * @global  string    the current password
 129   *
 130   * @return  boolean   always true
 131   *
 132   * @access  public
 133   */
 134  function PMA_auth_set_user()
 135  {
 136      global $cfg;
 137      global $PHP_AUTH_USER, $PHP_AUTH_PW;
 138  
 139      $cfg['Server']['user']     = $PHP_AUTH_USER;
 140      $cfg['Server']['password'] = $PHP_AUTH_PW;
 141  
 142      return true;
 143  } // end of the 'PMA_auth_set_user()' function
 144  
 145  
 146  /**
 147   * User is not allowed to login to MySQL -> authentication failed
 148   *
 149   * @return  boolean   always true (no return indeed)
 150   *
 151   * @access  public
 152   */
 153  function PMA_auth_fails()
 154  {
 155      $error = PMA_DBI_getError();
 156      if ($error && $GLOBALS['errno'] != 1045) {
 157          PMA_sendHeaderLocation('error.php?error=' . urlencode($error));
 158          exit;
 159      } else {
 160          PMA_auth();
 161          return true;
 162      }
 163  
 164  } // end of the 'PMA_auth_fails()' function
 165  
 166  ?>


Généré le : Mon Nov 26 15:18:20 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics