send email notification to admin for non-successful let's encrypt results; fixes #1162
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -397,6 +397,7 @@ abstract class ApiCommand extends ApiParameter
|
||||
|
||||
$nat_fields = [
|
||||
'`c`.`loginname`',
|
||||
'`c`.`name`',
|
||||
'`a`.`loginname`',
|
||||
'`adminname`',
|
||||
'`databasename`',
|
||||
|
||||
@@ -100,7 +100,7 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
AND `id`<> :stdd
|
||||
");
|
||||
$usages_stmt = Database::prepare("
|
||||
SELECT * FROM `" . TABLE_PANEL_DISKSPACE . "`
|
||||
SELECT webspace, mail, mysql FROM `" . TABLE_PANEL_DISKSPACE . "`
|
||||
WHERE `customerid` = :cid
|
||||
ORDER BY `stamp` DESC LIMIT 1
|
||||
");
|
||||
@@ -109,11 +109,10 @@ class Customers extends ApiCommand implements ResourceEntity
|
||||
while ($row = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
if ($show_usages) {
|
||||
// get number of domains
|
||||
Database::pexecute($domains_stmt, [
|
||||
$domains = Database::pexecute_first($domains_stmt, [
|
||||
'cid' => $row['customerid'],
|
||||
'stdd' => $row['standardsubdomain']
|
||||
]);
|
||||
$domains = $domains_stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$row['domains'] = intval($domains['domains']);
|
||||
// get disk-space usages for web, mysql and mail
|
||||
$usages = Database::pexecute_first($usages_stmt, [
|
||||
|
||||
@@ -556,6 +556,10 @@ EOC;
|
||||
Settings::Set('system.le_froxlor_enabled', 0);
|
||||
}
|
||||
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_WARNING, "Let's Encrypt deactivated for domain " . $domain);
|
||||
if (!defined('CRON_IS_FORCED') && !defined('CRON_DEBUG_FLAG')) {
|
||||
// email info to admin that lets encrypt has been disabled for this domain
|
||||
Cronjob::notifyMailToAdmin("Let's Encrypt has been deactivated for domain '" . $domain . "' due to failed dns validation (wrong or no IP address)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -586,11 +590,20 @@ EOC;
|
||||
$acmesh_cmd .= " --debug";
|
||||
}
|
||||
|
||||
$acme_result = FileDir::safe_exec($acmesh_cmd);
|
||||
$exit_code = null;
|
||||
$acme_result = FileDir::safe_exec($acmesh_cmd, $exit_code);
|
||||
// debug output of acme.sh run
|
||||
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, implode("\n", $acme_result));
|
||||
|
||||
self::certToDb($certrow, $cronlog, $acme_result);
|
||||
if ($exit_code != 0) {
|
||||
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, "Non-successful exit-code returned :(");
|
||||
if (!defined('CRON_IS_FORCED') && !defined('CRON_DEBUG_FLAG')) {
|
||||
Cronjob::notifyMailToAdmin("Let's Encrypt certificate could not be obtained for: " . implode(", ", $domains) . "\n\n" . implode("\n", $acme_result));
|
||||
}
|
||||
} else {
|
||||
$cronlog->logAction(FroxlorLogger::CRON_ACTION, LOG_DEBUG, "Successful exit-code returned - storing certificate");
|
||||
self::certToDb($certrow, $cronlog, $acme_result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ class FileDir
|
||||
}
|
||||
|
||||
// execute the command and return output
|
||||
$return = '';
|
||||
$return = [];
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
if ($return_value == false) {
|
||||
|
||||
@@ -310,42 +310,37 @@ class Cronjob
|
||||
}
|
||||
|
||||
/**
|
||||
* Cronjob function to end a cronjob in a critical condition
|
||||
* but not without sending a notification mail to the admin
|
||||
* Send notification to system admin via email
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $subject
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function dieWithMail(string $message, string $subject = "[froxlor] Cronjob error")
|
||||
public static function notifyMailToAdmin(string $message, string $subject = "[froxlor] Important notice")
|
||||
{
|
||||
if (Settings::Get('system.send_cron_errors') == '1') {
|
||||
$_mail = new Mailer(true);
|
||||
$_mailerror = false;
|
||||
$mailerr_msg = "";
|
||||
try {
|
||||
$_mail->Subject = $subject;
|
||||
$_mail->AltBody = $message;
|
||||
$_mail->MsgHTML(nl2br($message));
|
||||
$_mail->AddAddress(Settings::Get('panel.adminmail'), Settings::Get('panel.adminmail_defname'));
|
||||
$_mail->Send();
|
||||
} catch (\PHPMailer\PHPMailer\Exception $e) {
|
||||
$mailerr_msg = $e->errorMessage();
|
||||
$_mailerror = true;
|
||||
} catch (Exception $e) {
|
||||
$mailerr_msg = $e->getMessage();
|
||||
$_mailerror = true;
|
||||
}
|
||||
|
||||
$_mail->ClearAddresses();
|
||||
|
||||
if ($_mailerror) {
|
||||
echo 'Error sending mail: ' . $mailerr_msg . "\n";
|
||||
}
|
||||
$mail = new Mailer(true);
|
||||
$mailerror = false;
|
||||
$mailerr_msg = "";
|
||||
try {
|
||||
$mail->Subject = $subject;
|
||||
$mail->AltBody = $message;
|
||||
$mail->MsgHTML(nl2br($message));
|
||||
$mail->AddAddress(Settings::Get('panel.adminmail'), Settings::Get('panel.adminmail_defname'));
|
||||
$mail->Send();
|
||||
} catch (\PHPMailer\PHPMailer\Exception $e) {
|
||||
$mailerr_msg = $e->errorMessage();
|
||||
$mailerror = true;
|
||||
} catch (Exception $e) {
|
||||
$mailerr_msg = $e->getMessage();
|
||||
$mailerror = true;
|
||||
}
|
||||
|
||||
die($message);
|
||||
$mail->ClearAddresses();
|
||||
|
||||
if ($mailerror) {
|
||||
echo 'Error sending mail: ' . $mailerr_msg . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user