2015-07-20 00:09:47 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
exports = module.exports = {
|
|
|
|
|
userAdded: userAdded,
|
|
|
|
|
userRemoved: userRemoved,
|
|
|
|
|
adminChanged: adminChanged,
|
|
|
|
|
passwordReset: passwordReset,
|
2019-05-06 22:09:18 +02:00
|
|
|
appUpdatesAvailable: appUpdatesAvailable,
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2016-01-18 16:11:00 +01:00
|
|
|
sendInvite: sendInvite,
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2019-02-11 12:32:02 -08:00
|
|
|
appUp: appUp,
|
2015-08-04 14:31:40 +02:00
|
|
|
appDied: appDied,
|
2019-05-07 12:04:28 +02:00
|
|
|
appUpdated: appUpdated,
|
2017-01-07 13:52:32 -08:00
|
|
|
oomEvent: oomEvent,
|
2015-08-04 14:31:40 +02:00
|
|
|
|
2016-10-14 14:46:34 -07:00
|
|
|
backupFailed: backupFailed,
|
2016-01-22 17:37:41 -08:00
|
|
|
|
2016-07-26 16:20:31 -07:00
|
|
|
certificateRenewalError: certificateRenewalError,
|
2019-10-14 09:30:20 -07:00
|
|
|
boxUpdateError: boxUpdateError,
|
2016-03-19 20:40:03 -07:00
|
|
|
|
2017-09-15 14:21:52 +02:00
|
|
|
sendTestMail: sendTestMail,
|
|
|
|
|
|
2019-04-15 16:36:37 -07:00
|
|
|
_mailQueue: [] // accumulate mails in test mode
|
2015-07-20 00:09:47 -07:00
|
|
|
};
|
|
|
|
|
|
2017-11-14 20:34:25 -08:00
|
|
|
var assert = require('assert'),
|
2019-10-24 13:34:14 -07:00
|
|
|
BoxError = require('./boxerror.js'),
|
2019-05-07 11:30:12 -07:00
|
|
|
custom = require('./custom.js'),
|
2015-07-20 00:09:47 -07:00
|
|
|
debug = require('debug')('box:mailer'),
|
|
|
|
|
ejs = require('ejs'),
|
2019-11-05 19:54:53 -08:00
|
|
|
mail = require('./mail.js'),
|
2015-07-20 00:09:47 -07:00
|
|
|
nodemailer = require('nodemailer'),
|
|
|
|
|
path = require('path'),
|
|
|
|
|
safe = require('safetydance'),
|
2016-10-13 11:14:17 +02:00
|
|
|
settings = require('./settings.js'),
|
2017-01-27 08:07:57 -08:00
|
|
|
showdown = require('showdown'),
|
2015-07-20 00:09:47 -07:00
|
|
|
smtpTransport = require('nodemailer-smtp-transport'),
|
2019-01-10 10:51:31 -08:00
|
|
|
util = require('util');
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2017-02-07 09:18:43 -08:00
|
|
|
var NOOP_CALLBACK = function (error) { if (error) debug(error); };
|
2017-01-19 14:55:54 +01:00
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
var MAIL_TEMPLATES_DIR = path.join(__dirname, 'mail_templates');
|
|
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
// This will collect the most common details required for notification emails
|
|
|
|
|
function getMailConfig(callback) {
|
|
|
|
|
assert.strictEqual(typeof callback, 'function');
|
|
|
|
|
|
2019-03-10 16:05:27 -07:00
|
|
|
settings.getCloudronName(function (error, cloudronName) {
|
|
|
|
|
// this is not fatal
|
|
|
|
|
if (error) {
|
|
|
|
|
debug(error);
|
|
|
|
|
cloudronName = 'Cloudron';
|
|
|
|
|
}
|
2018-01-19 17:44:12 +01:00
|
|
|
|
2019-03-10 16:05:27 -07:00
|
|
|
callback(null, {
|
|
|
|
|
cloudronName: cloudronName,
|
2019-07-26 10:49:29 -07:00
|
|
|
notificationFrom: `"${cloudronName}" <no-reply@${settings.adminDomain()}>`
|
2018-01-19 17:44:12 +01:00
|
|
|
});
|
|
|
|
|
});
|
2016-09-03 12:02:42 -07:00
|
|
|
}
|
|
|
|
|
|
2019-04-15 16:36:37 -07:00
|
|
|
function sendMail(mailOptions, callback) {
|
|
|
|
|
assert.strictEqual(typeof mailOptions, 'object');
|
2017-01-19 14:55:54 +01:00
|
|
|
callback = callback || NOOP_CALLBACK;
|
2015-11-10 00:24:40 -08:00
|
|
|
|
2019-04-15 16:36:37 -07:00
|
|
|
if (process.env.BOX_ENV === 'test') {
|
|
|
|
|
exports._mailQueue.push(mailOptions);
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-05 19:54:53 -08:00
|
|
|
mail.getMailAuth(function (error, data) {
|
2017-01-19 14:55:54 +01:00
|
|
|
if (error) return callback(error);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
var transport = nodemailer.createTransport(smtpTransport({
|
2019-11-05 19:54:53 -08:00
|
|
|
host: data.ip,
|
|
|
|
|
port: data.port,
|
2018-12-28 13:32:37 -08:00
|
|
|
auth: {
|
2019-07-26 10:49:29 -07:00
|
|
|
user: mailOptions.authUser || `no-reply@${settings.adminDomain()}`,
|
2019-11-05 19:54:53 -08:00
|
|
|
pass: data.relayToken
|
2018-12-28 13:32:37 -08:00
|
|
|
}
|
2015-07-20 00:09:47 -07:00
|
|
|
}));
|
|
|
|
|
|
2019-04-15 16:36:37 -07:00
|
|
|
transport.sendMail(mailOptions, function (error) {
|
2019-10-24 13:34:14 -07:00
|
|
|
if (error) return callback(new BoxError(BoxError.EXTERNAL_ERROR, error));
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2019-04-15 16:36:37 -07:00
|
|
|
debug(`Email "${mailOptions.subject}" sent to ${mailOptions.to}`);
|
2017-01-19 14:55:54 +01:00
|
|
|
|
|
|
|
|
callback(null);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function render(templateFile, params) {
|
|
|
|
|
assert.strictEqual(typeof templateFile, 'string');
|
|
|
|
|
assert.strictEqual(typeof params, 'object');
|
|
|
|
|
|
2017-08-04 12:02:50 +02:00
|
|
|
var content = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
content = ejs.render(safe.fs.readFileSync(path.join(MAIL_TEMPLATES_DIR, templateFile), 'utf8'), params);
|
|
|
|
|
} catch (e) {
|
2017-08-04 11:15:55 -07:00
|
|
|
debug(`Error rendering ${templateFile}`, e);
|
2017-08-04 12:02:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return content;
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
2019-01-10 12:00:04 +01:00
|
|
|
function mailUserEvent(mailTo, user, event) {
|
|
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
|
|
|
|
assert.strictEqual(typeof user, 'object');
|
|
|
|
|
assert.strictEqual(typeof event, 'string');
|
|
|
|
|
|
|
|
|
|
getMailConfig(function (error, mailConfig) {
|
|
|
|
|
if (error) return debug('Error getting mail details:', error);
|
|
|
|
|
|
|
|
|
|
var mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
|
|
|
|
to: mailTo,
|
|
|
|
|
subject: util.format('[%s] %s %s', mailConfig.cloudronName, user.username || user.fallbackEmail || user.email, event),
|
|
|
|
|
text: render('user_event.ejs', { user: user, event: event, format: 'text' }),
|
|
|
|
|
};
|
|
|
|
|
|
2019-04-15 16:36:37 -07:00
|
|
|
sendMail(mailOptions);
|
2019-01-10 12:00:04 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-18 16:11:00 +01:00
|
|
|
function sendInvite(user, invitor) {
|
2015-07-20 00:09:47 -07:00
|
|
|
assert.strictEqual(typeof user, 'object');
|
|
|
|
|
assert(typeof invitor === 'object');
|
|
|
|
|
|
2016-01-18 16:11:00 +01:00
|
|
|
debug('Sending invite mail');
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
getMailConfig(function (error, mailConfig) {
|
|
|
|
|
if (error) return debug('Error getting mail details:', error);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2016-10-13 11:14:17 +02:00
|
|
|
var templateData = {
|
|
|
|
|
user: user,
|
2019-07-26 10:49:29 -07:00
|
|
|
webadminUrl: settings.adminOrigin(),
|
|
|
|
|
setupLink: `${settings.adminOrigin()}/api/v1/session/account/setup.html?reset_token=${user.resetToken}&email=${encodeURIComponent(user.email)}`,
|
2016-10-13 11:14:17 +02:00
|
|
|
invitor: invitor,
|
2018-01-19 17:44:12 +01:00
|
|
|
cloudronName: mailConfig.cloudronName,
|
2019-07-26 10:49:29 -07:00
|
|
|
cloudronAvatarUrl: settings.adminOrigin() + '/api/v1/cloudron/avatar'
|
2016-10-13 11:14:17 +02:00
|
|
|
};
|
|
|
|
|
|
2016-10-13 11:38:52 +02:00
|
|
|
var templateDataText = JSON.parse(JSON.stringify(templateData));
|
|
|
|
|
templateDataText.format = 'text';
|
|
|
|
|
|
|
|
|
|
var templateDataHTML = JSON.parse(JSON.stringify(templateData));
|
|
|
|
|
templateDataHTML.format = 'html';
|
|
|
|
|
|
2016-10-13 11:14:17 +02:00
|
|
|
var mailOptions = {
|
2018-01-19 17:44:12 +01:00
|
|
|
from: mailConfig.notificationFrom,
|
2018-01-21 14:50:24 +01:00
|
|
|
to: user.fallbackEmail,
|
2018-01-19 17:44:12 +01:00
|
|
|
subject: util.format('Welcome to %s', mailConfig.cloudronName),
|
2016-10-13 11:38:52 +02:00
|
|
|
text: render('welcome_user.ejs', templateDataText),
|
|
|
|
|
html: render('welcome_user.ejs', templateDataHTML)
|
2016-10-13 11:14:17 +02:00
|
|
|
};
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2019-04-15 16:36:37 -07:00
|
|
|
sendMail(mailOptions);
|
2016-10-13 11:14:17 +02:00
|
|
|
});
|
2016-01-18 16:11:00 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-10 12:00:04 +01:00
|
|
|
function userAdded(mailTo, user) {
|
|
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
2016-01-18 16:11:00 +01:00
|
|
|
assert.strictEqual(typeof user, 'object');
|
|
|
|
|
|
2019-01-10 12:00:04 +01:00
|
|
|
debug(`userAdded: Sending mail for added users ${user.fallbackEmail} to ${mailTo}`);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
getMailConfig(function (error, mailConfig) {
|
|
|
|
|
if (error) return debug('Error getting mail details:', error);
|
2016-01-20 12:40:54 +01:00
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
var templateData = {
|
|
|
|
|
user: user,
|
|
|
|
|
cloudronName: mailConfig.cloudronName,
|
2019-07-26 10:49:29 -07:00
|
|
|
cloudronAvatarUrl: settings.adminOrigin() + '/api/v1/cloudron/avatar'
|
2018-01-19 17:44:12 +01:00
|
|
|
};
|
2016-10-13 12:37:25 +02:00
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
var templateDataText = JSON.parse(JSON.stringify(templateData));
|
|
|
|
|
templateDataText.format = 'text';
|
2017-01-17 15:34:50 +01:00
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
var templateDataHTML = JSON.parse(JSON.stringify(templateData));
|
|
|
|
|
templateDataHTML.format = 'html';
|
2017-01-17 15:34:50 +01:00
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
var mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
2019-01-10 12:00:04 +01:00
|
|
|
to: mailTo,
|
2018-01-21 14:50:24 +01:00
|
|
|
subject: util.format('[%s] User %s added', mailConfig.cloudronName, user.fallbackEmail),
|
2018-01-19 17:44:12 +01:00
|
|
|
text: render('user_added.ejs', templateDataText),
|
|
|
|
|
html: render('user_added.ejs', templateDataHTML)
|
|
|
|
|
};
|
2016-10-13 12:37:25 +02:00
|
|
|
|
2019-04-15 16:36:37 -07:00
|
|
|
sendMail(mailOptions);
|
2016-01-20 12:40:54 +01:00
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
2019-01-10 12:00:04 +01:00
|
|
|
function userRemoved(mailTo, user) {
|
|
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
2016-04-03 01:41:47 +02:00
|
|
|
assert.strictEqual(typeof user, 'object');
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2019-01-10 12:00:04 +01:00
|
|
|
debug('Sending mail for userRemoved.', user.id, user.username, user.email);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2019-01-10 12:00:04 +01:00
|
|
|
mailUserEvent(mailTo, user, 'was removed');
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
2019-01-10 12:00:04 +01:00
|
|
|
function adminChanged(mailTo, user, isAdmin) {
|
|
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
2015-07-20 00:09:47 -07:00
|
|
|
assert.strictEqual(typeof user, 'object');
|
2019-01-10 12:00:04 +01:00
|
|
|
assert.strictEqual(typeof isAdmin, 'boolean');
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
debug('Sending mail for adminChanged');
|
|
|
|
|
|
2019-01-10 12:00:04 +01:00
|
|
|
mailUserEvent(mailTo, user, isAdmin ? 'is now an admin' : 'is no more an admin');
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function passwordReset(user) {
|
|
|
|
|
assert.strictEqual(typeof user, 'object');
|
|
|
|
|
|
2016-04-03 01:41:47 +02:00
|
|
|
debug('Sending mail for password reset for user %s.', user.email, user.id);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
getMailConfig(function (error, mailConfig) {
|
|
|
|
|
if (error) return debug('Error getting mail details:', error);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2016-10-13 16:44:09 +02:00
|
|
|
var templateData = {
|
|
|
|
|
user: user,
|
2019-07-26 10:49:29 -07:00
|
|
|
resetLink: `${settings.adminOrigin()}/api/v1/session/password/reset.html?reset_token=${user.resetToken}&email=${encodeURIComponent(user.email)}`,
|
2018-01-19 17:44:12 +01:00
|
|
|
cloudronName: mailConfig.cloudronName,
|
2019-07-26 10:49:29 -07:00
|
|
|
cloudronAvatarUrl: settings.adminOrigin() + '/api/v1/cloudron/avatar'
|
2016-10-13 16:44:09 +02:00
|
|
|
};
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2016-10-13 16:44:09 +02:00
|
|
|
var templateDataText = JSON.parse(JSON.stringify(templateData));
|
|
|
|
|
templateDataText.format = 'text';
|
|
|
|
|
|
|
|
|
|
var templateDataHTML = JSON.parse(JSON.stringify(templateData));
|
|
|
|
|
templateDataHTML.format = 'html';
|
|
|
|
|
|
|
|
|
|
var mailOptions = {
|
2018-01-19 17:44:12 +01:00
|
|
|
from: mailConfig.notificationFrom,
|
2018-01-21 14:50:24 +01:00
|
|
|
to: user.fallbackEmail,
|
2018-01-19 17:44:12 +01:00
|
|
|
subject: util.format('[%s] Password Reset', mailConfig.cloudronName),
|
2016-10-13 16:44:09 +02:00
|
|
|
text: render('password_reset.ejs', templateDataText),
|
|
|
|
|
html: render('password_reset.ejs', templateDataHTML)
|
|
|
|
|
};
|
|
|
|
|
|
2019-04-15 16:36:37 -07:00
|
|
|
sendMail(mailOptions);
|
2016-10-13 16:44:09 +02:00
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
2019-02-11 12:32:02 -08:00
|
|
|
function appUp(mailTo, app) {
|
|
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
|
|
|
|
assert.strictEqual(typeof app, 'object');
|
|
|
|
|
|
|
|
|
|
debug('Sending mail for app %s @ %s up', app.id, app.fqdn);
|
|
|
|
|
|
|
|
|
|
getMailConfig(function (error, mailConfig) {
|
|
|
|
|
if (error) return debug('Error getting mail details:', error);
|
|
|
|
|
|
|
|
|
|
var mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
|
|
|
|
to: mailTo,
|
|
|
|
|
subject: util.format('[%s] App %s is back online', mailConfig.cloudronName, app.fqdn),
|
|
|
|
|
text: render('app_up.ejs', { title: app.manifest.title, appFqdn: app.fqdn, format: 'text' })
|
|
|
|
|
};
|
|
|
|
|
|
2019-04-15 16:36:37 -07:00
|
|
|
sendMail(mailOptions);
|
2019-02-11 12:32:02 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 12:00:04 +01:00
|
|
|
function appDied(mailTo, app) {
|
|
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
2015-07-20 00:09:47 -07:00
|
|
|
assert.strictEqual(typeof app, 'object');
|
|
|
|
|
|
2017-01-17 16:02:42 +01:00
|
|
|
debug('Sending mail for app %s @ %s died', app.id, app.fqdn);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
getMailConfig(function (error, mailConfig) {
|
|
|
|
|
if (error) return debug('Error getting mail details:', error);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
var mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
2019-01-10 12:00:04 +01:00
|
|
|
to: mailTo,
|
2018-01-19 17:44:12 +01:00
|
|
|
subject: util.format('[%s] App %s is down', mailConfig.cloudronName, app.fqdn),
|
2019-05-10 15:53:34 -07:00
|
|
|
text: render('app_down.ejs', { title: app.manifest.title, appFqdn: app.fqdn, supportEmail: custom.spec().support.email, format: 'text' })
|
2018-01-19 17:44:12 +01:00
|
|
|
};
|
2018-01-19 16:27:19 +01:00
|
|
|
|
2019-04-15 16:36:37 -07:00
|
|
|
sendMail(mailOptions);
|
2017-01-27 08:04:03 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-07 14:22:51 +02:00
|
|
|
function appUpdated(mailTo, app, callback) {
|
2019-05-07 12:04:28 +02:00
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
|
|
|
|
assert.strictEqual(typeof app, 'object');
|
2019-05-07 14:22:51 +02:00
|
|
|
callback = callback || NOOP_CALLBACK;
|
2019-05-07 12:04:28 +02:00
|
|
|
|
|
|
|
|
debug('Sending mail for app %s @ %s updated', app.id, app.fqdn);
|
|
|
|
|
|
|
|
|
|
getMailConfig(function (error, mailConfig) {
|
|
|
|
|
if (error) return debug('Error getting mail details:', error);
|
|
|
|
|
|
2019-06-12 17:15:02 +02:00
|
|
|
var converter = new showdown.Converter();
|
|
|
|
|
var templateData = {
|
|
|
|
|
title: app.manifest.title,
|
|
|
|
|
appFqdn: app.fqdn,
|
|
|
|
|
version: app.manifest.version,
|
|
|
|
|
changelog: app.manifest.changelog,
|
|
|
|
|
changelogHTML: converter.makeHtml(app.manifest.changelog),
|
|
|
|
|
cloudronName: mailConfig.cloudronName,
|
2019-07-26 10:49:29 -07:00
|
|
|
cloudronAvatarUrl: settings.adminOrigin() + '/api/v1/cloudron/avatar'
|
2019-06-12 17:15:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var templateDataText = JSON.parse(JSON.stringify(templateData));
|
|
|
|
|
templateDataText.format = 'text';
|
|
|
|
|
|
|
|
|
|
var templateDataHTML = JSON.parse(JSON.stringify(templateData));
|
|
|
|
|
templateDataHTML.format = 'html';
|
|
|
|
|
|
2019-05-07 12:04:28 +02:00
|
|
|
var mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
|
|
|
|
to: mailTo,
|
2019-06-12 17:15:02 +02:00
|
|
|
subject: `[${mailConfig.cloudronName}] App ${app.fqdn} was updated`,
|
|
|
|
|
text: render('app_updated.ejs', templateDataText),
|
|
|
|
|
html: render('app_updated.ejs', templateDataHTML)
|
2019-05-07 12:04:28 +02:00
|
|
|
};
|
|
|
|
|
|
2019-05-07 14:22:51 +02:00
|
|
|
sendMail(mailOptions, callback);
|
2019-05-07 12:04:28 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-06 22:09:18 +02:00
|
|
|
function appUpdatesAvailable(mailTo, apps, hasSubscription, callback) {
|
2019-03-10 16:05:27 -07:00
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
2019-05-06 22:09:18 +02:00
|
|
|
assert.strictEqual(typeof apps, 'object');
|
2017-11-02 18:31:51 -07:00
|
|
|
assert.strictEqual(typeof hasSubscription, 'boolean');
|
2019-03-10 16:05:27 -07:00
|
|
|
assert.strictEqual(typeof callback, 'function');
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
getMailConfig(function (error, mailConfig) {
|
|
|
|
|
if (error) return debug('Error getting mail details:', error);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
var converter = new showdown.Converter();
|
2019-05-06 22:09:18 +02:00
|
|
|
apps.forEach(function (app) {
|
|
|
|
|
app.changelogHTML = converter.makeHtml(app.updateInfo.manifest.changelog);
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
var templateData = {
|
2019-07-26 10:49:29 -07:00
|
|
|
webadminUrl: settings.adminOrigin(),
|
2018-01-19 17:44:12 +01:00
|
|
|
hasSubscription: hasSubscription,
|
2019-05-06 22:09:18 +02:00
|
|
|
apps: apps,
|
2018-01-19 17:44:12 +01:00
|
|
|
cloudronName: mailConfig.cloudronName,
|
2019-07-26 10:49:29 -07:00
|
|
|
cloudronAvatarUrl: settings.adminOrigin() + '/api/v1/cloudron/avatar'
|
2018-01-19 17:44:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var templateDataText = JSON.parse(JSON.stringify(templateData));
|
|
|
|
|
templateDataText.format = 'text';
|
|
|
|
|
|
|
|
|
|
var templateDataHTML = JSON.parse(JSON.stringify(templateData));
|
|
|
|
|
templateDataHTML.format = 'html';
|
|
|
|
|
|
|
|
|
|
var mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
2019-03-10 16:05:27 -07:00
|
|
|
to: mailTo,
|
2019-05-06 22:09:18 +02:00
|
|
|
subject: `New app updates available for ${mailConfig.cloudronName}`,
|
|
|
|
|
text: render('app_updates_available.ejs', templateDataText),
|
|
|
|
|
html: render('app_updates_available.ejs', templateDataHTML)
|
2018-01-19 17:44:12 +01:00
|
|
|
};
|
|
|
|
|
|
2019-04-15 16:36:37 -07:00
|
|
|
sendMail(mailOptions, callback);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-10 15:53:20 -07:00
|
|
|
function backupFailed(mailTo, errorMessage, logUrl) {
|
|
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
|
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
getMailConfig(function (error, mailConfig) {
|
|
|
|
|
if (error) return debug('Error getting mail details:', error);
|
2016-10-14 14:46:34 -07:00
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
var mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
2019-03-10 15:53:20 -07:00
|
|
|
to: mailTo,
|
2018-01-19 17:44:12 +01:00
|
|
|
subject: util.format('[%s] Failed to backup', mailConfig.cloudronName),
|
2019-03-06 16:23:25 -08:00
|
|
|
text: render('backup_failed.ejs', { cloudronName: mailConfig.cloudronName, message: errorMessage, logUrl: logUrl, format: 'text' })
|
2018-01-19 17:44:12 +01:00
|
|
|
};
|
2018-01-19 16:27:19 +01:00
|
|
|
|
2019-04-15 16:36:37 -07:00
|
|
|
sendMail(mailOptions);
|
2016-10-14 14:46:34 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-10 15:53:20 -07:00
|
|
|
function certificateRenewalError(mailTo, domain, message) {
|
|
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
2016-03-19 20:40:03 -07:00
|
|
|
assert.strictEqual(typeof domain, 'string');
|
|
|
|
|
assert.strictEqual(typeof message, 'string');
|
|
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
getMailConfig(function (error, mailConfig) {
|
|
|
|
|
if (error) return debug('Error getting mail details:', error);
|
2016-03-19 20:40:03 -07:00
|
|
|
|
2016-07-26 16:47:58 -07:00
|
|
|
var mailOptions = {
|
2018-01-19 17:44:12 +01:00
|
|
|
from: mailConfig.notificationFrom,
|
2019-03-10 15:53:20 -07:00
|
|
|
to: mailTo,
|
2016-07-26 16:47:58 -07:00
|
|
|
subject: util.format('[%s] Certificate renewal error', domain),
|
|
|
|
|
text: render('certificate_renewal_error.ejs', { domain: domain, message: message, format: 'text' })
|
|
|
|
|
};
|
|
|
|
|
|
2019-04-15 16:36:37 -07:00
|
|
|
sendMail(mailOptions);
|
2016-07-26 16:47:58 -07:00
|
|
|
});
|
2016-03-19 20:40:03 -07:00
|
|
|
}
|
|
|
|
|
|
2019-10-14 09:30:20 -07:00
|
|
|
function boxUpdateError(mailTo, message) {
|
|
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
|
|
|
|
assert.strictEqual(typeof message, 'string');
|
|
|
|
|
|
|
|
|
|
getMailConfig(function (error, mailConfig) {
|
|
|
|
|
if (error) return debug('Error getting mail details:', error);
|
|
|
|
|
|
|
|
|
|
var mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
|
|
|
|
to: mailTo,
|
|
|
|
|
subject: util.format('[%s] Cloudron update error', mailConfig.cloudronName),
|
|
|
|
|
text: render('box_update_error.ejs', { message: message, format: 'text' })
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
sendMail(mailOptions);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-06 11:54:37 -08:00
|
|
|
function oomEvent(mailTo, program, event) {
|
2019-01-10 12:00:04 +01:00
|
|
|
assert.strictEqual(typeof mailTo, 'string');
|
2017-01-07 13:52:32 -08:00
|
|
|
assert.strictEqual(typeof program, 'string');
|
2019-03-06 11:54:37 -08:00
|
|
|
assert.strictEqual(typeof event, 'object');
|
2017-01-07 13:52:32 -08:00
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
getMailConfig(function (error, mailConfig) {
|
|
|
|
|
if (error) return debug('Error getting mail details:', error);
|
2017-01-07 13:52:32 -08:00
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
var mailOptions = {
|
|
|
|
|
from: mailConfig.notificationFrom,
|
2019-01-10 12:00:04 +01:00
|
|
|
to: mailTo,
|
2019-03-06 11:54:37 -08:00
|
|
|
subject: util.format('[%s] %s was restarted (OOM)', mailConfig.cloudronName, program),
|
2019-03-06 15:59:35 -08:00
|
|
|
text: render('oom_event.ejs', { cloudronName: mailConfig.cloudronName, program: program, event: JSON.stringify(event), format: 'text' })
|
2018-01-19 17:44:12 +01:00
|
|
|
};
|
2018-01-19 16:27:19 +01:00
|
|
|
|
2019-04-15 16:36:37 -07:00
|
|
|
sendMail(mailOptions);
|
2017-01-07 13:52:32 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-15 16:47:43 -07:00
|
|
|
function sendTestMail(domain, email, callback) {
|
2018-01-23 16:10:23 -08:00
|
|
|
assert.strictEqual(typeof domain, 'string');
|
2017-09-15 14:21:52 +02:00
|
|
|
assert.strictEqual(typeof email, 'string');
|
2019-04-15 16:47:43 -07:00
|
|
|
assert.strictEqual(typeof callback, 'function');
|
2017-09-15 14:21:52 +02:00
|
|
|
|
2018-01-19 17:44:12 +01:00
|
|
|
getMailConfig(function (error, mailConfig) {
|
|
|
|
|
if (error) return debug('Error getting mail details:', error);
|
2017-09-15 14:21:52 +02:00
|
|
|
|
2018-01-19 16:27:19 +01:00
|
|
|
var mailOptions = {
|
2019-04-15 16:58:27 -07:00
|
|
|
authUser: `no-reply@${domain}`,
|
2018-02-03 18:27:55 -08:00
|
|
|
from: `"${mailConfig.cloudronName}" <no-reply@${domain}>`,
|
2018-01-19 16:27:19 +01:00
|
|
|
to: email,
|
2018-01-19 17:44:12 +01:00
|
|
|
subject: util.format('Test Email from %s', mailConfig.cloudronName),
|
|
|
|
|
text: render('test.ejs', { cloudronName: mailConfig.cloudronName, format: 'text'})
|
2018-01-19 16:27:19 +01:00
|
|
|
};
|
|
|
|
|
|
2019-04-15 16:47:43 -07:00
|
|
|
sendMail(mailOptions, callback);
|
2018-01-19 16:27:19 +01:00
|
|
|
});
|
2017-09-15 14:21:52 +02:00
|
|
|
}
|