diff --git a/.gitignore b/.gitignore index d186c27de..cf3b0654c 100755 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ composer.lock .DS_Store Thumbs.db .idea/ -.phpunit.result.cache \ No newline at end of file +.phpunit.result.cache +.direnv +.envrc \ No newline at end of file diff --git a/composer.json b/composer.json index f308fa4d1..6a6ced233 100755 --- a/composer.json +++ b/composer.json @@ -19,7 +19,6 @@ "nesbot/carbon": "^2.71", "opis/closure": "~3.6", "pda/pheanstalk": "~4.0", - "phpseclib/phpseclib": "~2.0", "predis/predis": "^1.1", "symfony/browser-kit": "~6.4", "symfony/console": "~6.4", @@ -59,7 +58,6 @@ "illuminate/pagination": "self.version", "illuminate/queue": "self.version", "illuminate/redis": "self.version", - "illuminate/remote": "self.version", "illuminate/routing": "self.version", "illuminate/session": "self.version", "illuminate/support": "self.version", diff --git a/src/Illuminate/Foundation/Application.php b/src/Illuminate/Foundation/Application.php index f2deb35e6..b7c0a7a6c 100755 --- a/src/Illuminate/Foundation/Application.php +++ b/src/Illuminate/Foundation/Application.php @@ -1142,7 +1142,6 @@ public function registerCoreContainerAliases() 'router' => 'Illuminate\Routing\Router', 'session' => 'Illuminate\Session\SessionManager', 'session.store' => 'Illuminate\Session\Store', - 'remote' => 'Illuminate\Remote\RemoteManager', 'url' => 'Illuminate\Routing\UrlGenerator', 'validator' => 'Illuminate\Validation\Factory', 'view' => 'Illuminate\View\Factory', diff --git a/src/Illuminate/Foundation/Console/TailCommand.php b/src/Illuminate/Foundation/Console/TailCommand.php deleted file mode 100644 index 9dee85f33..000000000 --- a/src/Illuminate/Foundation/Console/TailCommand.php +++ /dev/null @@ -1,168 +0,0 @@ -getPath($this->argument('connection')); - - if ($path) - { - $this->tailLogFile($path, $this->argument('connection')); - } - else - { - $this->error('Could not determine path to log file.'); - } - - return 0; - } - - /** - * Tail the given log file for the connection. - * - * @param string $path - * @param string $connection - * @return void - */ - protected function tailLogFile($path, $connection) - { - if (is_null($connection)) - { - $this->tailLocalLogs($path); - } - else - { - $this->tailRemoteLogs($path, $connection); - } - } - - /** - * Tail a local log file for the application. - * - * @param string $path - * @return string - */ - protected function tailLocalLogs($path) - { - $output = $this->output; - - $lines = $this->option('lines'); - - Process::fromShellCommandline('tail -f -n '.$lines.' '.escapeshellarg($path)) - ->setTimeout(null) - ->run(function($type, $line) use ($output) { - $output->write($line); - }); - } - - /** - * Tail a remote log file at the given path and connection. - * - * @param string $path - * @param string $connection - * @return void - */ - protected function tailRemoteLogs($path, $connection) - { - $out = $this->output; - - $lines = $this->option('lines'); - - $this->getRemote($connection)->run('tail -f -n '.$lines.' '.escapeshellarg($path), function($line) use ($out) - { - $out->write($line); - }); - } - - /** - * Get a connection to the remote server. - * - * @param string $connection - * @return \Illuminate\Remote\Connection - */ - protected function getRemote($connection) - { - return $this->laravel['remote']->connection($connection); - } - - /** - * Get the path to the Laravel log file. - * - * @param string $connection - * @return string - */ - protected function getPath($connection) - { - if ($this->option('path')) return $this->option('path'); - - if (is_null($connection)) - { - return storage_path('/logs/laravel.log'); - } - - return $this->getRoot($connection).str_replace(base_path(), '', storage_path()).'/logs/laravel.log'; - } - - /** - * Get the path to the Laravel install root. - * - * @param string $connection - * @return string - */ - protected function getRoot($connection) - { - return $this->laravel['config']['remote.connections.'.$connection.'.root']; - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return array( - array('connection', InputArgument::OPTIONAL, 'The remote connection name'), - ); - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return array( - array('path', null, InputOption::VALUE_OPTIONAL, 'The fully qualified path to the log file.'), - - array('lines', null, InputOption::VALUE_OPTIONAL, 'The number of lines to tail.', 20), - ); - } - -} diff --git a/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php b/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php index 2881bc762..16f252143 100755 --- a/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php +++ b/src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php @@ -2,7 +2,6 @@ use Illuminate\Foundation\Artisan; use Illuminate\Support\ServiceProvider; -use Illuminate\Foundation\Console\TailCommand; use Illuminate\Foundation\Console\ChangesCommand; use Illuminate\Foundation\Console\EnvironmentCommand; @@ -27,11 +26,6 @@ public function register() return new Artisan($app); }); - $this->app->bindShared('command.tail', function() - { - return new TailCommand; - }); - $this->app->bindShared('command.changes', function() { return new ChangesCommand; @@ -42,7 +36,7 @@ public function register() return new EnvironmentCommand; }); - $this->commands('command.tail', 'command.changes', 'command.environment'); + $this->commands( 'command.changes', 'command.environment'); } /** diff --git a/src/Illuminate/Remote/Connection.php b/src/Illuminate/Remote/Connection.php deleted file mode 100644 index 18042da60..000000000 --- a/src/Illuminate/Remote/Connection.php +++ /dev/null @@ -1,262 +0,0 @@ -name = $name; - $this->host = $host; - $this->username = $username; - $this->gateway = $gateway ?: new SecLibGateway($host, $auth, new Filesystem); - } - - /** - * Define a set of commands as a task. - * - * @param string $task - * @param string|array $commands - * @return void - */ - public function define($task, $commands) - { - $this->tasks[$task] = $commands; - } - - /** - * Run a task against the connection. - * - * @param string $task - * @param \Closure $callback - * @return void - */ - public function task($task, Closure $callback = null) - { - if (isset($this->tasks[$task])) - { - return $this->run($this->tasks[$task], $callback); - } - } - - /** - * Run a set of commands against the connection. - * - * @param string|array $commands - * @param \Closure $callback - * @return void - */ - public function run($commands, Closure $callback = null) - { - // First, we will initialize the SSH gateway, and then format the commands so - // they can be run. Once we have the commands formatted and the server is - // ready to go we will just fire off these commands against the server. - $gateway = $this->getGateway(); - - $callback = $this->getCallback($callback); - - $gateway->run($this->formatCommands($commands)); - - // After running the commands against the server, we will continue to ask for - // the next line of output that is available, and write it them out using - // our callback. Once we hit the end of output, we'll bail out of here. - while (true) - { - if (is_null($line = $gateway->nextLine())) break; - - call_user_func($callback, $line, $this); - } - } - - /** - * Download the contents of a remote file. - * - * @param string $remote - * @param string $local - * @return void - */ - public function get($remote, $local) - { - $this->getGateway()->get($remote, $local); - } - - /** - * Get the contents of a remote file. - * - * @param string $remote - * @return string - */ - public function getString($remote) - { - return $this->getGateway()->getString($remote); - } - - /** - * Upload a local file to the server. - * - * @param string $local - * @param string $remote - * @return void - */ - public function put($local, $remote) - { - $this->getGateway()->put($local, $remote); - } - - /** - * Upload a string to to the given file on the server. - * - * @param string $remote - * @param string $contents - * @return void - */ - public function putString($remote, $contents) - { - $this->getGateway()->putString($remote, $contents); - } - - /** - * Display the given line using the default output. - * - * @param string $line - * @return void - */ - public function display($line) - { - $server = $this->username.'@'.$this->host; - - $lead = '['.$server.'] ('.$this->name.')'; - - $this->getOutput()->writeln($lead.' '.$line); - } - - /** - * Format the given command set. - * - * @param string|array $commands - * @return string - */ - protected function formatCommands($commands) - { - return is_array($commands) ? implode(' && ', $commands) : $commands; - } - - /** - * Get the display callback for the connection. - * - * @param \Closure|null $callback - * @return \Closure - */ - protected function getCallback($callback) - { - if ( ! is_null($callback)) return $callback; - - return function($line) { $this->display($line); }; - } - - /** - * Get the exit status of the last command. - * - * @return int|bool - */ - public function status() - { - return $this->gateway->status(); - } - - /** - * Get the gateway implementation. - * - * @return \Illuminate\Remote\GatewayInterface - * - * @throws \RuntimeException - */ - public function getGateway() - { - if ( ! $this->gateway->connected() && ! $this->gateway->connect($this->username)) - { - throw new \RuntimeException("Unable to connect to remote server."); - } - - return $this->gateway; - } - - /** - * Get the output implementation for the connection. - * - * @return \Symfony\Component\Console\Output\OutputInterface - */ - public function getOutput() - { - if (is_null($this->output)) $this->output = new NullOutput; - - return $this->output; - } - - /** - * Set the output implementation. - * - * @param \Symfony\Component\Console\Output\OutputInterface $output - * @return void - */ - public function setOutput(OutputInterface $output) - { - $this->output = $output; - } - -} diff --git a/src/Illuminate/Remote/ConnectionInterface.php b/src/Illuminate/Remote/ConnectionInterface.php deleted file mode 100644 index 0b46ab39a..000000000 --- a/src/Illuminate/Remote/ConnectionInterface.php +++ /dev/null @@ -1,52 +0,0 @@ -connections = $connections; - } - - /** - * Define a set of commands as a task. - * - * @param string $task - * @param string|array $commands - * @return void - */ - public function define($task, $commands) - { - foreach ($this->connections as $connection) - { - $connection->define($task, $commands); - } - } - - /** - * Run a task against the connection. - * - * @param string $task - * @param \Closure $callback - * @return void - */ - public function task($task, Closure $callback = null) - { - foreach ($this->connections as $connection) - { - $connection->task($task, $callback); - } - } - - /** - * Run a set of commands against the connection. - * - * @param string|array $commands - * @param \Closure $callback - * @return void - */ - public function run($commands, Closure $callback = null) - { - foreach ($this->connections as $connection) - { - $connection->run($commands, $callback); - } - } - - /** - * Upload a local file to the server. - * - * @param string $local - * @param string $remote - * @return void - */ - public function put($local, $remote) - { - foreach ($this->connections as $connection) - { - $connection->put($local, $remote); - } - } - - /** - * Upload a string to to the given file on the server. - * - * @param string $remote - * @param string $contents - * @return void - */ - public function putString($remote, $contents) - { - foreach ($this->connections as $connection) - { - $connection->putString($remote, $contents); - } - } - -} diff --git a/src/Illuminate/Remote/RemoteManager.php b/src/Illuminate/Remote/RemoteManager.php deleted file mode 100644 index 7d01f1897..000000000 --- a/src/Illuminate/Remote/RemoteManager.php +++ /dev/null @@ -1,199 +0,0 @@ -app = $app; - } - - /** - * Get a remote connection instance. - * - * @param string|array|mixed $name - * @return \Illuminate\Remote\ConnectionInterface - */ - public function into($name) - { - if (is_string($name) || is_array($name)) - { - return $this->connection($name); - } - - return $this->connection(func_get_args()); - } - - /** - * Get a remote connection instance. - * - * @param string|array $name - * @return \Illuminate\Remote\ConnectionInterface - */ - public function connection($name = null) - { - if (is_array($name)) return $this->multiple($name); - - return $this->resolve($name ?: $this->getDefaultConnection()); - } - - /** - * Get a connection group instance by name. - * - * @param string $name - * @return \Illuminate\Remote\ConnectionInterface - */ - public function group($name) - { - return $this->connection($this->app['config']['remote.groups.'.$name]); - } - - /** - * Resolve a multiple connection instance. - * - * @param array $names - * @return \Illuminate\Remote\MultiConnection - */ - public function multiple(array $names) - { - return new MultiConnection(array_map($this->resolve(...), $names)); - } - - /** - * Resolve a remote connection instance. - * - * @param string $name - * @return \Illuminate\Remote\Connection - */ - public function resolve($name) - { - return $this->makeConnection($name, $this->getConfig($name)); - } - - /** - * Make a new connection instance. - * - * @param string $name - * @param array $config - * @return \Illuminate\Remote\Connection - */ - protected function makeConnection($name, array $config) - { - $this->setOutput($connection = new Connection( - - $name, $config['host'], $config['username'], $this->getAuth($config) - - )); - - return $connection; - } - - /** - * Set the output implementation on the connection. - * - * @param \Illuminate\Remote\Connection $connection - * @return void - */ - protected function setOutput(Connection $connection) - { - $output = php_sapi_name() == 'cli' ? new ConsoleOutput : new NullOutput; - - $connection->setOutput($output); - } - - /** - * Format the appropriate authentication array payload. - * - * @param array $config - * @return array - * - * @throws \InvalidArgumentException - */ - protected function getAuth(array $config) - { - if (isset($config['agent']) && $config['agent'] === true) - { - return array('agent' => true); - } - elseif (isset($config['key']) && trim((string) $config['key']) != '') - { - return array('key' => $config['key'], 'keyphrase' => $config['keyphrase']); - } - elseif (isset($config['keytext']) && trim((string) $config['keytext']) != '') - { - return array('keytext' => $config['keytext']); - } - elseif (isset($config['password'])) - { - return array('password' => $config['password']); - } - - throw new \InvalidArgumentException('Password / key is required.'); - } - - /** - * Get the configuration for a remote server. - * - * @param string $name - * @return array - * - * @throws \InvalidArgumentException - */ - protected function getConfig($name) - { - $config = $this->app['config']['remote.connections.'.$name]; - - if ( ! is_null($config)) return $config; - - throw new \InvalidArgumentException("Remote connection [$name] not defined."); - } - - /** - * Get the default connection name. - * - * @return string - */ - public function getDefaultConnection() - { - return $this->app['config']['remote.default']; - } - - /** - * Set the default connection name. - * - * @param string $name - * @return void - */ - public function setDefaultConnection($name) - { - $this->app['config']['remote.default'] = $name; - } - - /** - * Dynamically pass methods to the default connection. - * - * @param string $method - * @param array $parameters - * @return mixed - */ - public function __call($method, $parameters) - { - return call_user_func_array(array($this->connection(), $method), $parameters); - } - -} diff --git a/src/Illuminate/Remote/RemoteServiceProvider.php b/src/Illuminate/Remote/RemoteServiceProvider.php deleted file mode 100644 index 0bceea907..000000000 --- a/src/Illuminate/Remote/RemoteServiceProvider.php +++ /dev/null @@ -1,37 +0,0 @@ -app->bindShared('remote', function($app) - { - return new RemoteManager($app); - }); - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return array('remote'); - } - -} diff --git a/src/Illuminate/Remote/SecLibGateway.php b/src/Illuminate/Remote/SecLibGateway.php deleted file mode 100644 index 28103a9b3..000000000 --- a/src/Illuminate/Remote/SecLibGateway.php +++ /dev/null @@ -1,322 +0,0 @@ -auth = $auth; - $this->files = $files; - $this->setHostAndPort($host); - } - - /** - * Set the host and port from a full host string. - * - * @param string $host - * @return void - */ - protected function setHostAndPort($host) - { - if ( ! Str::contains($host, ':')) - { - $this->host = $host; - } - else - { - list($this->host, $this->port) = explode(':', $host); - - $this->port = (int) $this->port; - } - } - - /** - * Connect to the SSH server. - * - * @param string $username - * @return bool - */ - public function connect($username) - { - return $this->getConnection()->login($username, $this->getAuthForLogin()); - } - - /** - * Determine if the gateway is connected. - * - * @return bool - */ - public function connected() - { - return $this->getConnection()->isConnected(); - } - - /** - * Run a command against the server (non-blocking). - * - * @param string $command - * @return void - */ - public function run($command) - { - $this->getConnection()->exec($command, false); - } - - /** - * Download the contents of a remote file. - * - * @param string $remote - * @param string $local - * @return void - */ - public function get($remote, $local) - { - $this->getConnection()->get($remote, $local); - } - - /** - * Get the contents of a remote file. - * - * @param string $remote - * @return string - */ - public function getString($remote) - { - return $this->getConnection()->get($remote); - } - - /** - * Upload a local file to the server. - * - * @param string $local - * @param string $remote - * @return void - */ - public function put($local, $remote) - { - $this->getConnection()->put($remote, $local, NET_SFTP_LOCAL_FILE); - } - - /** - * Upload a string to to the given file on the server. - * - * @param string $remote - * @param string $contents - * @return void - */ - public function putString($remote, $contents) - { - $this->getConnection()->put($remote, $contents); - } - - /** - * Get the next line of output from the server. - * - * @return string|null - */ - public function nextLine() - { - $value = $this->getConnection()->_get_channel_packet(NET_SSH2_CHANNEL_EXEC); - - return $value === true ? null : $value; - } - - /** - * Get the authentication object for login. - * - * @return \Crypt_RSA|\System_SSH_Agent|string - * @throws \InvalidArgumentException - */ - protected function getAuthForLogin() - { - if ($this->useAgent()) return $this->getAgent(); - - // If a "key" was specified in the auth credentials, we will load it into a - // secure RSA key instance, which will be used to connect to the servers - // in place of a password, and avoids the developer specifying a pass. - elseif ($this->hasRsaKey()) - { - return $this->loadRsaKey($this->auth); - } - - // If a plain password was set on the auth credentials, we will just return - // that as it can be used to connect to the server. This will be used if - // there is no RSA key and it gets specified in the credential arrays. - elseif (isset($this->auth['password'])) - { - return $this->auth['password']; - } - - throw new \InvalidArgumentException('Password / key is required.'); - } - - /** - * Determine if an RSA key is configured. - * - * @return bool - */ - protected function hasRsaKey() - { - $hasKey = (isset($this->auth['key']) && trim((string) $this->auth['key']) != ''); - - return $hasKey || (isset($this->auth['keytext']) && trim((string) $this->auth['keytext']) != ''); - } - - /** - * Load the RSA key instance. - * - * @param array $auth - * @return \Crypt_RSA - */ - protected function loadRsaKey(array $auth) - { - with($key = $this->getKey($auth))->loadKey($this->readRsaKey($auth)); - - return $key; - } - - /** - * Read the contents of the RSA key. - * - * @param array $auth - * @return string - */ - protected function readRsaKey(array $auth) - { - if (isset($auth['key'])) return $this->files->get($auth['key']); - - return $auth['keytext']; - } - - /** - * Create a new RSA key instance. - * - * @param array $auth - * @return \Crypt_RSA - */ - protected function getKey(array $auth) - { - with($key = $this->getNewKey())->setPassword(array_get($auth, 'keyphrase')); - - return $key; - } - - /** - * Determine if the SSH Agent should provide an RSA key. - * - * @return bool - */ - protected function useAgent() - { - return isset($this->auth['agent']) && $this->auth['agent'] === true; - } - - /** - * Get a new SSH Agent instance. - * - * @return \System_SSH_Agent - */ - public function getAgent() - { - return new System_SSH_Agent; - } - - /** - * Get a new RSA key instance. - * - * @return \Crypt_RSA - */ - public function getNewKey() - { - return new Crypt_RSA; - } - - /** - * Get the exit status of the last command. - * - * @return int|bool - */ - public function status() - { - return $this->getConnection()->getExitStatus(); - } - - /** - * Get the host used by the gateway. - * - * @return string - */ - public function getHost() - { - return $this->host; - } - - /** - * Get the port used by the gateway. - * - * @return int - */ - public function getPort() - { - return $this->port; - } - - /** - * Get the underlying Net_SFTP connection. - * - * @return \Net_SFTP - */ - public function getConnection() - { - if ($this->connection) return $this->connection; - - return $this->connection = new Net_SFTP($this->host, $this->port); - } - -} diff --git a/src/Illuminate/Remote/composer.json b/src/Illuminate/Remote/composer.json deleted file mode 100644 index f7bb904da..000000000 --- a/src/Illuminate/Remote/composer.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "illuminate/remote", - "license": "MIT", - "authors": [ - { - "name": "Taylor Otwell", - "email": "taylorotwell@gmail.com" - } - ], - "require": { - "php": ">=5.4.0", - "illuminate/filesystem": "4.2.*", - "illuminate/support": "4.2.*", - "phpseclib/phpseclib": "0.3.*" - }, - "require-dev": { - "illuminate/console": "4.2.*" - }, - "autoload": { - "psr-0": { - "Illuminate\\Remote": "" - } - }, - "target-dir": "Illuminate/Remote", - "extra": { - "branch-alias": { - "dev-master": "4.2-dev" - } - }, - "minimum-stability": "dev" -} diff --git a/src/Illuminate/Support/Facades/SSH.php b/src/Illuminate/Support/Facades/SSH.php deleted file mode 100644 index 5178a4b06..000000000 --- a/src/Illuminate/Support/Facades/SSH.php +++ /dev/null @@ -1,16 +0,0 @@ -getGateway(); - $this->assertEquals('127.0.0.1', $gateway->getHost()); - $this->assertEquals(22, $gateway->getPort()); - } - - - public function testConnectProperlyCallsLoginWithAuth() - { - $gateway = $this->getGateway(); - $gateway->shouldReceive('getNewKey')->andReturn($key = m::mock('StdClass')); - $key->shouldReceive('setPassword')->once()->with('keyphrase'); - $key->shouldReceive('loadKey')->once()->with('keystuff'); - $gateway->getConnection()->shouldReceive('login')->with('taylor', $key); - - $gateway->connect('taylor'); - } - - - public function testKeyTextCanBeSetManually() - { - $files = m::mock(Filesystem::class); - $gateway = m::mock(SecLibGateway::class, ['127.0.0.1:22', ['username' => 'taylor', 'keytext' => 'keystuff'], $files] - )->makePartial(); - $gateway->shouldReceive('getConnection')->andReturn(m::mock('StdClass')); - $gateway->shouldReceive('getNewKey')->andReturn($key = m::mock('StdClass')); - $key->shouldReceive('setPassword')->once()->with(null); - $key->shouldReceive('loadKey')->once()->with('keystuff'); - $gateway->getConnection()->shouldReceive('login')->with('taylor', $key); - - $gateway->connect('taylor'); - } - - - public function getGateway() - { - $files = m::mock(Filesystem::class); - $files->shouldReceive('get')->with('keypath')->andReturn('keystuff'); - $gateway = m::mock(SecLibGateway::class, ['127.0.0.1:22', ['username' => 'taylor', 'key' => 'keypath', 'keyphrase' => 'keyphrase'], $files] - )->makePartial(); - $gateway->shouldReceive('getConnection')->andReturn(m::mock('StdClass')); - return $gateway; - } - -}