Subversion Repositories Applications.papyrus

Rev

Rev 1173 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1173 Rev 1713
Line 16... Line 16...
16
 * @package    Auth
16
 * @package    Auth
17
 * @author     Martin Jansen <mj@php.net>
17
 * @author     Martin Jansen <mj@php.net>
18
 * @author     Adam Ashley <aashley@php.net>
18
 * @author     Adam Ashley <aashley@php.net>
19
 * @copyright  2001-2006 The PHP Group
19
 * @copyright  2001-2006 The PHP Group
20
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
20
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
21
 * @version    CVS: $Id: Auth.php,v 1.2 2006-12-14 15:04:29 jp_milcent Exp $
21
 * @version    CVS: $Id: Auth.php,v 1.3 2007-11-19 15:10:59 jp_milcent Exp $
22
 * @link       http://pear.php.net/package/Auth
22
 * @link       http://pear.php.net/package/Auth
23
 */
23
 */
Line 24... Line 24...
24
 
24
 
25
/**
25
/**
Line 46... Line 46...
46
 * Returned if checkAuthCallback says session should not continue.
46
 * Returned if checkAuthCallback says session should not continue.
47
 */
47
 */
48
define('AUTH_CALLBACK_ABORT',           -6);
48
define('AUTH_CALLBACK_ABORT',           -6);
Line 49... Line 49...
49
 
49
 
-
 
50
/**
-
 
51
 * Auth Log level - INFO
-
 
52
 */
-
 
53
define('AUTH_LOG_INFO',     6);
-
 
54
/**
-
 
55
 * Auth Log level - DEBUG
-
 
56
 */
-
 
57
define('AUTH_LOG_DEBUG',    7);
-
 
58
 
-
 
59
 
50
/**
60
/**
51
 * PEAR::Auth
61
 * PEAR::Auth
52
 *
62
 *
53
 * The PEAR::Auth class provides methods for creating an
63
 * The PEAR::Auth class provides methods for creating an
54
 * authentication system using PHP.
64
 * authentication system using PHP.
Line 57... Line 67...
57
 * @package    Auth
67
 * @package    Auth
58
 * @author     Martin Jansen <mj@php.net>
68
 * @author     Martin Jansen <mj@php.net>
59
 * @author     Adam Ashley <aashley@php.net>
69
 * @author     Adam Ashley <aashley@php.net>
60
 * @copyright  2001-2006 The PHP Group
70
 * @copyright  2001-2006 The PHP Group
61
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
71
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
62
 * @version    Release: 1.4.3  File: $Revision: 1.2 $
72
 * @version    Release: 1.5.4  File: $Revision: 1.3 $
63
 * @link       http://pear.php.net/package/Auth
73
 * @link       http://pear.php.net/package/Auth
64
 */
74
 */
65
class Auth {
75
class Auth {
Line 66... Line 76...
66
 
76
 
Line 256... Line 266...
256
     */
266
     */
257
    var $authdata;
267
    var $authdata;
Line 258... Line 268...
258
    
268
 
259
    /**
269
    /**
260
      * How many times has checkAuth been called
270
      * How many times has checkAuth been called
261
      * var int
271
      * @var int
262
      */
272
      */
Line -... Line 273...
-
 
273
    var $authChecks = 0;
-
 
274
 
-
 
275
    /**
-
 
276
     * PEAR::Log object
-
 
277
     *
-
 
278
     * @var object Log
-
 
279
     */
-
 
280
    var $logger = null;
-
 
281
 
-
 
282
    /**
-
 
283
     * Whether to enable logging of behaviour
-
 
284
     *
-
 
285
     * @var boolean
-
 
286
     */
-
 
287
    var $enableLogging = false;
-
 
288
 
-
 
289
    /**
-
 
290
     * Whether to regenerate session id everytime start is called
-
 
291
     *
-
 
292
     * @var boolean
-
 
293
     */
263
    var $authChecks = 0;
294
    var $regenerateSessionId = false;
264
 
295
 
Line 265... Line 296...
265
    // }}}
296
    // }}}
266
    // {{{ Auth() [constructor]
297
    // {{{ Auth() [constructor]
Line 361... Line 392...
361
            }
392
            }
