Subversion Repositories Applications.gtt

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
Line 2... Line 2...
2
/**
2
/**
3
 * PEAR_Command_Auth (login, logout commands)
3
 * PEAR_Command_Auth (login, logout commands)
4
 *
4
 *
5
 * PHP versions 4 and 5
5
 * PHP versions 4 and 5
6
 *
6
 *
7
 * LICENSE: This source file is subject to version 3.0 of the PHP license
-
 
8
 * that is available through the world-wide-web at the following URI:
-
 
9
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
-
 
10
 * the PHP License and are unable to obtain it through the web, please
-
 
11
 * send a note to license@php.net so we can mail you a copy immediately.
-
 
12
 *
-
 
13
 * @category   pear
7
 * @category   pear
14
 * @package    PEAR
8
 * @package    PEAR
15
 * @author     Stig Bakken <ssb@php.net>
9
 * @author     Stig Bakken <ssb@php.net>
16
 * @author     Greg Beaver <cellog@php.net>
10
 * @author     Greg Beaver <cellog@php.net>
17
 * @copyright  1997-2006 The PHP Group
11
 * @copyright  1997-2009 The Authors
18
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
12
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
19
 * @version    CVS: $Id: Auth.php,v 1.24 2006/03/05 21:23:21 cellog Exp $
-
 
20
 * @link       http://pear.php.net/package/PEAR
13
 * @link       http://pear.php.net/package/PEAR
21
 * @since      File available since Release 0.1
14
 * @since      File available since Release 0.1
-
 
15
 * @deprecated since 1.8.0alpha1
22
 */
16
 */
Line 23... Line 17...
23
 
17
 
24
/**
18
/**
25
 * base class
19
 * base class
26
 */
20
 */
27
require_once 'PEAR/Command/Common.php';
-
 
Line 28... Line 21...
28
require_once 'PEAR/Config.php';
21
require_once 'PEAR/Command/Channels.php';
29
 
22
 
30
/**
23
/**
31
 * PEAR commands for login/logout
24
 * PEAR commands for login/logout
32
 *
25
 *
33
 * @category   pear
26
 * @category   pear
34
 * @package    PEAR
27
 * @package    PEAR
35
 * @author     Stig Bakken <ssb@php.net>
28
 * @author     Stig Bakken <ssb@php.net>
36
 * @author     Greg Beaver <cellog@php.net>
29
 * @author     Greg Beaver <cellog@php.net>
37
 * @copyright  1997-2006 The PHP Group
30
 * @copyright  1997-2009 The Authors
38
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
31
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
39
 * @version    Release: 1.5.1
32
 * @version    Release: 1.10.1
-
 
33
 * @link       http://pear.php.net/package/PEAR
40
 * @link       http://pear.php.net/package/PEAR
34
 * @since      Class available since Release 0.1
41
 * @since      Class available since Release 0.1
35
 * @deprecated since 1.8.0alpha1
42
 */
36
 */
43
class PEAR_Command_Auth extends PEAR_Command_Common
-
 
