|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the slince/spike package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Slince <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Spike\Client\Command; |
|
13
|
|
|
|
|
14
|
|
|
use Spike\Common\Tunnel\HttpTunnel; |
|
15
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
18
|
|
|
|
|
19
|
|
|
class ShowProxyHostsCommand extends Command |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* {@inheritdoc} |
|
23
|
|
|
*/ |
|
24
|
|
|
public function configure() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->setName('list-proxy') |
|
27
|
|
|
->setDescription('Lists all supported proxy hosts by the client'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* {@inheritdoc} |
|
32
|
|
|
*/ |
|
33
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
|
34
|
|
|
{ |
|
35
|
|
|
$tunnels = $this->getClient()->getConfiguration()->getTunnels(); |
|
36
|
|
|
if ($tunnels) { |
|
37
|
|
|
$table = new Table($output); |
|
38
|
|
|
$table->setHeaders(['Protocol', 'Server Port', 'Local Host', 'Proxy Host']); |
|
39
|
|
|
foreach ($tunnels as $tunnel) { |
|
40
|
|
|
if ($tunnel instanceof HttpTunnel) { |
|
41
|
|
|
foreach ($tunnel->getProxyHosts() as $proxyHost => $forwardHost) { |
|
42
|
|
|
$table->addRow([$tunnel->getProtocol(), $tunnel->getServerPort(), $forwardHost, $proxyHost]); |
|
43
|
|
|
} |
|
44
|
|
|
} else { |
|
45
|
|
|
$table->addRow([$tunnel->getProtocol(), $tunnel->getServerPort(), $tunnel->getHost(), '-']); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
$table->render(); |
|
49
|
|
|
} else { |
|
50
|
|
|
$output->writeln('<comment>Hi, there is no proxy host, you should create a configuration file first</comment>'); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
} |