Skip to content

Commit 3e091da

Browse files
committed
Letsencrypt enhanced generation and logs
Signed-off-by: Kristián Feldsam <feldsam@gmail.com>
1 parent b880181 commit 3e091da

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

server/plugins-available/apache2_plugin.inc.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,18 +1243,24 @@ function update($event_name, $data) {
12431243
$success = false;
12441244
$letsencrypt = explode("\n", shell_exec('which letsencrypt certbot /root/.local/share/letsencrypt/bin/letsencrypt'));
12451245
$letsencrypt = reset($letsencrypt);
1246+
$letsencrypt_cmd = $letsencrypt . " certonly -n --text --agree-tos --expand --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";
12461247
if(is_executable($letsencrypt)) {
1247-
$success = $this->_exec($letsencrypt . " certonly -n --text --agree-tos --expand --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");
1248+
$success = $this->_exec($letsencrypt_cmd);
12481249
}
12491250
if(!$success) {
12501251
// error issuing cert
12511252
$app->log('Let\'s Encrypt SSL Cert for: ' . $domain . ' could not be issued.', LOGLEVEL_WARN);
1252-
$data['new']['ssl_letsencrypt'] = 'n';
1253-
if($data['old']['ssl'] == 'n') $data['new']['ssl'] = 'n';
1254-
/* Update the DB of the (local) Server */
1255-
$app->db->query("UPDATE web_domain SET `ssl` = ?, `ssl_letsencrypt` = ? WHERE `domain` = ?", $data['new']['ssl'], 'n', $data['new']['domain']);
1256-
/* Update also the master-DB of the Server-Farm */
1257-
$app->dbmaster->query("UPDATE web_domain SET `ssl` = ?, `ssl_letsencrypt` = ? WHERE `domain` = ?", $data['new']['ssl'], 'n', $data['new']['domain']);
1253+
$app->log($letsencrypt_cmd, LOGLEVEL_WARN);
1254+
1255+
// if cert already exists, dont remove it. Ex. expired/misstyped/noDnsYet alias domain, api down...
1256+
if(!file_exists($crt_tmp_file)) {
1257+
$data['new']['ssl_letsencrypt'] = 'n';
1258+
if($data['old']['ssl'] == 'n') $data['new']['ssl'] = 'n';
1259+
/* Update the DB of the (local) Server */
1260+
$app->db->query("UPDATE web_domain SET `ssl` = ?, `ssl_letsencrypt` = ? WHERE `domain` = ?", $data['new']['ssl'], 'n', $data['new']['domain']);
1261+
/* Update also the master-DB of the Server-Farm */
1262+
$app->dbmaster->query("UPDATE web_domain SET `ssl` = ?, `ssl_letsencrypt` = ? WHERE `domain` = ?", $data['new']['ssl'], 'n', $data['new']['domain']);
1263+
}
12581264
}
12591265
//}
12601266

@@ -3355,8 +3361,12 @@ private function _exec($command) {
33553361
$ret = 0;
33563362
$app->log('exec: '.$command, LOGLEVEL_DEBUG);
33573363
exec($command, $out, $ret);
3358-
if($ret != 0) return false;
3359-
else return true;
3364+
if($ret != 0) {
3365+
$app->log(implode("\n", $out), LOGLEVEL_WARN);
3366+
return false;
3367+
} else {
3368+
return true;
3369+
}
33603370
}
33613371

33623372
private function _checkTcp ($host, $port) {

0 commit comments

Comments
 (0)