Skip to content

Commit b1a1c21

Browse files
committed
version bump
1 parent 285bcd1 commit b1a1c21

File tree

3 files changed

+45
-51
lines changed

3 files changed

+45
-51
lines changed

app.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ var routes = require("./routes").routes;
1616
// set the view engine to ejs
1717
app.set('view engine', 'ejs');
1818

19-
var bodyParser = require('body-parser')
19+
var bodyParser = require('body-parser');
2020
app.use( bodyParser.json() ); // to support JSON-encoded bodies
2121
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
2222
extended: true
2323
}));
24-
app.use(busboy()) // to support file uploads
24+
app.use(busboy()); // to support file uploads
2525

2626
// include all folders
2727
app.use(express.static(__dirname + '/public'));
@@ -44,7 +44,7 @@ app.get(routes.root, function(req, res) {
4444
moment: moment
4545
});
4646
});
47-
})
47+
});
4848

4949
app.post(routes.save, function(req, res) {
5050
// new job
@@ -56,31 +56,31 @@ app.post(routes.save, function(req, res) {
5656
crontab.update(req.body);
5757
}
5858
res.end();
59-
})
59+
});
6060

6161
app.post(routes.stop, function(req, res) {
6262
crontab.status(req.body._id, true);
6363
res.end();
64-
})
64+
});
6565

6666
app.post(routes.start, function(req, res) {
6767
crontab.status(req.body._id, false);
6868
res.end();
69-
})
69+
});
7070

7171
app.post(routes.remove, function(req, res) {
7272
crontab.remove(req.body._id);
7373
res.end();
74-
})
74+
});
7575
app.get(routes.crontab, function(req, res) {
7676
crontab.set_crontab(req.query.env_vars);
7777
res.end();
78-
})
78+
});
7979

8080
app.get(routes.backup, function(req, res) {
8181
crontab.backup();
8282
res.end();
83-
})
83+
});
8484

8585
app.get(routes.restore, function(req, res) {
8686
// get all the crontabs
@@ -92,17 +92,17 @@ app.get(routes.restore, function(req, res) {
9292
db: req.query.db
9393
});
9494
});
95-
})
95+
});
9696

9797
app.get(routes.delete_backup, function(req, res) {
9898
restore.delete(req.query.db);
9999
res.end();
100-
})
100+
});
101101

102102
app.get(routes.restore_backup, function(req, res) {
103103
crontab.restore(req.query.db);
104104
res.end();
105-
})
105+
});
106106

107107
app.get(routes.export, function(req, res) {
108108
var file = __dirname + '/crontabs/crontab.db';
@@ -115,7 +115,7 @@ app.get(routes.export, function(req, res) {
115115

116116
var filestream = fs.createReadStream(file);
117117
filestream.pipe(res);
118-
})
118+
});
119119

120120

121121
app.post(routes.import, function(req, res) {
@@ -129,12 +129,12 @@ app.post(routes.import, function(req, res) {
129129
res.redirect(routes.root);
130130
});
131131
});
132-
})
132+
});
133133

134134
app.get(routes.import_crontab, function(req, res) {
135-
crontab.import_crontab()
135+
crontab.import_crontab();
136136
res.end();
137-
})
137+
});
138138

139139
app.get(routes.logger, function(req, res) {
140140
var fs = require("fs");
@@ -143,8 +143,8 @@ app.get(routes.logger, function(req, res) {
143143
res.sendFile(_file);
144144
else
145145
res.end("No errors logged yet");
146-
})
146+
});
147147

148148
app.listen(app.get('port'), function() {
149-
console.log("Crontab UI is running at localhost:" + app.get('port'))
150-
})
149+
console.log("Crontab UI is running at localhost:" + app.get('port'));
150+
});

crontab.js

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ db.loadDatabase(function (err) {
55
});
66
var exec = require('child_process').exec;
77
var fs = require('fs');
8-
var cron_parser = require("cron-parser")
9-
var os = require("os")
8+
var cron_parser = require("cron-parser");
9+
var os = require("os");
1010

1111
exports.log_folder = __dirname + '/crontabs/logs';
1212
exports.env_file = __dirname + '/crontabs/env.db';
@@ -22,36 +22,36 @@ crontab = function(name, command, schedule, stopped, logging){
2222
data.timestamp = (new Date()).toString();
2323
data.logging = logging;
2424
return data;
25-
}
25+
};
2626

2727
exports.create_new = function(name, command, schedule, logging){
2828
var tab = crontab(name, command, schedule, false, logging);
2929
tab.created = new Date().valueOf();
3030
db.insert(tab);
31-
}
31+
};
3232

3333
exports.update = function(data){
3434
db.update({_id: data._id}, crontab(data.name, data.command, data.schedule, null, data.logging));
35-
}
35+
};
3636

3737
exports.status = function(_id, stopped){
3838
db.update({_id: _id},{$set: {stopped: stopped}});
39-
}
39+
};
4040

