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 4... Line 4...
4
 * PEAR_Command_Channels (list-channels, update-channels, channel-delete, channel-add,
4
 * PEAR_Command_Channels (list-channels, update-channels, channel-delete, channel-add,
5
 * channel-update, channel-info, channel-alias, channel-discover commands)
5
 * channel-update, channel-info, channel-alias, channel-discover commands)
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.0 of the PHP license
-
 
10
 * that is available through the world-wide-web at the following URI:
-
 
11
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
-
 
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.
-
 
14
 *
-
 
15
 * @category   pear
9
 * @category   pear
16
 * @package    PEAR
10
 * @package    PEAR
17
 * @author     Stig Bakken <ssb@php.net>
11
 * @author     Stig Bakken <ssb@php.net>
18
 * @author     Greg Beaver <cellog@php.net>
12
 * @author     Greg Beaver <cellog@php.net>
19
 * @copyright  1997-2006 The PHP Group
13
 * @copyright  1997-2009 The Authors
20
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
14
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
21
 * @version    CVS: $Id: Channels.php,v 1.46 2006/07/17 18:19:25 pajoye Exp $
-
 
22
 * @link       http://pear.php.net/package/PEAR
15
 * @link       http://pear.php.net/package/PEAR
23
 * @since      File available since Release 1.4.0a1
16
 * @since      File available since Release 1.4.0a1
24
 */
17
 */
Line 25... Line 18...
25
 
18
 
26
/**
19
/**
27
 * base class
20
 * base class
28
 */
21
 */
Line -... Line 22...
-
 
22
require_once 'PEAR/Command/Common.php';
-
 
23
 
29
require_once 'PEAR/Command/Common.php';
24
define('PEAR_COMMAND_CHANNELS_CHANNEL_EXISTS', -500);
30
 
25
 
31
/**
26
/**
32
 * PEAR commands for managing channels.
27
 * PEAR commands for managing channels.
33
 *
28
 *
34
 * @category   pear
29
 * @category   pear
35
 * @package    PEAR
30
 * @package    PEAR
36
 * @author     Greg Beaver <cellog@php.net>
31
 * @author     Greg Beaver <cellog@php.net>
37
 * @copyright  1997-2006 The PHP Group
32
 * @copyright  1997-2009 The Authors
38
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
33
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
39
 * @version    Release: 1.5.1
34
 * @version    Release: 1.10.1
40
 * @link       http://pear.php.net/package/PEAR
35
 * @link       http://pear.php.net/package/PEAR
41
 * @since      Class available since Release 1.4.0a1
36
 * @since      Class available since Release 1.4.0a1
42
 */
37
 */
43
class PEAR_Command_Channels extends PEAR_Command_Common
-
 
