Хранилища Subversion ant

Редакция

Редакция 69 | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS

Редакция 69 Редакция 87
1
<?php
1
<?php
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
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:
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
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
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.
11
 * send a note to license@php.net so we can mail you a copy immediately.
12
 *
12
 *
13
 * @category   pear
13
 * @category   pear
14
 * @package    PEAR
14
 * @package    PEAR
15
 * @author     Stig Bakken <ssb@php.net>
15
 * @author     Stig Bakken <ssb@php.net>
16
 * @author     Greg Beaver <cellog@php.net>
16
 * @author     Greg Beaver <cellog@php.net>
17
 * @copyright  1997-2008 The PHP Group
17
 * @copyright  1997-2008 The PHP Group
18
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
18
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
19
 * @version    CVS: $Id: Auth.php,v 1.31 2008/01/03 20:26:36 cellog Exp $
19
 * @version    CVS: $Id: Auth.php,v 1.31 2008/01/03 20:26:36 cellog Exp $
20
 * @link       http://pear.php.net/package/PEAR
20
 * @link       http://pear.php.net/package/PEAR
21
 * @since      File available since Release 0.1
21
 * @since      File available since Release 0.1
22
 */
22
 */
23
23
24
/**
24
/**
25
 * base class
25
 * base class
26
 */
26
 */
27
require_once 'PEAR/Command/Common.php';
27
require_once 'PEAR/Command/Common.php';
28
require_once 'PEAR/Config.php';
28
require_once 'PEAR/Config.php';
29
29
30
/**
30
/**
31
 * PEAR commands for login/logout
31
 * PEAR commands for login/logout
32
 *
32
 *
33
 * @category   pear
33
 * @category   pear
34
 * @package    PEAR
34
 * @package    PEAR
35
 * @author     Stig Bakken <ssb@php.net>
35
 * @author     Stig Bakken <ssb@php.net>
36
 * @author     Greg Beaver <cellog@php.net>
36
 * @author     Greg Beaver <cellog@php.net>
37
 * @copyright  1997-2008 The PHP Group
37
 * @copyright  1997-2008 The PHP Group
38
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
38
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
39
 * @version    Release: 1.7.2
39
 * @version    Release: 1.7.2
40
 * @link       http://pear.php.net/package/PEAR
40
 * @link       http://pear.php.net/package/PEAR
41
 * @since      Class available since Release 0.1
41
 * @since      Class available since Release 0.1
42
 */
42
 */
