diff --git a/src/certificates.js b/src/certificates.js index fe1fd9042..3f7ca3513 100644 --- a/src/certificates.js +++ b/src/certificates.js @@ -10,6 +10,7 @@ var acme = require('./cert/acme.js'), constants = require('./constants.js'), debug = require('debug')('box:src/certificates'), fs = require('fs'), + mailer = require('./mailer.js'), nginx = require('./nginx.js'), path = require('path'), paths = require('./paths.js'), @@ -150,6 +151,8 @@ function autoRenew(callback) { api.getCertificate(domain, apiOptions, function (error) { var certFilePath, keyFilePath; + mailer.certificateRenewed(domain, error ? error.message : ''); + if (error) { debug('autoRenew: could not renew cert for %s because %s', domain, error); diff --git a/src/mail_templates/certificate_renewed.ejs b/src/mail_templates/certificate_renewed.ejs new file mode 100644 index 000000000..6f1a712bc --- /dev/null +++ b/src/mail_templates/certificate_renewed.ejs @@ -0,0 +1,22 @@ +<%if (format === 'text') { %> + +Dear Cloudron Team, + +<% if (message) { %> + + <%= domain %> was not renewed. + <%- message %> + +<% } else { %> + + <%= domain %> was renewed. + +<% } %> + +Thank you, +Your Cloudron + +<% } else { %> + +<% } %> + diff --git a/src/mailer.js b/src/mailer.js index 80414e5ee..068fecdf1 100644 --- a/src/mailer.js +++ b/src/mailer.js @@ -20,6 +20,8 @@ exports = module.exports = { outOfDiskSpace: outOfDiskSpace, + certificateRenewed: certificateRenewed, + FEEDBACK_TYPE_FEEDBACK: 'feedback', FEEDBACK_TYPE_TICKET: 'ticket', FEEDBACK_TYPE_APP_MISSING: 'app_missing', @@ -375,6 +377,20 @@ function outOfDiskSpace(message) { sendMails([ mailOptions ]); } +function certificateRenewed(domain, message) { + assert.strictEqual(typeof domain, 'string'); + assert.strictEqual(typeof message, 'string'); + + var mailOptions = { + from: config.adminEmail(), + to: 'admin@cloudron.io', + subject: util.format('[%s] Certificate was %s renewed', domain, message ? 'not' : ''), + text: render('certificate_renewed.ejs', { domain: domain, message: message, format: 'text' }) + }; + + sendMails([ mailOptions ]); +} + // this function bypasses the queue intentionally. it is also expected to work without the mailer module initialized // crashnotifier should be able to send mail when there is no db function sendCrashNotification(program, context) {