44
{
-
 
45
    // {{{ properties
38
class PEAR_Command_Channels extends PEAR_Command_Common
46
 
39
{
47
    var $commands = array(
40
    var $commands = array(
48
        'list-channels' => array(
41
        'list-channels' => array(
49
            'summary' => 'List Available Channels',
42
            'summary' => 'List Available Channels',
Line 131... Line 124...
131
            'summary' => 'Initialize a Channel from its server',
124
            'summary' => 'Initialize a Channel from its server',
132
            'function' => 'doDiscover',
125
            'function' => 'doDiscover',
133
            'shortcut' => 'di',
126
            'shortcut' => 'di',
134
            'options' => array(),
127
            'options' => array(),
135
            'doc' => '[<channel.xml>|<channel name>]
128
            'doc' => '[<channel.xml>|<channel name>]
136
Initialize a Channel from its server and creates the local channel.xml.
129
Initialize a channel from its server and create a local channel.xml.
-
 
130
If <channel name> is in the format "<username>:<password>@<channel>" then
-
 
131
<username> and <password> will be set as the login username/password for
-
 
132
<channel>. Use caution when passing the username/password in this way, as
-
 
133
it may allow other users on your computer to briefly view your username/
-
 
134
password via the system\'s process list.
137
'
135
'
138
            ),
136
            ),
-
 
137
        'channel-login' => array(
-
 
138
            'summary' => 'Connects and authenticates to remote channel server',
-
 
139
            'shortcut' => 'cli',
-
 
140
            'function' => 'doLogin',
-
 
141
            'options' => array(),
-
 
142
            'doc' => '<channel name>
-
 
143
Log in to a remote channel server.  If <channel name> is not supplied,
-
 
144
the default channel is used. To use remote functions in the installer
-
 
145
that require any kind of privileges, you need to log in first.  The
-
 
146
username and password you enter here will be stored in your per-user
-
 
147
PEAR configuration (~/.pearrc on Unix-like systems).  After logging
-
 
148
in, your username and password will be sent along in subsequent
-
 
149
operations on the remote server.',
-
 
150
            ),
-
 
151
        'channel-logout' => array(
-
 
152
            'summary' => 'Logs out from the remote channel server',
-
 
153
            'shortcut' => 'clo',
-
 
154
            'function' => 'doLogout',
-
 
155
            'options' => array(),
-
 
156
            'doc' => '<channel name>
-
 
157
Logs out from a remote channel server.  If <channel name> is not supplied,
-
 
158
the default channel is used. This command does not actually connect to the
-
 
159
remote server, it only deletes the stored username and password from your user
-
 
160
configuration.',
-
 
161
            ),
139
        );
162
        );
Line 140... Line -...
140
 
-
 
141
    // }}}
-
 
142
    // {{{ constructor
-
 
143
 
163
 
144
    /**
164
    /**
145
     * PEAR_Command_Registry constructor.
165
     * PEAR_Command_Registry constructor.
146
     *
166
     *
147
     * @access public
167
     * @access public
148
     */
168
     */
149
    function PEAR_Command_Channels(&$ui, &$config)
169
    function __construct(&$ui, &$config)
150
    {
170
    {
151
        parent::PEAR_Command_Common($ui, $config);
171
        parent::__construct($ui, $config);
Line 152... Line -...
152
    }
-
 
153
 
-
 
154
    // }}}
-
 
155
 
-
 
156
    // {{{ doList()
172
    }
157
    
173
 
158
    function _sortChannels($a, $b)
174
    function _sortChannels($a, $b)
159
    {
175
    {
Line 167... Line 183...
167
        usort($registered, array(&$this, '_sortchannels'));
183
        usort($registered, array(&$this, '_sortchannels'));
168
        $i = $j = 0;
184
        $i = $j = 0;
169
        $data = array(
185
        $data = array(
170
            'caption' => 'Registered Channels:',
186
            'caption' => 'Registered Channels:',
171
            'border' => true,
187
            'border' => true,
172
            'headline' => array('Channel', 'Summary')
188
            'headline' => array('Channel', 'Alias', 'Summary')
173
            );
189
            );
174
        foreach ($registered as $channel) {
190
        foreach ($registered as $channel) {
175
            $data['data'][] = array($channel->getName(),
191
            $data['data'][] = array($channel->getName(),
-
 
192
                                    $channel->getAlias(),
176
                                      $channel->getSummary());
193
                                    $channel->getSummary());
177
        }
194
        }
-
 
195
 
178
        if (count($registered)==0) {
196
        if (count($registered) === 0) {
179
            $data = '(no registered channels)';
197
            $data = '(no registered channels)';
180
        }
198
        }
181
        $this->ui->outputData($data, $command);
199
        $this->ui->outputData($data, $command);
182
        return true;
200
        return true;
183
    }
201
    }
184
    
202
 
185
    function doUpdateAll($command, $options, $params)
203
    function doUpdateAll($command, $options, $params)
186
    {
204
    {
187
        $reg = &$this->config->getRegistry();
205
        $reg = &$this->config->getRegistry();
188
        $savechannel = $this->config->get('default_channel');
-
 
189
        if (isset($options['channel'])) {
-
 
190
            if (!$reg->channelExists($options['channel'])) {
-
 
191
                return $this->raiseError('Unknown channel "' . $options['channel'] . '"');
-
 
192
            }
-
 
193
            $this->config->set('default_channel', $options['channel']);
-
 
194
        } else {
-
 
195
            $this->config->set('default_channel', 'pear.php.net');
-
 
196
        }
-
 
197
        $remote = &$this->config->getRemote();
-
 
198
        $channels = $remote->call('channel.listAll');
206
        $channels = $reg->getChannels();
199
        if (PEAR::isError($channels)) {
-
 
200
            $this->config->set('default_channel', $savechannel);
-
 
201
            return $channels;
-
 
202
        }
-
 
203
        if (!is_array($channels) || isset($channels['faultCode'])) {
-
 
204
            $this->config->set('default_channel', $savechannel);
-
 
205
            return $this->raiseError("Incorrect channel listing returned from channel '$chan'");
-
 
206
        }
207
 
207
        if (!count($channels)) {
208
        $success = true;
208
            $data = 'no updates available';
-
 
209
        }
-
 
210
        $dl = &$this->getDownloader();
-
 
211
        if (!class_exists('System')) {
-
 
212
            require_once 'System.php';
-
 
213
        }
-
 
214
        $tmpdir = System::mktemp(array('-d'));
-
 
215
        foreach ($channels as $channel) {
209
        foreach ($channels as $channel) {
216
            $channel = $channel[0];
-
 
217
            $save = $channel;
-
 
218
            if ($reg->channelExists($channel, true)) {
-
 
219
                $this->ui->outputData("Updating channel \"$channel\"", $command);
-
 
220
                $test = $reg->getChannel($channel, true);
-
 
221
                if (PEAR::isError($test)) {
-
 
222
                    $this->ui->outputData("Channel '$channel' is corrupt in registry!", $command);
-
 
223
                    $lastmodified = false;
-
 
224
                } else {
-
 
225
                    $lastmodified = $test->lastModified();
-
 
226
                    
-
 
227
                }
-
 
228
                PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
-
 
229
                $contents = $dl->downloadHttp('http://' . $test->getName() . '/channel.xml',
-
 
230
                    $this->ui, $tmpdir, null, $lastmodified);
-
 
231
                PEAR::staticPopErrorHandling();
-
 
232
                if (PEAR::isError($contents)) {
-
 
233
                    $this->ui->outputData('ERROR: Cannot retrieve channel.xml for channel "' .
-
 
234
                        $test->getName() . '"', $command);
-
 
235
                    continue;
-
 
236
                }
-
 
237
                if (!$contents) {
-
 
238
                    $this->ui->outputData("Channel \"$channel\" is up-to-date", $command);
-
 
239
                    continue;
-
 
240
                }
-
 
241
                list($contents, $lastmodified) = $contents;
-
 
242
                $info = implode('', file($contents));
-
 
243
                if (!$info) {
-
 
244
                    $this->ui->outputData("Channel \"$channel\" is up-to-date", $command);
-
 
245
                    continue;
-
 
246
                }
-
 
247
                if (!class_exists('PEAR_ChannelFile')) {
-
 
248
                    require_once 'PEAR/ChannelFile.php';
-
 
249
                }
-
 
250
                $channelinfo = new PEAR_ChannelFile;
-
 
251
                $channelinfo->fromXmlString($info);
-
 
252
                if ($channelinfo->getErrors()) {
-
 
253
                    $this->ui->outputData("Downloaded channel data from channel \"$channel\" " . 
-
 
254
                        'is corrupt, skipping', $command);
-
 
255
                    continue;
-
 
256
                }
-
 
257
                $channel = $channelinfo;
-
 
258
                if ($channel->getName() != $save) {
210
            if ($channel->getName() != '__uri') {
259
                    $this->ui->outputData('ERROR: Security risk - downloaded channel ' .
-
 
260
                        'definition file for channel "'
-
 
261
                        . $channel->getName() . ' from channel "' . $save .
-
 
262
                        '".  To use anyway, use channel-update', $command);
-
 
263
                    continue;
-
 
264
                }
-
 
265
                $reg->updateChannel($channel, $lastmodified);
-
 
266
            } else {
-
 
267
                if ($reg->isAlias($channel)) {
-
 
268
                    $temp = &$reg->getChannel($channel);
-
 
269
                    if (PEAR::isError($temp)) {
-
 
270
                        return $this->raiseError($temp);
-
 
271
                    }
-
 
272
                    $temp->setAlias($temp->getName(), true); // set the alias to the channel name
-
 
273
                    if ($reg->channelExists($temp->getName())) {
-
 
274
                        $this->ui->outputData('ERROR: existing channel "' . $temp->getName() .
-
 
275
                            '" is aliased to "' . $channel . '" already and cannot be ' .
-
 
276
                            're-aliased to "' . $temp->getName() . '" because a channel with ' .
-
 
277
                            'that name or alias already exists!  Please re-alias and try ' .
-
 
278
                            'again.', $command);
-
 
279
                        continue;
-
 
280
                    }
-
 
281
                }
-
 
282
                $this->ui->outputData("Adding new channel \"$channel\"", $command);
-
 
283
                PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
211
                PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
284
                $contents = $dl->downloadHttp('http://' . $channel . '/channel.xml',
-
 
285
                    $this->ui, $tmpdir, null, false);
212
                $err = $this->doUpdate('channel-update',
286
                PEAR::staticPopErrorHandling();
-
 
287
                if (PEAR::isError($contents)) {
-
 
288
                    $this->ui->outputData('ERROR: Cannot retrieve channel.xml for channel "' .
-
 
289
                        $channel . '"', $command);
213
                                          $options,
290
                    continue;
-
 
291
                }
-
 
292
                list($contents, $lastmodified) = $contents;
-
 
293
                $info = implode('', file($contents));
-
 
294
                if (!class_exists('PEAR_ChannelFile')) {
-
 
295
                    require_once 'PEAR/ChannelFile.php';
214
                                          array($channel->getName()));
296
                }
-
 
297
                $channelinfo = new PEAR_Channelfile;
-
 
298
                $channelinfo->fromXmlString($info);
-
 
299
                if ($channelinfo->getErrors()) {
215
                if (PEAR::isError($err)) {
300
                    $this->ui->outputData("Downloaded channel data from channel \"$channel\"" .
-
 
301
                        ' is corrupt, skipping', $command);
216
                    $this->ui->outputData($err->getMessage(), $command);
302
                    continue;
217
                    $success = false;
303
                }
218
                } else {
304
                $channel = $channelinfo;
-
 
305
                if ($channel->getName() != $save) {
-
 
306
                    $this->ui->outputData('ERROR: Security risk - downloaded channel ' .
-
 
307
                        'definition file for channel "'
-
 
308
                        . $channel->getName() . '" from channel "' . $save .
-
 
309
                        '".  To use anyway, use channel-update', $command);
-
 
310
                    continue;
219
                    $success &= $err;
311
                }
220
                }
312
                $reg->addChannel($channel, $lastmodified);
-
 
313
            }
221
            }
314
        }
222
        }
315
        $this->config->set('default_channel', $savechannel);
-
 
316
        $this->ui->outputData('update-channels complete', $command);
-
 
317
        return true;
223
        return $success;
318
    }
224
    }
319
    
225
 
320
    function doInfo($command, $options, $params)
226
    function doInfo($command, $options, $params)
321
    {
227
    {
322
        if (sizeof($params) != 1) {
228
        if (count($params) !== 1) {
323
            return $this->raiseError("No channel specified");
229
            return $this->raiseError("No channel specified");
324
        }
230
        }
-
 
231
 
325
        $reg = &$this->config->getRegistry();
232
        $reg     = &$this->config->getRegistry();
326
        $channel = strtolower($params[0]);
233
        $channel = strtolower($params[0]);
327
        if ($reg->channelExists($channel)) {
234
        if ($reg->channelExists($channel)) {
328
            $chan = $reg->getChannel($channel);
235
            $chan = $reg->getChannel($channel);
329
            if (PEAR::isError($chan)) {
236
            if (PEAR::isError($chan)) {
330
                return $this->raiseError($chan);
237
                return $this->raiseError($chan);
331
            }
238
            }
332
        } else {
239
        } else {
333
            if (strpos($channel, '://')) {
240
            if (strpos($channel, '://')) {
334
                $downloader = &$this->getDownloader();
241
                $downloader = &$this->getDownloader();
335
                if (!class_exists('System')) {
-
 
336
                    require_once 'System.php';
-
 
337
                }
-
 
338
                $tmpdir = System::mktemp(array('-d'));
242
                $tmpdir = $this->config->get('temp_dir');
339
                PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
243
                PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
340
                $loc = $downloader->downloadHttp($channel, $this->ui, $tmpdir);
244
                $loc = $downloader->downloadHttp($channel, $this->ui, $tmpdir);
341
                PEAR::staticPopErrorHandling();
245
                PEAR::staticPopErrorHandling();
342
                if (PEAR::isError($loc)) {
246
                if (PEAR::isError($loc)) {
343
                    return $this->raiseError('Cannot open "' . $channel . '"');
247
                    return $this->raiseError('Cannot open "' . $channel .
-
 
248
                        '" (' . $loc->getMessage() . ')');
344
                } else {
249
                } else {
345
                    $contents = implode('', file($loc));
250
                    $contents = implode('', file($loc));
346
                }
251
                }
347
            } else {
252
            } else {
348
                if (file_exists($params[0])) {
253
                if (!file_exists($params[0])) {
349
                    $fp = fopen($params[0], 'r');
-
 
350
                    if (!$fp) {
-
 
351
                        return $this->raiseError('Cannot open "' . $params[0] . '"');
-
 
352
                    }
-
 
353
                } else {
-
 
354
                    return $this->raiseError('Unknown channel "' . $channel . '"');
254
                    return $this->raiseError('Unknown channel "' . $channel . '"');
355
                }
255
                }
-
 
256
 
-
 
257
                $fp = fopen($params[0], 'r');
-
 
258
                if (!$fp) {
-
 
259
                    return $this->raiseError('Cannot open "' . $params[0] . '"');
-
 
260
                }
-
 
261
 
356
                $contents = '';
262
                $contents = '';
357
                while (!feof($fp)) {
263
                while (!feof($fp)) {
358
                    $contents .= fread($fp, 1024);
264
                    $contents .= fread($fp, 1024);
359
                }
265
                }
360
                fclose($fp);
266
                fclose($fp);
361
            }
267
            }
-
 
268
 
362
            if (!class_exists('PEAR_ChannelFile')) {
269
            if (!class_exists('PEAR_ChannelFile')) {
363
                require_once 'PEAR/ChannelFile.php';
270
                require_once 'PEAR/ChannelFile.php';
364
            }
271
            }
-
 
272
 
365
            $chan = new PEAR_ChannelFile;
273
            $chan = new PEAR_ChannelFile;
366
            $chan->fromXmlString($contents);
274
            $chan->fromXmlString($contents);
367
            $chan->validate();
275
            $chan->validate();
368
            if ($errs = $chan->getErrors(true)) {
276
            if ($errs = $chan->getErrors(true)) {
369
                foreach ($errs as $err) {
277
                foreach ($errs as $err) {
370
                    $this->ui->outputData($err['level'] . ': ' . $err['message']);
278
                    $this->ui->outputData($err['level'] . ': ' . $err['message']);
371
                }
279
                }
372
                return $this->raiseError('Channel file "' . $params[0] . '" is not valid');
280
                return $this->raiseError('Channel file "' . $params[0] . '" is not valid');
373
            }
281
            }
374
        }
282
        }
-
 
283
 
375
        if ($chan) {
284
        if (!$chan) {
-
 
285
            return $this->raiseError('Serious error: Channel "' . $params[0] .
-
 
286
                '" has a corrupted registry entry');
-
 
287
        }
-
 
288
 
376
            $channel = $chan->getName();
289
        $channel = $chan->getName();
377
            $caption = 'Channel ' . $channel . ' Information:';
290
        $caption = 'Channel ' . $channel . ' Information:';
378
            $data1 = array(
291
        $data1 = array(
379
                'caption' => $caption,
292
            'caption' => $caption,
380
                'border' => true);
293
            'border' => true);
381
            $data1['data']['server'] = array('Name and Server', $chan->getName());
294
        $data1['data']['server'] = array('Name and Server', $chan->getName());
382
            if ($chan->getAlias() != $chan->getName()) {
295
        if ($chan->getAlias() != $chan->getName()) {
383
                $data1['data']['alias'] = array('Alias', $chan->getAlias());
296
            $data1['data']['alias'] = array('Alias', $chan->getAlias());
384
            }
297
        }
-
 
298
 
385
            $data1['data']['summary'] = array('Summary', $chan->getSummary());
299
        $data1['data']['summary'] = array('Summary', $chan->getSummary());
386
            $validate = $chan->getValidationPackage();
300
        $validate = $chan->getValidationPackage();
387
            $data1['data']['vpackage'] = array('Validation Package Name', $validate['_content']);
301
        $data1['data']['vpackage'] = array('Validation Package Name', $validate['_content']);
388
            $data1['data']['vpackageversion'] =
302
        $data1['data']['vpackageversion'] =
389
                array('Validation Package Version', $validate['attribs']['version']);
303
            array('Validation Package Version', $validate['attribs']['version']);
390
            $d = array();
304
        $d = array();
391
            $d['main'] = $data1;
305
        $d['main'] = $data1;
392
 
306
 
393
            $data['data'] = array();
307
        $data['data'] = array();
394
            $data['caption'] = 'Server Capabilities';
308
        $data['caption'] = 'Server Capabilities';
395
            $data['headline'] = array('Type', 'Version/REST type', 'Function Name/REST base');
309
        $data['headline'] = array('Type', 'Version/REST type', 'Function Name/REST base');
396
            $capabilities = $chan->getFunctions('xmlrpc');
-
 
397
            $soaps = $chan->getFunctions('soap');
-
 
398
            if ($capabilities || $soaps || $chan->supportsREST()) {
310
        if ($chan->supportsREST()) {
399
                if ($capabilities) {
-
 
400
                    if (!isset($capabilities[0])) {
-
 
401
                        $capabilities = array($capabilities);
-
 
402
                    }
-
 
403
                    foreach ($capabilities as $protocol) {
-
 
404
                        $data['data'][] = array('xmlrpc', $protocol['attribs']['version'],
-
 
405
                            $protocol['_content']);
-
 
406
                    }
-
 
407
                }
-
 
408
                if ($soaps) {
-
 
409
                    if (!isset($soaps[0])) {
-
 
410
                        $soaps = array($soaps);
-
 
411
                    }
-
 
412
                    foreach ($soaps as $protocol) {
-
 
413
                        $data['data'][] = array('soap', $protocol['attribs']['version'],
-
 
414
                            $protocol['_content']);
-
 
415
                    }
-
 
416
                }
-
 
417
                if ($chan->supportsREST()) {
311
            if ($chan->supportsREST()) {
418
                    $funcs = $chan->getFunctions('rest');
312
                $funcs = $chan->getFunctions('rest');
419
                    if (!isset($funcs[0])) {
313
                if (!isset($funcs[0])) {
420
                        $funcs = array($funcs);
314
                    $funcs = array($funcs);
421
                    }
315
                }
422
                    foreach ($funcs as $protocol) {
316
                foreach ($funcs as $protocol) {
423
                        $data['data'][] = array('rest', $protocol['attribs']['type'],
317
                    $data['data'][] = array('rest', $protocol['attribs']['type'],
424
                            $protocol['_content']); 
318
                        $protocol['_content']);
425
                    }
-
 
426
                }
319
                }
427
            } else {
-
 
428
                $data['data'][] = array('No supported protocols');
-
 
429
            }
320
            }
-
 
321
        } else {
-
 
322
            $data['data'][] = array('No supported protocols');
-
 
323
        }
-
 
324
 
430
            $d['protocols'] = $data;
325
        $d['protocols'] = $data;
431
            $data['data'] = array();
326
        $data['data'] = array();
432
            $mirrors = $chan->getMirrors();
327
        $mirrors = $chan->getMirrors();
433
            if ($mirrors) {
328
        if ($mirrors) {
434
                $data['caption'] = 'Channel ' . $channel . ' Mirrors:';
329
            $data['caption'] = 'Channel ' . $channel . ' Mirrors:';
435
                unset($data['headline']);
330
            unset($data['headline']);
436
                foreach ($mirrors as $mirror) {
331
            foreach ($mirrors as $mirror) {
437
                    $data['data'][] = array($mirror['attribs']['host']);
332
                $data['data'][] = array($mirror['attribs']['host']);
438
                    $d['mirrors'] = $data;
333
                $d['mirrors'] = $data;
439
                }
334
            }
-
 
335
 
440
                foreach ($mirrors as $mirror) {
336
            foreach ($mirrors as $i => $mirror) {
441
                    $data['data'] = array();
337
                $data['data'] = array();
442
                    $data['caption'] = 'Mirror ' . $mirror['attribs']['host'] . ' Capabilities';
338
                $data['caption'] = 'Mirror ' . $mirror['attribs']['host'] . ' Capabilities';
443
                    $data['headline'] = array('Type', 'Version/REST type', 'Function Name/REST base');
339
                $data['headline'] = array('Type', 'Version/REST type', 'Function Name/REST base');
444
                    $capabilities = $chan->getFunctions('xmlrpc', $mirror['attribs']['host']);
-
 
445
                    $soaps = $chan->getFunctions('soap', $mirror['attribs']['host']);
340
                if ($chan->supportsREST($mirror['attribs']['host'])) {
446
                    if ($capabilities || $soaps || $chan->supportsREST($mirror['attribs']['host'])) {
341
                    if ($chan->supportsREST($mirror['attribs']['host'])) {
447
                        if ($capabilities) {
-
 
448
                            if (!isset($capabilities[0])) {
-
 
449
                                $capabilities = array($capabilities);
-
 
450
                            }
-
 
451
                            foreach ($capabilities as $protocol) {
-
 
452
                                $data['data'][] = array('xmlrpc', $protocol['attribs']['version'],
342
                        $funcs = $chan->getFunctions('rest', $mirror['attribs']['host']);
453
                                    $protocol['_content']);
-
 
454
                            }
-
 
455
                        }
-
 
456
                        if ($soaps) {
-
 
457
                            if (!isset($soaps[0])) {
343
                        if (!isset($funcs[0])) {
458
                                $soaps = array($soaps);
344
                            $funcs = array($funcs);
459
                            }
-
 
460
                            foreach ($soaps as $protocol) {
-
 
461
                                $data['data'][] = array('soap', $protocol['attribs']['version'],
-
 
462
                                    $protocol['_content']);
-
 
463
                            }
-
 
464
                        }
345
                        }
465
                        if ($chan->supportsREST($mirror['attribs']['host'])) {
-
 
466
                            $funcs = $chan->getFunctions('rest', $mirror['attribs']['host']);
-
 
467
                            if (!isset($funcs[0])) {
-
 
468
                                $funcs = array($funcs);
-
 
469
                            }
-
 
-
 
346
 
470
                            foreach ($funcs as $protocol) {
347
                        foreach ($funcs as $protocol) {
471
                                $data['data'][] = array('rest', $protocol['attribs']['type'],
348
                            $data['data'][] = array('rest', $protocol['attribs']['type'],
472
                                    $protocol['_content']); 
349
                                $protocol['_content']);
473
                            }
-
 
474
                        }
350
                        }
475
                    } else {
-
 
476
                        $data['data'][] = array('No supported protocols');
-
 
477
                    }
351
                    }
-
 
352
                } else {
478
                    $d['mirrorprotocols'] = $data;
353
                    $data['data'][] = array('No supported protocols');
479
                }
354
                }
-
 
355
                $d['mirrorprotocols' . $i] = $data;
480
            }
356
            }
481
            $this->ui->outputData($d, 'channel-info');
-
 
482
        } else {
-
 
483
            return $this->raiseError('Serious error: Channel "' . $params[0] .
-
 
484
                '" has a corrupted registry entry');
-
 
485
        }
357
        }
-
 
358
        $this->ui->outputData($d, 'channel-info');
486
    }
359
    }
Line 487... Line 360...
487
 
360
 
488
    // }}}
361
    // }}}
489
    
362
 
490
    function doDelete($command, $options, $params)
363
    function doDelete($command, $options, $params)
491
    {
364
    {
492
        if (sizeof($params) != 1) {
365
        if (count($params) !== 1) {
493
            return $this->raiseError('channel-delete: no channel specified');
366
            return $this->raiseError('channel-delete: no channel specified');
-
 
367
        }
494
        }
368
 
495
        $reg = &$this->config->getRegistry();
369
        $reg = &$this->config->getRegistry();
496
        if (!$reg->channelExists($params[0])) {
370
        if (!$reg->channelExists($params[0])) {
497
            return $this->raiseError('channel-delete: channel "' . $params[0] . '" does not exist');
371
            return $this->raiseError('channel-delete: channel "' . $params[0] . '" does not exist');
-
 
372
        }
498
        }
373
 
499
        $channel = $reg->channelName($params[0]);
374
        $channel = $reg->channelName($params[0]);
500
        if ($channel == 'pear.php.net') {
375
        if ($channel == 'pear.php.net') {
501
            return $this->raiseError('Cannot delete the pear.php.net channel');
376
            return $this->raiseError('Cannot delete the pear.php.net channel');
-
 
377
        }
502
        }
378
 
503
        if ($channel == 'pecl.php.net') {
379
        if ($channel == 'pecl.php.net') {
504
            return $this->raiseError('Cannot delete the pecl.php.net channel');
380
            return $this->raiseError('Cannot delete the pecl.php.net channel');
-
 
381
        }
-
 
382
 
-
 
383
        if ($channel == 'doc.php.net') {
-
 
384
            return $this->raiseError('Cannot delete the doc.php.net channel');
-
 
385
        }
505
        }
386
 
506
        if ($channel == '__uri') {
387
        if ($channel == '__uri') {
507
            return $this->raiseError('Cannot delete the __uri pseudo-channel');
388
            return $this->raiseError('Cannot delete the __uri pseudo-channel');
-
 
389
        }
508
        }
390
 
509
        if (PEAR::isError($err = $reg->listPackages($channel))) {
391
        if (PEAR::isError($err = $reg->listPackages($channel))) {
510
            return $err;
392
            return $err;
-
 
393
        }
511
        }
394
 
512
        if (count($err)) {
395
        if (count($err)) {
513
            return $this->raiseError('Channel "' . $channel .
396
            return $this->raiseError('Channel "' . $channel .
514
                '" has installed packages, cannot delete');
397
                '" has installed packages, cannot delete');
-
 
398
        }
515
        }
399
 
516
        if (!$reg->deleteChannel($channel)) {
400
        if (!$reg->deleteChannel($channel)) {
517
            return $this->raiseError('Channel "' . $channel . '" deletion failed');
401
            return $this->raiseError('Channel "' . $channel . '" deletion failed');
518
        } else {
402
        } else {
519
            $this->config->deleteChannel($channel);
403
            $this->config->deleteChannel($channel);
520
            $this->ui->outputData('Channel "' . $channel . '" deleted', $command);
404
            $this->ui->outputData('Channel "' . $channel . '" deleted', $command);
521
        }
405
        }
Line 522... Line 406...
522
    }
406
    }
523
 
407
 
524
    function doAdd($command, $options, $params)
408
    function doAdd($command, $options, $params)
525
    {
409
    {
526
        if (sizeof($params) != 1) {
410
        if (count($params) !== 1) {
-
 
411
            return $this->raiseError('channel-add: no channel file specified');
527
            return $this->raiseError('channel-add: no channel file specified');
412
        }
528
        }
413
 
-
 
414
        if (strpos($params[0], '://')) {
529
        if (strpos($params[0], '://')) {
415
            $downloader = &$this->getDownloader();
530
            $downloader = &$this->getDownloader();
416
            $tmpdir = $this->config->get('temp_dir');
-
 
417
            if (!file_exists($tmpdir)) {
-
 
418
                require_once 'System.php';
-
 
419
                PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
-
 
420
                $err = System::mkdir(array('-p', $tmpdir));
-
 
421
                PEAR::staticPopErrorHandling();
-
 
422
                if (PEAR::isError($err)) {
-
 
423
                    return $this->raiseError('channel-add: temp_dir does not exist: "' .
-
 
424
                        $tmpdir .
-
 
425
                        '" - You can change this location with "pear config-set temp_dir"');
-
 
426
                }
-
 
427
            }
-
 
428
 
-
 
429
            if (!is_writable($tmpdir)) {
-
 
430
                return $this->raiseError('channel-add: temp_dir is not writable: "' .
531
            if (!class_exists('System')) {
431
                    $tmpdir .
532
                require_once 'System.php';
-
 
-
 
432
                    '" - You can change this location with "pear config-set temp_dir"');
533
            }
433
            }
534
            $tmpdir = System::mktemp(array('-d'));
434
 
535
            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
435
            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
536
            $loc = $downloader->downloadHttp($params[0], $this->ui, $tmpdir, null, false);
436
            $loc = $downloader->downloadHttp($params[0], $this->ui, $tmpdir, null, false);
537
            PEAR::staticPopErrorHandling();
437
            PEAR::staticPopErrorHandling();
538
            if (PEAR::isError($loc)) {
-
 
539
                return $this->raiseError('channel-add: Cannot open "' . $params[0] . '"');
438
            if (PEAR::isError($loc)) {
540
            } else {
-
 
541
                list($loc, $lastmodified) = $loc;
439
                return $this->raiseError('channel-add: Cannot open "' . $params[0] .
-
 
440
                    '" (' . $loc->getMessage() . ')');
-
 
441
            }
-
 
442
 
542
                $contents = implode('', file($loc));
443
            list($loc, $lastmodified) = $loc;
543
            }
444
            $contents = implode('', file($loc));
544
        } else {
445
        } else {
545
            $lastmodified = $fp = false;
446
            $lastmodified = $fp = false;
546
            if (file_exists($params[0])) {
447
            if (file_exists($params[0])) {
-
 
448
                $fp = fopen($params[0], 'r');
547
                $fp = fopen($params[0], 'r');
449
            }
548
            }
450
 
549
            if (!$fp) {
451
            if (!$fp) {
-
 
452
                return $this->raiseError('channel-add: cannot open "' . $params[0] . '"');
550
                return $this->raiseError('channel-add: cannot open "' . $params[0] . '"');
453
            }
551
            }
454
 
552
            $contents = '';
455
            $contents = '';
553
            while (!feof($fp)) {
456
            while (!feof($fp)) {
554
                $contents .= fread($fp, 1024);
457
                $contents .= fread($fp, 1024);
555
            }
458
            }
-
 
459
            fclose($fp);
556
            fclose($fp);
460
        }
557
        }
461
 
558
        if (!class_exists('PEAR_ChannelFile')) {
462
        if (!class_exists('PEAR_ChannelFile')) {
-
 
463
            require_once 'PEAR/ChannelFile.php';
559
            require_once 'PEAR/ChannelFile.php';
464
        }
560
        }
465
 
561
        $channel = new PEAR_ChannelFile;
466
        $channel = new PEAR_ChannelFile;
562
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
467
        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
563
        $result = $channel->fromXmlString($contents);
468
        $result = $channel->fromXmlString($contents);
Line 574... Line 479...
574
                if ($exit) {
479
                if ($exit) {
575
                    return $this->raiseError('channel-add: invalid channel.xml file');
480
                    return $this->raiseError('channel-add: invalid channel.xml file');
576
                }
481
                }
577
            }
482
            }
578
        }
483
        }