362
            if (isset($options['advancedsecurity'])) {
393
            if (isset($options['advancedsecurity'])) {
363
                $this->advancedsecurity = $options['advancedsecurity'];
394
                $this->advancedsecurity = $options['advancedsecurity'];
364
                unset($options['advancedsecurity']);
395
                unset($options['advancedsecurity']);
365
            }
396
            }
-
 
397
            if (isset($options['enableLogging'])) {
-
 
398
                $this->enableLogging = $options['enableLogging'];
-
 
399
                unset($options['enableLogging']);
-
 
400
            }
-
 
401
            if (isset($options['regenerateSessionId']) && is_bool($options['regenerateSessionId'])) {
-
 
402
                $this->regenerateSessionId = $options['regenerateSessionId'];
-
 
403
            }
366
        }
404
        }
367
        return($options);
405
        return($options);
368
    }
406
    }
Line 369... Line 407...
369
 
407
 
Line 384... Line 422...
384
    {
422
    {
385
        if(!is_object($this->storage)) {
423
        if(!is_object($this->storage)) {
386
            $this->storage =& $this->_factory($this->storage_driver, 
424
            $this->storage =& $this->_factory($this->storage_driver,
387
                    $this->storage_options);
425
                    $this->storage_options);
388
            $this->storage->_auth_obj =& $this;
426
            $this->storage->_auth_obj =& $this;
-
 
427
            $this->log('Loaded storage container ('.$this->storage_driver.')', AUTH_LOG_DEBUG);
389
            return(true);
428
            return(true);
390
        }
429
        }
391
        return(false);
430
        return(false);
392
    }
431
    }
Line 427... Line 466...
427
     * @return void
466
     * @return void
428
     * @access private
467
     * @access private
429
     */
468
     */
430
    function assignData()
469
    function assignData()
