| 94 |
jpm |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* PEAR_Command_Auth (login, logout commands)
|
|
|
4 |
*
|
|
|
5 |
* PHP versions 4 and 5
|
|
|
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
|
|
|
14 |
* @package PEAR
|
|
|
15 |
* @author Stig Bakken <ssb@php.net>
|
|
|
16 |
* @author Greg Beaver <cellog@php.net>
|
|
|
17 |
* @copyright 1997-2006 The PHP Group
|
|
|
18 |
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
|
|
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
|
|
|
21 |
* @since File available since Release 0.1
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* base class
|
|
|
26 |
*/
|
|
|
27 |
require_once 'PEAR/Command/Common.php';
|
|
|
28 |
require_once 'PEAR/Config.php';
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* PEAR commands for login/logout
|
|
|
32 |
*
|
|
|
33 |
* @category pear
|
|
|
34 |
* @package PEAR
|
|
|
35 |
* @author Stig Bakken <ssb@php.net>
|
|
|
36 |
* @author Greg Beaver <cellog@php.net>
|
|
|
37 |
* @copyright 1997-2006 The PHP Group
|
|
|
38 |
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
|
|
39 |
* @version Release: 1.5.1
|
|
|
40 |
* @link http://pear.php.net/package/PEAR
|
|
|
41 |
* @since Class available since Release 0.1
|
|
|
42 |
*/
|
|
|
43 |
class PEAR_Command_Auth extends PEAR_Command_Common
|
|
|
44 |
{
|
|
|
45 |
// {{{ properties
|
|
|
46 |
|
|
|
47 |
var $commands = array(
|
|
|
48 |
'login' => array(
|
|
|
49 |
'summary' => 'Connects and authenticates to remote server',
|
|
|
50 |
'shortcut' => 'li',
|
|
|
51 |
'function' => 'doLogin',
|
|
|
52 |
'options' => array(),
|
|
|
53 |
'doc' => '
|
|
|
54 |
Log in to the remote server. To use remote functions in the installer
|
|
|
55 |
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
|
|
|
57 |
PEAR configuration (~/.pearrc on Unix-like systems). After logging
|
|
|
58 |
in, your username and password will be sent along in subsequent
|
|
|
59 |
operations on the remote server.',
|
|
|
60 |
),
|
|
|
61 |
'logout' => array(
|
|
|
62 |
'summary' => 'Logs out from the remote server',
|
|
|
63 |
'shortcut' => 'lo',
|
|
|
64 |
'function' => 'doLogout',
|
|
|
65 |
'options' => array(),
|
|
|
66 |
'doc' => '
|
|
|
67 |
Logs out from the remote server. This command does not actually
|
|
|
68 |
connect to the remote server, it only deletes the stored username and
|
|
|
69 |
password from your user configuration.',
|
|
|
70 |
)
|
|
|
71 |
|
|
|
72 |
);
|
|
|
73 |
|
|
|
74 |
// }}}
|
|
|
75 |
|
|
|
76 |
// {{{ constructor
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* 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 |
*
|
|
|
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'),
|
|
|
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 {
|
|
|
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;
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
// }}}
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
?>
|