|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'autoload.php'; //Path to composer autoload |
|
4
|
|
|
|
|
5
|
|
|
$dnsWriter = new class extends \LE_ACME2\Authorizer\AbstractDNSWriter { |
|
6
|
|
|
|
|
7
|
|
|
public function write(\LE_ACME2\Order $order, string $identifier, string $digest): bool { |
|
8
|
|
|
|
|
9
|
|
|
$status = false; |
|
10
|
|
|
|
|
11
|
|
|
// Write digest to DNS system |
|
12
|
|
|
|
|
13
|
|
|
// return true, if the dns configuration is usable and the process should be progressed |
|
14
|
|
|
return $status; |
|
15
|
|
|
} |
|
16
|
|
|
}; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
// Config the desired paths |
|
20
|
|
|
\LE_ACME2\Account::setCommonKeyDirectoryPath('/etc/ssl/le-storage/'); |
|
21
|
|
|
\LE_ACME2\Authorizer\DNS::setWriter($dnsWriter); |
|
22
|
|
|
|
|
23
|
|
|
// General configs |
|
24
|
|
|
\LE_ACME2\Connector\Connector::getInstance()->useStagingServer(true); |
|
25
|
|
|
\LE_ACME2\Utilities\Logger::getInstance()->setDesiredLevel(\LE_ACME2\Utilities\Logger::LEVEL_INFO); |
|
26
|
|
|
|
|
27
|
|
|
// Optional configs |
|
28
|
|
|
//\LE_ACME2\Utilities\Certificate::enableFeatureOCSPMustStaple(); |
|
29
|
|
|
//\LE_ACME2\Order::setPreferredChain(\LE_ACME2\Order::IDENTRUST_ISSUER_CN); |
|
30
|
|
|
//\LE_ACME2\Utilities\Event::getInstance()->subscribe( |
|
31
|
|
|
// \LE_ACME2\Utilities\Event::EVENT_CONNECTOR_WILL_REQUEST, |
|
32
|
|
|
// function(string $event, array $payload = null) { |
|
33
|
|
|
// // Do something, f.e. force to save the logs |
|
34
|
|
|
// } |
|
35
|
|
|
//); |
|
36
|
|
|
|
|
37
|
|
|
$account_email = '[email protected]'; |
|
38
|
|
|
|
|
39
|
|
|
$account = !\LE_ACME2\Account::exists($account_email) ? |
|
40
|
|
|
\LE_ACME2\Account::create($account_email) : |
|
41
|
|
|
\LE_ACME2\Account::get($account_email); |
|
42
|
|
|
|
|
43
|
|
|
// Update email address |
|
44
|
|
|
// $account->update('[email protected]'); |
|
45
|
|
|
|
|
46
|
|
|
// Deactivate account |
|
47
|
|
|
// Warning: It seems not possible to reactivate an account. |
|
48
|
|
|
// $account->deactivate(); |
|
49
|
|
|
|
|
50
|
|
|
$subjects = [ |
|
51
|
|
|
'example.org', // First item will be set as common name on the certificate |
|
52
|
|
|
'www.example.org' |
|
53
|
|
|
]; |
|
54
|
|
|
|
|
55
|
|
|
if(!\LE_ACME2\Order::exists($account, $subjects)) { |
|
56
|
|
|
|
|
57
|
|
|
// Do some pre-checks, f.e. external dns checks - not required |
|
58
|
|
|
|
|
59
|
|
|
$order = \LE_ACME2\Order::create($account, $subjects); |
|
60
|
|
|
} else { |
|
61
|
|
|
$order = \LE_ACME2\Order::get($account, $subjects); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
// Clear current order (in case to restart on status "invalid") |
|
65
|
|
|
// Already received certificate bundles will not be affected |
|
66
|
|
|
// $order->clear(); |
|
67
|
|
|
|
|
68
|
|
|
if($order->shouldStartAuthorization(\LE_ACME2\Order::CHALLENGE_TYPE_DNS)) { |
|
69
|
|
|
// Do some pre-checks, f.e. external dns checks - not required |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
if($order->authorize(\LE_ACME2\Order::CHALLENGE_TYPE_DNS)) { |
|
73
|
|
|
$order->finalize(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
if($order->isCertificateBundleAvailable()) { |
|
77
|
|
|
|
|
78
|
|
|
$bundle = $order->getCertificateBundle(); |
|
79
|
|
|
$order->enableAutoRenewal(); |
|
80
|
|
|
|
|
81
|
|
|
// Revoke certificate |
|
82
|
|
|
// $order->revokeCertificate($reason = 0); |
|
83
|
|
|
} |