|
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\Command\Command; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
18
|
|
|
use JamesRezo\WebHelper\Factory; |
|
19
|
|
|
use JamesRezo\WebHelper\WebServer\NullWebServer; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Analyze a webserver configuration. |
|
23
|
|
|
*/ |
|
24
|
|
|
class AnalyzeCommand extends Command |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* {@inheritdoc} |
|
28
|
|
|
*/ |
|
29
|
5 |
|
protected function configure() |
|
30
|
|
|
{ |
|
31
|
5 |
|
$this |
|
32
|
5 |
|
->setName('analyze') |
|
33
|
5 |
|
->setDescription('Analyze a webserver configuration') |
|
34
|
5 |
|
->setHelp('The <info>analyze</info> command parses the configuration of a webserver.') |
|
35
|
5 |
|
->addArgument('webserver', InputArgument::REQUIRED, 'a webserver name.') |
|
36
|
5 |
|
->addArgument('configfile', InputArgument::REQUIRED, 'a configuration file.') |
|
37
|
|
|
; |
|
38
|
5 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Execute the command. |
|
42
|
|
|
* |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
* |
|
45
|
|
|
* @param InputInterface $input the input interface |
|
46
|
|
|
* @param OutputInterface $output the output interface |
|
47
|
|
|
*/ |
|
48
|
4 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
49
|
|
|
{ |
|
50
|
4 |
|
$webservername = $input->getArgument('webserver'); |
|
51
|
4 |
|
$version = 0; |
|
52
|
4 |
|
if (preg_match(',([^:]+)(:([\.\d]+))$,', $webservername, $matches)) { |
|
53
|
1 |
|
$version = $matches[3]; |
|
54
|
1 |
|
$webservername = $matches[1]; |
|
55
|
1 |
|
} |
|
56
|
|
|
|
|
57
|
4 |
|
$factory = new Factory(); |
|
58
|
4 |
|
$webserver = $factory->createWebServer($webservername, $version); |
|
59
|
4 |
|
if ($webserver instanceof NullWebServer) { |
|
60
|
1 |
|
$output->writeln('<error>Web Server "'.$webservername.'" unknown.</error>'); |
|
61
|
1 |
|
return 1; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
3 |
|
$configfile = $input->getArgument('configfile'); |
|
65
|
3 |
|
if (!is_readable($configfile)) { |
|
66
|
1 |
|
$output->writeln('<error>Configuration file "'.$configfile.'" does not exist.</error>'); |
|
67
|
1 |
|
return 1; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
//For now, just outputs a cleaned list of directives |
|
71
|
2 |
|
$output->write($webserver->getActiveConfig($configfile)); |
|
72
|
2 |
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|