-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
87 lines (71 loc) · 2.48 KB
/
app.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var express = require('express');
var fs = require('fs');
var http = require('http');
var path = require('path');
var request = require('request');
var socketio = require('socket.io');
var app = express();
app.use('/', express.static(path.join(__dirname, 'static')));
var port = 9000;
var server = http.Server(app);
server.listen(port);
console.log('Web server listening on port', port);
// websockets server for push notifications
var io = socketio(server);
io.on('connection', function (socket) {
console.log('A user connected from', socket.handshake.address);
});
// log file paths - for now let's just symlink these to the live log files
var bind_log = path.join(__dirname, 'bind_log');
var tshark_log = path.join(__dirname, 'tshark_log');
// watch bind log for dns queries
fs.realpath(bind_log, function (err, logpath) {
if (err) console.log('Error:', err.message);
else console.log('Watching bind log file:', logpath);
});
fs.watchFile(bind_log, function (curr, prev) {
fs.readFile(bind_log, {
encoding: 'utf-8',
}, function (err, data) {
if (err) return;
// parse lines from bind log file and send to client
data.trim().slice(prev.size).split('\n').forEach(function (line) {
var m = line.match(/client (.+)#.*query: ([\w\-\.]+) .* \((.+)\)/);
if (m) {
console.log('New line in bind log:', line);
io.emit('bind', {
client: m[1],
host: m[2],
ip: m[3],
});
}
});
});
});
// watch tshark log for http post data
fs.realpath(tshark_log, function (err, logpath) {
if (err) console.log('Error:', err.message);
else console.log('Watching tshark log file:', logpath);
});
fs.watchFile(tshark_log, function (curr, prev) {
fs.readFile(tshark_log, {
encoding: 'utf-8',
}, function (err, data) {
if (err) return;
// parse lines from tshark log file and send to client
data.trim().slice(prev.size).split('\n').forEach(function (line) {
var m = line.match(/^(.*)\t(.*)\t(.*)\t(.*)\t(.*)$/);
if (m) {
console.log('New line in tshark bind log:', line);
io.emit('tshark', {
src: m[1],
dst: m[2],
host: m[3],
keys: m[4].split('|'),
values: m[5].split('|'),
});
}
});
});
});
// web pages