summaryrefslogtreecommitdiffstats
path: root/application/controllers/CertificateController.php
blob: 414d1f3cf8d8852ac6a7abdee3b7bef7b6ef9222 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
// Icinga Web 2 X.509 Module | (c) 2018 Icinga GmbH | GPLv2

namespace Icinga\Module\X509\Controllers;

use Icinga\Exception\ConfigurationError;
use Icinga\Module\X509\CertificateDetails;
use Icinga\Module\X509\Controller;
use ipl\Sql;

class CertificateController extends Controller
{
    public function indexAction()
    {
        $certId = $this->params->getRequired('cert');

        try {
            $conn = $this->getDb();
        } catch (ConfigurationError $_) {
            $this->render('missing-resource', null, true);
            return;
        }

        $cert = $conn->select(
            (new Sql\Select())
                ->from('x509_certificate')
                ->columns('*')
                ->where(['id = ?' => $certId])
        )->fetch();

        if ($cert === false) {
            $this->httpNotFound($this->translate('Certificate not found.'));
        }

        $this->setTitle($this->translate('X.509 Certificate'));

        $this->view->certificateDetails = (new CertificateDetails())
            ->setCert($cert);
    }
}