Implement config/tls

refs #3016
This commit is contained in:
Alexander A. Klimov 2017-11-17 12:23:42 +01:00
parent 1e7483b6f2
commit 9adb516515
2 changed files with 158 additions and 0 deletions

View File

@ -5,6 +5,7 @@ namespace Icinga\Controllers;
use Exception;
use Icinga\Application\Version;
use Icinga\File\Storage\LocalFileStorage;
use InvalidArgumentException;
use Icinga\Application\Config;
use Icinga\Application\Icinga;
@ -52,6 +53,12 @@ class ConfigController extends Controller
'url' => 'config/userbackend',
'baseTarget' => '_main'
));
$tabs->add('tls', array(
'title' => $this->translate('Configure TLS root CA certificate collections and TLS client identities'),
'label' => $this->translate('TLS'),
'url' => 'config/tls',
'baseTarget' => '_main'
));
return $tabs;
}
@ -188,6 +195,38 @@ class ConfigController extends Controller
$this->render('userbackend/reorder');
}
/**
* Action for listing TLS root CA certificate collections and TLS client identities
*/
public function tlsAction()
{
$this->assertPermission('config/application/tlscert');
$this->createApplicationTabs()->activate('tls');
$rootCaCollections = array();
foreach (new LocalFileStorage(Icinga::app()->getStorageDir('framework/tls/rootcacollections')) as $ca) {
$matches = array();
if (preg_match('~\A([0-9a-f]{2}+)\.pem\z~i', $ca, $matches)) {
$rootCaCollections[hex2bin($matches[1])] = null;
}
}
ksort($rootCaCollections);
$this->view->rootCaCollections = array_keys($rootCaCollections);
$clientIdentities = array();
foreach (new LocalFileStorage(Icinga::app()->getStorageDir('framework/tls/clientidentities')) as $client) {
$matches = array();
if (preg_match('~\A([0-9a-f]{2}+)\.pem\z~i', $client, $matches)) {
$clientIdentities[hex2bin($matches[1])] = null;
}
}
ksort($clientIdentities);
$this->view->clientIdentities = array_keys($clientIdentities);
}
/**
* Create a new user backend
*/

View File

@ -0,0 +1,119 @@
<?php
/** @var \Icinga\Web\Widget\Tabs $tabs */
/** @var string[] $rootCaCollections */
/** @var string[] $clientIdentities */
?>
<div class="controls">
<?= $tabs ?>
</div>
<div class="content">
<h1><?= $this->translate('TLS Root CA Certificate Collections') ?></h1>
<?= $this->qlink(
$this->translate('Create A New TLS Root CA Certificate Collection') ,
'tlsrootcacollection/create',
null,
array(
'class' => 'button-link',
'data-base-target' => '_next',
'icon' => 'plus',
'title' => $this->translate('Create a new TLS root CA certificate collection')
)
) ?>
<?php if (! empty($rootCaCollections)): ?>
<table class="table-row-selectable common-table" data-base-target="_next">
<thead>
<tr>
<th><?= $this->translate('Certificate Collection Name') ?></th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($rootCaCollections as $name): ?>
<tr>
<td><?= $this->qlink(
$name,
'tlsrootcacollection/edit',
array('name' => $name),
array(
'title' => sprintf(
$this->translate('Edit TLS root CA certificate collection "%s"'),
$name
)
)
) ?></td>
<td class="icon-col text-right"><?= $this->qlink(
null,
'tlsrootcacollection/remove',
array('name' => $name),
array(
'class' => 'action-link',
'icon' => 'cancel',
'title' => sprintf(
$this->translate('Remove TLS root CA certificate collection "%s"'),
$name
)
)
) ?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<?php endif; ?>
<h1><?= $this->translate('TLS Client Identities') ?></h1>
<?= $this->qlink(
$this->translate('Create A New TLS Client Identity') ,
'tlsclientidentity/create',
null,
array(
'class' => 'button-link',
'data-base-target' => '_next',
'icon' => 'plus',
'title' => $this->translate('Create a new TLS client identity')
)
) ?>
<?php if (! empty($clientIdentities)): ?>
<table class="table-row-selectable common-table" data-base-target="_next">
<thead>
<tr>
<th><?= $this->translate('Client Identity Name') ?></th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($clientIdentities as $name): ?>
<tr>
<td><?= $this->qlink(
$name,
'tlsclientidentity/edit',
array('name' => $name),
array(
'title' => sprintf(
$this->translate('Edit TLS client identity "%s"'),
$name
)
)
) ?></td>
<td class="icon-col text-right"><?= $this->qlink(
null,
'tlsclientidentity/remove',
array('name' => $name),
array(
'class' => 'action-link',
'icon' => 'cancel',
'title' => sprintf(
$this->translate('Remove TLS client identity "%s"'),
$name
)
)
) ?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<?php endif; ?>
</div>