diff --git a/crontab.js b/crontab.js index 3c41f89..1b39b94 100644 --- a/crontab.js +++ b/crontab.js @@ -65,11 +65,17 @@ exports.set_crontab = function(env_vars, callback){ 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"; + let tmp_log = "/tmp/" + tab._id + ".log"; + let log_file = exports.log_folder + "/" + tab._id + ".log"; if(tab.command[tab.command.length-1] != ";") // add semicolon tab.command +=";"; - 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"; + // hook is in beta + if (tab.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"; + } 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"; + } } else { crontab_string += tab.schedule + " " + tab.command + "\n"; @@ -96,7 +102,7 @@ exports.get_backup_names = function(){ var backups = []; fs.readdirSync(__dirname + '/crontabs').forEach(function(file){ // file name begins with backup - if(file.indexOf("backup") == 0){ + if(file.indexOf("backup") === 0){ backups.push(file); } }); @@ -150,7 +156,10 @@ exports.import_crontab = function(){ var command = line.replace(regex, '').trim(); var schedule = line.replace(command, '').trim(); - if(command && schedule){ + var is_valid = false; + try { is_valid = cron_parser.parseString(line).expressions.length > 0; } catch (e){} + + if(command && schedule && is_valid){ var name = namePrefix + '_' + index; db.findOne({ command: command, schedule: schedule }, function(err, doc) { diff --git a/package.json b/package.json index 47a168c..ebaad85 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "crontab-ui", - "version": "0.2.1", + "version": "0.2.2", "description": "Easy and safe way to manage your crontab file", "main": "index.js", "scripts": { diff --git a/public/js/script.js b/public/js/script.js index 95c69b1..66b1f7a 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -26,6 +26,9 @@ function messageBox(body, title, ok_text, close_text, callback){ /*********** crontab actions ****************/ +// TODO get rid of global variables +var schedule = ""; +var job_command = ""; function deleteJob(_id){ // TODO fix this. pass callback properly @@ -84,7 +87,7 @@ function editJob(_id){ $("#job-name").val(job.name); $("#job-command").val(job.command); // if macro not used - if(job.schedule.indexOf("@") != 0){ + if(job.schedule.indexOf("@") !== 0){ var components = job.schedule.split(" "); $("#job-minute").val(components[0]); $("#job-hour").val(components[1]); @@ -102,6 +105,9 @@ function editJob(_id){ $("#job-save").unbind("click"); // remove existing events attached to this $("#job-save").click(function(){ // TODO good old boring validations + if (!schedule) { + schedule = "* * * * *"; + } $.post(routes.save, {name: $("#job-name").val(), command: job_command , schedule: schedule, _id: _id, logging: $("#job-logging").prop("checked")}, function(){ location.reload(); }); @@ -124,6 +130,9 @@ function newJob(){ $("#job-save").unbind("click"); // remove existing events attached to this $("#job-save").click(function(){ // TODO good old boring validations + if (!schedule) { + schedule = "* * * * *"; + } $.post(routes.save, {name: $("#job-name").val(), command: job_command , schedule: schedule, _id: -1, logging: $("#job-logging").prop("checked")}, function(){ location.reload(); }); @@ -162,8 +171,6 @@ function import_db(){ // script corresponding to job popup management -var schedule = ""; -var job_command = ""; function job_string(){ $("#job-string").val(schedule + " " + job_command); return schedule + " " + job_command; diff --git a/views/popup.ejs b/views/popup.ejs index 931f979..f9bb15e 100644 --- a/views/popup.ejs +++ b/views/popup.ejs @@ -72,7 +72,8 @@

- +
+