-
 
484
 
579
        $reg = &$this->config->getRegistry();
485
        $reg = &$this->config->getRegistry();
580
        if ($reg->channelExists($channel->getName())) {
486
        if ($reg->channelExists($channel->getName())) {
581
            return $this->raiseError('channel-add: Channel "' . $channel->getName() .
487
            return $this->raiseError('channel-add: Channel "' . $channel->getName() .
582
                '" exists, use channel-update to update entry');
488
                '" exists, use channel-update to update entry', PEAR_COMMAND_CHANNELS_CHANNEL_EXISTS);
583
        }
489
        }
-
 
490
 
584
        $ret = $reg->addChannel($channel, $lastmodified);
491
        $ret = $reg->addChannel($channel, $lastmodified);
585
        if (PEAR::isError($ret)) {
492
        if (PEAR::isError($ret)) {
586
            return $ret;
493
            return $ret;
587
        }
494
        }
-
 
495
 
588
        if (!$ret) {
496
        if (!$ret) {
589
            return $this->raiseError('channel-add: adding Channel "' . $channel->getName() .
497
            return $this->raiseError('channel-add: adding Channel "' . $channel->getName() .
590
                '" to registry failed');
498
                '" to registry failed');
591
        }
499
        }
-
 
500
 
592
        $this->config->setChannels($reg->listChannels());
