read certificate data folder from acme.sh.env file, fixes #846

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2020-05-28 20:08:49 +02:00
parent 3c7bdcb5e0
commit d73d8da2fd
2 changed files with 26 additions and 4 deletions

View File

@@ -6,6 +6,7 @@ use Froxlor\Settings;
use Froxlor\Database\Database;
use Froxlor\PhpHelper;
use Froxlor\Domain\Domain;
use Froxlor\FileDir;
/**
* This file is part of the Froxlor project.
@@ -490,7 +491,7 @@ class AcmeSh extends \Froxlor\Cron\FroxlorCron
private static function checkFsFilesAreNewer($domain, $cert_date = 0)
{
$certificate_folder = dirname(self::$acmesh) . "/" . $domain;
$certificate_folder = self::getWorkingDirFromEnv($domain);
if (Settings::Get('system.leecc') > 0) {
$certificate_folder .= "_ecc";
}
@@ -506,6 +507,27 @@ class AcmeSh extends \Froxlor\Cron\FroxlorCron
return false;
}
public static function getWorkingDirFromEnv($domain = "")
{
$env_file = FileDir::makeCorrectFile(dirname(self::$acmesh) . '/acme.sh.env');
if (file_exists($env_file)) {
$output = [];
$cut = <<<EOC
cut -d'"' -f2
EOC;
exec('grep "LE_WORKING_DIR" ' . escapeshellarg($env_file) . ' | ' . $cut, $output);
if (is_array($output) && ! empty($output) && isset($output[0]) && ! empty($output[0])) {
return FileDir::makeCorrectDir($output[0] . "/" . $domain);
}
}
return FileDir::makeCorrectDir(dirname(self::$acmesh) . "/" . $domain);
}
public static function getAcmeSh()
{
return self::$acmesh;
}
/**
* get certificate files from filesystem and store in $return array
*
@@ -515,7 +537,7 @@ class AcmeSh extends \Froxlor\Cron\FroxlorCron
*/
private static function readCertificateToVar($domain, &$return, &$cronlog)
{
$certificate_folder = dirname(self::$acmesh) . "/" . $domain;
$certificate_folder = self::getWorkingDirFromEnv($domain);
$certificate_folder_noecc = null;
if (Settings::Get('system.leecc') > 0) {
$certificate_folder_noecc = \Froxlor\FileDir::makeCorrectDir($certificate_folder);

View File

@@ -329,9 +329,9 @@ class Domain
public static function doLetsEncryptCleanUp($domainname = null)
{
// @ see \Froxlor\Cron\Http\LetsEncrypt\AcmeSh.php
$acmesh = "/root/.acme.sh/acme.sh";
$acmesh = \Froxlor\Cron\Http\LetsEncrypt\AcmeSh::getAcmeSh();
if (file_exists($acmesh)) {
$certificate_folder = dirname($acmesh) . "/" . $domainname;
$certificate_folder = \Froxlor\Cron\Http\LetsEncrypt\AcmeSh::getWorkingDirFromEnv($domainname);
if (\Froxlor\Settings::Get('system.leecc') > 0) {
$certificate_folder .= "_ecc";
}