re-adding the different certificate sources for domains in overview

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-05-20 15:41:06 +02:00
parent fef416ce84
commit f6c265dfa1
8 changed files with 116 additions and 25 deletions

View File

@@ -94,6 +94,7 @@ class Domains extends ApiCommand implements ResourceEntity
if ($with_ips) { if ($with_ips) {
$row['ipsandports'] = $this->getIpsForDomain($row['id']); $row['ipsandports'] = $this->getIpsForDomain($row['id']);
} }
$row['domain_hascert'] = $this->getHasCertValueForDomain((int)$row['id'], (int)$row['parentdomainid']);
$result[] = $row; $result[] = $row;
} }
return $this->response([ return $this->response([
@@ -882,6 +883,7 @@ class Domains extends ApiCommand implements ResourceEntity
if ($with_ips) { if ($with_ips) {
$result['ipsandports'] = $this->getIpsForDomain($result['id']); $result['ipsandports'] = $this->getIpsForDomain($result['id']);
} }
$result['domain_hascert'] = $this->getHasCertValueForDomain((int)$result['id'], (int)$result['parentdomainid']);
$this->logger()->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "[API] get domain '" . $result['domain'] . "'"); $this->logger()->logAction(FroxlorLogger::ADM_ACTION, LOG_NOTICE, "[API] get domain '" . $result['domain'] . "'");
return $this->response($result); return $this->response($result);
} }
@@ -891,6 +893,35 @@ class Domains extends ApiCommand implements ResourceEntity
throw new Exception("Not allowed to execute given command.", 403); throw new Exception("Not allowed to execute given command.", 403);
} }
private function getHasCertValueForDomain(int $domainid, int $parentdomainid): int
{
// nothing (ssl_global)
$domain_hascert = 0;
$ssl_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_DOMAIN_SSL_SETTINGS . "` WHERE `domainid` = :domainid");
Database::pexecute($ssl_stmt, array(
"domainid" => $domainid
));
$ssl_result = $ssl_stmt->fetch(PDO::FETCH_ASSOC);
if (is_array($ssl_result) && isset($ssl_result['ssl_cert_file']) && $ssl_result['ssl_cert_file'] != '') {
// own certificate (ssl_customer_green)
$domain_hascert = 1;
} else {
// check if it's parent has one set (shared)
if ($parentdomainid != 0) {
$ssl_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_DOMAIN_SSL_SETTINGS . "` WHERE `domainid` = :domainid");
Database::pexecute($ssl_stmt, array(
"domainid" => $parentdomainid
));
$ssl_result = $ssl_stmt->fetch(PDO::FETCH_ASSOC);
if (is_array($ssl_result) && isset($ssl_result['ssl_cert_file']) && $ssl_result['ssl_cert_file'] != '') {
// parent has a certificate (ssl_shared)
$domain_hascert = 2;
}
}
}
return $domain_hascert;
}
/** /**
* validate given ips * validate given ips
* *

View File

@@ -478,6 +478,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
} }
$result = Database::pexecute_first($result_stmt, $params, true, true); $result = Database::pexecute_first($result_stmt, $params, true, true);
if ($result) { if ($result) {
$result['domain_hascert'] = $this->getHasCertValueForDomain((int)$result['id'], (int)$result['parentdomainid']);
$this->logger()->logAction($this->isAdmin() ? FroxlorLogger::ADM_ACTION : FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] get subdomain '" . $result['domain'] . "'"); $this->logger()->logAction($this->isAdmin() ? FroxlorLogger::ADM_ACTION : FroxlorLogger::USR_ACTION, LOG_NOTICE, "[API] get subdomain '" . $result['domain'] . "'");
return $this->response($result); return $this->response($result);
} }
@@ -485,6 +486,35 @@ class SubDomains extends ApiCommand implements ResourceEntity
throw new Exception("Subdomain with " . $key . " could not be found", 404); throw new Exception("Subdomain with " . $key . " could not be found", 404);
} }
private function getHasCertValueForDomain(int $domainid, int $parentdomainid): int
{
// nothing (ssl_global)
$domain_hascert = 0;
$ssl_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_DOMAIN_SSL_SETTINGS . "` WHERE `domainid` = :domainid");
Database::pexecute($ssl_stmt, array(
"domainid" => $domainid
));
$ssl_result = $ssl_stmt->fetch(PDO::FETCH_ASSOC);
if (is_array($ssl_result) && isset($ssl_result['ssl_cert_file']) && $ssl_result['ssl_cert_file'] != '') {
// own certificate (ssl_customer_green)
$domain_hascert = 1;
} else {
// check if it's parent has one set (shared)
if ($parentdomainid != 0) {
$ssl_stmt = Database::prepare("SELECT * FROM `" . TABLE_PANEL_DOMAIN_SSL_SETTINGS . "` WHERE `domainid` = :domainid");
Database::pexecute($ssl_stmt, array(
"domainid" => $parentdomainid
));
$ssl_result = $ssl_stmt->fetch(PDO::FETCH_ASSOC);
if (is_array($ssl_result) && isset($ssl_result['ssl_cert_file']) && $ssl_result['ssl_cert_file'] != '') {
// parent has a certificate (ssl_shared)
$domain_hascert = 2;
}
}
}
return $domain_hascert;
}
/** /**
* validate given path and replace with url if given and valid * validate given path and replace with url if given and valid
* *
@@ -922,6 +952,7 @@ class SubDomains extends ApiCommand implements ResourceEntity
$result = []; $result = [];
Database::pexecute($domains_stmt, $query_fields, true, true); Database::pexecute($domains_stmt, $query_fields, true, true);
while ($row = $domains_stmt->fetch(PDO::FETCH_ASSOC)) { while ($row = $domains_stmt->fetch(PDO::FETCH_ASSOC)) {
$row['domain_hascert'] = $this->getHasCertValueForDomain((int)$row['id'], (int)$row['parentdomainid']);
$result[] = $row; $result[] = $row;
} }
return $this->response([ return $this->response([

View File

@@ -37,12 +37,12 @@ class Domain
$linker = UI::getLinker(); $linker = UI::getLinker();
$result = '<a href="https://' . $attributes['data'] . '" target="_blank">' . $attributes['data'] . '</a>'; $result = '<a href="https://' . $attributes['data'] . '" target="_blank">' . $attributes['data'] . '</a>';
$result .= ' (<a href="' . $linker->getLink([ $result .= ' (<a href="' . $linker->getLink([
'section' => 'customers', 'section' => 'customers',
'page' => 'customers', 'page' => 'customers',
'action' => 'su', 'action' => 'su',
'sort' => $attributes['fields']['loginname'], 'sort' => $attributes['fields']['loginname'],
'id' => $attributes['fields']['customerid'], 'id' => $attributes['fields']['customerid'],
]) . '">' . $attributes['fields']['loginname'] . '</a>)'; ]) . '">' . $attributes['fields']['loginname'] . '</a>)';
return $result; return $result;
} }
@@ -143,7 +143,8 @@ class Domain
public static function canEditSSL(array $attributes): bool public static function canEditSSL(array $attributes): bool
{ {
if (Settings::Get('system.use_ssl') == '1' if (
Settings::Get('system.use_ssl') == '1'
&& DDomain::domainHasSslIpPort($attributes['fields']['id']) && DDomain::domainHasSslIpPort($attributes['fields']['id'])
&& (int)$attributes['fields']['caneditdomain'] == 1 && (int)$attributes['fields']['caneditdomain'] == 1
&& (int)$attributes['fields']['letsencrypt'] == 0 && (int)$attributes['fields']['letsencrypt'] == 0
@@ -163,4 +164,37 @@ class Domain
{ {
return ($attributes['fields']['parentdomainid'] == 0 && empty($attributes['fields']['domainaliasid'])); return ($attributes['fields']['parentdomainid'] == 0 && empty($attributes['fields']['domainaliasid']));
} }
public static function editSSLButtons(array $attributes): array
{
$result = [
'icon' => 'fa fa-shield',
'title' => lng('panel.ssleditor'),
'href' => [
'section' => 'domains',
'page' => 'domainssleditor',
'action' => 'view',
'id' => ':id'
],
];
// specified certificate for domain
if ($attributes['fields']['domain_hascert'] == 1) {
$result['icon'] .= ' text-success';
}
// shared certificates (e.g. subdomain if domain where certificate is specified)
elseif ($attributes['fields']['domain_hascert'] == 2) {
$result['icon'] .= ' text-warning';
$result['title'] .= "\n".lng('panel.ssleditor_infoshared');
}
// no certificate specified, using global fallbacks (IPs and Ports or if empty SSL settings)
elseif ($attributes['fields']['domain_hascert'] == 0) {
$result['icon'] .= ' text-danger';
$result['title'] .= "\n".lng('panel.ssleditor_infoglobal');
}
$result['visible'] = [Domain::class, 'canEditSSL'];
return $result;
}
} }

View File

@@ -160,6 +160,13 @@ class Listing
// Check each action for a href // Check each action for a href
foreach ($actions as $key => $action) { foreach ($actions as $key => $action) {
// complete link built via callback
if (isset($action['callback']) && !empty($action['callback'])) {
$action = call_user_func($action['callback'], ['fields' => $item]);
$actions[$key] = $action;
}
// Call user function if visible is an array // Call user function if visible is an array
if (isset($action['visible']) && is_array($action['visible'])) { if (isset($action['visible']) && is_array($action['visible'])) {
$actions[$key]['visible'] = call_user_func($action['visible'], ['fields' => $item]); $actions[$key]['visible'] = call_user_func($action['visible'], ['fields' => $item]);

View File

@@ -172,15 +172,7 @@ return [
'visible' => [Domain::class, 'adminCanEditDNS'] 'visible' => [Domain::class, 'adminCanEditDNS']
], ],
'domainssleditor' => [ 'domainssleditor' => [
'icon' => 'fa fa-shield', 'callback' => [Domain::class, 'editSSLButtons'],
'title' => lng('panel.ssleditor'), // @todo different certificate types by $row['domain_hascert']
'href' => [
'section' => 'domains',
'page' => 'domainssleditor',
'action' => 'view',
'id' => ':id'
],
'visible' => [Domain::class, 'canEditSSL']
], ],
'letsencrypt' => [ 'letsencrypt' => [
'icon' => 'fa fa-shield', 'icon' => 'fa fa-shield',

View File

@@ -111,15 +111,7 @@ return [
'visible' => [Domain::class, 'canEditDNS'] 'visible' => [Domain::class, 'canEditDNS']
], ],
'domainssleditor' => [ 'domainssleditor' => [
'icon' => 'fa fa-shield', 'callback' => [Domain::class, 'editSSLButtons'],
'title' => lng('panel.ssleditor'), // @todo different certificate types by $row['domain_hascert']
'href' => [
'section' => 'domains',
'page' => 'domainssleditor',
'action' => 'view',
'id' => ':id'
],
'visible' => [Domain::class, 'canEditSSL']
], ],
'letsencrypt' => [ 'letsencrypt' => [
'icon' => 'fa fa-shield', 'icon' => 'fa fa-shield',

View File

@@ -1132,6 +1132,8 @@ Vielen Dank, Ihr Administrator',
'variable' => 'Variable', 'variable' => 'Variable',
'description' => 'Beschreibung', 'description' => 'Beschreibung',
'ssleditor' => 'SSL-Einstellungen für diese Domain', 'ssleditor' => 'SSL-Einstellungen für diese Domain',
'ssleditor_infoshared' => 'Aktuell Zertifikat der Elterndomain genutzt',
'ssleditor_infoglobal' => 'Aktuell globales Zertifikat genutzt',
'dashboard' => 'Dashboard', 'dashboard' => 'Dashboard',
'assigned' => 'zugewiesen', 'assigned' => 'zugewiesen',
'available' => 'verfügbar', 'available' => 'verfügbar',

View File

@@ -1495,6 +1495,8 @@ Yours sincerely, your administrator',
'description' => 'Description', 'description' => 'Description',
'cancel' => 'Cancel', 'cancel' => 'Cancel',
'ssleditor' => 'SSL settings for this domain', 'ssleditor' => 'SSL settings for this domain',
'ssleditor_infoshared' => 'Currently using certificate of parentdomain',
'ssleditor_infoglobal' => 'Currently using global certificate',
'dashboard' => 'Dashboard', 'dashboard' => 'Dashboard',
'assigned' => 'Assigned', 'assigned' => 'Assigned',
'available' => 'Available', 'available' => 'Available',