501
        $this->config->setChannels($reg->listChannels());
593
        $this->config->writeConfigFile();
502
        $this->config->writeConfigFile();
594
        $this->ui->outputData('Adding Channel "' . $channel->getName() . '" succeeded', $command);
503
        $this->ui->outputData('Adding Channel "' . $channel->getName() . '" succeeded', $command);
595
    }
504
    }
Line 596... Line 505...
596
 
505
 
597
    function doUpdate($command, $options, $params)
506
    function doUpdate($command, $options, $params)
-
 
507
    {
-
 
508
        if (count($params) !== 1) {
-
 
509
            return $this->raiseError("No channel file specified");
-
 
510
        }
-
 
511
 
598
    {
512
        $tmpdir = $this->config->get('temp_dir');
599
        if (!class_exists('System')) {
513
        if (!file_exists($tmpdir)) {
-
 
514
            require_once 'System.php';
-
 
515
            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
-
 
516
            $err = System::mkdir(array('-p', $tmpdir));
-
 
517
            PEAR::staticPopErrorHandling();
-
 
518
            if (PEAR::isError($err)) {
-
 
519
                return $this->raiseError('channel-add: temp_dir does not exist: "' .
-
 
520
                    $tmpdir .
-
 
521
                    '" - You can change this location with "pear config-set temp_dir"');
600
            require_once 'System.php';
522
            }
-
 
523
        }
601
        }
524
 
602
        $tmpdir = System::mktemp(array('-d'));
525
        if (!is_writable($tmpdir)) {
603
        $reg = &$this->config->getRegistry();
526
            return $this->raiseError('channel-add: temp_dir is not writable: "' .
604
        if (sizeof($params) != 1) {
527
                $tmpdir .
605
            return $this->raiseError("No channel file specified");
528
                '" - You can change this location with "pear config-set temp_dir"');
-
 
529
        }
-
 
530
 
606
        }
531
        $reg = &$this->config->getRegistry();
607
        $lastmodified = false;
532
        $lastmodified = false;
608
        if ((!file_exists($params[0]) || is_dir($params[0]))
533
        if ((!file_exists($params[0]) || is_dir($params[0]))
609
              && $reg->channelExists(strtolower($params[0]))) {
534
              && $reg->channelExists(strtolower($params[0]))) {
610
            $c = $reg->getChannel(strtolower($params[0]));
535
            $c = $reg->getChannel(strtolower($params[0]));
611
            if (PEAR::isError($c)) {
536
            if (PEAR::isError($c)) {
612
                return $this->raiseError($c);
537
                return $this->raiseError($c);
-
 
538
            }
613
            }
539
 
614
            $this->ui->outputData('Retrieving channel.xml from remote server');
540
            $this->ui->outputData("Updating channel \"$params[0]\"", $command);
615
            $dl = &$this->getDownloader(array());
541
            $dl = &$this->getDownloader(array());
616
            // if force is specified, use a timestamp of "1" to force retrieval
542
            // if force is specified, use a timestamp of "1" to force retrieval
617
            $lastmodified = isset($options['force']) ? false : $c->lastModified();
543
            $lastmodified = isset($options['force']) ? false : $c->lastModified();
618
            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
544
            PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
619
            $contents = $dl->downloadHttp('http://' . $c->getName() . '/channel.xml',
545
            $contents = $dl->downloadHttp('http://' . $c->getName() . '/channel.xml',
620
                $this->ui, $tmpdir, null, $lastmodified);
546
                $this->ui, $tmpdir, null, $lastmodified);
621
            PEAR::staticPopErrorHandling();
547
            PEAR::staticPopErrorHandling();
-
 
548
            if (PEAR::isError($contents)) {
-
 
549
                // Attempt to fall back to https
-
 
550
                $this->ui->outputData("Channel \"$params[0]\" is not responding over http://, failed with message: " . $contents->getMessage());
-
 
551
                $this->ui->outputData("Trying channel \"$params[0]\" over https:// instead");
-
 
552
                PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
-
 
553
                $contents = $dl->downloadHttp('https://' . $c->getName() . '/channel.xml',
-
 
554
                    $this->ui, $tmpdir, null, $lastmodified);
-
 
555
                PEAR::staticPopErrorHandling();
622
            if (PEAR::isError($contents)) {
556
                if (PEAR::isError($contents)) {
623
                return $this->raiseError('Cannot retrieve channel.xml for channel "' .
557
                    return $this->raiseError('Cannot retrieve channel.xml for channel "' .
-
 
558
                        $c->getName() . '" (' . $contents->getMessage() . ')');
624
                    $c->getName() . '"');
559
                }
-
 
560
            }
625
            }
561
 
626
            list($contents, $lastmodified) = $contents;
562
            list($contents, $lastmodified) = $contents;
627
            if (!$contents) {
563
            if (!$contents) {
628
                $this->ui->outputData("Channel $params[0] channel.xml is up to date");
564
                $this->ui->outputData("Channel \"$params[0]\" is up to date");
629
                return;
565
                return;
-
 
566
            }
630
            }
567
 
631
            $contents = implode('', file($contents));
568
            $contents = implode('', file($contents));
632
            if (!class_exists('PEAR_ChannelFile')) {
569
            if (!class_exists('PEAR_ChannelFile')) {
633
                require_once 'PEAR/ChannelFile.php';
570
                require_once 'PEAR/ChannelFile.php';
-
 
571
            }
634
            }
572
 
635
            $channel = new PEAR_ChannelFile;
573
            $channel = new PEAR_ChannelFile;
636
            $channel->fromXmlString($contents);
574
            $channel->fromXmlString($contents);
637
            if (!$channel->getErrors()) {
575
            if (!$channel->getErrors()) {
638
                // security check: is the downloaded file for the channel we got it from?
576
                // security check: is the downloaded file for the channel we got it from?
639
                if (strtolower($channel->getName()) != strtolower($c->getName())) {
577
                if (strtolower($channel->getName()) != strtolower($c->getName())) {
640
                    if (isset($options['force'])) {
-
 
641
                        $this->ui->log(0, 'WARNING: downloaded channel definition file' .
-
 
642
                            ' for channel "' . $channel->getName() . '" from channel "' .
-
 
643
                            strtolower($c->getName()) . '"');
-
 
644
                    } else {
578
                    if (!isset($options['force'])) {
645
                        return $this->raiseError('ERROR: downloaded channel definition file' .
579
                        return $this->raiseError('ERROR: downloaded channel definition file' .
646
                            ' for channel "' . $channel->getName() . '" from channel "' .
580
                            ' for channel "' . $channel->getName() . '" from channel "' .
647
                            strtolower($c->getName()) . '"');
581
                            strtolower($c->getName()) . '"');
-
 
582
                    }
-
 
583
 
-
 
584
                    $this->ui->log(0, 'WARNING: downloaded channel definition file' .
-
 
585
                        ' for channel "' . $channel->getName() . '" from channel "' .
648
                    }
586
                        strtolower($c->getName()) . '"');
649
                }
587
                }
650
            }
588
            }
651
        } else {
589
        } else {
652
            if (strpos($params[0], '://')) {
590
            if (strpos($params[0], '://')) {
653
                $dl = &$this->getDownloader();
591
                $dl = &$this->getDownloader();
654
                PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
592
                PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
655
                $loc = $dl->downloadHttp($params[0],
593
                $loc = $dl->downloadHttp($params[0],
656
                    $this->ui, $tmpdir, null, $lastmodified);
594
                    $this->ui, $tmpdir, null, $lastmodified);
657
                PEAR::staticPopErrorHandling();
595
                PEAR::staticPopErrorHandling();
658
                if (PEAR::isError($loc)) {
596
                if (PEAR::isError($loc)) {
659
                    return $this->raiseError("Cannot open " . $params[0]);
-
 
660
                } else {
597
                    return $this->raiseError("Cannot open " . $params[0] .
661
                    list($loc, $lastmodified) = $loc;
-
 
662
                    $contents = implode('', file($loc));
598
                         ' (' . $loc->getMessage() . ')');
-
 
599
                }
-
 
600
 
-
 
601
                list($loc, $lastmodified) = $loc;
663
                }
602
                $contents = implode('', file($loc));
664
            } else {
603
            } else {
665
                $fp = false;
604
                $fp = false;
666
                if (file_exists($params[0])) {
605
                if (file_exists($params[0])) {
667
                    $fp = fopen($params[0], 'r');
606
                    $fp = fopen($params[0], 'r');
-
 
607
                }
668
                }
608
 
669
                if (!$fp) {
609
                if (!$fp) {
670
                    return $this->raiseError("Cannot open " . $params[0]);
610
                    return $this->raiseError("Cannot open " . $params[0]);
-
 
611
                }
671
                }
612
 
672
                $contents = '';
613
                $contents = '';
673
                while (!feof($fp)) {
614
                while (!feof($fp)) {
674
                    $contents .= fread($fp, 1024);
615
                    $contents .= fread($fp, 1024);
675
                }
616
                }
676
                fclose($fp);
617
                fclose($fp);
-
 
618
            }
677
            }
619
 
678
            if (!class_exists('PEAR_ChannelFile')) {
620
            if (!class_exists('PEAR_ChannelFile')) {
679
                require_once 'PEAR/ChannelFile.php';
621
                require_once 'PEAR/ChannelFile.php';
-
 
622
            }
680
            }
623
 
681
            $channel = new PEAR_ChannelFile;
624
            $channel = new PEAR_ChannelFile;
682
            $channel->fromXmlString($contents);
625
            $channel->fromXmlString($contents);
-
 
626
        }
683
        }
627
 
684
        $exit = false;
628
        $exit = false;
685
        if (count($errors = $channel->getErrors(true))) {
629
        if (count($errors = $channel->getErrors(true))) {
686
            foreach ($errors as $error) {
630
            foreach ($errors as $error) {
687
                $this->ui->outputData(ucfirst($error['level'] . ': ' . $error['message']));
631
                $this->ui->outputData(ucfirst($error['level'] . ': ' . $error['message']));
Line 691... Line 635...
691
            }
635
            }
692
            if ($exit) {
636
            if ($exit) {
693
                return $this->raiseError('Invalid channel.xml file');
637
                return $this->raiseError('Invalid channel.xml file');
694
            }
638
            }
695
        }
639
        }
-
 
640
 
696
        if (!$reg->channelExists($channel->getName())) {
641
        if (!$reg->channelExists($channel->getName())) {
697
            return $this->raiseError('Error: Channel "' . $channel->getName() .
642
            return $this->raiseError('Error: Channel "' . $channel->getName() .
698
                '" does not exist, use channel-add to add an entry');
643
                '" does not exist, use channel-add to add an entry');
699
        }
644
        }
-
 
645
 
700
        $ret = $reg->updateChannel($channel, $lastmodified);
646
        $ret = $reg->updateChannel($channel, $lastmodified);
701
        if (PEAR::isError($ret)) {
647
        if (PEAR::isError($ret)) {
702
            return $ret;
648
            return $ret;
703
        }
649
        }
-
 
650
 
704
        if (!$ret) {
651
        if (!$ret) {
705
            return $this->raiseError('Updating Channel "' . $channel->getName() .
652
            return $this->raiseError('Updating Channel "' . $channel->getName() .
706
                '" in registry failed');
653
                '" in registry failed');
707
        }
654
        }
-
 
655
 
708
        $this->config->setChannels($reg->listChannels());
656
        $this->config->setChannels($reg->listChannels());
709
        $this->config->writeConfigFile();
657
        $this->config->writeConfigFile();
710
        $this->ui->outputData('Update of Channel "' . $channel->getName() . '" succeeded');
658
        $this->ui->outputData('Update of Channel "' . $channel->getName() . '" succeeded');
711
    }
659
    }
