-
Notifications
You must be signed in to change notification settings - Fork 142
/
AppNodeUpdateCerts.php
53 lines (40 loc) · 1.42 KB
/
AppNodeUpdateCerts.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
42
43
44
45
46
47
48
49
50
51
52
53
<?php
// Sync Let's Encrypt SSL certificates with AppNode sitemgr database. (AppNode ONLY!)
// Check Medoo.php and PHP privileges before running
require_once('Medoo.php');
use Medoo\Medoo;
$sitecode = array('sitecode1', 'sitecode2'); // 'site_code' in sitemgr.db (网站代号)
$certpath = '/data/ssl';
$dbpath = '/opt/appnode/agent/apps/sitemgr/db/sitemgr.db';
$certname = array('*.example.com', 'example.com'); // folder name in Let's Encrypt home directory
$enable_nginx_cert_replace = true;
$ngxcertdir = array('/path/to/cert', '/path/to/cert'); // nginx cert path
$db = new Medoo([
'type' => 'sqlite',
'database' => $dbpath
]);
$size = count($sitecode);
for ($i=0;$i<$size;$i++)
{
$data = $db -> get("site",[
"setting"
],[
"site_code" => $sitecode[$i]
]);
$data = json_decode($data["setting"]);
$newkey = file_get_contents("$certpath/$certname[$i]/$certname[$i].key");
$newcert = file_get_contents("$certpath/$certname[$i]/fullchain.cer");
$data -> SSLKeyPemCode = $newkey;
$data -> SSLCertPemCode = $newcert;
$data = json_encode($data);
$data = $db -> update("site",[
"setting" => $data
],[
"site_code" => $sitecode[$i]
]);
if ($enable_nginx_cert_replace && $ngxcertdir[$i] != '') {
file_put_contents("$ngxcertdir[$i]/site.key", $newkey);
file_put_contents("$ngxcertdir[$i]/site.crt", $newcert);
}
}
echo 'Done!';