blob: 392c0136a21e4edf1ff860b5e1b82a5ab744c254 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\TestRunner\Aws;
use Symfony\Component\Console\Output\OutputInterface;
use Crypt_RSA;
use Net_SSH2;
class Ssh extends Net_SSH2
{
/**
* @var OutputInterface
*/
private $output;
public static function connectToAws($host, $pemFile)
{
$key = new Crypt_RSA();
$key->loadKey(file_get_contents($pemFile));
$ssh = new Ssh($host);
if (!$ssh->login('ubuntu', $key)) {
$error = error_get_last();
throw new \RuntimeException("Login to $host using $pemFile failed: " . $error['message']);
}
return $ssh;
}
public function setOutput(OutputInterface $output)
{
$this->output = $output;
}
public function exec($command, $callback = null)
{
$command = 'cd www/piwik && ' . $command;
$output = $this->output;
$output->writeln("Executing <comment>$command</comment>");
return parent::exec($command, function($tempOutput) use ($output) {
if ($output) {
$output->write($tempOutput);
}
});
}
}
|