Permalink
Browse files

Shift PEAR_RemoteInstaller to seperate package

  • Loading branch information...
1 parent d74b149 commit 48e9a4d52e400c42a725c7c25acf7917e2e07750 @CloCkWeRX CloCkWeRX committed Apr 13, 2012
Showing with 0 additions and 1,246 deletions.
  1. +0 −360 PEAR/Command/Remoteinstall.php
  2. +0 −238 PEAR/Command/Remoteinstall.xml
  3. +0 −260 PEAR/FTP.php
  4. +0 −233 PEAR/RemoteInstaller.php
  5. +0 −155 package-RemoteInstall.xml
View
360 PEAR/Command/Remoteinstall.php
@@ -1,360 +0,0 @@
-<?php
-/**
- * PEAR_Command_Install (remote-install, remote-upgrade, remote-upgrade-all, remote-uninstall commands)
- *
- * PHP versions 4 and 5
- *
- * @category pear
- * @package PEAR
- * @author Stig Bakken <ssb@php.net>
- * @author Greg Beaver <cellog@php.net>
- * @copyright 1997-2009 The Authors
- * @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id$
- * @link http://pear.php.net/package/PEAR
- * @since File available since Release 0.1
- */
-
-/**
- * base class
- */
-require_once 'PEAR/Command/Install.php';
-
-define('PEAR_REMOTEINSTALL_OK', 1);
-/**
- * PEAR commands for installation or deinstallation/upgrading of
- * packages.
- *
- * @category pear
- * @package PEAR
- * @author Stig Bakken <ssb@php.net>
- * @author Greg Beaver <cellog@php.net>
- * @copyright 1997-2009 The Authors
- * @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: @package_version@
- * @link http://pear.php.net/package/PEAR
- * @since Class available since Release 0.1
- */
-class PEAR_Command_RemoteInstall extends PEAR_Command_Install
-{
- var $commands = array(
- 'remote-install' => array(
- 'summary' => 'Install Package',
- 'function' => 'doInstall',
- 'shortcut' => 'inr',
- 'options' => array(
- 'force' => array(
- 'shortopt' => 'f',
- 'doc' => 'will overwrite newer installed packages',
- ),
- 'nodeps' => array(
- 'shortopt' => 'n',
- 'doc' => 'ignore dependencies, install anyway',
- ),
- 'register-only' => array(
- 'shortopt' => 'r',
- 'doc' => 'do not install files, only register the package as installed',
- ),
- 'soft' => array(
- 'shortopt' => 's',
- 'doc' => 'soft install, fail silently, or upgrade if already installed',
- ),
- 'nobuild' => array(
- 'shortopt' => 'B',
- 'doc' => 'don\'t build C extensions',
- ),
- 'nocompress' => array(
- 'shortopt' => 'Z',
- 'doc' => 'request uncompressed files when downloading',
- ),
- 'installroot' => array(
- 'shortopt' => 'R',
- 'arg' => 'DIR',
- 'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
- ),
- 'ignore-errors' => array(
- 'doc' => 'force install even if there were errors',
- ),
- 'alldeps' => array(
- 'shortopt' => 'a',
- 'doc' => 'install all required and optional dependencies',
- ),
- 'onlyreqdeps' => array(
- 'shortopt' => 'o',
- 'doc' => 'install all required dependencies',
- ),
- 'remoteconfig' => array(
- 'shortopt' => 'F',
- 'arg' => 'URL',
- 'doc' => 'also install to ftp site using remote config file (ftp://host.com/pear.conf)'
- ),
- 'offline' => array(
- 'shortopt' => 'O',
- 'doc' => 'do not attempt to download any urls or contact channels',
- ),
- 'pretend' => array(
- 'shortopt' => 'p',
- 'doc' => 'Only list the packages that would be downloaded',
- ),
- ),
- 'doc' => '[channel/]<package> ...
-Installs one or more PEAR packages. You can specify a package to
-install in four ways:
-
-"Package-1.0.tgz" : installs from a local file
-
-"http://example.com/Package-1.0.tgz" : installs from
-anywhere on the net.
-
-"package.xml" : installs the package described in
-package.xml. Useful for testing, or for wrapping a PEAR package in
-another package manager such as RPM.
-
-"Package[-version/state][.tar]" : queries your default channel\'s server
-({config master_server}) and downloads the newest package with
-the preferred quality/state ({config preferred_state}).
-
-To retrieve Package version 1.1, use "Package-1.1," to retrieve
-Package state beta, use "Package-beta." To retrieve an uncompressed
-file, append .tar (make sure there is no file by the same name first)
-
-To download a package from another channel, prefix with the channel name like
-"channel/Package"
-
-More than one package may be specified at once. It is ok to mix these
-four ways of specifying packages.
-'),
- 'remote-upgrade' => array(
- 'summary' => 'Upgrade Package',
- 'function' => 'doInstall',
- 'shortcut' => 'upr',
- 'options' => array(
- 'force' => array(
- 'shortopt' => 'f',
- 'doc' => 'overwrite newer installed packages',
- ),
- 'nodeps' => array(
- 'shortopt' => 'n',
- 'doc' => 'ignore dependencies, upgrade anyway',
- ),
- 'register-only' => array(
- 'shortopt' => 'r',
- 'doc' => 'do not install files, only register the package as upgraded',
- ),
- 'nobuild' => array(
- 'shortopt' => 'B',
- 'doc' => 'don\'t build C extensions',
- ),
- 'nocompress' => array(
- 'shortopt' => 'Z',
- 'doc' => 'request uncompressed files when downloading',
- ),
- 'installroot' => array(
- 'shortopt' => 'R',
- 'arg' => 'DIR',
- 'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
- ),
- 'ignore-errors' => array(
- 'doc' => 'force install even if there were errors',
- ),
- 'alldeps' => array(
- 'shortopt' => 'a',
- 'doc' => 'install all required and optional dependencies',
- ),
- 'onlyreqdeps' => array(
- 'shortopt' => 'o',
- 'doc' => 'install all required dependencies',
- ),
- 'remoteconfig' => array(
- 'shortopt' => 'F',
- 'arg' => 'URL',
- 'doc' => 'also upgrade on ftp site using remote config file (ftp://host.com/pear.conf)'
- ),
- 'offline' => array(
- 'shortopt' => 'O',
- 'doc' => 'do not attempt to download any urls or contact channels',
- ),
- 'pretend' => array(
- 'shortopt' => 'p',
- 'doc' => 'Only list the packages that would be downloaded',
- ),
- ),
- 'doc' => '<package> ...
-Upgrades one or more PEAR packages. See documentation for the
-"install" command for ways to specify a package.
-
-When upgrading, your package will be updated if the provided new
-package has a higher version number (use the -f option if you need to
-upgrade anyway).
-
-More than one package may be specified at once.
-'),
- 'remote-upgrade-all' => array(
- 'summary' => 'Upgrade All Packages',
- 'function' => 'doInstall',
- 'shortcut' => 'uar',
- 'options' => array(
- 'nodeps' => array(
- 'shortopt' => 'n',
- 'doc' => 'ignore dependencies, upgrade anyway',
- ),
- 'register-only' => array(
- 'shortopt' => 'r',
- 'doc' => 'do not install files, only register the package as upgraded',
- ),
- 'nobuild' => array(
- 'shortopt' => 'B',
- 'doc' => 'don\'t build C extensions',
- ),
- 'nocompress' => array(
- 'shortopt' => 'Z',
- 'doc' => 'request uncompressed files when downloading',
- ),
- 'installroot' => array(
- 'shortopt' => 'R',
- 'arg' => 'DIR',
- 'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
- ),
- 'ignore-errors' => array(
- 'doc' => 'force install even if there were errors',
- ),
- 'remoteconfig' => array(
- 'shortopt' => 'F',
- 'arg' => 'URL',
- 'doc' => 'also upgrade on ftp site using remote config file (ftp://host.com/pear.conf)'
- ),
- ),
- 'doc' => '
-Upgrades all packages that have a newer release available. Upgrades are
-done only if there is a release available of the state specified in
-"preferred_state" (currently {config preferred_state}), or a state considered
-more stable.
-'),
- 'remote-uninstall' => array(
- 'summary' => 'Un-install Package',
- 'function' => 'doUninstall',
- 'shortcut' => 'unr',
- 'options' => array(
- 'nodeps' => array(
- 'shortopt' => 'n',
- 'doc' => 'ignore dependencies, uninstall anyway',
- ),
- 'register-only' => array(
- 'shortopt' => 'r',
- 'doc' => 'do not remove files, only register the packages as not installed',
- ),
- 'installroot' => array(
- 'shortopt' => 'R',
- 'arg' => 'DIR',
- 'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
- ),
- 'ignore-errors' => array(
- 'doc' => 'force install even if there were errors',
- ),
- 'remoteconfig' => array(
- 'shortopt' => 'F',
- 'arg' => 'URL',
- 'doc' => 'also uninstall on ftp site using remote config file (ftp://host.com/pear.conf)'
- ),
- 'offline' => array(
- 'shortopt' => 'O',
- 'doc' => 'do not attempt to uninstall remotely',
- ),
- ),
- 'doc' => '[channel/]<package> ...
-Uninstalls one or more PEAR packages. More than one package may be
-specified at once. Prefix with channel name to uninstall from a
-channel not in your default channel ({config default_channel})
-'),
- );
-
- /**
- * PEAR_Command_Install constructor.
- *
- * @access public
- */
- function PEAR_Command_Remoteinstall(&$ui, &$config)
- {
- parent::PEAR_Command_Install($ui, $config);
- }
-
- /**
- * For unit testing purposes
- */
- function &getDownloader(&$ui, $options, &$config)
- {
- if (!class_exists('PEAR_Downloader')) {
- require_once 'PEAR/Downloader.php';
- }
- $a = &new PEAR_Downloader($ui, $options, $config);
- return $a;
- }
-
- /**
- * For unit testing purposes
- */
- function &getInstaller(&$ui)
- {
- if (!class_exists('PEAR_RemoteInstaller')) {
- require_once 'PEAR/RemoteInstaller.php';
- }
- $a = &new PEAR_RemoteInstaller($ui);
- return $a;
- }
-
- function doInstall($command, $options, $params)
- {
- if (empty($this->installer)) {
- $this->installer = &$this->getInstaller($this->ui);
- }
-
- if (isset($options['remoteconfig'])) {
- $e = $this->config->readFTPConfigFile($options['remoteconfig']);
- if (!PEAR::isError($e)) {
- $this->installer->setConfig($this->config);
- }
- } elseif (!$this->config->get('remote_config')) {
- return $this->raiseError('Error: ' . $command . ' expects either option ' .
- '"remoteconfig" be set, or remote_config configuration variable be used');
- } else {
- $e = $this->config->readFTPConfigFile($this->config->get('remote_config'));
- if (!PEAR::isError($e)) {
- $this->installer->setConfig($this->config);
- }
- }
-
- $command = str_replace('remote-', '', $command); // fool parent
- return parent::doInstall($command, $options, $params);
- }
-
- function doUninstall($command, $options, $params)
- {
- if (empty($this->installer)) {
- $this->installer = &$this->getInstaller($this->ui);
- }
-
- if (isset($options['remoteconfig'])) {
- $e = $this->config->readFTPConfigFile($options['remoteconfig']);
- if (!PEAR::isError($e)) {
- $this->installer->setConfig($this->config);
- }
- } elseif (!$this->config->get('remote_config')) {
- return $this->raiseError('Error: ' . $command . ' expects either option ' .
- '"remoteconfig" be set, or remote_config configuration variable be used');
- } else {
- $e = $this->config->readFTPConfigFile($this->config->get('remote_config'));
- if (!PEAR::isError($e)) {
- $this->installer->setConfig($this->config);
- }
- }
-
- $command = 'uninstall'; // fool parent
- return parent::doUninstall($command, $options, $params);
- }
-}
-
-/**
- * This is a hack for PEAR 1.4.x to work
- * @ignore
- */
-class Net_FTP {}
View
238 PEAR/Command/Remoteinstall.xml
@@ -1,238 +0,0 @@
-<commands version="1.0">
- <remote-install>
- <summary>Install Package</summary>
- <function>doInstall</function>
- <shortcut>inr</shortcut>
- <options>
- <force>
- <shortopt>f</shortopt>
- <doc>will overwrite newer installed packages</doc>
- </force>
- <nodeps>
- <shortopt>n</shortopt>
- <doc>ignore dependencies, install anyway</doc>
- </nodeps>
- <register-only>
- <shortopt>r</shortopt>
- <doc>do not install files, only register the package as installed</doc>
- </register-only>
- <soft>
- <shortopt>s</shortopt>
- <doc>soft install, fail silently, or upgrade if already installed</doc>
- </soft>
- <nobuild>
- <shortopt>B</shortopt>
- <doc>don&#039;t build C extensions</doc>
- </nobuild>
- <nocompress>
- <shortopt>Z</shortopt>
- <doc>request uncompressed files when downloading</doc>
- </nocompress>
- <installroot>
- <shortopt>R</shortopt>
- <doc>root directory used when installing files (ala PHP&#039;s INSTALL_ROOT)</doc>
- <arg>DIR</arg>
- </installroot>
- <ignore-errors>
- <shortopt></shortopt>
- <doc>force install even if there were errors</doc>
- </ignore-errors>
- <alldeps>
- <shortopt>a</shortopt>
- <doc>install all required and optional dependencies</doc>
- </alldeps>
- <onlyreqdeps>
- <shortopt>o</shortopt>
- <doc>install all required dependencies</doc>
- </onlyreqdeps>
- <remoteconfig>
- <shortopt>F</shortopt>
- <doc>also install to ftp site using remote config file (ftp://host.com/pear.conf)</doc>
- <arg>URL</arg>
- </remoteconfig>
- <offline>
- <shortopt>O</shortopt>
- <doc>do not attempt to download any urls or contact channels</doc>
- </offline>
- <pretend>
- <shortopt>p</shortopt>
- <doc>Only list the packages that would be downloaded</doc>
- </pretend>
- </options>
- <doc>[channel/]&lt;package&gt; ...
-Installs one or more PEAR packages. You can specify a package to
-install in four ways:
-
-&quot;Package-1.0.tgz&quot; : installs from a local file
-
-&quot;http://example.com/Package-1.0.tgz&quot; : installs from
-anywhere on the net.
-
-&quot;package.xml&quot; : installs the package described in
-package.xml. Useful for testing, or for wrapping a PEAR package in
-another package manager such as RPM.
-
-&quot;Package[-version/state][.tar]&quot; : queries your default channel&#039;s server
-({config master_server}) and downloads the newest package with
-the preferred quality/state ({config preferred_state}).
-
-To retrieve Package version 1.1, use &quot;Package-1.1,&quot; to retrieve
-Package state beta, use &quot;Package-beta.&quot; To retrieve an uncompressed
-file, append .tar (make sure there is no file by the same name first)
-
-To download a package from another channel, prefix with the channel name like
-&quot;channel/Package&quot;
-
-More than one package may be specified at once. It is ok to mix these
-four ways of specifying packages.
-</doc>
- </remote-install>
- <remote-upgrade>
- <summary>Upgrade Package</summary>
- <function>doInstall</function>
- <shortcut>upr</shortcut>
- <options>
- <force>
- <shortopt>f</shortopt>
- <doc>overwrite newer installed packages</doc>
- </force>
- <nodeps>
- <shortopt>n</shortopt>
- <doc>ignore dependencies, upgrade anyway</doc>
- </nodeps>
- <register-only>
- <shortopt>r</shortopt>
- <doc>do not install files, only register the package as upgraded</doc>
- </register-only>
- <nobuild>
- <shortopt>B</shortopt>
- <doc>don&#039;t build C extensions</doc>
- </nobuild>
- <nocompress>
- <shortopt>Z</shortopt>
- <doc>request uncompressed files when downloading</doc>
- </nocompress>
- <installroot>
- <shortopt>R</shortopt>
- <doc>root directory used when installing files (ala PHP&#039;s INSTALL_ROOT)</doc>
- <arg>DIR</arg>
- </installroot>
- <ignore-errors>
- <shortopt></shortopt>
- <doc>force install even if there were errors</doc>
- </ignore-errors>
- <alldeps>
- <shortopt>a</shortopt>
- <doc>install all required and optional dependencies</doc>
- </alldeps>
- <onlyreqdeps>
- <shortopt>o</shortopt>
- <doc>install all required dependencies</doc>
- </onlyreqdeps>
- <remoteconfig>
- <shortopt>F</shortopt>
- <doc>also upgrade on ftp site using remote config file (ftp://host.com/pear.conf)</doc>
- <arg>URL</arg>
- </remoteconfig>
- <offline>
- <shortopt>O</shortopt>
- <doc>do not attempt to download any urls or contact channels</doc>
- </offline>
- <pretend>
- <shortopt>p</shortopt>
- <doc>Only list the packages that would be downloaded</doc>
- </pretend>
- </options>
- <doc>&lt;package&gt; ...
-Upgrades one or more PEAR packages. See documentation for the
-&quot;install&quot; command for ways to specify a package.
-
-When upgrading, your package will be updated if the provided new
-package has a higher version number (use the -f option if you need to
-upgrade anyway).
-
-More than one package may be specified at once.
-</doc>
- </remote-upgrade>
- <remote-upgrade-all>
- <summary>Upgrade All Packages</summary>
- <function>doInstall</function>
- <shortcut>uar</shortcut>
- <options>
- <nodeps>
- <shortopt>n</shortopt>
- <doc>ignore dependencies, upgrade anyway</doc>
- </nodeps>
- <register-only>
- <shortopt>r</shortopt>
- <doc>do not install files, only register the package as upgraded</doc>
- </register-only>
- <nobuild>
- <shortopt>B</shortopt>
- <doc>don&#039;t build C extensions</doc>
- </nobuild>
- <nocompress>
- <shortopt>Z</shortopt>
- <doc>request uncompressed files when downloading</doc>
- </nocompress>
- <installroot>
- <shortopt>R</shortopt>
- <doc>root directory used when installing files (ala PHP&#039;s INSTALL_ROOT)</doc>
- <arg>DIR</arg>
- </installroot>
- <ignore-errors>
- <shortopt></shortopt>
- <doc>force install even if there were errors</doc>
- </ignore-errors>
- <remoteconfig>
- <shortopt>F</shortopt>
- <doc>also upgrade on ftp site using remote config file (ftp://host.com/pear.conf)</doc>
- <arg>URL</arg>
- </remoteconfig>
- </options>
- <doc>
-Upgrades all packages that have a newer release available. Upgrades are
-done only if there is a release available of the state specified in
-&quot;preferred_state&quot; (currently {config preferred_state}), or a state considered
-more stable.
-</doc>
- </remote-upgrade-all>
- <remote-uninstall>
- <summary>Un-install Package</summary>
- <function>doUninstall</function>
- <shortcut>unr</shortcut>
- <options>
- <nodeps>
- <shortopt>n</shortopt>
- <doc>ignore dependencies, uninstall anyway</doc>
- </nodeps>
- <register-only>
- <shortopt>r</shortopt>
- <doc>do not remove files, only register the packages as not installed</doc>
- </register-only>
- <installroot>
- <shortopt>R</shortopt>
- <doc>root directory used when installing files (ala PHP&#039;s INSTALL_ROOT)</doc>
- <arg>DIR</arg>
- </installroot>
- <ignore-errors>
- <shortopt></shortopt>
- <doc>force install even if there were errors</doc>
- </ignore-errors>
- <remoteconfig>
- <shortopt>F</shortopt>
- <doc>also uninstall on ftp site using remote config file (ftp://host.com/pear.conf)</doc>
- <arg>URL</arg>
- </remoteconfig>
- <offline>
- <shortopt>O</shortopt>
- <doc>do not attempt to uninstall remotely</doc>
- </offline>
- </options>
- <doc>[channel/]&lt;package&gt; ...
-Uninstalls one or more PEAR packages. More than one package may be
-specified at once. Prefix with channel name to uninstall from a
-channel not in your default channel ({config default_channel})
-</doc>
- </remote-uninstall>
-</commands>
View
260 PEAR/FTP.php
@@ -1,260 +0,0 @@
-<?php
-/**
- * PEAR_FTP
- *
- * PHP versions 4 and 5
- *
- * @category pear
- * @package PEAR
- * @author Greg Beaver <cellog@php.net>
- * @copyright 1997-2009 The Authors
- * @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id$
- * @link http://pear.php.net/package/PEAR
- * @since File available since Release 1.4.0a1
- */
-
-/**
- * FTP class used for PEAR's remote installation feature
- * @category pear
- * @package PEAR
- * @author Greg Beaver <cellog@php.net>
- * @copyright 1997-2009 The Authors
- * @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: @package_version@
- * @link http://pear.php.net/package/PEAR
- * @since Class available since Release 1.4.0a1
- */
-class PEAR_FTP extends PEAR
-{
- /**
- * @var array
- * @access private
- */
- protected $_parsed;
-
- /**
- * URI to prepend to all paths
- * @var string
- */
- protected $_uri;
-
- /**
- * Value to prepend to relative paths
- * @var string|null
- */
- protected $_pathprepend = null;
- /**
- * Resource needed for ssh2 action
- * @var resource
- */
- protected $_ssh2connection;
-
- /**
- * @param string full url to remote config file
- * @return true|PEAR_Error
- */
- public function init($url = null)
- {
- if ($url !== null) {
- $this->_parsed = @parse_url($url);
- } else {
- return;
- }
- if (!isset($this->_parsed['host'])) {
- return PEAR::raiseError('No FTP Host specified');
- }
- if (!isset($this->_parsed['scheme'])) {
- return PEAR::raiseError('No FTP Scheme (ftp/ftps/ssh2.sftp) specified');
- }
- if (!in_array($this->_parsed['scheme'], array('ftp', 'ftps', 'ssh2.sftp'), true)) {
- return PEAR::raiseError('Only ftp/ftps/ssh2.sftp is supported for remote config');
- }
- if (!in_array($this->_parsed['scheme'], stream_get_wrappers(), true)) {
- if ($this->_parsed['scheme'] == 'ftps' && !extension_loaded('openssl')) {
- if (OS_WINDOWS) {
- return PEAR::raiseError('In order to use ftps, you must ' .
- 'put "extension=php_openssl.dll" into php.ini and ' .
- 'copy libeay32.dll and ssleay32.dll to \windows\system32');
- } else {
- return PEAR::raiseError('In order to use ftps, you must ' .
- 'enable the "openssl" extension in php.ini');
- }
- }
- if ($this->_parsed['scheme'] == 'ssh2.sftp') {
- if (OS_WINDOWS) {
- return PEAR::raiseError('In order to use ssh2.sftp, you must ' .
- 'enable the "php_ssh2.dll" extension in php.ini');
- } else {
- return PEAR::raiseError('In order to use ssh2.sftp, you must ' .
- 'install ssh2 via "pecl install ssh2" and enable the "ssh2" ' .
- 'extension in php.ini');
- }
- }
- return PEAR::raiseError('Your PHP does not support this wrapper: ' .
- $this->_parsed['scheme']);
- }
- if (!isset($this->_parsed['path'])) {
- return PEAR::raiseError('No FTP file path to remote config specified');
- }
- $host = $this->_parsed['host'];
- $pass = isset($this->_parsed['pass']) ? ':' . $this->_parsed['pass'] : '';
- $user = isset($this->_parsed['user']) ? $this->_parsed['user'] . "$pass@" : '';
- $port = isset($this->_parsed['port']) ? ':' . $this->_parsed['port'] : '';
- $path = dirname($this->_parsed['path']);
- if ($path[strlen($path) - 1] == '/') {
- $path = substr($path, 0, strlen($path) - 1);
- }
- if ($this->_parsed['scheme'] == 'ssh2.sftp') {
- $connection = @ssh2_connect($host, isset($this->_parsed['port']) ?
- $this->_parsed['port'] : 22);
- if (!$connection) {
- return PEAR::raiseError('Unable to connect to remote host: ' .
- $php_errormsg);
- }
- $a = @ssh2_auth_password($connection, urldecode($this->_parsed['user']),
- urldecode($this->_parsed['pass']));
- if (!$a) {
- return PEAR::raiseError('Unable to authenticate to remote host: ' .
- $php_errormsg);
- }
-
- $sftp = @ssh2_sftp($connection);
- if (!$sftp) {
- return PEAR::raiseError('Unable to initiate sftp session: ' .
- $php_errormsg);
- }
- $this->_uri = $this->_parsed['scheme'] . '://' . $sftp;
- $this->_pathprepend = $path;
- $this->_ssh2connection = $sftp;
- } else {
- $this->_uri = $this->_parsed['scheme'] . '://' . $user . $host;
- $this->_pathprepend = $path;
- }
- return true;
- }
-
- /**
- * This works similar to the mkdir-command on your local machine. You can either give
- * it an absolute or relative path. The relative path will be completed with the actual
- * selected server-path. (see: pwd())
- *
- * @access public
- * @param string $dir relative dir-path
- * @param bool $recursive (optional) Create all needed directories
- * @return mixed True on success, otherwise PEAR::Error
- * @see NET_FTP_ERR_CREATEDIR_FAILED
- */
- public function mkdir($dir, $recursive = false)
- {
- if (method_exists($this, '_testftp_mkdir')) {
- $res = $this->_testftp_mkdir($this->_prepend($dir), 0755, $recursive);
- } else {
- $res = @mkdir($this->_prepend($dir), 0755, $recursive);
- }
- if (!$res) {
- return $this->raiseError("Creation of '$dir' failed");
- } else {
- return true;
- }
- }
-
- /**
- * @param string full path to local file
- * @param string full path to remote file
- */
- public function installFile($local, $remote)
- {
- $this->pushErrorHandling(PEAR_ERROR_RETURN);
- $this->mkdir(dirname($remote), true);
- $this->popErrorHandling();
- return $this->put($local, $remote, true);
- }
-
- /**
- * Retrieve a file from the remote server
- *
- * @param string $relfile relative path of the remote file
- * @param string $localfile full local path to save the file in
- */
- public function get($relfile, $localfile, $binary = true)
- {
- $local = @fopen($localfile, 'w' . ($binary ? 'b' : ''));
- $remote = @fopen($this->_prepend($relfile), 'r' . ($binary ? 'b' : ''));
- if (!$remote) {
- return PEAR::raiseError('Could not open remote file ' .
- $this->_prepend($relfile) . ' for retrieval');
- }
- if (!$local) {
- return PEAR::raiseError('Could not open local file ' .
- $this->_prepend($relfile) . ' for retrieving remote file ' .
- $this->_prepend($relfile));
- }
- $ret = @stream_copy_to_stream($remote, $local);
- if ($local) {
- @fclose($local);
- }
- if ($remote) {
- @fclose($remote);
- }
- return $ret ? $ret : PEAR::raiseError('FTP get of ' . $this->_prepend($relfile) .
- ' failed');
- }
-
- public function put($localfile, $remotefile, $overwrite = false, $binary = true)
- {
- // sometimes we get the wrong size for files, this might fix it
- clearstatcache();
- $local = @fopen($localfile, 'r' . ($binary ? 'b' : ''));
- if (!$local) {
- return PEAR::raiseError('Could not put local file ' . $localfile .
- 'opening the file failed');
- }
- $opts = array('ftp' => array('overwrite' => $overwrite));
- $context = stream_context_create($opts);
- $remote = @fopen($this->_prepend($remotefile), 'w' . ($binary ? 'b' : ''), false,
- $context);
- if (!$remote) {
- return PEAR::raiseError('Could not open remote file ' .
- $this->_prepend($remotefile) . ' for saving a copy of local file ' . $localfile);
- }
- $ret = @stream_copy_to_stream($local, $remote);
- if ($local) {
- @fclose($local);
- }
- if ($remote) {
- @fclose($remote);
- }
- return $ret ? $ret : PEAR::raiseError('FTP put of ' . $this->_prepend($remotefile) .
- ' failed');
- }
-
- public function disconnect()
- {
- // does nothing here
- }
-
- public function rm($path, $recursive = false)
- {
- if (@unlink($this->_prepend($path))) {
- return true;
- }
- return PEAR::raiseError('rm of ' . $this->_prepend($path) . ' failed');
- }
-
- /**
- * Return a ftp URI for usage with filesystem functions directly
- *
- * @param string $path relative path to the on the FTP server
- * @return string full path to the ftp server including ftp[s]://...
- */
- private function _prepend($path)
- {
- if ($path[0] == '/') {
- return $this->_uri . $path;
- } else {
- return $this->_uri . $this->_pathprepend . '/' . $path;
- }
- }
-}
-?>
View
233 PEAR/RemoteInstaller.php
@@ -1,233 +0,0 @@
-<?php
-/**
- * PEAR_Installer
- *
- * PHP versions 4 and 5
- *
- * @category pear
- * @package PEAR
- * @author Stig Bakken <ssb@php.net>
- * @author Tomas V.V. Cox <cox@idecnet.com>
- * @author Martin Jansen <mj@php.net>
- * @author Greg Beaver <cellog@php.net>
- * @copyright 2005-2009 The Authors
- * @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id$
- * @link http://pear.php.net/package/PEAR
- * @since File available since Release 0.1.0
- */
-
-/**
- * parent class
- */
-require_once 'PEAR/Installer.php';
-
-/**
- * Administration class used to install PEAR packages and maintain the
- * installed package database.
- *
- * @category pear
- * @package PEAR
- * @author Greg Beaver <cellog@php.net>
- * @copyright 2005-2009 The Authors
- * @license http://opensource.org/licenses/bsd-license.php New BSD License
- * @version Release: @package_version@
- * @link http://pear.php.net/package/PEAR
- * @since Class available since Release 0.1.0
- */
-class PEAR_RemoteInstaller extends PEAR_Installer
-{
-
- /**
- * Delete a package's installed files, does not remove empty directories.
- *
- * @param string package name
- * @param string channel name
- * @param bool if true, then files are backed up first
- * @return bool TRUE on success, or a PEAR error on failure
- * @access protected
- */
- function _deletePackageFiles($package, $channel = false, $backup = false)
- {
- if (!$channel) {
- $channel = 'pear.php.net';
- }
- if (!strlen($package)) {
- return $this->raiseError("No package to uninstall given");
- }
- if (strtolower($package) == 'pear' && $channel == 'pear.php.net') {
- // to avoid race conditions, include all possible needed files
- require_once 'PEAR/Task/Common.php';
- require_once 'PEAR/Task/Replace.php';
- require_once 'PEAR/Task/Unixeol.php';
- require_once 'PEAR/Task/Windowseol.php';
- require_once 'PEAR/PackageFile/v1.php';
- require_once 'PEAR/PackageFile/v2.php';
- require_once 'PEAR/PackageFile/Generator/v1.php';
- require_once 'PEAR/PackageFile/Generator/v2.php';
- }
- $filelist = $this->_registry->packageInfo($package, 'filelist', $channel);
- if ($filelist == null) {
- return $this->raiseError("$channel/$package not installed");
- }
- $ret = array();
- if ($this->config->isDefinedLayer('ftp') && isset($this->_options['upgrade'])) {
- $pkg = $this->_registry->getPackage($package, $channel);
- $this->ftpUninstall($pkg); // no error checking
- }
- return parent::_deletePackageFiles($package, $channel, $backup);
- }
-
- /**
- * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
- */
- public function ftpUninstall($pkg)
- {
- $ftp = &$this->config->getFTP();
- if (!$ftp) {
- return $this->raiseError('FTP client not initialized');
- }
- $this->log(2, 'Connect to FTP server');
- $e = $ftp->init();
- if (PEAR::isError($e)) {
- return $e;
- }
- PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN);
- foreach ($pkg->getFilelist() as $file => $atts) {
- if ($pkg->getPackagexmlVersion() == '1.0') {
- $channel = 'pear.php.net';
- switch ($atts['role']) {
- case 'doc':
- case 'data':
- case 'test':
- $dest_dir = $this->config->get($atts['role'] . '_dir', 'ftp', $channel) .
- DIRECTORY_SEPARATOR . $pkg->getPackage();
- unset($atts['baseinstalldir']);
- break;
- case 'ext':
- case 'php':
- $dest_dir = $this->config->get($atts['role'] . '_dir', 'ftp', $channel);
- break;
- case 'script':
- $dest_dir = $this->config->get('bin_dir', 'ftp', $channel);
- break;
- default:
- continue 2;
- }
- $save_destdir = $dest_dir;
- if (!empty($atts['baseinstalldir'])) {
- $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
- }
- if (dirname($file) != '.' && empty($atts['install-as'])) {
- $dest_dir .= DIRECTORY_SEPARATOR . dirname($file);
- }
- if (empty($atts['install-as'])) {
- $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file);
- } else {
- $dest_file = $dest_dir . DIRECTORY_SEPARATOR . $atts['install-as'];
- }
-
- // Clean up the DIRECTORY_SEPARATOR mess
- $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
- $dest_file = preg_replace(array('!\\\\+!', '!/!', "!$ds2+!"),
- array('/', '/', '/'),
- $dest_file);
- } else {
- $role = &PEAR_Installer_Role::factory($pkg, $atts['role'], $this->config);
- $role->setup($this, $pkg, $atts, $file);
- if (!$role->isInstallable()) {
- continue; // this shouldn't happen
- }
- $tmp_path = ''; // unused
- list($save_destdir, $dest_dir, $dest_file, $orig_file) =
- $role->processInstallation($pkg, $atts, $file, $tmp_path, 'ftp');
- $dest_file = str_replace(DIRECTORY_SEPARATOR, '/', $dest_file);
- }
- $this->log(2, 'Deleting "' . $dest_file . '"');
- $ftp->rm($dest_file);
- }
- PEAR::staticPopErrorHandling();
- $this->log(2, 'Disconnect from FTP server');
- return $ftp->disconnect();
- }
-
- /**
- * Upload an installed package - does not work with register-only packages!
- * @param PEAR_PackageFile_v1|PEAR_PackageFile_v2
- */
- public function ftpInstall($pkg)
- {
- if ($pkg->getPackageType() != 'php') {
- return PEAR::raiseError('Error: can only install PHP scripts remotely,' .
- ' no PHP extensions can be compiled remotely');
- }
- $ftp = &$this->config->getFTP();
- if (!$ftp) {
- return PEAR::raiseError('FTP client not initialized');
- }
- $this->log(2, 'Connect to FTP server');
- $e = $ftp->init();
- if (PEAR::isError($e)) {
- return $e;
- }
- $pf = &$this->_registry->getPackage($pkg->getPackage(), $pkg->getChannel());
- foreach ($pf->getFilelist() as $file => $atts) {
- if ($pf->getPackagexmlVersion() == '1.0') {
- $channel = 'pear.php.net';
- switch ($atts['role']) {
- case 'doc':
- case 'data':
- case 'test':
- $dest_dir = $this->config->get($atts['role'] . '_dir', 'ftp', $channel) .
- DIRECTORY_SEPARATOR . $pf->getPackage();
- unset($atts['baseinstalldir']);
- break;
- case 'ext':
- case 'php':
- $dest_dir = $this->config->get($atts['role'] . '_dir', 'ftp', $channel);
- break;
- case 'script':
- $dest_dir = $this->config->get('bin_dir', 'ftp', $channel);
- break;
- default:
- continue 2;
- }
- $save_destdir = $dest_dir;
- if (!empty($atts['baseinstalldir'])) {
- $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
- }
- if (dirname($file) != '.' && empty($atts['install-as'])) {
- $dest_dir .= DIRECTORY_SEPARATOR . dirname($file);
- }
- if (empty($atts['install-as'])) {
- $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file);
- } else {
- $dest_file = $dest_dir . DIRECTORY_SEPARATOR . $atts['install-as'];
- }
-
- // Clean up the DIRECTORY_SEPARATOR mess
- $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
- $dest_file = preg_replace(array('!\\+!', '!/!', "!$ds2+!"),
- array('/', '/', '/'),
- $dest_file);
- } else {
- $role = &PEAR_Installer_Role::factory($pf, $atts['role'], $this->config);
- $role->setup($this, $pf, $atts, $file);
- if (!$role->isInstallable()) {
- continue; // this shouldn't happen
- }
- list($save_destdir, $dest_dir, $dest_file, $orig_file) =
- $role->processInstallation($pkg, $atts, $file, $file /* not used */, 'ftp');
- $dest_file = str_replace(DIRECTORY_SEPARATOR, '/', $dest_file);
- }
- $installedas = $atts['installed_as'];
- $this->log(2, 'Uploading "' . $installedas . '" to "' . $dest_file . '"');
- if (PEAR::isError($e = $ftp->installFile($installedas, $dest_file))) {
- return $e;
- }
- }
- $this->log(2, 'Disconnect from FTP server');
- return $ftp->disconnect();
- }
-}
-?>
View
155 package-RemoteInstall.xml
@@ -1,155 +0,0 @@
-<?xml version="1.0"?>
-<package version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
-http://pear.php.net/dtd/tasks-1.0.xsd
-http://pear.php.net/dtd/package-2.0
-http://pear.php.net/dtd/package-2.0.xsd">
- <name>PEAR_RemoteInstaller</name>
- <channel>pear.php.net</channel>
- <summary>PEAR Remote installation plugin through FTP, SFTP, and FTPS</summary>
- <description>Originally part of the 1.4.0 new features,
-remote installation through FTP, FTPS and SFTP is now its own package.
-This package adds the commands &quot;remote-install&quot; &quot;remote-upgrade&quot;
-&quot;remote-uninstall&quot; and &quot;remote-upgrade-all&quot; to the PEAR core.
-
-To take advantage, you must have a config file on the remote
-ftp server and full access to the server to create and remove
-files. The config-create command can be used to get started,
-and the remote_config configuration variable is set to the
-full URL as in &quot;ftp://ftp.example.com/path/to/pear.ini&quot; or
-&quot;ftps://user:pass@ftp.example.com/path/to/pear.ini&quot; or
-&quot;ssh2.sftp://user:pass@ftp.example.com/path/to/pear.ini&quot;
-
-After this is done, install/upgrade as normal using the
-remote* commands as if they were local.
- </description>
- <lead>
- <name>Greg Beaver</name>
- <user>cellog</user>
- <email>cellog@php.net</email>
- <active>yes</active>
- </lead>
- <date>2006-12-15</date>
- <version>
- <release>0.3.2</release>
- <api>0.1.0</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <license uri="http://www.php.net/license">PHP License</license>
- <notes>
- * fix Bug #9768: notice error raised with remote-uninstall
- </notes>
- <contents>
- <dir name="/">
- <dir name="PEAR">
- <dir name="Command">
- <file name="Remoteinstall.xml" role="php"/>
- <file name="Remoteinstall.php" role="php">
- <tasks:replace from="@package_version@" to="version" type="package-info" />
- </file>
- </dir> <!-- /PEAR/Command -->
- <file name="FTP.php" role="php">
- <tasks:replace from="@package_version@" to="version" type="package-info" />
- </file>
- <file name="RemoteInstaller.php" role="php">
- <tasks:replace from="@package_version@" to="version" type="package-info" />
- </file>
- </dir> <!-- /PEAR -->
- </dir> <!-- / -->
- </contents>
- <dependencies>
- <required>
- <php>
- <min>5.0.0</min>
- </php>
- <pearinstaller>
- <min>1.5.0RC1</min>
- </pearinstaller>
- <package>
- <name>PEAR</name>
- <channel>pear.php.net</channel>
- <min>1.4.3</min>
- </package>
- </required>
- <optional>
- <package>
- <name>ssh2</name>
- <channel>pecl.php.net</channel>
- <providesextension>ssh2</providesextension>
- </package>
- </optional>
- </dependencies>
- <phprelease/>
- <changelog>
- <release>
- <version>
- <release>0.1.0</release>
- <api>0.1.0</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <date>2005-08-20</date>
- <license uri="http://www.php.net/license/3_0.txt">PHP License</license>
- <notes>
- initial separate release from PEAR
- </notes>
- </release>
- <release>
- <version>
- <release>0.2.0</release>
- <api>0.1.0</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <date>2005-11-29</date>
- <license uri="http://www.php.net/license">PHP License</license>
- <notes>
- Update to new format needed by PEAR 1.4.3
- </notes>
- </release>
- <release>
- <version>
- <release>0.3.0</release>
- <api>0.1.0</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <date>2006-04-02</date>
- <license uri="http://www.php.net/license">PHP License</license>
- <notes>
- Support for FTPS and SFTP is now available!
- * Drop Net_FTP dependency, add dependency on PHP 5, use streams to access
- FTP.
- * Require PEAR 1.4.3 for security reasons
- * Add optional dep on ssh2 extension
- </notes>
- </release>
- <release>
- <version>
- <release>0.3.1</release>
- <api>0.1.0</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <date>2006-12-15</date>
- <license uri="http://www.php.net/license">PHP License</license>
- <notes>
-fix Bug #7881: stream_copy_to_stream function args reversed
-fix bug in uninstall - $atts instead of $atts['attribs']
-fix unclear error message in put()
-up required PEAR Installer dependency to 1.5.0RC1 because of bug
-fixed in that version
- </notes>
- </release>
- </changelog>
-</package>

0 comments on commit 48e9a4d

Please sign in to comment.