431
    {
470
    {
-
 
471
        $this->log('Auth::assignData() called.', AUTH_LOG_DEBUG);
-
 
472
 
432
        if (   isset($this->post[$this->_postUsername]) 
473
        if (   isset($this->post[$this->_postUsername])
433
            && $this->post[$this->_postUsername] != '') {
474
            && $this->post[$this->_postUsername] != '') {
434
            $this->username = (get_magic_quotes_gpc() == 1 
475
            $this->username = (get_magic_quotes_gpc() == 1
435
                    ? stripslashes($this->post[$this->_postUsername]) 
476
                    ? stripslashes($this->post[$this->_postUsername])
436
                    : $this->post[$this->_postUsername]);
477
                    : $this->post[$this->_postUsername]);
Line 452... Line 493...
452
     * @return void
493
     * @return void
453
     * @access public
494
     * @access public
454
     */
495
     */
455
    function start()
496
    function start()
456
    {
497
    {
-
 
498
        $this->log('Auth::start() called.', AUTH_LOG_DEBUG);
-
 
499
 
-
 
500
        // #10729 - Regenerate session id here if we are generating it on every
-
 
501
        //          page load.
-
 
502
        if ($this->regenerateSessionId) {
-
 
503
            session_regenerate_id(true);
-
 
504
        }
-
 
505
 
457
        $this->assignData();
506
        $this->assignData();
458
        if (!$this->checkAuth() && $this->allowLogin) {
507
        if (!$this->checkAuth() && $this->allowLogin) {
459
            $this->login();
508
            $this->login();
460
        }
509
        }
461
    }
510
    }
Line 469... Line 518...
469
     * @return void
518
     * @return void
470
     * @access private
519
     * @access private
471
     */
520
     */
472
    function login()
521
    function login()
473
    {
522
    {
-
 
523
        $this->log('Auth::login() called.', AUTH_LOG_DEBUG);
-
 
524
 
474
        $login_ok = false;
525
        $login_ok = false;
475
        $this->_loadStorage();
526
        $this->_loadStorage();
Line 476... Line 527...
476
        
527
 
477
        // Check if using challenge response
528
        // Check if using challenge response
Line 483... Line 534...
483
        // When the user has already entered a username, we have to validate it.
534
        // When the user has already entered a username, we have to validate it.
484
        if (!empty($this->username)) {
535
        if (!empty($this->username)) {
485
            if (true === $this->storage->fetchData($this->username, $this->password, $usingChap)) {
536
            if (true === $this->storage->fetchData($this->username, $this->password, $usingChap)) {
486
                $this->session['challengekey'] = md5($this->username.$this->password);
537
                $this->session['challengekey'] = md5($this->username.$this->password);
487
                $login_ok = true;
538
                $login_ok = true;
-
 
539
                $this->log('Successful login.', AUTH_LOG_INFO);
488
            }
540
            }
489
        }
541
        }
Line 490... Line 542...
490
 
542
 
491
        if (!empty($this->username) && $login_ok) {
543
        if (!empty($this->username) && $login_ok) {
492
            $this->setAuth($this->username);
544
            $this->setAuth($this->username);
-
 
545
            if (is_callable($this->loginCallback)) {
493
            if (is_callable($this->loginCallback)) {
546
                $this->log('Calling loginCallback ('.$this->loginCallback.').', AUTH_LOG_DEBUG);
494
                call_user_func_array($this->loginCallback, array($this->username, &$this));
547
                call_user_func_array($this->loginCallback, array($this->username, &$this));
495
            }
548
            }
Line 496... Line 549...
496
        }
549
        }
497
 
550
 
498
        // If the login failed or the user entered no username, 
551
        // If the login failed or the user entered no username,
-
 
552
        // output the login screen again.
499
        // output the login screen again.
553
        if (!empty($this->username) && !$login_ok) {
500
        if (!empty($this->username) && !$login_ok) {
554
            $this->log('Incorrect login.', AUTH_LOG_INFO);
-
 
555
            $this->status = AUTH_WRONG_LOGIN;
501
            $this->status = AUTH_WRONG_LOGIN;
556
            if (is_callable($this->loginFailedCallback)) {
502
            if (is_callable($this->loginFailedCallback)) {
557
                $this->log('Calling loginFailedCallback ('.$this->loginFailedCallback.').', AUTH_LOG_DEBUG);
503
                call_user_func_array($this->loginFailedCallback, array($this->username, &$this));
558
                call_user_func_array($this->loginFailedCallback, array($this->username, &$this));
Line 504... Line 559...
504
            }
559
            }
-
 
560
        }
505
        }
561
 
-
 
562
        if ((empty($this->username) || !$login_ok) && $this->showLogin) {
506
 
563
            $this->log('Rendering Login Form.', AUTH_LOG_INFO);
507
        if ((empty($this->username) || !$login_ok) && $this->showLogin) {
564
            if (is_callable($this->loginFunction)) {
508
            if (is_callable($this->loginFunction)) {
565
                $this->log('Calling loginFunction ('.$this->loginFunction.').', AUTH_LOG_DEBUG);
509
                call_user_func_array($this->loginFunction, array($this->username, $this->status, &$this));
566
                call_user_func_array($this->loginFunction, array($this->username, $this->status, &$this));
510
            } else {
567
            } else {
-
 
568
                // BC fix Auth used to use drawLogin for this
511
                // BC fix Auth used to use drawLogin for this
569
                // call is sub classes implement this
512
                // call is sub classes implement this
570
                if (is_callable(array($this, 'drawLogin'))) {
Line -... Line 571...
-
 
571
                    $this->log('Calling Auth::drawLogin()', AUTH_LOG_DEBUG);
-
 
572
                    return $this->drawLogin($this->username, $this);
513
                if (is_callable(array($this, 'drawLogin'))) {
573
                }
514
                    return $this->drawLogin($this->username, $this);
574
 
515
                }
575
                $this->log('Using default Auth_Frontend_Html', AUTH_LOG_DEBUG);
516
 
576
 
517
                // New Login form
577
                // New Login form
Line 572... Line 632...
572
     * @access public
632
     * @access public
573
     */
633
     */
574
    function setSessionName($name = 'session')
634
    function setSessionName($name = 'session')
575
    {
635
    {
576
        $this->_sessionName = '_auth_'.$name;
636
        $this->_sessionName = '_auth_'.$name;
-
 
637
        // Make Sure Auth session variable is there
-
 
638
        if(!isset($_SESSION[$this->_sessionName])) {
-
 
639
            $_SESSION[$this->_sessionName] = array();
-
 
640
        }
577
        $this->session =& $_SESSION[$this->_sessionName];
641
        $this->session =& $_SESSION[$this->_sessionName];
578
    }
642
    }
Line 579... Line 643...
579
 
643
 
580
    // }}}
644
    // }}}
Line 734... Line 798...
734
     * @return void
798
     * @return void
735
     * @access public
799
     * @access public
736
     */
800
     */
737
    function setAuth($username)
801
    function setAuth($username)
738
    {
802
    {
-
 
803
        $this->log('Auth::setAuth() called.', AUTH_LOG_DEBUG);
Line -... Line 804...
-
 
804
 
-
 
805
        // #10729 - Regenerate session id here only if generating at login only
-
 
806
        //          Don't do it if we are regenerating on every request so we don't
-
 
807
        //          regenerate it twice in one request.
739
    
808
        if (!$this->regenerateSessionId) {
740
        // #2021 - Change the session id to avoid session fixation attacks php 4.3.3 > 
809
            // #2021 - Change the session id to avoid session fixation attacks php 4.3.3 >
-
 
810
            session_regenerate_id(true);
Line 741... Line 811...
741
        session_regenerate_id(true);
811
        }
742
 
812
 
743
        if (!isset($this->session) || !is_array($this->session)) {
813
        if (!isset($this->session) || !is_array($this->session)) {
Line 752... Line 822...
752
            ? $this->server['REMOTE_ADDR'] 
822
            ? $this->server['REMOTE_ADDR']
753
            : '';
823
            : '';
754
        $this->session['sessionuseragent'] = isset($this->server['HTTP_USER_AGENT']) 
824
        $this->session['sessionuseragent'] = isset($this->server['HTTP_USER_AGENT'])
755
            ? $this->server['HTTP_USER_AGENT'] 
825
            ? $this->server['HTTP_USER_AGENT']
756
            : '';
826
            : '';
-
 
827
        $this->session['sessionforwardedfor'] = isset($this->server['HTTP_X_FORWARDED_FOR'])
-
 
828
            ? $this->server['HTTP_X_FORWARDED_FOR']
-
 
829
            : '';
Line 757... Line 830...
757
 
830
 
758
        // This should be set by the container to something more safe
831
        // This should be set by the container to something more safe
759
        // Like md5(passwd.microtime)
832
        // Like md5(passwd.microtime)
760
        if(empty($this->session['challengekey'])) {
833
        if(empty($this->session['challengekey'])) {
Line 799... Line 872...
799
     * @access public
872
     * @access public
800
     * @return boolean  Whether or not the user is authenticated.
873
     * @return boolean  Whether or not the user is authenticated.
801
     */
874
     */
802
    function checkAuth()
875
    function checkAuth()
803
    {
876
    {
-
 
877
        $this->log('Auth::checkAuth() called.', AUTH_LOG_DEBUG);
804
        $this->authChecks++;
878
        $this->authChecks++;
805
        if (isset($this->session)) {
879
        if (isset($this->session)) {
806
            // Check if authentication session is expired
880
            // Check if authentication session is expired
807
            if (   $this->expire > 0
881
            if (   $this->expire > 0
808
                && isset($this->session['timestamp'])
882
                && isset($this->session['timestamp'])
809
                && ($this->session['timestamp'] + $this->expire) < time()) {
883
                && ($this->session['timestamp'] + $this->expire) < time()) {
-
 
884
                $this->log('Session Expired', AUTH_LOG_INFO);
810
                $this->expired = true;
885
                $this->expired = true;
811
                $this->status = AUTH_EXPIRED;
886
                $this->status = AUTH_EXPIRED;
812
                $this->logout();
887
                $this->logout();
813
                return false;
888
                return false;
814
            }
889
            }
Line 815... Line 890...
815
 
890
 
816
            // Check if maximum idle time is reached
891
            // Check if maximum idle time is reached
817
            if (   $this->idle > 0
892
            if (   $this->idle > 0
818
                && isset($this->session['idle']) 
893
                && isset($this->session['idle'])
-
 
894
                && ($this->session['idle'] + $this->idle) < time()) {
819
                && ($this->session['idle'] + $this->idle) < time()) {
895
                $this->log('Session Idle Time Reached', AUTH_LOG_INFO);
820
                $this->idled = true;
896
                $this->idled = true;
821
                $this->status = AUTH_IDLED;
897
                $this->status = AUTH_IDLED;
822
                $this->logout();
898
                $this->logout();
823
                return false;
899
                return false;
Line 828... Line 904...
828
                && $this->session['registered'] == true 
904
                && $this->session['registered'] == true
829
                && $this->session['username'] != '') {
905
                && $this->session['username'] != '') {
830
                Auth::updateIdle();
906
                Auth::updateIdle();
Line 831... Line 907...
831
 
907
 
-
 
908
                if ($this->advancedsecurity) {
Line 832... Line 909...
832
                if ($this->advancedsecurity) {
909
                    $this->log('Advanced Security Mode Enabled.', AUTH_LOG_DEBUG);
833
                    
910
 
-
 
911
                    // Only Generate the challenge once
834
                    // Only Generate the challenge once
912
                    if($this->authChecks == 1) {
835
                    if($this->authChecks == 1) {
913
                        $this->log('Generating new Challenge Cookie.', AUTH_LOG_DEBUG);
836
                        $this->session['challengecookieold'] = $this->session['challengecookie'];
914
                        $this->session['challengecookieold'] = $this->session['challengecookie'];
837
                        $this->session['challengecookie'] = md5($this->session['challengekey'].microtime());
915
                        $this->session['challengecookie'] = md5($this->session['challengekey'].microtime());
Line 838... Line 916...
838
                        setcookie('authchallenge', $this->session['challengecookie']);
916
                        setcookie('authchallenge', $this->session['challengecookie']);
839
                    }
917
                    }
840
                    
918
 
-
 
919
                    // Check for ip change
841
                    // Check for ip change
920
                    if (   isset($this->server['REMOTE_ADDR'])
842
                    if (   isset($this->server['REMOTE_ADDR']) 
921
                        && $this->session['sessionip'] != $this->server['REMOTE_ADDR']) {
843
                        && $this->session['sessionip'] != $this->server['REMOTE_ADDR']) {
922
                        $this->log('Security Breach. Remote IP Address changed.', AUTH_LOG_INFO);
844
                        // Check if the IP of the user has changed, if so we 
923
                        // Check if the IP of the user has changed, if so we
845
                        // assume a man in the middle attack and log him out
924
                        // assume a man in the middle attack and log him out
846
                        $this->expired = true;
925
                        $this->expired = true;
847
                        $this->status = AUTH_SECURITY_BREACH;
926
                        $this->status = AUTH_SECURITY_BREACH;
Line -... Line 927...
-
 
927
                        $this->logout();
-
 
928
                        return false;
-
 
929
                    }
-
 
930
 
-
 
931
                    // Check for ip change (if connected via proxy)
-
 
932
                    if (   isset($this->server['HTTP_X_FORWARDED_FOR'])
-
 
933
                        && $this->session['sessionforwardedfor'] != $this->server['HTTP_X_FORWARDED_FOR']) {
-
 
934
                        $this->log('Security Breach. Forwarded For IP Address changed.', AUTH_LOG_INFO);
-
 
935
                        // Check if the IP of the user connecting via proxy has
-
 
936
                        // changed, if so we assume a man in the middle attack
-
 
937
                        // and log him out.
-
 
938
                        $this->expired = true;
-
 
939
                        $this->status = AUTH_SECURITY_BREACH;
848
                        $this->logout();
940
                        $this->logout();
849
                        return false;
941
                        return false;
850
                    }
942
                    }
-
 
943
 
851
                    
944
                    // Check for useragent change
852
                    // Check for useragent change
945
                    if (   isset($this->server['HTTP_USER_AGENT'])
853
                    if (   isset($this->server['HTTP_USER_AGENT']) 
946
                        && $this->session['sessionuseragent'] != $this->server['HTTP_USER_AGENT']) {
854
                        && $this->session['sessionuseragent'] != $this->server['HTTP_USER_AGENT']) {
947
                        $this->log('Security Breach. User Agent changed.', AUTH_LOG_INFO);
855
                        // Check if the User-Agent of the user has changed, if 
948
                        // Check if the User-Agent of the user has changed, if
Line 864... Line 957...
864
                    // this is the first time and check is skipped
957
                    // this is the first time and check is skipped
865
                    // TODO when user open two pages similtaneuly (open in new window,open 
958
                    // TODO when user open two pages similtaneuly (open in new window,open
866
                    // in tab) auth breach is caused find out a way around that if possible
959
                    // in tab) auth breach is caused find out a way around that if possible
867
                    if (   isset($this->session['challengecookieold']) 
960
                    if (   isset($this->session['challengecookieold'])
868
                        && $this->session['challengecookieold'] != $this->cookie['authchallenge']) {
961
                        && $this->session['challengecookieold'] != $this->cookie['authchallenge']) {
-
 
962
                        $this->log('Security Breach. Challenge Cookie mismatch.', AUTH_LOG_INFO);
869
                        $this->expired = true;
963
                        $this->expired = true;
870
                        $this->status = AUTH_SECURITY_BREACH;
964
                        $this->status = AUTH_SECURITY_BREACH;
871
                        $this->logout();
965
                        $this->logout();
872
                        $this->login();
966
                        $this->login();
873
                        return false;
967
                        return false;
874
                    }
968
                    }
875
                }
969
                }
Line 876... Line 970...
876
 
970
 
-
 
971
                if (is_callable($this->checkAuthCallback)) {
877
                if (is_callable($this->checkAuthCallback)) {
972
                    $this->log('Calling checkAuthCallback ('.$this->checkAuthCallback.').', AUTH_LOG_DEBUG);
878
                    $checkCallback = call_user_func_array($this->checkAuthCallback, array($this->username, &$this));
973
                    $checkCallback = call_user_func_array($this->checkAuthCallback, array($this->username, &$this));
-
 
974
                    if ($checkCallback == false) {
879
                    if ($checkCallback == false) {
975
                        $this->log('checkAuthCallback failed.', AUTH_LOG_INFO);
880
                        $this->expired = true;
976
                        $this->expired = true;
881
                        $this->status = AUTH_CALLBACK_ABORT;
977
                        $this->status = AUTH_CALLBACK_ABORT;
882
                        $this->logout();
978
                        $this->logout();
883
                        return false;
979
                        return false;
884
                    }
980
                    }
Line -... Line 981...
-
 
981
                }
885
                }
982
 
886
 
983
                $this->log('Session OK.', AUTH_LOG_INFO);
887
                return true;
984
                return true;
-
 
985
            }
888
            }
986
        }
889
        }
987
        $this->log('Unable to locate session storage.', AUTH_LOG_DEBUG);
Line 890... Line 988...
890
        return false;
988
        return false;
891
    }
989
    }
Line 905... Line 1003...
905
    {
1003
    {
906
        static $staticAuth;
1004
        static $staticAuth;
907
        if(!isset($staticAuth)) {
1005
        if(!isset($staticAuth)) {
908
            $staticAuth = new Auth('null', $options);
1006
            $staticAuth = new Auth('null', $options);
909
        }
1007
        }
-
 
1008
        $staticAuth->log('Auth::staticCheckAuth() called', AUTH_LOG_DEBUG);
910
        return $staticAuth->checkAuth();
1009
        return $staticAuth->checkAuth();
911
    }
1010
    }
Line 912... Line 1011...
912
 
1011
 
913
    // }}}
1012
    // }}}
Line 919... Line 1018...
919
     * @access public
1018
     * @access public
920
     * @return bool  True if the user is logged in, otherwise false.
1019
     * @return bool  True if the user is logged in, otherwise false.
921
     */
1020
     */
922
    function getAuth()
1021
    function getAuth()
923
    {
1022
    {
-
 
1023
        $this->log('Auth::getAuth() called.', AUTH_LOG_DEBUG);
924
        return $this->checkAuth();
1024
        return $this->checkAuth();
925
    }
1025
    }
Line 926... Line 1026...
926
 
1026
 
927
    // }}}
1027
    // }}}
Line 937... Line 1037...
937
     * @access public
1037
     * @access public
938
     * @return void
1038
     * @return void
939
     */
1039
     */
940
    function logout()
1040
    function logout()
941
    {
1041
    {
-
 
1042
        $this->log('Auth::logout() called.', AUTH_LOG_DEBUG);
-
 
1043
 
942
        if (is_callable($this->logoutCallback)) {
1044
        if (is_callable($this->logoutCallback) && isset($this->session['username'])) {
-
 
1045
            $this->log('Calling logoutCallback ('.$this->logoutCallback.').', AUTH_LOG_DEBUG);
943
            call_user_func_array($this->logoutCallback, array($this->session['username'], &$this));
1046
            call_user_func_array($this->logoutCallback, array($this->session['username'], &$this));
944
        }
1047
        }
Line 945... Line 1048...
945
 
1048
 
946
        $this->username = '';
1049
        $this->username = '';
Line 1052... Line 1155...
1052
     * @access public
1155
     * @access public
1053
     * @return array
1156
     * @return array
1054
     */
1157
     */
1055
    function listUsers()
1158
    function listUsers()
1056
    {
1159
    {
-
 
1160
        $this->log('Auth::listUsers() called.', AUTH_LOG_DEBUG);
1057
        $this->_loadStorage();
1161
        $this->_loadStorage();
1058
        return $this->storage->listUsers();
1162
        return $this->storage->listUsers();
1059
    }
1163
    }
Line 1060... Line 1164...
1060
 
1164
 
Line 1071... Line 1175...
1071
     * @return mixed  True on success, PEAR error object on error
1175
     * @return mixed  True on success, PEAR error object on error
1072
     *                and AUTH_METHOD_NOT_SUPPORTED otherwise.
1176
     *                and AUTH_METHOD_NOT_SUPPORTED otherwise.
1073
     */
1177
     */
1074
    function addUser($username, $password, $additional = '')
1178
    function addUser($username, $password, $additional = '')
1075
    {
1179
    {
-
 
1180
        $this->log('Auth::addUser() called.', AUTH_LOG_DEBUG);
1076
        $this->_loadStorage();
1181
        $this->_loadStorage();
1077
        return $this->storage->addUser($username, $password, $additional);
1182
        return $this->storage->addUser($username, $password, $additional);
1078
    }
1183
    }
Line 1079... Line 1184...
1079
 
1184
 
Line 1088... Line 1193...
1088
     * @return mixed  True on success, PEAR error object on error
1193
     * @return mixed  True on success, PEAR error object on error
1089
     *                and AUTH_METHOD_NOT_SUPPORTED otherwise.
1194
     *                and AUTH_METHOD_NOT_SUPPORTED otherwise.
1090
     */
1195
     */
1091
    function removeUser($username)
1196
    function removeUser($username)
1092
    {
1197
    {
-
 
1198
        $this->log('Auth::removeUser() called.', AUTH_LOG_DEBUG);
1093
        $this->_loadStorage();
1199
        $this->_loadStorage();
1094
        return $this->storage->removeUser($username);
1200
        return $this->storage->removeUser($username);
1095
    }
1201
    }
Line 1096... Line 1202...
1096
 
1202
 
Line 1106... Line 1212...
1106
     * @return mixed True on success, PEAR error object on error
1212
     * @return mixed True on success, PEAR error object on error
1107
     *               and AUTH_METHOD_NOT_SUPPORTED otherwise.
1213
     *               and AUTH_METHOD_NOT_SUPPORTED otherwise.
1108
     */
1214
     */
1109
    function changePassword($username, $password)
1215
    function changePassword($username, $password)
1110
    {
1216
    {
-
 
1217
        $this->log('Auth::changePassword() called', AUTH_LOG_DEBUG);
1111
        $this->_loadStorage();
1218
        $this->_loadStorage();
1112
        return $this->storage->changePassword($username, $password);
1219
        return $this->storage->changePassword($username, $password);
1113
    }
1220
    }
Line 1114... Line 1221...
1114
 
1221
 
-
 
1222
    // }}}
-
 
1223
    // {{{ log()
-
 
1224
 
-
 
1225
    /**
-
 
1226
     * Log a message from the Auth system
-
 
1227
     *
-
 
1228
     * @access public
-
 
1229
     * @param string The message to log
-
 
1230
     * @param string The log level to log the message under. See the Log documentation for more info.
-
 
1231
     * @return boolean
-
 
1232
     */
-
 
1233
    function log($message, $level = AUTH_LOG_DEBUG)
-
 
1234
    {
-
 
1235
        if (!$this->enableLogging) return false;
-
 
1236
 
-
 
1237
        $this->_loadLogger();
-
 
1238
 
-
 
1239
        $this->logger->log('AUTH: '.$message, $level);
-
 
1240
    }
-
 
1241
 
-
 
1242
    // }}}
-
 
1243
    // {{{ _loadLogger()
-
 
1244
 
-
 
1245
    /**
-
 
1246
      * Load Log object if not already loaded
-
 
1247
      *
-
 
1248
      * Suspend logger instantiation to make Auth lighter to use
-
 
1249
      * for calls which do not require logging
-
 
1250
      *
-
 
1251
      * @return bool    True if the logger is loaded, false if the logger
-
 
1252
      *                 is already loaded
-
 
1253
      * @access private
-
 
1254
      */
-
 
1255
    function _loadLogger()
-
 
1256
    {
-
 
1257
        if(is_null($this->logger)) {
-
 
1258
            if (!class_exists('Log')) {
-
 
1259
                include_once 'Log.php';
-
 
1260
            }
-
 
1261
            $this->logger =& Log::singleton('null',
-
 
1262
                    null,
-
 
1263
                    'auth['.getmypid().']',
-
 
1264
                    array(),
-
 
1265
                    AUTH_LOG_DEBUG);
-
 
1266
            return(true);
-
 
1267
        }
-
 
1268
        return(false);
-
 
1269
    }
-
 
1270
 
-
 
1271
    // }}}
-
 
1272
    // {{{ attachLogObserver()
-
 
1273
 
-
 
1274
    /**
-
 
1275
     * Attach an Observer to the Auth Log Source
-
 
1276
     *
-
 
1277
     * @param object Log_Observer A Log Observer instance
-
 
1278
     * @return boolean
-
 
1279
     */
-
 
1280
    function attachLogObserver(&$observer) {
-
 
1281
 
-
 
1282
        $this->_loadLogger();
-
 
1283
 
-
 
1284
        return $this->logger->attach($observer);
-
 
1285
 
-
 
1286
    }
-
 
1287
 
Line 1115... Line 1288...
1115
    // }}}
1288
    // }}}
1116
 
1289