public function issueNewCertificate($cn, array $san, $reuseCSR = false)
{
$cn = trim($cn);
$san[] = $cn;
$san = array_unique($san);
$san = array_map(function ($domain) {
return trim(mb_strtolower($domain));
}, $san);
foreach ($san as $key => $domain) {
if (empty($domain)) {
unset($san['key']);
continue;
}
if (!$this->validateDomain($domain)) {
throw new \RuntimeException("Domain name \"{$domain}\" is not valid");
}
}
@mkdir("/data/{$cn}");
$path = "/data/{$cn}/domains";
@file_put_contents($path, join("\n", $san));
if (!@is_file($path)) {
throw new \RuntimeException("Can't create file at path {$path}");
}
// TODO: rewrite, good enough for now
exec('/usr/bin/php ' . __DIR__ . "/../bin/cli.php issue:new --domain {$cn} " . ($reuseCSR ? '--reuse-csr' : '') . " > /dev/null 2>&1 &");
}