From 933b64001cdaa8bcde5be6173d72d6c44f69d85e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 20 Jan 2024 12:49:23 +0000 Subject: [PATCH] Improve design --- .../templates/email-certificate-failed.tpl | 25 +++++++- app/config/locale/translations/en.json | 6 -- .../Platform/Workers/Certificates.php | 58 +++---------------- 3 files changed, 31 insertions(+), 58 deletions(-) diff --git a/app/config/locale/templates/email-certificate-failed.tpl b/app/config/locale/templates/email-certificate-failed.tpl index 213383bf51..ad1801efa0 100644 --- a/app/config/locale/templates/email-certificate-failed.tpl +++ b/app/config/locale/templates/email-certificate-failed.tpl @@ -1 +1,24 @@ -

Custom mail

\ No newline at end of file + + + + + +

Hello,

+

Domain {{domain}} failed to generate certificate after {{attempts}} consecutive attempts with following error:

+ + + + + +
+

{{error}}

+
+ +

We suggest to follow the below steps:

+
    +
  1. Examine the logs above to identify the issue
  2. +
  3. Ensure the domain did not expire without a renewal
  4. +
  5. Check DNS configuration for any unwanted changes
  6. +
+ +

The previous certificate will be valid for 30 days since the first failure. We highly recommend investigating this issue, otherwise the domain will end up without a valid HTTPS communication.

\ No newline at end of file diff --git a/app/config/locale/translations/en.json b/app/config/locale/translations/en.json index 8f8c4a5597..656aaeb310 100644 --- a/app/config/locale/translations/en.json +++ b/app/config/locale/translations/en.json @@ -30,12 +30,6 @@ "emails.invitation.footer": "If you are not interested, you can ignore this message.", "emails.invitation.thanks": "Thanks", "emails.invitation.signature": "{{project}} team", - "emails.certificate.subject": "Certificate failure for %s", - "emails.certificate.hello": "Hello", - "emails.certificate.body": "Certificate for your domain '{{domain}}' could not be generated. This is attempt no. {{attempt}}, and the failure was caused by: {{error}}", - "emails.certificate.footer": "Your previous certificate will be valid for 30 days since the first failure. We highly recommend investigating this case, otherwise your domain will end up without a valid SSL communication.", - "emails.certificate.thanks": "Thanks", - "emails.certificate.signature": "{{project}} team", "sms.verification.body": "{{secret}} is your {{project}} verification code.", "locale.country.unknown": "Unknown", "countries.af": "Afghanistan", diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index 52561a827f..b60920eae4 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -22,7 +22,6 @@ use Utopia\Database\Exception\Structure; use Utopia\Database\Helpers\ID; use Utopia\Database\Query; use Utopia\Domains\Domain; -use Utopia\Locale\Locale; use Utopia\Logger\Log; use Utopia\Platform\Action; use Utopia\Queue\Message; @@ -425,18 +424,13 @@ class Certificates extends Action Console::warning('Cannot renew domain (' . $domain . ') on attempt no. ' . $attempt . ' certificate: ' . $errorMessage); // Send mail to administratore mail - - $template = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-webhook-failed.tpl'); - - $template->setParam('{{webhook}}', $webhook->getAttribute('name')); - $template->setParam('{{project}}', $project->getAttribute('name')); - $template->setParam('{{url}}', $webhook->getAttribute('url')); - $template->setParam('{{error}}', $curlError ?? 'The server returned ' . $statusCode . ' status code'); - $template->setParam('{{redirect}}', "/console/project-$projectId/settings/webhooks/$webhookId"); - $template->setParam('{{attempts}}', $attempts); + $template = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-certificate-failed.tpl'); + $template->setParam('{{domain}}', $domain); + $template->setParam('{{error}}', \nl2br($errorMessage)); + $template->setParam('{{attempts}}', $attempt); // TODO: Use setbodyTemplate once #7307 is merged - $subject = 'Webhook deliveries have been paused'; + $subject = 'Certificate failed to generate'; $body = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-base-styled.tpl'); $body @@ -446,47 +440,9 @@ class Certificates extends Action $queueForMails ->setSubject($subject) - ->setBody($body->render()); - - foreach ($users as $user) { - $queueForMails - ->setVariables(['user' => $user->getAttribute('name', '')]) - ->setName($user->getAttribute('name', '')) - ->setRecipient($user->getAttribute('email')) - ->trigger(); - } - - $locale = new Locale(App::getEnv('_APP_LOCALE', 'en')); - if (!$locale->getText('emails.sender') || !$locale->getText("emails.certificate.hello") || !$locale->getText("emails.certificate.subject") || !$locale->getText("emails.certificate.body") || !$locale->getText("emails.certificate.footer") || !$locale->getText("emails.certificate.thanks") || !$locale->getText("emails.certificate.signature")) { - $locale->setDefault('en'); - } - - $subject = \sprintf($locale->getText("emails.certificate.subject"), $domain); - - $message = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-inner-base.tpl'); - $message - ->setParam('{{body}}', $locale->getText("emails.certificate.body")) - ->setParam('{{hello}}', $locale->getText("emails.certificate.hello")) - ->setParam('{{footer}}', $locale->getText("emails.certificate.footer")) - ->setParam('{{thanks}}', $locale->getText("emails.certificate.thanks")) - ->setParam('{{signature}}', $locale->getText("emails.certificate.signature")); - $body = $message->render(); - - $emailVariables = [ - 'direction' => $locale->getText('settings.direction'), - 'domain' => $domain, - 'error' => '
' . $errorMessage . '
', - 'attempt' => $attempt, - 'project' => 'Console', - 'redirect' => 'https://' . $domain, - ]; - - $queueForMails - ->setRecipient(App::getEnv('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS')) - ->setSubject($subject) - ->setBody($body) - ->setVariables($emailVariables) + ->setBody($body->render()) ->setName('Appwrite Administrator') + ->setRecipient(App::getEnv('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS')) ->trigger(); }