1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is, guess what, part of WebHelper. |
5
|
|
|
* |
6
|
|
|
* (c) James <[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 JamesRezo\WebHelper\Command; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
17
|
|
|
use JamesRezo\WebHelper\WebServer\NullWebServer; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Analyze a webserver configuration. |
21
|
|
|
*/ |
22
|
|
|
class AnalyzeCommand extends BaseCommand |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
5 |
|
protected function configure() |
28
|
|
|
{ |
29
|
5 |
|
$this |
30
|
5 |
|
->setName('analyze') |
31
|
5 |
|
->setDescription('Analyze a webserver configuration') |
32
|
5 |
|
->setHelp('The <info>analyze</info> command parses the configuration of a webserver.') |
33
|
5 |
|
->addArgument('webserver', InputArgument::REQUIRED, 'a webserver name.') |
34
|
5 |
|
->addArgument('configfile', InputArgument::REQUIRED, 'a configuration file.') |
35
|
|
|
; |
36
|
5 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Execute the command. |
40
|
|
|
* |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
* |
43
|
|
|
* @param InputInterface $input the input interface |
44
|
|
|
* @param OutputInterface $output the output interface |
45
|
|
|
*/ |
46
|
4 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
47
|
|
|
{ |
48
|
4 |
|
$webserver = $this->getWebServer($input, $output); |
49
|
4 |
|
if ($webserver instanceof NullWebServer) { |
50
|
1 |
|
return 1; |
51
|
|
|
} |
52
|
|
|
|
53
|
3 |
|
$configfile = $input->getArgument('configfile'); |
54
|
3 |
|
if (!is_readable($configfile)) { |
55
|
1 |
|
$output->writeln('<error>Configuration file "'.$configfile.'" does not exist.</error>'); |
56
|
|
|
|
57
|
1 |
|
return 1; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
//For now, just outputs a cleaned list of directives |
61
|
2 |
|
$activeConfig = $webserver->getActiveConfig($configfile); |
62
|
2 |
|
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) { |
63
|
|
|
$output->write(implode(PHP_EOL, $activeConfig)); |
64
|
|
|
} |
65
|
|
|
|
66
|
2 |
|
$parsedActiveConfig = $webserver->parseActiveConfig($activeConfig); |
67
|
2 |
|
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { |
68
|
|
|
$output->writeln(var_export($parsedActiveConfig, true)); |
69
|
|
|
} |
70
|
2 |
|
} |
71
|
|
|
} |
72
|
|
|
|