adding env feature

v0.1.6
alseambusher 2016-02-14 08:28:39 -08:00
parent 0c6cc5512a
commit 5f52cbcf44
4 changed files with 14 additions and 1 deletions

1
app.js
View File

@ -38,6 +38,7 @@ app.get(routes.root, function(req, res) {
routes : JSON.stringify(routes),
crontabs : JSON.stringify(docs),
backups : crontab.get_backup_names(),
env : crontab.get_env()
});
});
})

View File

@ -6,8 +6,10 @@ db.loadDatabase(function (err) {
var exec = require('child_process').exec;
var fs = require('fs');
var cron_parser = require("cron-parser")
var os = require("os")
exports.log_folder = __dirname + '/crontabs/logs';
exports.env_file = __dirname + '/crontabs/env.db';
crontab = function(name, command, schedule, stopped, logging){
var data = {};
@ -70,6 +72,8 @@ exports.set_crontab = function(env_vars){
crontab_string += tab.schedule + " " + tab.command + "\n";
}
});
fs.writeFile(exports.env_file, env_vars);
fs.writeFile("/tmp/crontab", crontab_string, function(err) {
exec("crontab /tmp/crontab");
});
@ -118,6 +122,13 @@ exports.reload_db= function(){
db.loadDatabase();
}
exports.get_env = function(){
if (fs.existsSync(exports.env_file)) {
return fs.readFileSync(exports.env_file , 'utf8').replace("\n", "\n");
}
return ""
}
// TODO
exports.import_crontab = function(){
exec("crontab -l", function(error, stdout, stderr){

View File

@ -1,6 +1,6 @@
{
"name": "crontab-ui",
"version": "0.1.5",
"version": "0.1.6",
"description": "Easy and safe way to manage your crontab file",
"main": "index.js",
"scripts": {

View File

@ -13,6 +13,7 @@
$('[data-toggle="tooltip"]').tooltip();
crontabs = JSON.parse('<%- crontabs.replace(/\\\\/g, "\\\\\\\\").replace(/\\\"/g,"\\\\\"") %>');
routes = JSON.parse('<%- routes %>');
$("#env_vars").val(`<%- env %>`);
})
</script>
</head>