DirectAdmin\LetsEncrypt\Lib\Domain::requestCertificate PHP Method

requestCertificate() public method

Request certificate at ACME
public requestCertificate ( KeyPair | null $domainKeys = null, array | null $subdomains = null ) : array
$domainKeys Kelunik\Acme\KeyPair | null
$subdomains array | null List of subdomains to request
return array
    public function requestCertificate($domainKeys = null, $subdomains = null)
    {
        if ($domainKeys == null) {
            if ($this->domainKeys == null) {
                $this->createKeys();
            } else {
                $domainKeys = $this->domainKeys;
            }
        }
        $domains = (array) $this->getDomain();
        if ($subdomains == null) {
            $domains = array_merge($domains, $this->getSubdomains());
        } else {
            $domains = array_merge($domains, $subdomains);
        }
        try {
            $location = \amp\wait($this->account->acme->requestCertificate($domainKeys, $domains));
            $this->certificates = \amp\wait($this->account->acme->pollForCertificate($location));
        } catch (\Exception $e) {
            throw new \Exception("Error requesting certificate: " . $e->getMessage(), 0, $e);
        }
        return $this->certificates;
    }

Usage Example

Example #1
0
        if (!$domain->existsInStorage('config.json')) {
            $log->log('Skipped domain ' . $domain->getDomain());
            continue;
        }
        $log->log('Processing domain ' . $domain->getDomain());
        // Check if a renew is required, if everything needs to be checked within 10 days or in the past
        if (strtotime($domain->config('expire')) - time() >= 10 * 86400) {
            $log->log('Domain ' . $domain->getDomain() . ' doesn\'t need a reissue');
            continue;
        }
        try {
            $challenges = new Challenges($domain);
            $challenges->solveChallenge();
            $log->log('Successfully completed challenge for ' . $domain->getDomain());
            $domain->createKeys();
            $domain->requestCertificate(null, $domain->config('subdomains'));
            $log->log('Successfully received certificate from Let\'s Encrypt');
            $domain->applyCertificates();
            $log->log('Successfully applied certificate and CA certificates to DirectAdmin');
            $domain->config('domain', $domain->getDomain());
            $domain->config('subdomains', $domain->getSubdomains());
            $domain->config('status', 'applied to DirectAdmin (renewed)');
            $domain->config('expire', date('Y-m-d', strtotime('+50 days')));
            $log->log('Reissued domain ' . $domain->getDomain() . ' with success.');
        } catch (\Exception $e) {
            $log->error($e->getMessage(), null, false);
        }
    }
}
// Rewrite and restart HTTPD files
$queue = 'action=rewrite&value=httpd' . PHP_EOL;