summaryrefslogtreecommitdiffstats
path: root/library/X509/ChainDetails.php
blob: 722b7b3b5b5d0c3abb0a4f27a980c326638d5bc9 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php

// Icinga Web 2 X.509 Module | (c) 2018 Icinga GmbH | GPLv2

namespace Icinga\Module\X509;

use Icinga\Module\X509\Model\X509Certificate;
use Icinga\Web\Url;
use ipl\Html\Html;
use ipl\Web\Widget\IcingaIcon;
use ipl\Web\Widget\Icon;

/**
 * Table widget to display X.509 chain details
 */
class ChainDetails extends DataTable
{
    protected $defaultAttributes = [
        'class' => 'cert-table common-table table-row-selectable',
        'data-base-target' => '_next'
    ];

    public function createColumns()
    {
        return [
            [
                'attributes' => ['class' => 'icon-col'],
                'renderer' => function () {
                    return new IcingaIcon('certificate', ['title' => mt('x509', 'Is a x509 certificate')]);
                }
            ],

            'version' => [
                'attributes' => ['class' => 'version-col'],
                'renderer' => function ($version) {
                    return Html::tag('div', ['class' => 'badge'], $version);
                }
            ],

            'subject' => [
                'label' => mt('x509', 'Subject', 'x509.certificate')
            ],

            'ca' => [
                'attributes' => ['class' => 'icon-col'],
                'renderer' => function ($ca) {
                    if (! $ca) {
                        return null;
                    }

                    return new IcingaIcon('ca-check-circle', ['title' => mt('x509', 'Is Certificate Authority')]);
                }
            ],

            'self_signed' => [
                'attributes' => ['class' => 'icon-col'],
                'renderer' => function ($selfSigned) {
                    if (! $selfSigned) {
                        return null;
                    }

                    return new IcingaIcon('refresh-cert', ['title' => mt('x509', 'Is Self-Signed')]);
                }
            ],

            'trusted' => [
                'attributes' => ['class' => 'icon-col'],
                'renderer' => function ($trusted) {
                    if (! $trusted) {
                        return null;
                    }

                    return new Icon('thumbs-up', ['title' => mt('x509', 'Is Trusted')]);
                }
            ],

            'signature_algo' => [
                'label' => mt('x509', 'Signature Algorithm'),
                'renderer' => function ($algo, $data) {
                    return "{$data->signature_hash_algo} with $algo";
                }
            ],

            'pubkey_algo' => [
                'label' => mt('x509', 'Public Key'),
                'renderer' => function ($algo, $data) {
                    return "$algo {$data->pubkey_bits} bits";
                }
            ],

            'valid_to' => [
                'attributes' => ['class' => 'expiration-col'],
                'label' => mt('x509', 'Expiration'),
                'renderer' => function ($to, $data) {
                    return new ExpirationWidget($data->valid_from, $to);
                }
            ]
        ];
    }

    protected function renderRow(X509Certificate $row)
    {
        $tr = parent::renderRow($row);

        $url = Url::fromPath('x509/certificate', ['cert' => $row->id]);

        $tr->getAttributes()->add(['href' => $url->getAbsoluteUrl()]);

        return $tr;
    }
}