Subversion Repositories Applications.papyrus

Rev

Rev 1173 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1173 Rev 1713
1
<?php
1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3
 
3
 
4
/**
4
/**
5
 * Storage driver for use against PEAR website
5
 * Storage driver for use against PEAR website
6
 *
6
 *
7
 * PHP versions 4 and 5
7
 * PHP versions 4 and 5
8
 *
8
 *
9
 * LICENSE: This source file is subject to version 3.01 of the PHP license
9
 * LICENSE: This source file is subject to version 3.01 of the PHP license
10
 * that is available through the world-wide-web at the following URI:
10
 * that is available through the world-wide-web at the following URI:
11
 * http://www.php.net/license/3_01.txt.  If you did not receive a copy of
11
 * http://www.php.net/license/3_01.txt.  If you did not receive a copy of
12
 * the PHP License and are unable to obtain it through the web, please
12
 * the PHP License and are unable to obtain it through the web, please
13
 * send a note to license@php.net so we can mail you a copy immediately.
13
 * send a note to license@php.net so we can mail you a copy immediately.
14
 *
14
 *
15
 * @category   Authentication
15
 * @category   Authentication
16
 * @package    Auth
16
 * @package    Auth
17
 * @author     Yavor Shahpasov <yavo@netsmart.com.cy>
17
 * @author     Yavor Shahpasov <yavo@netsmart.com.cy>
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: PEAR.php,v 1.1 2006-12-14 15:04:28 jp_milcent Exp $
21
 * @version    CVS: $Id: PEAR.php,v 1.2 2007-11-19 15:11:00 jp_milcent Exp $
22
 * @link       http://pear.php.net/package/Auth
22
 * @link       http://pear.php.net/package/Auth
23
 * @since      File available since Release 1.3.0
23
 * @since      File available since Release 1.3.0
24
 */
24
 */
25
 
25
 
26
/**
26
/**
27
 * Include Auth_Container base class
27
 * Include PEAR HTTP_Client.
28
 */
28
 */
29
require_once 'Auth/Container.php';
29
require_once 'HTTP/Client.php';
30
/**
30
/**
31
 * Include PEAR XML_RPC
31
 * Include Auth_Container base class
32
 */
32
 */
33
require_once 'XML/RPC.php';
33
require_once 'Auth/Container.php';
34
 
34
 
35
/**
35
/**
36
 * Storage driver for authenticating against PEAR website
36
 * Storage driver for authenticating against PEAR website
37
 *
37
 *
38
 * This driver provides a method for authenticating against the pear.php.net
38
 * This driver provides a method for authenticating against the pear.php.net
39
 * authentication system.
39
 * authentication system.
40
 *
40
 *
41
 * @category   Authentication
41
 * @category   Authentication
42
 * @package    Auth
42
 * @package    Auth
43
 * @author     Yavor Shahpasov <yavo@netsmart.com.cy>
43
 * @author     Yavor Shahpasov <yavo@netsmart.com.cy>
44
 * @author     Adam Ashley <aashley@php.net>
44
 * @author     Adam Ashley <aashley@php.net>
-
 
45
 * @author     Adam Harvey <aharvey@php.net>
45
 * @copyright  2001-2006 The PHP Group
46
 * @copyright  2001-2007 The PHP Group
46
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
47
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
47
 * @version    Release: 1.4.3  File: $Revision: 1.1 $
48
 * @version    Release: 1.5.4  File: $Revision: 1.2 $
48
 * @link       http://pear.php.net/package/Auth
49
 * @link       http://pear.php.net/package/Auth
49
 * @since      Class available since Release 1.3.0
50
 * @since      Class available since Release 1.3.0
50
 */
51
 */
51
class Auth_Container_Pear extends Auth_Container
52
class Auth_Container_Pear extends Auth_Container
52
{
53
{
53
 
54
 
54
    // {{{ Auth_Container_Pear() [constructor]
55
    // {{{ Auth_Container_Pear() [constructor]
55
 
56
 
56
    /**
57
    /**
57
     * Constructor
58
     * Constructor
58
     *
59
     *
59
     * Currently does nothing
60
     * Currently does nothing
60
     * 
61
     *
61
     * @return void
62
     * @return void
62
     */
63
     */
63
    function Auth_Container_Pear()
64
    function Auth_Container_Pear()
64
    {
65
    {
65
    
66
 
66
    }
67
    }
67
 
68
 
68
    // }}}
69
    // }}}
69
    // {{{ fetchData()
70
    // {{{ fetchData()
70
    
71
 
71
    /**
72
    /**
72
     * Get user information from pear.php.net
73
     * Get user information from pear.php.net
73
     *
74
     *
74
     * This function uses the given username and password to authenticate
75
     * This function uses the given username and password to authenticate
75
     * against the pear.php.net website
76
     * against the pear.php.net website
76
     *
77
     *
77
     * @param string    Username
78
     * @param string    Username
78
     * @param string    Password
79
     * @param string    Password
79
     * @return mixed    Error object or boolean
80
     * @return mixed    Error object or boolean
80
     */
81
     */
81
    function fetchData($username, $password)
82
    function fetchData($username, $password)
82
    {
83
    {
83
        $rpc = new XML_RPC_Client('/xmlrpc.php', 'pear.php.net');
84
        $this->log('Auth_Container_PEAR::fetchData() called.', AUTH_LOG_DEBUG);
-
 
85
 
84
        $rpc_message = new XML_RPC_Message("user.info", array(new XML_RPC_Value($username, "string")) );
86
        $client = new HTTP_Client;
85
        
87
 
-
 
88
        $this->log('Auth_Container_PEAR::fetchData() getting salt.', AUTH_LOG_DEBUG);
-
 
89
        $code = $client->get('https://pear.php.net/rest-login.php/getsalt');
86
        // Error Checking howto ???
90
        if ($code != 200) {
87
        $result = $rpc->send($rpc_message);
91
            return PEAR::raiseError('Bad response to salt request.', $code);
-
 
92
        }
88
        $value = $result->value();
93
        $resp = $client->currentResponse();
89
        $userinfo = xml_rpc_decode($value);
94
        $salt = $resp['body'];
-
 
95
 
90
        if ($userinfo['password'] == md5($password)) {
96
        $this->log('Auth_Container_PEAR::fetchData() calling validate.', AUTH_LOG_DEBUG);
91
            $this->activeUser = $userinfo['handle'];
97
        $code = $client->post('https://pear.php.net/rest-login.php/validate',
92
            foreach ($userinfo as $uk=>$uv) {
98
                              array('username' => $username,
93
                $this->_auth_obj->setAuthData($uk, $uv);
99
                                    'password' => md5($salt.md5($password))));
94
            }
100
        if ($code != 200) {
95
            return true;
101
            return PEAR::raiseError('Bad response to validate request.', $code);
96
        }
102
        }
-
 
103
        $resp = $client->currentResponse();
-
 
104
 
-
 
105
        list($code, $message) = explode(' ', $resp['body'], 1);
-
 
106
        if ($code != 8) {
-
 
107
            return PEAR::raiseError($message, $code);
-
 
108
        }
97
        return false;
109
        return true;
98
    }
110
    }
99
 
111
 
100
    // }}}
112
    // }}}
101
    
113
 
102
}
114
}
103
?>
115
?>