-
Notifications
You must be signed in to change notification settings - Fork 0
/
loggedfs-web.js
57 lines (48 loc) · 1.56 KB
/
loggedfs-web.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var loggedfsClient = function(){
this.config = require('./config.json');
this.terminal = require('child_process').spawn('loggedfs', ['-f', '-p', this.config.mount_directory, '-c',this. config.loggedfs_config]);
};
loggedfsClient.prototype.start = function(onDataCallback, onEndCallback) {
var that = this;
this.terminal.stdout.on('data', function(data) {
var chunks = data.toString().split('\n');
for(var i in chunks) {
onDataCallback(that.parseOutput(chunks[i]));
}
});
this.terminal.on('exit', onEndCallback);
};
loggedfsClient.prototype.parseOutput = function(outputString) {
if(!outputString) return null;
var re = /(.*) \(src\/loggedfs\.cpp:\d*\) (.*?) (\/.*) \{(.*)\} \[ pid += (\d*) (.*) uid = (\d*) +\]/;
var match = re.exec(outputString);
var parsedOutput;
if (match == null) {
parsedOutput = {
rawString: outputString
};
}
else
parsedOutput = {
time: match[1],
action: match[2],
attempt: match[3],
result: match[4] === 'SUCCESS' ? true:false,
pid: +match[5],
pname: match[6],
uid: +match[7]
};
return this.filterExcludes(parsedOutput);
};
loggedfsClient.prototype.filterExcludes = function(parsedOutput) {
if(this.config.excludes)
for(var item in parsedOutput)
if(this.config.excludes[item])
for(var exclude in this.config.excludes[item]) {
var re = new RegExp(this.config.excludes[item][exclude]);
if(re.exec(parsedOutput[item]))
return null;
}
return parsedOutput;
};
module.exports = loggedfsClient;