adding mail config ui options
parent
b207df5332
commit
b84a04adb0
1
app.js
1
app.js
|
@ -27,6 +27,7 @@ app.use(busboy()); // to support file uploads
|
||||||
app.use(express.static(__dirname + '/public'));
|
app.use(express.static(__dirname + '/public'));
|
||||||
app.use(express.static(__dirname + '/public/css'));
|
app.use(express.static(__dirname + '/public/css'));
|
||||||
app.use(express.static(__dirname + '/public/js'));
|
app.use(express.static(__dirname + '/public/js'));
|
||||||
|
app.use(express.static(__dirname + '/config'));
|
||||||
app.set('views', __dirname + '/views');
|
app.set('views', __dirname + '/views');
|
||||||
|
|
||||||
// set port to 8000 or the value set by environment var PORT
|
// set port to 8000 or the value set by environment var PORT
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
var defaults = require("../config/mailconfig.js");
|
||||||
|
|
||||||
|
var nodemailer = require('nodemailer');
|
||||||
|
|
||||||
|
// create reusable transporter object using the default SMTP transport
|
||||||
|
var transporter = nodemailer.createTransport(defaults.transporterStr);
|
||||||
|
var mailOptions = defaults.mailOptions;
|
||||||
|
|
||||||
|
var stdin = process.stdin,
|
||||||
|
stdout = process.stdout,
|
||||||
|
inputChunks = [];
|
||||||
|
|
||||||
|
stdin.resume();
|
||||||
|
stdin.setEncoding('utf8');
|
||||||
|
|
||||||
|
stdin.on('data', function (chunk) {
|
||||||
|
inputChunks.push(chunk);
|
||||||
|
});
|
||||||
|
|
||||||
|
stdin.on('end', function () {
|
||||||
|
var inputJSON = inputChunks.join(),
|
||||||
|
mailOptions = JSON.parse(inputJSON);
|
||||||
|
|
||||||
|
// outputJSON = JSON.stringify(parsedData, null, ' ');
|
||||||
|
// stdout.write(outputJSON);
|
||||||
|
// stdout.write('\n');
|
||||||
|
});
|
||||||
|
|
||||||
|
transporter.sendMail(mailOptions, function(error, info){
|
||||||
|
if(error){
|
||||||
|
return console.log(error);
|
||||||
|
}
|
||||||
|
console.log('Message sent: ' + info.response);
|
||||||
|
});
|
|
@ -0,0 +1,22 @@
|
||||||
|
/*jshint esversion: 6*/
|
||||||
|
// refer nodemailer for more info
|
||||||
|
|
||||||
|
var transporterStr = 'smtps://user%40gmail.com:pass@smtp.gmail.com';
|
||||||
|
|
||||||
|
var mailOptions = {
|
||||||
|
from: '"Fred Foo 👥" <foo@blurdybloop.com>', // sender address
|
||||||
|
to: 'bar@blurdybloop.com, baz@blurdybloop.com', // list of receivers
|
||||||
|
subject: 'Hello ✔', // Subject line
|
||||||
|
text: 'Hello world 🐴', // plaintext body
|
||||||
|
html: '<b>Hello world 🐴</b>' // html body
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof window === 'undefined') {
|
||||||
|
exports.transporterStr = transporterStr;
|
||||||
|
exports.mailOptions = mailOptions;
|
||||||
|
} else {
|
||||||
|
if (!window.config)
|
||||||
|
window.config = {};
|
||||||
|
window.config.transporterStr = transporterStr;
|
||||||
|
window.config.mailOptions = mailOptions;
|
||||||
|
}
|
21
crontab.js
21
crontab.js
|
@ -45,6 +45,8 @@ exports.status = function(_id, stopped){
|
||||||
exports.remove = function(_id){
|
exports.remove = function(_id){
|
||||||
db.remove({_id: _id}, {});
|
db.remove({_id: _id}, {});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Iterates through all the crontab entries in the db and calls the callback with the entries
|
||||||
exports.crontabs = function(callback){
|
exports.crontabs = function(callback){
|
||||||
db.find({}).sort({ created: -1 }).exec(function(err, docs){
|
db.find({}).sort({ created: -1 }).exec(function(err, docs){
|
||||||
for(var i=0; i<docs.length; i++){
|
for(var i=0; i<docs.length; i++){
|
||||||
|
@ -56,6 +58,8 @@ exports.crontabs = function(callback){
|
||||||
callback(docs);
|
callback(docs);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Set actual crontab file from the db
|
||||||
exports.set_crontab = function(env_vars, callback){
|
exports.set_crontab = function(env_vars, callback){
|
||||||
exports.crontabs( function(tabs){
|
exports.crontabs( function(tabs){
|
||||||
var crontab_string = "";
|
var crontab_string = "";
|
||||||
|
@ -72,9 +76,22 @@ exports.set_crontab = function(env_vars, callback){
|
||||||
// hook is in beta
|
// hook is in beta
|
||||||
if (tab.hook){
|
if (tab.hook){
|
||||||
let tmp_hook = "/tmp/" + tab._id + ".hook";
|
let tmp_hook = "/tmp/" + tab._id + ".hook";
|
||||||
crontab_string += tab.schedule + " ({ " + tab.command + " } | tee " + tmp_hook + ") 3>&1 1>&2 2>&3 | tee " + tmp_log +"; if test -f " + tmp_log +"; then date >> " + log_file + "; cat " + tmp_log + " >> " + log_file + "; rm " + tmp_log + "; fi; if test -f " + tmp_hook + "; then " + tab.hook + " < " + tmp_hook + "; rm " + tmp_hook + "; fi \n";
|
crontab_string += tab.schedule + " ({ " + tab.command + " } | tee " + tmp_hook + ") 3>&1 1>&2 2>&3 | tee " + tmp_log +
|
||||||
|
"; if test -f " + tmp_log +
|
||||||
|
"; then date >> " + log_file +
|
||||||
|
"; cat " + tmp_log + " >> " + log_file +
|
||||||
|
"; rm " + tmp_log +
|
||||||
|
"; fi; if test -f " + tmp_hook +
|
||||||
|
"; then " + tab.hook + " < " + tmp_hook +
|
||||||
|
"; rm " + tmp_hook +
|
||||||
|
"; fi \n";
|
||||||
} else {
|
} else {
|
||||||
crontab_string += tab.schedule + " { " + tab.command + " } 2> " + tmp_log +"; if test -f " + tmp_log +"; then date >> " + log_file + "; cat " + tmp_log + " >> " + log_file + "; rm " + tmp_log + "; fi \n";
|
crontab_string += tab.schedule + " { " + tab.command + " } 2> " + tmp_log +
|
||||||
|
"; if test -f " + tmp_log +
|
||||||
|
"; then date >> " + log_file +
|
||||||
|
"; cat " + tmp_log + " >> " + log_file +
|
||||||
|
"; rm " + tmp_log +
|
||||||
|
"; fi \n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "crontab-ui",
|
"name": "crontab-ui",
|
||||||
"version": "0.2.2",
|
"version": "0.2.3",
|
||||||
"description": "Easy and safe way to manage your crontab file",
|
"description": "Easy and safe way to manage your crontab file",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -20,7 +20,8 @@
|
||||||
"node": "latest"
|
"node": "latest"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"crontab-ui": "bin/crontab-ui.js"
|
"crontab-ui": "bin/crontab-ui.js",
|
||||||
|
"crontab-ui-mailer": "bin/crontab-ui-mailer.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
@ -169,6 +169,63 @@ function import_db(){
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setMailConfig(a){
|
||||||
|
let data = JSON.parse(a.getAttribute("data-json"));
|
||||||
|
let container = document.createElement("div");
|
||||||
|
|
||||||
|
let message = "<p>This is based on nodemailer. Refer <a href='https://github.com/nodemailer/nodemailer'>this</a> for more details.</p>";
|
||||||
|
container.innerHTML += message;
|
||||||
|
|
||||||
|
let transporterLabel = document.createElement("label");
|
||||||
|
transporterLabel.innerHTML = "Transporter";
|
||||||
|
let transporterInput = document.createElement("input");
|
||||||
|
transporterInput.type = "text";
|
||||||
|
transporterInput.id = "transporterInput";
|
||||||
|
transporterInput.setAttribute("placeholder", config.transporterStr);
|
||||||
|
transporterInput.className = "form-control";
|
||||||
|
if (data.transporterStr){
|
||||||
|
transporterInput.setAttribute("value", data.transporterStr);
|
||||||
|
}
|
||||||
|
container.appendChild(transporterLabel);
|
||||||
|
container.appendChild(transporterInput);
|
||||||
|
|
||||||
|
container.innerHTML += "<br/>";
|
||||||
|
|
||||||
|
let mailOptionsLabel = document.createElement("label");
|
||||||
|
mailOptionsLabel.innerHTML = "Mail Config";
|
||||||
|
let mailOptionsInput = document.createElement("textarea");
|
||||||
|
mailOptionsInput.setAttribute("placeholder", JSON.stringify(config.mailOptions, null, 2));
|
||||||
|
mailOptionsInput.className = "form-control";
|
||||||
|
mailOptionsInput.id = "mailOptionsInput";
|
||||||
|
mailOptionsInput.setAttribute("rows", "10");
|
||||||
|
if (data.mailOptions)
|
||||||
|
mailOptionsInput.innerHTML = JSON.stringify(data.mailOptions, null, 2);
|
||||||
|
container.appendChild(mailOptionsLabel);
|
||||||
|
container.appendChild(mailOptionsInput);
|
||||||
|
|
||||||
|
container.innerHTML += "<br/>";
|
||||||
|
|
||||||
|
let button = document.createElement("a");
|
||||||
|
button.className = "btn btn-primary btn-small";
|
||||||
|
button.innerHTML = "Use Defaults";
|
||||||
|
button.onclick = function(){
|
||||||
|
document.getElementById("transporterInput").value = config.transporterStr;
|
||||||
|
document.getElementById("mailOptionsInput").innerHTML = JSON.stringify(config.mailOptions, null, 2);
|
||||||
|
};
|
||||||
|
container.appendChild(button);
|
||||||
|
|
||||||
|
messageBox(container, "Mailing", null, null, function(){
|
||||||
|
let transporterStr = document.getElementById("transporterInput").value;
|
||||||
|
let mailOptions = JSON.parse(document.getElementById("mailOptionsInput").innerHTML);
|
||||||
|
if (transporterStr && mailOptions){
|
||||||
|
a.setAttribute("data-json", JSON.stringify({transporterStr: transporterStr, mailOptions: mailOptions}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function setHookConfig(a){
|
||||||
|
messageBox("<p>Coming Soon</p>", "Hooks", null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
// script corresponding to job popup management
|
// script corresponding to job popup management
|
||||||
function job_string(){
|
function job_string(){
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
<script src="jquery.js"></script>
|
<script src="jquery.js"></script>
|
||||||
<script src="script.js"></script>
|
<script src="script.js"></script>
|
||||||
<script src="bootstrap.min.js"></script>
|
<script src="bootstrap.min.js"></script>
|
||||||
|
<script src="mailconfig.js"></script>
|
||||||
<script type="text/javascript" src="https://cdn.datatables.net/v/bs/dt-1.10.12/datatables.min.js"></script>
|
<script type="text/javascript" src="https://cdn.datatables.net/v/bs/dt-1.10.12/datatables.min.js"></script>
|
||||||
<link rel="stylesheet" href="bootstrap.min.css" />
|
<link rel="stylesheet" href="bootstrap.min.css" />
|
||||||
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css"/>
|
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css"/>
|
||||||
|
|
|
@ -1,36 +1,3 @@
|
||||||
<div class="modal fade" id="popup">
|
|
||||||
<div class="modal-dialog">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="modal-header">
|
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
|
||||||
<h4 class="modal-title" id="modal-title">Message</h4>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body" id="modal-body">
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<button type="button" class="btn btn-default" data-dismiss="modal" id="modal-close-button">Close</button>
|
|
||||||
<button type="button" class="btn btn-primary" data-dismiss="modal" id="modal-button">Ok</button>
|
|
||||||
</div>
|
|
||||||
</div><!-- /.modal-content -->
|
|
||||||
</div><!-- /.modal-dialog -->
|
|
||||||
</div><!-- /.modal -->
|
|
||||||
|
|
||||||
<div class="modal fade" id="info-popup">
|
|
||||||
<div class="modal-dialog">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="modal-header">
|
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
|
||||||
<h4 class="modal-title" id="info-title">Message</h4>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body" id="info-body">
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<button type="button" class="btn btn-primary" data-dismiss="modal" id="info-button">Ok</button>
|
|
||||||
</div>
|
|
||||||
</div><!-- /.modal-content -->
|
|
||||||
</div><!-- /.modal-dialog -->
|
|
||||||
</div><!-- /.modal -->
|
|
||||||
|
|
||||||
<!-- Job -->
|
<!-- Job -->
|
||||||
<div class="modal fade" id="job">
|
<div class="modal fade" id="job">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
|
@ -73,7 +40,8 @@
|
||||||
<label>Job</label>
|
<label>Job</label>
|
||||||
<input type='text' class='form-control' id='job-string' disabled='disabled'/><br />
|
<input type='text' class='form-control' id='job-string' disabled='disabled'/><br />
|
||||||
<label><input type="checkbox" id="job-logging" style="position:relative;top:2px"/> Enable error logging.</label><br />
|
<label><input type="checkbox" id="job-logging" style="position:relative;top:2px"/> Enable error logging.</label><br />
|
||||||
<!-- <label><input type="checkbox" id="job-mail_toggle" style="position:relative;top:2px"/> Enable email.</label> -->
|
<a class="btn btn-primary btn-small" data-json="{}" onclick="setMailConfig(this);">Mailing</a>
|
||||||
|
<a class="btn btn-primary btn-small" data-json="{}" onclick="setHookConfig(this);">Hooks</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||||
|
@ -82,3 +50,36 @@
|
||||||
</div><!-- /.modal-content -->
|
</div><!-- /.modal-content -->
|
||||||
</div><!-- /.modal-dialog -->
|
</div><!-- /.modal-dialog -->
|
||||||
</div><!-- /.modal -->
|
</div><!-- /.modal -->
|
||||||
|
|
||||||
|
<div class="modal fade" id="popup">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||||
|
<h4 class="modal-title" id="modal-title">Message</h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body" id="modal-body">
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-default" data-dismiss="modal" id="modal-close-button">Close</button>
|
||||||
|
<button type="button" class="btn btn-primary" data-dismiss="modal" id="modal-button">Ok</button>
|
||||||
|
</div>
|
||||||
|
</div><!-- /.modal-content -->
|
||||||
|
</div><!-- /.modal-dialog -->
|
||||||
|
</div><!-- /.modal -->
|
||||||
|
|
||||||
|
<div class="modal fade" id="info-popup">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||||
|
<h4 class="modal-title" id="info-title">Message</h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body" id="info-body">
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-primary" data-dismiss="modal" id="info-button">Ok</button>
|
||||||
|
</div>
|
||||||
|
</div><!-- /.modal-content -->
|
||||||
|
</div><!-- /.modal-dialog -->
|
||||||
|
</div><!-- /.modal -->
|
||||||
|
|
Loading…
Reference in New Issue