44
{
-
 
45
    // {{{ properties
37
class PEAR_Command_Auth extends PEAR_Command_Channels
46
 
38
{
47
    var $commands = array(
39
    var $commands = array(
48
        'login' => array(
40
        'login' => array(
49
            'summary' => 'Connects and authenticates to remote server',
41
            'summary' => 'Connects and authenticates to remote server [Deprecated in favor of channel-login]',
50
            'shortcut' => 'li',
42
            'shortcut' => 'li',
51
            'function' => 'doLogin',
43
            'function' => 'doLogin',
-
 
44
            'options' => array(),
-
 
45
            'doc' => '<channel name>
-
 
46
WARNING: This function is deprecated in favor of using channel-login
52
            'options' => array(),
47
 
53
            'doc' => '
48
Log in to a remote channel server.  If <channel name> is not supplied,
54
Log in to the remote server.  To use remote functions in the installer
49
the default channel is used. To use remote functions in the installer
55
that require any kind of privileges, you need to log in first.  The
50
that require any kind of privileges, you need to log in first.  The
56
username and password you enter here will be stored in your per-user
51
username and password you enter here will be stored in your per-user
57
PEAR configuration (~/.pearrc on Unix-like systems).  After logging
52
PEAR configuration (~/.pearrc on Unix-like systems).  After logging
58
in, your username and password will be sent along in subsequent
53
in, your username and password will be sent along in subsequent
59
operations on the remote server.',
54
operations on the remote server.',
60
            ),
55
            ),
61
        'logout' => array(
56
        'logout' => array(
62
            'summary' => 'Logs out from the remote server',
57
            'summary' => 'Logs out from the remote server [Deprecated in favor of channel-logout]',
63
            'shortcut' => 'lo',
58
            'shortcut' => 'lo',
64
            'function' => 'doLogout',
59
            'function' => 'doLogout',
-
 
60
            'options' => array(),
-
 
61
            'doc' => '
65
            'options' => array(),
62
WARNING: This function is deprecated in favor of using channel-logout
66
            'doc' => '
63
 
67
Logs out from the remote server.  This command does not actually
64
Logs out from the remote server.  This command does not actually
68
connect to the remote server, it only deletes the stored username and
65
connect to the remote server, it only deletes the stored username and
Line 69... Line 66...
69
password from your user configuration.',
66
password from your user configuration.',
Line 70... Line -...
70
            )
-
 
71
 
-
 
72
        );
-
 
73
 
-
 
74
    // }}}
67
            )
75
 
68
 
76
    // {{{ constructor
69
        );
77
 
70
 
78
    /**
71
    /**
79
     * PEAR_Command_Auth constructor.
72
     * PEAR_Command_Auth constructor.
80
     *
-
 
81
     * @access public
-
 
82
     */
-
 
83
    function PEAR_Command_Auth(&$ui, &$config)
-
 
84
    {
-
 
85
        parent::PEAR_Command_Common($ui, $config);
-
 
86
    }
-
 
87
 
-
 
88
    // }}}
-
 
89
 
-
 
90
    // {{{ doLogin()
-
 
91
 
-
 
92
    /**
-
 
93
     * Execute the 'login' command.
-
 
94
     *
-
 
95
     * @param string $command command name
-
 
96
     *
-
 
97
     * @param array $options option_name => value
-
 
98
     *
-
 
99
     * @param array $params list of additional parameters
-
 
100
     *
-
 
101
     * @return bool TRUE on success or
-
 
102
     * a PEAR error on failure
-
 
103
     *
73
     *
104
     * @access public
-
 
105
     */
-
 
106
    function doLogin($command, $options, $params)
-
 
107
    {
-
 
108
        $reg = &$this->config->getRegistry();
-
 
109
        $channel = $this->config->get('default_channel');
-
 
110
        $chan = $reg->getChannel($channel);
-
 
111
        if (PEAR::isError($chan)) {
-
 
112
            return $this->raiseError($chan);
-
 
113
        }
-
 
114
        $server = $this->config->get('preferred_mirror');
-
 
115
        $remote = &$this->config->getRemote();
-
 
116
        $username = $this->config->get('username');
-
 
117
        if (empty($username)) {
-
 
118
            $username = isset($_ENV['USER']) ? $_ENV['USER'] : null;
-
 
119
        }
-
 
120
        $this->ui->outputData("Logging in to $server.", $command);
-
 
121
        
-
 
122
        list($username, $password) = $this->ui->userDialog(
-
 
123
            $command,
-
 
124
            array('Username', 'Password'),
74
     * @access public
125
            array('text',     'password'),
-
 
126
            array($username,  '')
-
 
127
            );
-
 
128
        $username = trim($username);
-
 
129
        $password = trim($password);
-
 
130
        
-
 
131
        $this->config->set('username', $username);
-
 
132
        $this->config->set('password', $password);
-
 
133
 
-
 
134
        if ($chan->supportsREST()) {
-
 
135
            $ok = true;
-
 
136
        } else {
-
 
137
            $remote->expectError(401);
-
 
138
            $ok = $remote->call('logintest');
-
 
139
            $remote->popExpect();
-
 
140
        }
-
 
141
        if ($ok === true) {
-
 
142
            $this->ui->outputData("Logged in.", $command);
-
 
143
            $this->config->store();
-
 
144
        } else {
75
     */
145
            return $this->raiseError("Login failed!");
-
 
146
        }
-
 
147
        return true;
-
 
148
    }
-
 
149
 
-
 
150
    // }}}
-
 
151
    // {{{ doLogout()
-
 
152
 
-
 
153
    /**
-
 
154
     * Execute the 'logout' command.
-
 
155
     *
-
 
156
     * @param string $command command name
-
 
157
     *
-
 
158
     * @param array $options option_name => value
-
 
159
     *
-
 
160
     * @param array $params list of additional parameters
-
 
161
     *
-
 
162
     * @return bool TRUE on success or
-
 
163
     * a PEAR error on failure
-
 
164
     *
-
 
165
     * @access public
-
 
166
     */
-
 
167
    function doLogout($command, $options, $params)
-
 
168
    {
-
 
169
        $reg = &$this->config->getRegistry();
-
 
170
        $channel = $this->config->get('default_channel');
-
 
171
        $chan = $reg->getChannel($channel);
-
 
172
        if (PEAR::isError($chan)) {
-
 
173
            return $this->raiseError($chan);
-
 
174
        }
-
 
175
        $server = $this->config->get('preferred_mirror');
-
 
176
        $this->ui->outputData("Logging out from $server.", $command);
-
 
177
        $this->config->remove('username');
-
 
178
        $this->config->remove('password');
-
 
179
        $this->config->store();
-
 
180
        return true;
76
    function __construct(&$ui, &$config)
181
    }
-
 
182
 
-
 
183
    // }}}
77
    {