From 0c6cc5512adf5d252b0cd9aa0b7c4c4131661c43 Mon Sep 17 00:00:00 2001 From: Fantoccini Date: Sun, 14 Feb 2016 14:46:27 +1100 Subject: [PATCH] Add textarea for environment variables --- app.js | 4 ++-- crontab.js | 13 ++++++++----- public/js/script.js | 3 +-- views/index.ejs | 5 ++++- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app.js b/app.js index f42893a..d95d2d9 100755 --- a/app.js +++ b/app.js @@ -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(); }) diff --git a/crontab.js b/crontab.js index 5152696..129c850 100644 --- a/crontab.js +++ b/crontab.js @@ -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/.log|| {if test -f /tmp/; then date >> ; cat /tmp/.log >> ; rm /tmp.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); }); } diff --git a/public/js/script.js b/public/js/script.js index 4e79575..943cec5 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -46,7 +46,7 @@ function startJob(_id){ function setCrontab(){ messageBox("

Do you want to set the crontab file?

", "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 - diff --git a/views/index.ejs b/views/index.ejs index 587275c..045a1de 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -20,7 +20,10 @@ <% include navbar %>

Cronjobs

- +
+ + +
New Backup