added ssl-certificate overview for admins and customers to show CN, Issuer, ValidFrom and ValidTo dates

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p) 2016-09-26 11:48:36 +02:00
parent 79b839c024
commit ed0ede645a
9 changed files with 253 additions and 0 deletions

View File

@ -2099,6 +2099,11 @@ if ($page == 'domains' || $page == 'overview') {
} elseif ($page == 'domaindnseditor' && Settings::Get('system.dnsenabled') == '1') {
require_once __DIR__.'/dns_editor.php';
} elseif ($page == 'sslcertificates') {
require_once __DIR__.'/ssl_certificates.php';
}
function formatDomainEntry(&$row, &$idna_convert)

View File

@ -935,4 +935,9 @@ if ($page == 'overview') {
} elseif ($page == 'domaindnseditor' && $userinfo['dnsenabled'] == '1' && Settings::Get('system.dnsenabled') == '1') {
require_once __DIR__.'/dns_editor.php';
} elseif ($page == 'sslcertificates') {
require_once __DIR__.'/ssl_certificates.php';
}

View File

@ -95,6 +95,10 @@ return array(
array(
'url' => 'customer_domains.php?page=domains',
'label' => $lng['menue']['domains']['settings']
),
array(
'url' => 'customer_domains.php?page=sslcertificates',
'label' => $lng['domains']['ssl_certificates']
)
)
),
@ -200,6 +204,11 @@ return array(
'label' => $lng['admin']['domains'],
'required_resources' => 'domains'
),
array(
'url' => 'admin_domains.php?page=sslcertificates',
'label' => $lng['domains']['ssl_certificates'],
'required_resources' => 'domains'
),
array(
'url' => 'admin_ipsandports.php?page=ipsandports',
'label' => $lng['admin']['ipsandports']['ipsandports'],

View File

@ -2051,3 +2051,7 @@ $lng['serversettings']['mail_smtp_auth'] = 'Enable SMTP authentication';
$lng['serversettings']['mail_smtp_port'] = 'TCP port to connect to';
$lng['serversettings']['mail_smtp_user'] = 'SMTP username';
$lng['serversettings']['mail_smtp_passwd'] = 'SMTP password';
$lng['domains']['ssl_certificates'] = 'SSL certificates';
$lng['domains']['ssl_certificate_removed'] = 'The certificate with the id #%s has been removed successfully';
$lng['domains']['ssl_certificate_error'] = "Error reading certificate for domain: %s";
$lng['domains']['no_ssl_certificates'] = "There are no domains with SSL certificate";

View File

@ -1702,3 +1702,7 @@ $lng['serversettings']['mail_smtp_auth'] = 'Nutze SMTP Authentifizierung';
$lng['serversettings']['mail_smtp_port'] = 'TCP Port für SMTP';
$lng['serversettings']['mail_smtp_user'] = 'SMTP Benutzer';
$lng['serversettings']['mail_smtp_passwd'] = 'SMTP Passwort';
$lng['domains']['ssl_certificates'] = 'SSL Zertifikate';
$lng['domains']['ssl_certificate_removed'] = 'Das Zertifikat mit der ID #%s wurde erfolgreich gelöscht.';
$lng['domains']['ssl_certificate_error'] = "Fehler beim Lesen des Zertifikats für die Domain: %s";
$lng['domains']['no_ssl_certificates'] = "Es wurden keine SSL-Zertifikate gefunden";

133
ssl_certificates.php Normal file
View File

@ -0,0 +1,133 @@
<?php
if (! defined('AREA'))
die('You cannot access this file directly!');
/**
* This file is part of the Froxlor project.
* Copyright (c) 2016 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Froxlor team <team@froxlor.org> (2016-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Panel
*
*/
// This file is being included in admin_domains and customer_domains
// and therefore does not need to require lib/init.php
$del_stmt = Database::prepare("DELETE FROM `" . TABLE_PANEL_DOMAIN_SSL_SETTINGS . "` WHERE id = :id");
$success_message = "";
// do the delete and then just showa success-message and the certificates list again
if ($action == 'delete') {
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
if ($id > 0) {
Database::pexecute($del_stmt, array(
'id' => $id
));
$success_message = sprintf($lng['domains']['ssl_certificate_removed'], $id);
}
}
$log->logAction(USR_ACTION, LOG_NOTICE, "viewed domains::ssl_certificates");
$fields = array(
'd.domain' => $lng['domains']['domainname']
);
$paging = new paging($userinfo, TABLE_PANEL_DOMAIN_SSL_SETTINGS, $fields);
// select all my (accessable) certificates
$certs_stmt_query = "SELECT s.*, d.domain, d.letsencrypt, c.customerid, c.loginname
FROM `" . TABLE_PANEL_DOMAIN_SSL_SETTINGS . "` s
LEFT JOIN `" . TABLE_PANEL_DOMAINS . "` d ON `d`.`id` = `s`.`domainid`
LEFT JOIN `" . TABLE_PANEL_CUSTOMERS . "` c ON `c`.`customerid` = `d`.`customerid`
WHERE ";
$qry_params = array();
if (AREA == 'admin' && $userinfo['customers_see_all'] == '0') {
// admin with only customer-specific permissions
$certs_stmt_query .= "d.adminid = :adminid ";
$qry_params['adminid'] = $userinfo['adminid'];
} elseif (AREA == 'customer') {
// customer-area
$certs_stmt_query .= "d.customerid = :cid ";
$qry_params['cid'] = $userinfo['customerid'];
} else {
$certs_stmt_query .= "1 ";
}
// sorting by domain-name
$certs_stmt_query .= $paging->getSqlWhere(true) . " " . $paging->getSqlOrderBy() . " " . $paging->getSqlLimit();
$certs_stmt = Database::prepare($certs_stmt_query);
Database::pexecute($certs_stmt, $qry_params);
$all_certs = $certs_stmt->fetchAll(PDO::FETCH_ASSOC);
$certificates = "";
if (count($all_certs) == 0) {
$message = $lng['domains']['no_ssl_certificates'];
$sortcode = "";
$arrowcode = array('d.domain' => '');
$searchcode = "";
$pagingcode = "";
eval("\$certificates.=\"" . getTemplate("ssl_certificates/certs_error", true) . "\";");
} else {
$paging->setEntries(count($all_certs));
$sortcode = $paging->getHtmlSortCode($lng);
$arrowcode = $paging->getHtmlArrowCode($filename . '?page=' . $page . '&s=' . $s);
$searchcode = $paging->getHtmlSearchCode($lng);
$pagingcode = $paging->getHtmlPagingCode($filename . '?page=' . $page . '&s=' . $s);
foreach ($all_certs as $idx => $cert) {
if ($paging->checkDisplay($idx)) {
if (empty($cert['domain']) || empty($cert['ssl_cert_file'])) {
// no domain found to the entry or empty entry - safely delete it from the DB
Database::pexecute($del_stmt, array(
'id' => $cert['id']
));
continue;
}
$cert_data = openssl_x509_parse($cert['ssl_cert_file']);
$cert['domain'] = $idna_convert->encode($cert['domain']);
$adminCustomerLink = "";
if (AREA == 'admin') {
if (! empty($cert['loginname'])) {
$adminCustomerLink = '&nbsp;(<a href="' . $linker->getLink(array(
'section' => 'customers',
'page' => 'customers',
'action' => 'su',
'id' => $cert['customerid']
)) . '" rel="external">' . $cert['loginname'] . '</a>)';
}
}
if ($cert_data) {
$validFrom = date('d.m.Y H:i:s', $cert_data['validFrom_time_t']);
$validTo = date('d.m.Y H:i:s', $cert_data['validTo_time_t']);
$isValid = true;
if ($cert_data['validTo_time_t'] < time()) {
$isValid = false;
}
$row = htmlentities_array($cert);
eval("\$certificates.=\"" . getTemplate("ssl_certificates/certs_cert", true) . "\";");
} else {
$message = sprintf($lng['domains']['ssl_certificate_error'], $cert['domain']);
eval("\$certificates.=\"" . getTemplate("ssl_certificates/certs_error", true) . "\";");
}
} else {
continue;
}
}
}
eval("echo \"" . getTemplate("ssl_certificates/certs_list", true) . "\";");

View File

@ -0,0 +1,33 @@
<tr <if !$isValid>class="domain-expired"</if>>
<td>
<a href="http://{$row['domain']}" target="_blank">{$row['domain']}</a>
{$adminCustomerLink}
</td>
<td>
{$cert_data['subject']['CN']}
</td>
<td>
{$cert_data['issuer']['O']}
</td>
<td>
{$validFrom}
</td>
<td>
<if !$isValid><strong><span class="red"></if>
{$validTo}
<if !$isValid></span></strong></if>
</td>
<td>
<if $row['letsencrypt'] != 1 && AREA == 'customer'>
<a href="{$linker->getLink(array('section' => 'domains', 'page' => 'domainssleditor', 'action' => 'view', 'id' => $row['domainid']))}">
<img src="templates/{$theme}/assets/img/icons/edit.png" alt="{$lng['panel']['edit']}" title="{$lng['panel']['edit']}" />
</a>&nbsp;
</if>
<if $row['letsencrypt'] == '1'>
<img src="templates/{$theme}/assets/img/icons/ssl_letsencrypt.png" alt="{$lng['panel']['letsencrypt']}" title="{$lng['panel']['letsencrypt']}" />
</if>
<a href="{$linker->getLink(array('section' => 'domains', 'page' => 'sslcertificates', 'action' => 'delete', 'id' => $row['id']))}">
<img src="templates/{$theme}/assets/img/icons/delete.png" alt="{$lng['panel']['delete']}" title="{$lng['panel']['delete']}" />
</a>
</td>
</tr>

View File

@ -0,0 +1,3 @@
<tr>
<td colspan="6"><span class="red">{$message}</span></td>
</tr>

View File

@ -0,0 +1,57 @@
$header
<article>
<header>
<h2>
<img src="templates/{$theme}/assets/img/icons/lock_big.png" alt="" />&nbsp;
{$lng['domains']['ssl_certificates']}
</h2>
</header>
<if !empty($success_message)>
<div class="successcontainer bradius">
<div class="successtitle">{$lng['success']['success']}</div>
<div class="success">
$success_message
</div>
</div>
</if>
<section>
<form action="{$linker->getLink(array('section' => 'domains', 'page' => 'sslcertificates'))}" method="post" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="s" value="$s" />
<input type="hidden" name="page" value="$page" />
<div class="overviewsearch">
{$searchcode}
</div>
<table class="full hl">
<thead>
<tr>
<th>{$lng['domains']['domainname']}&nbsp;{$arrowcode['d.domain']}</th>
<th>Certificate for</th>
<th>Issuer</th>
<th>Valid from</th>
<th>Valid until</th>
<th>{$lng['panel']['options']}</th>
</tr>
</thead>
<if $pagingcode != ''>
<tfoot>
<tr>
<td colspan="6">{$pagingcode}</td>
</tr>
</tfoot>
</if>
<tbody>
{$certificates}
</tbody>
</table>
</form>
</section>
</article>
$footer