43
class PEAR_Command_Auth extends PEAR_Command_Common
43
class PEAR_Command_Auth extends PEAR_Command_Common
44
{
44
{
45
    // {{{ properties
45
    // {{{ properties
46
46
47
    var $commands = array(
47
    var $commands = array(
48
        'login' => array(
48
        'login' => array(
49
            'summary' => 'Connects and authenticates to remote server',
49
            'summary' => 'Connects and authenticates to remote server',
50
            'shortcut' => 'li',
50
            'shortcut' => 'li',
51
            'function' => 'doLogin',
51
            'function' => 'doLogin',
52
            'options' => array(),
52
            'options' => array(),
53
            'doc' => '<channel name>
53
            'doc' => '<channel name>
54
Log in to a remote channel server.  If <channel name> is not supplied,
54
Log in to a remote channel server.  If <channel name> is not supplied,
55
the default channel is used. To use remote functions in the installer
55
the default channel is used. To use remote functions in the installer
56
that require any kind of privileges, you need to log in first.  The
56
that require any kind of privileges, you need to log in first.  The
57
username and password you enter here will be stored in your per-user
57
username and password you enter here will be stored in your per-user
58
PEAR configuration (~/.pearrc on Unix-like systems).  After logging
58
PEAR configuration (~/.pearrc on Unix-like systems).  After logging
59
in, your username and password will be sent along in subsequent
59
in, your username and password will be sent along in subsequent
60
operations on the remote server.',
60
operations on the remote server.',
61
            ),
61
            ),
62
        'logout' => array(
62
        'logout' => array(
63
            'summary' => 'Logs out from the remote server',
63
            'summary' => 'Logs out from the remote server',
64
            'shortcut' => 'lo',
64
            'shortcut' => 'lo',
65
            'function' => 'doLogout',
65
            'function' => 'doLogout',
66
            'options' => array(),
66
            'options' => array(),
67
            'doc' => '
67
            'doc' => '
68
Logs out from the remote server.  This command does not actually
68
Logs out from the remote server.  This command does not actually
69
connect to the remote server, it only deletes the stored username and
69
connect to the remote server, it only deletes the stored username and
70
password from your user configuration.',
70
password from your user configuration.',
71
            )
71
            )
72
72
73
        );
73
        );
74
74
75
    // }}}
75
    // }}}
76
76
77
    // {{{ constructor
77
    // {{{ constructor
78
78
79
    /**
79
    /**
80
     * PEAR_Command_Auth constructor.
80
     * PEAR_Command_Auth constructor.
81
     *
81
     *
82
     * @access public
82
     * @access public
83
     */
83
     */
84
    function PEAR_Command_Auth(&$ui, &$config)
84
    function PEAR_Command_Auth(&$ui, &$config)
85
    {
85
    {
86
        parent::PEAR_Command_Common($ui, $config);
86
        parent::PEAR_Command_Common($ui, $config);
87
    }
87
    }
88
88
89
    // }}}
89
    // }}}
90
90
91
    // {{{ doLogin()
91
    // {{{ doLogin()
92
92
93
    /**
93
    /**
94
     * Execute the 'login' command.
94
     * Execute the 'login' command.
95
     *
95
     *
96
     * @param string $command command name
96
     * @param string $command command name
97
     *
97
     *
98
     * @param array $options option_name => value
98
     * @param array $options option_name => value
99
     *
99
     *
100
     * @param array $params list of additional parameters
100
     * @param array $params list of additional parameters
101
     *
101
     *
102
     * @return bool TRUE on success or
102
     * @return bool TRUE on success or
103
     * a PEAR error on failure
103
     * a PEAR error on failure
104
     *
104
     *
105
     * @access public
105
     * @access public
106
     */
106
     */
107
    function doLogin($command, $options, $params)
107
    function doLogin($command, $options, $params)
108
    {
108
    {
109
        $reg = &$this->config->getRegistry();
109
        $reg = &$this->config->getRegistry();
110
       
110
       
111
        // If a parameter is supplied, use that as the channel to log in to
111
        // If a parameter is supplied, use that as the channel to log in to
112
        if (isset($params[0])) {
112
        if (isset($params[0])) {
113
            $channel = $params[0];
113
            $channel = $params[0];
114
        } else {
114
        } else {
115
            $channel = $this->config->get('default_channel');
115
            $channel = $this->config->get('default_channel');
116
        }
116
        }
117
       
117
       
118
        $chan = $reg->getChannel($channel);
118
        $chan = $reg->getChannel($channel);
119
        if (PEAR::isError($chan)) {
119
        if (PEAR::isError($chan)) {
120
            return $this->raiseError($chan);
120
            return $this->raiseError($chan);
121
        }
121
        }
122
        $server = $this->config->get('preferred_mirror', null, $channel);
122
        $server = $this->config->get('preferred_mirror', null, $channel);
123
        $remote = &$this->config->getRemote();
123
        $remote = &$this->config->getRemote();
124
        $username = $this->config->get('username', null, $channel);
124
        $username = $this->config->get('username', null, $channel);
125
        if (empty($username)) {
125
        if (empty($username)) {
126
            $username = isset($_ENV['USER']) ? $_ENV['USER'] : null;
126
            $username = isset($_ENV['USER']) ? $_ENV['USER'] : null;
127
        }
127
        }
128
        $this->ui->outputData("Logging in to $server.", $command);
128
        $this->ui->outputData("Logging in to $server.", $command);
129
       
129
       
130
        list($username, $password) = $this->ui->userDialog(
130
        list($username, $password) = $this->ui->userDialog(
131
            $command,
131
            $command,
132
            array('Username', 'Password'),
132
            array('Username', 'Password'),
133
            array('text',     'password'),
133
            array('text',     'password'),
134
            array($username,  '')
134
            array($username,  '')
135
            );
135
            );
136
        $username = trim($username);
136
        $username = trim($username);
137
        $password = trim($password);
137
        $password = trim($password);
138
138
139
        $ourfile = $this->config->getConfFile('user');
139
        $ourfile = $this->config->getConfFile('user');
140
        if (!$ourfile) {
140
        if (!$ourfile) {
141
            $ourfile = $this->config->getConfFile('system');
141
            $ourfile = $this->config->getConfFile('system');
142
        }
142
        }
143
143
144
        $this->config->set('username', $username, 'user', $channel);
144
        $this->config->set('username', $username, 'user', $channel);
145
        $this->config->set('password', $password, 'user', $channel);
145
        $this->config->set('password', $password, 'user', $channel);
146
146
147
        if ($chan->supportsREST()) {
147
        if ($chan->supportsREST()) {
148
            $ok = true;
148
            $ok = true;
149
        } else {
149
        } else {
150
            $remote->expectError(401);
150
            $remote->expectError(401);
151
            $ok = $remote->call('logintest');
151
            $ok = $remote->call('logintest');
152
            $remote->popExpect();
152
            $remote->popExpect();
153
        }
153
        }
154
        if ($ok === true) {
154
        if ($ok === true) {
155
            $this->ui->outputData("Logged in.", $command);
155
            $this->ui->outputData("Logged in.", $command);
156
            // avoid changing any temporary settings changed with -d
156
            // avoid changing any temporary settings changed with -d
157
            $ourconfig = new PEAR_Config($ourfile, $ourfile);
157
            $ourconfig = new PEAR_Config($ourfile, $ourfile);
158
            $ourconfig->set('username', $username, 'user', $channel);
158
            $ourconfig->set('username', $username, 'user', $channel);
159
            $ourconfig->set('password', $password, 'user', $channel);
159
            $ourconfig->set('password', $password, 'user', $channel);
160
            $ourconfig->store();
160
            $ourconfig->store();
161
        } else {
161
        } else {
162
            return $this->raiseError("Login failed!");
162
            return $this->raiseError("Login failed!");
163
        }
163
        }
164
        return true;
164
        return true;
165
    }
165
    }
166
166
167
    // }}}
167
    // }}}
168
    // {{{ doLogout()
168
    // {{{ doLogout()
169
169
170
    /**
170
    /**
171
     * Execute the 'logout' command.
171
     * Execute the 'logout' command.
172
     *
172
     *
173
     * @param string $command command name
173
     * @param string $command command name
174
     *
174
     *
175
     * @param array $options option_name => value
175
     * @param array $options option_name => value
176
     *
176
     *
177
     * @param array $params list of additional parameters
177
     * @param array $params list of additional parameters
178
     *
178
     *
179
     * @return bool TRUE on success or
179
     * @return bool TRUE on success or
180
     * a PEAR error on failure
180
     * a PEAR error on failure
181
     *
181
     *
182
     * @access public
182
     * @access public
183
     */
183
     */
184
    function doLogout($command, $options, $params)
184
    function doLogout($command, $options, $params)
185
    {
185
    {
186
        $reg = &$this->config->getRegistry();
186
        $reg = &$this->config->getRegistry();
187
        $channel = $this->config->get('default_channel');
187
        $channel = $this->config->get('default_channel');
188
        $chan = $reg->getChannel($channel);
188
        $chan = $reg->getChannel($channel);
189
        if (PEAR::isError($chan)) {
189
        if (PEAR::isError($chan)) {
190
            return $this->raiseError($chan);
190
            return $this->raiseError($chan);
191
        }
191
        }
192
        $server = $this->config->get('preferred_mirror');
192
        $server = $this->config->get('preferred_mirror');
193
        $this->ui->outputData("Logging out from $server.", $command);
193
        $this->ui->outputData("Logging out from $server.", $command);
194
        $this->config->remove('username');
194
        $this->config->remove('username');
195
        $this->config->remove('password');
195
        $this->config->remove('password');
196
        $this->config->store();
196
        $this->config->store();
197
        return true;
197
        return true;
198
    }
198
    }
199
199
200
    // }}}
200
    // }}}
201
}
201
}
202
202
203
?>
203
?>