Updated installation script

This commit is contained in:
Andris Reinman 2016-09-08 15:31:38 +03:00
parent 63f20a199a
commit d651cca039
5 changed files with 104 additions and 3 deletions

View file

@ -41,6 +41,11 @@ module.exports.sendMail = (mail, template, callback) => {
});
}
if (!mail.headers) {
mail.headers = {};
}
mail.headers['X-Sending-Zone'] = 'transactional';
getTemplate(template.html, (err, htmlRenderer) => {
if (err) {
return callback(err);

View file

@ -13,7 +13,7 @@ let upload = multer();
let settings = require('../lib/models/settings');
let allowedKeys = ['service_url', 'smtp_hostname', 'smtp_port', 'smtp_encryption', 'smtp_disable_auth', 'smtp_user', 'smtp_pass', 'admin_email', 'smtp_log', 'smtp_max_connections', 'smtp_max_messages', 'smtp_self_signed', 'default_from', 'default_address', 'default_subject', 'default_homepage', 'default_postaddress', 'default_sender', 'verp_hostname', 'verp_use', 'disable_wysiwyg', 'pgp_private_key', 'pgp_passphrase', 'ua_code', 'shoutout', 'disable_confirmations', 'smtp_throttling'];
let allowedKeys = ['service_url', 'smtp_hostname', 'smtp_port', 'smtp_encryption', 'smtp_disable_auth', 'smtp_user', 'smtp_pass', 'admin_email', 'smtp_log', 'smtp_max_connections', 'smtp_max_messages', 'smtp_self_signed', 'default_from', 'default_address', 'default_subject', 'default_homepage', 'default_postaddress', 'default_sender', 'verp_hostname', 'verp_use', 'disable_wysiwyg', 'pgp_private_key', 'pgp_passphrase', 'ua_code', 'shoutout', 'disable_confirmations', 'smtp_throttling', 'dkim_api_key', 'dkim_private_key', 'dkim_selector', 'dkim_domain'];
router.all('/*', (req, res, next) => {
if (!req.user) {

View file

@ -4,6 +4,7 @@ let express = require('express');
let router = new express.Router();
let request = require('request');
let campaigns = require('../lib/models/campaigns');
let settings = require('../lib/models/settings');
let log = require('npmlog');
let multer = require('multer');
let uploads = multer();
@ -286,4 +287,44 @@ router.post('/zone-mta', (req, res, next) => {
});
});
router.post('/zone-mta/sender-config', (req, res) => {
if (!req.query.api_token) {
return res.json({
error: 'api_token value not set'
});
}
settings.list(['dkim_api_key', 'dkim_private_key', 'dkim_selector', 'dkim_domain'], (err, configItems) => {
if (err) {
return res.json({
error: err.message
});
}
if (configItems.dkimApiKey !== req.query.api_token) {
return res.json({
error: 'invalid api_token value'
});
}
configItems.dkimSelector = (configItems.dkimSelector || '').trim();
configItems.dkimPrivateKey = (configItems.dkimPrivateKey || '').trim();
if (!configItems.dkimSelector || !configItems.dkimPrivateKey) {
// empty response
return res.json({});
}
let from = (req.body.from || '').trim();
let domain = from.split('@').pop().toLowerCase().trim();
res.json({
keys: {
domainName: configItems.dkimDomain || domain,
keySelector: configItems.dkimSelector,
privateKey: configItems.dkimPrivateKey
}
});
});
});
module.exports = router;

View file

@ -26,6 +26,7 @@ fi
HOSTNAME="${HOSTNAME:-`hostname`}"
MYSQL_PASSWORD=`pwgen -1`
DKIM_API_KEY=`pwgen -1`
# Setup MySQL user for Mailtrain
mysql -u root -e "CREATE USER 'mailtrain'@'localhost' IDENTIFIED BY '$MYSQL_PASSWORD';"
@ -57,6 +58,7 @@ INSERT INTO \`settings\` (\`key\`, \`value\`) VALUES ('smtp_encryption','NONE')
INSERT INTO \`settings\` (\`key\`, \`value\`) VALUES ('smtp_port','587') ON DUPLICATE KEY UPDATE \`value\`='587';
INSERT INTO \`settings\` (\`key\`, \`value\`) VALUES ('default_homepage','http://$HOSTNAME/') ON DUPLICATE KEY UPDATE \`value\`='http://$HOSTNAME/';
INSERT INTO \`settings\` (\`key\`, \`value\`) VALUES ('service_url','http://$HOSTNAME/') ON DUPLICATE KEY UPDATE \`value\`='http://$HOSTNAME/';
INSERT INTO \`settings\` (\`key\`, \`value\`) VALUES ('dkim_api_key','http://$DKIM_API_KEY/') ON DUPLICATE KEY UPDATE \`value\`='http://$DKIM_API_KEY/';
EOT
# Add new user for the mailtrain daemon to run as
@ -131,6 +133,13 @@ cat >> config/production.json <<EOT
"bounces": {
"enabled": false,
"url": "http://localhost/webhooks/zone-mta"
},
"getSenderConfig": 'http://localhost/webhooks/zone-mta/sender-config?api_token=$DKIM_API_KEY',
"zones": {
"transactional": {
"processes": 1,
"connections": 1
}
}
}
EOT

View file

@ -185,7 +185,7 @@
</div>
<div class="pull-right">
<button type="submit" id="verify-button" form="smtp-verify" class="btn btn-info" data-loading-text="Checking..." ><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Check SMTP config</button>
<button type="submit" id="verify-button" form="smtp-verify" class="btn btn-info" data-loading-text="Checking..."><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Check SMTP config</button>
</div>
</fieldset>
@ -312,7 +312,53 @@
<label for="pgp-private-key" class="col-sm-2 control-label">GPG Private Key</label>
<div class="col-sm-10">
<textarea class="form-control gpg-text" rows="3" id="pgp-private-key" name="pgp-private-key" placeholder="Begins with &#39;-----BEGIN PGP PRIVATE KEY BLOCK-----&#39;">{{pgpPrivateKey}}</textarea>
<span class="help-block">This value is optional. if you do not provide a private key GPG encrypted messages are sent without signing.</span>
<span class="help-block">This value is optional. If you do not provide a private key GPG encrypted messages are sent without signing.</span>
</div>
</div>
</fieldset>
<fieldset>
<legend>
DKIM Signing by ZoneMTA
</legend>
<p>
If you are using <a href="https://github.com/zone-eu/zone-mta">ZoneMTA</a> then Mailtrain can provide a DKIM key for signing all outgoing messages. Other services usually provide their own means to DKIM sign your messages
</p>
<p class="text-warning">
Do not use sensitive keys here. The private key is not encrypted in the database.
</p>
<div class="form-group">
<label for="pgp-passphrase" class="col-sm-2 control-label">ZoneMTA DKIM API Key</label>
<div class="col-sm-10">
<input type="password" class="form-control" name="dkim-api-key" id="dkim-api-key" placeholder="Some secret value" value="{{dkimApiKey}}">
<span class="help-block">Secret value known to ZoneMTA for requesting DKIM key information. If this value was generated by the Mailtrain installation script then you can keep it as it is</span>
</div>
</div>
<div class="form-group">
<label for="pgp-passphrase" class="col-sm-2 control-label">DKIM domain</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="dkim-domain" id="dkim-domain" placeholder="Domain name for the DKIM key" value="{{dkimDomain}}">
<span class="help-block">Leave blank to use the sender email address domain</span>
</div>
</div>
<div class="form-group">
<label for="pgp-passphrase" class="col-sm-2 control-label">DKIM key selector</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="dkim-selector" id="dkim-selector" placeholder="DKIM key selector" value="{{dkimSelector}}">
<span class="help-block">Signing is disabled without a valid selector value</span>
</div>
</div>
<div class="form-group">
<label for="dkim-private-key" class="col-sm-2 control-label">DKIM Private Key</label>
<div class="col-sm-10">
<textarea class="form-control gpg-text" rows="3" id="dkim-private-key" name="dkim-private-key" placeholder="Begins with &#39;-----BEGIN RSA PRIVATE KEY-----&#39;">{{dkimPrivateKey}}</textarea>
<span class="help-block">This value is optional. If you do not provide a private key then messages are not signed.</span>
</div>
</div>