Line 719... Line 667...
719
        return $a;
667
        return $a;
720
    }
668
    }
Line 721... Line 669...
721
 
669
 
722
    function doAlias($command, $options, $params)
670
    function doAlias($command, $options, $params)
723
    {
-
 
724
        $reg = &$this->config->getRegistry();
671
    {
725
        if (sizeof($params) == 1) {
672
        if (count($params) === 1) {
726
            return $this->raiseError('No channel alias specified');
673
            return $this->raiseError('No channel alias specified');
-
 
674
        }
727
        }
675
 
728
        if (sizeof($params) != 2) {
676
        if (count($params) !== 2 || (!empty($params[1]) && $params[1]{0} == '-')) {
729
            return $this->raiseError(
677
            return $this->raiseError(
730
                'Invalid format, correct is: channel-alias channel alias');
678
                'Invalid format, correct is: channel-alias channel alias');
-
 
679
        }
-
 
680
 
731
        }
681
        $reg = &$this->config->getRegistry();
-
 
682
        if (!$reg->channelExists($params[0], true)) {
732
        if (!$reg->channelExists($params[0], true)) {
683
            $extra = '';
733
            if ($reg->isAlias($params[0])) {
684
            if ($reg->isAlias($params[0])) {
734
                $extra = ' (use "channel-alias ' . $reg->channelName($params[0]) . ' ' .
685
                $extra = ' (use "channel-alias ' . $reg->channelName($params[0]) . ' ' .
735
                    strtolower($params[1]) . '")';
-
 
736
            } else {
-
 
737
                $extra = '';
686
                    strtolower($params[1]) . '")';
-
 
687
            }
738
            }
688
 
739
            return $this->raiseError('"' . $params[0] . '" is not a valid channel' . $extra);
689
            return $this->raiseError('"' . $params[0] . '" is not a valid channel' . $extra);
-
 
690
        }
740
        }
691
 
741
        if ($reg->isAlias($params[1])) {
692
        if ($reg->isAlias($params[1])) {
742
            return $this->raiseError('Channel "' . $reg->channelName($params[1]) . '" is ' .
693
            return $this->raiseError('Channel "' . $reg->channelName($params[1]) . '" is ' .
743
                'already aliased to "' . strtolower($params[1]) . '", cannot re-alias');
694
                'already aliased to "' . strtolower($params[1]) . '", cannot re-alias');
-
 
695
        }
744
        }
696
 
745
        $chan = &$reg->getChannel($params[0]);
697
        $chan = $reg->getChannel($params[0]);
746
        if (PEAR::isError($chan)) {
698
        if (PEAR::isError($chan)) {
747
            return $this->raiseError('Corrupt registry?  Error retrieving channel "' . $params[0] .
699
            return $this->raiseError('Corrupt registry?  Error retrieving channel "' . $params[0] .
748
                '" information (' . $chan->getMessage() . ')');
700
                '" information (' . $chan->getMessage() . ')');
-
 
701
        }
749
        }
702
 
750
        // make it a local alias
703
        // make it a local alias
751
        if (!$chan->setAlias(strtolower($params[1]), true)) {
704
        if (!$chan->setAlias(strtolower($params[1]), true)) {
752
            return $this->raiseError('Alias "' . strtolower($params[1]) .
705
            return $this->raiseError('Alias "' . strtolower($params[1]) .
753
                '" is not a valid channel alias');
706
                '" is not a valid channel alias');
-
 
707
        }
754
        }
708
 
755
        $reg->updateChannel($chan);
709
        $reg->updateChannel($chan);
756
        $this->ui->outputData('Channel "' . $chan->getName() . '" aliased successfully to "' .
710
        $this->ui->outputData('Channel "' . $chan->getName() . '" aliased successfully to "' .
757
            strtolower($params[1]) . '"');
711
            strtolower($params[1]) . '"');
Line -... Line 712...
-
 
712
    }
-
 
713
 
-
 
714
    /**
-
 
715
     * The channel-discover command
-
 
716
     *
-
 
717
     * @param string $command command name
-
 
718
     * @param array  $options option_name => value
-
 
719
     * @param array  $params  list of additional parameters.
-
 
720
     *               $params[0] should contain a string with either:
-
 
721
     *               - <channel name> or
-
 
722
     *               - <username>:<password>@<channel name>
758
    }
723
     * @return null|PEAR_Error
759
 
724
     */
760
    function doDiscover($command, $options, $params)
-
 
761
    {
725
    function doDiscover($command, $options, $params)
762
        $reg = &$this->config->getRegistry();
726
    {
763
        if (sizeof($params) != 1) {
727
        if (count($params) !== 1) {
-
 
728
            return $this->raiseError("No channel server specified");
-
 
729
        }
764
            return $this->raiseError("No channel server specified");
730
 
765
        }
731
        // Look for the possible input format "<username>:<password>@<channel>"
766
        if ($reg->channelExists($params[0])) {
732
        if (preg_match('/^(.+):(.+)@(.+)\\z/', $params[0], $matches)) {
767
            if ($reg->isAlias($params[0])) {
733
            $username = $matches[1];
-
 
734
            $password = $matches[2];
768
                return $this->raiseError("A channel alias named \"$params[0]\" " .
735
            $channel  = $matches[3];
769
                    'already exists, aliasing channel "' . $reg->channelName($params[0])
736
        } else {
-
 
737
            $channel = $params[0];
-
 
738
        }
-
 
739
 
-
 
740
        $reg = &$this->config->getRegistry();
770
                    . '"');
741
        if ($reg->channelExists($channel)) {
771
            } else {
742
            if (!$reg->isAlias($channel)) {
-
 
743
                return $this->raiseError("Channel \"$channel\" is already initialized", PEAR_COMMAND_CHANNELS_CHANNEL_EXISTS);
-
 
744
            }
-
 
745
 
-
 
746
            return $this->raiseError("A channel alias named \"$channel\" " .
772
                return $this->raiseError("Channel \"$params[0]\" is already initialized");
747
                'already exists, aliasing channel "' . $reg->channelName($channel)
-
 
748
                . '"');
773
            }
749
        }
774
        }
750
 
775
        $this->pushErrorHandling(PEAR_ERROR_RETURN);
751
        $this->pushErrorHandling(PEAR_ERROR_RETURN);
776
        $err = $this->doAdd($command, $options, array('http://' . $params[0] . '/channel.xml'));
752
        $err = $this->doAdd($command, $options, array('http://' . $channel . '/channel.xml'));
-
 
753
        $this->popErrorHandling();
777
        $this->popErrorHandling();
754
        if (PEAR::isError($err)) {
-
 
755
            if ($err->getCode() === PEAR_COMMAND_CHANNELS_CHANNEL_EXISTS) {
-
 
756
                return $this->raiseError("Discovery of channel \"$channel\" failed (" .
-
 
757
                    $err->getMessage() . ')');
-
 
758
            }
-
 
759
            // Attempt fetch via https
-
 
760
            $this->ui->outputData("Discovering channel $channel over http:// failed with message: " . $err->getMessage());
-
 
761
            $this->ui->outputData("Trying to discover channel $channel over https:// instead");
-
 
762
            $this->pushErrorHandling(PEAR_ERROR_RETURN);
-
 
763
            $err = $this->doAdd($command, $options, array('https://' . $channel . '/channel.xml'));
-
 
764
            $this->popErrorHandling();
778
        if (PEAR::isError($err)) {
765
            if (PEAR::isError($err)) {
-
 
766
                return $this->raiseError("Discovery of channel \"$channel\" failed (" .
779
            return $this->raiseError("Discovery of channel \"$params[0]\" failed (" .
767
                    $err->getMessage() . ')');
-
 
768
            }
-
 
769
        }
-
 
770
 
-
 
771
        // Store username/password if they were given
-
 
772
        // Arguably we should do a logintest on the channel here, but since
-
 
773
        // that's awkward on a REST-based channel (even "pear login" doesn't
-
 
774
        // do it for those), and XML-RPC is deprecated, it's fairly pointless.
-
 
775
        if (isset($username)) {
-
 
776
            $this->config->set('username', $username, 'user', $channel);
-
 
777
            $this->config->set('password', $password, 'user', $channel);
-
 
778
            $this->config->store();
-
 
779
            $this->ui->outputData("Stored login for channel \"$channel\" using username \"$username\"", $command);
780
                $err->getMessage() . ')');
780
        }
-
 
781
 
-
 
782
        $this->ui->outputData("Discovery of channel \"$channel\" succeeded", $command);
-
 
783
    }
-
 
784
 
-
 
785
    /**
-
 
786
     * Execute the 'login' command.
-
 
787
     *
-
 
788
     * @param string $command command name
-
 
789
     * @param array $options option_name => value
-
 
790
     * @param array $params list of additional parameters
-
 
791
     *
-
 
792
     * @return bool TRUE on success or
-
 
793
     * a PEAR error on failure
-
 
794
     *
-
 
795
     * @access public
-
 
796
     */
-
 
797
    function doLogin($command, $options, $params)
-
 
798
    {
-
 
799
        $reg = &$this->config->getRegistry();
-
 
800
 
-
 
801
        // If a parameter is supplied, use that as the channel to log in to
-
 
802
        $channel = isset($params[0]) ? $params[0] : $this->config->get('default_channel');
-
 
803
 
-
 
804
        $chan = $reg->getChannel($channel);
-
 
805
        if (PEAR::isError($chan)) {
-
 
806
            return $this->raiseError($chan);
-
 
807
        }
-
 
808
 
-
 
809
        $server   = $this->config->get('preferred_mirror', null, $channel);
-
 
810
        $username = $this->config->get('username',         null, $channel);
-
 
811
        if (empty($username)) {
-
 
812
            $username = isset($_ENV['USER']) ? $_ENV['USER'] : null;
-
 
813
        }
-
 
814
        $this->ui->outputData("Logging in to $server.", $command);
-
 
815
 
-
 
816
        list($username, $password) = $this->ui->userDialog(
-
 
817
            $command,
-
 
818
            array('Username', 'Password'),
-
 
819
            array('text',     'password'),
-
 
820
            array($username,  '')
-
 
821
            );
-
 
822
        $username = trim($username);
-
 
823
        $password = trim($password);
-
 
824
 
-
 
825
        $ourfile = $this->config->getConfFile('user');
-
 
826
        if (!$ourfile) {
-
 
827
            $ourfile = $this->config->getConfFile('system');
-
 
828
        }
-
 
829
 
-
 
830
        $this->config->set('username', $username, 'user', $channel);
-
 
831
        $this->config->set('password', $password, 'user', $channel);
-
 
832
 
-
 
833
        if ($chan->supportsREST()) {
-
 
834
            $ok = true;
-
 
835
        }
-
 
836
 
-
 
837
        if ($ok !== true) {
-
 
838
            return $this->raiseError('Login failed!');
-
 
839
        }
-
 
840
 
-
 
841
        $this->ui->outputData("Logged in.", $command);
-
 
842
        // avoid changing any temporary settings changed with -d
-
 
843
        $ourconfig = new PEAR_Config($ourfile, $ourfile);
-
 
844
        $ourconfig->set('username', $username, 'user', $channel);
-
 
845
        $ourconfig->set('password', $password, 'user', $channel);
-
 
846
        $ourconfig->store();
-
 
847
 
-
 
848
        return true;
-
 
849
    }
-
 
850
 
-
 
851
    /**
-
 
852
     * Execute the 'logout' command.
-
 
853
     *
-
 
854
     * @param string $command command name
-
 
855
     * @param array $options option_name => value
-
 
856
     * @param array $params list of additional parameters
-
 
857
     *
-
 
858
     * @return bool TRUE on success or
-
 
859
     * a PEAR error on failure
-
 
860
     *
-
 
861
     * @access public
-
 
862
     */
-
 
863
    function doLogout($command, $options, $params)
-
 
864
    {
-
 
865
        $reg     = &$this->config->getRegistry();
-
 
866
 
-
 
867
        // If a parameter is supplied, use that as the channel to log in to
-
 
868
        $channel = isset($params[0]) ? $params[0] : $this->config->get('default_channel');
-
 
869
 
-
 
870
        $chan    = $reg->getChannel($channel);
-
 
871
        if (PEAR::isError($chan)) {
-
 
872
            return $this->raiseError($chan);
-
 
873
        }
-
 
874
 
-
 
875
        $server = $this->config->get('preferred_mirror', null, $channel);
-
 
876
        $this->ui->outputData("Logging out from $server.", $command);
-
 
877
        $this->config->remove('username', 'user', $channel);
-
 
878
        $this->config->remove('password', 'user', $channel);
781
        }
879
        $this->config->store();
782
        $this->ui->outputData("Discovery of channel \"$params[0]\" succeeded", $command);
880
        return true;
783
    }
-