4141
exports.remove = function(_id){
4242
db.remove({_id: _id}, {});
43-
}
43+
};
4444
exports.crontabs = function(callback){
4545
db.find({}).sort({ created: -1 }).exec(function(err, docs){
4646
for(var i=0; i<docs.length; i++){
4747
if(docs[i].schedule == "@reboot")
48-
docs[i].next = "Next Reboot"
48+
docs[i].next = "Next Reboot";
4949
else
5050
docs[i].next = cron_parser.parseExpression(docs[i].schedule).next().toString();
5151
}
5252
callback(docs);
5353
});
54-
}
54+
};
5555
exports.set_crontab = function(env_vars){
5656
exports.crontabs( function(tabs){
5757
var crontab_string = "";
@@ -64,7 +64,7 @@ exports.set_crontab = function(env_vars){
6464
tmp_log = "/tmp/" + tab._id + ".log";
6565
log_file = exports.log_folder + "/" + tab._id + ".log";
6666
if(tab.command[tab.command.length-1] != ";") // add semicolon
67-
tab.command +=";"
67+
tab.command +=";";
6868
//{ command; } 2>/tmp/<id>.log|| {if test -f /tmp/<id>; then date >> <log file>; cat /tmp/<id>.log >> <log file>; rm /tmp<id>.log }
6969
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";
7070
}
@@ -79,10 +79,10 @@ exports.set_crontab = function(env_vars){
7979
});
8080

8181
});
82-
}
82+
};
8383

8484
exports.get_backup_names = function(){
85-
var backups = []
85+
var backups = [];
8686
fs.readdirSync(__dirname + '/crontabs').forEach(function(file){
8787
// file name begins with backup
8888
if(file.indexOf("backup") == 0){
@@ -92,10 +92,10 @@ exports.get_backup_names = function(){
9292

9393
// Sort by date. Newest on top
9494
for(var i=0; i<backups.length; i++){
95-
var Ti = backups[i].split("backup")[1]
95+
var Ti = backups[i].split("backup")[1];
9696
Ti = new Date(Ti.substring(0, Ti.length-3)).valueOf();
9797
for(var j=0; j<i; j++){
98-
var Tj = backups[j].split("backup")[1]
98+
var Tj = backups[j].split("backup")[1];
9999
Tj = new Date(Tj.substring(0, Tj.length-3)).valueOf();
100100
if(Ti > Tj){
101101
var temp = backups[i];
@@ -106,62 +106,56 @@ exports.get_backup_names = function(){
106106
}
107107

108108
return backups;
109-
}
109+
};
110110

111111
exports.backup = function(){
112112
//TODO check if it failed
113113
fs.createReadStream( __dirname + '/crontabs/crontab.db').pipe(fs.createWriteStream( __dirname + '/crontabs/backup ' + (new Date()).toString().replace("+", " ") + '.db'));
114-
}
114+
};
115115

116116
exports.restore = function(db_name){
117117
fs.createReadStream( __dirname + '/crontabs/' + db_name).pipe(fs.createWriteStream( __dirname + '/crontabs/crontab.db'));
118118
db.loadDatabase(); // reload the database
119-
}
119+
};
120120

121121
exports.reload_db= function(){
122122
db.loadDatabase();
123-
}
123+
};
124124

125125
exports.get_env = function(){
126126
if (fs.existsSync(exports.env_file)) {
127127
return fs.readFileSync(exports.env_file , 'utf8').replace("\n", "\n");
128128
}
129-
return ""
130-
}
129+
return "";
130+
};
131131

132-
// TODO
133132
exports.import_crontab = function(){
134133
exec("crontab -l", function(error, stdout, stderr){
135134
var lines = stdout.split("\n");
136-
137135
var namePrefix = new Date().getTime();
138136

139137
lines.forEach(function(line, index){
140138
var regex = /^((\@[a-zA-Z]+\s)|(([^\s]+)\s([^\s]+)\s([^\s]+)\s([^\s]+)\s([^\s]+)\s))/;
141139
var command = line.replace(regex, '').trim();
142140
var schedule = line.replace(command, '').trim();
143-
141+
144142
if(command && schedule){
145143
var name = namePrefix + '_' + index;
146144

147-
db.crontabs.findOne({ command: command, schedule: schedule }, function(err, doc) {
145+
db.findOne({ command: command, schedule: schedule }, function(err, doc) {
148146
if(err) {
149147
throw err;
150148
}
151149
if(!doc){
152-
exports.create_new(name, command, null, null, schedule, null);
150+
exports.create_new(name, command, schedule, null);
153151
}
154152
else{
155153
doc.command = command;
156154
doc.schedule = schedule;
157155
exports.update(doc);
158156
}
159157
});
160-
161-
162158
}
163-
164-
})
165-
//console.log(stdout);
159+
});
166160
});
167-
}
161+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "crontab-ui",
3-
"version": "0.1.7",
3+
"version": "0.1.8",
44
"description": "Easy and safe way to manage your crontab file",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)