|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\Module\metarefresh\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use Exception; |
|
8
|
|
|
use SimpleSAML\Configuration; |
|
9
|
|
|
use SimpleSAML\Error; |
|
10
|
|
|
use SimpleSAML\Logger; |
|
11
|
|
|
use SimpleSAML\Utils; |
|
12
|
|
|
use SimpleSAML\XHTML\Template; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Controller class for the metarefresh module. |
|
16
|
|
|
* |
|
17
|
|
|
* This class serves the different views available in the module. |
|
18
|
|
|
* |
|
19
|
|
|
* @package SimpleSAML\Module\metarefresh |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
class MetaRefresh |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var \SimpleSAML\Configuration */ |
|
25
|
|
|
protected Configuration $module_config; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var \SimpleSAML\Utils\Auth |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $authUtils; |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Controller constructor. |
|
35
|
|
|
* |
|
36
|
|
|
* It initializes the global configuration and auth source configuration for the controllers implemented here. |
|
37
|
|
|
* |
|
38
|
|
|
* @param \SimpleSAML\Configuration $config The configuration to use by the controllers. |
|
39
|
|
|
* |
|
40
|
|
|
* @throws \Exception |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct( |
|
43
|
|
|
protected Configuration $config, |
|
44
|
|
|
) { |
|
45
|
|
|
$this->module_config = Configuration::getConfig('module_metarefresh.php'); |
|
46
|
|
|
$this->authUtils = new Utils\Auth(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Inject the \SimpleSAML\Utils\Auth dependency. |
|
52
|
|
|
* |
|
53
|
|
|
* @param \SimpleSAML\Utils\Auth $authUtils |
|
54
|
|
|
*/ |
|
55
|
|
|
public function setAuthUtils(Utils\Auth $authUtils): void |
|
56
|
|
|
{ |
|
57
|
|
|
$this->authUtils = $authUtils; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Inject the \SimpleSAML\Configuration dependency. |
|
63
|
|
|
* |
|
64
|
|
|
* @param \SimpleSAML\Configuration $module_config |
|
65
|
|
|
*/ |
|
66
|
|
|
public function setModuleConfig(Configuration $module_config): void |
|
67
|
|
|
{ |
|
68
|
|
|
$this->module_config = $module_config; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @return \SimpleSAML\XHTML\Template |
|
74
|
|
|
*/ |
|
75
|
|
|
public function main(): Template |
|
76
|
|
|
{ |
|
77
|
|
|
$this->authUtils->requireAdmin(); |
|
78
|
|
|
|
|
79
|
|
|
Logger::setCaptureLog(true); |
|
80
|
|
|
|
|
81
|
|
|
$mf = new \SimpleSAML\Module\metarefresh\MetaRefresh($this->config, $this->module_config); |
|
82
|
|
|
|
|
83
|
|
|
try { |
|
84
|
|
|
$mf->runRefresh(); |
|
85
|
|
|
} catch (Exception $e) { |
|
86
|
|
|
$e = Error\Exception::fromException($e); |
|
87
|
|
|
$e->logWarning(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
$logentries = Logger::getCapturedLog(); |
|
91
|
|
|
|
|
92
|
|
|
$t = new Template($this->config, 'metarefresh:fetch.twig'); |
|
93
|
|
|
$t->data['logentries'] = $logentries; |
|
94
|
|
|
return $t; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|