diff --git a/src/infra_version.js b/src/infra_version.js index ebb1f472d..b5dc50403 100644 --- a/src/infra_version.js +++ b/src/infra_version.js @@ -18,7 +18,7 @@ exports = module.exports = { 'postgresql': { repo: 'cloudron/postgresql', tag: 'cloudron/postgresql:0.17.0' }, 'mongodb': { repo: 'cloudron/mongodb', tag: 'cloudron/mongodb:0.13.0' }, 'redis': { repo: 'cloudron/redis', tag: 'cloudron/redis:0.11.0' }, - 'mail': { repo: 'cloudron/mail', tag: 'cloudron/mail:0.34.2' }, + 'mail': { repo: 'cloudron/mail', tag: 'cloudron/mail:0.35.0' }, 'graphite': { repo: 'cloudron/graphite', tag: 'cloudron/graphite:0.11.0' } } }; diff --git a/src/platform.js b/src/platform.js index e3cb4dc21..259b2e21c 100644 --- a/src/platform.js +++ b/src/platform.js @@ -251,9 +251,10 @@ function createMailConfig(callback) { if (error) return callback(error); var catchAll = result[settings.CATCH_ALL_ADDRESS_KEY].join(','); + var mailFromValidation = result[settings.MAIL_FROM_VALIDATION_KEY]; if (!safe.fs.writeFileSync(paths.ADDON_CONFIG_DIR + '/mail/mail.ini', - `mail_domain=${fqdn}\nmail_server_name=${mailFqdn}\nalerts_from=${alertsFrom}\nalerts_to=${alertsTo}\ncatch_all=${catchAll}\n`, 'utf8')) { + `mail_domain=${fqdn}\nmail_server_name=${mailFqdn}\nalerts_from=${alertsFrom}\nalerts_to=${alertsTo}\ncatch_all=${catchAll}\mail_from_validation=${mailFromValidation}\n`, 'utf8')) { return callback(new Error('Could not create mail var file:' + safe.error.message)); } diff --git a/src/routes/settings.js b/src/routes/settings.js index 597e25202..94f0ba86a 100644 --- a/src/routes/settings.js +++ b/src/routes/settings.js @@ -30,6 +30,9 @@ exports = module.exports = { getCatchAllAddress: getCatchAllAddress, setCatchAllAddress: setCatchAllAddress, + getMailFromValidation: getMailFromValidation, + setMailFromValidation: setMailFromValidation, + getAppstoreConfig: getAppstoreConfig, setAppstoreConfig: setAppstoreConfig, @@ -132,6 +135,27 @@ function setMailConfig(req, res, next) { }); } +function getMailFromValidation(req, res, next) { + settings.getMailFromValidation(function (error, enabled) { + if (error) return next(new HttpError(500, error)); + + next(new HttpSuccess(200, { enabled: enabled })); + }); +} + +function setMailFromValidation(req, res, next) { + assert.strictEqual(typeof req.body, 'object'); + + if (typeof req.body.enabled !== 'boolean') return next(new HttpError(400, 'enabled is required')); + + settings.setMailFromValidation({ enabled: req.body.enabled }, function (error) { + if (error && error.reason === SettingsError.BAD_FIELD) return next(new HttpError(400, error.message)); + if (error) return next(new HttpError(500, error)); + + next(new HttpSuccess(202)); + }); +} + function getMailRelay(req, res, next) { settings.getMailRelay(function (error, mail) { if (error) return next(new HttpError(500, error)); diff --git a/src/server.js b/src/server.js index 35c6a9036..0bb2fc9d8 100644 --- a/src/server.js +++ b/src/server.js @@ -217,6 +217,8 @@ function initializeExpressSync() { router.post('/api/v1/settings/mail_relay', settingsScope, routes.user.requireAdmin, routes.settings.setMailRelay); router.get ('/api/v1/settings/catch_all_address', settingsScope, routes.user.requireAdmin, routes.settings.getCatchAllAddress); router.put ('/api/v1/settings/catch_all_address', settingsScope, routes.user.requireAdmin, routes.settings.setCatchAllAddress); + router.get ('/api/v1/settings/mail_from_validation', settingsScope, routes.user.requireAdmin, routes.settings.getMailFromValidation); + router.post('/api/v1/settings/mail_from_validation', settingsScope, routes.user.requireAdmin, routes.settings.setMailFromValidation); // feedback router.post('/api/v1/feedback', usersScope, routes.cloudron.feedback); diff --git a/src/settings.js b/src/settings.js index d55c2c26c..48c03159f 100644 --- a/src/settings.js +++ b/src/settings.js @@ -42,6 +42,9 @@ exports = module.exports = { getMailConfig: getMailConfig, setMailConfig: setMailConfig, + getMailFromValidation: getMailFromValidation, + setMailFromValidation: setMailFromValidation, + getMailRelay: getMailRelay, setMailRelay: setMailRelay, @@ -53,6 +56,7 @@ exports = module.exports = { // booleans. if you add an entry here, be sure to fix getAll DEVELOPER_MODE_KEY: 'developer_mode', DYNAMIC_DNS_KEY: 'dynamic_dns', + MAIL_FROM_VALIDATION_KEY: 'mail_from_validation', // json. if you add an entry here, be sure to fix getAll DNS_CONFIG_KEY: 'dns_config', @@ -115,6 +119,7 @@ var gDefaults = (function () { result[exports.MAIL_CONFIG_KEY] = { enabled: false }; result[exports.MAIL_RELAY_KEY] = { provider: 'cloudron-smtp' }; result[exports.CATCH_ALL_ADDRESS_KEY] = [ ]; + result[exports.MAIL_FROM_VALIDATION_KEY] = true; return result; })(); @@ -465,6 +470,32 @@ function setMailConfig(mailConfig, callback) { }); } +function getMailFromValidation(callback) { + assert.strictEqual(typeof callback, 'function'); + + settingsdb.get(exports.MAIL_FROM_VALIDATION_KEY, function (error, value) { + if (error && error.reason === DatabaseError.NOT_FOUND) return callback(null, gDefaults[exports.MAIL_FROM_VALIDATION_KEY]); + if (error) return callback(new SettingsError(SettingsError.INTERNAL_ERROR, error)); + + callback(null, !!value); + }); +} + +function setMailFromValidation(enabled, callback) { + assert.strictEqual(typeof enabled, 'boolean'); + assert.strictEqual(typeof callback, 'function'); + + settingsdb.set(exports.MAIL_FROM_VALIDATION_KEY, enabled, function (error) { + if (error) return callback(new SettingsError(SettingsError.INTERNAL_ERROR, error)); + + exports.events.emit(exports.MAIL_FROM_VALIDATION_KEY, enabled); + + platform.createMailConfig(NOOP_CALLBACK); + + callback(null); + }); +} + function getMailRelay(callback) { assert.strictEqual(typeof callback, 'function'); @@ -602,6 +633,7 @@ function getAll(callback) { // convert booleans result[exports.DEVELOPER_MODE_KEY] = !!result[exports.DEVELOPER_MODE_KEY]; result[exports.DYNAMIC_DNS_KEY] = !!result[exports.DYNAMIC_DNS_KEY]; + result[exports.MAIL_FROM_VALIDATION_KEY] = !!result[exports.MAIL_FROM_VALIDATION_KEY]; // convert JSON objects [exports.DNS_CONFIG_KEY, exports.TLS_CONFIG_KEY, exports.BACKUP_CONFIG_KEY, exports.MAIL_CONFIG_KEY,