|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SimpleSAML\Module\monitor; |
|
4
|
|
|
|
|
5
|
|
|
use \SimpleSAML\Modules\Monitor\DependencyInjection as DependencyInjection; |
|
6
|
|
|
use \SimpleSAML\Modules\Monitor\State as State; |
|
7
|
|
|
use \SimpleSAML\Modules\Monitor\TestConfiguration as TestConfiguration; |
|
8
|
|
|
use \SimpleSAML\Modules\Monitor\Monitor as Monitor; |
|
9
|
|
|
use \SimpleSAML\Configuration as ApplicationConfiguration; |
|
10
|
|
|
use \Symfony\Component\HttpFoundation\JsonResponse; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Controller class for the monitor module. |
|
14
|
|
|
* |
|
15
|
|
|
* This class serves the different views available in the module. |
|
16
|
|
|
* |
|
17
|
|
|
* @package SimpleSAML\Module\monitor |
|
18
|
|
|
*/ |
|
19
|
|
|
class Controller |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var \SimpleSAML\Configuration */ |
|
22
|
|
|
protected $config; |
|
23
|
|
|
|
|
24
|
|
|
/** @var \SimpleSAML\Configuration */ |
|
25
|
|
|
protected $moduleConfig; |
|
26
|
|
|
|
|
27
|
|
|
/** @var \SimpleSAML\Configuration */ |
|
28
|
|
|
protected $authsourceConfig; |
|
29
|
|
|
|
|
30
|
|
|
/** @var \SimpleSAML\Modules\Monitor\DependencyInjection */ |
|
31
|
|
|
protected $serverVars; |
|
32
|
|
|
|
|
33
|
|
|
/** @var \SimpleSAML\Modules\Monitor\DependencyInjection */ |
|
34
|
|
|
protected $requestVars; |
|
35
|
|
|
|
|
36
|
|
|
/** @var array */ |
|
37
|
|
|
static private $healthInfo = [ |
|
38
|
|
|
State::SKIPPED => ['SKIPPED', 'yellow'], |
|
39
|
|
|
State::FATAL => ['FATAL', 'purple'], |
|
40
|
|
|
State::ERROR => ['NOK', 'red' ], |
|
41
|
|
|
State::NOSTATE => ['NOSTATE', 'cyan' ], |
|
42
|
|
|
State::WARNING => ['WARNING', 'orange'], |
|
43
|
|
|
State::OK => ['OK', 'green' ] |
|
44
|
|
|
]; |
|
45
|
|
|
|
|
46
|
|
|
/** @var \SimpleSAML\Module\Monitor\TestConfiguration */ |
|
|
|
|
|
|
47
|
|
|
protected $testConfiguration; |
|
48
|
|
|
|
|
49
|
|
|
/** @var int */ |
|
50
|
|
|
protected $state; |
|
51
|
|
|
|
|
52
|
|
|
/** @var int */ |
|
53
|
|
|
protected $reponseCode = 200; |
|
54
|
|
|
|
|
55
|
|
|
/** @var \SimpleSAML\Module\Monitor\Monitor */ |
|
|
|
|
|
|
56
|
|
|
protected $monitor; |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Controller constructor. |
|
61
|
|
|
* |
|
62
|
|
|
* It initializes the global configuration and auth source configuration for the controllers implemented here. |
|
63
|
|
|
* |
|
64
|
|
|
* @param \SimpleSAML\Configuration $config The configuration to use by the controllers. |
|
65
|
|
|
* @param \SimpleSAML\Monitor $monitor The monitor object to use by the controllers. |
|
|
|
|
|
|
66
|
|
|
* |
|
67
|
|
|
* @throws \Exception |
|
68
|
|
|
*/ |
|
69
|
|
|
public function __construct( |
|
70
|
|
|
Configuration $config |
|
|
|
|
|
|
71
|
|
|
) { |
|
72
|
|
|
$this->config = $config; |
|
73
|
|
|
$this->moduleConfig = ApplicationConfiguration::getOptionalConfig('module_monitor.php'); |
|
74
|
|
|
$this->authsourceConfig = ApplicationConfiguration::getOptionalConfig('authsources.php'); |
|
75
|
|
|
|
|
76
|
|
|
$this->serverVars = new DependencyInjection($_SERVER); |
|
77
|
|
|
$this->requestVars = new DependencyInjection($_REQUEST); |
|
78
|
|
|
|
|
79
|
|
|
$this->testConfiguration = new TestConfiguration($this->serverVars, $this->requestVars, $this->config, $this->authsourceConfig, $this->moduleConfig); |
|
|
|
|
|
|
80
|
|
|
$this->monitor = new Monitor($this->testConfiguration); |
|
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
$this->state = $this->monitor->getState(); |
|
83
|
|
|
if ($this->state === State::OK) { |
|
84
|
|
|
$this->responseCode = 200; |
|
|
|
|
|
|
85
|
|
|
} else if ($this->state === State::WARNING) { |
|
86
|
|
|
$this->responseCode = 417; |
|
87
|
|
|
} else { |
|
88
|
|
|
$this->responseCode = 500; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Display the main monitoring page. |
|
95
|
|
|
* |
|
96
|
|
|
* @param string $format Default is XHTML output |
|
97
|
|
|
* @return \SimpleSAML\XHTML\Template |
|
98
|
|
|
*/ |
|
99
|
|
|
public function main($format) |
|
|
|
|
|
|
100
|
|
|
{ |
|
101
|
|
|
$this->monitor->invokeTestSuites(); |
|
102
|
|
|
$results = $this->monitor->getResults(); |
|
103
|
|
|
|
|
104
|
|
|
switch ($this->requestVars->get('output')) { |
|
105
|
|
|
case 'xml': |
|
106
|
|
|
$t = $this->processXml(); |
|
107
|
|
|
break; |
|
108
|
|
|
case 'json': |
|
109
|
|
|
return $this->processJson($results); |
|
110
|
|
|
case 'text': |
|
111
|
|
|
$t = $this->processText(); |
|
112
|
|
|
break; |
|
113
|
|
|
default: |
|
114
|
|
|
$t = new \SimpleSAML\XHTML\Template($globalConfig, 'monitor:monitor.php'); |
|
|
|
|
|
|
115
|
|
|
break; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
$t->data['header'] = 'Monitor'; |
|
119
|
|
|
$t->data = array_merge($t->data, $results); |
|
120
|
|
|
|
|
121
|
|
|
$t->data['overall'] = $this->state; |
|
122
|
|
|
$t->data['healthInfo'] = $this->healthInfo; |
|
123
|
|
|
$t->data['responseCode'] = $this->responseCode; |
|
124
|
|
|
|
|
125
|
|
|
$this->setStatusCode($this->responseCode); |
|
|
|
|
|
|
126
|
|
|
return $t; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @return \SimpleSAML\XHTML\Template |
|
132
|
|
|
*/ |
|
133
|
|
|
private function processXml() { |
|
134
|
|
|
$t = new \SimpleSAML\XHTML\Template($this->config, 'monitor:monitor.xml.php'); |
|
135
|
|
|
$t->headers->set('Content-Type', 'text/xml'); |
|
136
|
|
|
return $t; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @param array $results |
|
142
|
|
|
* @return \SimpleSAML\XHTML\Template |
|
143
|
|
|
*/ |
|
144
|
|
|
private function processJson(array $results) { |
|
145
|
|
|
return JsonResponse::create(['overall' => $this->healthInfo[$this->state][0], 'results' => $results], $this->responseCode); |
|
|
|
|
|
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @return \SimpleSAML\XHTML\Template |
|
151
|
|
|
*/ |
|
152
|
|
|
private function processText() { |
|
153
|
|
|
$t = new \SimpleSAML\XHTML\Template($this->config, 'monitor:monitor.text.php'); |
|
154
|
|
|
|
|
155
|
|
|
if ($this->state === State::OK) { |
|
156
|
|
|
$t->data['status'] = 'OK'; |
|
157
|
|
|
} else if ($this->state === State::WARNING) { |
|
158
|
|
|
$t->data['status'] = 'WARN'; |
|
159
|
|
|
} else { |
|
160
|
|
|
$t->data['status'] = 'FAIL'; |
|
161
|
|
|
} |
|
162
|
|
|
return $t; |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths