[ Index ]
 

Code source de Flux CMS 1.5

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/inc/ -> Auth.php (source)

   1  <?php
   2  /* vim: set expandtab tabstop=4 shiftwidth=4: */
   3  // +----------------------------------------------------------------------+
   4  // | PHP Version 4                                                        |
   5  // +----------------------------------------------------------------------+
   6  // | Copyright (c) 1997-2003 The PHP Group                                |
   7  // +----------------------------------------------------------------------+
   8  // | This source file is subject to version 2.02 of the PHP license,      |
   9  // | that is bundled with this package in the file LICENSE, and is        |
  10  // | available at through the world-wide-web at                           |
  11  // | http://www.php.net/license/2_02.txt.                                 |
  12  // | If you did not receive a copy of the PHP license and are unable to   |
  13  // | obtain it through the world-wide-web, please send a note to          |
  14  // | license@php.net so we can mail you a copy immediately.               |
  15  // +----------------------------------------------------------------------+
  16  // | Authors: Martin Jansen <mj@php.net>                                  |
  17  // +----------------------------------------------------------------------+
  18  //
  19  // $Id: Auth.php 8603 2007-05-02 08:48:55Z chregu $
  20  //
  21  
  22  require_once  'PEAR.php';
  23  
  24  define('AUTH_IDLED',       -1);
  25  define('AUTH_EXPIRED',     -2);
  26  define('AUTH_WRONG_LOGIN', -3);
  27  define('AUTH_SECURITY_BREACH', -4);
  28  
  29  /**
  30   * PEAR::Auth
  31   *
  32   * The PEAR::Auth class provides methods for creating an
  33   * authentication system using PHP.
  34   *
  35   * @author  Martin Jansen <mj@php.net>
  36   * @package Auth
  37   * @version $Revision: 1.77 $
  38   */
  39  class Auth {
  40  
  41      /**
  42       * Auth lifetime in seconds
  43       *
  44       * If this variable is set to 0, auth never expires
  45       *
  46       * @var  integer
  47       * @see  setExpire(), checkAuth()
  48       */
  49      var $expire = 0;
  50  
  51      /**
  52       * Has the auth session expired?
  53       *
  54       * @var   bool
  55       * @see   checkAuth(), drawLogin()
  56       */
  57      var $expired = false;
  58  
  59      /**
  60       * Maximum idletime in seconds
  61       *
  62       * The difference to $expire is, that the idletime gets
  63       * refreshed each time checkAuth() is called. If this
  64       * variable is set to 0, idletime is never checked.
  65       *
  66       * @var integer
  67       * @see setIdle(), checkAuth()
  68       */
  69      var $idle = 0;
  70  
  71      /**
  72       * Is the maximum idletime over?
  73       *
  74       * @var boolean
  75       * @see checkAuth(), drawLogin();
  76       */
  77      var $idled = false;
  78  
  79      /**
  80       * Storage object
  81       *
  82       * @var object
  83       * @see Auth(), validateLogin()
  84       */
  85      var $storage = '';
  86  
  87      /**
  88       * User-defined function that creates the login screen
  89       *
  90       * @var string
  91       */
  92      var $loginFunction = '';
  93  
  94      /**
  95       * Should the login form be displayed, and are users allowed to authenticate via this page?
  96       *
  97       * @var   bool
  98       * @see   setShowlogin()
  99       */
 100      var $showLogin = true;
 101  
 102      /**
 103       * Current authentication status
 104       *
 105       * @var string
 106       */
 107      var $status = '';
 108  
 109      /**
 110       * Username
 111       *
 112       * @var string
 113       */
 114      var $username = '';
 115  
 116      /**
 117       * Password
 118       *
 119       * @var string
 120       */
 121      var $password = '';
 122  
 123      /**
 124       * Login callback function name
 125       *
 126       * @var string
 127       * @see setLoginCallback()
 128       */
 129      var $loginCallback = '';
 130  
 131      /**
 132       * Failed Login callback function name
 133       *
 134       * @var string
 135       * @see setLoginFailedCallback()
 136       */
 137      var $loginFailedCallback = '';
 138  
 139      /**
 140       * Logout callback function name
 141       *
 142       * @var string
 143       * @see setLogoutCallback()
 144       */
 145      var $logoutCallback = '';
 146  
 147      /**
 148       * Auth session-array name
 149       *
 150       * @var string
 151       */
 152      var $_sessionName = '_authsession';
 153      
 154      /**
 155       * Package Version
 156       *
 157       * @var string
 158       */
 159      var $version = "1.3.0";
 160  
 161      /**
 162       * Flag to use advanced security
 163       * When set extra checks will be made to see if the 
 164       * user's IP or useragent have changed across requests. 
 165       * Turned off by default to preserve BC.
 166       *
 167       * @var boolean
 168       */     
 169      var $advancedsecurity = false;
 170      
 171      /**
 172       * Username key in POST array
 173       *
 174       * @var string
 175       */
 176      var $_postUsername = 'username';
 177      
 178      /**
 179       * Password key in POST array
 180       *
 181       * @var string
 182       */
 183      var $_postPassword = 'password';
 184      
 185      /**
 186       * A hash to hold various superglobals as reference
 187       * @var array
 188       */
 189      var $authdata;
 190      
 191      var $idcol = 'id';
 192  
 193      // {{{ Constructor
 194  
 195      /**
 196       * Constructor
 197       *
 198       * Set up the storage driver.
 199       *
 200       * @param string    Type of the storage driver
 201       * @param mixed     Additional options for the storage driver
 202       *                  (example: if you are using DB as the storage
 203       *                   driver, you have to pass the dsn string here)
 204       *
 205       * @param string    Name of the function that creates the login form
 206       * @param boolean   Should the login form be displayed if neccessary?
 207       * @return void
 208       */
 209      function Auth($storageDriver, $options = '', $loginFunction = '', $showLogin = true)
 210      {
 211      if (!empty($options['sessionName'])) {
 212          $this->_sessionName = $options['sessionName'];
 213              unset($options['sessionName']);
 214          }
 215          
 216          if (!empty($options['postUsername'])) {
 217              $this->_postUsername = $options['postUsername'];
 218              unset($options['postUsername']);
 219          }
 220          
 221          if (!empty($options['postPassword'])) {
 222              $this->_postPassword = $options['postPassword'];
 223              unset($options['postPassword']);
 224          }
 225  
 226          if (!empty($options['idcol'])) {
 227              $this->idcol = $options['idcol'];
 228          }
 229  
 230          if ($loginFunction != '' && is_callable($loginFunction)) {
 231              $this->loginFunction = $loginFunction;
 232          }
 233  
 234          if (is_bool($showLogin)) {
 235              $this->showLogin = $showLogin;
 236          }
 237  
 238          if (is_object($storageDriver)) {
 239              $this->storage =& $storageDriver;
 240          } else {
 241              $this->storage = $this->_factory($storageDriver, $options);
 242          }
 243          // Pass a reference to auth to the container, ugly but works
 244          // this is used by the DB container to use method setAuthData not staticaly.
 245          $this->storage->_auth_obj =& $this;
 246          
 247      }
 248  
 249      // }}}
 250      // {{{ _factory()
 251  
 252      /**
 253       * Return a storage driver based on $driver and $options
 254       *
 255       * @access private
 256       * @static
 257       * @param  string $driver  Type of storage class to return
 258       * @param  string $options Optional parameters for the storage class
 259       * @return object Object   Storage object
 260       */
 261      function _factory($driver, $options = '')
 262      {
 263          $storage_path = 'Auth/Container/' . $driver . '.php';
 264          $storage_class = 'Auth_Container_' . $driver;
 265  
 266          //require_once $storage_path;
 267          return new $storage_class($options);
 268      }
 269  
 270      // }}}
 271      // {{{ assignData()
 272  
 273      /**
 274       * Assign data from login form to internal values
 275       *
 276       * This function takes the values for username and password
 277       * from $HTTP_POST_VARS/$_POST and assigns them to internal variables.
 278       * If you wish to use another source apart from $HTTP_POST_VARS/$_POST,
 279       * you have to derive this function.
 280       *
 281       * @access private
 282       * @global $HTTP_POST_VARS, $_POST
 283       * @see    Auth
 284       * @return void
 285       */
 286      function assignData()
 287      {
 288          $post = &$this->_importGlobalVariable('post');
 289  
 290          if (isset($post[$this->_postUsername]) && $post[$this->_postUsername] != '') {
 291              $this->username = (get_magic_quotes_gpc() == 1 ? stripslashes($post[$this->_postUsername]) : $post[$this->_postUsername]);
 292          }
 293  
 294          if (isset($post[$this->_postPassword]) && $post[$this->_postPassword] != '') {
 295              $this->password = (get_magic_quotes_gpc() == 1 ? stripslashes($post[$this->_postPassword]) : $post[$this->_postPassword] );
 296          }
 297  
 298      }
 299  
 300      // }}}
 301      // {{{ start()
 302  
 303      /**
 304       * Start new auth session
 305       *
 306       * @access public
 307       * @return void
 308       */
 309      function start()
 310      {
 311          
 312          $this->assignData();
 313          @session_start();
 314  
 315          if (!$this->checkAuth() && $this->showLogin) {
 316          $this->login();
 317          }
 318      }
 319  
 320      // }}}
 321      // {{{ login()
 322  
 323      /**
 324       * Login function
 325       *
 326       * @access private
 327       * @return void
 328       */
 329      function login()
 330      {
 331          $login_ok = false;
 332  
 333          /**
 334           * When the user has already entered a username,
 335           * we have to validate it.
 336           */
 337          if (!empty($this->username)) {
 338              if (true === $this->storage->fetchData($this->username, $this->password)) {
 339                  $login_ok = true;
 340              }
 341          }
 342  
 343          if (!empty($this->username) && $login_ok) {
 344              $this->setAuth($this->username);
 345              if (is_callable($this->loginCallback)) {
 346                  call_user_func($this->loginCallback,$this->username, @$this);
 347                  #call_user_func_array($this->loginFailedCallback, array($this->username, &$this));
 348              }
 349          }
 350  
 351          /**
 352           * If the login failed or the user entered no username,
 353           * output the login screen again.
 354           */
 355          if (!empty($this->username) && !$login_ok) {
 356              $this->status = AUTH_WRONG_LOGIN;
 357              if (is_callable($this->loginFailedCallback)) {
 358                  call_user_func($this->loginFailedCallback,$this->username, @$this);
 359                  #call_user_func_array($this->loginFailedCallback, array($this->username, &$this));
 360              }
 361          }
 362  
 363          if ((empty($this->username) || !$login_ok) && $this->showLogin) {
 364              $this->drawLogin($this->storage->activeUser);
 365              return;
 366          }
 367      }
 368  
 369      // }}}
 370      // {{{ setExpire()
 371  
 372      /**
 373       * Set the maximum expire time
 374       *
 375       * @access public
 376       * @param  integer time in seconds
 377       * @param  bool    add time to current expire time or not
 378       * @return void
 379       */
 380      function setExpire($time, $add = false)
 381      {
 382          if ($add) {
 383              $this->expire += $time;
 384          } else {
 385              $this->expire = $time;
 386          }
 387      }
 388  
 389      // }}}
 390      // {{{ setIdle()
 391  
 392      /**
 393       * Set the maximum idle time
 394       *
 395       * @access public
 396       * @param  integer time in seconds
 397       * @param  bool    add time to current maximum idle time or not
 398       * @return void
 399       */
 400      function setIdle($time, $add = false)
 401      {
 402          if ($add) {
 403              $this->idle += $time;
 404          } else {
 405              $this->idle = $time;
 406          }
 407      }
 408  
 409      // }}}
 410      // {{{ setSessionname()
 411  
 412      /**
 413       * Set name of the session to a customized value.
 414       *
 415       * If you are using multiple instances of PEAR::Auth
 416       * on the same domain, you can change the name of
 417       * session per application via this function.
 418       *
 419       * @access public
 420       * @param  string New name for the session
 421       * @return void
 422       */
 423      function setSessionname($name = 'PHPSESSID')
 424      {
 425          @session_name($name);
 426      }
 427  
 428      // }}}
 429      // {{{ setShowLogin()
 430  
 431      /**
 432       * Should the login form be displayed if neccessary?
 433       *
 434       * @access public
 435       * @param  bool    show login form or not
 436       * @return void
 437       */
 438      function setShowLogin($showLogin = true)
 439      {
 440          $this->showLogin = $showLogin;
 441      }
 442  
 443      /**
 444       * Register a callback function to be called on user login.
 445       * The function will receive two parameters, the username and a reference to the auth object.
 446       *
 447       * @access public
 448       * @param  string  callback function name
 449       * @return void
 450       * @see    setLogoutCallback()
 451       */
 452      function setLoginCallback($loginCallback)
 453      {
 454          $this->loginCallback = $loginCallback;
 455      }
 456  
 457      /**
 458       * Register a callback function to be called on failed user login.
 459       * The function will receive a single parameter, the username and a reference to the auth object.
 460       *
 461       * @access public
 462       * @param  string  callback function name
 463       * @return void
 464       */
 465      function setFailedLoginCallback($loginFailedCallback)
 466      {
 467          $this->loginFailedCallback = $loginFailedCallback;
 468      }
 469  
 470      /**
 471       * Register a callback function to be called on user logout.
 472       * The function will receive three parameters, the username and a reference to the auth object.
 473       *
 474       * @access public
 475       * @param  string  callback function name
 476       * @return void
 477       * @see    setLoginCallback()
 478       */
 479      function setLogoutCallback($logoutCallback)
 480      {
 481          $this->logoutCallback = $logoutCallback;
 482      }
 483  
 484      // }}}
 485      // {{{ setAuthData()
 486  
 487      /**
 488       * Register additional information that is to be stored
 489       * in the session.
 490       *
 491       * @access public
 492       * @param  string  Name of the data field
 493       * @param  mixed   Value of the data field
 494       * @param  boolean Should existing data be overwritten? (default
 495       *                 is true)
 496       * @return void
 497       */
 498      function setAuthData($name, $value, $overwrite = true)
 499      {
 500          $session = &Auth::_importGlobalVariable('session');
 501  
 502          if (!empty($session[$this->_sessionName]['data'][$name]) && $overwrite == false) {
 503              return;
 504          }
 505          $session[$this->_sessionName]['data'][$name] = $value;
 506      }
 507  
 508      // }}}
 509      // {{{ getAuthData()
 510  
 511      /**
 512       * Get additional information that is stored in the session.
 513       *
 514       * If no value for the first parameter is passed, the method will
 515       * return all data that is currently stored.
 516       *
 517       * @access public
 518       * @param  string Name of the data field
 519       * @return mixed  Value of the data field.
 520       */
 521      function getAuthData($name = null)
 522      {
 523          $session = &Auth::_importGlobalVariable('session');
 524          if (!isset($session[$this->_sessionName]['data'])) {
 525              return null;
 526          }
 527  
 528          if (is_null($name)) {
 529              if (isset($session[$this->_sessionName]['data'])) {
 530                  return $session[$this->_sessionName]['data'];
 531              } else {
 532                  return null;
 533              }
 534          }
 535          if (isset($session[$this->_sessionName]['data'][$name])) {
 536              return $session[$this->_sessionName]['data'][$name];
 537          } else {
 538              return null;
 539          }
 540      }
 541  
 542      // }}}
 543      // {{{ setAuth()
 544  
 545      /**
 546       * Register variable in a session telling that the user
 547       * has logged in successfully
 548       *
 549       * @access public
 550       * @param  string Username
 551       * @return void
 552       */
 553      function setAuth($username)
 554      {
 555          $session = &Auth::_importGlobalVariable('session');
 556          $server = &$this->_importGlobalVariable('server');
 557  
 558          if (!isset($session[$this->_sessionName]) && !isset($_SESSION)) {
 559              session_register($this->_sessionName);
 560          }
 561  
 562          if (!isset($session[$this->_sessionName]) || !is_array($session[$this->_sessionName])) {
 563              $session[$this->_sessionName] = array();
 564          }
 565  
 566          if (!isset($session[$this->_sessionName]['data'])) {
 567              $session[$this->_sessionName]['data']       = array();
 568          }
 569  
 570          $session[$this->_sessionName]['sessionip'] = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
 571          $session[$this->_sessionName]['sessionuseragent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
 572  
 573          $session[$this->_sessionName]['registered'] = true;
 574          $session[$this->_sessionName]['username']   = $username;
 575          $session[$this->_sessionName]['timestamp']  = time();
 576          $session[$this->_sessionName]['idle']       = time();
 577      }
 578      
 579      function setAdvancedSecurity($flag=true) {
 580          $this->advancedsecurity = $flag;
 581      }
 582  
 583      // }}}
 584      // {{{ checkAuth()
 585  
 586      /**
 587       * Checks if there is a session with valid auth information.
 588       *
 589       * @access private
 590       * @return boolean  Whether or not the user is authenticated.
 591       */
 592      function checkAuth()
 593      {
 594          $session = &$this->_importGlobalVariable('session');
 595      if ($this->advancedsecurity) {
 596              // Check for ip change
 597              if (isset($session[$this->_sessionName]['sessionip']) && isset($_SERVER['REMOTE_ADDR']) && $session[$this->_sessionName]['sessionip'] != $_SERVER['REMOTE_ADDR']) {
 598                  // Check if the IP of the user has changed, if so we assume a man in the middle attack and log him out
 599                  $this->expired = true;
 600                  $this->status = AUTH_SECURITY_BREACH;
 601                  $this->logout();
 602                  return false;
 603              }
 604              
 605              // Check for useragent change
 606              if (isset($session[$this->_sessionName]['sessionuseragent']) && isset($_SERVER['HTTP_USER_AGENT']) && $session[$this->_sessionName]['sessionuseragent'] != $_SERVER['HTTP_USER_AGENT']) {
 607                  // Check if the User-Agent of the user has changed, if so we assume a man in the middle attack and log him out
 608  
 609                  $this->expired = true;
 610                  $this->status = AUTH_SECURITY_BREACH;
 611                  return false;
 612                  $this->logout();
 613              }
 614              
 615          }
 616  
 617      if (isset($session[$this->_sessionName])) {
 618              // Check if authentication session is expired
 619              if ($this->expire > 0 &&
 620                  isset($session[$this->_sessionName]['timestamp']) &&
 621                  ($session[$this->_sessionName]['timestamp'] + $this->expire) < time()) {
 622                  $this->expired = true;
 623                  $this->status = AUTH_EXPIRED;
 624                  $this->logout();
 625                  return false;
 626              }
 627  
 628              // Check if maximum idle time is reached
 629              if ($this->idle > 0 &&
 630                  isset($session[$this->_sessionName]['idle']) &&
 631                  ($session[$this->_sessionName]['idle'] + $this->idle) < time()) {
 632  
 633  
 634                  $this->idled = true;
 635                  $this->status = AUTH_IDLED;
 636                  $this->logout();
 637                  return false;
 638              }
 639  
 640              if (isset($session[$this->_sessionName]['registered']) &&
 641                  isset($session[$this->_sessionName]['username']) &&
 642                  $session[$this->_sessionName]['registered'] == true &&
 643                  $session[$this->_sessionName]['username'] != '') {
 644  
 645                  Auth::updateIdle();
 646  
 647                  return true;
 648              }
 649          }
 650  
 651          return false;
 652      }
 653  
 654      // }}}
 655      // {{{ getAuth()
 656  
 657      /**
 658       * Has the user been authenticated?
 659       *
 660       * @access public
 661       * @return bool  True if the user is logged in, otherwise false.
 662       */
 663      function getAuth()
 664      {
 665      $session = &$this->_importGlobalVariable('session');
 666          if (!empty($session) &&
 667              (isset($session[$this->_sessionName]['registered']) &&
 668               $session[$this->_sessionName]['registered'] === true))
 669          {
 670              return true;
 671          } else {
 672              return false;
 673          }
 674      }
 675  
 676      // }}}
 677      // {{{ drawLogin()
 678  
 679      /**
 680       * Draw the login form
 681       *
 682       * Normally you will not use this output in your application,
 683       * because you can pass a different function name to the
 684       * constructor. For more information on this, please
 685       * consult the documentation.
 686       *
 687       * @access private
 688       * @param  string  Username if already entered
 689       * @return void
 690       */
 691      function drawLogin($username = '')
 692      {
 693          if (is_callable($this->loginFunction)) {
 694              call_user_func($this->loginFunction, $username, $this->status, @$this);
 695              #call_user_func_array($this->loginFailedCallback, array($this->username, &$this));
 696          } else {
 697              $server = &$this->_importGlobalVariable('server');
 698  
 699              echo '<center>'."\n";
 700  
 701              if (!empty($this->status) && $this->status == AUTH_EXPIRED) {
 702                  echo '<i>Your session has expired. Please login again!</i>'."\n";
 703              } else if (!empty($this->status) && $this->status == AUTH_IDLED) {
 704                  echo '<i>You have been idle for too long. Please login again!</i>'."\n";
 705              } else if (!empty ($this->status) && $this->status == AUTH_WRONG_LOGIN) {
 706                  echo '<i>Wrong login data!</i>'."\n";
 707              } else if (!empty ($this->status) && $this->status == AUTH_SECURITY_BREACH) {
 708                  echo '<i>Security problem. Either your IP or your User-Agent(Browser) has changed!</i>'."\n";
 709              }
 710              PEAR::raiseError('You are using the built-in login screen of PEAR::Auth.<br />See the <a href="http://pear.php.net/manual/">manual</a> for details on how to create your own login function.', null);
 711  
 712              echo '<form method="post" action="' . $server['PHP_SELF'] . '">'."\n";
 713              echo '<table border="0" cellpadding="2" cellspacing="0" summary="login form">'."\n";
 714              echo '<tr>'."\n";
 715              echo '    <td colspan="2" bgcolor="#eeeeee"><b>Login:</b></td>'."\n";
 716              echo '</tr>'."\n";
 717              echo '<tr>'."\n";
 718              echo '    <td>Username:</td>'."\n";
 719              echo '    <td><input type="text" name="username" value="' . $username . '" /></td>'."\n";
 720              echo '</tr>'."\n";
 721              echo '<tr>'."\n";
 722              echo '    <td>Password:</td>'."\n";
 723              echo '    <td><input type="password" name="password" /></td>'."\n";
 724              echo '</tr>'."\n";
 725              echo '<tr>'."\n";
 726              echo '    <td colspan="2" bgcolor="#eeeeee"><input type="submit" /></td>'."\n";
 727              echo '</tr>'."\n";
 728              echo '</table>'."\n";
 729              echo '</form>'."\n";
 730              echo '</center>'."\n\n";
 731          }
 732      }
 733  
 734      // }}}
 735      // {{{ logout()
 736  
 737      /**
 738       * Logout function
 739       *
 740       * This function clears any auth tokens in the currently
 741       * active session and executes the logout callback function,
 742       * if any
 743       *
 744       * @access public
 745       * @return void
 746       */
 747      function logout()
 748      {
 749          $session = &$this->_importGlobalVariable('session');
 750  
 751          if (is_callable($this->logoutCallback)) {
 752              call_user_func($this->logoutCallback, $session[$this->_sessionName]['username'], @$this);
 753              #call_user_func_array($this->loginFailedCallback, array($this->username, &$this));
 754          }
 755  
 756          $this->username = '';
 757          $this->password = '';
 758  
 759          $session[$this->_sessionName] = array();
 760          if (isset($_SESSION)) {
 761              unset($session[$this->_sessionName]);
 762          } else {
 763              session_unregister($this->_sessionName);
 764          }
 765      }
 766  
 767      // }}}
 768      // {{{ updateIdle()
 769  
 770      /**
 771       * Update the idletime
 772       *
 773       * @access private
 774       * @return void
 775       */
 776      function updateIdle()
 777      {
 778          $session = &$this->_importGlobalVariable('session');
 779          $session[$this->_sessionName]['idle'] = time();
 780      }
 781  
 782      // }}}
 783      // {{{ getUsername()
 784  
 785      /**
 786       * Get the username
 787       *
 788       * @access public
 789       * @return string
 790       */
 791      function getUsername()
 792      {
 793          $session = &$this->_importGlobalVariable('session');
 794          if (!isset($session[$this->_sessionName]['username'])) {
 795              return '';
 796          }
 797          return $session[$this->_sessionName]['username'];
 798      }
 799      
 800      function getUserId()
 801      {
 802          $session = &$this->_importGlobalVariable('session');
 803          if (!isset($session[$this->_sessionName]['username'])) {
 804              return '';
 805          }
 806          return $session[$this->_sessionName]['data'][$this->idcol];
 807      }
 808  
 809      // }}}
 810      // {{{ getStatus()
 811  
 812      /**
 813       * Get the current status
 814       *
 815       * @access public
 816       * @return string
 817       */
 818      function getStatus()
 819      {
 820          return $this->status;
 821      }
 822  
 823      // }}}
 824      // {{{ sessionValidThru()
 825  
 826      /**
 827       * Returns the time up to the session is valid
 828       *
 829       * @access public
 830       * @return integer
 831       */
 832      function sessionValidThru()
 833      {
 834          $session = &$this->_importGlobalVariable('session');
 835          if (!isset($session[$this->_sessionName]['idle'])) {
 836              return 0;
 837          }
 838          return ($session[$this->_sessionName]['idle'] + $this->idle);
 839      }
 840  
 841      // }}}
 842      // {{{ listUsers()
 843  
 844      /**
 845       * List all users that are currently available in the storage
 846       * container
 847       *
 848       * @access public
 849       * @return array
 850       */
 851      function listUsers()
 852      {
 853          return $this->storage->listUsers();
 854      }
 855  
 856      // }}}
 857      // {{{ addUser()
 858  
 859      /**
 860       * Add user to the storage container
 861       *
 862       * @access public
 863       * @param  string Username
 864       * @param  string Password
 865       * @param  mixed  Additional parameters
 866       * @return mixed  True on success, PEAR error object on error
 867       *                and AUTH_METHOD_NOT_SUPPORTED otherwise.
 868       */
 869      function addUser($username, $password, $additional = '')
 870      {
 871          return $this->storage->addUser($username, $password, $additional);
 872      }
 873  
 874      // }}}
 875      // {{{ removeUser()
 876  
 877      /**
 878       * Remove user from the storage container
 879       *
 880       * @access public
 881       * @param  string Username
 882       * @return mixed  True on success, PEAR error object on error
 883       *                and AUTH_METHOD_NOT_SUPPORTED otherwise.
 884       */
 885      function removeUser($username)
 886      {
 887          return $this->storage->removeUser($username);
 888      }
 889  
 890      // }}}
 891      // {{{ changePassword()
 892  
 893      /**
 894       * Change password for user in the storage container
 895       *
 896       * @access public
 897       * @param string Username
 898       * @param string The new password 
 899       * @return mixed True on success, PEAR error object on error
 900       *               and AUTH_METHOD_NOT_SUPPORTED otherwise.
 901       */
 902      function changePassword($username, $password)
 903      {
 904          return $this->storage->changePassword($username, $password);
 905      }
 906  
 907      // }}}
 908      // {{{ _importGlobalVariable()
 909  
 910      /**
 911       * Import variables from special namespaces.
 912       *
 913       * @access private
 914       * @param string Type of variable (server, session, post)
 915       * @return array
 916       */
 917      function &_importGlobalVariable($variable)
 918      {
 919          $var = null;
 920  
 921          switch (strtolower($variable)) {
 922              case 'session' :
 923                  isset($_SESSION) ? $var = &$_SESSION : $var = &$GLOBALS['HTTP_SESSION_VARS'] ;
 924                  break;
 925  
 926              case 'server' :
 927                  isset($_SERVER) ? $var = &$_SERVER : $var = &$GLOBALS['HTTP_SERVER_VARS'];
 928                  break;
 929  
 930              case 'post' :
 931                  isset($_POST) ? $var = &$_POST : $var = &$GLOBALS['HTTP_POST_VARS'];
 932                  break;
 933  
 934              case 'cookie' :
 935                  isset($_COOKIE) ? $var = &$_COOKIE : $var = &$GLOBALS['HTTP_COOKIE_VARS'];
 936                  break;
 937  
 938              case 'get' :
 939                  isset($_GET) ? $var = &$_GET : $var = &$GLOBALS['HTTP_GET_VARS'];
 940                  break;
 941  
 942              default:
 943                  break;
 944  
 945          }
 946  
 947          return $var;
 948      }
 949  
 950      // }}}
 951  }
 952  ?>


Généré le : Wed Nov 21 13:08:55 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics