2002-03-18 17:39:52 +00:00
|
|
|
<?php
|
|
|
|
//
|
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
// | PHP Version 4 |
|
|
|
|
// +----------------------------------------------------------------------+
|
2002-12-31 16:18:29 +00:00
|
|
|
// | Copyright (c) 1997-2003 The PHP Group |
|
2002-03-18 17:39:52 +00:00
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
// | This source file is subject to version 2.02 of the PHP license, |
|
|
|
|
// | that is bundled with this package in the file LICENSE, and is |
|
|
|
|
// | available at through the world-wide-web at |
|
|
|
|
// | http://www.php.net/license/2_02.txt. |
|
|
|
|
// | If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
// | obtain it through the world-wide-web, please send a note to |
|
|
|
|
// | license@php.net so we can mail you a copy immediately. |
|
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
// | Author: Stig Bakken <ssb@fast.no> |
|
|
|
|
// +----------------------------------------------------------------------+
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
require_once "PEAR/Command/Common.php";
|
|
|
|
require_once "PEAR/Remote.php";
|
|
|
|
require_once "PEAR/Config.php";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PEAR commands for managing configuration data.
|
|
|
|
*
|
|
|
|
*/
|
2002-03-22 11:09:58 +00:00
|
|
|
class PEAR_Command_Auth extends PEAR_Command_Common
|
2002-03-18 17:39:52 +00:00
|
|
|
{
|
2002-11-26 21:49:55 +00:00
|
|
|
// {{{ properties
|
|
|
|
|
2002-05-14 01:49:56 +00:00
|
|
|
var $commands = array(
|
|
|
|
'login' => array(
|
|
|
|
'summary' => 'Connects and authenticates to remote server',
|
2002-05-21 01:27:53 +00:00
|
|
|
'shortcut' => 'li',
|
2002-05-14 01:49:56 +00:00
|
|
|
'function' => 'doLogin',
|
|
|
|
'options' => array(),
|
2002-05-21 01:27:53 +00:00
|
|
|
'doc' => '
|
|
|
|
Log in to the remote server. To use remote functions in the installer
|
|
|
|
that require any kind of privileges, you need to log in first. The
|
|
|
|
username and password you enter here will be stored in your per-user
|
|
|
|
PEAR configuration (~/.pearrc on Unix-like systems). After logging
|
|
|
|
in, your username and password will be sent along in subsequent
|
|
|
|
operations on the remote server.',
|
2002-05-14 01:49:56 +00:00
|
|
|
),
|
|
|
|
'logout' => array(
|
|
|
|
'summary' => 'Logs out from the remote server',
|
2002-05-21 01:27:53 +00:00
|
|
|
'shortcut' => 'lo',
|
2002-05-14 01:49:56 +00:00
|
|
|
'function' => 'doLogout',
|
|
|
|
'options' => array(),
|
2002-05-21 01:27:53 +00:00
|
|
|
'doc' => '
|
|
|
|
Logs out from the remote server. This command does not actually
|
|
|
|
connect to the remote server, it only deletes the stored username and
|
|
|
|
password from your user configuration.',
|
2002-05-14 01:49:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
2002-11-26 21:49:55 +00:00
|
|
|
// }}}
|
|
|
|
|
|
|
|
// {{{ constructor
|
|
|
|
|
2002-03-18 17:39:52 +00:00
|
|
|
/**
|
2002-03-22 11:09:58 +00:00
|
|
|
* PEAR_Command_Auth constructor.
|
2002-03-18 17:39:52 +00:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2002-03-22 11:09:58 +00:00
|
|
|
function PEAR_Command_Auth(&$ui, &$config)
|
2002-03-18 17:39:52 +00:00
|
|
|
{
|
2002-03-22 09:22:28 +00:00
|
|
|
parent::PEAR_Command_Common($ui, $config);
|
2002-03-18 17:39:52 +00:00
|
|
|
}
|
|
|
|
|
2002-11-26 21:49:55 +00:00
|
|
|
// }}}
|
|
|
|
|
|
|
|
// {{{ doLogin()
|
|
|
|
|
2002-03-18 17:39:52 +00:00
|
|
|
/**
|
2002-05-14 12:34:49 +00:00
|
|
|
* Execute the 'login' command.
|
2002-05-14 01:49:56 +00:00
|
|
|
*
|
|
|
|
* @param string $command command name
|
|
|
|
*
|
|
|
|
* @param array $options option_name => value
|
|
|
|
*
|
|
|
|
* @param array $params list of additional parameters
|
|
|
|
*
|
|
|
|
* @return bool TRUE on success, FALSE for unknown commands, or
|
|
|
|
* a PEAR error on failure
|
|
|
|
*
|
2002-03-18 17:39:52 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2002-05-14 01:49:56 +00:00
|
|
|
function doLogin($command, $options, $params)
|
2002-03-18 17:39:52 +00:00
|
|
|
{
|
2002-05-14 01:49:56 +00:00
|
|
|
$server = $this->config->get('master_server');
|
|
|
|
$remote = new PEAR_Remote($this->config);
|
|
|
|
$username = $this->config->get('username');
|
|
|
|
if (empty($username)) {
|
|
|
|
$username = @$_ENV['USER'];
|
|
|
|
}
|
2002-06-02 13:07:19 +00:00
|
|
|
$this->ui->outputData("Logging in to $server.", $command);
|
|
|
|
|
|
|
|
list($username, $password) = $this->ui->userDialog(
|
|
|
|
$command,
|
|
|
|
array('Username', 'Password'),
|
|
|
|
array('text', 'password'),
|
|
|
|
array($username, '')
|
|
|
|
);
|
|
|
|
$username = trim($username);
|
|
|
|
$password = trim($password);
|
|
|
|
|
2002-05-14 01:49:56 +00:00
|
|
|
$this->config->set('username', $username);
|
|
|
|
$this->config->set('password', $password);
|
2002-06-02 13:07:19 +00:00
|
|
|
|
2002-05-14 01:49:56 +00:00
|
|
|
$remote->expectError(401);
|
|
|
|
$ok = $remote->call('logintest');
|
|
|
|
$remote->popExpect();
|
|
|
|
if ($ok === true) {
|
2002-06-02 13:07:19 +00:00
|
|
|
$this->ui->outputData("Logged in.", $command);
|
2002-05-14 01:49:56 +00:00
|
|
|
$this->config->store();
|
|
|
|
} else {
|
2002-06-02 13:07:19 +00:00
|
|
|
return $this->raiseError("Login failed!");
|
2002-04-01 15:23:46 +00:00
|
|
|
}
|
2002-05-14 01:49:56 +00:00
|
|
|
|
2002-04-01 15:23:46 +00:00
|
|
|
}
|
2002-03-18 17:39:52 +00:00
|
|
|
|
2002-11-26 21:49:55 +00:00
|
|
|
// }}}
|
|
|
|
// {{{ doLogout()
|
|
|
|
|
2002-03-19 19:31:02 +00:00
|
|
|
/**
|
2002-05-14 01:49:56 +00:00
|
|
|
* Execute the 'logout' command.
|
2002-03-19 19:31:02 +00:00
|
|
|
*
|
2002-05-14 01:49:56 +00:00
|
|
|
* @param string $command command name
|
2002-03-19 19:31:02 +00:00
|
|
|
*
|
2002-05-14 01:49:56 +00:00
|
|
|
* @param array $options option_name => value
|
2002-03-19 19:31:02 +00:00
|
|
|
*
|
2002-05-14 01:49:56 +00:00
|
|
|
* @param array $params list of additional parameters
|
2002-03-19 19:31:02 +00:00
|
|
|
*
|
2002-03-22 09:22:28 +00:00
|
|
|
* @return bool TRUE on success, FALSE for unknown commands, or
|
|
|
|
* a PEAR error on failure
|
2002-03-19 19:31:02 +00:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2002-05-14 01:49:56 +00:00
|
|
|
function doLogout($command, $options, $params)
|
2002-03-18 17:39:52 +00:00
|
|
|
{
|
2002-03-31 01:51:08 +00:00
|
|
|
$server = $this->config->get('master_server');
|
2002-06-02 13:07:19 +00:00
|
|
|
$this->ui->outputData("Logging out from $server.", $command);
|
2002-05-14 01:49:56 +00:00
|
|
|
$this->config->remove('username');
|
|
|
|
$this->config->remove('password');
|
|
|
|
$this->config->store();
|
2002-03-18 17:39:52 +00:00
|
|
|
}
|
|
|
|
|
2002-11-26 21:49:55 +00:00
|
|
|
// }}}
|
2002-03-18 17:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|