forked from yourivw/LEClient
-
Notifications
You must be signed in to change notification settings - Fork 6
/
exampleDNSFinish.php
41 lines (39 loc) · 1.9 KB
/
exampleDNSFinish.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
//Sets the maximum execution time to two minutes, to be sure.
ini_set('max_execution_time', 120);
// Including the LetsEncrypt Client.
require_once('LEClient/LEClient.php');
// Listing the contact information in case a new account has to be created.
$email = array('[email protected]');
// Defining the base name for this order
$basename = 'example.org';
// Listing the domains to be included on the certificate
$domains = array('example.org', 'test.example.org');
// Initiating the client instance. In this case using the staging server (argument 2) and outputting all status and debug information (argument 3).
$client = new LEClient($email, true, LECLient::LOG_STATUS);
// Initiating the order instance. The keys and certificate will be stored in /example.org/ (argument 1) and the domains in the array (argument 2) will be on the certificate.
$order = $client->getOrCreateOrder($basename, $domains);
// Check whether there are any authorizations pending. If that is the case, try to verify the pending authorizations.
if(!$order->allAuthorizationsValid())
{
// Get the DNS challenges from the pending authorizations.
$pending = $order->getPendingAuthorizations(LEOrder::CHALLENGE_TYPE_DNS);
// Walk the list of pending authorization DNS challenges.
if(!empty($pending))
{
foreach($pending as $challenge)
{
// Let LetsEncrypt verify this challenge, which should have been fulfilled in exampleDNSStart.php.
$order->verifyPendingOrderAuthorization($challenge['identifier'], LEOrder::CHALLENGE_TYPE_DNS);
}
}
}
// Check once more whether all authorizations are valid before we can finalize the order.
if($order->allAuthorizationsValid())
{
// Finalize the order first, if that is not yet done.
if(!$order->isFinalized()) $order->finalizeOrder();
// Check whether the order has been finalized before we can get the certificate. If finalized, get the certificate.
if($order->isFinalized()) $order->getCertificate();
}
?>