Skip to content

Commit df19dd8

Browse files
author
Till Brehm
committed
Merge branch 'stable-3.1' of git.ispconfig.org:ispconfig/ispconfig3 into stable-3.1
2 parents a5bd6a8 + a49635d commit df19dd8

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

server/plugins-available/apache2_plugin.inc.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,8 @@ function update($event_name, $data) {
485485

486486
if($this->action != 'insert') $this->action = 'update';
487487

488+
$update_letsencrypt = false;
489+
488490
if($data['new']['type'] != 'vhost' && $data['new']['type'] != 'vhostsubdomain' && $data['new']['type'] != 'vhostalias' && $data['new']['parent_domain_id'] > 0) {
489491

490492
$old_parent_domain_id = intval($data['old']['parent_domain_id']);
@@ -504,6 +506,7 @@ function update($event_name, $data) {
504506
$data['new'] = $tmp;
505507
$data['old'] = $tmp;
506508
$this->action = 'update';
509+
$update_letsencrypt = true;
507510
}
508511

509512
// load the server configuration options
@@ -1177,8 +1180,7 @@ function update($event_name, $data) {
11771180
($data['old']['ssl'] == 'n' || $data['old']['ssl_letsencrypt'] == 'n') // we have new let's encrypt configuration
11781181
|| ($data['old']['domain'] != $data['new']['domain']) // we have domain update
11791182
|| ($data['old']['subdomain'] != $data['new']['subdomain']) // we have new or update on "auto" subdomain
1180-
|| ($data['new']['type'] == 'subdomain') // we have new or update on subdomain
1181-
|| ($data['old']['type'] == 'alias' || $data['new']['type'] == 'alias') // we have new or update on aliasdomain
1183+
|| $update_letsencrypt == true
11821184
)) {
11831185
// default values
11841186
$temp_domains = array();
@@ -1230,13 +1232,14 @@ function update($event_name, $data) {
12301232
$webroot = $data['new']['document_root']."/web";
12311233

12321234
//* check if we have already a Let's Encrypt cert
1233-
if(!file_exists($crt_tmp_file) && !file_exists($key_tmp_file)) {
1235+
//if(!file_exists($crt_tmp_file) && !file_exists($key_tmp_file)) {
1236+
// we must not skip if cert exists, otherwise changed domains (alias or sub) won't make it to the cert
12341237
$app->log("Create Let's Encrypt SSL Cert for: $domain", LOGLEVEL_DEBUG);
12351238

12361239
$success = false;
12371240
$letsencrypt = array_shift( explode("\n", shell_exec('which letsencrypt certbot /root/.local/share/letsencrypt/bin/letsencrypt')) );
12381241
if(is_executable($letsencrypt)) {
1239-
$success = $this->_exec($letsencrypt . " certonly --text --agree-tos --authenticator webroot --server https://acme-v01.api.letsencrypt.org/directory --rsa-key-size 4096 --email postmaster@$domain --domains $lddomain --webroot-path /usr/local/ispconfig/interface/acme");
1242+
$success = $this->_exec($letsencrypt . " certonly --text --agree-tos --authenticator webroot --server https://acme-v01.api.letsencrypt.org/directory --rsa-key-size 4096 --email postmaster@$domain --domains $lddomain --webroot-path /usr/local/ispconfig/interface/acme <<< '1'");
12401243
}
12411244
if(!$success) {
12421245
// error issuing cert
@@ -1248,7 +1251,7 @@ function update($event_name, $data) {
12481251
/* Update also the master-DB of the Server-Farm */
12491252
$app->dbmaster->query("UPDATE web_domain SET `ssl` = ?, `ssl_letsencrypt` = ? WHERE `domain` = ?", $data['new']['ssl'], 'n', $data['new']['domain']);
12501253
}
1251-
}
1254+
//}
12521255

12531256
//* check is been correctly created
12541257
if(file_exists($crt_tmp_file) OR file_exists($key_tmp_file)) {
@@ -2102,6 +2105,19 @@ function delete($event_name, $data) {
21022105
//exec('fuser -km '.escapeshellarg($data['old']['document_root'].'/'.$log_folder).' 2>/dev/null');
21032106
exec('umount '.escapeshellarg($data['old']['document_root'].'/'.$log_folder).' 2>/dev/null');
21042107
}
2108+
2109+
// remove letsencrypt if it exists (renew will always fail otherwise)
2110+
2111+
$domain = $data['old']['ssl_domain'];
2112+
if(!$domain) $domain = $data['old']['domain'];
2113+
if(substr($domain, 0, 2) === '*.') {
2114+
// wildcard domain not yet supported by letsencrypt!
2115+
$domain = substr($domain, 2);
2116+
}
2117+
//$crt_tmp_file = "/etc/letsencrypt/live/".$domain."/cert.pem";
2118+
//$key_tmp_file = "/etc/letsencrypt/live/".$domain."/privkey.pem";
2119+
$le_conf_file = '/etc/letsencrypt/renewal/' . $domain . '.conf';
2120+
@rename('/etc/letsencrypt/renewal/' . $domain . '.conf', '/etc/letsencrypt/renewal/' . $domain . '.conf~backup');
21052121
}
21062122

21072123
//* remove mountpoint from fstab

server/plugins-available/nginx_plugin.inc.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ function update($event_name, $data) {
333333
return 0;
334334
}
335335

336+
$update_letsencrypt = false;
337+
336338
if($this->action != 'insert') $this->action = 'update';
337339

338340
if($data['new']['type'] != 'vhost' && $data['new']['type'] != 'vhostsubdomain' && $data['new']['type'] != 'vhostalias' && $data['new']['parent_domain_id'] > 0) {
@@ -354,6 +356,7 @@ function update($event_name, $data) {
354356
$data['new'] = $tmp;
355357
$data['old'] = $tmp;
356358
$this->action = 'update';
359+
$update_letsencrypt = true;
357360
}
358361

359362
// load the server configuration options
@@ -1251,8 +1254,7 @@ function update($event_name, $data) {
12511254
($data['old']['ssl'] == 'n' || $data['old']['ssl_letsencrypt'] == 'n') // we have new let's encrypt configuration
12521255
|| ($data['old']['domain'] != $data['new']['domain']) // we have domain update
12531256
|| ($data['old']['subdomain'] != $data['new']['subdomain']) // we have new or update on "auto" subdomain
1254-
|| ($data['new']['type'] == 'subdomain') // we have new or update on subdomain
1255-
|| ($data['old']['type'] == 'alias' || $data['new']['type'] == 'alias') // we have new or update on alias domain
1257+
|| $update_letsencrypt == true
12561258
)) {
12571259
// default values
12581260
$temp_domains = array();
@@ -1309,13 +1311,14 @@ function update($event_name, $data) {
13091311
$webroot = $data['new']['document_root']."/web";
13101312

13111313
//* check if we have already a Let's Encrypt cert
1312-
if(!file_exists($crt_tmp_file) && !file_exists($key_tmp_file)) {
1314+
//if(!file_exists($crt_tmp_file) && !file_exists($key_tmp_file)) {
1315+
// we must not skip if cert exists, otherwise changed domains (alias or sub) won't make it to the cert
13131316
$app->log("Create Let's Encrypt SSL Cert for: $domain", LOGLEVEL_DEBUG);
13141317

13151318
$success = false;
13161319
$letsencrypt = array_shift( explode("\n", shell_exec('which letsencrypt certbot /root/.local/share/letsencrypt/bin/letsencrypt')) );
13171320
if(is_executable($letsencrypt)) {
1318-
$success = $this->_exec($letsencrypt . " certonly --text --agree-tos --authenticator webroot --server https://acme-v01.api.letsencrypt.org/directory --rsa-key-size 4096 --email postmaster@$domain --domains $lddomain --webroot-path /usr/local/ispconfig/interface/acme");
1321+
$success = $this->_exec($letsencrypt . " certonly --text --agree-tos --authenticator webroot --server https://acme-v01.api.letsencrypt.org/directory --rsa-key-size 4096 --email postmaster@$domain --domains $lddomain --webroot-path /usr/local/ispconfig/interface/acme <<< '1'");
13191322
}
13201323
if(!$success) {
13211324
// error issuing cert
@@ -1327,7 +1330,7 @@ function update($event_name, $data) {
13271330
/* Update also the master-DB of the Server-Farm */
13281331
$app->dbmaster->query("UPDATE web_domain SET `ssl` = ?, `ssl_letsencrypt` = ? WHERE `domain` = ?", $data['new']['ssl'], 'n', $data['new']['domain']);
13291332
}
1330-
}
1333+
//}
13311334

13321335
//* check is been correctly created
13331336
if(file_exists($crt_tmp_file) OR file_exists($key_tmp_file)) {
@@ -2124,6 +2127,18 @@ function delete($event_name, $data) {
21242127
//exec('fuser -km '.escapeshellarg($data['old']['document_root'].'/'.$log_folder).' 2>/dev/null');
21252128
exec('umount '.escapeshellarg($data['old']['document_root'].'/'.$log_folder).' 2>/dev/null');
21262129
}
2130+
2131+
// remove letsencrypt if it exists (renew will always fail otherwise)
2132+
$domain = $data['old']['ssl_domain'];
2133+
if(!$domain) $domain = $data['old']['domain'];
2134+
if(substr($domain, 0, 2) === '*.') {
2135+
// wildcard domain not yet supported by letsencrypt!
2136+
$domain = substr($domain, 2);
2137+
}
2138+
//$crt_tmp_file = "/etc/letsencrypt/live/".$domain."/cert.pem";
2139+
//$key_tmp_file = "/etc/letsencrypt/live/".$domain."/privkey.pem";
2140+
$le_conf_file = '/etc/letsencrypt/renewal/' . $domain . '.conf';
2141+
@rename('/etc/letsencrypt/renewal/' . $domain . '.conf', '/etc/letsencrypt/renewal/' . $domain . '.conf~backup');
21272142
}
21282143

21292144
//* remove mountpoint from fstab

0 commit comments

Comments
 (0)