Basic support for Mosaico-based email templates.
This commit is contained in:
parent
b5cdf57f72
commit
7b5642e911
38 changed files with 1271 additions and 751 deletions
|
|
@ -12,7 +12,11 @@ async function getAnonymousConfig(context) {
|
|||
isAuthMethodLocal: passport.isAuthMethodLocal,
|
||||
externalPasswordResetLink: config.ldap.passwordresetlink,
|
||||
language: config.language || 'en',
|
||||
isAuthenticated: !!context.user
|
||||
isAuthenticated: !!context.user,
|
||||
urlBase: config.www.urlBase,
|
||||
sandboxUrlBase: config.www.sandboxUrlBase,
|
||||
port: config.www.port,
|
||||
sandboxPort: config.www.sandboxPort
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ module.exports.csrfProtection = csrf({
|
|||
|
||||
module.exports.parseForm = bodyParser.urlencoded({
|
||||
extended: false,
|
||||
limit: config.www.postsize
|
||||
limit: config.www.postSize
|
||||
});
|
||||
|
||||
module.exports.loggedIn = (req, res, next) => {
|
||||
|
|
@ -87,35 +87,45 @@ module.exports.loggedIn = (req, res, next) => {
|
|||
};
|
||||
|
||||
module.exports.authByAccessToken = (req, res, next) => {
|
||||
nodeifyPromise((async () => {
|
||||
if (!req.query.access_token) {
|
||||
if (!req.query.access_token) {
|
||||
res.status(403);
|
||||
res.json({
|
||||
error: 'Missing access_token',
|
||||
data: []
|
||||
});
|
||||
}
|
||||
|
||||
users.getByAccessToken(req.query.access_token).then(user => {
|
||||
req.user = user;
|
||||
next();
|
||||
}).catch(err => {
|
||||
if (err instanceof interoperableErrors.PermissionDeniedError) {
|
||||
res.status(403);
|
||||
return res.json({
|
||||
error: 'Missing access_token',
|
||||
res.json({
|
||||
error: 'Invalid or expired access_token',
|
||||
data: []
|
||||
});
|
||||
} else {
|
||||
res.status(500);
|
||||
res.json({
|
||||
error: err.message || err,
|
||||
data: []
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
try {
|
||||
const user = await users.getByAccessToken(req.query.access_token);
|
||||
module.exports.tryAuthByRestrictedAccessToken = (req, res, next) => {
|
||||
if (req.cookies.restricted_access_token) {
|
||||
users.getByRestrictedAccessToken(req.cookies.restricted_access_token).then(user => {
|
||||
req.user = user;
|
||||
next();
|
||||
} catch (err) {
|
||||
if (err instanceof interoperableErrors.NotFoundError) {
|
||||
res.status(403);
|
||||
return res.json({
|
||||
error: 'Invalid or expired access_token',
|
||||
data: []
|
||||
});
|
||||
} else {
|
||||
res.status(500);
|
||||
return res.json({
|
||||
error: err.message || err,
|
||||
data: []
|
||||
});
|
||||
}
|
||||
}
|
||||
})(), next);
|
||||
}).catch(err => {
|
||||
next();
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.setup = app => {
|
||||
|
|
|
|||
|
|
@ -8,25 +8,25 @@ const fs = require('fs');
|
|||
const tryRequire = require('try-require');
|
||||
const posix = tryRequire('posix');
|
||||
|
||||
function _getConfigUidGid(prefix, defaultUid, defaultGid) {
|
||||
function _getConfigUidGid(userKey, groupKey, defaultUid, defaultGid) {
|
||||
let uid = defaultUid;
|
||||
let gid = defaultGid;
|
||||
|
||||
if (posix) {
|
||||
try {
|
||||
if (config.user) {
|
||||
uid = posix.getpwnam(config[prefix + 'user']).uid;
|
||||
if (config[userKey]) {
|
||||
uid = posix.getpwnam(config[userKey]).uid;
|
||||
}
|
||||
} catch (err) {
|
||||
log.info('PrivilegeHelpers', 'Failed to resolve user id "%s"', config[prefix + 'user']);
|
||||
log.info('PrivilegeHelpers', 'Failed to resolve user id "%s"', config[userKey]);
|
||||
}
|
||||
|
||||
try {
|
||||
if (config.user) {
|
||||
gid = posix.getpwnam(config[prefix + 'group']).gid;
|
||||
if (config[groupKey]) {
|
||||
gid = posix.getpwnam(config[groupKey]).gid;
|
||||
}
|
||||
} catch (err) {
|
||||
log.info('PrivilegeHelpers', 'Failed to resolve group id "%s"', config[prefix + 'group']);
|
||||
log.info('PrivilegeHelpers', 'Failed to resolve group id "%s"', config[groupKey]);
|
||||
}
|
||||
} else {
|
||||
log.info('PrivilegeHelpers', 'Posix module not installed. Cannot resolve uid/gid');
|
||||
|
|
@ -36,12 +36,12 @@ function _getConfigUidGid(prefix, defaultUid, defaultGid) {
|
|||
}
|
||||
|
||||
function getConfigUidGid() {
|
||||
return _getConfigUidGid('', process.getuid(), process.getgid());
|
||||
return _getConfigUidGid('user', 'group', process.getuid(), process.getgid());
|
||||
}
|
||||
|
||||
function getConfigROUidGid() {
|
||||
let rwIds = getConfigUidGid();
|
||||
return _getConfigUidGid('ro', rwIds.uid, rwIds.gid);
|
||||
const rwIds = getConfigUidGid();
|
||||
return _getConfigUidGid('roUser', 'roGroup', rwIds.uid, rwIds.gid);
|
||||
}
|
||||
|
||||
function ensureMailtrainOwner(file, callback) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,50 @@
|
|||
'use strict';
|
||||
|
||||
const fork = require('child_process').fork;
|
||||
|
||||
const config = require('config');
|
||||
const log = require('npmlog');
|
||||
const workers = new Set();
|
||||
|
||||
function spawn(callback) {
|
||||
let processes = Math.max(Number(config.queue.processes) || 1, 1);
|
||||
let spawned = 0;
|
||||
let returned = false;
|
||||
|
||||
if (processes > 1 && !config.redis.enabled) {
|
||||
log.error('Queue', '%s processes requested but Redis is not enabled, spawning 1 process', processes);
|
||||
processes = 1;
|
||||
}
|
||||
|
||||
let spawnSender = function () {
|
||||
if (spawned >= processes) {
|
||||
if (!returned) {
|
||||
returned = true;
|
||||
return callback();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
let child = fork(__dirname + '/../services/sender.js', []);
|
||||
let pid = child.pid;
|
||||
workers.add(child);
|
||||
|
||||
child.on('close', (code, signal) => {
|
||||
spawned--;
|
||||
workers.delete(child);
|
||||
log.error('Child', 'Sender process %s exited with %s', pid, code || signal);
|
||||
// Respawn after 5 seconds
|
||||
setTimeout(() => spawnSender(), 5 * 1000).unref();
|
||||
});
|
||||
|
||||
spawned++;
|
||||
setImmediate(spawnSender);
|
||||
};
|
||||
|
||||
spawnSender();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
workers: new Set()
|
||||
workers,
|
||||
spawn
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue