@@ -265,26 +265,34 @@ public function request_certificates($data, $server_type = 'apache') {
265265 unset($ subdomains );
266266 unset($ aliasdomains );
267267
268+ $ letsencrypt_use_certcommand = false ;
268269 $ letsencrypt_cmd = '' ;
270+ $ letsencrypt = false ;
269271 $ success = false ;
272+
273+ $ letsencrypt = explode ("\n" , shell_exec ('which letsencrypt certbot /root/.local/share/letsencrypt/bin/letsencrypt /opt/eff.org/certbot/venv/bin/certbot ' ));
274+ $ letsencrypt = reset ($ letsencrypt );
275+ if (!is_executable ($ letsencrypt )) {
276+ $ letsencrypt = false ;
277+ }
270278 if (!empty ($ cli_domain_arg )) {
271279 if (!isset ($ server_config ['migration_mode ' ]) || $ server_config ['migration_mode ' ] != 'y ' ) {
272280 $ app ->log ("Create Let's Encrypt SSL Cert for: $ domain " , LOGLEVEL_DEBUG );
273281 $ app ->log ("Let's Encrypt SSL Cert domains: $ cli_domain_arg " , LOGLEVEL_DEBUG );
274282
275- $ letsencrypt = explode ("\n" , shell_exec ('which letsencrypt certbot /root/.local/share/letsencrypt/bin/letsencrypt /opt/eff.org/certbot/venv/bin/certbot ' ));
276- $ letsencrypt = reset ($ letsencrypt );
277- if (is_executable ($ letsencrypt )) {
283+ if ($ letsencrypt ) {
278284 $ letsencrypt_version = exec ($ letsencrypt . ' --version 2>&1 ' , $ ret , $ val );
279285 if (preg_match ('/^(\S+|\w+)\s+(\d+(\.\d+)+)$/ ' , $ letsencrypt_version , $ matches )) {
280286 $ letsencrypt_version = $ matches [2 ];
281287 }
282- if ($ letsencrypt_version >= 0.22 ) {
288+ if (version_compare ( $ letsencrypt_version, ' 0.22 ' , ' >= ' ) ) {
283289 $ acme_version = 'https://acme-v02.api.letsencrypt.org/directory ' ;
284290 } else {
285291 $ acme_version = 'https://acme-v01.api.letsencrypt.org/directory ' ;
286292 }
287- if ($ letsencrypt_version >= 0.31 ) {
293+ if (version_compare ($ letsencrypt_version , '0.30 ' , '>= ' )) {
294+ $ app ->log ("LE version is " . $ letsencrypt_version . ", so using certificates command " , LOGLEVEL_DEBUG );
295+ $ letsencrypt_use_certcommand = true ;
288296 $ webroot_map = array ();
289297 for ($ i = 0 ; $ i < count ($ temp_domains ); $ i ++) {
290298 $ webroot_map [$ temp_domains [$ i ]] = '/usr/local/ispconfig/interface/acme ' ;
@@ -302,8 +310,50 @@ public function request_certificates($data, $server_type = 'apache') {
302310 $ success = true ;
303311 }
304312 }
305-
306- $ le_files = $ this ->get_letsencrypt_certificate_paths ($ temp_domains );
313+ $ le_files = array ();
314+ if ($ letsencrypt_use_certcommand === true && $ letsencrypt ) {
315+ $ letsencrypt_cmd = $ letsencrypt . " certificates " . $ cli_domain_arg ;
316+ $ output = explode ("\n" , shell_exec ($ letsencrypt_cmd . " 2>/dev/null | grep -v '^ \$' " ));
317+ $ le_path = '' ;
318+ $ skip_to_next = true ;
319+ foreach ($ output as $ outline ) {
320+ $ outline = trim ($ outline );
321+ $ app ->log ("LE CERT OUTPUT: " . $ outline , LOGLEVEL_DEBUG );
322+
323+ if ($ skip_to_next === true && !preg_match ('/^\s*Certificate Name/ ' , $ outline )) {
324+ continue ;
325+ }
326+ $ skip_to_next = false ;
327+
328+ if (preg_match ('/^\s*Expiry.*?VALID:\s+\D/ ' , $ outline )) {
329+ $ app ->log ("Found LE path is expired or invalid: " . $ matches [1 ], LOGLEVEL_DEBUG );
330+ $ skip_to_next = true ;
331+ continue ;
332+ }
333+
334+ if (preg_match ('/^\s*Certificate Path:\s*(\/.*?)\s*$/ ' , $ outline , $ matches )) {
335+ $ app ->log ("Found LE path: " . $ matches [1 ], LOGLEVEL_DEBUG );
336+ $ le_path = dirname ($ matches [1 ]);
337+ if (is_dir ($ le_path )) {
338+ break ;
339+ } else {
340+ $ le_path = false ;
341+ }
342+ }
343+ }
344+
345+ if ($ le_path ) {
346+ $ le_files = array (
347+ 'privkey ' => $ le_path . '/privkey.pem ' ,
348+ 'chain ' => $ le_path . '/chain.pem ' ,
349+ 'cert ' => $ le_path . '/cert.pem ' ,
350+ 'fullchain ' => $ le_path . '/fullchain.pem '
351+ );
352+ }
353+ }
354+ if (empty ($ le_files )) {
355+ $ le_files = $ this ->get_letsencrypt_certificate_paths ($ temp_domains );
356+ }
307357 unset($ temp_domains );
308358
309359 if ($ server_type != 'apache ' || version_compare ($ app ->system ->getapacheversion (true ), '2.4.8 ' , '>= ' )) {
0 commit comments