Add textarea for environment variables

pull/4/head
Fantoccini 9 years ago
parent ed99f4b541
commit 0c6cc5512a

@ -19,7 +19,7 @@ var bodyParser = require('body-parser')
app.use( bodyParser.json() ); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
}));
app.use(busboy()) // to support file uploads
// include all folders
@ -69,7 +69,7 @@ app.post(routes.remove, function(req, res) {
res.end();
})
app.get(routes.crontab, function(req, res) {
crontab.set_crontab();
crontab.set_crontab(req.query.env_vars);
res.end();
})

@ -16,7 +16,7 @@ crontab = function(name, command, schedule, stopped, logging){
data.schedule = schedule;
if(stopped != null) {
data.stopped = stopped;
}
}
data.timestamp = (new Date()).toString();
data.logging = logging;
return data;
@ -50,15 +50,18 @@ exports.crontabs = function(callback){
callback(docs);
});
}
exports.set_crontab = function(){
exports.set_crontab = function(env_vars){
exports.crontabs( function(tabs){
var crontab_string = "";
if (env_vars) {
crontab_string = env_vars + "\n";
}
tabs.forEach(function(tab){
if(!tab.stopped){
if (tab.logging && tab.logging == "true"){
tmp_log = "/tmp/" + tab._id + ".log";
log_file = exports.log_folder + "/" + tab._id + ".log";
if(tab.command[tab.command.length-1] != ";") // add semicolon
if(tab.command[tab.command.length-1] != ";") // add semicolon
tab.command +=";"
//{ command; } 2>/tmp/<id>.log|| {if test -f /tmp/<id>; then date >> <log file>; cat /tmp/<id>.log >> <log file>; rm /tmp<id>.log }
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";
@ -69,7 +72,7 @@ exports.set_crontab = function(){
});
fs.writeFile("/tmp/crontab", crontab_string, function(err) {
exec("crontab /tmp/crontab");
});
});
});
}
@ -129,6 +132,6 @@ exports.import_crontab = function(){
*/
//if(line.indexOf("@")
})
console.log(stdout);
console.log(stdout);
});
}

@ -46,7 +46,7 @@ function startJob(_id){
function setCrontab(){
messageBox("<p> Do you want to set the crontab file? </p>", "Confirm crontab setup", null, null, function(){
$.get(routes.crontab, {}, function(){
$.get(routes.crontab, { "env_vars": $("#env_vars").val() }, function(){
// TODO show only if success
infoMessageBox("Successfuly set crontab file!","Information");
});
@ -155,4 +155,3 @@ function set_schedule(){
job_string();
}
// popup management ends

@ -20,7 +20,10 @@
<% include navbar %>
<div class="container">
<h2>Cronjobs</h2>
<div class="form-group">
<label for="env_vars">Environment Variables:</label>
<textarea class="form-control" rows="3" id="env_vars" placeholder="# Please set PATH, MAILTO, HOME... here"></textarea>
</div>
<a class="btn btn-primary" onclick="newJob();"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span> New</a>
<a class="btn btn-info" onclick="doBackup();"><span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span> Backup</a>
<form id="import_form" enctype="multipart/form-data" action="<%= JSON.parse(routes).import %>" method="post" style="display:none">

Loading…
Cancel
Save